pi-DoMUS: Parallel Deal.II MUltiphysics Solver
pidomus.h
Go to the documentation of this file.
1 
15 #ifndef __pi_DoMUS_h_
16 #define __pi_DoMUS_h_
17 
18 
19 #include <deal.II/base/timer.h>
20 // #include <deal.II/base/parameter_handler.h>
21 
25 #include <mpi.h>
26 
27 // #include <deal.II/lac/precondition.h>
28 
29 #include "copy_data.h"
30 #include "base_interface.h"
31 #include <deal2lkit/parsed_grid_generator.h>
32 #include <deal2lkit/parsed_finite_element.h>
33 #include <deal2lkit/parsed_grid_refinement.h>
34 #include <deal2lkit/error_handler.h>
35 #include <deal2lkit/parsed_function.h>
36 #include <deal2lkit/parsed_data_out.h>
37 #include <deal2lkit/parameter_acceptor.h>
38 #include <deal2lkit/sundials_interface.h>
39 #include <deal2lkit/ida_interface.h>
40 #include <deal2lkit/imex_stepper.h>
41 
42 #include <deal2lkit/any_data.h>
43 #include <deal2lkit/fe_values_cache.h>
44 
45 #include "lac/lac_type.h"
46 #include "lac/lac_initializer.h"
47 
48 using namespace dealii;
49 using namespace deal2lkit;
50 using namespace pidomus;
51 
52 template <int dim, int spacedim = dim, typename LAC = LATrilinos>
53 class piDoMUS : public ParameterAcceptor, public SundialsInterface<typename LAC::VectorType>
54 {
55 
56 
57  // This is a class required to make tests
58  template<int fdim, int fspacedim, typename fn_LAC>
59  friend void test(piDoMUS<fdim, fspacedim, fn_LAC> &);
60 
61 public:
62 
63 
64  piDoMUS (const std::string &name,
65  const BaseInterface<dim, spacedim, LAC> &energy,
66  const MPI_Comm &comm = MPI_COMM_WORLD);
67 
68  virtual void declare_parameters(ParameterHandler &prm);
69  virtual void parse_parameters_call_back();
70 
71  void run ();
72 
73 
74  /*********************************************************
75  * Public interface from SundialsInterface
76  *********************************************************/
77  virtual shared_ptr<typename LAC::VectorType>
78  create_new_vector() const;
79 
81  virtual unsigned int n_dofs() const;
82 
87  virtual void output_step(const double t,
88  const typename LAC::VectorType &solution,
89  const typename LAC::VectorType &solution_dot,
90  const unsigned int step_number,
91  const double h);
92 
98  virtual bool solver_should_restart(const double t,
99  const unsigned int step_number,
100  const double h,
101  typename LAC::VectorType &solution,
102  typename LAC::VectorType &solution_dot);
103 
106  virtual int residual(const double t,
107  const typename LAC::VectorType &src_yy,
108  const typename LAC::VectorType &src_yp,
109  typename LAC::VectorType &dst);
110 
112  virtual int setup_jacobian(const double t,
113  const typename LAC::VectorType &src_yy,
114  const typename LAC::VectorType &src_yp,
115  const typename LAC::VectorType &residual,
116  const double alpha);
117 
118 
120  virtual int solve_jacobian_system(const double t,
121  const typename LAC::VectorType &y,
122  const typename LAC::VectorType &y_dot,
123  const typename LAC::VectorType &residual,
124  const double alpha,
125  const typename LAC::VectorType &src,
126  typename LAC::VectorType &dst) const;
127 
128 
129 
136  virtual typename LAC::VectorType &differential_components() const;
137 
141  typename LAC::VectorType &get_solution();
142 
146  void update_functions_and_constraints(const double &t);
147 
148 
149 
150 
159  void apply_dirichlet_bcs (const DoFHandler<dim,spacedim> &dof_handler,
160  ConstraintMatrix &constraints) const;
161 
166  void apply_neumann_bcs (const typename DoFHandler<dim,spacedim>::active_cell_iterator &cell,
167  FEValuesCache<dim,spacedim> &scratch,
168  std::vector<double> &local_residual) const;
169 
170 
180  void apply_forcing_terms (const typename DoFHandler<dim,spacedim>::active_cell_iterator &cell,
181  FEValuesCache<dim,spacedim> &scratch,
182  std::vector<double> &local_residual) const;
183 
184 
185 
186 private:
187  void make_grid_fe();
188  void setup_dofs (const bool &first_run = true);
189 
190  void assemble_matrices (const double t,
191  const typename LAC::VectorType &y,
192  const typename LAC::VectorType &y_dot,
193  const double alpha);
194  void refine_mesh ();
195 
196  void refine_and_transfer_solutions (LADealII::VectorType &y,
197  LADealII::VectorType &y_dot,
198  LADealII::VectorType &distributed_y,
199  LADealII::VectorType &distributed_y_dot,
200  bool adaptive_refinement);
201 
202 
203  void refine_and_transfer_solutions (LATrilinos::VectorType &y,
204  LATrilinos::VectorType &y_dot,
205  LATrilinos::VectorType &distributed_y,
206  LATrilinos::VectorType &distributed_y_dot,
207  bool adaptive_refinement);
208 
209 
210  void set_constrained_dofs_to_zero(typename LAC::VectorType &v) const;
211 
212  const MPI_Comm &comm;
213  const BaseInterface<dim, spacedim, LAC> &interface;
214 
215  unsigned int n_cycles;
216  unsigned int current_cycle;
217  unsigned int initial_global_refinement;
218  unsigned int max_time_iterations;
219 
220  std::string timer_file_name;
221 
222  ConditionalOStream pcout;
223  std::ofstream timer_outfile;
224  ConditionalOStream tcout;
225 
226 
227  shared_ptr<parallel::distributed::Triangulation<dim, spacedim> > triangulation;
228  shared_ptr<FiniteElement<dim, spacedim> > fe;
229  shared_ptr<DoFHandler<dim, spacedim> > dof_handler;
230 
231  ConstraintMatrix constraints;
232  ConstraintMatrix constraints_dot;
233 
234  LinearOperator<typename LAC::VectorType> jacobian_preconditioner_op;
236 
237  typename LAC::VectorType solution;
238  typename LAC::VectorType solution_dot;
239  typename LAC::VectorType explicit_solution;
240 
241  mutable typename LAC::VectorType distributed_solution;
242  mutable typename LAC::VectorType distributed_solution_dot;
243  mutable typename LAC::VectorType distributed_explicit_solution;
244 
245  mutable TimerOutput computing_timer;
246  ParsedDataOut<dim, spacedim> data_out;
247 
248  const unsigned int n_matrices;
249  std::vector<shared_ptr<typename LAC::BlockSparsityPattern> > matrix_sparsities;
250  std::vector<shared_ptr<typename LAC::BlockMatrix> > matrices;
251 
252  ErrorHandler<1> eh;
253  ParsedGridGenerator<dim, spacedim> pgg;
254  ParsedGridRefinement pgr;
255 
256  ParsedFunction<spacedim> exact_solution;
257 
258  ParsedFunction<spacedim> initial_solution;
259  ParsedFunction<spacedim> initial_solution_dot;
260 
261 
262  mutable ParsedMappedFunctions<spacedim> forcing_terms; // on the volume
263  mutable ParsedMappedFunctions<spacedim> neumann_bcs;
264  mutable ParsedDirichletBCs<dim,spacedim> dirichlet_bcs;
265  mutable ParsedDirichletBCs<dim,spacedim> dirichlet_bcs_dot;
266 
267 
268 
269  IDAInterface<typename LAC::VectorType> ida;
270  IMEXStepper<typename LAC::VectorType> euler;
271 
272 
273  std::vector<types::global_dof_index> dofs_per_block;
274  IndexSet global_partitioning;
275  std::vector<IndexSet> partitioning;
276  std::vector<IndexSet> relevant_partitioning;
277 
278  bool adaptive_refinement;
279  const bool we_are_parallel;
280  bool use_direct_solver;
281 
286  double jacobian_solver_tolerance;
287 
291  bool verbose;
292 
296  bool overwrite_iter;
297 
301  std::string time_stepper;
302 
306  double old_t;
307 
308 };
309 
310 #endif
Definition: pidomus.h:53
ActiveSelector::active_cell_iterator active_cell_iterator
Definition: copy_data.h:18
VectorType
void run(const std::vector< std::vector< Iterator > > &colored_iterators, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length=2 *MultithreadInfo::n_threads(), const unsigned int chunk_size=8)