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;
121 std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>
122 transport_process_variables;
125 const int process_id = 0;
130 transport_process_variables.push_back(*pv_iter);
137 for (
auto const& pv :
141 transport_process_variables.push_back(pv[0]);
178 for (std::size_t component_id = 0;
179 component_id < transport_process_variables.size();
182 auto const& pv = transport_process_variables[component_id].get();
184 auto integration_point_values_accessor =
188 std::vector<GlobalVector*>
const& x,
189 std::vector<NumLib::LocalToGlobalIndexMap const*>
const&
191 std::vector<double>& cache) ->
auto const&
198 pv.getName() +
"Flux",
201 integration_point_values_accessor));
206 std::vector<GlobalVector*>& x,
double const t,
int const process_id)
213 if (process_id !=
static_cast<int>(x.size() - 1))
219 x.begin(), x.end(), [](
auto const process_solution)
220 { MathLib::LinAlg::setLocalAccessibleVector(*process_solution); });
222 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
223 dof_tables.reserve(x.size());
224 std::generate_n(std::back_inserter(dof_tables), x.size(),
225 [&]() { return _local_to_global_index_map.get(); });
234 const double t,
double const dt, std::vector<GlobalVector*>
const& x,
235 std::vector<GlobalVector*>
const& x_prev,
int const process_id,
238 DBUG(
"Assemble ComponentTransportProcess.");
247 process_id, M, K, b);
259 matrix_specification, M, K, b);
263 const double t,
double const dt, std::vector<GlobalVector*>
const& x,
264 std::vector<GlobalVector*>
const& x_prev,
int const process_id,
267 DBUG(
"AssembleWithJacobian ComponentTransportProcess.");
272 "The AssembleWithJacobian() for ComponentTransportProcess is "
273 "implemented only for staggered scheme.");
279 "The Newton-Raphson scheme (AssembleWithJacobian()) is not "
280 "implemented for non-isothermal ComponentTransport. Please use the "
281 "Picard scheme for non-isothermal setups.");
285 t, dt, x, x_prev, process_id, b, Jac);
289 std::size_t
const element_id,
292 std::vector<GlobalVector*>
const& x)
const
294 std::vector<GlobalIndexType> indices_cache;
298 std::vector<std::vector<GlobalIndexType>> indices_of_all_coupled_processes{
299 x.size(), r_c_indices.rows};
300 auto const local_xs =
307 std::vector<GlobalVector*>& x, std::vector<GlobalVector*>
const& x_prev,
309 int const process_id)
314 INFO(
"Update process solutions via the look-up table approach");
328 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
329 dof_tables.reserve(x.size());
330 std::generate_n(std::back_inserter(dof_tables), x.size(),
331 [&]() { return _local_to_global_index_map.get(); });
338 x.begin(), x.end(), [](
auto const process_solution)
339 { MathLib::LinAlg::setLocalAccessibleVector(*process_solution); });
344 dof_tables, x, t, dt);
347 time_phreeqc.
start();
353 INFO(
"[time] Phreeqc took {:g} s.", time_phreeqc.
elapsed());
357 postSpeciationCalculation,
366 std::size_t matrix_id = 0u;
368 matrix_specification, matrix_id);
370 matrix_specification, matrix_id);
389 matrix_specification, matrix_id);
409 auto& equation_system =
static_cast<EqSys&
>(ode_sys);
410 equation_system.applyKnownSolutionsPicard(
411 A, rhs, *x[process_id],
414 auto& linear_solver =
417 linear_solver.solve(A, rhs, *x[process_id]);
429 std::vector<GlobalVector*>
const& x,
431 int const process_id)
438 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
439 dof_tables.reserve(x.size());
440 std::generate_n(std::back_inserter(dof_tables), x.size(),
441 [&]() { return _local_to_global_index_map.get(); });
449 computeReactionRelatedSecondaryVariable,
459std::vector<std::vector<std::string>>
461 std::vector<std::reference_wrapper<MeshLib::Mesh>>
const& meshes)
463 DBUG(
"CT process initializeSubmeshOutput().");
465 namespace R = ranges;
466 namespace RV = ranges::views;
468 auto get_residuum_name =
471 std::string
const& pv_name = pv.getName();
472 if (pv_name ==
"pressure")
474 return "LiquidMassFlowRate";
476 if (pv_name ==
"temperature")
478 return "HeatFlowRate";
480 return pv_name +
"FlowRate";
483 auto get_residuum_names = [get_residuum_name](
auto const& pvs)
484 {
return pvs | RV::transform(get_residuum_name); };
487 RV::transform(get_residuum_names) |
488 R::to<std::vector<std::vector<std::string>>>();
491 meshes, residuum_names);
493 return residuum_names;
497 std::vector<GlobalVector*>
const& ,
500 const int process_id)
509 std::vector<GlobalVector*>
const& x,
510 std::vector<GlobalVector*>
const& x_prev,
513 int const process_id)
520 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
521 dof_tables.reserve(x.size());
522 std::generate_n(std::back_inserter(dof_tables), x.size(),
523 [&]() { return _local_to_global_index_map.get(); });
541 std::vector<GlobalVector*>
const& x,
542 std::vector<GlobalVector*>
const& x_prev,
543 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)