OGS
TH2MProcess.cpp
Go to the documentation of this file.
1
11#include "TH2MProcess.h"
12
13#include <cassert>
14
16#include "MaterialLib/SolidModels/MechanicsBase.h" // for the instantiation of process data
22#include "ProcessLib/Process.h"
27#include "TH2MProcessData.h"
28
29namespace ProcessLib
30{
31namespace TH2M
32{
33template <int DisplacementDim>
35 std::string name,
36 MeshLib::Mesh& mesh,
37 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
38 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
39 unsigned const integration_order,
40 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
41 process_variables,
43 SecondaryVariableCollection&& secondary_variables,
44 bool const use_monolithic_scheme)
45 : Process(std::move(name), mesh, std::move(jacobian_assembler), parameters,
46 integration_order, std::move(process_variables),
47 std::move(secondary_variables), use_monolithic_scheme),
49 _process_data(std::move(process_data))
50{
52 DisplacementDim>(
54 _integration_point_writer, integration_order, local_assemblers_);
55}
56
57template <int DisplacementDim>
59{
60 return false;
61}
62
63template <int DisplacementDim>
66 const int process_id) const
67{
68 // For the monolithic scheme or the M process (deformation) in the staggered
69 // scheme.
70 if (_use_monolithic_scheme || process_id == deformation_process_id)
71 {
72 auto const& l = *_local_to_global_index_map;
73 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
74 &l.getGhostIndices(), &this->_sparsity_pattern};
75 }
76
77 // For staggered scheme and T or H process (pressure).
78 auto const& l = *_local_to_global_index_map_with_base_nodes;
79 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
80 &l.getGhostIndices(), &_sparsity_pattern_with_linear_element};
81}
82
83template <int DisplacementDim>
85{
86 // Create single component dof in every of the mesh's nodes.
87 _mesh_subset_all_nodes = std::make_unique<MeshLib::MeshSubset>(
88 _mesh, _mesh.getNodes(), _process_data.use_TaylorHood_elements);
89 // Create single component dof in the mesh's base nodes.
90 _base_nodes = MeshLib::getBaseNodes(_mesh.getElements());
91 _mesh_subset_base_nodes = std::make_unique<MeshLib::MeshSubset>(
92 _mesh, _base_nodes, _process_data.use_TaylorHood_elements);
93
94 // TODO move the two data members somewhere else.
95 // for extrapolation of secondary variables of stress or strain
96 std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component{
97 *_mesh_subset_all_nodes};
98 _local_to_global_index_map_single_component =
99 std::make_unique<NumLib::LocalToGlobalIndexMap>(
100 std::move(all_mesh_subsets_single_component),
101 // by location order is needed for output
103
104 if (_use_monolithic_scheme)
105 {
106 // For gas pressure, which is the first
107 std::vector<MeshLib::MeshSubset> all_mesh_subsets{
108 *_mesh_subset_base_nodes};
109
110 // For capillary pressure, which is the second
111 all_mesh_subsets.push_back(*_mesh_subset_base_nodes);
112
113 // For temperature, which is the third
114 all_mesh_subsets.push_back(*_mesh_subset_base_nodes);
115
116 // For displacement.
117 std::generate_n(
118 std::back_inserter(all_mesh_subsets),
119 getProcessVariables(monolithic_process_id)[deformation_process_id]
120 .get()
121 .getNumberOfGlobalComponents(),
122 [&]() { return *_mesh_subset_all_nodes; });
123
124 std::vector<int> const vec_n_components{
125 n_gas_pressure_components, n_capillary_pressure_components,
126 n_temperature_components, n_displacement_components};
127
128 _local_to_global_index_map =
129 std::make_unique<NumLib::LocalToGlobalIndexMap>(
130 std::move(all_mesh_subsets), vec_n_components,
132 assert(_local_to_global_index_map);
133 }
134 else
135 {
136 OGS_FATAL("A Staggered version of TH2M is not implemented.");
137 }
138}
139
140template <int DisplacementDim>
142 NumLib::LocalToGlobalIndexMap const& dof_table,
143 MeshLib::Mesh const& mesh,
144 unsigned const integration_order)
145{
146 createLocalAssemblers<DisplacementDim>(
147 mesh.getElements(), dof_table, local_assemblers_,
148 NumLib::IntegrationOrder{integration_order}, mesh.isAxiallySymmetric(),
149 _process_data);
150
151 auto add_secondary_variable = [&](std::string const& name,
152 int const num_components,
153 auto get_ip_values_function)
154 {
155 _secondary_variables.addSecondaryVariable(
156 name,
157 makeExtrapolator(num_components, getExtrapolator(),
158 local_assemblers_,
159 std::move(get_ip_values_function)));
160 };
161
162 ProcessLib::Reflection::addReflectedSecondaryVariables<DisplacementDim>(
164 _secondary_variables, getExtrapolator(), local_assemblers_);
165
166 //
167 // enable output of internal variables defined by material models
168 //
170 LocalAssemblerInterface<DisplacementDim>>(_process_data.solid_materials,
171 add_secondary_variable);
172
175 _process_data.solid_materials, local_assemblers_,
176 _integration_point_writer, integration_order);
177
178 _process_data.element_saturation = MeshLib::getOrCreateMeshProperty<double>(
179 const_cast<MeshLib::Mesh&>(mesh), "saturation_avg",
181
182 _process_data.gas_pressure_interpolated =
183 MeshLib::getOrCreateMeshProperty<double>(
184 const_cast<MeshLib::Mesh&>(mesh), "gas_pressure_interpolated",
186
187 _process_data.capillary_pressure_interpolated =
188 MeshLib::getOrCreateMeshProperty<double>(
189 const_cast<MeshLib::Mesh&>(mesh), "capillary_pressure_interpolated",
191
192 _process_data.liquid_pressure_interpolated =
193 MeshLib::getOrCreateMeshProperty<double>(
194 const_cast<MeshLib::Mesh&>(mesh), "liquid_pressure_interpolated",
196
197 _process_data.temperature_interpolated =
198 MeshLib::getOrCreateMeshProperty<double>(
199 const_cast<MeshLib::Mesh&>(mesh), "temperature_interpolated",
201
202 setIPDataInitialConditions(_integration_point_writer, mesh.getProperties(),
203 local_assemblers_);
204
205 // Initialize local assemblers after all variables have been set.
208 local_assemblers_, *_local_to_global_index_map);
209}
210
211template <int DisplacementDim>
213 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
214{
215 if (_use_monolithic_scheme)
216 {
217 initializeProcessBoundaryConditionsAndSourceTerms(
218 *_local_to_global_index_map, monolithic_process_id, media);
219 return;
220 }
221
222 // Staggered scheme:
223 OGS_FATAL("A Staggered version of TH2M is not implemented.");
224}
225
226template <int DisplacementDim>
228 std::vector<GlobalVector*>& x, double const t, int const process_id)
229{
230 if (process_id != 0)
231 {
232 return;
233 }
234
235 DBUG("Set initial conditions of TH2MProcess.");
236
239 local_assemblers_, getDOFTables(x.size()), x, t, process_id);
240}
241
242template <int DisplacementDim>
244 const double t, double const dt, std::vector<GlobalVector*> const& x,
245 std::vector<GlobalVector*> const& x_prev, int const process_id,
247{
248 DBUG("Assemble the equations for TH2M");
249
250 AssemblyMixin<TH2MProcess<DisplacementDim>>::assemble(t, dt, x, x_prev,
251 process_id, M, K, b);
252}
253
254template <int DisplacementDim>
256 const double t, double const dt, std::vector<GlobalVector*> const& x,
257 std::vector<GlobalVector*> const& x_prev, int const process_id,
259{
260 if (!_use_monolithic_scheme)
261 {
262 OGS_FATAL("A Staggered version of TH2M is not implemented.");
263 }
264
265 AssemblyMixin<TH2MProcess<DisplacementDim>>::assembleWithJacobian(
266 t, dt, x, x_prev, process_id, M, K, b, Jac);
267}
268
269template <int DisplacementDim>
271 std::vector<GlobalVector*> const& x, double const t, double const dt,
272 const int process_id)
273{
274 DBUG("PreTimestep TH2MProcess.");
275
276 if (hasMechanicalProcess(process_id))
277 {
279 getProcessVariables(process_id)[0];
280
283 local_assemblers_, pv.getActiveElementIDs(),
284 *_local_to_global_index_map, *x[process_id], t, dt);
285 }
286
287 AssemblyMixin<TH2MProcess<DisplacementDim>>::updateActiveElements(
288 process_id);
289}
290
291template <int DisplacementDim>
293 std::vector<GlobalVector*> const& x,
294 std::vector<GlobalVector*> const& x_prev, double const t, double const dt,
295 const int process_id)
296{
297 DBUG("PostTimestep TH2MProcess.");
298
299 ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
302 local_assemblers_, pv.getActiveElementIDs(), getDOFTables(x.size()), x,
303 x_prev, t, dt, process_id);
304}
305
306template <int DisplacementDim>
308 double const t, double const dt, std::vector<GlobalVector*> const& x,
309 GlobalVector const& x_prev, const int process_id)
310{
311 if (process_id != 0)
312 {
313 return;
314 }
315
316 DBUG("Compute the secondary variables for TH2MProcess.");
317
318 ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
321 local_assemblers_, pv.getActiveElementIDs(), getDOFTables(x.size()), t,
322 dt, x, x_prev, process_id);
323}
324
325template <int DisplacementDim>
326std::vector<std::string>
328 std::vector<std::reference_wrapper<MeshLib::Mesh>> const& meshes)
329{
330 INFO("TH2M process initializeSubmeshOutput().");
331 const int process_id = 0;
332 std::vector<std::string> residuum_names{
333 "GasMassFlowRate", "LiquidMassFlowRate", "HeatFlowRate", "NodalForces"};
334
335 AssemblyMixin<TH2MProcess<DisplacementDim>>::initializeAssemblyOnSubmeshes(
336 process_id, meshes, residuum_names);
337
338 return residuum_names;
339}
340
341template <int DisplacementDim>
342std::tuple<NumLib::LocalToGlobalIndexMap*, bool>
344{
345 const bool manage_storage = false;
346 return std::make_tuple(_local_to_global_index_map_single_component.get(),
347 manage_storage);
348}
349
350template <int DisplacementDim>
352 const int process_id) const
353{
354 if (hasMechanicalProcess(process_id))
355 {
356 return *_local_to_global_index_map;
357 }
358
359 // For the equation of pressure
360 return *_local_to_global_index_map_with_base_nodes;
361}
362
363template class TH2MProcess<2>;
364template class TH2MProcess<3>;
365
366} // namespace TH2M
367} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Global vector based on Eigen vector.
Definition EigenVector.h:25
bool isAxiallySymmetric() const
Definition Mesh.h:137
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
Properties & getProperties()
Definition Mesh.h:134
std::vector< std::size_t > const & getActiveElementIDs() const
std::unique_ptr< ProcessLib::AbstractJacobianAssembler > _jacobian_assembler
Definition Process.h:366
Handles configuration of several secondary variables from the project file.
void postTimestepConcreteProcess(std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, const double t, const double dt, int const) override
bool isLinear() const override
std::tuple< NumLib::LocalToGlobalIndexMap *, bool > getDOFTableForExtrapolatorData() const override
void setInitialConditionsConcreteProcess(std::vector< GlobalVector * > &x, double const t, int const process_id) override
TH2MProcess(std::string name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, unsigned const integration_order, std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > &&process_variables, TH2MProcessData< DisplacementDim > &&process_data, SecondaryVariableCollection &&secondary_variables, bool const use_monolithic_scheme)
std::vector< std::string > initializeAssemblyOnSubmeshes(std::vector< std::reference_wrapper< MeshLib::Mesh > > const &meshes) override
void preTimestepConcreteProcess(std::vector< GlobalVector * > const &x, double const t, double const dt, const int process_id) override
MathLib::MatrixSpecifications getMatrixSpecifications(const int process_id) const override
void initializeBoundaryConditions(std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media) override
void computeSecondaryVariableConcrete(double const t, double const dt, std::vector< GlobalVector * > const &x, GlobalVector const &x_prev, const int process_id) override
void assembleConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b) override
void assembleWithJacobianConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, GlobalMatrix &Jac) override
void constructDofTable() override
NumLib::LocalToGlobalIndexMap const & getDOFTable(const int process_id) const override
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
std::vector< Node * > getBaseNodes(std::vector< Element * > const &elements)
Definition Utils.h:26
@ BY_LOCATION
Ordering data by spatial location.
void solidMaterialInternalVariablesToIntegrationPointWriter(std::map< int, std::unique_ptr< SolidMaterial > > const &solid_materials, std::vector< std::unique_ptr< LocalAssemblerInterface > > const &local_assemblers, std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > &integration_point_writer, int const integration_order)
void solidMaterialInternalToSecondaryVariables(std::map< int, std::unique_ptr< SolidMaterial > > const &solid_materials, AddSecondaryVariableCallback const &add_secondary_variable)
void addReflectedIntegrationPointWriters(ReflData const &reflection_data, std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > &integration_point_writers, unsigned const integration_order, std::vector< std::unique_ptr< LocAsmIF > > const &local_assemblers)
SecondaryVariableFunctions makeExtrapolator(const unsigned num_components, NumLib::Extrapolator &extrapolator, LocalAssemblerCollection const &local_assemblers, typename NumLib::ExtrapolatableLocalAssemblerCollection< LocalAssemblerCollection >::IntegrationPointValuesMethod integration_point_values_method)
void setIPDataInitialConditions(std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > const &_integration_point_writer, MeshLib::Properties const &mesh_properties, LocalAssemblersVector &local_assemblers)
static void executeSelectedMemberOnDereferenced(Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)