29 #ifndef EWOMS_ENERGY_MODULE_HH 30 #define EWOMS_ENERGY_MODULE_HH 32 #include <dune/common/fvector.hh> 34 #include <opm/material/common/Valgrind.hpp> 46 #include <type_traits> 54 template <
class TypeTag,
bool enableEnergy>
60 template <
class TypeTag>
71 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
116 template <
class Flu
idState>
125 template <
class RateVector,
class Flu
idState>
156 template <
class LhsEval>
158 const IntensiveQuantities&,
166 template <
class LhsEval,
class Scv>
168 const IntensiveQuantities&,
177 template <
class LhsEval>
179 const IntensiveQuantities&)
188 template <
class Context>
200 template <
class Context>
213 template <
class Context>
224 template <
class TypeTag>
237 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
238 enum { numPhases = FluidSystem::numPhases };
239 enum { energyEqIdx = Indices::energyEqIdx };
240 static constexpr
unsigned temperatureIdx = Indices::temperatureIdx;
242 using Toolbox = Opm::MathToolbox<Evaluation>;
258 if (pvIdx == temperatureIdx) {
259 return "temperature";
269 static std::string
eqName(
unsigned eqIdx)
271 if (eqIdx == energyEqIdx) {
283 if (pvIdx != temperatureIdx) {
288 return std::max(static_cast<Scalar>(1.0) / 1000,
289 1.0 / model.solution(0)[globalDofIdx][temperatureIdx]);
299 if (eqIdx != energyEqIdx) {
305 return static_cast<Scalar
>(1.0) / (4.184e3 * 30.0);
312 { rateVec[energyEqIdx] = rate; }
318 { rateVec[energyEqIdx] += rate; }
324 {
return -extQuants.temperatureGradNormal() * extQuants.thermalConductivity(); }
330 template <
class RateVector,
class Flu
idState>
332 const FluidState& fluidState,
334 const Evaluation& volume)
336 rateVec[energyEqIdx] =
338 fluidState.density(phaseIdx) *
339 fluidState.enthalpy(phaseIdx);
345 template <
class Flu
idState>
347 const FluidState& fs)
349 priVars[temperatureIdx] = Toolbox::value(fs.temperature(0));
351 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
352 assert(std::abs(Toolbox::value(fs.temperature(0))
353 - Toolbox::value(fs.temperature(phaseIdx))) < 1e-30);
362 template <
class LhsEval>
364 const IntensiveQuantities& intQuants,
367 const auto& fs = intQuants.fluidState();
368 storage[energyEqIdx] +=
369 Toolbox::template decay<LhsEval>(fs.density(phaseIdx)) *
370 Toolbox::template decay<LhsEval>(fs.internalEnergy(phaseIdx)) *
371 Toolbox::template decay<LhsEval>(fs.saturation(phaseIdx)) *
372 Toolbox::template decay<LhsEval>(intQuants.porosity());
379 template <
class Scv,
class LhsEval>
381 const IntensiveQuantities& intQuants,
385 const auto& fs = intQuants.fractureFluidState();
386 storage[energyEqIdx] +=
387 Toolbox::template decay<LhsEval>(fs.density(phaseIdx)) *
388 Toolbox::template decay<LhsEval>(fs.internalEnergy(phaseIdx)) *
389 Toolbox::template decay<LhsEval>(fs.saturation(phaseIdx)) *
390 Toolbox::template decay<LhsEval>(intQuants.fracturePorosity()) *
391 Toolbox::template decay<LhsEval>(intQuants.fractureVolume()) / scv.volume();
398 template <
class LhsEval>
400 const IntensiveQuantities& intQuants)
401 { storage[energyEqIdx] += Opm::decay<LhsEval>(intQuants.solidInternalEnergy()); }
409 template <
class Context>
411 const Context& context,
415 const auto& extQuants = context.extensiveQuantities(spaceIdx, timeIdx);
418 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
419 if (!context.model().phaseIsConsidered(phaseIdx)) {
424 const unsigned upIdx =
static_cast<unsigned>(extQuants.upstreamIndex(phaseIdx));
425 const IntensiveQuantities& up = context.intensiveQuantities(upIdx, timeIdx);
428 extQuants.volumeFlux(phaseIdx) *
429 up.fluidState().enthalpy(phaseIdx) *
430 up.fluidState().density(phaseIdx);
439 template <
class Context>
441 const Context& context,
445 const auto& scvf = context.stencil(timeIdx).interiorFace(spaceIdx);
446 const auto& extQuants = context.extensiveQuantities(spaceIdx, timeIdx);
450 flux[energyEqIdx] *= 1 - extQuants.fractureWidth() / (2 * scvf.area());
453 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
454 if (!context.model().phaseIsConsidered(phaseIdx)) {
459 const unsigned upIdx =
static_cast<unsigned>(extQuants.upstreamIndex(phaseIdx));
460 const IntensiveQuantities& up = context.intensiveQuantities(upIdx, timeIdx);
463 extQuants.fractureVolumeFlux(phaseIdx) *
464 up.fluidState().enthalpy(phaseIdx) *
465 up.fluidState().density(phaseIdx);
475 template <
class Context>
477 const Context& context,
481 const auto& extQuants = context.extensiveQuantities(spaceIdx, timeIdx);
484 flux[energyEqIdx] += -extQuants.temperatureGradNormal() * extQuants.thermalConductivity();
494 template <
unsigned PVOffset,
bool enableEnergy>
500 template <
unsigned PVOffset>
504 static constexpr
unsigned temperatureIdx = std::numeric_limits<unsigned>::max();
507 enum { energyEqIdx = -1000 };
516 template <
unsigned PVOffset>
520 static constexpr
unsigned temperatureIdx = PVOffset;
523 enum { energyEqIdx = PVOffset };
535 template <
class TypeTag,
bool enableEnergy>
541 template <
class TypeTag>
549 using Toolbox = Opm::MathToolbox<Evaluation>;
558 throw std::logic_error(
"solidInternalEnergy() does not make sense for isothermal models");
567 throw std::logic_error(
"thermalConductivity() does not make sense for isothermal models");
574 template <
class Flu
idState,
class Context>
576 const Context& context,
580 const Scalar T = context.problem().temperature(context, spaceIdx, timeIdx);
581 fluidState.setTemperature(Toolbox::createConstant(T));
588 template <
class Flu
idState>
590 typename FluidSystem::template ParameterCache<typename FluidState::ValueType>&,
591 const ElementContext&,
600 template <
class TypeTag>
611 enum { numPhases = FluidSystem::numPhases };
612 static constexpr
unsigned temperatureIdx = Indices::temperatureIdx;
614 using Toolbox = Opm::MathToolbox<Evaluation>;
620 template <
class Flu
idState,
class Context>
622 const Context& context,
626 const auto& priVars = context.primaryVars(spaceIdx, timeIdx);
627 if constexpr (std::is_same_v<Evaluation, Scalar>) {
628 fluidState.setTemperature(Toolbox::createConstant(priVars[temperatureIdx]));
633 fluidState.setTemperature(Toolbox::createVariable(priVars[temperatureIdx], temperatureIdx));
636 fluidState.setTemperature(Toolbox::createConstant(priVars[temperatureIdx]));
645 template <
class Flu
idState>
647 typename FluidSystem::template ParameterCache<typename FluidState::ValueType>& paramCache,
648 const ElementContext& elemCtx,
653 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
654 if (!elemCtx.model().phaseIsConsidered(phaseIdx)) {
658 fs.setEnthalpy(phaseIdx,
659 FluidSystem::enthalpy(fs, paramCache, phaseIdx));
663 const auto& problem = elemCtx.problem();
664 const auto& solidEnergyParams = problem.solidEnergyLawParams(elemCtx, dofIdx, timeIdx);
665 const auto& thermalCondParams = problem.thermalConductionLawParams(elemCtx, dofIdx, timeIdx);
667 solidInternalEnergy_ = SolidEnergyLaw::solidInternalEnergy(solidEnergyParams, fs);
668 thermalConductivity_ = ThermalConductionLaw::thermalConductivity(thermalCondParams, fs);
670 Opm::Valgrind::CheckDefined(solidInternalEnergy_);
671 Opm::Valgrind::CheckDefined(thermalConductivity_);
680 {
return solidInternalEnergy_; }
687 {
return thermalConductivity_; }
690 Evaluation solidInternalEnergy_;
691 Evaluation thermalConductivity_;
700 template <
class TypeTag,
bool enableEnergy>
706 template <
class TypeTag>
722 template <
class Context,
class Flu
idState>
723 void updateBoundary_(
const Context&,
735 throw std::logic_error(
"Calling temperatureGradNormal() does not make sense " 736 "for isothermal models");
744 throw std::logic_error(
"Calling thermalConductivity() does not make sense for " 745 "isothermal models");
752 template <
class TypeTag>
760 enum { dimWorld = GridView::dimensionworld };
761 using EvalDimVector = Dune::FieldVector<Evaluation, dimWorld>;
762 using DimVector = Dune::FieldVector<Scalar, dimWorld>;
769 void update_(
const ElementContext& elemCtx,
unsigned faceIdx,
unsigned timeIdx)
771 const auto& gradCalc = elemCtx.gradientCalculator();
774 EvalDimVector temperatureGrad;
775 gradCalc.calculateGradient(temperatureGrad,
778 temperatureCallback);
781 const auto& face = elemCtx.stencil(0).interiorFace(faceIdx);
783 temperatureGradNormal_ = 0;
784 for (
unsigned dimIdx = 0; dimIdx < dimWorld; ++dimIdx) {
785 temperatureGradNormal_ += (face.normal()[dimIdx]*temperatureGrad[dimIdx]);
788 const auto& extQuants = elemCtx.extensiveQuantities(faceIdx, timeIdx);
789 const auto& intQuantsInside = elemCtx.intensiveQuantities(extQuants.interiorIndex(), timeIdx);
790 const auto& intQuantsOutside = elemCtx.intensiveQuantities(extQuants.exteriorIndex(), timeIdx);
793 thermalConductivity_ = 0.5 * (intQuantsInside.thermalConductivity() +
794 intQuantsOutside.thermalConductivity());
795 Opm::Valgrind::CheckDefined(thermalConductivity_);
798 template <
class Context,
class Flu
idState>
799 void updateBoundary_(
const Context& context,
unsigned bfIdx,
unsigned timeIdx,
const FluidState& fs)
801 const auto& stencil = context.stencil(timeIdx);
802 const auto& face = stencil.boundaryFace(bfIdx);
804 const auto& elemCtx = context.elementContext();
805 const unsigned insideScvIdx = face.interiorIndex();
806 const auto& insideScv = elemCtx.stencil(timeIdx).subControlVolume(insideScvIdx);
808 const auto& intQuantsInside = elemCtx.intensiveQuantities(insideScvIdx, timeIdx);
809 const auto& fsInside = intQuantsInside.fluidState();
812 DimVector distVec = face.integrationPos();
813 distVec -= insideScv.geometry().center();
816 for (
unsigned dimIdx = 0; dimIdx < dimWorld; ++dimIdx) {
817 dist += distVec[dimIdx] * face.normal()[dimIdx];
826 temperatureGradNormal_ =
827 (fs.temperature(0) - fsInside.temperature(0)) / dist;
830 thermalConductivity_ = intQuantsInside.thermalConductivity();
838 {
return temperatureGradNormal_; }
845 {
return thermalConductivity_; }
848 Evaluation temperatureGradNormal_;
849 Evaluation thermalConductivity_;
static void setEnthalpyRate(RateVector &rateVec, const Evaluation &rate)
Set the rate of energy flux of a rate vector.
Definition: energymodule.hh:311
static void addPhaseStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants, unsigned phaseIdx)
Add the energy storage term for a fluid phase to an equation vector.
Definition: energymodule.hh:363
const Evaluation & thermalConductivity() const
The total thermal conductivity at the face .
Definition: energymodule.hh:844
static void addDiffusiveFlux(RateVector &, const Context &, unsigned, unsigned)
Adds the diffusive energy flux to the flux vector over the face of a sub-control volume.
Definition: energymodule.hh:214
static void updateTemperatures_(FluidState &fluidState, const Context &context, unsigned spaceIdx, unsigned timeIdx)
Update the temperatures of the fluids of a fluid state.
Definition: energymodule.hh:621
static void addAdvectiveFlux(RateVector &flux, const Context &context, unsigned spaceIdx, unsigned timeIdx)
Evaluates the advective energy fluxes for a flux integration point and adds the result in the flux ve...
Definition: energymodule.hh:410
static std::string primaryVarName(unsigned pvIdx)
Returns the name of a primary variable or an empty string if the specified primary variable index doe...
Definition: energymodule.hh:256
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
static Scalar primaryVarWeight(const Model &, unsigned, unsigned)
Returns the relative weight of a primary variable for calculating relative errors.
Definition: energymodule.hh:100
void update_(FluidState &, typename FluidSystem::template ParameterCache< typename FluidState::ValueType > &, const ElementContext &, unsigned, unsigned)
Update the quantities required to calculate energy fluxes.
Definition: energymodule.hh:589
static void setEnthalpyRate(RateVector &rateVec, const FluidState &fluidState, unsigned phaseIdx, const Evaluation &volume)
Given a fluid state, set the enthalpy rate which emerges from a volumetric rate.
Definition: energymodule.hh:331
static void handleFractureFlux(RateVector &, const Context &, unsigned, unsigned)
Evaluates the advective energy fluxes over a fracture which should be attributed to a face of a subco...
Definition: energymodule.hh:201
static void handleFractureFlux(RateVector &flux, const Context &context, unsigned spaceIdx, unsigned timeIdx)
Evaluates the advective energy fluxes over a fracture which should be attributed to a face of a subco...
Definition: energymodule.hh:440
Provides the quantities required to calculate energy fluxes.
Definition: energymodule.hh:701
void update_(const ElementContext &, unsigned, unsigned)
Update the quantities required to calculate energy fluxes.
Definition: energymodule.hh:717
void update_(const ElementContext &elemCtx, unsigned faceIdx, unsigned timeIdx)
Update the quantities required to calculate energy fluxes.
Definition: energymodule.hh:769
Scalar thermalConductivity() const
The total thermal conductivity at the face .
Definition: energymodule.hh:742
Defines the common properties required by the porous medium multi-phase models.
static void setPriVarTemperatures(PrimaryVariables &, const FluidState &)
Given a fluid state, set the temperature in the primary variables.
Definition: energymodule.hh:117
static void registerParameters()
Register all run-time parameters for the energy module.
Definition: energymodule.hh:248
static void setEnthalpyRate(RateVector &, const Evaluation &)
Add the rate of the enthalpy flux to a rate vector.
Definition: energymodule.hh:135
Evaluation solidInternalEnergy() const
Returns the volumetric internal energy of the solid matrix in the sub-control volume.
Definition: energymodule.hh:556
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
static void addToEnthalpyRate(RateVector &rateVec, const Evaluation &rate)
Add the rate of the enthalpy flux to a rate vector.
Definition: energymodule.hh:317
static Scalar primaryVarWeight(const Model &model, unsigned globalDofIdx, unsigned pvIdx)
Returns the relative weight of a primary variable for calculating relative errors.
Definition: energymodule.hh:281
Provides the volumetric quantities required for the energy equation.
Definition: energymodule.hh:536
const Evaluation & solidInternalEnergy() const
Returns the volumetric internal energy of the solid matrix in the sub-control volume.
Definition: energymodule.hh:679
static void addAdvectiveFlux(RateVector &, const Context &, unsigned, unsigned)
Evaluates the advective energy fluxes over a face of a subcontrol volume and adds the result in the f...
Definition: energymodule.hh:189
const Evaluation & thermalConductivity() const
Returns the total conductivity capacity of the solid matrix in the sub-control volume.
Definition: energymodule.hh:686
Declare the properties used by the infrastructure code of the finite volume discretizations.
static void addToEnthalpyRate(RateVector &, const Evaluation &)
Add the rate of the enthalpy flux to a rate vector.
Definition: energymodule.hh:142
static void addDiffusiveFlux(RateVector &flux, const Context &context, unsigned spaceIdx, unsigned timeIdx)
Adds the diffusive energy flux to the flux vector over the face of a sub-control volume.
Definition: energymodule.hh:476
static std::string eqName(unsigned)
Returns the name of an equation or an empty string if the specified equation index does not belong to...
Definition: energymodule.hh:93
This method contains all callback classes for quantities that are required by some extensive quantiti...
static void addFracturePhaseStorage(Dune::FieldVector< LhsEval, numEq > &, const IntensiveQuantities &, const Scv &, unsigned)
Add the energy storage term for a fluid phase to an equation vector.
Definition: energymodule.hh:167
Callback class for temperature.
Definition: quantitycallbacks.hh:48
static void updateTemperatures_(FluidState &fluidState, const Context &context, unsigned spaceIdx, unsigned timeIdx)
Update the temperatures of the fluids of a fluid state.
Definition: energymodule.hh:575
const Evaluation & temperatureGradNormal() const
The temperature gradient times the face normal [K m^2 / m].
Definition: energymodule.hh:837
static std::string primaryVarName(unsigned)
Returns the name of a primary variable or an empty string if the specified primary variable index doe...
Definition: energymodule.hh:85
static void setPriVarTemperatures(PrimaryVariables &priVars, const FluidState &fs)
Given a fluid state, set the temperature in the primary variables.
Definition: energymodule.hh:346
void update_(FluidState &fs, typename FluidSystem::template ParameterCache< typename FluidState::ValueType > ¶mCache, const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Update the quantities required to calculate energy fluxes.
Definition: energymodule.hh:646
static Scalar eqWeight(const Model &, unsigned, unsigned eqIdx)
Returns the relative weight of a equation.
Definition: energymodule.hh:295
static void addSolidEnergyStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants)
Add the energy storage term for a fluid phase to an equation vector.
Definition: energymodule.hh:399
static std::string eqName(unsigned eqIdx)
Returns the name of an equation or an empty string if the specified equation index does not belong to...
Definition: energymodule.hh:269
static void addPhaseStorage(Dune::FieldVector< LhsEval, numEq > &, const IntensiveQuantities &, unsigned)
Add the energy storage term for a fluid phase to an equation vector.
Definition: energymodule.hh:157
Provides the auxiliary methods required for consideration of the energy equation. ...
Definition: energymodule.hh:55
Provides the indices required for the energy equation.
Definition: energymodule.hh:495
static void addFracturePhaseStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants, const Scv &scv, unsigned phaseIdx)
Add the energy storage term for a fluid phase to an equation vector.
Definition: energymodule.hh:380
static void registerParameters()
Register all run-time parameters for the energy module.
Definition: energymodule.hh:77
static void setEnthalpyRate(RateVector &, const FluidState &, unsigned, const Evaluation &)
Given a fluid state, set the enthalpy rate which emerges from a volumetric rate.
Definition: energymodule.hh:126
Evaluation thermalConductivity() const
Returns the total thermal conductivity of the solid matrix in the sub-control volume.
Definition: energymodule.hh:565
Scalar temperatureGradNormal() const
The temperature gradient times the face normal [K m^2 / m].
Definition: energymodule.hh:733
static Scalar thermalConductionRate(const ExtensiveQuantities &)
Add the rate of the conductive energy flux to a rate vector.
Definition: energymodule.hh:149
static void addSolidEnergyStorage(Dune::FieldVector< LhsEval, numEq > &, const IntensiveQuantities &)
Add the energy storage term for the fracture part a fluid phase to an equation vector.
Definition: energymodule.hh:178
static Evaluation thermalConductionRate(const ExtensiveQuantities &extQuants)
Returns the conductive energy flux for a given flux integration point.
Definition: energymodule.hh:323
static Scalar eqWeight(const Model &, unsigned, unsigned)
Returns the relative weight of a equation of the residual.
Definition: energymodule.hh:108