8#include <range/v3/algorithm/copy.hpp>
9#include <range/v3/view/drop.hpp>
37 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
38 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>
const& parameters,
39 unsigned const integration_order,
40 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
44 bool const use_monolithic_scheme,
45 std::unique_ptr<ProcessLib::SurfaceFluxData>&& surfaceflux,
46 std::unique_ptr<ChemistryLib::ChemicalSolverInterface>&&
47 chemical_solver_interface,
49 bool const ls_compute_only_upon_timestep_change)
50 :
Process(std::move(
name), mesh, std::move(jacobian_assembler), parameters,
51 integration_order, std::move(process_variables),
52 std::move(secondary_variables), use_monolithic_scheme),
54 use_monolithic_scheme},
55 _process_data(std::move(process_data)),
56 _surfaceflux(std::move(surfaceflux)),
57 _chemical_solver_interface(std::move(chemical_solver_interface)),
58 _ls_compute_only_upon_timestep_change{
59 ls_compute_only_upon_timestep_change}
61 this->_jacobian_assembler->checkPerturbationSize(_process_variables.size());
63 if (ls_compute_only_upon_timestep_change)
69 "Using the linear solver compute() method only upon timestep "
70 "change only makes sense for linear model equations.");
74 "You specified that the ComponentTransport linear solver will do "
75 "the compute() step only upon timestep change. This is an expert "
76 "option. It is your responsibility to ensure that "
77 "the conditions for the correct use of this feature are met! "
78 "Otherwise OGS might compute garbage without being recognized. "
79 "There is no safety net!");
82 "You specified that the ComponentTransport linear solver will do "
83 "the compute() step only upon timestep change. This option will "
84 "only be used by the Picard non-linear solver. The Newton-Raphson "
85 "non-linear solver will silently ignore this setting, i.e., it "
86 "won't do any harm, there, but you won't observe the speedup you "
90 if (_use_monolithic_scheme)
93 std::vector<int> non_deformation_component_ids(
94 _process_variables.size());
95 std::iota(non_deformation_component_ids.begin(),
96 non_deformation_component_ids.end(), 0);
97 this->_jacobian_assembler->setNonDeformationComponentIDsNoSizeCheck(
98 non_deformation_component_ids);
105 unsigned const integration_order)
107 int const mesh_space_dimension =
_process_data.mesh_space_dimension;
117 std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>
118 transport_process_variables;
121 const int process_id = 0;
126 transport_process_variables.push_back(*pv_iter);
133 for (
auto const& pv :
137 transport_process_variables.push_back(pv[0]);
167 for (std::size_t component_id = 0;
168 component_id < transport_process_variables.size();
171 auto const& pv = transport_process_variables[component_id].get();
173 auto integration_point_values_accessor =
177 std::vector<GlobalVector*>
const& x,
178 std::vector<NumLib::LocalToGlobalIndexMap const*>
const&
180 std::vector<double>& cache) ->
auto const&
187 pv.getName() +
"Flux",
190 integration_point_values_accessor));
195 std::vector<GlobalVector*>& x,
double const t,
int const process_id)
202 if (process_id !=
static_cast<int>(x.size() - 1))
208 x.begin(), x.end(), [](
auto const process_solution)
209 { MathLib::LinAlg::setLocalAccessibleVector(*process_solution); });
211 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
212 dof_tables.reserve(x.size());
213 std::generate_n(std::back_inserter(dof_tables), x.size(),
214 [&]() { return _local_to_global_index_map.get(); });
223 const double t,
double const dt, std::vector<GlobalVector*>
const& x,
224 std::vector<GlobalVector*>
const& x_prev,
int const process_id,
227 DBUG(
"Assemble ComponentTransportProcess.");
236 process_id, M, K, b);
248 matrix_specification, M, K, b);
252 const double t,
double const dt, std::vector<GlobalVector*>
const& x,
253 std::vector<GlobalVector*>
const& x_prev,
int const process_id,
256 DBUG(
"AssembleWithJacobian ComponentTransportProcess.");
261 "The AssembleWithJacobian() for ComponentTransportProcess is "
262 "implemented only for staggered scheme.");
266 t, dt, x, x_prev, process_id, b, Jac);
270 std::size_t
const element_id,
273 std::vector<GlobalVector*>
const& x)
const
275 std::vector<GlobalIndexType> indices_cache;
279 std::vector<std::vector<GlobalIndexType>> indices_of_all_coupled_processes{
280 x.size(), r_c_indices.rows};
281 auto const local_xs =
288 std::vector<GlobalVector*>& x, std::vector<GlobalVector*>
const& x_prev,
290 int const process_id)
295 INFO(
"Update process solutions via the look-up table approach");
309 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
310 dof_tables.reserve(x.size());
311 std::generate_n(std::back_inserter(dof_tables), x.size(),
312 [&]() { return _local_to_global_index_map.get(); });
319 dof_tables, x, t, dt);
322 time_phreeqc.
start();
328 INFO(
"[time] Phreeqc took {:g} s.", time_phreeqc.
elapsed());
332 postSpeciationCalculation,
341 std::size_t matrix_id = 0u;
343 matrix_specification, matrix_id);
345 matrix_specification, matrix_id);
364 matrix_specification, matrix_id);
384 auto& equation_system =
static_cast<EqSys&
>(ode_sys);
385 equation_system.applyKnownSolutionsPicard(
386 A, rhs, *x[process_id],
389 auto& linear_solver =
392 linear_solver.solve(A, rhs, *x[process_id]);
404 std::vector<GlobalVector*>
const& x,
406 int const process_id)
413 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
414 dof_tables.reserve(x.size());
415 std::generate_n(std::back_inserter(dof_tables), x.size(),
416 [&]() { return _local_to_global_index_map.get(); });
430 computeReactionRelatedSecondaryVariable,
434std::vector<std::vector<std::string>>
436 std::vector<std::reference_wrapper<MeshLib::Mesh>>
const& meshes)
438 DBUG(
"CT process initializeSubmeshOutput().");
440 namespace R = ranges;
441 namespace RV = ranges::views;
443 auto get_residuum_name =
446 std::string
const& pv_name = pv.getName();
447 if (pv_name ==
"pressure")
449 return "LiquidMassFlowRate";
451 if (pv_name ==
"temperature")
453 return "HeatFlowRate";
455 return pv_name +
"FlowRate";
458 auto get_residuum_names = [get_residuum_name](
auto const& pvs)
459 {
return pvs | RV::transform(get_residuum_name); };
462 RV::transform(get_residuum_names) |
463 R::to<std::vector<std::vector<std::string>>>();
466 meshes, residuum_names);
468 return residuum_names;
472 std::vector<GlobalVector*>
const& ,
475 const int process_id)
484 std::vector<GlobalVector*>
const& x,
485 std::vector<GlobalVector*>
const& x_prev,
488 int const process_id)
495 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
496 dof_tables.reserve(x.size());
497 std::generate_n(std::back_inserter(dof_tables), x.size(),
498 [&]() { return _local_to_global_index_map.get(); });
516 std::vector<GlobalVector*>
const& x,
517 std::vector<GlobalVector*>
const& x_prev,
518 int const process_id)
Interface for coupling OpenGeoSys with an external geochemical solver.
MathLib::EigenMatrix GlobalMatrix
MathLib::EigenVector GlobalVector
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
double elapsed() const
Get the elapsed time in seconds.
void start()
Start the timer.
bool isAxiallySymmetric() const
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
void assemble(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, std::vector< std::size_t > const *const sorted_element_subset=nullptr, bool const copy_residua_to_mesh=false)
void updateActiveElements()
void preOutput(double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id)
void initializeAssemblyOnSubmeshes(std::vector< std::reference_wrapper< MeshLib::Mesh > > const &submeshes, std::vector< std::vector< std::string > > const &residuum_names)
void assembleWithJacobian(double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector &b, GlobalMatrix &Jac, std::vector< std::size_t > const *const sorted_element_subset=nullptr, bool const copy_residua_to_mesh=false)
virtual std::vector< double > const & getIntPtLiquidDensity(const double t, std::vector< GlobalVector * > const &x, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_table, std::vector< double > &cache) const =0
virtual std::vector< double > const & getIntPtDarcyVelocity(const double t, std::vector< GlobalVector * > const &x, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_table, std::vector< double > &cache) const =0
virtual void setChemicalSystemID(std::size_t const)=0
void initializeChemicalSystem(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, std::vector< GlobalVector * > const &x, double const t)
void setChemicalSystem(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, std::vector< GlobalVector * > const &x, double const t, double const dt)
void assembleReactionEquation(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, std::vector< GlobalVector * > const &x, double const t, double const dt, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, int const process_id)
virtual std::vector< double > const & getIntPtMolarFlux(const double t, std::vector< GlobalVector * > const &x, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_table, std::vector< double > &cache, int const component_id) const =0
std::vector< std::vector< std::string > > initializeAssemblyOnSubmeshes(std::vector< std::reference_wrapper< MeshLib::Mesh > > const &meshes) override
void setInitialConditionsConcreteProcess(std::vector< GlobalVector * > &x, double const t, int const process_id) override
void preOutputConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id) override
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
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
std::unique_ptr< ChemistryLib::ChemicalSolverInterface > _chemical_solver_interface
ComponentTransportProcessData _process_data
void preTimestepConcreteProcess(std::vector< GlobalVector * > const &, const double, const double, const int) override
void computeSecondaryVariableConcrete(double const, double const, std::vector< GlobalVector * > const &x, GlobalVector const &, int const) override
void solveReactionEquation(std::vector< GlobalVector * > &x, std::vector< GlobalVector * > const &x_prev, double const t, double const dt, NumLib::EquationSystem &ode_sys, int const process_id) override
std::vector< std::unique_ptr< ComponentTransportLocalAssemblerInterface > > local_assemblers_
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
void postTimestepConcreteProcess(std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, const double t, const double dt, int const process_id) override
std::unique_ptr< ProcessLib::SurfaceFluxData > _surfaceflux
ComponentTransportProcess(std::string name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const ¶meters, unsigned const integration_order, std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > &&process_variables, ComponentTransportProcessData &&process_data, SecondaryVariableCollection &&secondary_variables, bool const use_monolithic_scheme, std::unique_ptr< ProcessLib::SurfaceFluxData > &&surfaceflux, std::unique_ptr< ChemistryLib::ChemicalSolverInterface > &&chemical_solver_interface, bool const is_linear, bool const ls_compute_only_upon_timestep_change)
Eigen::Vector3d getFlux(std::size_t const element_id, MathLib::Point3d const &p, double const t, std::vector< GlobalVector * > const &x) const override
virtual void postTimestep(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, double const t, double const dt, int const process_id)
virtual void computeSecondaryVariable(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, double const t, double const dt, std::vector< GlobalVector * > const &x, GlobalVector const &x_prev, int const process_id)
Process(std::string name_, MeshLib::Mesh &mesh, std::unique_ptr< AbstractJacobianAssembler > &&jacobian_assembler, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const ¶meters, unsigned const integration_order, std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > &&process_variables, SecondaryVariableCollection &&secondary_variables, const bool use_monolithic_scheme=true)
std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > _process_variables
std::vector< std::size_t > const & getActiveElementIDs() const
SecondaryVariableCollection _secondary_variables
unsigned const _integration_order
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _local_to_global_index_map
std::unique_ptr< ProcessLib::AbstractJacobianAssembler > _jacobian_assembler
MathLib::MatrixSpecifications getMatrixSpecifications(const int process_id) const override
NumLib::Extrapolator & getExtrapolator() const
const bool _use_monolithic_scheme
Handles configuration of several secondary variables from the project file.
NonlinearSolverTag
Tag used to specify which nonlinear solver will be used.
void copy(PETScVector const &x, PETScVector &y)
void setLocalAccessibleVector(PETScVector const &x)
void matMult(PETScMatrix const &A, PETScVector const &x, PETScVector &y)
void aypx(PETScVector &y, PetscScalar const a, PETScVector const &x)
@ COMPLETE_MATRIX_UPDATE
Both A and b fully updated.
void finalizeVectorAssembly(VEC_T &)
General function to finalize the vector assembly.
bool finalizeMatrixAssembly(MAT_T &)
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)
void computeFluxCorrectedTransport(NumericalStabilization const &stabilizer, const double t, const double dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, const MathLib::MatrixSpecifications &matrix_specification, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b)
NumLib::LocalToGlobalIndexMap::RowColumnIndices getRowColumnIndices(std::size_t const id, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< GlobalIndexType > &indices)
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 NUMLIB_EXPORT MatrixProvider & provider
static NUMLIB_EXPORT VectorProvider & provider
static void executeSelectedMemberOnDereferenced(Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)