mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Refactoring in BlackOilLocalResidualTpfa.
This commit is contained in:
parent
1b2c18f089
commit
6c0d5ea8c5
@ -99,7 +99,7 @@ public:
|
|||||||
static void computeStorage(Dune::FieldVector<LhsEval, numEq>& storage,
|
static void computeStorage(Dune::FieldVector<LhsEval, numEq>& storage,
|
||||||
const ElementContext& elemCtx,
|
const ElementContext& elemCtx,
|
||||||
unsigned dofIdx,
|
unsigned dofIdx,
|
||||||
unsigned timeIdx) const
|
unsigned timeIdx)
|
||||||
{
|
{
|
||||||
// retrieve the intensive quantities for the SCV at the specified point in time
|
// retrieve the intensive quantities for the SCV at the specified point in time
|
||||||
const IntensiveQuantities& intQuants = elemCtx.intensiveQuantities(dofIdx, timeIdx);
|
const IntensiveQuantities& intQuants = elemCtx.intensiveQuantities(dofIdx, timeIdx);
|
||||||
|
@ -178,33 +178,31 @@ public:
|
|||||||
/*!
|
/*!
|
||||||
* \copydoc FvBaseLocalResidual::computeFlux
|
* \copydoc FvBaseLocalResidual::computeFlux
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void computeFlux(RateVector& flux,
|
static void computeFlux(RateVector& flux,
|
||||||
const Problem& problem,
|
const Problem& problem,
|
||||||
const unsigned globalFocusDofIdx,
|
const unsigned globalIndexIn,
|
||||||
const unsigned globalIndexIn,
|
const unsigned globalIndexEx,
|
||||||
const unsigned globalIndexEx,
|
const IntensiveQuantities& intQuantsIn,
|
||||||
const IntensiveQuantities& intQuantsIn,
|
const IntensiveQuantities& intQuantsEx,
|
||||||
const IntensiveQuantities& intQuantsEx,
|
const unsigned timeIdx)
|
||||||
const unsigned timeIdx)
|
|
||||||
{
|
{
|
||||||
assert(timeIdx == 0);
|
assert(timeIdx == 0);
|
||||||
flux = 0.0;
|
flux = 0.0;
|
||||||
Scalar Vin = problem.model().dofTotalVolume(globalIndexIn);
|
Scalar Vin = problem.model().dofTotalVolume(globalIndexIn);
|
||||||
Scalar Vex = problem.model().dofTotalVolume(globalIndexEx);
|
Scalar Vex = problem.model().dofTotalVolume(globalIndexEx);
|
||||||
|
|
||||||
|
|
||||||
Scalar trans = 1.0;//problem.transmissibility(globalIndexIn,globalIndexEx);
|
Scalar trans = 1.0; // problem.transmissibility(globalIndexIn,globalIndexEx);
|
||||||
//Scalar faceArea = problem.area(globalIndexIn,globalIndexEx);
|
// Scalar faceArea = problem.area(globalIndexIn,globalIndexEx);
|
||||||
Scalar faceArea = 1.0;//NB need correct calculation local residual
|
Scalar faceArea = 1.0; // NB need correct calculation local residual
|
||||||
Scalar thpres = problem.thresholdPressure(globalIndexIn, globalIndexEx);
|
Scalar thpres = problem.thresholdPressure(globalIndexIn, globalIndexEx);
|
||||||
|
|
||||||
// estimate the gravity correction: for performance reasons we use a simplified
|
// estimate the gravity correction: for performance reasons we use a simplified
|
||||||
// approach for this flux module that assumes that gravity is constant and always
|
// approach for this flux module that assumes that gravity is constant and always
|
||||||
// acts into the downwards direction. (i.e., no centrifuge experiments, sorry.)
|
// acts into the downwards direction. (i.e., no centrifuge experiments, sorry.)
|
||||||
constexpr Scalar g = 9.8;
|
Scalar g = problem.gravity()[dimWorld - 1];
|
||||||
|
|
||||||
|
|
||||||
// this is quite hacky because the dune grid interface does not provide a
|
// this is quite hacky because the dune grid interface does not provide a
|
||||||
// cellCenterDepth() method (so we ask the problem to provide it). The "good"
|
// cellCenterDepth() method (so we ask the problem to provide it). The "good"
|
||||||
// solution would be to take the Z coordinate of the element centroids, but since
|
// solution would be to take the Z coordinate of the element centroids, but since
|
||||||
@ -215,31 +213,32 @@ public:
|
|||||||
|
|
||||||
// the distances from the DOF's depths. (i.e., the additional depth of the
|
// the distances from the DOF's depths. (i.e., the additional depth of the
|
||||||
// exterior DOF)
|
// exterior DOF)
|
||||||
Scalar distZ = zIn - zEx;// NB could be precalculated
|
Scalar distZ = zIn - zEx; // NB could be precalculated
|
||||||
|
|
||||||
//
|
//
|
||||||
//const ExtensiveQuantities& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
|
// const ExtensiveQuantities& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
|
||||||
calculateFluxes_(globalFocusDofIdx,
|
calculateFluxes_(flux,
|
||||||
flux,
|
problem, // should be removed
|
||||||
problem,// should be removed
|
|
||||||
intQuantsIn,
|
intQuantsIn,
|
||||||
intQuantsEx,
|
intQuantsEx,
|
||||||
timeIdx,//input
|
timeIdx, // input
|
||||||
Vin,
|
Vin,
|
||||||
Vex,
|
Vex,
|
||||||
globalIndexIn,
|
globalIndexIn,
|
||||||
globalIndexEx,
|
globalIndexEx,
|
||||||
distZ*g,
|
distZ * g,
|
||||||
thpres,
|
thpres,
|
||||||
trans,
|
trans,
|
||||||
faceArea);// should be removed
|
faceArea); // should be removed
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function demonstrates compatibility with the ElementContext-based interface.
|
||||||
|
// Actually using it will lead to double work since the element context already contains
|
||||||
|
// fluxes through its stored ExtensiveQuantities.
|
||||||
static void computeFlux(RateVector& flux,
|
static void computeFlux(RateVector& flux,
|
||||||
const ElementContext& elemCtx,
|
const ElementContext& elemCtx,
|
||||||
unsigned scvfIdx,
|
unsigned scvfIdx,
|
||||||
unsigned timeIdx) //const
|
unsigned timeIdx)
|
||||||
{
|
{
|
||||||
assert(timeIdx == 0);
|
assert(timeIdx == 0);
|
||||||
|
|
||||||
@ -253,15 +252,14 @@ public:
|
|||||||
unsigned exteriorDofIdx = scvf.exteriorIndex();
|
unsigned exteriorDofIdx = scvf.exteriorIndex();
|
||||||
assert(interiorDofIdx != exteriorDofIdx);
|
assert(interiorDofIdx != exteriorDofIdx);
|
||||||
|
|
||||||
//unsigned I = stencil.globalSpaceIndex(interiorDofIdx);
|
// unsigned I = stencil.globalSpaceIndex(interiorDofIdx);
|
||||||
//unsigned J = stencil.globalSpaceIndex(exteriorDofIdx);
|
// unsigned J = stencil.globalSpaceIndex(exteriorDofIdx);
|
||||||
Scalar Vin = elemCtx.dofVolume(interiorDofIdx, /*timeIdx=*/0);
|
Scalar Vin = elemCtx.dofVolume(interiorDofIdx, /*timeIdx=*/0);
|
||||||
Scalar Vex = elemCtx.dofVolume(exteriorDofIdx, /*timeIdx=*/0);
|
Scalar Vex = elemCtx.dofVolume(exteriorDofIdx, /*timeIdx=*/0);
|
||||||
const auto& globalIndexIn = stencil.globalSpaceIndex(interiorDofIdx);
|
const auto& globalIndexIn = stencil.globalSpaceIndex(interiorDofIdx);
|
||||||
const auto& globalIndexEx = stencil.globalSpaceIndex(exteriorDofIdx);
|
const auto& globalIndexEx = stencil.globalSpaceIndex(exteriorDofIdx);
|
||||||
Scalar trans = problem.transmissibility(elemCtx, interiorDofIdx, exteriorDofIdx);
|
Scalar trans = problem.transmissibility(elemCtx, interiorDofIdx, exteriorDofIdx);
|
||||||
//Scalar faceArea = scvf.area();
|
Scalar faceArea = scvf.area();
|
||||||
Scalar faceArea = 1.0;
|
|
||||||
Scalar thpres = problem.thresholdPressure(globalIndexIn, globalIndexEx);
|
Scalar thpres = problem.thresholdPressure(globalIndexIn, globalIndexEx);
|
||||||
|
|
||||||
// estimate the gravity correction: for performance reasons we use a simplified
|
// estimate the gravity correction: for performance reasons we use a simplified
|
||||||
@ -283,44 +281,38 @@ public:
|
|||||||
// exterior DOF)
|
// exterior DOF)
|
||||||
Scalar distZ = zIn - zEx;
|
Scalar distZ = zIn - zEx;
|
||||||
|
|
||||||
//
|
calculateFluxes_(flux,
|
||||||
//const ExtensiveQuantities& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
|
problem, // only used for trans compressibility
|
||||||
unsigned focusDofIdx = elemCtx.focusDofIndex();
|
|
||||||
const auto& globalFocusDofIdx = stencil.globalSpaceIndex(focusDofIdx);
|
|
||||||
calculateFluxes_(globalFocusDofIdx,
|
|
||||||
flux,
|
|
||||||
problem,//only used for trans compressibility
|
|
||||||
intQuantsIn,
|
intQuantsIn,
|
||||||
intQuantsEx,
|
intQuantsEx,
|
||||||
timeIdx,//input
|
timeIdx, // input
|
||||||
Vin,
|
Vin,
|
||||||
Vex,
|
Vex,
|
||||||
globalIndexIn,
|
globalIndexIn,
|
||||||
globalIndexEx,
|
globalIndexEx,
|
||||||
distZ*g,
|
distZ * g,
|
||||||
thpres,
|
thpres,
|
||||||
trans,
|
trans,
|
||||||
faceArea
|
faceArea);
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void calculateFluxes_(unsigned globalFocusDofIdx,
|
static void calculateFluxes_(
|
||||||
RateVector& flux,
|
RateVector& flux,
|
||||||
const Problem& problem, //only used for rockCompressibility which should be moved to intensive quantities
|
const Problem& problem, // only used for rockCompressibility which should be moved to intensive quantities
|
||||||
const IntensiveQuantities& intQuantsIn,
|
const IntensiveQuantities& intQuantsIn,
|
||||||
const IntensiveQuantities& intQuantsEx,
|
const IntensiveQuantities& intQuantsEx,
|
||||||
const unsigned timeIdx,
|
const unsigned timeIdx,
|
||||||
const Scalar& Vin,
|
const Scalar& Vin,
|
||||||
const Scalar& Vex,
|
const Scalar& Vex,
|
||||||
const unsigned& globalIndexIn,
|
const unsigned& globalIndexIn,
|
||||||
const unsigned& globalIndexEx,
|
const unsigned& globalIndexEx,
|
||||||
const Scalar& distZg,
|
const Scalar& distZg,
|
||||||
const Scalar& thpres,
|
const Scalar& thpres,
|
||||||
const Scalar& trans,
|
const Scalar& trans,
|
||||||
const Scalar& faceArea // may be removed but need for compatibility with volume local assembly
|
const Scalar& faceArea
|
||||||
){
|
)
|
||||||
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
|
{
|
||||||
|
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
|
||||||
if (!FluidSystem::phaseIsActive(phaseIdx))
|
if (!FluidSystem::phaseIsActive(phaseIdx))
|
||||||
continue;
|
continue;
|
||||||
// darcy flux calculation
|
// darcy flux calculation
|
||||||
@ -328,72 +320,71 @@ public:
|
|||||||
//
|
//
|
||||||
short upIdx;
|
short upIdx;
|
||||||
// fake intices should only be used to get upwind anc compatibility with old functions
|
// fake intices should only be used to get upwind anc compatibility with old functions
|
||||||
short interiorDofIdx = 0;//NB
|
short interiorDofIdx = 0; // NB
|
||||||
short exteriorDofIdx = 1;//NB
|
short exteriorDofIdx = 1; // NB
|
||||||
Evaluation pressureDifference;
|
Evaluation pressureDifference;
|
||||||
ExtensiveQuantities::calculatePhasePressureDiff_(upIdx,
|
ExtensiveQuantities::calculatePhasePressureDiff_(upIdx,
|
||||||
dnIdx,
|
dnIdx,
|
||||||
pressureDifference,
|
pressureDifference,
|
||||||
intQuantsIn,
|
intQuantsIn,
|
||||||
intQuantsEx,
|
intQuantsEx,
|
||||||
timeIdx,//input
|
timeIdx, // input
|
||||||
phaseIdx,//input
|
phaseIdx, // input
|
||||||
interiorDofIdx,//input
|
interiorDofIdx, // input
|
||||||
exteriorDofIdx,//intput
|
exteriorDofIdx, // intput
|
||||||
Vin,
|
Vin,
|
||||||
Vex,
|
Vex,
|
||||||
globalIndexIn,
|
globalIndexIn,
|
||||||
globalIndexEx,
|
globalIndexEx,
|
||||||
distZg,
|
distZg,
|
||||||
thpres);
|
thpres);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const IntensiveQuantities& up = (upIdx == interiorDofIdx) ? intQuantsIn : intQuantsEx;
|
const IntensiveQuantities& up = (upIdx == interiorDofIdx) ? intQuantsIn : intQuantsEx;
|
||||||
unsigned globalUpIndex;
|
unsigned globalUpIndex;
|
||||||
if(upIdx == interiorDofIdx){
|
if (upIdx == interiorDofIdx) {
|
||||||
//up = intQuantsIn;
|
// up = intQuantsIn;
|
||||||
globalUpIndex = globalIndexIn;
|
globalUpIndex = globalIndexIn;
|
||||||
}else{
|
} else {
|
||||||
//up = intQuantsEx;
|
// up = intQuantsEx;
|
||||||
globalUpIndex = globalIndexEx;
|
globalUpIndex = globalIndexEx;
|
||||||
}
|
}
|
||||||
// TODO: should the rock compaction transmissibility multiplier be upstreamed
|
// TODO: should the rock compaction transmissibility multiplier be upstreamed
|
||||||
// or averaged? all fluids should see the same compaction?!
|
// or averaged? all fluids should see the same compaction?!
|
||||||
//const auto& globalIndex = stencil.globalSpaceIndex(upstreamIdx);
|
// const auto& globalIndex = stencil.globalSpaceIndex(upstreamIdx);
|
||||||
const Evaluation& transMult = up.rockCompTransMultiplier();
|
const Evaluation& transMult = up.rockCompTransMultiplier();
|
||||||
//const Evaluation& transMult =
|
// const Evaluation& transMult =
|
||||||
// problem.template rockCompTransMultiplier<Evaluation>(up, globalUpIndex);
|
// problem.template rockCompTransMultiplier<Evaluation>(up, globalUpIndex);
|
||||||
Evaluation darcyFlux;
|
Evaluation darcyFlux;
|
||||||
if(pressureDifference == 0){
|
if (pressureDifference == 0) {
|
||||||
darcyFlux = 0.0; //NB maybe we could drop calculations
|
darcyFlux = 0.0; // NB maybe we could drop calculations
|
||||||
}else{
|
} else {
|
||||||
//if (upIdx == interiorDofIdx)
|
// if (upIdx == interiorDofIdx)
|
||||||
if(globalUpIndex == globalIndexIn)
|
if (globalUpIndex == globalIndexIn)
|
||||||
darcyFlux =
|
darcyFlux = pressureDifference * up.mobility(phaseIdx) * transMult * (-trans / faceArea);
|
||||||
pressureDifference*up.mobility(phaseIdx)*transMult*(-trans/faceArea);
|
else
|
||||||
else
|
darcyFlux = pressureDifference * (Toolbox::value(up.mobility(phaseIdx)) * Toolbox::value(transMult) * (-trans / faceArea));
|
||||||
darcyFlux =
|
}
|
||||||
pressureDifference*(Toolbox::value(up.mobility(phaseIdx))*Toolbox::value(transMult)*(-trans/faceArea));
|
// const auto& darcyFlux = extQuants.volumeFlux(phaseIdx);
|
||||||
}
|
// unsigned upIdx = static_cast<unsigned>(extQuants.upstreamIndex(phaseIdx));
|
||||||
//const auto& darcyFlux = extQuants.volumeFlux(phaseIdx);
|
|
||||||
//unsigned upIdx = static_cast<unsigned>(extQuants.upstreamIndex(phaseIdx));
|
// const IntensiveQuantities& up = elemCtx.intensiveQuantities(upIdx, timeIdx);
|
||||||
|
unsigned pvtRegionIdx = up.pvtRegionIndex();
|
||||||
//const IntensiveQuantities& up = elemCtx.intensiveQuantities(upIdx, timeIdx);
|
using FluidState = typename IntensiveQuantities::FluidState;
|
||||||
unsigned pvtRegionIdx = up.pvtRegionIndex();
|
// if (upIdx == globalFocusDofIdx){
|
||||||
using FluidState = typename IntensiveQuantities::FluidState;
|
if (globalUpIndex == globalIndexIn) {
|
||||||
//if (upIdx == globalFocusDofIdx){
|
const auto& invB
|
||||||
if (globalUpIndex == globalFocusDofIdx){
|
= getInvB_<FluidSystem, FluidState, Evaluation>(up.fluidState(), phaseIdx, pvtRegionIdx);
|
||||||
const auto& invB = getInvB_<FluidSystem, FluidState, Evaluation>(up.fluidState(), phaseIdx, pvtRegionIdx);
|
const auto& surfaceVolumeFlux = invB * darcyFlux;
|
||||||
const auto& surfaceVolumeFlux = invB*darcyFlux;
|
evalPhaseFluxes_<Evaluation, Evaluation, FluidState>(
|
||||||
evalPhaseFluxes_<Evaluation,Evaluation,FluidState>(flux, phaseIdx, pvtRegionIdx, surfaceVolumeFlux, up.fluidState());
|
flux, phaseIdx, pvtRegionIdx, surfaceVolumeFlux, up.fluidState());
|
||||||
}else{
|
} else {
|
||||||
const auto& invB = getInvB_<FluidSystem, FluidState, Scalar>(up.fluidState(), phaseIdx, pvtRegionIdx);
|
const auto& invB = getInvB_<FluidSystem, FluidState, Scalar>(up.fluidState(), phaseIdx, pvtRegionIdx);
|
||||||
const auto& surfaceVolumeFlux = invB*darcyFlux;
|
const auto& surfaceVolumeFlux = invB * darcyFlux;
|
||||||
evalPhaseFluxes_<Scalar,Evaluation,FluidState>(flux, phaseIdx, pvtRegionIdx, surfaceVolumeFlux, up.fluidState());
|
evalPhaseFluxes_<Scalar, Evaluation, FluidState>(
|
||||||
}
|
flux, phaseIdx, pvtRegionIdx, surfaceVolumeFlux, up.fluidState());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// // deal with solvents (if present)
|
// // deal with solvents (if present)
|
||||||
@ -419,7 +410,7 @@ public:
|
|||||||
|
|
||||||
// DiffusionModule::addDiffusiveFlux(flux, elemCtx, scvfIdx, timeIdx);
|
// DiffusionModule::addDiffusiveFlux(flux, elemCtx, scvfIdx, timeIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void computeSource(RateVector& source,
|
static void computeSource(RateVector& source,
|
||||||
const Problem& problem,
|
const Problem& problem,
|
||||||
unsigned globalSpaceIdex,
|
unsigned globalSpaceIdex,
|
||||||
|
@ -443,9 +443,8 @@ private:
|
|||||||
const IntensiveQuantities* intQuantsExP = model_().cachedIntensiveQuantities(globJ, /*timeIdx*/ 0);
|
const IntensiveQuantities* intQuantsExP = model_().cachedIntensiveQuantities(globJ, /*timeIdx*/ 0);
|
||||||
assert(intQuantsExP);
|
assert(intQuantsExP);
|
||||||
const IntensiveQuantities& intQuantsEx = *intQuantsExP;
|
const IntensiveQuantities& intQuantsEx = *intQuantsExP;
|
||||||
unsigned globalFocusDofIdx = globI;
|
|
||||||
LocalResidual::computeFlux(
|
LocalResidual::computeFlux(
|
||||||
adres, problem_(), globalFocusDofIdx, globI, globJ, intQuantsIn, intQuantsEx, 0);
|
adres, problem_(), globI, globJ, intQuantsIn, intQuantsEx, 0);
|
||||||
adres *= trans_[globI][loc];
|
adres *= trans_[globI][loc];
|
||||||
setResAndJacobi(res, bMat, adres);
|
setResAndJacobi(res, bMat, adres);
|
||||||
residual_[globI] += res;
|
residual_[globI] += res;
|
||||||
|
Loading…
Reference in New Issue
Block a user