28#ifndef OPM_TEMPERATURE_MODEL_HPP
29#define OPM_TEMPERATURE_MODEL_HPP
31#include <opm/common/OpmLog/OpmLog.hpp>
48template<
class TypeTag,
class MyTypeTag>
57template<
typename Scalar,
typename IndexTraits>
class WellState;
64template <class TypeTag, bool enableTempV = getPropValue<TypeTag, Properties::EnergyModuleType>() == EnergyModules::SequentialImplicitThermal >
66 GetPropType<TypeTag, Properties::GridView>,
67 GetPropType<TypeTag, Properties::DofMapper>,
68 GetPropType<TypeTag, Properties::Stencil>,
69 GetPropType<TypeTag, Properties::FluidSystem>,
70 GetPropType<TypeTag, Properties::Scalar>>
87 using TemperatureEvaluation = DenseAd::Evaluation<Scalar,1>;
92 using IndexTraits =
typename FluidSystem::IndexTraitsType;
98 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
99 enum { numPhases = FluidSystem::numPhases };
100 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
101 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
102 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
106 :
BaseType(simulator.vanguard().gridView(),
107 simulator.vanguard().eclState(),
108 simulator.vanguard().cartesianIndexMapper(),
109 simulator.model().dofMapper())
115 const unsigned int numCells =
simulator_.model().numTotalDof();
125 for (
unsigned globI = 0; globI < numCells; ++globI) {
133 const auto& elemMapper =
simulator_.model().elementMapper();
143 const unsigned int numCells =
simulator_.model().numTotalDof();
144 for (
unsigned globI = 0; globI < numCells; ++globI) {
151 const int nw =
simulator_.problem().wellModel().wellState().numWells();
164 const unsigned int numCells =
simulator_.model().numTotalDof();
165 for (
unsigned globI = 0; globI < numCells; ++globI) {
173 const int nw = wellState.
numWells();
174 for (
auto wellID = 0*nw; wellID < nw; ++wellID) {
175 auto& ws = wellState.
well(wellID);
185 template <
class Restarter>
195 template <
class Restarter>
204 const unsigned int numCells =
simulator_.model().numTotalDof();
206 #pragma omp parallel for
208 for (
unsigned globI = 0; globI < numCells; ++globI) {
209 Scalar storage = 0.0;
217 const int max_iter = 20;
218 const int min_iter = 1;
220 for (
int iter = 0; iter < max_iter; ++iter) {
222 if (iter > min_iter &&
converged(iter)) {
230 const unsigned int numCells =
simulator_.model().numTotalDof();
231 EnergyVector dx(numCells);
234 if (
simulator_.gridView().comm().rank() == 0) {
235 OpmLog::warning(
"Temp model: Linear solver did not converge. Temperature values not updated.");
238 for (
unsigned globI = 0; globI < numCells; ++globI) {
247 const unsigned int numCells =
simulator_.model().numTotalDof();
248 Scalar maxNorm = 0.0;
249 Scalar sumNorm = 0.0;
250 for (
unsigned globI = 0; globI < numCells; ++globI) {
251 maxNorm = max(maxNorm, std::abs(this->
energyVector_[globI]));
254 maxNorm =
simulator_.gridView().comm().sum(maxNorm);
255 sumNorm =
simulator_.gridView().comm().sum(sumNorm);
256 const int globalNumCells =
simulator_.gridView().comm().sum(numCells);
257 sumNorm /= globalNumCells;
258 const auto tolerance_cnv_energy = Parameters::Get<Parameters::ToleranceCnvEnergy<Scalar>>();
259 const auto tolerance_energy_balance = Parameters::Get<Parameters::ToleranceEnergyBalance<Scalar>>();
260 if (maxNorm < tolerance_cnv_energy || sumNorm < tolerance_energy_balance) {
261 const auto msg = fmt::format(
"Temperature model (TEMP): Newton converged after {} iterations", iter);
268 template<
class LhsEval>
271 const auto& poro = decay<LhsEval>(intQuants.porosity());
273 const auto& fs = intQuants.fluidState();
274 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
275 if (!FluidSystem::phaseIsActive(phaseIdx))
278 const auto& u = decay<LhsEval>(fs.internalEnergy(phaseIdx));
279 const auto& S = decay<LhsEval>(fs.saturation(phaseIdx));
280 const auto& rho = decay<LhsEval>(fs.density(phaseIdx));
282 storage += poro*S*u*rho;
286 Scalar rockFraction = intQuants.rockFraction();
287 const auto& uRock = decay<LhsEval>(intQuants.rockInternalEnergy());
288 storage += rockFraction*uRock;
289 storage*= getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>();
292 template <
class Res
idualNBInfo>
293 void computeFluxTerm(
unsigned globI,
unsigned globJ,
const ResidualNBInfo& res_nbinfo, Evaluation& flux) {
295 const IntensiveQuantities& intQuantsIn =
intQuants_[globI];
296 const IntensiveQuantities& intQuantsEx =
intQuants_[globJ];
298 RateVector darcyFlux(0.0);
299 LocalResidual::computeFlux(tmp, darcyFlux, globI, globJ, intQuantsIn, intQuantsEx, res_nbinfo,
simulator_.problem().moduleParams());
300 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
301 if (!FluidSystem::phaseIsActive(phaseIdx))
304 const unsigned activeCompIdx =
305 FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
307 bool inIsUp = darcyFlux[activeCompIdx] > 0;
308 const IntensiveQuantities& up = inIsUp ? intQuantsIn : intQuantsEx;
309 const auto& fs = up.fluidState();
311 flux += fs.enthalpy(phaseIdx)
312 * fs.density(phaseIdx)
313 * darcyFlux[activeCompIdx];
315 flux += getValue(fs.enthalpy(phaseIdx))
316 * getValue(fs.density(phaseIdx))
317 * getValue(darcyFlux[activeCompIdx]);
320 flux *= getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>();
323 template <
class Res
idualNBInfo>
324 void computeHeatFluxTerm(
unsigned globI,
unsigned globJ,
const ResidualNBInfo& res_nbinfo, Evaluation& heatFlux) {
325 const IntensiveQuantities& intQuantsIn =
intQuants_[globI];
326 const IntensiveQuantities& intQuantsEx =
intQuants_[globJ];
327 const Scalar inAlpha =
simulator_.problem().thermalHalfTransmissibility(globI, globJ);
328 const Scalar outAlpha =
simulator_.problem().thermalHalfTransmissibility(globJ, globI);
329 short interiorDofIdx = 0;
330 short exteriorDofIdx = 1;
331 EnergyModule::ExtensiveQuantities::updateEnergy(heatFlux,
337 intQuantsIn.fluidState(),
338 intQuantsEx.fluidState(),
341 res_nbinfo.faceArea);
342 heatFlux *= getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>()*res_nbinfo.faceArea;
349 const unsigned int numCells =
simulator_.model().numTotalDof();
351#pragma omp parallel for
353 for (
unsigned globI = 0; globI < numCells; ++globI) {
354 Scalar volume =
simulator_.model().dofTotalVolume(globI);
355 Scalar storefac = volume / dt;
356 Evaluation storage = 0.0;
359 (*this->
energyMatrix_)[globI][globI][0][0] += storefac * storage.derivative(Indices::temperatureIdx);
362 const auto& neighborInfo =
simulator_.model().linearizer().getNeighborInfo();
364#pragma omp parallel for
366 for (
unsigned globI = 0; globI < numCells; ++globI) {
367 const auto& nbInfos = neighborInfo[globI];
368 for (
const auto& nbInfo : nbInfos) {
369 unsigned globJ = nbInfo.neighbor;
370 assert(globJ != globI);
373 Evaluation flux = 0.0;
376 (*this->
energyMatrix_)[globI][globI][0][0] += flux.derivative(Indices::temperatureIdx);
377 (*this->
energyMatrix_)[globJ][globI][0][0] -= flux.derivative(Indices::temperatureIdx);
380 Evaluation heatFlux = 0.0;
383 (*this->
energyMatrix_)[globI][globI][0][0] += heatFlux.derivative(Indices::temperatureIdx);
384 (*this->
energyMatrix_)[globJ][globI][0][0] -= heatFlux.derivative(Indices::temperatureIdx);
389 const auto& wellPtrs =
simulator_.problem().wellModel().localNonshutWells();
390 for (
const auto& wellPtr : wellPtrs) {
394 if (
simulator_.gridView().comm().size() > 1) {
411 const auto& eclWell = well.wellEcl();
412 std::size_t well_index =
simulator_.problem().wellModel().wellState().index(well.name()).value();
413 const auto& ws =
simulator_.problem().wellModel().wellState().well(well_index);
415 for (std::size_t i = 0; i < ws.perf_data.size(); ++i) {
416 const auto globI = ws.perf_data.cell_index[i];
418 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
419 if (!FluidSystem::phaseIsActive(phaseIdx))
422 Evaluation rate = well.volumetricSurfaceRateForConnection(globI, phaseIdx);
423 if (rate > 0 && eclWell.isInjector()) {
424 fs.setTemperature(eclWell.inj_temperature());
425 const auto& rho = FluidSystem::density(fs, phaseIdx, fs.pvtRegionIndex());
426 fs.setDensity(phaseIdx, rho);
427 const auto& h = FluidSystem::enthalpy(fs, phaseIdx, fs.pvtRegionIndex());
428 fs.setEnthalpy(phaseIdx, h);
429 rate *= getValue(fs.enthalpy(phaseIdx)) * getValue(fs.density(phaseIdx)) / getValue(fs.invB(phaseIdx));
431 const Evaluation d = 1.0 - fs.Rv() * fs.Rs();
432 if (phaseIdx == gasPhaseIdx && d > 0) {
433 const auto& oilrate = well.volumetricSurfaceRateForConnection(globI, oilPhaseIdx);
434 rate -= oilrate * getValue(fs.Rs());
437 if (phaseIdx == oilPhaseIdx && d > 0) {
438 const auto& gasrate = well.volumetricSurfaceRateForConnection(globI, gasPhaseIdx);
439 rate -= gasrate * getValue(fs.Rv());
442 rate *= fs.enthalpy(phaseIdx) * getValue(fs.density(phaseIdx)) / getValue(fs.invB(phaseIdx));
445 rate *= getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>();
447 (*this->
energyMatrix_)[globI][globI][0][0] -= rate.derivative(Indices::temperatureIdx);
461template <
class TypeTag>
474 template <
class Restarter>
484 template <
class Restarter>
Contains the high level supplements required to extend the black oil model by energy.
Definition: blackoilenergymodules.hh:60
Definition: GenericTemperatureModel.hpp:55
Opm::GenericTemperatureModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::energyVector_ EnergyVector energyVector_
Definition: GenericTemperatureModel.hpp:89
Opm::GenericTemperatureModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::energy_rates_ std::vector< GetPropType< TypeTag, Properties::Scalar > > energy_rates_
Definition: GenericTemperatureModel.hpp:92
Opm::GenericTemperatureModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::energyMatrix_ std::unique_ptr< EnergyMatrix > energyMatrix_
Definition: GenericTemperatureModel.hpp:90
Opm::GenericTemperatureModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::EnergyMatrix Dune::BCRSMatrix< Opm::MatrixBlock< GetPropType< TypeTag, Properties::Scalar >, 1, 1 > > EnergyMatrix
Definition: GenericTemperatureModel.hpp:57
Opm::GenericTemperatureModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::linearSolve_ bool linearSolve_(const EnergyMatrix &M, EnergyVector &x, EnergyVector &b)
Definition: GenericTemperatureModel_impl.hpp:163
Opm::GenericTemperatureModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::EnergyVector Dune::BlockVector< Dune::FieldVector< GetPropType< TypeTag, Properties::Scalar >, 1 > > EnergyVector
Definition: GenericTemperatureModel.hpp:58
Opm::GenericTemperatureModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::doTemp bool doTemp()
Definition: GenericTemperatureModel.hpp:62
Opm::GenericTemperatureModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::doInit void doInit(std::size_t numGridDof)
Initialize all internal data structures needed by the temperature module.
Definition: GenericTemperatureModel_impl.hpp:113
Opm::GenericTemperatureModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::maxTempChange_ GetPropType< TypeTag, Properties::Scalar > maxTempChange_
Definition: GenericTemperatureModel.hpp:94
Opm::GenericTemperatureModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::temperature_ std::vector< GetPropType< TypeTag, Properties::Scalar > > temperature_
Definition: GenericTemperatureModel.hpp:91
void beginTimeStep()
Definition: TemperatureModel.hpp:489
void init()
Definition: TemperatureModel.hpp:488
const Scalar temperature(size_t) const
Definition: TemperatureModel.hpp:490
void deserialize(Restarter &)
This method restores the complete state of the temperature from disk.
Definition: TemperatureModel.hpp:485
void serialize(Restarter &)
This method writes the complete state of all temperature to the hard disk.
Definition: TemperatureModel.hpp:475
TemperatureModel(Simulator &)
Definition: TemperatureModel.hpp:467
A class which handles sequential implicit solution of the energy equation as specified in by TEMP.
Definition: TemperatureModel.hpp:71
void serialize(Restarter &)
This method writes the complete state of all temperature to the hard disk.
Definition: TemperatureModel.hpp:186
void assembleEquationWell(const Well &well)
Definition: TemperatureModel.hpp:409
std::vector< int > interiorRows_
Definition: TemperatureModel.hpp:456
EnergyVector storage1_
Definition: TemperatureModel.hpp:453
bool converged(const int iter)
Definition: TemperatureModel.hpp:246
void computeHeatFluxTerm(unsigned globI, unsigned globJ, const ResidualNBInfo &res_nbinfo, Evaluation &heatFlux)
Definition: TemperatureModel.hpp:324
void computeStorageTerm(unsigned globI, LhsEval &storage)
Definition: TemperatureModel.hpp:269
void deserialize(Restarter &)
This method restores the complete state of the temperature from disk.
Definition: TemperatureModel.hpp:196
void endTimeStep(WellStateType &wellState)
Informs the temperature model that a time step has just been finished.
Definition: TemperatureModel.hpp:158
const Simulator & simulator_
Definition: TemperatureModel.hpp:452
void beginTimeStep()
Definition: TemperatureModel.hpp:137
void advanceTemperatureFields()
Definition: TemperatureModel.hpp:215
void updateStorageCache()
Definition: TemperatureModel.hpp:201
void assembleEquations()
Definition: TemperatureModel.hpp:345
void solveAndUpdate()
Definition: TemperatureModel.hpp:229
std::vector< IntensiveQuantities > intQuants_
Definition: TemperatureModel.hpp:454
void computeFluxTerm(unsigned globI, unsigned globJ, const ResidualNBInfo &res_nbinfo, Evaluation &flux)
Definition: TemperatureModel.hpp:293
std::vector< int > overlapRows_
Definition: TemperatureModel.hpp:455
TemperatureModel(Simulator &simulator)
Definition: TemperatureModel.hpp:105
void init()
Definition: TemperatureModel.hpp:113
Definition: WellState.hpp:66
int numWells() const
Definition: WellState.hpp:99
const SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index) const
Definition: WellState.hpp:290
Provides data handles for parallel communication which operate on DOFs.
Definition: blackoilmodel.hh:80
void findOverlapAndInterior(const Grid &grid, const Mapper &mapper, std::vector< int > &overlapRows, std::vector< int > &interiorRows)
Find the rows corresponding to overlap cells.
Definition: findOverlapRowsAndColumns.hpp:92
Definition: blackoilbioeffectsmodules.hh:43
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
The Opm property system, traits with inheritance.
Definition: TemperatureModel.hpp:49
a tag to mark properties as undefined
Definition: propertysystem.hh:38