pi-DoMUS: Parallel Deal.II MUltiphysics Solver
free_swelling_three_fields.h
Go to the documentation of this file.
1 
5 #ifndef _free_swelling_three_fields_h_
6 #define _free_swelling_three_fields_h_
7 
9 #include <deal2lkit/parsed_function.h>
10 
11 
12 #include <deal.II/fe/fe_values.h>
17 
21 
22 #include <deal.II/lac/solver_cg.h>
24 
25 #include "lac/lac_type.h"
26 
27 
28 typedef LADealII LAC;
29 // typedef LATrilinos LAC; //
30 
31 
32 template <int dim, int spacedim>
33 class FreeSwellingThreeFields : public ConservativeInterface<dim,spacedim,dim+2, FreeSwellingThreeFields<dim,spacedim>, LAC>
34 {
35  typedef FEValuesCache<dim,spacedim> Scratch;
36  typedef Assembly::CopyData::piDoMUSPreconditioner<dim,spacedim> CopyPreconditioner;
37  typedef Assembly::CopyData::piDoMUSSystem<dim,spacedim> CopySystem;
39 
40 public:
41 
42  /* specific and useful functions for this very problem */
44 
46 
49 
50 
51  /* these functions MUST have the follwowing names
52  * because they are called by the ConservativeInterface class
53  */
54 
55  template<typename Number>
57  Scratch &,
58  CopyPreconditioner &,
59  Number &energy) const;
60 
61  template<typename Number>
63  Scratch &,
64  CopySystem &,
65  Number &energy) const;
66 //
67 // void compute_system_operators(const DoFHandler<dim,spacedim> &,
68 // const TrilinosWrappers::BlockSparseMatrix &,
69 // const TrilinosWrappers::BlockSparseMatrix &,
70 // LinearOperator<VEC> &,
71 // LinearOperator<VEC> &) const;
72 
73 private:
74  double T;
75  double Omega;
76  double G;
77  double chi;
78  double l0;
79 
80  double mu;
81  double mu0;
82  double l02;
83  double l03;
84  double l0_3;
85  double l0_6;
86  const double R=8.314;
87 
88 
89 // mutable shared_ptr<TrilinosWrappers::PreconditionJacobi> U_prec;
90 // mutable shared_ptr<TrilinosWrappers::PreconditionJacobi> p_prec;
91 // mutable shared_ptr<TrilinosWrappers::PreconditionJacobi> c_prec;
92 
93 };
94 
95 template <int dim, int spacedim>
97  ConservativeInterface<dim,spacedim,dim+2,FreeSwellingThreeFields<dim,spacedim>, LAC>("Free Swelling Three Fields",
98  "FESystem[FE_Q(2)^d-FE_Q(1)-FE_Q(2)]",
99  "u,u,u,p,c", "1,1,0;1,0,1;0,1,1", "1,0,0;0,1,0;0,0,1","1,0,0")
100 {};
101 
102 
103 template <int dim, int spacedim>
104 template<typename Number>
106  Scratch &fe_cache,
107  CopyPreconditioner &data,
108  Number &energy) const
109 {
110  Number alpha = this->alpha;
111  this->reinit(alpha, cell, fe_cache);
112 
113  const FEValuesExtractors::Vector displacement(0);
114  auto &us = fe_cache.get_values("solution", "u", displacement, alpha);
115  auto &us_dot = fe_cache.get_values("solution_dot", "u", displacement, alpha);
116 
117  const FEValuesExtractors::Scalar pressure(dim);
118  const FEValuesExtractors::Scalar concentration(dim+1);
119 
120  auto &ps = fe_cache.get_values("solution", "p", pressure, alpha);
121  auto &cs = fe_cache.get_values("solution", "c", concentration, alpha);
122 
123  const unsigned int n_q_points = us.size();
124 
125  auto &JxW = fe_cache.get_JxW_values();
126  energy = 0;
127  for (unsigned int q=0; q<n_q_points; ++q)
128  {
129  const Tensor <1, dim, Number> &u = us[q];
130  const Tensor <1, dim, Number> &u_dot = us_dot[q];
131  auto &c = cs[q];
132  auto &p = ps[q];
133 
134  energy += 0.5*(u*u
135  +p*p
136  +c*c)*JxW[q];
137  }
138 }
139 
140 template <int dim, int spacedim>
141 template<typename Number>
143  Scratch &fe_cache,
144  CopySystem &data,
145  Number &energy) const
146 {
147  Number alpha = this->alpha;
148  this->reinit(alpha, cell, fe_cache);
149 
150  const FEValuesExtractors::Vector displacement(0);
151  auto &us = fe_cache.get_values("solution", "u", displacement, alpha);
152  auto &us_dot = fe_cache.get_values("solution_dot", "u_dot", displacement, alpha);
153  auto &Fs = fe_cache.get_deformation_gradients("solution", "Fu", displacement, alpha);
154 
155  const FEValuesExtractors::Scalar pressure(dim);
156  const FEValuesExtractors::Scalar concentration(dim+1);
157 
158  auto &ps = fe_cache.get_values("solution", "p", pressure, alpha);
159  auto &cs = fe_cache.get_values("solution", "c", concentration, alpha);
160 
161  const unsigned int n_q_points = us.size();
162 
163  auto &JxW = fe_cache.get_JxW_values();
164  energy = 0;
165  for (unsigned int q=0; q<n_q_points; ++q)
166  {
167 
168  auto &u = us[q];
169  const Tensor <1, dim, Number> &u_dot = us_dot[q];
170  const Tensor <2, dim, Number> &F = Fs[q];
171  const Tensor<2, dim, Number> C = transpose(F)*F;
172  auto &c = cs[q];
173  auto &p = ps[q];
174 
175  Number I = trace(C);
176  Number J = determinant(F);
177 
178 
179  Number psi = ( 0.5*G*l0_3*(l02*I - dim)
180 
181  + (l0_3*R*T/Omega)*((Omega*l03*c)*std::log((Omega*l03*c)/(1.+Omega*l03*c))
182  + chi*((Omega*l03*c)/(1.+Omega*l03*c)) )
183 
184  - (mu0)*c - p*(J-l0_3-Omega*c)) ;
185 
186  energy += (u*u_dot + psi)*JxW[q];
187  }
188 
189 }
190 
191 
192 template <int dim, int spacedim>
194 {
196  this->add_parameter(prm, &T, "T", "298.0", Patterns::Double(0.0));
197  this->add_parameter(prm, &Omega, "Omega", "1e-5", Patterns::Double(0.0));
198  this->add_parameter(prm, &chi, "chi", "0.1", Patterns::Double(0.0));
199  this->add_parameter(prm, &l0, "l0", "1.5", Patterns::Double(1.0));
200  this->add_parameter(prm, &G, "G", "10e3", Patterns::Double(0.0));
201  this->add_parameter(prm, &mu, "mu", "-1.8e-22", Patterns::Double(-1000.0));
202 }
203 
204 template <int dim, int spacedim>
206 {
208  l02 = l0*l0;
209  l03 = l02*l0;
210  l0_3 = 1./l03;
211  l0_6 = 1./(l03*l03);
212 
213  mu0 = R*T*(std::log((l03-1.)/l03) + l0_3 + chi*l0_6) + G*Omega/l0;
214 }
215 //
216 //template <int dim, int spacedim>
217 //void
218 //FreeSwellingThreeFields<dim,spacedim>::compute_system_operators(const DoFHandler<dim,spacedim> &dh,
219 // const TrilinosWrappers::BlockSparseMatrix &matrix,
220 // const TrilinosWrappers::BlockSparseMatrix &preconditioner_matrix,
221 // LinearOperator<VEC> &system_op,
222 // LinearOperator<VEC> &prec_op) const
223 //{
224 //
225 // std::vector<std::vector<bool> > constant_modes;
226 // FEValuesExtractors::Vector velocity_components(0);
227 // DoFTools::extract_constant_modes (dh, dh.get_fe().component_mask(velocity_components),
228 // constant_modes);
229 //
230 // p_prec.reset (new TrilinosWrappers::PreconditionJacobi());
231 // c_prec.reset (new TrilinosWrappers::PreconditionJacobi());
232 // U_prec.reset (new TrilinosWrappers::PreconditionJacobi());
233 //
241 //
242 // U_prec->initialize (preconditioner_matrix.block(0,0));
243 // p_prec->initialize (preconditioner_matrix.block(1,1));
244 // c_prec->initialize (preconditioner_matrix.block(2,2));
245 //
246 //
247 // // SYSTEM MATRIX:
248 // auto A = linear_operator< TrilinosWrappers::MPI::Vector >( matrix.block(0,0) );
249 // auto Bt = linear_operator< TrilinosWrappers::MPI::Vector >( matrix.block(0,1) );
250 // auto Z02 = 0*linear_operator< TrilinosWrappers::MPI::Vector >( matrix.block(0,2) );
251 //
252 // auto B = linear_operator< TrilinosWrappers::MPI::Vector >( matrix.block(1,0) );
253 // auto Z11 = 0*linear_operator< TrilinosWrappers::MPI::Vector >( matrix.block(1,1) );
254 // auto C = linear_operator< TrilinosWrappers::MPI::Vector >( matrix.block(1,2) );
255 //
256 // auto Z20 = 0*linear_operator< TrilinosWrappers::MPI::Vector >( matrix.block(2,0) );
257 // auto D = linear_operator< TrilinosWrappers::MPI::Vector >( matrix.block(2,1) );
258 // auto E = linear_operator< TrilinosWrappers::MPI::Vector >( matrix.block(2,2) );
259 //
260 // auto P0 = linear_operator< TrilinosWrappers::MPI::Vector >(matrix.block(0,0));
261 // auto P1 = linear_operator< TrilinosWrappers::MPI::Vector >(preconditioner_matrix.block(1,1));
262 // auto P2 = linear_operator< TrilinosWrappers::MPI::Vector >(matrix.block(2,2));
263 //
264 //
265 // static ReductionControl solver_control_pre(5000, 1e-7);
266 // static SolverCG<TrilinosWrappers::MPI::Vector> solver_CG(solver_control_pre);
267 //
268 // auto P0_inv = inverse_operator( P0, solver_CG, *U_prec);
269 // auto P1_inv = inverse_operator( P1, solver_CG, *p_prec);
270 // auto P2_inv = inverse_operator( P2, solver_CG, *c_prec);
271 //
272 //
276 //
277 //
278 // // ASSEMBLE THE PROBLEM:
279 // const std::array<std::array<LinearOperator<TrilinosWrappers::MPI::Vector>, 3 >, 3 > matrix_array = {{
280 // {{ A, Bt , Z02 }},
281 // {{ B, Z11 , C }},
282 // {{ Z20, D , E }}
283 // }
284 // };
285 //
286 // system_op = block_operator<3, 3, VEC >(matrix_array);
287 //
288 // const std::array<LinearOperator<TrilinosWrappers::MPI::Vector>, 3 > diagonal_array = {{ P0_inv, P1_inv, P2_inv }};
289 //
290 // // system_op = linear_operator<VEC, VEC>(matrix);
291 //
292 // prec_op = block_back_substitution<3, VEC>(matrix_array, diagonal_array);
293 //
294 //}
295 
296 
297 template class FreeSwellingThreeFields <3,3>;
298 
299 #endif
300 
Definition: conservative.h:20
~FreeSwellingThreeFields()
Definition: free_swelling_three_fields.h:43
Definition: lac_type.h:33
FreeSwellingThreeFields()
Definition: free_swelling_three_fields.h:96
void parse_parameters_call_back()
Definition: free_swelling_three_fields.h:205
ActiveSelector::active_cell_iterator active_cell_iterator
Definition: free_swelling_three_fields.h:33
void system_energy(const typename DoFHandler< dim, spacedim >::active_cell_iterator &, Scratch &, CopySystem &, Number &energy) const
Definition: free_swelling_three_fields.h:142
void preconditioner_energy(const typename DoFHandler< dim, spacedim >::active_cell_iterator &, Scratch &, CopyPreconditioner &, Number &energy) const
Definition: free_swelling_three_fields.h:105
LADealII LAC
Definition: free_swelling_three_fields.h:28
void declare_parameters(ParameterHandler &prm)
Definition: free_swelling_three_fields.h:193