pi-DoMUS: Parallel Deal.II MUltiphysics Solver
scalar_reaction_diffusion_convection.h
Go to the documentation of this file.
1 #ifndef _pidoums_compressible_neo_hookean_h_
2 #define _pidoums_compressible_neo_hookean_h_
3 
4 #include "pde_system_interface.h"
5 
11 
12 //typedef LATrilinos LAC;
13 
14 template <int dim, int spacedim, typename LAC=LATrilinos>
15 class ScalarReactionDiffusionConvection : public PDESystemInterface<dim,spacedim, ScalarReactionDiffusionConvection<dim,spacedim,LAC>, LAC>
16 {
17 
18 public:
21 
23 
24  // interface with the PDESystemInterface :)
25 
26 
27  template <typename EnergyType, typename ResidualType>
29  FEValuesCache<dim,spacedim> &scratch,
30  std::vector<EnergyType> &energies,
31  std::vector<std::vector<ResidualType> > &local_residuals,
32  bool compute_only_system_terms) const;
33 
34 
36  const std::vector<shared_ptr<LATrilinos::BlockMatrix> >,
39 
40 private:
41  double nu;
42 
43  mutable shared_ptr<TrilinosWrappers::PreconditionJacobi> preconditioner;
44 
45  ParsedFunction<dim> convection;
46 
47 };
48 
49 template <int dim, int spacedim, typename LAC>
52  PDESystemInterface<dim,spacedim,ScalarReactionDiffusionConvection<dim,spacedim,LAC>, LAC >("Scalar Reaction Diffusion Convection",
53  1,1,
54  "FE_Q(2)",
55  "u", "1"),
56  convection("Convection parameter", dim, "cos(pi*x)*sin(pi*y); -sin(pi*x)*cos(pi*y)")
57 {}
58 
59 
60 template <int dim, int spacedim, typename LAC>
62 {
64  this->add_parameter(prm, &nu, "Diffusion coefficient", "1.0", Patterns::Double(0.0));
65 }
66 
67 
68 template <int dim, int spacedim, typename LAC>
69 template <typename EnergyType, typename ResidualType>
70 void
73  FEValuesCache<dim,spacedim> &fe_cache,
74  std::vector<EnergyType> &,
75  std::vector<std::vector<ResidualType> > &residuals,
76  bool ) const
77 {
78  const FEValuesExtractors::Scalar concentration(0);
79 
80  ResidualType alpha = this->alpha;
81  // Initialize the various solutions, derivatives, etc with the right type for
82  // alpha.
83  this->reinit (alpha, cell, fe_cache);
84 
85  auto &us = fe_cache.get_values("solution", "u", concentration, alpha);
86  auto &uts = fe_cache.get_values("solution_dot", "ut", concentration, alpha);
87  auto &gradus = fe_cache.get_gradients("solution", "gradu", concentration, alpha);
88 
89  const unsigned int n_q_points = us.size();
90  auto &JxW = fe_cache.get_JxW_values();
91 
92  std::vector<Vector<double> > convection_values(n_q_points, Vector<double>(dim));
93 
94  auto &fev = fe_cache.get_current_fe_values();
95  convection.vector_value_list(fev.get_quadrature_points(), convection_values);
96 
97  for (unsigned int q=0; q<n_q_points; ++q)
98  {
99 
100  auto &u = us[q];
101  auto &ut = uts[q];
102 
103  auto &gradu = gradus[q];
104 
105  auto &b = convection_values[q];
106  for (unsigned int i=0; i<residuals[0].size(); ++i)
107  {
108 
109  // test functions:
110  auto v = fev[concentration].value(i,q);
111  auto gradv = fev[concentration].gradient(i,q);
112 
113  residuals[0][i] += (ut*v +
114  nu*(gradu*gradv)
115  )*JxW[q];
116 
117  for (unsigned int d=0; d<dim; ++d)
118  residuals[0][i] += (u*gradu[d]*b[d]*v)*JxW[q];
119  }
120  }
121 }
122 
123 
124 
125 template <int dim, int spacedim, typename LAC>
126 void
128  const std::vector<shared_ptr<LATrilinos::BlockMatrix> > matrices,
131 {
132 
133  preconditioner.reset (new TrilinosWrappers::PreconditionJacobi());
134  preconditioner->initialize(matrices[0]->block(0,0));
135 
136  auto P = linear_operator<LATrilinos::VectorType::BlockType>(matrices[0]->block(0,0));
137 
138  auto A = linear_operator<LATrilinos::VectorType::BlockType>( matrices[0]->block(0,0) );
139 
140  static ReductionControl solver_control_pre(5000, 1e-8);
141  static SolverGMRES<LATrilinos::VectorType::BlockType> solver_GMRES(solver_control_pre);
142  auto P_inv = inverse_operator( P, solver_GMRES, *preconditioner);
143 
144  auto P00 = P_inv;
145 
146  // ASSEMBLE THE PROBLEM:
147  system_op = block_operator<1, 1, LATrilinos::VectorType>({{
148  {{ A }}
149  }
150  });
151 
152  prec_op = block_operator<1, 1, LATrilinos::VectorType>({{
153  {{ P00 }} ,
154  }
155  });
156 }
157 #endif
Definition: scalar_reaction_diffusion_convection.h:15
Definition: lac_type.h:33
void declare_parameters(ParameterHandler &prm)
Definition: scalar_reaction_diffusion_convection.h:61
ActiveSelector::active_cell_iterator active_cell_iterator
This is the class that users should derive from.
Definition: pde_system_interface.h:46
void compute_system_operators(const DoFHandler< dim, spacedim > &, const std::vector< shared_ptr< LATrilinos::BlockMatrix > >, LinearOperator< LATrilinos::VectorType > &, LinearOperator< LATrilinos::VectorType > &) const
Definition: scalar_reaction_diffusion_convection.h:127
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)
~ScalarReactionDiffusionConvection()
Definition: scalar_reaction_diffusion_convection.h:19
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
Definition: scalar_reaction_diffusion_convection.h:72
ScalarReactionDiffusionConvection()
Definition: scalar_reaction_diffusion_convection.h:51