Hermes2D  3.0
discrete_problem.h
1 
16 #ifndef __H2D_DISCRETE_PROBLEM_H
17 #define __H2D_DISCRETE_PROBLEM_H
18 
19 #include "hermes_common.h"
20 #include "weakform/weakform.h"
21 #include "function/function.h"
22 #include "exceptions.h"
23 #include "mixins2d.h"
24 #include "discrete_problem_helpers.h"
25 #include "discrete_problem_thread_assembler.h"
26 
27 namespace Hermes
28 {
29  namespace Hermes2D
30  {
31  class PrecalcShapeset;
36  template<typename Scalar>
37  class HERMES_API DiscreteProblem :
38  public Hermes::Mixins::Loggable,
39  public Hermes::Mixins::TimeMeasurable,
41  public Hermes::Mixins::StateQueryable,
44  public Hermes::Mixins::IntegrableWithGlobalOrder,
47  {
48  public:
55  DiscreteProblem(WeakFormSharedPtr<Scalar> wf, std::vector<SpaceSharedPtr<Scalar> > spaces, bool linear = false, bool dirichlet_lift_accordingly = true);
62  DiscreteProblem(WeakFormSharedPtr<Scalar> wf, SpaceSharedPtr<Scalar> space, bool linear = false, bool dirichlet_lift_accordingly = true);
69  DiscreteProblem(bool linear = false, bool dirichlet_lift_accordingly = true);
71  virtual ~DiscreteProblem();
72 
74  bool assemble(Scalar*& coeff_vec, SparseMatrix<Scalar>* mat, Vector<Scalar>* rhs = nullptr);
77  bool assemble(Scalar*& coeff_vec, Vector<Scalar>* rhs = nullptr);
80  bool assemble(SparseMatrix<Scalar>* mat, Vector<Scalar>* rhs = nullptr);
84  bool assemble(Vector<Scalar>* rhs);
85 
87  void set_time(double time);
88  void set_time_step(double time_step);
89 
91  void set_spaces(std::vector<SpaceSharedPtr<Scalar> > spaces);
92  void set_space(SpaceSharedPtr<Scalar> space);
93 
95  void set_weak_formulation(WeakFormSharedPtr<Scalar> wf);
96 
98  std::vector<SpaceSharedPtr<Scalar> > get_spaces();
99 
101  typedef void(*reassembled_states_reuse_linear_system_fn)(Traverse::State**& states, unsigned int& num_states, SparseMatrix<Scalar>* mat, Vector<Scalar>* rhs, Vector<Scalar>* dirichlet_lift_rhs, Scalar*& coeff_vec);
102  void set_reassembled_states_reuse_linear_system_fn(reassembled_states_reuse_linear_system_fn fn) {
103  this->reassembled_states_reuse_linear_system = fn;
104  }
105  reassembled_states_reuse_linear_system_fn reassembled_states_reuse_linear_system;
106  void set_reusable_DOFs(bool **reusable_DOFs, bool **reusable_Dirichlet)
107  {
108  for (int i = 0; i < this->num_threads_used; i++)
109  {
110  this->threadAssembler[i]->reusable_DOFs = reusable_DOFs;
111  this->threadAssembler[i]->reusable_Dirichlet = reusable_Dirichlet;
112  }
113  }
114 
116  virtual void set_verbose_output(bool to_set);
117 
118  protected:
120  void init_assembling(Traverse::State**& states, unsigned int& num_states, std::vector<MeshSharedPtr>& meshes);
121  void deinit_assembling(Traverse::State** states, unsigned int num_states);
122 
124  void set_RK(int original_spaces_count, bool force_diagonal_blocks = nullptr, Table* block_weights = nullptr);
125 
127  bool isOkay() const;
128  inline std::string getClassName() const { return "DiscreteProblem"; }
129 
131  void init(bool linear, bool dirichlet_lift_accordingly);
132 
134  std::vector<SpaceSharedPtr<Scalar> > spaces;
135  int spaces_size;
136 
138  Vector<Scalar>* dirichlet_lift_rhs;
139 
141  bool nonlinear, add_dirichlet_lift;
142 
144  bool set_matrix(SparseMatrix<Scalar>* mat);
145  bool set_rhs(Vector<Scalar>* rhs);
146  void invalidate_matrix();
147 
150 
153 
154  template<typename T> friend class Solver;
155  template<typename T> friend class LinearSolver;
156  template<typename T, typename S> friend class AdaptSolver;
157  template<typename T> friend class NonlinearSolver;
158  template<typename T> friend class NewtonSolver;
159  template<typename T> friend class PicardSolver;
160  template<typename T> friend class RungeKutta;
161  template<typename T> friend class KellyTypeAdapt;
162  };
163  }
164 }
165 #endif
Definition: adapt.h:24
Class utilizes parallel calculation.
Definition: mixins2d.h:37
std::vector< SpaceSharedPtr< Scalar > > spaces
Space instances for all equations in the system.
Provides capabilities to (re-)assemble a matrix / vector only where necessary. See also Solver::keep_...
Used to pass the instances of Space around.
Definition: space.h:34
::xsd::cxx::tree::time< char, simple_type > time
C++ type corresponding to the time XML Schema built-in type.
DiscreteProblemSelectiveAssembler< Scalar > selectiveAssembler
Select the right things to assemble.
DiscreteProblemThreadAssembler< Scalar > ** threadAssembler
Assembly data.
Used to pass the instances of WeakForm around.
Definition: weakform.h:55
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
This class is a one-thread (non-DG) assembly worker.
Vector< Scalar > * dirichlet_lift_rhs
Dirichlet lift rhs part.