OGS
HTProcess.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "HTProcess.h"
5
6#include <cassert>
7
8#include "MonolithicHTFEM.h"
15#include "StaggeredHTFEM.h"
16
17namespace ProcessLib
18{
19namespace HT
20{
22 std::string name,
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 HTProcessData&& process_data,
30 SecondaryVariableCollection&& secondary_variables,
31 bool const use_monolithic_scheme,
32 std::unique_ptr<ProcessLib::SurfaceFluxData>&& surfaceflux)
33 : Process(std::move(name), mesh, std::move(jacobian_assembler), parameters,
34 integration_order, std::move(process_variables),
35 std::move(secondary_variables), use_monolithic_scheme),
36 _process_data(std::move(process_data)),
37 _surfaceflux(std::move(surfaceflux))
38{
39 this->_jacobian_assembler->checkPerturbationSize(2);
41 {
42 this->_jacobian_assembler->setNonDeformationComponentIDsNoSizeCheck(
43 {0, 1} /* two variables: pressure and temperature */);
44 }
45}
46
48 NumLib::LocalToGlobalIndexMap const& dof_table,
49 MeshLib::Mesh const& mesh,
50 unsigned const integration_order)
51{
52 int const mesh_space_dimension = _process_data.mesh_space_dimension;
53
55 {
57 mesh_space_dimension, mesh.getElements(), dof_table,
60 }
61 else
62 {
64 mesh_space_dimension, mesh.getElements(), dof_table,
67 }
68
71
72 _secondary_variables.addSecondaryVariable(
73 "darcy_velocity",
74 makeExtrapolator(mesh_space_dimension, getExtrapolator(),
77}
78
80 const double t, double const dt, std::vector<GlobalVector*> const& x,
81 std::vector<GlobalVector*> const& x_prev, int const process_id,
83{
84 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
86 {
87 DBUG("Assemble HTProcess.");
88 dof_tables.emplace_back(_local_to_global_index_map.get());
89 }
90 else
91 {
92 if (process_id == _process_data.heat_transport_process_id)
93 {
94 DBUG(
95 "Assemble the equations of heat transport process within "
96 "HTProcess.");
97 }
98 else
99 {
100 DBUG(
101 "Assemble the equations of single phase fully saturated "
102 "fluid flow process within HTProcess.");
103 }
104 dof_tables.emplace_back(_local_to_global_index_map.get());
105 dof_tables.emplace_back(_local_to_global_index_map.get());
106
107 // For numerical Jacobian assembler
108 // (only one variable per process in staggered scheme);
109 this->_jacobian_assembler->setNonDeformationComponentIDsNoSizeCheck(
110 {process_id});
111 }
112
113 // Call global assembler for each local assembly item.
116 getActiveElementIDs(), dof_tables, t, dt, x, x_prev, process_id, &M, &K,
117 &b);
118}
119
121 const double t, double const dt, std::vector<GlobalVector*> const& x,
122 std::vector<GlobalVector*> const& x_prev, int const process_id,
123 GlobalVector& b, GlobalMatrix& Jac)
124{
125 DBUG("AssembleWithJacobian HTProcess.");
126
127 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
129 {
130 dof_tables.emplace_back(_local_to_global_index_map.get());
131 }
132 else
133 {
134 dof_tables.emplace_back(_local_to_global_index_map.get());
135 dof_tables.emplace_back(_local_to_global_index_map.get());
136 }
137
138 // Call global assembler for each local assembly item.
141 _local_assemblers, getActiveElementIDs(), dof_tables, t, dt, x, x_prev,
142 process_id, &b, &Jac);
143}
144
145std::tuple<NumLib::LocalToGlobalIndexMap*, bool>
147{
149 {
150 // For single-variable-single-component processes reuse the existing DOF
151 // table.
152 const bool manage_storage = false;
153 return std::make_tuple(_local_to_global_index_map.get(),
154 manage_storage);
155 }
156
157 // Otherwise construct a new DOF table.
158 std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component{
160
161 const bool manage_storage = true;
162 return std::make_tuple(new NumLib::LocalToGlobalIndexMap(
163 std::move(all_mesh_subsets_single_component),
164 // by location order is needed for output
166 manage_storage);
167}
168
169Eigen::Vector3d HTProcess::getFlux(std::size_t element_id,
170 MathLib::Point3d const& p,
171 double const t,
172 std::vector<GlobalVector*> const& x) const
173{
174 // fetch local_x from primary variable
175 std::vector<GlobalIndexType> indices_cache;
176 auto const r_c_indices = NumLib::getRowColumnIndices(
177 element_id, *_local_to_global_index_map, indices_cache);
178 std::vector<std::vector<GlobalIndexType>> indices_of_all_coupled_processes{
179 x.size(), r_c_indices.rows};
180 auto const local_x =
181 getCoupledLocalSolutions(x, indices_of_all_coupled_processes);
182
183 return _local_assemblers[element_id]->getFlux(p, t, local_x);
184}
185
186// this is almost a copy of the implementation in the GroundwaterFlow
188 std::vector<GlobalVector*> const& x,
189 std::vector<GlobalVector*> const& /*x_prev*/,
190 const double t,
191 const double /*delta_t*/,
192 int const process_id)
193{
194 // For the monolithic scheme, process_id is always zero.
195 if (_use_monolithic_scheme && process_id != 0)
196 {
197 OGS_FATAL(
198 "The condition of process_id = 0 must be satisfied for monolithic "
199 "HTProcess, which is a single process.");
200 }
202 process_id != _process_data.hydraulic_process_id)
203 {
204 DBUG("This is the thermal part of the staggered HTProcess.");
205 return;
206 }
207 if (!_surfaceflux) // computing the surfaceflux is optional
208 {
209 return;
210 }
211
212 _surfaceflux->integrate(x, t, *this, process_id, _integration_order, _mesh,
214}
215} // namespace HT
216} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:10
MathLib::EigenMatrix GlobalMatrix
MathLib::EigenVector GlobalVector
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
bool isAxiallySymmetric() const
Definition Mesh.h:130
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:101
virtual std::vector< double > const & getIntPtDarcyVelocity(const double, std::vector< GlobalVector * > const &x, std::vector< NumLib::LocalToGlobalIndexMap const * > const &, std::vector< double > &) const =0
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
Definition HTProcess.cpp:47
void assembleWithJacobianConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector &b, GlobalMatrix &Jac) override
std::tuple< NumLib::LocalToGlobalIndexMap *, bool > getDOFTableForExtrapolatorData() const override
HTProcess(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, HTProcessData &&process_data, SecondaryVariableCollection &&secondary_variables, bool const use_monolithic_scheme, std::unique_ptr< ProcessLib::SurfaceFluxData > &&surfaceflux)
Definition HTProcess.cpp:21
std::unique_ptr< ProcessLib::SurfaceFluxData > _surfaceflux
Definition HTProcess.h:156
Eigen::Vector3d getFlux(std::size_t element_id, MathLib::Point3d const &p, double const t, std::vector< GlobalVector * > const &x) const override
HTProcessData _process_data
Definition HTProcess.h:152
void assembleConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b) override
Definition HTProcess.cpp:79
void postTimestepConcreteProcess(std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, const double t, const double delta_t, int const process_id) override
std::vector< std::unique_ptr< HTLocalAssemblerInterface > > _local_assemblers
Definition HTProcess.h:154
virtual void initialize(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table)
std::string const name
Definition Process.h:361
Process(std::string name_, MeshLib::Mesh &mesh, std::unique_ptr< 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, SecondaryVariableCollection &&secondary_variables, const bool use_monolithic_scheme=true)
Definition Process.cpp:37
std::unique_ptr< MeshLib::MeshSubset const > _mesh_subset_all_nodes
Definition Process.h:365
MeshLib::Mesh & _mesh
Definition Process.h:364
std::vector< std::size_t > const & getActiveElementIDs() const
Definition Process.h:160
SecondaryVariableCollection _secondary_variables
Definition Process.h:369
VectorMatrixAssembler _global_assembler
Definition Process.h:376
unsigned const _integration_order
Definition Process.h:383
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _local_to_global_index_map
Definition Process.h:367
std::unique_ptr< ProcessLib::AbstractJacobianAssembler > _jacobian_assembler
Definition Process.h:375
NumLib::Extrapolator & getExtrapolator() const
Definition Process.h:201
const bool _use_monolithic_scheme
Definition Process.h:378
Handles configuration of several secondary variables from the project file.
void assemble(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix *M, GlobalMatrix *K, GlobalVector *b)
void assembleWithJacobian(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector *b, GlobalMatrix *Jac)
NumLib::LocalToGlobalIndexMap::RowColumnIndices getRowColumnIndices(std::size_t const id, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< GlobalIndexType > &indices)
@ BY_LOCATION
Ordering data by spatial location.
void createLocalAssemblers(std::vector< MeshLib::Element * > const &mesh_elements, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< std::unique_ptr< LocalAssemblerInterface > > &local_assemblers, ProviderOrOrder const &provider_or_order, ExtraCtorArgs &&... extra_ctor_args)
std::vector< double > getCoupledLocalSolutions(std::vector< GlobalVector * > const &global_solutions, std::vector< std::vector< GlobalIndexType > > const &indices)
SecondaryVariableFunctions makeExtrapolator(const unsigned num_components, NumLib::Extrapolator &extrapolator, LocalAssemblerCollection const &local_assemblers, typename NumLib::ExtrapolatableLocalAssemblerCollection< LocalAssemblerCollection >::IntegrationPointValuesMethod integration_point_values_method)
static void executeSelectedMemberDereferenced(Object &object, Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)