OGS
CreateHTProcess.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "CreateHTProcess.h"
5
7#include "HTProcess.h"
8#include "HTProcessData.h"
16#include "ParameterLib/Utils.h"
20
21namespace ProcessLib
22{
23namespace HT
24{
56
57std::unique_ptr<Process> createHTProcess(
58 std::string const& name,
59 MeshLib::Mesh& mesh,
60 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
61 std::vector<ProcessVariable> const& variables,
62 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
63 unsigned const integration_order,
64 BaseLib::ConfigTree const& config,
65 std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
66 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
67{
69 config.checkConfigParameter("type", "HT");
70
71 DBUG("Create HTProcess.");
72
73 auto const coupling_scheme =
75 config.getConfigParameterOptional<std::string>("coupling_scheme");
76 const bool use_monolithic_scheme =
77 !(coupling_scheme && (*coupling_scheme == "staggered"));
78
80
82 auto const pv_config = config.getConfigSubtree("process_variables");
83
84 // Process IDs, which are set according to the appearance order of the
85 // process variables.
86 int const heat_transport_process_id = 0;
87 int hydraulic_process_id = 0;
88
89 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
90 process_variables;
91 if (use_monolithic_scheme) // monolithic scheme.
92 {
95 auto per_process_variables = findProcessVariables(
96 variables, pv_config,
97 {
98 "temperature",
100 "pressure"});
101 process_variables.push_back(std::move(per_process_variables));
102 }
103 else // staggered scheme.
104 {
105 using namespace std::string_literals;
106 for (auto const& variable_name : {"temperature"s, "pressure"s})
107 {
108 auto per_process_variables =
109 findProcessVariables(variables, pv_config, {variable_name});
110 process_variables.push_back(std::move(per_process_variables));
111 }
112 hydraulic_process_id = 1;
113 }
114
116 std::vector<double> const b =
118 config.getConfigParameter<std::vector<double>>("specific_body_force");
119 assert(!b.empty() && b.size() < 4);
120 int const mesh_space_dimension =
122 if (static_cast<int>(b.size()) != mesh_space_dimension)
123 {
124 OGS_FATAL(
125 "specific body force (gravity vector) has {:d} components, mesh "
126 "dimension is {:d}",
127 b.size(), mesh_space_dimension);
128 }
129
130 // Specific body force parameter.
131 Eigen::VectorXd specific_body_force(b.size());
132 bool const has_gravity = MathLib::toVector(b).norm() > 0;
133 if (has_gravity)
134 {
135 std::copy_n(b.data(), b.size(), specific_body_force.data());
136 }
137
138 ParameterLib::ConstantParameter<double> default_solid_thermal_expansion(
139 "default solid thermal expansion", 0.);
140 ParameterLib::ConstantParameter<double> default_biot_constant(
141 "default_biot constant", 0.);
142 ParameterLib::Parameter<double>* solid_thermal_expansion =
143 &default_solid_thermal_expansion;
144 ParameterLib::Parameter<double>* biot_constant = &default_biot_constant;
145
146 auto const solid_config =
148 config.getConfigSubtreeOptional("solid_thermal_expansion");
149 const bool has_fluid_thermal_expansion = static_cast<bool>(solid_config);
150 if (solid_config)
151 {
152 solid_thermal_expansion = &ParameterLib::findParameter<double>(
154 *solid_config, "thermal_expansion", parameters, 1, &mesh);
155 DBUG("Use '{:s}' as solid thermal expansion.",
156 solid_thermal_expansion->name);
159 *solid_config, "biot_constant", parameters, 1, &mesh);
160 DBUG("Use '{:s}' as Biot's constant.", biot_constant->name);
161 }
162
163 std::unique_ptr<ProcessLib::SurfaceFluxData> surfaceflux;
164 auto calculatesurfaceflux_config =
166 config.getConfigSubtreeOptional("calculatesurfaceflux");
167 if (calculatesurfaceflux_config)
168 {
170 *calculatesurfaceflux_config, meshes);
171 }
172
173 auto media_map =
175
176 DBUG("Check the media properties of HT process ...");
177 checkMPLProperties(mesh, media_map);
178 DBUG("Media properties verified.");
179
180 auto stabilizer = NumLib::createNumericalStabilization(mesh, config);
181
182 auto const* aperture_size_parameter = &ParameterLib::findParameter<double>(
184 auto const aperture_config =
186 config.getConfigSubtreeOptional("aperture_size");
187 if (aperture_config)
188 {
189 aperture_size_parameter = &ParameterLib::findParameter<double>(
191 *aperture_config, "parameter", parameters, 1);
192 }
193
194 auto const rotation_matrices = MeshLib::getElementRotationMatrices(
195 mesh_space_dimension, mesh.getDimension(), mesh.getElements());
196 std::vector<Eigen::VectorXd> projected_specific_body_force_vectors;
197 projected_specific_body_force_vectors.reserve(rotation_matrices.size());
198
199 std::transform(rotation_matrices.begin(), rotation_matrices.end(),
200 std::back_inserter(projected_specific_body_force_vectors),
201 [&specific_body_force](const auto& R)
202 { return R * R.transpose() * specific_body_force; });
203
204 HTProcessData process_data{std::move(media_map),
205 has_fluid_thermal_expansion,
206 *solid_thermal_expansion,
207 *biot_constant,
208 has_gravity,
209 heat_transport_process_id,
210 hydraulic_process_id,
211 std::move(stabilizer),
212 projected_specific_body_force_vectors,
213 mesh_space_dimension,
214 *aperture_size_parameter,
215 NumLib::ShapeMatrixCache{integration_order}};
216
217 SecondaryVariableCollection secondary_variables;
218
219 ProcessLib::createSecondaryVariables(config, secondary_variables);
220
221 return std::make_unique<HTProcess>(
222 std::move(name), mesh, std::move(jacobian_assembler), parameters,
223 integration_order, std::move(process_variables),
224 std::move(process_data), std::move(secondary_variables),
225 use_monolithic_scheme, std::move(surfaceflux));
226}
227
228} // namespace HT
229} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:19
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
std::optional< T > getConfigParameterOptional(std::string const &param) const
T getConfigParameter(std::string const &param) const
ConfigTree getConfigSubtree(std::string const &root) const
void checkConfigParameter(std::string const &param, std::string_view const value) const
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:97
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:100
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:79
static PROCESSLIB_EXPORT const std::string constant_one_parameter_name
Definition Process.h:40
Handles configuration of several secondary variables from the project file.
void checkMaterialSpatialDistributionMap(MeshLib::Mesh const &mesh, MaterialPropertyLib::MaterialSpatialDistributionMap const &media_map, ContainerMedium const &required_properties_medium, ContainerSolid const &required_properties_solid_phase, ContainerLiquid const &required_properties_liquid_phase, ContainerGas const &required_properties_gas_phase)
MaterialSpatialDistributionMap createMaterialSpatialDistributionMap(std::map< int, std::shared_ptr< Medium > > const &media, MeshLib::Mesh const &mesh)
Eigen::Map< const Vector > toVector(std::vector< double > const &data, Eigen::VectorXd::Index size)
Creates an Eigen mapped vector from the given data vector.
std::vector< Eigen::MatrixXd > getElementRotationMatrices(int const space_dimension, int const mesh_dimension, std::vector< Element * > const &elements)
Element rotation matrix computation.
int getSpaceDimension(std::vector< Node * > const &nodes)
Computes dimension of the embedding space containing the set of given points.
NumericalStabilization createNumericalStabilization(MeshLib::Mesh const &mesh, BaseLib::ConfigTree const &config)
OGS_NO_DANGLING Parameter< ParameterDataType > & findParameter(std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase > > const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
void checkMPLProperties(MeshLib::Mesh const &mesh, MaterialPropertyLib::MaterialSpatialDistributionMap const &media_map)
std::unique_ptr< Process > createHTProcess(std::string const &name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< ProcessVariable > const &variables, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, unsigned const integration_order, BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes, std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)
std::vector< std::reference_wrapper< ProcessVariable > > findProcessVariables(std::vector< ProcessVariable > const &variables, BaseLib::ConfigTree const &pv_config, std::initializer_list< std::string > tags)
void createSecondaryVariables(BaseLib::ConfigTree const &config, SecondaryVariableCollection &secondary_variables)
Single, constant value parameter.
static std::unique_ptr< ProcessLib::SurfaceFluxData > createSurfaceFluxData(BaseLib::ConfigTree const &calculatesurfaceflux_config, std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes)