28#ifndef OPM_GENERIC_TEMPERATURE_MODEL_IMPL_HPP
29#define OPM_GENERIC_TEMPERATURE_MODEL_IMPL_HPP
31#include <dune/istl/operators.hh>
32#include <dune/istl/solvers.hh>
33#include <dune/istl/schwarz.hh>
34#include <dune/istl/preconditioners.hh>
35#include <dune/istl/schwarz.hh>
37#include <opm/common/OpmLog/OpmLog.hpp>
39#include <opm/grid/CpGrid.hpp>
41#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
42#include <opm/input/eclipse/Schedule/Well/Well.hpp>
51#include <fmt/format.h>
63template<
class M,
class V>
66 using Comm = Dune::OwnerOverlapCopyCommunication<int, int>;
71template<
class Vector,
class Gr
id,
class Matrix>
72std::tuple<std::unique_ptr<Dune::OverlappingSchwarzOperator<Matrix,Vector,Vector,
73 Dune::OwnerOverlapCopyCommunication<int,int>>>,
74 std::unique_ptr<typename EnergySolverSelector<Matrix,Vector>::type>>
77 OPM_THROW(std::logic_error,
"Grid not supported for parallel Temperatures.");
78 return {
nullptr,
nullptr};
81template<
class Vector,
class Matrix>
82std::tuple<std::unique_ptr<Dune::OverlappingSchwarzOperator<Matrix,Vector,Vector,
83 Dune::OwnerOverlapCopyCommunication<int,int>>>,
84 std::unique_ptr<typename EnergySolverSelector<Matrix,Vector>::type>>
87 using EnergyOperator = Dune::OverlappingSchwarzOperator<Matrix,Vector,Vector,
88 Dune::OwnerOverlapCopyCommunication<int,int>>;
90 const auto& cellComm = grid.cellCommunication();
91 auto op = std::make_unique<EnergyOperator>(M, cellComm);
92 auto dummyWeights = [](){
return Vector();};
93 return {std::move(op), std::make_unique<EnergySolver>(*op, cellComm, prm, dummyWeights, 0)};
97template<
class Gr
id,
class Gr
idView,
class DofMapper,
class Stencil,
class Flu
idSystem,
class Scalar>
100 const EclipseState& eclState,
102 const DofMapper& dofMapper)
103 : gridView_(gridView)
104 , eclState_(eclState)
105 , cartMapper_(cartMapper)
106 , dofMapper_(dofMapper)
111template<
class Gr
id,
class Gr
idView,
class DofMapper,
class Stencil,
class Flu
idSystem,
class Scalar>
113doInit(std::size_t numGridDof)
115 doTemp_ = eclState_.getSimulationConfig().isTemp();
117 temperature_.resize(numGridDof);
118 energyVector_.resize(numGridDof);
120 energyMatrix_ = std::make_unique<EnergyMatrix>(numGridDof, numGridDof, EnergyMatrix::random);
123 using NeighborSet = std::set<unsigned>;
124 std::vector<NeighborSet> neighbors(numGridDof);
126 Stencil stencil(gridView_, dofMapper_);
127 for (
const auto& elem : elements(gridView_)) {
128 stencil.update(elem);
130 for (
unsigned primaryDofIdx = 0; primaryDofIdx < stencil.numPrimaryDof(); ++primaryDofIdx) {
131 unsigned myIdx = stencil.globalSpaceIndex(primaryDofIdx);
133 for (
unsigned dofIdx = 0; dofIdx < stencil.numDof(); ++dofIdx) {
134 unsigned neighborIdx = stencil.globalSpaceIndex(dofIdx);
135 neighbors[myIdx].insert(neighborIdx);
141 for (
unsigned dofIdx = 0; dofIdx < numGridDof; ++ dofIdx) {
142 energyMatrix_->setrowsize(dofIdx, neighbors[dofIdx].size());
144 energyMatrix_->endrowsizes();
149 for (
unsigned dofIdx = 0; dofIdx < numGridDof; ++ dofIdx) {
150 typename NeighborSet::iterator nIt = neighbors[dofIdx].begin();
151 typename NeighborSet::iterator nEndIt = neighbors[dofIdx].end();
152 for (; nIt != nEndIt; ++nIt) {
153 energyMatrix_->addindex(dofIdx, *nIt);
156 energyMatrix_->endindices();
158 maxTempChange_ = Parameters::Get<Parameters::MaxTemperatureChange<Scalar>>();
161template<
class Gr
id,
class Gr
idView,
class DofMapper,
class Stencil,
class Flu
idSystem,
class Scalar>
166 Scalar tolerance = 1e-2;
171 prm.
put(
"maxiter", maxIter);
172 prm.
put(
"tol", tolerance);
173 prm.
put(
"verbosity", verbosity);
174 prm.
put(
"solver", std::string(
"bicgstab"));
175 prm.
put(
"preconditioner.type", std::string(
"ParOverILU0"));
178 if(gridView_.grid().comm().size() > 1)
180 auto [energyOperator, solver] =
181 createParallelFlexibleSolver<EnergyVector>(gridView_.grid(), M, prm);
182 (void) energyOperator;
185 solver->apply(x, b, result);
188 return result.converged;
193 using EnergySolver = Dune::BiCGSTABSolver<EnergyVector>;
194 using EnergyOperator = Dune::MatrixAdapter<EnergyMatrix,EnergyVector,EnergyVector>;
195 using EnergyScalarProduct = Dune::SeqScalarProduct<EnergyVector>;
196 using EnergyPreconditioner = Dune::SeqILU< EnergyMatrix,EnergyVector,EnergyVector>;
198 EnergyOperator energyOperator(M);
199 EnergyScalarProduct energyScalarProduct;
200 EnergyPreconditioner energyPreconditioner(M, 0, 1);
202 EnergySolver solver (energyOperator, energyScalarProduct,
203 energyPreconditioner, tolerance, maxIter,
207 solver.apply(x, b, result);
210 return result.converged;
Definition: CollectDataOnIORank.hpp:49
Definition: FlexibleSolver.hpp:45
GenericTemperatureModel(const GridView &gridView, const EclipseState &eclState, const CartesianIndexMapper &cartMapper, const DofMapper &dofMapper)
Definition: GenericTemperatureModel_impl.hpp:99
Dune::BCRSMatrix< Opm::MatrixBlock< Scalar, 1, 1 > > EnergyMatrix
Definition: GenericTemperatureModel.hpp:57
bool linearSolve_(const EnergyMatrix &M, EnergyVector &x, EnergyVector &b)
Definition: GenericTemperatureModel_impl.hpp:163
Dune::BlockVector< Dune::FieldVector< Scalar, 1 > > EnergyVector
Definition: GenericTemperatureModel.hpp:58
void doInit(std::size_t numGridDof)
Initialize all internal data structures needed by the temperature module.
Definition: GenericTemperatureModel_impl.hpp:113
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:39
void put(const std::string &key, const T &data)
Definition: blackoilbioeffectsmodules.hh:43
Dune::InverseOperatorResult InverseOperatorResult
Definition: GpuBridge.hpp:32
std::tuple< std::unique_ptr< Dune::OverlappingSchwarzOperator< Matrix, Vector, Vector, Dune::OwnerOverlapCopyCommunication< int, int > > >, std::unique_ptr< typename EnergySolverSelector< Matrix, Vector >::type > > createParallelFlexibleSolver(const Grid &, const Matrix &, const PropertyTree &)
Definition: GenericTemperatureModel_impl.hpp:75
Definition: GenericTemperatureModel_impl.hpp:65
Dune::OverlappingSchwarzOperator< M, V, V, Comm > EnergyOperator
Definition: GenericTemperatureModel_impl.hpp:67
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: GenericTemperatureModel_impl.hpp:66