ExaDG
Loading...
Searching...
No Matches
mapping_deformation_structure.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef EXADG_GRID_MAPPING_DEFORMATION_STRUCTURE_H_
23#define EXADG_GRID_MAPPING_DEFORMATION_STRUCTURE_H_
24
25// deal.II
26#include <deal.II/base/timer.h>
27
28// ExaDG
29#include <exadg/grid/mapping_deformation_base.h>
30#include <exadg/structure/spatial_discretization/operator.h>
31#include <exadg/utilities/print_solver_results.h>
32
33namespace ExaDG
34{
35namespace Structure
36{
42template<int dim, typename Number>
43class DeformedMapping : public DeformedMappingBase<dim, Number>
44{
45public:
46 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
47
52 std::shared_ptr<Grid<dim> const> grid,
53 std::shared_ptr<dealii::Mapping<dim> const> mapping_undeformed,
54 std::shared_ptr<MultigridMappings<dim, Number>> const multigrid_mappings_undeformed,
55 std::shared_ptr<BoundaryDescriptor<dim> const> boundary_descriptor,
56 std::shared_ptr<FieldFunctions<dim> const> field_functions,
57 std::shared_ptr<MaterialDescriptor const> material_descriptor,
58 Parameters const & param,
59 std::string const & field,
60 bool const setup_scalar_field,
61 MPI_Comm const & mpi_comm)
62 : DeformedMappingBase<dim, Number>(mapping_undeformed, param.degree, *grid->triangulation),
63 param(param),
64 pcout(std::cout, dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0),
65 iterations({0, {0, 0}})
66 {
67 // initialize PDE operator
68 pde_operator = std::make_shared<Operator<dim, Number>>(grid,
70 multigrid_mappings_undeformed,
71 boundary_descriptor,
72 field_functions,
73 material_descriptor,
74 param,
75 field,
76 setup_scalar_field,
77 mpi_comm);
78
79 // setup PDE operator and solver
80 pde_operator->setup();
81
82 // finally, initialize dof vector
83 pde_operator->initialize_dof_vector(displacement);
84 }
85
86 std::shared_ptr<Operator<dim, Number> const>
87 get_pde_operator() const
88 {
89 return pde_operator;
90 }
91
92 dealii::MatrixFree<dim, Number> const &
93 get_matrix_free() const
94 {
95 return *pde_operator->get_matrix_free();
96 }
97
101 void
102 update(double const time,
103 bool const print_solver_info,
104 types::time_step time_step_number) override
105 {
106 dealii::Timer timer;
107 timer.restart();
108
109 if(param.large_deformation) // nonlinear problem
110 {
111 VectorType const_vector;
112
113 bool const update_preconditioner =
114 this->param.update_preconditioner &&
115 time_step_number % this->param.update_preconditioner_every_time_steps == 0;
116
117 auto const iter = pde_operator->solve_nonlinear(displacement,
118 const_vector,
119 0.0 /* no acceleration term */,
120 0.0 /* no damping term */,
121 time,
122 update_preconditioner);
123
124 iterations.first += 1;
125 std::get<0>(iterations.second) += std::get<0>(iter);
126 std::get<1>(iterations.second) += std::get<1>(iter);
127
128 if(print_solver_info)
129 {
130 this->pcout << std::endl << "Solve moving mesh problem (nonlinear elasticity):";
131 print_solver_info_nonlinear(pcout, std::get<0>(iter), std::get<1>(iter), timer.wall_time());
132 }
133 }
134 else // linear problem
135 {
136 // calculate right-hand side vector
137 VectorType rhs;
138 pde_operator->initialize_dof_vector(rhs);
139 pde_operator->rhs(rhs, time);
140
141 auto const iter = pde_operator->solve_linear(displacement,
142 rhs,
143 0.0 /* no acceleration term */,
144 0.0 /* no damping term */,
145 time,
146 false /* do not update preconditioner */);
147
148 iterations.first += 1;
149 std::get<1>(iterations.second) += iter;
150
151 if(print_solver_info)
152 {
153 this->pcout << std::endl << "Solve moving mesh problem (linear elasticity):";
154 print_solver_info_linear(pcout, iter, timer.wall_time());
155 }
156 }
157
158 this->initialize_mapping_from_dof_vector(this->mapping_undeformed,
159 displacement,
160 pde_operator->get_dof_handler());
161 }
162
166 void
167 print_iterations() const override
168 {
169 std::vector<std::string> names;
170 std::vector<double> iterations_avg;
171
172 if(param.large_deformation)
173 {
174 names = {"Nonlinear iterations",
175 "Linear iterations (accumulated)",
176 "Linear iterations (per nonlinear it.)"};
177
178 iterations_avg.resize(3);
179 iterations_avg[0] =
180 (double)std::get<0>(iterations.second) / std::max(1., (double)iterations.first);
181 iterations_avg[1] =
182 (double)std::get<1>(iterations.second) / std::max(1., (double)iterations.first);
183 if(iterations_avg[0] > std::numeric_limits<double>::min())
184 iterations_avg[2] = iterations_avg[1] / iterations_avg[0];
185 else
186 iterations_avg[2] = iterations_avg[1];
187 }
188 else // linear
189 {
190 names = {"Linear iterations"};
191 iterations_avg.resize(1);
192 iterations_avg[0] =
193 (double)std::get<1>(iterations.second) / std::max(1., (double)iterations.first);
194 }
195
196 print_list_of_iterations(pcout, names, iterations_avg);
197 }
198
199private:
200 // matrix-free
201 std::shared_ptr<MatrixFreeData<dim, Number>> matrix_free_data;
202 std::shared_ptr<dealii::MatrixFree<dim, Number>> matrix_free;
203
204 // PDE operator
205 std::shared_ptr<Operator<dim, Number>> pde_operator;
206
207 Parameters const & param;
208
209 // store solution of previous time step / iteration so that a good initial
210 // guess is available in the next step, easing convergence or reducing computational
211 // costs by allowing larger tolerances
212 VectorType displacement;
213
214 dealii::ConditionalOStream pcout;
215
216 std::pair<
217 unsigned int /* calls */,
218 std::tuple<unsigned long long, unsigned long long> /* iteration counts {Newton, linear}*/>
219 iterations;
220};
221
222} // namespace Structure
223} // namespace ExaDG
224
225#endif /* EXADG_GRID_MAPPING_DEFORMATION_STRUCTURE_H_ */
std::shared_ptr< dealii::Mapping< dim > const > mapping_undeformed
Definition mapping_deformation_base.h:106
DeformedMappingBase(std::shared_ptr< dealii::Mapping< dim > const > mapping_undeformed, unsigned int const mapping_degree_deformed, dealii::Triangulation< dim > const &triangulation)
Definition mapping_deformation_base.h:60
Definition grid.h:40
void initialize_mapping_from_dof_vector(std::shared_ptr< dealii::Mapping< dim > const > mapping, VectorType const &displacement_vector, dealii::DoFHandler< dim > const &dof_handler)
Definition mapping_dof_vector.h:212
Definition grid.h:84
void print_iterations() const override
Definition mapping_deformation_structure.h:167
void update(double const time, bool const print_solver_info, types::time_step time_step_number) override
Definition mapping_deformation_structure.h:102
DeformedMapping(std::shared_ptr< Grid< dim > const > grid, std::shared_ptr< dealii::Mapping< dim > const > mapping_undeformed, std::shared_ptr< MultigridMappings< dim, Number > > const multigrid_mappings_undeformed, std::shared_ptr< BoundaryDescriptor< dim > const > boundary_descriptor, std::shared_ptr< FieldFunctions< dim > const > field_functions, std::shared_ptr< MaterialDescriptor const > material_descriptor, Parameters const &param, std::string const &field, bool const setup_scalar_field, MPI_Comm const &mpi_comm)
Definition mapping_deformation_structure.h:51
Definition parameters.h:41
Definition interpolate.h:34
Definition driver.cpp:33
Definition boundary_descriptor.h:48
Definition field_functions.h:32