Skip to content

Commit

Permalink
static hack
Browse files Browse the repository at this point in the history
  • Loading branch information
akva2 committed Feb 20, 2025
1 parent 2f75055 commit c6e1b9c
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions opm/simulators/flow/OutputBlackoilModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class OutputBlackOilModule : public GenericOutputBlackoilModule<GetPropType<Type
int episodeIndex;
const FluidState& fs;
const IntensiveQuantities& intQuants;
const HysteresisParams& hParams;
};

using ScalarExtractFunc = std::function<Scalar(const ExtractContext&)>;
Expand All @@ -280,7 +281,9 @@ class OutputBlackOilModule : public GenericOutputBlackoilModule<GetPropType<Type
const auto& problem = elemCtx.simulator().problem();
const auto& modelResid = elemCtx.simulator().model().linearizer().residual();
const auto& matLawManager = problem.materialLawManager();
HysteresisParams hysterParams;
static int filtered_time = -1000;
static std::vector<Entry> filtered_extractors;
if (filtered_time != elemCtx.simulator().episodeIndex()) {
const auto extractors = std::array{
Entry{&this->saturation_, [](const unsigned phase, const ExtractContext& ectx)
{ return getValue(ectx.fs.saturation(phase)); }},
Expand Down Expand Up @@ -484,44 +487,44 @@ class OutputBlackOilModule : public GenericOutputBlackoilModule<GetPropType<Type
return std::max(getValue(ectx.fs.saturation(waterPhaseIdx)),
problem.maxWaterSaturation(ectx.globalDofIdx));
}, !matLawManager->enableHysteresis()},
Entry{&this->soMax_, [&hysterParams](const ExtractContext&)
Entry{&this->soMax_, [](const ExtractContext& ectx)
{
return hysterParams.somax;
return ectx.hParams.somax;
}, matLawManager->enableHysteresis() &&
matLawManager->enableNonWettingHysteresis() &&
FluidSystem::phaseIsActive(oilPhaseIdx) &&
FluidSystem::phaseIsActive(waterPhaseIdx)},
Entry{&this->swMax_, [&hysterParams](const ExtractContext&)
Entry{&this->swMax_, [](const ExtractContext& ectx)
{
return hysterParams.swmax;
return ectx.hParams.swmax;
}, matLawManager->enableHysteresis() &&
matLawManager->enableWettingHysteresis() &&
FluidSystem::phaseIsActive(oilPhaseIdx) &&
FluidSystem::phaseIsActive(waterPhaseIdx)},
Entry{&this->swmin_, [&hysterParams](const ExtractContext&)
Entry{&this->swmin_, [](const ExtractContext& ectx)
{
return hysterParams.swmin;
return ectx.hParams.swmin;
}, matLawManager->enableHysteresis() &&
matLawManager->enablePCHysteresis() &&
FluidSystem::phaseIsActive(oilPhaseIdx) &&
FluidSystem::phaseIsActive(waterPhaseIdx)},
Entry{&this->sgmax_, [&hysterParams](const ExtractContext&)
Entry{&this->sgmax_, [](const ExtractContext& ectx)
{
return hysterParams.sgmax;
return ectx.hParams.sgmax;
}, matLawManager->enableHysteresis() &&
matLawManager->enableNonWettingHysteresis() &&
FluidSystem::phaseIsActive(oilPhaseIdx) &&
FluidSystem::phaseIsActive(gasPhaseIdx)},
Entry{&this->shmax_, [&hysterParams](const ExtractContext&)
Entry{&this->shmax_, [](const ExtractContext& ectx)
{
return hysterParams.shmax;
return ectx.hParams.shmax;
}, matLawManager->enableHysteresis() &&
matLawManager->enableWettingHysteresis() &&
FluidSystem::phaseIsActive(oilPhaseIdx) &&
FluidSystem::phaseIsActive(gasPhaseIdx)},
Entry{&this->somin_, [&hysterParams](const ExtractContext&)
Entry{&this->somin_, [](const ExtractContext& ectx)
{
return hysterParams.somin;
return ectx.hParams.somin;
}, matLawManager->enableHysteresis() &&
matLawManager->enablePCHysteresis() &&
FluidSystem::phaseIsActive(oilPhaseIdx) &&
Expand Down Expand Up @@ -581,6 +584,30 @@ class OutputBlackOilModule : public GenericOutputBlackoilModule<GetPropType<Type
FluidSystem::phaseIsActive(gasPhaseIdx)},
};

filtered_extractors.clear();
filtered_extractors.reserve(extractors.size());
std::copy_if(extractors.begin(), extractors.end(),
std::back_inserter(filtered_extractors),
[](const Entry& e)
{
return e.condition;
return std::visit(VisitorOverloadSet{
[](const ScalarBuffer* v)
{
return !v->empty();
},
[](const PhaseArray* v)
{
return std::any_of(v->begin(), v->end(),
[](const auto& ve)
{ return !ve.empty(); });
}
}, e.data);
});
filtered_time = elemCtx.simulator().episodeIndex();
}

HysteresisParams hysterParams;
for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) {
const auto& intQuants = elemCtx.intensiveQuantities(dofIdx, /*timeIdx=*/0);
const auto& fs = intQuants.fluidState();
Expand All @@ -590,7 +617,8 @@ class OutputBlackOilModule : public GenericOutputBlackoilModule<GetPropType<Type
elemCtx.primaryVars(dofIdx, /*timeIdx=*/0).pvtRegionIndex(),
elemCtx.simulator().episodeIndex(),
fs,
intQuants
intQuants,
hysterParams
};

if (matLawManager->enableHysteresis()) {
Expand All @@ -608,7 +636,7 @@ class OutputBlackOilModule : public GenericOutputBlackoilModule<GetPropType<Type
}
}

std::for_each(extractors.begin(), extractors.end(),
std::for_each(filtered_extractors.begin(), filtered_extractors.end(),
[&fs, &ectx](const auto& entry)
{
std::visit(VisitorOverloadSet{
Expand Down

0 comments on commit c6e1b9c

Please sign in to comment.