pi-DoMUS: Parallel Deal.II MUltiphysics Solver
old_interface.h
Go to the documentation of this file.
1 
39 #ifndef _interface_h_
40 #define _interface_h_
41 
43 
44 #include <deal2lkit/dof_utilities.h>
45 #include <deal2lkit/parsed_finite_element.h>
46 #include <deal2lkit/any_data.h>
47 #include <deal2lkit/parsed_function.h>
48 #include <deal2lkit/parsed_mapped_functions.h>
49 #include <deal2lkit/parsed_dirichlet_bcs.h>
50 
51 #include "data/assembly.h"
52 #include "lac/lac_type.h"
54 
55 template <int dim,int spacedim=dim, int n_components=1, typename LAC=LATrilinos>
56 class Interface : public ParsedFiniteElement<dim,spacedim>
57 {
58  typedef FEValuesCache<dim,spacedim> Scratch;
59  typedef Assembly::CopyData::piDoMUSPreconditioner<dim,dim> CopyPreconditioner;
60  typedef Assembly::CopyData::piDoMUSSystem<dim,dim> CopySystem;
61 
62 public:
63 
64  virtual ~Interface() {};
65 
66  Interface(const std::string &name="",
67  const std::string &default_fe="FE_Q(1)",
68  const std::string &default_component_names="u",
69  const std::string &default_coupling="",
70  const std::string &default_preconditioner_coupling="",
71  const std::string &default_differential_components="") :
72  ParsedFiniteElement<dim,spacedim>(name, default_fe, default_component_names,
73  n_components, default_coupling, default_preconditioner_coupling),
74  forcing_terms("Forcing terms", default_component_names, "0=ALL"),
75  neumann_bcs("Neumann boundary conditions", default_component_names, "0=ALL"),
76  dirichlet_bcs("Dirichlet boundary conditions", default_component_names, "0=ALL"),
77  str_diff_comp(default_differential_components),
78  old_t(-1.0)
79  {};
80 
81  virtual void declare_parameters (ParameterHandler &prm);
82  virtual void parse_parameters_call_back ();
83  const std::vector<unsigned int> get_differential_blocks() const;
84 
88  virtual void set_time (const double &t) const;
89 
90 
96 
104  virtual void apply_dirichlet_bcs (const DoFHandler<dim,spacedim> &dof_handler,
105  ConstraintMatrix &constraints) const;
106 
111  template<typename Number>
113  Scratch &scratch,
114  CopySystem &data,
115  std::vector<Number> &local_residual) const;
116 
117 
127  template<typename Number>
129  Scratch &scratch,
130  CopySystem &data,
131  std::vector<Number> &local_residual) const;
132 
146  virtual void initialize_data(const typename LAC::VectorType &solution,
147  const typename LAC::VectorType &solution_dot,
148  const double t,
149  const double alpha) const;
150 
151 
165  Scratch &,
166  CopySystem &,
167  Sdouble &) const;
168 
182  Scratch &,
183  CopyPreconditioner &,
184  SSdouble &) const;
185 
199  Scratch &,
200  CopySystem &,
201  Sdouble &) const;
202 
216  Scratch &,
217  CopySystem &,
218  SSdouble &) const;
219 
231  virtual void get_system_residual (const typename DoFHandler<dim,spacedim>::active_cell_iterator &cell,
232  Scratch &scratch,
233  CopySystem &data,
234  std::vector<Sdouble> &local_residual) const;
235 
247  virtual void get_system_residual (const typename DoFHandler<dim,spacedim>::active_cell_iterator &cell,
248  Scratch &scratch,
249  CopySystem &data,
250  std::vector<double> &local_residual) const;
251 
264  Scratch &scratch,
265  CopyPreconditioner &data,
266  std::vector<Sdouble> &local_residual) const;
267 
278  const typename LAC::BlockMatrix &,
279  const typename LAC::BlockMatrix &,
280  const std::vector<shared_ptr<typename LAC::BlockMatrix> >,
283 
284 
286  Scratch &scratch,
287  CopySystem &data) const;
288 
290  Scratch &scratch,
291  CopyPreconditioner &data) const;
292 
293  virtual shared_ptr<Mapping<dim,spacedim> > get_mapping(const DoFHandler<dim,spacedim> &,
294  const typename LAC::VectorType &) const;
295 
296  virtual UpdateFlags get_jacobian_flags() const;
297 
298  virtual UpdateFlags get_residual_flags() const;
299 
301 
302 
303  virtual UpdateFlags get_face_flags() const;
304 
305  void fix_solution_dot_derivative(FEValuesCache<dim,spacedim> &, double) const;
306 
307  void fix_solution_dot_derivative(FEValuesCache<dim,spacedim> &fe_cache, Sdouble alpha) const;
308 
309 
310  void fix_solution_dot_derivative(FEValuesCache<dim,spacedim> &fe_cache, SSdouble alpha) const;
311 
312  template<typename Number>
313  void reinit(const Number &alpha,
315  FEValuesCache<dim,spacedim> &fe_cache) const;
316 
317 
318  template<typename Number>
319  void reinit(const Number &alpha,
321  const unsigned int face_no,
322  FEValuesCache<dim,spacedim> &fe_cache) const;
323 
324 
325  // auxiliary matrices ///////////////////////////////////////////////////////
326  // TODO aux_mtrices energy
327 
329  Scratch &scratch,
330  CopyPreconditioner &data,
331  std::vector<std::vector<double> > &local_residuals) const;
332 
334  Scratch &scratch,
335  CopyPreconditioner &data,
336  std::vector<std::vector<Sdouble> > &local_residuals) const;
337 
339  Scratch &scratch,
340  CopyPreconditioner &data) const;
341 
342  // virtual void set_aux_matrix_update_flags();
343 
344  UpdateFlags get_aux_matrix_flags(const unsigned int &i) const;
345 
346  const Table<2,DoFTools::Coupling> &get_aux_matrix_coupling(const unsigned int &i) const;
347  virtual unsigned int get_number_of_aux_matrices() const;
348 
349  std::vector<UpdateFlags> aux_matrix_update_flags;
350  std::vector<Table<2,DoFTools::Coupling> > aux_matrix_coupling;
352 
353 
354 
355 protected:
356 
357 
358 
359  mutable ParsedMappedFunctions<spacedim,n_components> forcing_terms; // on the volume
360  mutable ParsedMappedFunctions<spacedim,n_components> neumann_bcs;
361  mutable ParsedDirichletBCs<dim,spacedim,n_components> dirichlet_bcs;
362 
363  std::string str_diff_comp;
364  std::vector<unsigned int> _diff_comp;
365 
369  mutable const typename LAC::VectorType *solution;
370 
374  mutable typename LAC::VectorType old_solution;
375 
379  mutable const typename LAC::VectorType *solution_dot;
380 
384  mutable double t;
385 
389  mutable double old_t;
390 
391  mutable double alpha;
392  mutable unsigned int dofs_per_cell;
393  mutable unsigned int n_q_points;
394  mutable unsigned int n_face_q_points;
395 
396 
397 };
398 
399 template <int dim, int spacedim, int n_components, typename LAC>
400 template<typename Number>
401 void
405  Scratch &scratch,
406  CopySystem &data,
407  std::vector<Number> &local_residual) const
408 {
409 
410  Number dummy = 0.0;
411 
412  for (unsigned int face=0; face < GeometryInfo<dim>::faces_per_cell; ++face)
413  {
414  unsigned int face_id = cell->face(face)->boundary_id();
415  if (cell->face(face)->at_boundary() && neumann_bcs.acts_on_id(face_id))
416  {
417  this->reinit(dummy, cell, face, scratch);
418 
419  auto &fev = scratch.get_current_fe_values();
420  auto &q_points = scratch.get_quadrature_points();
421  auto &JxW = scratch.get_JxW_values();
422 
423  for (unsigned int q=0; q<q_points.size(); ++q)
424  {
425  Vector<double> T(n_components);
426  neumann_bcs.get_mapped_function(face_id)->vector_value(q_points[q], T);
427 
428  for (unsigned int i=0; i<local_residual.size(); ++i)
429  for (unsigned int c=0; c<n_components; ++c)
430  local_residual[i] -= T[c]*fev.shape_value_component(i,q,c)*JxW[q];
431 
432  }
433  break;
434  }
435  }
436 }
437 
438 template <int dim, int spacedim, int n_components, typename LAC>
439 template<typename Number>
440 void
443  Scratch &scratch,
444  CopySystem &data,
445  std::vector<Number> &local_residual) const
446 {
447  unsigned cell_id = cell->material_id();
448  if (forcing_terms.acts_on_id(cell_id))
449  {
450  Number dummy = 0.0;
451  this->reinit(dummy, cell, scratch);
452 
453  auto &fev = scratch.get_current_fe_values();
454  auto &q_points = scratch.get_quadrature_points();
455  auto &JxW = scratch.get_JxW_values();
456  for (unsigned int q=0; q<q_points.size(); ++q)
457  for (unsigned int i=0; i<local_residual.size(); ++i)
458  for (unsigned int c=0; c<n_components; ++c)
459  {
460  double B = forcing_terms.get_mapped_function(cell_id)->value(q_points[q],c);
461  local_residual[i] -= B*fev.shape_value_component(i,q,c)*JxW[q];
462  }
463  }
464 }
465 
466 
467 template <int dim, int spacedim, int n_components, typename LAC>
468 template<typename Number>
469 void
472  FEValuesCache<dim,spacedim> &fe_cache) const
473 {
474  fe_cache.reinit(cell);
475  fe_cache.cache_local_solution_vector("old_solution", this->old_solution, alpha);
476  fe_cache.cache_local_solution_vector("solution", *this->solution, alpha);
477  fe_cache.cache_local_solution_vector("solution_dot", *this->solution_dot, alpha);
478  this->fix_solution_dot_derivative(fe_cache, alpha);
479 }
480 
481 
482 template <int dim, int spacedim, int n_components, typename LAC>
483 template<typename Number>
484 void
487  const unsigned int face_no,
488  FEValuesCache<dim,spacedim> &fe_cache) const
489 {
490  fe_cache.reinit(cell, face_no);
491  fe_cache.cache_local_solution_vector("old_solution", this->old_solution, alpha);
492  fe_cache.cache_local_solution_vector("solution", *this->solution, alpha);
493  fe_cache.cache_local_solution_vector("solution_dot", *this->solution_dot, alpha);
494  this->fix_solution_dot_derivative(fe_cache, alpha);
495 }
496 
497 
498 
499 #endif
virtual void apply_dirichlet_bcs(const DoFHandler< dim, spacedim > &dof_handler, ConstraintMatrix &constraints) const
Applies Dirichlet boundary conditions.
ParsedMappedFunctions< spacedim, n_components > forcing_terms
Definition: old_interface.h:359
virtual void get_aux_matrix_residuals(const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, Scratch &scratch, CopyPreconditioner &data, std::vector< std::vector< double > > &local_residuals) const
void apply_neumann_bcs(const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, Scratch &scratch, CopySystem &data, std::vector< Number > &local_residual) const
Applies Neumann boundary conditions.
Definition: old_interface.h:403
virtual void get_system_energy(const typename DoFHandler< dim, spacedim >::active_cell_iterator &, Scratch &, CopySystem &, Sdouble &) const
Build the energy needed to get the system matrix in the case it is required two derivatives.
ParsedDirichletBCs< dim, spacedim, n_components > dirichlet_bcs
Definition: old_interface.h:361
virtual void get_system_residual(const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, Scratch &scratch, CopySystem &data, std::vector< Sdouble > &local_residual) const
Build the residual needed to get the system matrix in the case it is required two derivatives...
double old_t
Previous time step.
Definition: old_interface.h:389
const std::vector< unsigned int > get_differential_blocks() const
virtual ~Interface()
Definition: old_interface.h:64
virtual UpdateFlags get_face_flags() const
virtual void initialize_data(const typename LAC::VectorType &solution, const typename LAC::VectorType &solution_dot, const double t, const double alpha) const
Initialize all data required for the system.
ActiveSelector::active_cell_iterator active_cell_iterator
virtual void assemble_local_preconditioner(const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, Scratch &scratch, CopyPreconditioner &data) const
virtual UpdateFlags get_jacobian_flags() const
std::string str_diff_comp
Definition: old_interface.h:363
Interface.
Definition: old_interface.h:56
virtual void compute_system_operators(const DoFHandler< dim, spacedim > &, const typename LAC::BlockMatrix &, const typename LAC::BlockMatrix &, const std::vector< shared_ptr< typename LAC::BlockMatrix > >, LinearOperator< typename LAC::VectorType > &, LinearOperator< typename LAC::VectorType > &) const
Compute linear operators needed by the problem.
std::vector< unsigned int > _diff_comp
Definition: old_interface.h:364
void fix_solution_dot_derivative(FEValuesCache< dim, spacedim > &, double) const
virtual void assemble_local_aux_matrices(const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, Scratch &scratch, CopyPreconditioner &data) const
const LAC::VectorType * solution_dot
Time derivative solution vector evaluated at time t.
Definition: old_interface.h:379
virtual void parse_parameters_call_back()
const LAC::VectorType * solution
Solution vector evaluated at time t.
Definition: old_interface.h:369
virtual void get_preconditioner_energy(const typename DoFHandler< dim, spacedim >::active_cell_iterator &, Scratch &, CopySystem &, Sdouble &) const
Build the energy needed to get the preconditioner in the case it is required just one derivative...
unsigned int n_q_points
Definition: old_interface.h:393
virtual UpdateFlags get_residual_flags() const
virtual void postprocess_newly_created_triangulation(Triangulation< dim, spacedim > &tria) const
This function is used to modify triangulation using boundary_id or manifold_id.
UpdateFlags
virtual void assemble_local_system(const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, Scratch &scratch, CopySystem &data) const
LAC::VectorType old_solution
Solution vector evaluated at time t-dt.
Definition: old_interface.h:374
const Table< 2, DoFTools::Coupling > & get_aux_matrix_coupling(const unsigned int &i) const
void reinit(const Number &alpha, const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, FEValuesCache< dim, spacedim > &fe_cache) const
Definition: old_interface.h:470
virtual void set_time(const double &t) const
update time of all parsed mapped functions
UpdateFlags get_aux_matrix_flags(const unsigned int &i) const
std::vector< Table< 2, DoFTools::Coupling > > aux_matrix_coupling
Definition: old_interface.h:350
double alpha
Definition: old_interface.h:391
unsigned int n_face_q_points
Definition: old_interface.h:394
unsigned int dofs_per_cell
Definition: old_interface.h:392
virtual UpdateFlags get_jacobian_preconditioner_flags() const
void apply_forcing_terms(const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, Scratch &scratch, CopySystem &data, std::vector< Number > &local_residual) const
Applies CONSERVATIVE forcing terms.
Definition: old_interface.h:442
virtual void get_preconditioner_residual(const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, Scratch &scratch, CopyPreconditioner &data, std::vector< Sdouble > &local_residual) const
Build the residual needed to get the preconditioner matrix in the case two derivatives are required...
ParsedMappedFunctions< spacedim, n_components > neumann_bcs
Definition: old_interface.h:360
std::vector< UpdateFlags > aux_matrix_update_flags
Definition: old_interface.h:349
virtual unsigned int get_number_of_aux_matrices() const
virtual void declare_parameters(ParameterHandler &prm)
Interface(const std::string &name="", const std::string &default_fe="FE_Q(1)", const std::string &default_component_names="u", const std::string &default_coupling="", const std::string &default_preconditioner_coupling="", const std::string &default_differential_components="")
Definition: old_interface.h:66
double t
Current time step.
Definition: old_interface.h:384
virtual shared_ptr< Mapping< dim, spacedim > > get_mapping(const DoFHandler< dim, spacedim > &, const typename LAC::VectorType &) const