OGS 6.2.0-97-g4a610c866
CreateComponentTransportProcess.cpp
Go to the documentation of this file.
1 
11 
17 #include "ParameterLib/Utils.h"
21 
24 namespace ProcessLib
25 {
26 namespace ComponentTransport
27 {
28 std::unique_ptr<Process> createComponentTransportProcess(
29  MeshLib::Mesh& mesh,
30  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
31  std::vector<ProcessVariable> const& variables,
32  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
33  unsigned const integration_order,
34  BaseLib::ConfigTree const& config,
35  std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
36  std::string const& output_directory,
37  std::map<int, std::unique_ptr<MaterialPropertyLib::Medium>> const& media)
38 {
40  config.checkConfigParameter("type", "ComponentTransport");
41 
42  DBUG("Create ComponentTransportProcess.");
43  auto const staggered_scheme =
45  config.getConfigParameterOptional<std::string>("coupling_scheme");
46  const bool use_monolithic_scheme =
47  !(staggered_scheme && (*staggered_scheme == "staggered"));
48 
49  // Process variable.
50 
52  auto const pv_config = config.getConfigSubtree("process_variables");
53 
54  std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
55  process_variables;
56 
57  // Collect all process variables in a vector before allocation
58  // pressure first, concentration then
59  auto const collected_process_variables = findProcessVariables(
60  variables, pv_config,
61  {
62  "pressure",
64  "concentration"});
65 
66  // Check number of components for each process variable
67  auto it = std::find_if(
68  collected_process_variables.cbegin(),
69  collected_process_variables.cend(),
70  [](std::reference_wrapper<ProcessLib::ProcessVariable> const& pv) {
71  return pv.get().getNumberOfComponents() != 1;
72  });
73 
74  if (it != collected_process_variables.end())
75  {
76  OGS_FATAL(
77  "Number of components for process variable '%s' should be 1 rather "
78  "than %d.",
79  it->get().getName().c_str(),
80  it->get().getNumberOfComponents());
81  }
82 
83  // Allocate the collected process variables into a two-dimensional vector,
84  // depending on what scheme is adopted
85  if (use_monolithic_scheme) // monolithic scheme.
86  {
87  process_variables.push_back(std::move(collected_process_variables));
88  }
89  else // staggered scheme.
90  {
91  std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>
92  per_process_variable;
93 
94  for (auto& pv : collected_process_variables)
95  {
96  per_process_variable.emplace_back(pv);
97  process_variables.push_back(std::move(per_process_variable));
98  }
99  }
100 
101  MaterialLib::PorousMedium::PorousMediaProperties porous_media_properties{
103  mesh, config, parameters)};
104 
106  auto const& fluid_config = config.getConfigSubtree("fluid");
107 
108  auto fluid_properties =
110 
111  // Parameter for the density of the fluid.
112  auto& fluid_reference_density = ParameterLib::findParameter<double>(
113  config,
115  "fluid_reference_density", parameters, 1);
116  DBUG("Use '%s' as fluid_reference_density parameter.",
117  fluid_reference_density.name.c_str());
118 
119  // Parameter for the retardation factor.
120  auto const& retardation_factor = ParameterLib::findParameter<double>(
121  config,
123  "retardation_factor", parameters, 1);
124 
125  // Parameter for the decay rate.
126  auto const& decay_rate = ParameterLib::findParameter<double>(
127  config,
129  "decay_rate", parameters, 1);
130 
131  // Specific body force parameter.
132  Eigen::VectorXd specific_body_force;
133  std::vector<double> const b =
135  config.getConfigParameter<std::vector<double>>("specific_body_force");
136  assert(b.size() > 0 && b.size() < 4);
137  if (b.size() < mesh.getDimension())
138  {
139  OGS_FATAL(
140  "specific body force (gravity vector) has %d components, mesh "
141  "dimension is %d",
142  b.size(), mesh.getDimension());
143  }
144  bool const has_gravity = MathLib::toVector(b).norm() > 0;
145  if (has_gravity)
146  {
147  specific_body_force.resize(b.size());
148  std::copy_n(b.data(), b.size(), specific_body_force.data());
149  }
150 
151  auto media_map =
153 
154  ComponentTransportProcessData process_data{
155  std::move(porous_media_properties),
156  fluid_reference_density,
157  std::move(fluid_properties),
158  std::move(media_map),
159  retardation_factor,
160  decay_rate,
161  specific_body_force,
162  has_gravity};
163 
164  SecondaryVariableCollection secondary_variables;
165 
166  NumLib::NamedFunctionCaller named_function_caller(
167  {"ComponentTransport_concentration_pressure"});
168 
169  ProcessLib::createSecondaryVariables(config, secondary_variables,
170  named_function_caller);
171 
172  std::unique_ptr<ProcessLib::SurfaceFluxData> surfaceflux;
173  auto surfaceflux_config =
175  config.getConfigSubtreeOptional("calculatesurfaceflux");
176  if (surfaceflux_config)
177  {
179  *surfaceflux_config, meshes, output_directory);
180  }
181 
182  return std::make_unique<ComponentTransportProcess>(
183  mesh, std::move(jacobian_assembler), parameters, integration_order,
184  std::move(process_variables), std::move(process_data),
185  std::move(secondary_variables), std::move(named_function_caller),
186  use_monolithic_scheme, std::move(surfaceflux));
187 }
188 
189 } // namespace ComponentTransport
190 } // namespace ProcessLib
void createSecondaryVariables(BaseLib::ConfigTree const &config, SecondaryVariableCollection &secondary_variables, NumLib::NamedFunctionCaller &named_function_caller)
Eigen::Map< const Vector > toVector(std::vector< double > const &data, Eigen::VectorXd::Index size)
Creates an Eigen mapped vector from the given data vector.
PorousMediaProperties createPorousMediaProperties(MeshLib::Mesh &mesh, BaseLib::ConfigTree const &configs, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const &parameters)
std::unique_ptr< Process > createComponentTransportProcess(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::string const &output_directory, std::map< int, std::unique_ptr< MaterialPropertyLib::Medium >> const &media)
std::unique_ptr< MaterialSpatialDistributionMap > createMaterialSpatialDistributionMap(std::map< int, std::unique_ptr< Medium >> const &media, MeshLib::Mesh const &mesh)
std::vector< std::reference_wrapper< ProcessVariable > > findProcessVariables(std::vector< ProcessVariable > const &variables, BaseLib::ConfigTree const &pv_config, std::initializer_list< std::string > tags)
Builds expression trees of named functions dynamically at runtime.
std::unique_ptr< FluidProperties > createFluidProperties(BaseLib::ConfigTree const &config)
static std::unique_ptr< ProcessLib::SurfaceFluxData > createSurfaceFluxData(BaseLib::ConfigTree const &calculatesurfaceflux_config, std::vector< std::unique_ptr< MeshLib::Mesh >> const &meshes, std::string const &output_directory)
Definition of readMeshFromFile function.
void checkConfigParameter(std::string const &param, T const &value) const
ConfigTree getConfigSubtree(std::string const &root) const
Definition: ConfigTree.cpp:150
Handles configuration of several secondary variables from the project file.
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition: Mesh.h:81
boost::optional< T > getConfigParameterOptional(std::string const &param) const
#define OGS_FATAL(fmt,...)
Definition: Error.h:63