OGS 6.2.0-97-g4a610c866
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  MeshLib::Mesh& mesh,
24  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
25  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
26  unsigned const integration_order,
27  std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
28  process_variables,
29  ComponentTransportProcessData&& process_data,
30  SecondaryVariableCollection&& secondary_variables,
31  NumLib::NamedFunctionCaller&& named_function_caller,
32  bool const use_monolithic_scheme,
33  std::unique_ptr<ProcessLib::SurfaceFluxData>&& surfaceflux)
34  : Process(mesh, std::move(jacobian_assembler), parameters,
35  integration_order, std::move(process_variables),
36  std::move(secondary_variables), std::move(named_function_caller),
37  use_monolithic_scheme),
38  _process_data(std::move(process_data)),
39  _surfaceflux(std::move(surfaceflux))
40 {
41 }
42 
44  NumLib::LocalToGlobalIndexMap const& dof_table,
45  MeshLib::Mesh const& mesh,
46  unsigned const integration_order)
47 {
48  const int process_id = 0;
49  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
50 
51  std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>
52  transport_process_variables;
54  {
55  for (auto pv_iter = std::next(_process_variables[process_id].begin());
56  pv_iter != _process_variables[process_id].end();
57  ++pv_iter)
58  transport_process_variables.push_back(*pv_iter);
59  }
60  else
61  {
62  for (auto pv_iter = std::next(_process_variables.begin());
63  pv_iter != _process_variables.end();
64  ++pv_iter)
65  transport_process_variables.push_back((*pv_iter)[0]);
66 
68  }
69 
70  ProcessLib::createLocalAssemblers<LocalAssemblerData>(
71  mesh.getDimension(), mesh.getElements(), dof_table,
73  mesh.isAxiallySymmetric(), integration_order, _process_data,
74  transport_process_variables);
75 
77  "darcy_velocity",
81 }
82 
84  const double t,
85  GlobalVector const& x,
86  GlobalMatrix& M,
87  GlobalMatrix& K,
88  GlobalVector& b)
89 {
90  DBUG("Assemble ComponentTransportProcess.");
91 
92  const int process_id = 0;
93  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
94 
95  std::vector<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
96  dof_tables;
98  {
99  dof_tables.push_back(std::ref(*_local_to_global_index_map));
100  }
101  else
102  {
104  std::generate_n(
105  std::back_inserter(dof_tables), _process_variables.size(),
106  [&]() { return std::ref(*_local_to_global_index_map); });
107  }
108  // Call global assembler for each local assembly item.
111  pv.getActiveElementIDs(), dof_tables, t, x, M, K, b,
113 }
114 
116 {
117  unsigned const number_of_coupled_solutions =
120  _coupled_solutions->coupled_xs_t0.reserve(number_of_coupled_solutions);
121  for (unsigned i = 0; i < number_of_coupled_solutions; ++i)
122  {
123  auto const& x_t0 = _xs_previous_timestep[i];
124  _coupled_solutions->coupled_xs_t0.emplace_back(x_t0.get());
125  }
126 }
127 
129  const double t, GlobalVector const& x, GlobalVector const& xdot,
130  const double dxdot_dx, const double dx_dx, GlobalMatrix& M, GlobalMatrix& K,
131  GlobalVector& b, GlobalMatrix& Jac)
132 {
133  DBUG("AssembleWithJacobian ComponentTransportProcess.");
134 
135  const int process_id = 0;
136  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
137  std::vector<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
138  dof_table = {std::ref(*_local_to_global_index_map)};
139  // Call global assembler for each local assembly item.
142  _local_assemblers, pv.getActiveElementIDs(), dof_table, t, x,
143  xdot, dxdot_dx, dx_dx, M, K, b, Jac, _coupled_solutions);
144 }
145 
146 Eigen::Vector3d ComponentTransportProcess::getFlux(std::size_t const element_id,
147  MathLib::Point3d const& p,
148  double const t,
149  GlobalVector const& x) const
150 {
151  std::vector<GlobalIndexType> indices_cache;
152  auto const r_c_indices = NumLib::getRowColumnIndices(
153  element_id, *_local_to_global_index_map, indices_cache);
154 
156  {
157  std::vector<double> local_x(x.get(r_c_indices.rows));
158 
159  return _local_assemblers[element_id]->getFlux(p, t, local_x);
160  }
161  else
162  {
163  std::vector<std::vector<GlobalIndexType>>
164  indices_of_all_coupled_processes{
165  _coupled_solutions->coupled_xs.size(), r_c_indices.rows};
166  auto const local_xs = getCurrentLocalSolutions(
167  *(this->_coupled_solutions), indices_of_all_coupled_processes);
168 
169  return _local_assemblers[element_id]->getFlux(p, t, local_xs);
170  }
171 }
172 
175 {
176  DBUG("Set the coupled term for the staggered scheme to local assembers.");
177 
178  const int process_id =
180  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
183  setStaggeredCoupledSolutions,
185 }
186 
188  GlobalVector const& x, const double /*t*/, const double /*delta_t*/,
189  int const process_id)
190 {
192  {
193  return;
194  }
195 
196  if (!_xs_previous_timestep[process_id])
197  {
198  _xs_previous_timestep[process_id] =
200  }
201  else
202  {
203  auto& x0 = *_xs_previous_timestep[process_id];
204  MathLib::LinAlg::copy(x, x0);
205  }
206 }
207 
209  GlobalVector const& x,
210  const double t,
211  const double /*delta_t*/,
212  int const process_id)
213 {
214  // For the monolithic scheme, process_id is always zero.
215  if (_use_monolithic_scheme && process_id != 0)
216  {
217  OGS_FATAL(
218  "The condition of process_id = 0 must be satisfied for "
219  "monolithic ComponentTransportProcess, which is a single process.");
220  }
221  if (!_use_monolithic_scheme && process_id != 0)
222  {
223  DBUG(
224  "This is the transport part of the staggered "
225  "ComponentTransportProcess.");
226  return;
227  }
228  if (!_surfaceflux) // computing the surfaceflux is optional
229  {
230  return;
231  }
232 
233  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
234 
235  _surfaceflux->integrate(x, t, *this, process_id, _integration_order,
236  _mesh, pv.getActiveElementIDs());
237  _surfaceflux->save(t);
238 }
239 
240 } // namespace ComponentTransport
241 } // namespace ProcessLib
MeshLib::Mesh & _mesh
Definition: Process.h:262
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:124
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:285
std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > _process_variables
Definition: Process.h:301
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:151
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:265
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.
ComponentTransportProcess(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)
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:267
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
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:280
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:276
VectorMatrixAssembler _global_assembler
Definition: Process.h:274
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