OGS
CreateComponentTransportProcess.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
5
9#include "CreateLookupTable.h"
10#include "LookupTable.h"
15#include "ParameterLib/Utils.h"
19
20namespace ProcessLib
21{
22namespace ComponentTransport
23{
25 MeshLib::Mesh const& mesh,
27{
28 std::array const required_properties_medium = {
33
34 std::array const required_properties_liquid_phase = {
37
38 std::array const required_properties_components = {
42
43 for (auto const& element_id : mesh.getElements() | MeshLib::views::ids)
44 {
45 auto const& medium = *media_map.getMedium(element_id);
46 checkRequiredProperties(medium, required_properties_medium);
47
48 // check if liquid phase definition and the corresponding properties
49 // exist
50 auto const& liquid_phase = medium.phase("AqueousLiquid");
51 checkRequiredProperties(liquid_phase, required_properties_liquid_phase);
52
53 // check if components and the corresponding properties exist
54 auto const number_of_components = liquid_phase.numberOfComponents();
55 for (std::size_t component_id = 0; component_id < number_of_components;
56 ++component_id)
57 {
58 if (!liquid_phase.hasComponent(component_id))
59 {
61 "The component {:d} in the AqueousLiquid phase isn't "
62 "specified.",
63 component_id);
64 }
65 auto const& component = liquid_phase.component(component_id);
66 checkRequiredProperties(component, required_properties_components);
67 }
68 }
69}
70
71std::unique_ptr<Process> createComponentTransportProcess(
72 std::string const& name,
73 MeshLib::Mesh& mesh,
74 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
75 std::vector<ProcessVariable> const& variables,
76 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
77 unsigned const integration_order,
78 BaseLib::ConfigTree const& config,
79 std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
80 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media,
81 std::unique_ptr<ChemistryLib::ChemicalSolverInterface>&&
82 chemical_solver_interface)
83{
85 config.checkConfigParameter("type", "ComponentTransport");
86
87 DBUG("Create ComponentTransportProcess.");
88
89 auto const coupling_scheme =
91 config.getConfigParameter<std::string>("coupling_scheme",
92 "monolithic_scheme");
93 const bool use_monolithic_scheme = (coupling_scheme != "staggered");
94
96
98 auto const pv_config = config.getConfigSubtree("process_variables");
99
100 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
101 process_variables;
102
104 std::vector collected_process_variables = findProcessVariables(
105 variables, pv_config,
106 {
107 "pressure",
109 "concentration"});
110
112 std::vector const temperature_variable = findProcessVariables(
113 variables, pv_config,
115 "temperature", true /*temperature is optional*/);
116 bool const isothermal = temperature_variable.empty();
117 if (!isothermal)
118 {
119 assert(temperature_variable.size() == 1);
120 collected_process_variables.insert(
121 ++collected_process_variables.begin(), temperature_variable[0]);
122 }
123
124 // Check number of components for each process variable
125 auto it = std::find_if(
126 collected_process_variables.cbegin(),
127 collected_process_variables.cend(),
128 [](std::reference_wrapper<ProcessLib::ProcessVariable> const& pv)
129 { return pv.get().getNumberOfGlobalComponents() != 1; });
130
131 if (it != collected_process_variables.end())
132 {
133 OGS_FATAL(
134 "Number of components for process variable '{:s}' should be 1 "
135 "rather "
136 "than {:d}.",
137 it->get().getName(),
138 it->get().getNumberOfGlobalComponents());
139 }
140
141 // Allocate the collected process variables into a two-dimensional vector,
142 // depending on what scheme is adopted
143 if (use_monolithic_scheme) // monolithic scheme.
144 {
145 if (!isothermal)
146 {
147 OGS_FATAL(
148 "Currently, non-isothermal component transport process can "
149 "only be simulated in staggered scheme.");
150 }
151
152 process_variables.push_back(std::move(collected_process_variables));
153 }
154 else // staggered scheme.
155 {
156 std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>
157 per_process_variable;
158
159 if (!chemical_solver_interface)
160 {
161 for (auto& pv : collected_process_variables)
162 {
163 per_process_variable.emplace_back(pv);
164 process_variables.push_back(std::move(per_process_variable));
165 }
166 }
167 else
168 {
169 auto sort_by_component =
170 [&per_process_variable,
171 collected_process_variables](auto const& c_name)
172 {
173 auto pv = std::find_if(collected_process_variables.begin(),
174 collected_process_variables.end(),
175 [&c_name](auto const& v) -> bool
176 { return v.get().getName() == c_name; });
177
178 if (pv == collected_process_variables.end())
179 {
180 OGS_FATAL(
181 "Component {:s} given in "
182 "<chemical_system>/<solution>/"
183 "<components> is not found in specified "
184 "coupled processes (see "
185 "<process>/<process_variables>/"
186 "<concentration>).",
187 c_name);
188 }
189
190 per_process_variable.emplace_back(*pv);
191 return std::move(per_process_variable);
192 };
193
194 auto const components =
195 chemical_solver_interface->getComponentList();
196 // pressure
197 per_process_variable.emplace_back(collected_process_variables[0]);
198 process_variables.push_back(std::move(per_process_variable));
199 // temperature
200 if (!isothermal)
201 {
202 per_process_variable.emplace_back(
203 collected_process_variables[1]);
204 process_variables.push_back(std::move(per_process_variable));
205 }
206 // concentration
207 assert(components.size() + (isothermal ? 1 : 2) ==
208 collected_process_variables.size());
209 std::transform(components.begin(), components.end(),
210 std::back_inserter(process_variables),
211 sort_by_component);
212 }
213 }
214
216 std::vector<double> const b =
218 config.getConfigParameter<std::vector<double>>("specific_body_force");
219 assert(!b.empty() && b.size() < 4);
220 // Specific body force parameter.
221 Eigen::VectorXd specific_body_force(b.size());
222 int const mesh_space_dimension =
224 if (static_cast<int>(b.size()) != mesh_space_dimension)
225 {
226 OGS_FATAL(
227 "specific body force (gravity vector) has {:d} components, mesh "
228 "dimension is {:d}",
229 b.size(), mesh_space_dimension);
230 }
231 bool const has_gravity = MathLib::toVector(b).norm() > 0;
232 if (has_gravity)
233 {
234 std::copy_n(b.data(), b.size(), specific_body_force.data());
235 }
236
237 bool const non_advective_form =
239 config.getConfigParameter<bool>("non_advective_form", false);
240
241 bool chemically_induced_porosity_change =
243 config.getConfigParameter<bool>("chemically_induced_porosity_change",
244 false);
245
246 auto const temperature_field = ParameterLib::findOptionalTagParameter<
247 double>(
249 config, "temperature_field", parameters, 1, &mesh);
250 if (!isothermal && temperature_field != nullptr)
251 {
252 OGS_FATAL("Temperature field is set for non-isothermal setup.")
253 }
254
255 auto media_map =
257
258 auto lookup_table = ComponentTransport::createLookupTable(
260 config.getConfigParameterOptional<std::string>("tabular_file"),
261 config.projectDirectory(),
262 process_variables);
263
264 DBUG("Check the media properties of ComponentTransport process ...");
265 checkMPLProperties(mesh, media_map);
266 DBUG("Media properties verified.");
267
268 auto stabilizer = NumLib::createNumericalStabilization(mesh, config);
269
270 auto const* aperture_size_parameter = &ParameterLib::findParameter<double>(
272 auto const aperture_config =
274 config.getConfigSubtreeOptional("aperture_size");
275 if (aperture_config)
276 {
277 aperture_size_parameter = &ParameterLib::findParameter<double>(
279 *aperture_config, "parameter", parameters, 1);
280 }
281
282 auto const is_linear =
284 config.getConfigParameter("linear", false);
285
286 auto const ls_compute_only_upon_timestep_change =
288 config.getConfigParameter(
289 "linear_solver_compute_only_upon_timestep_change", false);
290
291 auto const rotation_matrices = MeshLib::getElementRotationMatrices(
292 mesh_space_dimension, mesh.getDimension(), mesh.getElements());
293 std::vector<Eigen::VectorXd> projected_specific_body_force_vectors;
294 projected_specific_body_force_vectors.reserve(rotation_matrices.size());
295
296 std::transform(rotation_matrices.begin(), rotation_matrices.end(),
297 std::back_inserter(projected_specific_body_force_vectors),
298 [&specific_body_force](const auto& R)
299 { return R * R.transpose() * specific_body_force; });
300
302 std::move(media_map),
303 has_gravity,
304 non_advective_form,
305 temperature_field,
306 chemically_induced_porosity_change,
307 chemical_solver_interface.get(),
308 std::move(lookup_table),
309 std::move(stabilizer),
310 projected_specific_body_force_vectors,
311 mesh_space_dimension,
312 *aperture_size_parameter,
313 isothermal,
314 NumLib::ShapeMatrixCache{integration_order}};
315
316 SecondaryVariableCollection secondary_variables;
317
318 ProcessLib::createSecondaryVariables(config, secondary_variables);
319
320 std::unique_ptr<ProcessLib::SurfaceFluxData> surfaceflux;
321 auto surfaceflux_config =
323 config.getConfigSubtreeOptional("calculatesurfaceflux");
324 if (surfaceflux_config)
325 {
327 *surfaceflux_config, meshes);
328 }
329
330 return std::make_unique<ComponentTransportProcess>(
331 std::move(name), mesh, std::move(jacobian_assembler), parameters,
332 integration_order, std::move(process_variables),
333 std::move(process_data), std::move(secondary_variables),
334 use_monolithic_scheme, std::move(surfaceflux),
335 std::move(chemical_solver_interface), is_linear,
336 ls_compute_only_upon_timestep_change);
337}
338
339} // namespace ComponentTransport
340} // namespace ProcessLib
Interface for coupling OpenGeoSys with an external geochemical solver.
#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::filesystem::path projectDirectory() 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.
MaterialSpatialDistributionMap createMaterialSpatialDistributionMap(std::map< int, std::shared_ptr< Medium > > const &media, MeshLib::Mesh const &mesh)
@ longitudinal_dispersivity
used to compute the hydrodynamic dispersion tensor.
@ transversal_dispersivity
used to compute the hydrodynamic dispersion tensor.
@ retardation_factor
specify retardation factor used in component transport process.
Eigen::Map< const Vector > toVector(std::vector< double > const &data, Eigen::VectorXd::Index size)
Creates an Eigen mapped vector from the given data vector.
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:216
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)
Parameter< ParameterDataType > * findOptionalTagParameter(BaseLib::ConfigTree const &process_config, std::string const &tag, std::vector< std::unique_ptr< ParameterBase > > const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
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)
std::unique_ptr< LookupTable > createLookupTable(std::optional< std::string > const tabular_file, std::filesystem::path const &project_directory, std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > const &process_variables)
std::unique_ptr< Process > createComponentTransportProcess(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::unique_ptr< ChemistryLib::ChemicalSolverInterface > &&chemical_solver_interface)
void checkMPLProperties(MeshLib::Mesh const &mesh, MaterialPropertyLib::MaterialSpatialDistributionMap const &media_map)
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)
static std::unique_ptr< ProcessLib::SurfaceFluxData > createSurfaceFluxData(BaseLib::ConfigTree const &calculatesurfaceflux_config, std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes)