Files
ResInsight/ApplicationLibCode/Application/Tools/RiaEclipseUnitTools.cpp
T
Magne Sjaastad 56e98ba1c4 #14476 ApplicationLibCode: Replace CVF_ASSERT with CAF_ASSERT
Migrate all assert macros in ApplicationLibCode to CAF_ASSERT and remove every
use of cvfAssert.h.

CVF_ASSERT is replaced one to one. CVF_TIGHT_ASSERT is also replaced by
CAF_ASSERT, which is semantically exact: CVF_ENABLE_TIGHT_ASSERTS is 1 only
under _DEBUG, and that is what CAF_ASSERT now does. The two CVF_FAIL_MSG sites
become CAF_ASSERT( false && "message" ), preserving the message with the idiom
already used elsewhere in the code base.

Counts before and after: CVF_ASSERT 1044 to 0, CVF_TIGHT_ASSERT 66 to 0,
CVF_FAIL_MSG 2 to 0, cvfAssert.h references 154 to 0.

Include handling: files that included cvfAssert.h directly now include
cafAssert.h instead, includes left dead by the migration are removed, and files
that were relying on cvfAssert.h transitively get an explicit cafAssert.h. Files
that reach cafAssert.h through another caf header are left unchanged; a missing
include here is a compile error, not a silently disabled assert.

ResultStatisticsCache links only LibCore and therefore had no path to
cafAssert.h. Add the cafPdmCore directory as a private include path rather than
linking the library, since cafAssert.h is header only.

Note that this stops these asserts from firing in Release and RelWithDebInfo,
where CVF_ASSERT was previously active.
2026-08-07 15:05:57 +02:00

169 lines
6.2 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017- Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaEclipseUnitTools.h"
#include "cafAppEnum.h"
#include "cafAssert.h"
#include <cmath>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RiaEclipseUnitTools::darcysConstant( RiaDefines::EclipseUnitSystem unitSystem )
{
// CDARCY Darcys constant
// = 0.00852702 (E300); 0.008527 (ECLIPSE 100) (METRIC)
// = 0.00112712 (E300); 0.001127 (ECLIPSE 100) (FIELD)
// = 3.6 (LAB)
// = 0.00864 (PVT - M)
switch ( unitSystem )
{
case RiaDefines::EclipseUnitSystem::UNITS_FIELD:
return 0.001127;
case RiaDefines::EclipseUnitSystem::UNITS_METRIC:
return 0.008527;
default:
CAF_ASSERT( false );
return 0.0;
}
}
//--------------------------------------------------------------------------------------------------
/// Convert Gas to oil equivalents
/// If field unit, the Gas is in Mft^3(=1000ft^3) while the others are in [stb] (barrel)
//--------------------------------------------------------------------------------------------------
double RiaEclipseUnitTools::convertSurfaceGasFlowRateToOilEquivalents( RiaDefines::EclipseUnitSystem caseUnitSystem, double eclGasFlowRate )
{
/// Unused Gas to Barrel conversion :
/// we convert gas to stb as well. Based on
/// 1 [stb] = 0.15898729492800007 [m^3]
/// 1 [ft] = 0.3048 [m]
///
/// NB Mft^3 = 1000 ft^3 - can wrongly be interpreted as M for Mega in metric units
if ( caseUnitSystem == RiaDefines::EclipseUnitSystem::UNITS_FIELD )
{
const double fieldGasToOilEquivalent = 1000.0 / 5614.63;
return fieldGasToOilEquivalent * eclGasFlowRate;
}
if ( caseUnitSystem == RiaDefines::EclipseUnitSystem::UNITS_METRIC )
{
double metricGasToOilEquivalent = 1.0 / 1000.0; // Sm^3 Gas to Sm^3 oe
return metricGasToOilEquivalent * eclGasFlowRate;
}
return HUGE_VAL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaEclipseUnitTools::unitStringPressure( RiaDefines::EclipseUnitSystem unitSystem )
{
switch ( unitSystem )
{
case RiaDefines::EclipseUnitSystem::UNITS_METRIC:
return "barsa";
case RiaDefines::EclipseUnitSystem::UNITS_FIELD:
return "psia";
case RiaDefines::EclipseUnitSystem::UNITS_LAB:
return "atma";
case RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN:
return "";
default:
return "";
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RiaEclipseUnitTools::convertToMeter( double sourceValue, const QString& sourceValueUnitText, bool replaceUnmatched )
{
QString timmed = sourceValueUnitText.trimmed();
if ( timmed.compare( "m", Qt::CaseInsensitive ) == 0 || timmed.compare( "md-m", Qt::CaseInsensitive ) == 0 )
{
return sourceValue;
}
else if ( timmed.compare( "cm", Qt::CaseInsensitive ) == 0 )
{
return sourceValue / 100.0;
}
else if ( timmed.compare( "mm", Qt::CaseInsensitive ) == 0 )
{
return sourceValue / 1000.0;
}
else if ( timmed.compare( "in", Qt::CaseInsensitive ) == 0 || timmed.compare( "inches", Qt::CaseInsensitive ) == 0 )
{
return RiaEclipseUnitTools::inchToMeter( sourceValue );
}
else if ( timmed.compare( "ft", Qt::CaseInsensitive ) == 0 || timmed.compare( "feet", Qt::CaseInsensitive ) == 0 ||
timmed.compare( "md-ft", Qt::CaseInsensitive ) == 0 )
{
return RiaEclipseUnitTools::feetToMeter( sourceValue );
}
if ( replaceUnmatched )
return HUGE_VAL;
else
return sourceValue;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RiaEclipseUnitTools::convertToFeet( double sourceValue, const QString& sourceValueUnitText, bool replaceUnmatched )
{
QString timmed = sourceValueUnitText.trimmed();
if ( timmed.compare( "ft", Qt::CaseInsensitive ) == 0 || timmed.compare( "feet", Qt::CaseInsensitive ) == 0 ||
timmed.compare( "md-ft", Qt::CaseInsensitive ) == 0 )
{
return sourceValue;
}
else if ( timmed.compare( "in", Qt::CaseInsensitive ) == 0 || timmed.compare( "inches", Qt::CaseInsensitive ) == 0 )
{
return RiaEclipseUnitTools::inchToFeet( sourceValue );
}
else if ( timmed.compare( "cm", Qt::CaseInsensitive ) == 0 )
{
double meter = sourceValue / 100.0;
return RiaEclipseUnitTools::meterToFeet( meter );
}
else if ( timmed.compare( "mm", Qt::CaseInsensitive ) == 0 )
{
double meter = sourceValue / 1000.0;
return RiaEclipseUnitTools::meterToFeet( meter );
}
else if ( timmed.compare( "m", Qt::CaseInsensitive ) == 0 || timmed.compare( "md-m", Qt::CaseInsensitive ) == 0 )
{
return RiaEclipseUnitTools::meterToFeet( sourceValue );
}
if ( replaceUnmatched )
return HUGE_VAL;
else
return sourceValue;
}