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
23#include "ProcessLib/Process.h"
28#include "TH2MProcessData.h"
29
30namespace ProcessLib
31{
32namespace TH2M
33{
34template <int DisplacementDim>
36 std::string name,
37 MeshLib::Mesh& mesh,
38 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
39 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
40 unsigned const integration_order,
41 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
42 process_variables,
44 SecondaryVariableCollection&& secondary_variables,
45 bool const use_monolithic_scheme)
46 : Process(std::move(name), mesh, std::move(jacobian_assembler), parameters,
47 integration_order, std::move(process_variables),
48 std::move(secondary_variables), use_monolithic_scheme),
50 _process_data(std::move(process_data))
51{
53 DisplacementDim>(
55 _integration_point_writer, integration_order, local_assemblers_);
56}
57
58template <int DisplacementDim>
60{
61 return false;
62}
63
64template <int DisplacementDim>
67 const int process_id) const
68{
69 // For the monolithic scheme or the M process (deformation) in the staggered
70 // scheme.
71 if (_use_monolithic_scheme || process_id == deformation_process_id)
72 {
73 auto const& l = *_local_to_global_index_map;
74 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
75 &l.getGhostIndices(), &this->_sparsity_pattern};
76 }
77
78 // For staggered scheme and T or H process (pressure).
79 auto const& l = *_local_to_global_index_map_with_base_nodes;
80 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
81 &l.getGhostIndices(), &_sparsity_pattern_with_linear_element};
82}
83
84template <int DisplacementDim>
86{
87 // Create single component dof in every of the mesh's nodes.
88 _mesh_subset_all_nodes = std::make_unique<MeshLib::MeshSubset>(
89 _mesh, _mesh.getNodes(), _process_data.use_TaylorHood_elements);
90 // Create single component dof in the mesh's base nodes.
91 _base_nodes = MeshLib::getBaseNodes(_mesh.getElements());
92 _mesh_subset_base_nodes = std::make_unique<MeshLib::MeshSubset>(
93 _mesh, _base_nodes, _process_data.use_TaylorHood_elements);
94
95 // TODO move the two data members somewhere else.
96 // for extrapolation of secondary variables of stress or strain
97 std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component{
98 *_mesh_subset_all_nodes};
99 _local_to_global_index_map_single_component =
100 std::make_unique<NumLib::LocalToGlobalIndexMap>(
101 std::move(all_mesh_subsets_single_component),
102 // by location order is needed for output
104
105 if (_use_monolithic_scheme)
106 {
107 // For gas pressure, which is the first
108 std::vector<MeshLib::MeshSubset> all_mesh_subsets{
109 *_mesh_subset_base_nodes};
110
111 // For capillary pressure, which is the second
112 all_mesh_subsets.push_back(*_mesh_subset_base_nodes);
113
114 // For temperature, which is the third
115 all_mesh_subsets.push_back(*_mesh_subset_base_nodes);
116
117 // For displacement.
118 std::generate_n(
119 std::back_inserter(all_mesh_subsets),
120 getProcessVariables(monolithic_process_id)[deformation_process_id]
121 .get()
122 .getNumberOfGlobalComponents(),
123 [&]() { return *_mesh_subset_all_nodes; });
124
125 std::vector<int> const vec_n_components{
126 n_gas_pressure_components, n_capillary_pressure_components,
127 n_temperature_components, n_displacement_components};
128
129 _local_to_global_index_map =
130 std::make_unique<NumLib::LocalToGlobalIndexMap>(
131 std::move(all_mesh_subsets), vec_n_components,
133 assert(_local_to_global_index_map);
134 }
135 else
136 {
137 OGS_FATAL("A Staggered version of TH2M is not implemented.");
138 }
139}
140
141template <int DisplacementDim>
143 NumLib::LocalToGlobalIndexMap const& dof_table,
144 MeshLib::Mesh const& mesh,
145 unsigned const integration_order)
146{
148 mesh.getElements(), dof_table, local_assemblers_,
149 NumLib::IntegrationOrder{integration_order}, mesh.isAxiallySymmetric(),
150 _process_data);
151
152 auto add_secondary_variable = [&](std::string const& name,
153 int const num_components,
154 auto get_ip_values_function)
155 {
156 _secondary_variables.addSecondaryVariable(
157 name,
158 makeExtrapolator(num_components, getExtrapolator(),
159 local_assemblers_,
160 std::move(get_ip_values_function)));
161 };
162
165 _secondary_variables, getExtrapolator(), local_assemblers_);
166
167 //
168 // enable output of internal variables defined by material models
169 //
171 LocalAssemblerInterface<DisplacementDim>>(_process_data.solid_materials,
172 add_secondary_variable);
173
176 _process_data.solid_materials, local_assemblers_,
177 _integration_point_writer, integration_order);
178
179 _process_data.gas_pressure_interpolated =
181 const_cast<MeshLib::Mesh&>(mesh), "gas_pressure_interpolated",
183
184 _process_data.capillary_pressure_interpolated =
186 const_cast<MeshLib::Mesh&>(mesh), "capillary_pressure_interpolated",
188
189 _process_data.liquid_pressure_interpolated =
191 const_cast<MeshLib::Mesh&>(mesh), "liquid_pressure_interpolated",
193
194 _process_data.temperature_interpolated =
196 const_cast<MeshLib::Mesh&>(mesh), "temperature_interpolated",
198
199 setIPDataInitialConditions(_integration_point_writer, mesh.getProperties(),
200 local_assemblers_);
201
202 // Initialize local assemblers after all variables have been set.
205 local_assemblers_, *_local_to_global_index_map);
206}
207
208template <int DisplacementDim>
210 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
211{
212 if (_use_monolithic_scheme)
213 {
214 initializeProcessBoundaryConditionsAndSourceTerms(
215 *_local_to_global_index_map, monolithic_process_id, media);
216 return;
217 }
218
219 // Staggered scheme:
220 OGS_FATAL("A Staggered version of TH2M is not implemented.");
221}
222
223template <int DisplacementDim>
225 std::vector<GlobalVector*>& x, double const t, int const process_id)
226{
227 if (process_id != 0)
228 {
229 return;
230 }
231
232 DBUG("Set initial conditions of TH2MProcess.");
233
236 local_assemblers_, getDOFTables(x.size()), x, t, process_id);
237}
238
239template <int DisplacementDim>
241 const double t, double const dt, std::vector<GlobalVector*> const& x,
242 std::vector<GlobalVector*> const& x_prev, int const process_id,
244{
245 DBUG("Assemble the equations for TH2M");
246
247 AssemblyMixin<TH2MProcess<DisplacementDim>>::assemble(t, dt, x, x_prev,
248 process_id, M, K, b);
249}
250
251template <int DisplacementDim>
253 const double t, double const dt, std::vector<GlobalVector*> const& x,
254 std::vector<GlobalVector*> const& x_prev, int const process_id,
255 GlobalVector& b, GlobalMatrix& Jac)
256{
257 if (!_use_monolithic_scheme)
258 {
259 OGS_FATAL("A Staggered version of TH2M is not implemented.");
260 }
261
262 AssemblyMixin<TH2MProcess<DisplacementDim>>::assembleWithJacobian(
263 t, dt, x, x_prev, process_id, b, Jac);
264}
265
266template <int DisplacementDim>
268 std::vector<GlobalVector*> const& x, double const t, double const dt,
269 const int process_id)
270{
271 DBUG("PreTimestep TH2MProcess.");
272
273 if (hasMechanicalProcess(process_id))
274 {
277 local_assemblers_, getActiveElementIDs(),
278 *_local_to_global_index_map, *x[process_id], t, dt);
279 }
280
281 AssemblyMixin<TH2MProcess<DisplacementDim>>::updateActiveElements();
282}
283
284template <int DisplacementDim>
286 std::vector<GlobalVector*> const& x,
287 std::vector<GlobalVector*> const& x_prev, double const t, double const dt,
288 const int process_id)
289{
290 DBUG("PostTimestep TH2MProcess.");
291
294 local_assemblers_, getActiveElementIDs(), getDOFTables(x.size()), x,
295 x_prev, t, dt, process_id);
296}
297
298template <int DisplacementDim>
300 double const t, double const dt, std::vector<GlobalVector*> const& x,
301 GlobalVector const& x_prev, const int process_id)
302{
303 if (process_id != 0)
304 {
305 return;
306 }
307
308 DBUG("Compute the secondary variables for TH2MProcess.");
309
312 local_assemblers_, getActiveElementIDs(), getDOFTables(x.size()), t, dt,
313 x, x_prev, process_id);
314
315 computeCellAverages<DisplacementDim>(cell_average_data_, local_assemblers_);
316}
317
318template <int DisplacementDim>
319std::vector<std::vector<std::string>>
321 std::vector<std::reference_wrapper<MeshLib::Mesh>> const& meshes)
322{
323 INFO("TH2M process initializeSubmeshOutput().");
324 std::vector<std::vector<std::string>> residuum_names{
325 {"GasMassFlowRate", "LiquidMassFlowRate", "HeatFlowRate",
326 "NodalForces"}};
327
328 AssemblyMixin<TH2MProcess<DisplacementDim>>::initializeAssemblyOnSubmeshes(
329 meshes, residuum_names);
330
331 return residuum_names;
332}
333
334template <int DisplacementDim>
335std::tuple<NumLib::LocalToGlobalIndexMap*, bool>
337{
338 const bool manage_storage = false;
339 return std::make_tuple(_local_to_global_index_map_single_component.get(),
340 manage_storage);
341}
342
343template <int DisplacementDim>
345 const int process_id) const
346{
347 if (hasMechanicalProcess(process_id))
348 {
349 return *_local_to_global_index_map;
350 }
351
352 // For the equation of pressure
353 return *_local_to_global_index_map_with_base_nodes;
354}
355
356template class TH2MProcess<2>;
357template class TH2MProcess<3>;
358
359} // namespace TH2M
360} // 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::unique_ptr< ProcessLib::AbstractJacobianAssembler > _jacobian_assembler
Definition Process.h:376
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 assembleWithJacobianConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector &b, GlobalMatrix &Jac) 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)
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 constructDofTable() override
NumLib::LocalToGlobalIndexMap const & getDOFTable(const int process_id) const override
std::vector< std::vector< std::string > > initializeAssemblyOnSubmeshes(std::vector< std::reference_wrapper< MeshLib::Mesh > > const &meshes) override
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)
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::shared_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::shared_ptr< SolidMaterial > > const &solid_materials, AddSecondaryVariableCallback const &add_secondary_variable)
void addReflectedSecondaryVariables(ReflData const &reflection_data, SecondaryVariableCollection &secondary_variables, NumLib::Extrapolator &extrapolator, std::vector< std::unique_ptr< LocAsmIF > > const &local_assemblers)
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)
void createLocalAssemblers(std::vector< MeshLib::Element * > const &mesh_elements, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< std::unique_ptr< LocalAssemblerInterface< DisplacementDim > > > &local_assemblers, NumLib::IntegrationOrder const integration_order, bool const is_axially_symmetric, TH2MProcessData< DisplacementDim > &process_data)
void computeCellAverages(CellAverageData &cell_average_data, std::vector< std::unique_ptr< LAIntf > > 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)