OGS 6.1.0-1721-g6382411ad
CreateComponentTransportProcess.cpp
Go to the documentation of this file.
1 
11 
15 
17 
22 
25 namespace ProcessLib
26 {
27 namespace ComponentTransport
28 {
29 std::unique_ptr<Process> createComponentTransportProcess(
30  MeshLib::Mesh& mesh,
31  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
32  std::vector<ProcessVariable> const& variables,
33  std::vector<std::unique_ptr<ParameterBase>> const& parameters,
34  unsigned const integration_order,
35  BaseLib::ConfigTree const& config,
36  std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
37  std::string const& output_directory,
38  std::map<int, std::unique_ptr<MaterialPropertyLib::Medium>> const& media)
39 {
41  config.checkConfigParameter("type", "ComponentTransport");
42 
43  DBUG("Create ComponentTransportProcess.");
44  auto const staggered_scheme =
46  config.getConfigParameterOptional<std::string>("coupling_scheme");
47  const bool use_monolithic_scheme =
48  !(staggered_scheme && (*staggered_scheme == "staggered"));
49 
50  // Process variable.
51 
53  auto const pv_config = config.getConfigSubtree("process_variables");
54 
55  std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
56  process_variables;
57 
58  // Collect all process variables in a vector before allocation
59  // pressure first, concentration then
60  auto const collected_process_variables = findProcessVariables(
61  variables, pv_config,
62  {
63  "pressure",
65  "concentration"});
66 
67  // Check number of components for each process variable
68  auto it = std::find_if(
69  collected_process_variables.cbegin(),
70  collected_process_variables.cend(),
71  [](std::reference_wrapper<ProcessLib::ProcessVariable> const& pv) {
72  return pv.get().getNumberOfComponents() != 1;
73  });
74 
75  if (it != collected_process_variables.end())
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  // Allocate the collected process variables into a two-dimensional vector,
83  // depending on what scheme is adopted
84  if (use_monolithic_scheme) // monolithic scheme.
85  {
86  process_variables.push_back(std::move(collected_process_variables));
87  }
88  else // staggered scheme.
89  {
90  std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>
91  per_process_variable;
92 
93  for (auto& pv : collected_process_variables)
94  {
95  per_process_variable.emplace_back(pv);
96  process_variables.push_back(std::move(per_process_variable));
97  }
98  }
99 
100  MaterialLib::PorousMedium::PorousMediaProperties porous_media_properties{
102  mesh, config, parameters)};
103 
105  auto const& fluid_config = config.getConfigSubtree("fluid");
106 
107  auto fluid_properties =
109 
110  // Parameter for the density of the fluid.
111  auto& fluid_reference_density= findParameter<double>(
112  config,
114  "fluid_reference_density", parameters, 1);
115  DBUG("Use '%s' as fluid_reference_density parameter.",
116  fluid_reference_density.name.c_str());
117 
118  // Parameter for the retardation factor.
119  auto const& retardation_factor =
120  findParameter<double>(config,
122  "retardation_factor", parameters, 1);
123 
124  // Parameter for the decay rate.
125  auto const& decay_rate =
126  findParameter<double>(config,
128  "decay_rate", parameters, 1);
129 
130  // Specific body force parameter.
131  Eigen::VectorXd specific_body_force;
132  std::vector<double> const b =
134  config.getConfigParameter<std::vector<double>>("specific_body_force");
135  assert(b.size() > 0 && b.size() < 4);
136  if (b.size() < mesh.getDimension())
137  OGS_FATAL(
138  "specific body force (gravity vector) has %d components, mesh "
139  "dimension is %d",
140  b.size(), mesh.getDimension());
141  bool const has_gravity = MathLib::toVector(b).norm() > 0;
142  if (has_gravity)
143  {
144  specific_body_force.resize(b.size());
145  std::copy_n(b.data(), b.size(), specific_body_force.data());
146  }
147 
148  auto media_map =
150 
151  ComponentTransportProcessData process_data{
152  std::move(porous_media_properties),
153  fluid_reference_density,
154  std::move(fluid_properties),
155  std::move(media_map),
156  retardation_factor,
157  decay_rate,
158  specific_body_force,
159  has_gravity};
160 
161  SecondaryVariableCollection secondary_variables;
162 
163  NumLib::NamedFunctionCaller named_function_caller(
164  {"ComponentTransport_concentration_pressure"});
165 
166  ProcessLib::createSecondaryVariables(config, secondary_variables,
167  named_function_caller);
168 
169  std::unique_ptr<ProcessLib::SurfaceFluxData> surfaceflux;
170  auto surfaceflux_config =
172  config.getConfigSubtreeOptional("calculatesurfaceflux");
173  if (surfaceflux_config)
174  {
176  *surfaceflux_config, meshes, output_directory);
177  }
178 
179  return std::make_unique<ComponentTransportProcess>(
180  mesh, std::move(jacobian_assembler), parameters, integration_order,
181  std::move(process_variables), std::move(process_data),
182  std::move(secondary_variables), std::move(named_function_caller),
183  use_monolithic_scheme, std::move(surfaceflux));
184 }
185 
186 } // namespace ComponentTransport
187 } // 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.
std::unique_ptr< MaterialSpatialDistributionMap > createMaterialSpatialDistributionMap(std::map< int, std::unique_ptr< Medium >> const &media, MeshLib::Mesh const &mesh)
PorousMediaProperties createPorousMediaProperties(MeshLib::Mesh &mesh, BaseLib::ConfigTree const &configs, std::vector< std::unique_ptr< ProcessLib::ParameterBase >> const &parameters)
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:146
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< 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)
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:71