Merge pull request #5949 from akva2/fix_flows_compiler_warning

Fix compiler warning in FLOWS code
This commit is contained in:
Bård Skaflestad
2025-02-04 09:55:41 +01:00
committed by GitHub
3 changed files with 53 additions and 34 deletions

View File

@@ -179,7 +179,7 @@ struct BlackOilOnePhaseIndices
//////////////////////
//! \brief returns the index of "active" component
static unsigned canonicalToActiveComponentIndex(unsigned /*compIdx*/)
static constexpr unsigned canonicalToActiveComponentIndex(unsigned /*compIdx*/)
{
return 0;
}

View File

@@ -28,6 +28,8 @@
#ifndef EWOMS_BLACK_OIL_TWO_PHASE_INDICES_HH
#define EWOMS_BLACK_OIL_TWO_PHASE_INDICES_HH
#include <opm/common/utility/ConstexprAssert.hpp>
#include <cassert>
namespace Opm {
@@ -179,20 +181,20 @@ struct BlackOilTwoPhaseIndices
//////////////////////
//! \brief returns the index of "active" component
static unsigned canonicalToActiveComponentIndex(unsigned compIdx)
static constexpr unsigned canonicalToActiveComponentIndex(const unsigned compIdx)
{
// assumes canonical oil = 0, water = 1, gas = 2;
if (!gasEnabled) {
assert(compIdx != 2);
constexpr_assert(compIdx != 2);
// oil = 0, water = 1
return compIdx;
} else if (!waterEnabled) {
assert(compIdx != 1);
constexpr_assert(compIdx != 1);
// oil = 0, gas = 1
return compIdx / 2;
} else {
assert(!oilEnabled);
assert(compIdx != 0);
constexpr_assert(!oilEnabled);
constexpr_assert(compIdx != 0);
}
// water = 0, gas = 1;

View File

@@ -96,14 +96,14 @@ class OutputBlackOilModule : public GenericOutputBlackoilModule<GetPropType<Type
using Indices = GetPropType<TypeTag, Properties::Indices>;
using Dir = FaceDir::DirEnum;
enum { conti0EqIdx = Indices::conti0EqIdx };
enum { numPhases = FluidSystem::numPhases };
enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
enum { gasCompIdx = FluidSystem::gasCompIdx };
enum { oilCompIdx = FluidSystem::oilCompIdx };
enum { waterCompIdx = FluidSystem::waterCompIdx };
static constexpr int conti0EqIdx = Indices::conti0EqIdx;
static constexpr int numPhases = FluidSystem::numPhases;
static constexpr int oilPhaseIdx = FluidSystem::oilPhaseIdx;
static constexpr int gasPhaseIdx = FluidSystem::gasPhaseIdx;
static constexpr int waterPhaseIdx = FluidSystem::waterPhaseIdx;
static constexpr int gasCompIdx = FluidSystem::gasCompIdx;
static constexpr int oilCompIdx = FluidSystem::oilCompIdx;
static constexpr int waterCompIdx = FluidSystem::waterCompIdx;
enum { enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>() };
public:
@@ -705,25 +705,36 @@ public:
return;
const auto& problem = elemCtx.simulator().problem();
constexpr auto gas_idx = Indices::gasEnabled ?
conti0EqIdx + Indices::canonicalToActiveComponentIndex(gasCompIdx) : -1;
constexpr auto oil_idx = Indices::oilEnabled ?
conti0EqIdx + Indices::canonicalToActiveComponentIndex(oilCompIdx) : -1;
constexpr auto water_idx = Indices::waterEnabled ?
conti0EqIdx + Indices::canonicalToActiveComponentIndex(waterCompIdx) : -1;
for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) {
unsigned globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, /*timeIdx=*/0);
if (!problem.model().linearizer().getFlowsInfo().empty()) {
const auto& flowsInf = problem.model().linearizer().getFlowsInfo();
auto flowsInfos = flowsInf[globalDofIdx];
for (const auto& flowsInfo : flowsInfos) {
if (flowsInfo.faceId >= 0) {
if (!this->flows_[flowsInfo.faceId][gasCompIdx].empty()) {
this->flows_[flowsInfo.faceId][gasCompIdx][globalDofIdx]
= flowsInfo.flow[conti0EqIdx + Indices::canonicalToActiveComponentIndex(gasCompIdx)];
if constexpr (gas_idx >= 0) {
if (!this->flows_[flowsInfo.faceId][gasCompIdx].empty()) {
this->flows_[flowsInfo.faceId][gasCompIdx][globalDofIdx]
= flowsInfo.flow[gas_idx];
}
}
if (!this->flows_[flowsInfo.faceId][oilCompIdx].empty()) {
this->flows_[flowsInfo.faceId][oilCompIdx][globalDofIdx]
= flowsInfo.flow[conti0EqIdx + Indices::canonicalToActiveComponentIndex(oilCompIdx)];
if constexpr (oil_idx >= 0) {
if (!this->flows_[flowsInfo.faceId][oilCompIdx].empty()) {
this->flows_[flowsInfo.faceId][oilCompIdx][globalDofIdx]
= flowsInfo.flow[oil_idx];
}
}
if (!this->flows_[flowsInfo.faceId][waterCompIdx].empty()) {
this->flows_[flowsInfo.faceId][waterCompIdx][globalDofIdx]
= flowsInfo.flow[conti0EqIdx + Indices::canonicalToActiveComponentIndex(waterCompIdx)];
if constexpr (water_idx >= 0) {
if (!this->flows_[flowsInfo.faceId][waterCompIdx].empty()) {
this->flows_[flowsInfo.faceId][waterCompIdx][globalDofIdx]
= flowsInfo.flow[water_idx];
}
}
}
if (flowsInfo.faceId == -2) {
@@ -749,20 +760,26 @@ public:
// flores
if (!problem.model().linearizer().getFloresInfo().empty()) {
const auto& floresInf = problem.model().linearizer().getFloresInfo();
auto floresInfos =floresInf[globalDofIdx];
auto floresInfos = floresInf[globalDofIdx];
for (const auto& floresInfo : floresInfos) {
if (floresInfo.faceId >= 0) {
if (!this->flores_[floresInfo.faceId][gasCompIdx].empty()) {
this->flores_[floresInfo.faceId][gasCompIdx][globalDofIdx]
= floresInfo.flow[conti0EqIdx + Indices::canonicalToActiveComponentIndex(gasCompIdx)];
if constexpr (gas_idx >= 0) {
if (!this->flores_[floresInfo.faceId][gasCompIdx].empty()) {
this->flores_[floresInfo.faceId][gasCompIdx][globalDofIdx]
= floresInfo.flow[gas_idx];
}
}
if (!this->flores_[floresInfo.faceId][oilCompIdx].empty()) {
this->flores_[floresInfo.faceId][oilCompIdx][globalDofIdx]
= floresInfo.flow[conti0EqIdx + Indices::canonicalToActiveComponentIndex(oilCompIdx)];
if constexpr (oil_idx >= 0) {
if (!this->flores_[floresInfo.faceId][oilCompIdx].empty()) {
this->flores_[floresInfo.faceId][oilCompIdx][globalDofIdx]
= floresInfo.flow[oil_idx];
}
}
if (!this->flores_[floresInfo.faceId][waterCompIdx].empty()) {
this->flores_[floresInfo.faceId][waterCompIdx][globalDofIdx]
= floresInfo.flow[conti0EqIdx + Indices::canonicalToActiveComponentIndex(waterCompIdx)];
if constexpr (water_idx >= 0) {
if (!this->flores_[floresInfo.faceId][waterCompIdx].empty()) {
this->flores_[floresInfo.faceId][waterCompIdx][globalDofIdx]
= floresInfo.flow[water_idx];
}
}
}