OGS 6.2.1-97-g73d1aeda3
ComponentTransportProcess.cpp
Go to the documentation of this file.
1 
11 
12 #include <cassert>
13 
17 
18 namespace ProcessLib
19 {
20 namespace ComponentTransport
21 {
23  std::string name,
24  MeshLib::Mesh& mesh,
25  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
26  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
27  unsigned const integration_order,
28  std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
29  process_variables,
30  ComponentTransportProcessData&& process_data,
31  SecondaryVariableCollection&& secondary_variables,
32  NumLib::NamedFunctionCaller&& named_function_caller,
33  bool const use_monolithic_scheme,
34  std::unique_ptr<ProcessLib::SurfaceFluxData>&& surfaceflux,
35  std::vector<std::pair<int, std::string>>&& process_id_to_component_name_map)
36  : Process(std::move(name), mesh, std::move(jacobian_assembler), parameters,
37  integration_order, std::move(process_variables),
38  std::move(secondary_variables), std::move(named_function_caller),
39  use_monolithic_scheme),
40  _process_data(std::move(process_data)),
41  _surfaceflux(std::move(surfaceflux)),
42  _process_id_to_component_name_map(
43  std::move(process_id_to_component_name_map))
44 {
45 }
46 
48  NumLib::LocalToGlobalIndexMap const& dof_table,
49  MeshLib::Mesh const& mesh,
50  unsigned const integration_order)
51 {
52  const int process_id = 0;
53  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
54 
55  std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>
56  transport_process_variables;
58  {
59  for (auto pv_iter = std::next(_process_variables[process_id].begin());
60  pv_iter != _process_variables[process_id].end();
61  ++pv_iter)
62  {
63  transport_process_variables.push_back(*pv_iter);
64  }
65  }
66  else
67  {
68  for (auto pv_iter = std::next(_process_variables.begin());
69  pv_iter != _process_variables.end();
70  ++pv_iter)
71  {
72  transport_process_variables.push_back((*pv_iter)[0]);
73  }
74 
76  }
77 
78  ProcessLib::createLocalAssemblers<LocalAssemblerData>(
79  mesh.getDimension(), mesh.getElements(), dof_table,
81  mesh.isAxiallySymmetric(), integration_order, _process_data,
82  transport_process_variables);
83 
85  "darcy_velocity",
89 }
90 
92  const double t,
93  GlobalVector const& x,
94  GlobalMatrix& M,
95  GlobalMatrix& K,
96  GlobalVector& b)
97 {
98  DBUG("Assemble ComponentTransportProcess.");
99 
100  const int process_id = 0;
101  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
102 
103  std::vector<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
104  dof_tables;
106  {
107  dof_tables.push_back(std::ref(*_local_to_global_index_map));
108  }
109  else
110  {
112  std::generate_n(
113  std::back_inserter(dof_tables), _process_variables.size(),
114  [&]() { return std::ref(*_local_to_global_index_map); });
115  }
116  // Call global assembler for each local assembly item.
119  pv.getActiveElementIDs(), dof_tables, t, x, M, K, b,
121 }
122 
124 {
125  unsigned const number_of_coupled_solutions =
128  _coupled_solutions->coupled_xs_t0.reserve(number_of_coupled_solutions);
129  for (unsigned i = 0; i < number_of_coupled_solutions; ++i)
130  {
131  auto const& x_t0 = _xs_previous_timestep[i];
132  _coupled_solutions->coupled_xs_t0.emplace_back(x_t0.get());
133  }
134 }
135 
137  const double t, GlobalVector const& x, GlobalVector const& xdot,
138  const double dxdot_dx, const double dx_dx, GlobalMatrix& M, GlobalMatrix& K,
139  GlobalVector& b, GlobalMatrix& Jac)
140 {
141  DBUG("AssembleWithJacobian ComponentTransportProcess.");
142 
143  const int process_id = 0;
144  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
145  std::vector<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
146  dof_table = {std::ref(*_local_to_global_index_map)};
147  // Call global assembler for each local assembly item.
150  _local_assemblers, pv.getActiveElementIDs(), dof_table, t, x,
151  xdot, dxdot_dx, dx_dx, M, K, b, Jac, _coupled_solutions);
152 }
153 
154 Eigen::Vector3d ComponentTransportProcess::getFlux(std::size_t const element_id,
155  MathLib::Point3d const& p,
156  double const t,
157  GlobalVector const& x) const
158 {
159  std::vector<GlobalIndexType> indices_cache;
160  auto const r_c_indices = NumLib::getRowColumnIndices(
161  element_id, *_local_to_global_index_map, indices_cache);
162 
164  {
165  std::vector<double> local_x(x.get(r_c_indices.rows));
166 
167  return _local_assemblers[element_id]->getFlux(p, t, local_x);
168  }
169 
170  std::vector<std::vector<GlobalIndexType>>
171  indices_of_all_coupled_processes{
172  _coupled_solutions->coupled_xs.size(), r_c_indices.rows};
173  auto const local_xs = getCurrentLocalSolutions(
174  *(this->_coupled_solutions), indices_of_all_coupled_processes);
175 
176  return _local_assemblers[element_id]->getFlux(p, t, local_xs);
177 }
178 
181 {
182  DBUG("Set the coupled term for the staggered scheme to local assembers.");
183 
184  const int process_id =
186  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
189  setStaggeredCoupledSolutions,
191 }
192 
194  GlobalVector const& x, const double /*t*/, const double /*delta_t*/,
195  int const process_id)
196 {
198  {
199  return;
200  }
201 
202  if (!_xs_previous_timestep[process_id])
203  {
204  _xs_previous_timestep[process_id] =
206  }
207  else
208  {
209  auto& x0 = *_xs_previous_timestep[process_id];
210  MathLib::LinAlg::copy(x, x0);
211  }
212 }
213 
215  GlobalVector const& x,
216  const double t,
217  const double /*delta_t*/,
218  int const process_id)
219 {
220  // For the monolithic scheme, process_id is always zero.
221  if (_use_monolithic_scheme && process_id != 0)
222  {
223  OGS_FATAL(
224  "The condition of process_id = 0 must be satisfied for "
225  "monolithic ComponentTransportProcess, which is a single process.");
226  }
227  if (!_use_monolithic_scheme && process_id != 0)
228  {
229  DBUG(
230  "This is the transport part of the staggered "
231  "ComponentTransportProcess.");
232  return;
233  }
234  if (!_surfaceflux) // computing the surfaceflux is optional
235  {
236  return;
237  }
238 
239  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
240 
241  _surfaceflux->integrate(x, t, *this, process_id, _integration_order,
242  _mesh, pv.getActiveElementIDs());
243  _surfaceflux->save(t);
244 }
245 
246 } // namespace ComponentTransport
247 } // namespace ProcessLib
MeshLib::Mesh & _mesh
Definition: Process.h:287
static void executeSelectedMemberOnDereferenced(Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
std::vector< std::reference_wrapper< ProcessVariable > > const & getProcessVariables(const int process_id) const
Definition: Process.h:125
SecondaryVariableFunctions makeExtrapolator(const unsigned num_components, NumLib::Extrapolator &extrapolator, LocalAssemblerCollection const &local_assemblers, typename NumLib::ExtrapolatableLocalAssemblerCollection< LocalAssemblerCollection >::IntegrationPointValuesMethod integration_point_values_method)
unsigned const _integration_order
Definition: Process.h:310
std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > _process_variables
Definition: Process.h:326
void assemble(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< std::reference_wrapper< NumLib::LocalToGlobalIndexMap >> const &dof_tables, double const t, GlobalVector const &x, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, CoupledSolutionsForStaggeredScheme const *const cpl_xs)
void preTimestepConcreteProcess(GlobalVector const &x, const double, const double, int const process_id) override
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
NumLib::Extrapolator & getExtrapolator() const
Definition: Process.h:152
void assembleWithJacobian(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< std::reference_wrapper< NumLib::LocalToGlobalIndexMap >> const &dof_tables, const double t, GlobalVector const &x, GlobalVector const &xdot, const double dxdot_dx, const double dx_dx, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, GlobalMatrix &Jac, CoupledSolutionsForStaggeredScheme const *const cpl_xs)
bool isAxiallySymmetric() const
Definition: Mesh.h:137
void assembleConcreteProcess(const double t, GlobalVector const &x, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b) override
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _local_to_global_index_map
Definition: Process.h:290
std::vector< std::reference_wrapper< GlobalVector const > > const & coupled_xs
References to the current solutions of the coupled processes.
Builds expression trees of named functions dynamically at runtime.
static void executeSelectedMemberDereferenced(Object &object, Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
SecondaryVariableCollection _secondary_variables
Definition: Process.h:292
Eigen::Vector3d getFlux(std::size_t const element_id, MathLib::Point3d const &p, double const t, GlobalVector const &x) const override
std::vector< std::unique_ptr< GlobalVector > > _xs_previous_timestep
Solutions of the previous time step.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:108
ComponentTransportProcess(std::string name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const &parameters, unsigned const integration_order, std::vector< std::vector< std::reference_wrapper< ProcessVariable >>> &&process_variables, ComponentTransportProcessData &&process_data, SecondaryVariableCollection &&secondary_variables, NumLib::NamedFunctionCaller &&named_function_caller, bool const use_monolithic_scheme, std::unique_ptr< ProcessLib::SurfaceFluxData > &&surfaceflux, std::vector< std::pair< int, std::string >> &&process_id_to_component_name_map)
void assembleWithJacobianConcreteProcess(const double t, GlobalVector const &x, GlobalVector const &xdot, const double dxdot_dx, const double dx_dx, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, GlobalMatrix &Jac) override
CoupledSolutionsForStaggeredScheme * _coupled_solutions
Definition: Process.h:305
Handles configuration of several secondary variables from the project file.
unsigned getShapeFunctionOrder() const
std::unique_ptr< ProcessLib::SurfaceFluxData > _surfaceflux
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition: Mesh.h:81
std::vector< std::unique_ptr< ComponentTransportLocalAssemblerInterface > > _local_assemblers
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
void addSecondaryVariable(std::string const &internal_name, SecondaryVariableFunctions &&fcts)
NumLib::LocalToGlobalIndexMap::RowColumnIndices getRowColumnIndices(std::size_t const id, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< GlobalIndexType > &indices)
virtual std::vector< double > const & getIntPtDarcyVelocity(const double t, GlobalVector const &current_solution, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< double > &cache) const =0
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:36
const bool _use_monolithic_scheme
Definition: Process.h:301
VectorMatrixAssembler _global_assembler
Definition: Process.h:299
std::vector< GlobalVector * > coupled_xs_t0
Pointers to the vector of the solutions of the previous time step.
void postTimestepConcreteProcess(GlobalVector const &x, const double t, const double delta_t, int const process_id) override
std::vector< std::vector< double > > getCurrentLocalSolutions(const CoupledSolutionsForStaggeredScheme &cpl_xs, const std::vector< std::vector< GlobalIndexType >> &indices)
std::vector< std::size_t > & getActiveElementIDs() const