Capillary pressure laws: enforce that parameter objects are finalized before they are used

this only has an effect if compiled in debug mode, i.e., if the NDEBUG
symbol is not defined.
This commit is contained in:
Andreas Lauser
2013-11-15 16:15:10 +01:00
parent 0a7e764310
commit eb95c78cef
9 changed files with 205 additions and 55 deletions

View File

@@ -26,6 +26,8 @@
#include <opm/material/Valgrind.hpp>
#include <cassert>
namespace Opm {
/*!
@@ -45,24 +47,35 @@ public:
typedef TraitsT Traits;
BrooksCoreyParams()
{ Valgrind::SetUndefined(*this); }
{
Valgrind::SetUndefined(*this);
#ifndef NDEBUG
finalized_ = false;
#endif
}
BrooksCoreyParams(Scalar entryPressure, Scalar lambda)
: entryPressure_(entryPressure), lambda_(lambda)
{ }
{
finalize();
}
/*!
* \brief Calculate all dependent quantities once the independent
* quantities of the parameter object have been set.
*/
void finalize()
{ }
{
#ifndef NDEBUG
finalized_ = true;
#endif
}
/*!
* \brief Returns the entry pressure [Pa]
*/
Scalar entryPressure() const
{ return entryPressure_; }
{ assertFinalized_(); return entryPressure_; }
/*!
* \brief Set the entry pressure [Pa]
@@ -75,7 +88,7 @@ public:
* \brief Returns the lambda shape parameter
*/
Scalar lambda() const
{ return lambda_; }
{ assertFinalized_(); return lambda_; }
/*!
* \brief Set the lambda shape parameter
@@ -84,6 +97,16 @@ public:
{ lambda_ = v; }
private:
#ifndef NDEBUG
void assertFinalized_() const
{ assert(finalized_); }
bool finalized_;
#else
void assertFinalized_() const
{ }
#endif
Scalar entryPressure_;
Scalar lambda_;
};

View File

@@ -25,6 +25,8 @@
#include <type_traits>
#include <cassert>
namespace Opm {
/*!
@@ -45,19 +47,28 @@ public:
* \brief The default constructor.
*/
EclDefaultMaterialParams()
{ }
{
#ifndef NDEBUG
finalized_ = false;
#endif
}
/*!
* \brief Finish the initialization of the parameter object.
*/
void finalize()
{} // Do nothing: The two two-phase parameter objects need to be finalized themselfs!
{
// Do nothing: The two two-phase parameter objects need to be finalized themselfs!
#ifndef NDEBUG
finalized_ = true;
#endif
}
/*!
* \brief The parameter object for the gas-oil twophase law.
*/
const GasOilParams& gasOilParams() const
{ return gasOilParams_; }
{ assertFinalized_(); return gasOilParams_; }
/*!
* \brief Set the parameter object for the gas-oil twophase law.
@@ -69,7 +80,7 @@ public:
* \brief The parameter object for the oil-water twophase law.
*/
const OilWaterParams& oilWaterParams() const
{ return oilWaterParams_; }
{ assertFinalized_(); return oilWaterParams_; }
/*!
* \brief The parameter object for the oil-water twophase law.
@@ -78,6 +89,16 @@ public:
{ oilWaterParams_ = val; }
private:
#ifndef NDEBUG
void assertFinalized_() const
{ assert(finalized_); }
bool finalized_;
#else
void assertFinalized_() const
{ }
#endif
GasOilParams gasOilParams_;
OilWaterParams oilWaterParams_;
};

View File

@@ -44,9 +44,12 @@ public:
EffToAbsLawParams()
: EffLawParams()
{
sumResidualSaturations_ = 0.0;
for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
residualSaturation_[phaseIdx] = 0.0;
#ifndef NDEBUG
finalized_ = false;
#endif
}
/*!
@@ -55,32 +58,46 @@ public:
*/
void finalize()
{
sumResidualSaturations_ = 0.0;
for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
sumResidualSaturations_ += residualSaturation_[phaseIdx];
EffLawParams::finalize();
#ifndef NDEBUG
finalized_ = true;
#endif
}
/*!
* \brief Return the residual saturation of a phase.
*/
Scalar residualSaturation(int phaseIdx) const
{ return residualSaturation_[phaseIdx]; }
{ assertFinalized_(); return residualSaturation_[phaseIdx]; }
/*!
* \brief Return the sum of the residual saturations.
*/
Scalar sumResidualSaturations() const
{ return sumResidualSaturations_; }
{ assertFinalized_(); return sumResidualSaturations_; }
/*!
* \brief Set the residual saturation of a phase.
*/
void setResidualSaturation(int phaseIdx, Scalar value)
{
sumResidualSaturations_ -= residualSaturation_[phaseIdx];
sumResidualSaturations_ += value;
residualSaturation_[phaseIdx] = value;
}
{ residualSaturation_[phaseIdx] = value; }
private:
#ifndef NDEBUG
void assertFinalized_() const
{ assert(finalized_); }
bool finalized_;
#else
void assertFinalized_() const
{ }
#endif
Scalar residualSaturation_[numPhases];
Scalar sumResidualSaturations_;
};

View File

@@ -50,6 +50,10 @@ public:
setPcMinSat(phaseIdx, 0.0);
setPcMaxSat(phaseIdx, 0.0);
}
#ifndef NDEBUG
finalized_ = false;
#endif
}
/*!
@@ -57,7 +61,11 @@ public:
* quantities of the parameter object have been set.
*/
void finalize()
{ }
{
#ifndef NDEBUG
finalized_ = true;
#endif
}
/*!
* \brief Return the relative phase pressure at the minimum saturation of a phase.
@@ -65,7 +73,7 @@ public:
* This means \f$p_{c\alpha}\f$ at \f$S_\alpha=0\f$.
*/
Scalar pcMinSat(int phaseIdx) const
{ return pcMinSat_[phaseIdx]; }
{ assertFinalized_();return pcMinSat_[phaseIdx]; }
/*!
* \brief Set the relative phase pressure at the minimum saturation of a phase.
@@ -81,7 +89,7 @@ public:
* This means \f$p_{c\alpha}\f$ at \f$S_\alpha=1\f$.
*/
Scalar pcMaxSat(int phaseIdx) const
{ return pcMaxSat_[phaseIdx]; }
{ assertFinalized_(); return pcMaxSat_[phaseIdx]; }
/*!
* \brief Set the relative phase pressure at the maximum saturation of a phase.
@@ -92,6 +100,16 @@ public:
{ pcMaxSat_[phaseIdx] = val; }
private:
#ifndef NDEBUG
void assertFinalized_() const
{ assert(finalized_); }
bool finalized_;
#else
void assertFinalized_() const
{ }
#endif
Scalar pcMaxSat_[numPhases];
Scalar pcMinSat_[numPhases];
};

View File

@@ -49,6 +49,10 @@ public:
currentSnr_ = 0;
mdc_ = new ScanningCurve(/*Swr=*/0);
pisc_ = csc_ = NULL;
#ifndef NDEBUG
finalized_ = false;
#endif
}
ParkerLenhardParams(const ParkerLenhardParams &p)
@@ -57,6 +61,10 @@ public:
SwrPc_ = p.SwrPc();
mdc_ = new ScanningCurve(p.SwrPc());
pisc_ = csc_ = NULL;
#ifndef NDEBUG
finalized_ = p.finalized_;
#endif
}
~ParkerLenhardParams()
@@ -67,14 +75,18 @@ public:
* quantities of the parameter object have been set.
*/
void finalize()
{ }
{
#ifndef NDEBUG
finalized_ = true;
#endif
}
/*!
* \brief Returns the parameters of the main imbibition curve (which uses
* the van Genuchten capillary pressure model).
*/
const VanGenuchtenParams &micParams() const
{ return *micParams_; }
{ assertFinalized_(); return *micParams_; }
/*!
* \brief Sets the parameters of the main imbibition curve (which uses
@@ -88,7 +100,7 @@ public:
* the van Genuchten capillary pressure model).
*/
const VanGenuchtenParams &mdcParams() const
{ return *mdcParams_; }
{ assertFinalized_(); return *mdcParams_; }
/*!
* \brief Sets the parameters of the main drainage curve (which uses
@@ -101,7 +113,7 @@ public:
* \brief Returns non-wetting phase residual saturation.
*/
Scalar Snr() const
{ return Snr_; }
{ assertFinalized_(); return Snr_; }
/*!
* \brief Set the non-wetting phase residual saturation.
@@ -113,13 +125,13 @@ public:
* \brief Returns wetting phase residual saturation for the capillary pressure curve.
*/
Scalar SwrPc() const
{ return SwrPc_; }
{ assertFinalized_(); return SwrPc_; }
/*!
* \brief Returns wetting phase residual saturation for the residual saturation curves.
*/
Scalar SwrKr() const
{ return SwrKr_; }
{ assertFinalized_(); return SwrKr_; }
/*!
* \brief Set the wetting phase residual saturation for the
@@ -138,7 +150,7 @@ public:
* \brief Returns the current effective residual saturation.
*/
Scalar currentSnr() const
{ return currentSnr_; }
{ assertFinalized_(); return currentSnr_; }
/*!
* \brief Set the current effective residual saturation.
@@ -150,7 +162,7 @@ public:
* \brief Returns the main drainage curve
*/
ScanningCurve *mdc() const
{ return mdc_; }
{ assertFinalized_(); return mdc_; }
/*!
* \brief Set the main drainage curve.
@@ -162,7 +174,7 @@ public:
* \brief Returns the primary imbibition scanning curve
*/
ScanningCurve *pisc() const
{ return pisc_; }
{ assertFinalized_(); return pisc_; }
/*!
* \brief Set the primary imbibition scanning curve.
@@ -174,7 +186,7 @@ public:
* \brief Returns the current scanning curve
*/
ScanningCurve *csc() const
{ return csc_; }
{ assertFinalized_(); return csc_; }
/*!
* \brief Set the current scanning curve.
@@ -182,8 +194,17 @@ public:
void setCsc(ScanningCurve *val)
{ csc_ = val; }
private:
#ifndef NDEBUG
void assertFinalized_() const
{ assert(finalized_); }
bool finalized_;
#else
void assertFinalized_() const
{ }
#endif
const VanGenuchtenParams *micParams_;
const VanGenuchtenParams *mdcParams_;
Scalar SwrPc_;

View File

@@ -148,20 +148,19 @@ public:
{ krnSamples_ = samples; }
private:
void assertFinalized_() const
{
#ifndef NDEBUG
assert(finalized_);
void assertFinalized_() const
{ assert(finalized_); }
bool finalized_;
#else
void assertFinalized_() const
{ }
#endif
}
SamplePoints pcwnSamples_;
SamplePoints krwSamples_;
SamplePoints krnSamples_;
#ifndef NDEBUG
bool finalized_;
#endif
};
} // namespace Opm

View File

@@ -44,12 +44,16 @@ public:
RegularizedBrooksCoreyParams()
: BrooksCoreyParams()
, SwThres_(1e-2)
{ }
{
#ifndef NDEBUG
finalized_ = false;
#endif
}
RegularizedBrooksCoreyParams(Scalar entryPressure, Scalar lambda)
: BrooksCoreyParams(entryPressure, lambda)
, SwThres_(1e-2)
{ }
{ finalize(); }
/*!
* \brief Calculate all dependent quantities once the independent
@@ -58,6 +62,9 @@ public:
void finalize()
{
BrooksCoreyParams::finalize();
#ifndef NDEBUG
finalized_ = true;
#endif
}
/*!
@@ -65,7 +72,7 @@ public:
* is regularized.
*/
Scalar thresholdSw() const
{ return SwThres_; }
{ assertFinalized_(); return SwThres_; }
/*!
* \brief Set the threshold saturation below which the capillary pressure
@@ -75,6 +82,16 @@ public:
{ SwThres_ = value; }
private:
#ifndef NDEBUG
void assertFinalized_() const
{ assert(finalized_); }
bool finalized_;
#else
void assertFinalized_() const
{ }
#endif
Scalar SwThres_;
};
} // namespace Opm

View File

@@ -55,7 +55,9 @@ public:
: Parent(vgAlpha, vgN)
, pcnwLowSw_(0.01)
, pcnwHighSw_(0.99)
{}
{
finalize();
}
/*!
* \brief Calculate all dependent quantities once the independent
@@ -76,6 +78,9 @@ public:
pcnwHigh_, 0, // y0, y1
mThreshold, pcnwSlopeHigh_); // m0, m1
#ifndef NDEBUG
finalized_ = true;
#endif
}
/*!
@@ -83,14 +88,14 @@ public:
* capillary pressure is regularized.
*/
Scalar pcnwLowSw() const
{ return pcnwLowSw_; }
{ assertFinalized_(); return pcnwLowSw_; }
/*!
* \brief Return the capillary pressure at the low threshold
* saturation of the wetting phase.
*/
Scalar pcnwLow() const
{ return pcnwLow_; }
{ assertFinalized_(); return pcnwLow_; }
/*!
* \brief Return the slope capillary pressure curve if Sw is
@@ -99,7 +104,7 @@ public:
* For this case, we extrapolate the curve using a straight line.
*/
Scalar pcnwSlopeLow() const
{ return pcnwSlopeLow_; }
{ assertFinalized_(); return pcnwSlopeLow_; }
/*!
* \brief Set the threshold saturation below which the capillary
@@ -113,21 +118,21 @@ public:
* capillary pressure is regularized.
*/
Scalar pcnwHighSw() const
{ return pcnwHighSw_; }
{ assertFinalized_(); return pcnwHighSw_; }
/*!
* \brief Return the capillary pressure at the high threshold
* saturation of the wetting phase.
*/
Scalar pcnwHigh() const
{ return pcnwHigh_; }
{ assertFinalized_(); return pcnwHigh_; }
/*!
* \brief Return the spline curve which ought to be used between
* the upper threshold saturation and 1.
*/
const Spline<Scalar> &pcnwHighSpline() const
{ return pcnwHighSpline_; }
{ assertFinalized_(); return pcnwHighSpline_; }
/*!
* \brief Return the slope capillary pressure curve if Sw is
@@ -136,7 +141,7 @@ public:
* For this case, we extrapolate the curve using a straight line.
*/
Scalar pcnwSlopeHigh() const
{ return pcnwSlopeHigh_; }
{ assertFinalized_(); return pcnwSlopeHigh_; }
/*!
* \brief Set the threshold saturation below which the capillary
@@ -146,6 +151,16 @@ public:
{ pcnwHighSw_ = value; }
private:
#ifndef NDEBUG
void assertFinalized_() const
{ assert(finalized_); }
bool finalized_;
#else
void assertFinalized_() const
{ }
#endif
Scalar pcnwLowSw_;
Scalar pcnwHighSw_;

View File

@@ -43,12 +43,17 @@ public:
typedef TraitsT Traits;
VanGenuchtenParams()
{}
{
#ifndef NDEBUG
finalized_ = false;
#endif
}
VanGenuchtenParams(Scalar vgAlpha, Scalar vgN)
{
setVgAlpha(vgAlpha);
setVgN(vgN);
finalize();
}
/*!
@@ -56,14 +61,18 @@ public:
* quantities of the parameter object have been set.
*/
void finalize()
{ }
{
#ifndef NDEBUG
finalized_ = true;
#endif
}
/*!
* \brief Return the \f$\alpha\f$ shape parameter of van Genuchten's
* curve.
*/
Scalar vgAlpha() const
{ return vgAlpha_; }
{ assertFinalized_(); return vgAlpha_; }
/*!
* \brief Set the \f$\alpha\f$ shape parameter of van Genuchten's
@@ -77,7 +86,7 @@ public:
* curve.
*/
Scalar vgM() const
{ return vgM_; }
{ assertFinalized_(); return vgM_; }
/*!
* \brief Set the \f$m\f$ shape parameter of van Genuchten's
@@ -93,7 +102,7 @@ public:
* curve.
*/
Scalar vgN() const
{ return vgN_; }
{ assertFinalized_(); return vgN_; }
/*!
* \brief Set the \f$n\f$ shape parameter of van Genuchten's
@@ -105,6 +114,16 @@ public:
{ vgN_ = n; vgM_ = 1 - 1/vgN_; }
private:
#ifndef NDEBUG
void assertFinalized_() const
{ assert(finalized_); }
bool finalized_;
#else
void assertFinalized_() const
{ }
#endif
Scalar vgAlpha_;
Scalar vgM_;
Scalar vgN_;