OGS
CreateComponentTransportProcess.cpp
Go to the documentation of this file.
1
12
16#include "CreateLookupTable.h"
17#include "LookupTable.h"
22#include "ParameterLib/Utils.h"
26
27namespace ProcessLib
28{
29namespace ComponentTransport
30{
32 MeshLib::Mesh const& mesh,
34{
35 std::array const required_properties_medium = {
40
41 std::array const required_properties_liquid_phase = {
44
45 std::array const required_properties_components = {
49
50 for (auto const& element_id : mesh.getElements() | MeshLib::views::ids)
51 {
52 auto const& medium = *media_map.getMedium(element_id);
53 checkRequiredProperties(medium, required_properties_medium);
54
55 // check if liquid phase definition and the corresponding properties
56 // exist
57 auto const& liquid_phase = medium.phase("AqueousLiquid");
58 checkRequiredProperties(liquid_phase, required_properties_liquid_phase);
59
60 // check if components and the corresponding properties exist
61 auto const number_of_components = liquid_phase.numberOfComponents();
62 for (std::size_t component_id = 0; component_id < number_of_components;
63 ++component_id)
64 {
65 if (!liquid_phase.hasComponent(component_id))
66 {
68 "The component {:d} in the AqueousLiquid phase isn't "
69 "specified.",
70 component_id);
71 }
72 auto const& component = liquid_phase.component(component_id);
73 checkRequiredProperties(component, required_properties_components);
74 }
75 }
76}
77
78std::unique_ptr<Process> createComponentTransportProcess(
79 std::string const& name,
80 MeshLib::Mesh& mesh,
81 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
82 std::vector<ProcessVariable> const& variables,
83 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
84 unsigned const integration_order,
85 BaseLib::ConfigTree const& config,
86 std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
87 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media,
88 std::unique_ptr<ChemistryLib::ChemicalSolverInterface>&&
89 chemical_solver_interface)
90{
92 config.checkConfigParameter("type", "ComponentTransport");
93
94 DBUG("Create ComponentTransportProcess.");
95
96 auto const coupling_scheme =
98 config.getConfigParameter<std::string>("coupling_scheme",
99 "monolithic_scheme");
100 const bool use_monolithic_scheme = (coupling_scheme != "staggered");
101
103
105 auto const pv_config = config.getConfigSubtree("process_variables");
106
107 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
108 process_variables;
109
111 std::vector collected_process_variables = findProcessVariables(
112 variables, pv_config,
113 {
114 "pressure",
116 "concentration"});
117
119 std::vector const temperature_variable = findProcessVariables(
120 variables, pv_config,
122 "temperature", true /*temperature is optional*/);
123 bool const isothermal = temperature_variable.empty();
124 if (!isothermal)
125 {
126 assert(temperature_variable.size() == 1);
127 collected_process_variables.insert(
128 ++collected_process_variables.begin(), temperature_variable[0]);
129 }
130
131 // Check number of components for each process variable
132 auto it = std::find_if(
133 collected_process_variables.cbegin(),
134 collected_process_variables.cend(),
135 [](std::reference_wrapper<ProcessLib::ProcessVariable> const& pv)
136 { return pv.get().getNumberOfGlobalComponents() != 1; });
137
138 if (it != collected_process_variables.end())
139 {
140 OGS_FATAL(
141 "Number of components for process variable '{:s}' should be 1 "
142 "rather "
143 "than {:d}.",
144 it->get().getName(),
145 it->get().getNumberOfGlobalComponents());
146 }
147
148 // Allocate the collected process variables into a two-dimensional vector,
149 // depending on what scheme is adopted
150 if (use_monolithic_scheme) // monolithic scheme.
151 {
152 if (!isothermal)
153 {
154 OGS_FATAL(
155 "Currently, non-isothermal component transport process can "
156 "only be simulated in staggered scheme.");
157 }
158
159 process_variables.push_back(std::move(collected_process_variables));
160 }
161 else // staggered scheme.
162 {
163 std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>
164 per_process_variable;
165
166 if (!chemical_solver_interface)
167 {
168 for (auto& pv : collected_process_variables)
169 {
170 per_process_variable.emplace_back(pv);
171 process_variables.push_back(std::move(per_process_variable));
172 }
173 }
174 else
175 {
176 auto sort_by_component =
177 [&per_process_variable,
178 collected_process_variables](auto const& c_name)
179 {
180 auto pv = std::find_if(collected_process_variables.begin(),
181 collected_process_variables.end(),
182 [&c_name](auto const& v) -> bool
183 { return v.get().getName() == c_name; });
184
185 if (pv == collected_process_variables.end())
186 {
187 OGS_FATAL(
188 "Component {:s} given in "
189 "<chemical_system>/<solution>/"
190 "<components> is not found in specified "
191 "coupled processes (see "
192 "<process>/<process_variables>/"
193 "<concentration>).",
194 c_name);
195 }
196
197 per_process_variable.emplace_back(*pv);
198 return std::move(per_process_variable);
199 };
200
201 auto const components =
202 chemical_solver_interface->getComponentList();
203 // pressure
204 per_process_variable.emplace_back(collected_process_variables[0]);
205 process_variables.push_back(std::move(per_process_variable));
206 // temperature
207 if (!isothermal)
208 {
209 per_process_variable.emplace_back(
210 collected_process_variables[1]);
211 process_variables.push_back(std::move(per_process_variable));
212 }
213 // concentration
214 assert(components.size() + (isothermal ? 1 : 2) ==
215 collected_process_variables.size());
216 std::transform(components.begin(), components.end(),
217 std::back_inserter(process_variables),
218 sort_by_component);
219 }
220 }
221
223 std::vector<double> const b =
225 config.getConfigParameter<std::vector<double>>("specific_body_force");
226 assert(!b.empty() && b.size() < 4);
227 // Specific body force parameter.
228 Eigen::VectorXd specific_body_force(b.size());
229 int const mesh_space_dimension =
231 if (static_cast<int>(b.size()) != mesh_space_dimension)
232 {
233 OGS_FATAL(
234 "specific body force (gravity vector) has {:d} components, mesh "
235 "dimension is {:d}",
236 b.size(), mesh_space_dimension);
237 }
238 bool const has_gravity = MathLib::toVector(b).norm() > 0;
239 if (has_gravity)
240 {
241 std::copy_n(b.data(), b.size(), specific_body_force.data());
242 }
243
244 bool const non_advective_form =
246 config.getConfigParameter<bool>("non_advective_form", false);
247
248 bool chemically_induced_porosity_change =
250 config.getConfigParameter<bool>("chemically_induced_porosity_change",
251 false);
252
253 auto const temperature_field = ParameterLib::findOptionalTagParameter<
254 double>(
256 config, "temperature_field", parameters, 1, &mesh);
257 if (!isothermal && temperature_field != nullptr)
258 {
259 OGS_FATAL("Temperature field is set for non-isothermal setup.")
260 }
261
262 auto media_map =
264
265 auto lookup_table = ComponentTransport::createLookupTable(
267 config.getConfigParameterOptional<std::string>("tabular_file"),
268 process_variables);
269
270 DBUG("Check the media properties of ComponentTransport process ...");
271 checkMPLProperties(mesh, media_map);
272 DBUG("Media properties verified.");
273
274 auto stabilizer = NumLib::createNumericalStabilization(mesh, config);
275
276 auto const* aperture_size_parameter = &ParameterLib::findParameter<double>(
278 auto const aperture_config =
280 config.getConfigSubtreeOptional("aperture_size");
281 if (aperture_config)
282 {
283 aperture_size_parameter = &ParameterLib::findParameter<double>(
285 *aperture_config, "parameter", parameters, 1);
286 }
287
288 auto const is_linear =
290 config.getConfigParameter("linear", false);
291
292 auto const ls_compute_only_upon_timestep_change =
294 config.getConfigParameter(
295 "linear_solver_compute_only_upon_timestep_change", false);
296
297 auto const rotation_matrices = MeshLib::getElementRotationMatrices(
298 mesh_space_dimension, mesh.getDimension(), mesh.getElements());
299 std::vector<Eigen::VectorXd> projected_specific_body_force_vectors;
300 projected_specific_body_force_vectors.reserve(rotation_matrices.size());
301
302 std::transform(rotation_matrices.begin(), rotation_matrices.end(),
303 std::back_inserter(projected_specific_body_force_vectors),
304 [&specific_body_force](const auto& R)
305 { return R * R.transpose() * specific_body_force; });
306
308 std::move(media_map),
309 has_gravity,
310 non_advective_form,
311 temperature_field,
312 chemically_induced_porosity_change,
313 chemical_solver_interface.get(),
314 std::move(lookup_table),
315 std::move(stabilizer),
316 projected_specific_body_force_vectors,
317 mesh_space_dimension,
318 *aperture_size_parameter,
319 isothermal,
320 NumLib::ShapeMatrixCache{integration_order}};
321
322 SecondaryVariableCollection secondary_variables;
323
324 ProcessLib::createSecondaryVariables(config, secondary_variables);
325
326 std::unique_ptr<ProcessLib::SurfaceFluxData> surfaceflux;
327 auto surfaceflux_config =
329 config.getConfigSubtreeOptional("calculatesurfaceflux");
330 if (surfaceflux_config)
331 {
333 *surfaceflux_config, meshes);
334 }
335
336 return std::make_unique<ComponentTransportProcess>(
337 std::move(name), mesh, std::move(jacobian_assembler), parameters,
338 integration_order, std::move(process_variables),
339 std::move(process_data), std::move(secondary_variables),
340 use_monolithic_scheme, std::move(surfaceflux),
341 std::move(chemical_solver_interface), is_linear,
342 ls_compute_only_upon_timestep_change);
343}
344
345} // namespace ComponentTransport
346} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
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:106
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:88
static PROCESSLIB_EXPORT const std::string constant_one_parameter_name
Definition Process.h:47
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:225
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)
Definition Utils.h:166
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::unique_ptr< LookupTable > createLookupTable(std::optional< std::string > const tabular_file, std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > const &process_variables)
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)