OGS 6.2.1-97-g73d1aeda3
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  std::string name,
30  MeshLib::Mesh& mesh,
31  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
32  std::vector<ProcessVariable> const& variables,
33  std::vector<std::unique_ptr<ParameterLib::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  {
77  OGS_FATAL(
78  "Number of components for process variable '%s' should be 1 rather "
79  "than %d.",
80  it->get().getName().c_str(),
81  it->get().getNumberOfComponents());
82  }
83 
84  std::vector<std::pair<int, std::string>> process_id_to_component_name_map;
85  // Allocate the collected process variables into a two-dimensional vector,
86  // depending on what scheme is adopted
87  if (use_monolithic_scheme) // monolithic scheme.
88  {
89  process_variables.push_back(std::move(collected_process_variables));
90  }
91  else // staggered scheme.
92  {
93  std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>
94  per_process_variable;
95 
96  for (auto& pv : collected_process_variables)
97  {
98  per_process_variable.emplace_back(pv);
99  process_variables.push_back(std::move(per_process_variable));
100  }
101 
102  auto variable_id = 0;
103  for (unsigned process_id = 1; process_id < process_variables.size();
104  process_id++)
105  {
106  auto const& transport_process_variable =
107  process_variables[process_id][variable_id].get().getName();
108  process_id_to_component_name_map.emplace_back(
109  process_id, transport_process_variable);
110  }
111  }
112 
113  MaterialLib::PorousMedium::PorousMediaProperties porous_media_properties{
115  mesh, config, parameters)};
116 
118  auto const& fluid_config = config.getConfigSubtree("fluid");
119 
120  auto fluid_properties =
122 
123  // Parameter for the density of the fluid.
124  auto& fluid_reference_density = ParameterLib::findParameter<double>(
125  config,
127  "fluid_reference_density", parameters, 1);
128  DBUG("Use '%s' as fluid_reference_density parameter.",
129  fluid_reference_density.name.c_str(), &mesh);
130 
131  // Parameter for the decay rate.
132  auto const& decay_rate = ParameterLib::findParameter<double>(
133  config,
135  "decay_rate", parameters, 1, &mesh);
136 
137  // Specific body force parameter.
138  Eigen::VectorXd specific_body_force;
139  std::vector<double> const b =
141  config.getConfigParameter<std::vector<double>>("specific_body_force");
142  assert(!b.empty() && b.size() < 4);
143  if (b.size() < mesh.getDimension())
144  {
145  OGS_FATAL(
146  "specific body force (gravity vector) has %d components, mesh "
147  "dimension is %d",
148  b.size(), mesh.getDimension());
149  }
150  bool const has_gravity = MathLib::toVector(b).norm() > 0;
151  if (has_gravity)
152  {
153  specific_body_force.resize(b.size());
154  std::copy_n(b.data(), b.size(), specific_body_force.data());
155  }
156 
157  bool const non_advective_form =
159  config.getConfigParameter<bool>("non_advective_form", false);
160 
161  auto media_map =
163 
164  ComponentTransportProcessData process_data{
165  std::move(porous_media_properties),
166  fluid_reference_density,
167  std::move(fluid_properties),
168  std::move(media_map),
169  decay_rate,
170  specific_body_force,
171  has_gravity,
172  non_advective_form};
173 
174  SecondaryVariableCollection secondary_variables;
175 
176  NumLib::NamedFunctionCaller named_function_caller(
177  {"ComponentTransport_concentration_pressure"});
178 
179  ProcessLib::createSecondaryVariables(config, secondary_variables,
180  named_function_caller);
181 
182  std::unique_ptr<ProcessLib::SurfaceFluxData> surfaceflux;
183  auto surfaceflux_config =
185  config.getConfigSubtreeOptional("calculatesurfaceflux");
186  if (surfaceflux_config)
187  {
189  *surfaceflux_config, meshes, output_directory);
190  }
191 
192  return std::make_unique<ComponentTransportProcess>(
193  std::move(name), mesh, std::move(jacobian_assembler), parameters,
194  integration_order, std::move(process_variables),
195  std::move(process_data), std::move(secondary_variables),
196  std::move(named_function_caller), use_monolithic_scheme,
197  std::move(surfaceflux), std::move(process_id_to_component_name_map));
198 }
199 
200 } // namespace ComponentTransport
201 } // 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< 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
std::unique_ptr< Process > createComponentTransportProcess(std::string 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::string const &output_directory, std::map< int, std::unique_ptr< MaterialPropertyLib::Medium >> const &media)