28#ifndef EWOMS_BLACK_OIL_ENERGY_MODULE_HH
29#define EWOMS_BLACK_OIL_ENERGY_MODULE_HH
36#include <opm/material/common/Tabulated1DFunction.hpp>
38#include <opm/material/common/Valgrind.hpp>
40#include <dune/common/fvector.hh>
50template <class TypeTag, bool enableEnergyV = getPropValue<TypeTag, Properties::EnableEnergy>()>
65 static constexpr unsigned temperatureIdx = Indices::temperatureIdx;
66 static constexpr unsigned contiEnergyEqIdx = Indices::contiEnergyEqIdx;
68 static constexpr unsigned enableEnergy = enableEnergyV;
69 static constexpr unsigned numEq = getPropValue<TypeTag, Properties::NumEq>();
70 static constexpr unsigned numPhases = FluidSystem::numPhases;
79 if constexpr (enableEnergy)
89 if constexpr (enableEnergy)
95 if constexpr (enableEnergy)
96 return pvIdx == temperatureIdx;
106 return "temperature";
114 return static_cast<Scalar
>(1.0);
119 if constexpr (enableEnergy)
120 return eqIdx == contiEnergyEqIdx;
125 static std::string
eqName([[maybe_unused]]
unsigned eqIdx)
129 return "conti^energy";
132 static Scalar
eqWeight([[maybe_unused]]
unsigned eqIdx)
140 template <
class LhsEval>
141 static void addStorage(Dune::FieldVector<LhsEval, numEq>& storage,
142 const IntensiveQuantities& intQuants)
144 if constexpr (enableEnergy) {
145 const auto& poro = decay<LhsEval>(intQuants.porosity());
148 const auto& fs = intQuants.fluidState();
149 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
150 if (!FluidSystem::phaseIsActive(phaseIdx))
153 const auto& u = decay<LhsEval>(fs.internalEnergy(phaseIdx));
154 const auto& S = decay<LhsEval>(fs.saturation(phaseIdx));
155 const auto& rho = decay<LhsEval>(fs.density(phaseIdx));
157 storage[contiEnergyEqIdx] += poro*S*u*rho;
161 Scalar rockFraction = intQuants.rockFraction();
162 const auto& uRock = decay<LhsEval>(intQuants.rockInternalEnergy());
163 storage[contiEnergyEqIdx] += rockFraction*uRock;
164 storage[contiEnergyEqIdx] *= getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>();
169 [[maybe_unused]]
const ElementContext& elemCtx,
170 [[maybe_unused]]
unsigned scvfIdx,
171 [[maybe_unused]]
unsigned timeIdx)
173 if constexpr (enableEnergy) {
174 flux[contiEnergyEqIdx] = 0.0;
176 const auto& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
177 unsigned focusIdx = elemCtx.focusDofIndex();
178 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
179 if (!FluidSystem::phaseIsActive(phaseIdx))
182 unsigned upIdx = extQuants.upstreamIndex(phaseIdx);
183 if (upIdx == focusIdx)
184 addPhaseEnthalpyFlux_<Evaluation>(flux, phaseIdx, elemCtx, scvfIdx, timeIdx);
186 addPhaseEnthalpyFlux_<Scalar>(flux, phaseIdx, elemCtx, scvfIdx, timeIdx);
190 flux[contiEnergyEqIdx] += extQuants.energyFlux();
191 flux[contiEnergyEqIdx] *= getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>();
196 const Evaluation& heatFlux)
198 if constexpr (enableEnergy) {
200 flux[contiEnergyEqIdx] += heatFlux;
201 flux[contiEnergyEqIdx] *= getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>();
207 template <
class UpEval,
class Eval,
class Flu
idState>
210 const Eval& volumeFlux,
211 const FluidState& upFs)
213 flux[contiEnergyEqIdx] +=
214 decay<UpEval>(upFs.enthalpy(phaseIdx))
215 * decay<UpEval>(upFs.density(phaseIdx))
219 template <
class UpstreamEval>
222 const ElementContext& elemCtx,
226 const auto& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
227 unsigned upIdx = extQuants.upstreamIndex(phaseIdx);
228 const auto& up = elemCtx.intensiveQuantities(upIdx, timeIdx);
229 const auto& fs = up.fluidState();
230 const auto& volFlux = extQuants.volumeFlux(phaseIdx);
231 addPhaseEnthalpyFluxes_<UpstreamEval>(flux,
238 const Evaluation& hRate)
240 if constexpr (enableEnergy)
241 flux[contiEnergyEqIdx] += hRate;
250 if constexpr (enableEnergy)
251 priVars[temperatureIdx] = temperatureIdx;
257 template <
class Flu
idState>
259 const FluidState& fluidState)
261 if constexpr (enableEnergy)
262 priVars[temperatureIdx] = fluidState.temperature(0);
269 const PrimaryVariables& oldPv,
270 const EqVector& delta)
272 if constexpr (enableEnergy)
274 newPv[temperatureIdx] = oldPv[temperatureIdx] - delta[temperatureIdx];
286 return static_cast<Scalar
>(0.0);
295 return std::abs(scalarValue(resid[contiEnergyEqIdx]));
298 template <
class DofEntity>
299 static void serializeEntity(
const Model& model, std::ostream& outstream,
const DofEntity& dof)
301 if constexpr (enableEnergy) {
302 unsigned dofIdx = model.dofMapper().index(dof);
303 const PrimaryVariables& priVars = model.solution(0)[dofIdx];
304 outstream << priVars[temperatureIdx];
308 template <
class DofEntity>
311 if constexpr (enableEnergy) {
312 unsigned dofIdx = model.dofMapper().index(dof);
313 PrimaryVariables& priVars0 = model.solution(0)[dofIdx];
314 PrimaryVariables& priVars1 = model.solution(1)[dofIdx];
316 instream >> priVars0[temperatureIdx];
319 priVars1 = priVars0[temperatureIdx];
331template <class TypeTag, bool enableEnergyV = getPropValue<TypeTag, Properties::EnableEnergy>()>
348 enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
349 static constexpr int temperatureIdx = Indices::temperatureIdx;
350 static constexpr int waterPhaseIdx = FluidSystem::waterPhaseIdx;
362 auto& fs =
asImp_().fluidState_;
363 const auto& priVars = elemCtx.primaryVars(dofIdx, timeIdx);
366 fs.setTemperature(priVars.makeEvaluation(temperatureIdx, timeIdx, elemCtx.linearizationType()));
374 const PrimaryVariables& priVars,
375 [[maybe_unused]]
unsigned globalDofIdx,
376 const unsigned timeIdx,
379 auto& fs =
asImp_().fluidState_;
380 fs.setTemperature(priVars.makeEvaluation(temperatureIdx, timeIdx, lintype));
390 const typename FluidSystem::template ParameterCache<Evaluation>& paramCache)
392 auto& fs =
asImp_().fluidState_;
396 for (
int phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
397 if (!FluidSystem::phaseIsActive(phaseIdx)) {
401 const auto& h = FluidSystem::enthalpy(fs, paramCache, phaseIdx);
402 fs.setEnthalpy(phaseIdx, h);
405 const auto& solidEnergyLawParams = elemCtx.problem().solidEnergyLawParams(elemCtx, dofIdx, timeIdx);
408 const auto& thermalConductionLawParams = elemCtx.problem().thermalConductionLawParams(elemCtx, dofIdx, timeIdx);
416 const unsigned cell_idx = elemCtx.globalSpaceIndex(dofIdx, timeIdx);
417 rockFraction_ = elemCtx.problem().rockFraction(cell_idx, timeIdx);
431 {
return *
static_cast<Implementation*
>(
this); }
438template <
class TypeTag>
449 static constexpr bool enableTemperature = getPropValue<TypeTag, Properties::EnableTemperature>();
453 [[maybe_unused]]
unsigned dofIdx,
454 [[maybe_unused]]
unsigned timeIdx)
456 if constexpr (enableTemperature) {
459 auto& fs =
asImp_().fluidState_;
460 const Scalar T = elemCtx.problem().temperature(elemCtx, dofIdx, timeIdx);
461 fs.setTemperature(T);
465 template<
class Problem>
467 [[maybe_unused]]
const PrimaryVariables& priVars,
468 [[maybe_unused]]
unsigned globalDofIdx,
469 [[maybe_unused]]
unsigned timeIdx,
473 if constexpr (enableTemperature) {
474 auto& fs =
asImp_().fluidState_;
477 const Scalar T = problem.temperature(globalDofIdx, timeIdx);
478 fs.setTemperature(T);
485 const typename FluidSystem::template ParameterCache<Evaluation>&)
489 {
throw std::logic_error(
"Requested the rock internal energy, which is "
490 "unavailable because energy is not conserved"); }
493 {
throw std::logic_error(
"Requested the total thermal conductivity, which is "
494 "unavailable because energy is not conserved"); }
498 {
return *
static_cast<Implementation*
>(
this); }
509template <class TypeTag, bool enableEnergyV = getPropValue<TypeTag, Properties::EnableEnergy>()>
522 using Toolbox = MathToolbox<Evaluation>;
526 static const int dimWorld = GridView::dimensionworld;
527 using DimVector = Dune::FieldVector<Scalar, dimWorld>;
528 using DimEvalVector = Dune::FieldVector<Evaluation, dimWorld>;
530 template<
class Flu
idState>
532 const unsigned& focusDofIndex,
533 const unsigned& inIdx,
534 const unsigned& exIdx,
535 const IntensiveQuantities& inIq,
536 const IntensiveQuantities& exIq,
537 const FluidState& inFs,
538 const FluidState& exFs,
539 const Scalar& inAlpha,
540 const Scalar& outAlpha,
541 const Scalar& faceArea)
544 if (focusDofIndex == inIdx)
546 decay<Scalar>(exFs.temperature(0))
547 - inFs.temperature(0);
548 else if (focusDofIndex == exIdx)
551 - decay<Scalar>(inFs.temperature(0));
554 decay<Scalar>(exFs.temperature(0))
555 - decay<Scalar>(inFs.temperature(0));
558 if (focusDofIndex == inIdx)
559 inLambda = inIq.totalThermalConductivity();
561 inLambda = decay<Scalar>(inIq.totalThermalConductivity());
564 if (focusDofIndex == exIdx)
565 exLambda = exIq.totalThermalConductivity();
567 exLambda = decay<Scalar>(exIq.totalThermalConductivity());
570 const Evaluation& inH = inLambda*inAlpha;
571 const Evaluation& exH = exLambda*outAlpha;
572 if (inH > 0 && exH > 0) {
577 H = 1.0/(1.0/inH + 1.0/exH);
589 const auto& stencil = elemCtx.stencil(timeIdx);
590 const auto& scvf = stencil.interiorFace(scvfIdx);
592 const Scalar faceArea = scvf.area();
593 const unsigned inIdx = scvf.interiorIndex();
594 const unsigned exIdx = scvf.exteriorIndex();
595 const auto& inIq = elemCtx.intensiveQuantities(inIdx, timeIdx);
596 const auto& exIq = elemCtx.intensiveQuantities(exIdx, timeIdx);
597 const auto& inFs = inIq.fluidState();
598 const auto& exFs = exIq.fluidState();
599 const Scalar inAlpha = elemCtx.problem().thermalHalfTransmissibilityIn(elemCtx, scvfIdx, timeIdx);
600 const Scalar outAlpha = elemCtx.problem().thermalHalfTransmissibilityOut(elemCtx, scvfIdx, timeIdx);
602 elemCtx.focusDofIndex(),
614 template <
class Context,
class BoundaryFlu
idState>
618 const BoundaryFluidState& boundaryFs)
620 const auto& stencil = ctx.stencil(timeIdx);
621 const auto& scvf = stencil.boundaryFace(scvfIdx);
623 unsigned inIdx = scvf.interiorIndex();
624 const auto& inIq = ctx.intensiveQuantities(inIdx, timeIdx);
625 const auto& focusDofIdx = ctx.focusDofIndex();
626 const Scalar alpha = ctx.problem().thermalHalfTransmissibilityBoundary(ctx, scvfIdx);
630 template <
class BoundaryFlu
idState>
632 const IntensiveQuantities& inIq,
633 unsigned focusDofIndex,
636 const BoundaryFluidState& boundaryFs)
638 const auto& inFs = inIq.fluidState();
640 if (focusDofIndex == inIdx)
642 boundaryFs.temperature(0)
643 - inFs.temperature(0);
646 decay<Scalar>(boundaryFs.temperature(0))
647 - decay<Scalar>(inFs.temperature(0));
650 if (focusDofIndex == inIdx)
651 lambda = inIq.totalThermalConductivity();
653 lambda = decay<Scalar>(inIq.totalThermalConductivity());
668 {
return energyFlux_; }
671 Implementation& asImp_()
672 {
return *
static_cast<Implementation*
>(
this); }
674 Evaluation energyFlux_;
677template <
class TypeTag>
685 template<
class Flu
idState>
690 const IntensiveQuantities& ,
691 const IntensiveQuantities& ,
704 template <
class Context,
class BoundaryFlu
idState>
708 const BoundaryFluidState&)
711 template <
class BoundaryFlu
idState>
713 const IntensiveQuantities& ,
718 const BoundaryFluidState& )
721 {
throw std::logic_error(
"Requested the energy flux, but energy is not conserved"); }
Declares the properties required by the black oil model.
void updateEnergyBoundary(const Context &, unsigned, unsigned, const BoundaryFluidState &)
Definition: blackoilenergymodules.hh:705
static void updateEnergy(Evaluation &, const unsigned &, const unsigned &, const unsigned &, const IntensiveQuantities &, const IntensiveQuantities &, const FluidState &, const FluidState &, const Scalar &, const Scalar &, const Scalar &)
Definition: blackoilenergymodules.hh:686
static void updateEnergyBoundary(Evaluation &, const IntensiveQuantities &, unsigned, unsigned, unsigned, Scalar, const BoundaryFluidState &)
Definition: blackoilenergymodules.hh:712
void updateEnergy(const ElementContext &, unsigned, unsigned)
Definition: blackoilenergymodules.hh:699
const Evaluation & energyFlux() const
Definition: blackoilenergymodules.hh:720
Provides the energy specific extensive quantities to the generic black-oil module's extensive quantit...
Definition: blackoilenergymodules.hh:511
const Evaluation & energyFlux() const
Definition: blackoilenergymodules.hh:667
static void updateEnergy(Evaluation &energyFlux, const unsigned &focusDofIndex, const unsigned &inIdx, const unsigned &exIdx, const IntensiveQuantities &inIq, const IntensiveQuantities &exIq, const FluidState &inFs, const FluidState &exFs, const Scalar &inAlpha, const Scalar &outAlpha, const Scalar &faceArea)
Definition: blackoilenergymodules.hh:531
static void updateEnergyBoundary(Evaluation &energyFlux, const IntensiveQuantities &inIq, unsigned focusDofIndex, unsigned inIdx, Scalar alpha, const BoundaryFluidState &boundaryFs)
Definition: blackoilenergymodules.hh:631
void updateEnergyBoundary(const Context &ctx, unsigned scvfIdx, unsigned timeIdx, const BoundaryFluidState &boundaryFs)
Definition: blackoilenergymodules.hh:615
void updateEnergy(const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx)
Definition: blackoilenergymodules.hh:585
void updateEnergyQuantities_(const ElementContext &, unsigned, unsigned, const typename FluidSystem::template ParameterCache< Evaluation > &)
Definition: blackoilenergymodules.hh:482
const Evaluation & rockInternalEnergy() const
Definition: blackoilenergymodules.hh:488
const Evaluation & totalThermalConductivity() const
Definition: blackoilenergymodules.hh:492
void updateTemperature_(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Definition: blackoilenergymodules.hh:452
void updateTemperature_(const Problem &problem, const PrimaryVariables &priVars, unsigned globalDofIdx, unsigned timeIdx, const LinearizationType &lintype)
Definition: blackoilenergymodules.hh:466
Implementation & asImp_()
Definition: blackoilenergymodules.hh:497
Provides the volumetric quantities required for the equations needed by the energys extension of the ...
Definition: blackoilenergymodules.hh:333
Scalar rockFraction_
Definition: blackoilenergymodules.hh:435
Implementation & asImp_()
Definition: blackoilenergymodules.hh:430
Evaluation totalThermalConductivity_
Definition: blackoilenergymodules.hh:434
const Evaluation & rockInternalEnergy() const
Definition: blackoilenergymodules.hh:420
Evaluation rockInternalEnergy_
Definition: blackoilenergymodules.hh:433
void updateTemperature_(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Update the temperature of the intensive quantity's fluid state.
Definition: blackoilenergymodules.hh:358
void updateEnergyQuantities_(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx, const typename FluidSystem::template ParameterCache< Evaluation > ¶mCache)
Compute the intensive quantities needed to handle energy conservation.
Definition: blackoilenergymodules.hh:387
void updateTemperature_(const Problem &problem, const PrimaryVariables &priVars, unsigned globalDofIdx, const unsigned timeIdx, const LinearizationType &lintype)
Update the temperature of the intensive quantity's fluid state.
Definition: blackoilenergymodules.hh:373
const Scalar & rockFraction() const
Definition: blackoilenergymodules.hh:426
const Evaluation & totalThermalConductivity() const
Definition: blackoilenergymodules.hh:423
Contains the high level supplements required to extend the black oil model by energy.
Definition: blackoilenergymodules.hh:52
static void computeFlux(RateVector &flux, const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx)
Definition: blackoilenergymodules.hh:168
static void registerParameters()
Register all run-time parameters for the black-oil energy module.
Definition: blackoilenergymodules.hh:77
GetPropType< TypeTag, Properties::ExtensiveQuantities > ExtensiveQuantities
Definition: blackoilenergymodules.hh:73
static Scalar computeResidualError(const EqVector &resid)
Return how much a residual is considered an error.
Definition: blackoilenergymodules.hh:292
static void deserializeEntity(Model &model, std::istream &instream, const DofEntity &dof)
Definition: blackoilenergymodules.hh:309
static void addStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants)
Definition: blackoilenergymodules.hh:141
static bool primaryVarApplies(unsigned pvIdx)
Definition: blackoilenergymodules.hh:93
static std::string primaryVarName(unsigned pvIdx)
Definition: blackoilenergymodules.hh:102
static std::string eqName(unsigned eqIdx)
Definition: blackoilenergymodules.hh:125
static void serializeEntity(const Model &model, std::ostream &outstream, const DofEntity &dof)
Definition: blackoilenergymodules.hh:299
static Scalar primaryVarWeight(unsigned pvIdx)
Definition: blackoilenergymodules.hh:109
static void updatePrimaryVars(PrimaryVariables &newPv, const PrimaryVariables &oldPv, const EqVector &delta)
Do a Newton-Raphson update the primary variables of the energys.
Definition: blackoilenergymodules.hh:268
static void addToEnthalpyRate(RateVector &flux, const Evaluation &hRate)
Definition: blackoilenergymodules.hh:237
static void addHeatFlux(RateVector &flux, const Evaluation &heatFlux)
Definition: blackoilenergymodules.hh:195
static void registerOutputModules(Model &model, Simulator &simulator)
Register all energy specific VTK and ECL output modules.
Definition: blackoilenergymodules.hh:86
static void addPhaseEnthalpyFlux_(RateVector &flux, unsigned phaseIdx, const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx)
Definition: blackoilenergymodules.hh:220
static void addPhaseEnthalpyFluxes_(RateVector &flux, unsigned phaseIdx, const Eval &volumeFlux, const FluidState &upFs)
Definition: blackoilenergymodules.hh:208
static bool eqApplies(unsigned eqIdx)
Definition: blackoilenergymodules.hh:117
static void assignPrimaryVars(PrimaryVariables &priVars, Scalar)
Assign the energy specific primary variables to a PrimaryVariables object.
Definition: blackoilenergymodules.hh:247
static Scalar computeUpdateError(const PrimaryVariables &, const EqVector &)
Return how much a Newton-Raphson update is considered an error.
Definition: blackoilenergymodules.hh:280
static void assignPrimaryVars(PrimaryVariables &priVars, const FluidState &fluidState)
Assign the energy specific primary variables to a PrimaryVariables object.
Definition: blackoilenergymodules.hh:258
static Scalar eqWeight(unsigned eqIdx)
Definition: blackoilenergymodules.hh:132
VTK output module for the black oil model's energy related quantities.
Definition: vtkblackoilenergymodule.hh:62
Definition: blackoilboundaryratevector.hh:37
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:235
This method contains all callback classes for quantities that are required by some extensive quantiti...
Definition: linearizationtype.hh:35