ResInsight/ApplicationCode/ProjectDataModel/Completions/RimWellPathAicdParameters.cpp

225 lines
10 KiB
C++
Raw Normal View History

2018-12-05 05:52:36 -06:00
/////////////////////////////////////////////////////////////////////////////////
//
2019-01-09 08:21:38 -06:00
// Copyright (C) 2018- Equinor ASA
2018-12-05 05:52:36 -06:00
//
// 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 "RimWellPathAicdParameters.h"
#include "RimPerforationInterval.h"
2018-12-05 05:52:36 -06:00
#include "RimWellPath.h"
#include "RimWellPathValve.h"
2018-12-05 05:52:36 -06:00
#include "cafPdmDoubleStringValidator.h"
2018-12-05 05:52:36 -06:00
#include "cafPdmUiDoubleValueEditor.h"
#include "cafPdmUiGroup.h"
#include "cafPdmUiLineEditor.h"
2018-12-07 08:48:11 -06:00
#include <limits>
CAF_PDM_SOURCE_INIT( RimWellPathAicdParameters, "WellPathAicdParameters" );
2018-12-05 05:52:36 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPathAicdParameters::RimWellPathAicdParameters()
{
// clang-format off
CAF_PDM_InitObject("RimWellPathAicdParameters", "", "", "");
CAF_PDM_InitField(&m_deviceOpen, "DeviceOpen", true, "Device Open?", "", "", "");
2018-12-07 08:48:11 -06:00
CAF_PDM_InitFieldNoDefault(&m_aicdParameterFields[AICD_STRENGTH], "StrengthAICD", "Strength of AICD", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_aicdParameterFields[AICD_DENSITY_CALIB_FLUID], "DensityCalibrationFluid", "Calibration Fluid Density (kg/m^3)", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_aicdParameterFields[AICD_VISCOSITY_CALIB_FLUID], "ViscosityCalibrationFluid", "Calibration Fluid Viscosity (cP)", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_aicdParameterFields[AICD_VOL_FLOW_EXP], "VolumeFlowRateExponent", "Volume Flow Rate Exponent", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_aicdParameterFields[AICD_VISOSITY_FUNC_EXP], "ViscosityFunctionExponent", "Viscosity Function Exponent", "", "", "");
2018-12-05 05:52:36 -06:00
2018-12-07 08:48:11 -06:00
CAF_PDM_InitField(&m_aicdParameterFields[AICD_CRITICAL_WATER_IN_LIQUID_FRAC], "CriticalWaterLiquidFractionEmul", QString("1*"), "Critical Water in Liquid Fraction for emulsions", "", "", "");
CAF_PDM_InitField(&m_aicdParameterFields[AICD_EMULSION_VISC_TRANS_REGION], "ViscosityTransitionRegionEmul", QString("1*"), "Emulsion Viscosity Transition Region", "", "", "");
CAF_PDM_InitField(&m_aicdParameterFields[AICD_MAX_RATIO_EMULSION_VISC], "MaxRatioOfEmulsionVisc", QString("1*"), "Max Ratio of Emulsion to Continuous Viscosity", "", "", "");
CAF_PDM_InitField(&m_aicdParameterFields[AICD_MAX_FLOW_RATE], "MaxFlowRate", QString("1*"), "Max Flow Rate for AICD Device (m^3 / day)", "", "", "");
CAF_PDM_InitField(&m_aicdParameterFields[AICD_EXP_OIL_FRAC_DENSITY], "ExponentOilDensity", QString("1*"), "Density Exponent of Oil Fraction", "", "", "");
CAF_PDM_InitField(&m_aicdParameterFields[AICD_EXP_WATER_FRAC_DENSITY], "ExponentWaterDensity", QString("1*"), "Density Exponent of Water Fraction", "", "", "");
CAF_PDM_InitField(&m_aicdParameterFields[AICD_EXP_GAS_FRAC_DENSITY], "ExponentGasDensity", QString("1*"), "Density Exponent of Gas Fraction", "", "", "");
CAF_PDM_InitField(&m_aicdParameterFields[AICD_EXP_OIL_FRAC_VISCOSITY], "ExponentOilViscosity", QString("1*"), "Viscosity Exponent of Oil Fraction", "", "", "");
CAF_PDM_InitField(&m_aicdParameterFields[AICD_EXP_WATER_FRAC_VISCOSITY], "ExponentWaterViscosity", QString("1*"), "Viscosity Exponent of Water Fraction", "", "", "");
CAF_PDM_InitField(&m_aicdParameterFields[AICD_EXP_GAS_FRAC_VISCOSITY], "ExponentGasViscosity", QString("1*"), "Viscosity Exponent of Gas Fraction", "", "", "");
2018-12-05 05:52:36 -06:00
std::vector<caf::PdmFieldHandle*> allFields;
this->fields(allFields);
for (caf::PdmFieldHandle* field : allFields)
{
caf::PdmField<QString>* stringField = dynamic_cast<caf::PdmField<QString>*>(field);
if (stringField)
{
stringField->uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
}
}
// clang-format on
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPathAicdParameters::~RimWellPathAicdParameters()
{
}
2018-12-05 05:52:36 -06:00
//--------------------------------------------------------------------------------------------------
/// Requires that all the required parameters are set and a proper value
//--------------------------------------------------------------------------------------------------
bool RimWellPathAicdParameters::isValid() const
{
for ( const caf::PdmField<QString>* stringField : stringFieldsWithNoValidDefault() )
2018-12-05 05:52:36 -06:00
{
if ( stringField->value().isEmpty() ) return false;
2018-12-05 05:52:36 -06:00
bool ok = true;
stringField->value().toDouble( &ok );
if ( !ok ) return false;
2018-12-05 05:52:36 -06:00
}
return true;
}
2018-12-07 08:48:11 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimWellPathAicdParameters::isOpen() const
{
return m_deviceOpen;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::array<double, AICD_NUM_PARAMS> RimWellPathAicdParameters::doubleValues() const
{
std::array<double, AICD_NUM_PARAMS> doubleValues;
for ( int i = 0; i < (int)AICD_NUM_PARAMS; ++i )
2018-12-07 08:48:11 -06:00
{
caf::PdmDoubleStringValidator validator( nullptr );
QString stringValue = m_aicdParameterFields[(AICDParameters)i].value();
bool ok = true;
double doubleValue = stringValue.toDouble( &ok );
if ( ok )
2018-12-07 08:48:11 -06:00
{
doubleValues[i] = doubleValue;
}
else
{
doubleValues[i] = std::numeric_limits<double>::infinity();
}
}
return doubleValues;
}
2018-12-05 05:52:36 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathAicdParameters::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
2018-12-05 05:52:36 -06:00
{
bool readOnly = uiConfigName == QString( "InsideValve" );
uiOrdering.add( &m_deviceOpen );
m_deviceOpen.uiCapability()->setUiReadOnly( readOnly );
for ( int i = 0; i < (int)AICD_NUM_REQ_PARAMS; ++i )
2018-12-07 08:48:11 -06:00
{
uiOrdering.add( &m_aicdParameterFields[(AICDParameters)i] );
m_aicdParameterFields[(AICDParameters)i].uiCapability()->setUiReadOnly( readOnly );
2018-12-07 08:48:11 -06:00
}
caf::PdmUiGroup* additionalGroup = uiOrdering.addNewGroup( "Additional Parameters" );
for ( int i = (int)AICD_NUM_REQ_PARAMS; i < (int)AICD_NUM_PARAMS; ++i )
2018-12-07 08:48:11 -06:00
{
additionalGroup->add( &m_aicdParameterFields[(AICDParameters)i] );
m_aicdParameterFields[(AICDParameters)i].uiCapability()->setUiReadOnly( readOnly );
2018-12-07 08:48:11 -06:00
}
additionalGroup->setCollapsedByDefault( true );
2018-12-05 05:52:36 -06:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathAicdParameters::defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute )
2018-12-05 05:52:36 -06:00
{
const caf::PdmField<QString>* stringField = dynamic_cast<const caf::PdmField<QString>*>( field );
caf::PdmUiLineEditorAttribute* lineEditorAttr = dynamic_cast<caf::PdmUiLineEditorAttribute*>( attribute );
if ( stringField && lineEditorAttr )
2018-12-05 05:52:36 -06:00
{
if ( stringFieldsWithNoValidDefault().count( stringField ) )
2018-12-05 05:52:36 -06:00
{
lineEditorAttr->validator = new caf::PdmDoubleStringValidator( "" );
2018-12-05 05:52:36 -06:00
}
else
{
lineEditorAttr->validator = new caf::PdmDoubleStringValidator( "1*" );
2018-12-05 05:52:36 -06:00
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::set<const caf::PdmField<QString>*> RimWellPathAicdParameters::stringFieldsWithNoValidDefault() const
{
2018-12-07 08:48:11 -06:00
std::set<const caf::PdmField<QString>*> fields;
for ( int i = 0; i < (int)AICD_NUM_REQ_PARAMS; ++i )
2018-12-07 08:48:11 -06:00
{
fields.insert( &m_aicdParameterFields[(AICDParameters)i] );
2018-12-07 08:48:11 -06:00
}
2018-12-05 05:52:36 -06:00
return fields;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathAicdParameters::setUnitLabels()
{
if ( isMetric() )
2018-12-05 05:52:36 -06:00
{
m_aicdParameterFields[AICD_DENSITY_CALIB_FLUID].uiCapability()->setUiName(
"Calibration Fluid Density (kg / m ^ 3)" );
m_aicdParameterFields[AICD_MAX_FLOW_RATE].uiCapability()->setUiName(
"Max Flow Rate for AICD Device(m ^ 3 / day)" );
2018-12-05 05:52:36 -06:00
}
else
{
m_aicdParameterFields[AICD_DENSITY_CALIB_FLUID].uiCapability()->setUiName(
"Calibration Fluid Density (lb / ft ^3)" );
m_aicdParameterFields[AICD_MAX_FLOW_RATE].uiCapability()->setUiName(
"Max Flow Rate for AICD Device(ft ^ 3 / day)" );
2018-12-05 05:52:36 -06:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimWellPathAicdParameters::isMetric() const
{
bool metric = false;
RimWellPath* wellPath;
firstAncestorOrThisOfType( wellPath );
if ( wellPath )
2018-12-05 05:52:36 -06:00
{
2020-04-24 01:10:48 -05:00
if ( wellPath->unitSystem() == RiaEclipseUnitTools::UnitSystem::UNITS_METRIC )
2018-12-05 05:52:36 -06:00
{
metric = true;
}
}
return metric;
}