pi-DoMUS: Parallel Deal.II MUltiphysics Solver
template.h
Go to the documentation of this file.
1 #ifndef _pidoums_template_h_
2 #define _pidoums_template_h_
3 
4 #include "pde_system_interface.h"
5 
6 template <int dim, int spacedim, typename LAC>
7 class ProblemTemplate : public PDESystemInterface<dim,spacedim,ProblemTemplate<dim,spacedim,LAC> LAC>
8 {
9 public:
11  ProblemTemplate ();
12 
15 
16  // interface with the PDESystemInterface :)
17  template <typename EnergyType, typename ResidualType>
19  FEValuesCache<dim,spacedim> &scratch,
20  std::vector<EnergyType> &energies,
21  std::vector<std::vector<ResidualType> > &local_residuals,
22  bool compute_only_system_terms) const;
23 
24 
25  // this function is needed only for the iterative solver
27  const std::vector<shared_ptr<LATrilinos::BlockMatrix> >,
30 
31 
32 
34 
35  /* Coupling between the blocks of the finite elements in the system: */
36  /* 0: No coupling */
37  /* 1: Full coupling */
38  /* 2: Coupling only on faces */
39  /* If your matrices are fully coupled (as in this case), you can skip the */
40  /* implementation because it is already set by default. */
41 
42  // void set_matrix_couplings (std::vector<std::string> > &couplings) const;
43 
44 
45  /* this function allows to define the update_flags. */
46  /* by default they are */
47  /* (update_quadrature_points | */
48  /* update_JxW_values | */
49  /* update_values | */
50  /* update_gradients) */
51 
52  // UpdateFlags get_cell_update_flags() const;
53 
54  /* this function allows to set particular update_flags on the face */
55  /* by default it returns */
56  /* (update_values | update_quadrature_points | */
57  /* update_normal_vectors | update_JxW_values); */
58 
59  // UpdateFlags get_face_update_flags() const;
60 
61  /* this function defines Mapping used when Dirichlet boundary */
62  /* conditions are applied, when the Initial solution is */
63  /* interpolated, when the solution vector is stored in vtu format */
64  /* and when the the error_from_exact is performed. By default it */
65  /* returns StaticMappingQ1<dim,spacedim>::mapping; */
66 
67  // const Mapping<dim,spacedim> & get_mapping () const;
68 
69 private:
70 // additional variables such as preconditioners
71  mutable shared_ptr<TrilinosWrappers::PreconditionJacobi> preconditioner;
72 
73 };
74 
76 
77 template <int dim, int spacedim, typename LAC>
79  PDESystemInterface<dim,spacedim,ProblemTemplate<dim,spacedim,LAC>,LAC>
80  (\* section name in parameter file *\ "ProblemTemplate Parameters",
81  \* n componenets *\ dim,
82  \* n matrices *\ 2,
83  \* finite element type *\ "FESystem[FE_Q(1)^d]",
84  \* component names *\ "u,u,u",
85  \* differential (1) and algebraic components (0) needed by IDA *\ "1")
86 {}
87 
89 template <int dim, int spacedim, typename LAC>
91 {
93 
94  this->add_parameter(....);
95 }
96 
97 template <int dim, int spacedim, typename LAC>
99 {
100  // some operations with the just parsed parameters
101  ... ;
102 }
103 
104 
106 
107 template <int dim, int spacedim, typename LAC>
108 template <typename EnergyType, typename ResidualType>
109 void
112  FEValuesCache<dim,spacedim> &fe_cache,
113  std::vector<EnergyType> &energies,
114  std::vector<std::vector<ResidualType> > &local_residuals,
115  bool compute_only_system_matrix) const
116 {
117 
118  const FEValuesExtractors::Vector displacement(0);
119 
121  //
122  EnergyType et = 0; // dummy number to define the type of variables
123  this->reinit (et, cell, fe_cache);
124  auto &Fs = fe_cache.get_deformation_gradients("solution", "Fu", displacement, et);
125 
127  //
128  ResidualType rt = 0;
129  this->reinit (rt, cell, fe_cache);
130  auto &us = fe_cache.get_values("solution", "u", displacement, rt);
131 
132 
134  //
135  auto &fev = fe_cache.get_current_fe_values();
136  const unsigned int n_q_points = us.size();
137  auto &JxW = fe_cache.get_JxW_values();
138 
139 
140  for (unsigned int q=0; q<n_q_points; ++q)
141  {
143  auto &F = Fs[q];
144  auto C = transpose(F)*F;
145 
146  auto Ic = trace(C);
147  auto J = determinant(F);
148  auto lnJ = std::log (J);
149 
150  EnergyType psi = (mu/2.)*(Ic-dim) - mu*lnJ + (lambda/2.)*(lnJ)*(lnJ);
151 
152  energies[0] += (psi)*JxW[q];
153 
155  auto &u = us[q];
156  for (unsigned int i=0; i<local_residuals[0].size(); ++i)
157  {
158  auto v = fev[displacement] .value(i,q); // test function
159 
160  local_residuals[0] -= 0.1*v*u;
161 
162  // matrix[0] is assumed to be the system matrix other
163  // matrices are either preconditioner or auxiliary matrices
164  // needed to build it.
165  //
166  // if this function is called to evalute the system residual
167  // we do not need to assemble them so we guard them
168  if (!compute_only_system_matrix)
169  local_residuals[1] += v*u;
170  }
171  }
172 
173 }
174 
175 
176 template <int dim, int spacedim, typename LAC>
177 void
179  const std::vector<shared_ptr<LATrilinos::BlockMatrix> > matrices,
182 {
183 
184  preconditioner.reset (new TrilinosWrappers::PreconditionJacobi());
185  preconditioner->initialize(matrices[1]->block(0,0));
186  auto P = linear_operator<LATrilinos::VectorType::BlockType>(matrices[1]->block(0,0));
187 
188  auto A = linear_operator<LATrilinos::VectorType::BlockType>( matrices[0]->block(0,0) );
189 
190  static ReductionControl solver_control_pre(5000, 1e-4);
191  static SolverCG<LATrilinos::VectorType::BlockType> solver_CG(solver_control_pre);
192  auto P_inv = inverse_operator( P, solver_CG, *preconditioner);
193 
194  auto P00 = P_inv;
195 
196  // ASSEMBLE THE PROBLEM:
197  system_op = block_operator<1, 1, LATrilinos::VectorType>({{
198  {{ A }}
199  }
200  });
201 
202  prec_op = block_operator<1, 1, LATrilinos::VectorType>({{
203  {{ P00}} ,
204  }
205  });
206 }
207 
208 
209 
210 #endif
Definition: lac_type.h:33
Definition: template.h:7
ActiveSelector::active_cell_iterator active_cell_iterator
This is the class that users should derive from.
Definition: pde_system_interface.h:46
ProblemTemplate()
Definition: template.h:78
LinearOperator< typename Solver::vector_type, typename Solver::vector_type > inverse_operator(const LinearOperator< typename Solver::vector_type, typename Solver::vector_type > &op, Solver &solver, const Preconditioner &preconditioner)
void energies_and_residuals(const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, FEValuesCache< dim, spacedim > &scratch, std::vector< EnergyType > &energies, std::vector< std::vector< ResidualType > > &local_residuals, bool compute_only_system_terms) const
void parse_parameters_call_back()
void declare_parameters(ParameterHandler &prm)
Definition: template.h:90
void compute_system_operators(const DoFHandler< dim, spacedim > &, const std::vector< shared_ptr< LATrilinos::BlockMatrix > >, LinearOperator< LATrilinos::VectorType > &, LinearOperator< LATrilinos::VectorType > &) const
Definition: template.h:178
~ProblemTemplate()
Definition: template.h:10
void parse_parameters_call_back()
Definition: compressible_neo_hookean.h:71