Refactor enums for Segments

This commit is contained in:
Joakim Hove 2019-09-01 08:25:55 +02:00
parent 7021669758
commit 9690588dd4
5 changed files with 118 additions and 123 deletions

View File

@ -32,6 +32,31 @@ namespace Opm {
class WellSegments {
public:
enum class LengthDepth{
INC = 0,
ABS = 1
};
static const std::string LengthDepthToString(LengthDepth enumValue);
static LengthDepth LengthDepthFromString(const std::string& stringValue);
enum class CompPressureDrop {
HFA = 0,
HF_ = 1,
H__ = 2
};
static const std::string CompPressureDropToString(CompPressureDrop enumValue);
static CompPressureDrop CompPressureDropFromString(const std::string& stringValue);
enum class MultiPhaseModel {
HO = 0,
DF = 1
};
static const std::string MultiPhaseModelToString(MultiPhaseModel enumValue);
static MultiPhaseModel MultiPhaseModelFromString(const std::string& stringValue);
WellSegments() = default;
const std::string& wellName() const;
@ -40,8 +65,8 @@ namespace Opm {
double lengthTopSegment() const;
double volumeTopSegment() const;
WellSegment::CompPressureDropEnum compPressureDrop() const;
WellSegment::MultiPhaseModelEnum multiPhaseModel() const;
CompPressureDrop compPressureDrop() const;
MultiPhaseModel multiPhaseModel() const;
// mapping the segment number to the index in the vector of segments
int segmentNumberToIndex(const int segment_number) const;
@ -63,7 +88,6 @@ namespace Opm {
void processABS();
void processINC(const bool first_time);
// name of the well
std::string m_well_name;
// depth of the nodal point of the top segment
// it is taken as the BHP reference depth of the well
@ -74,11 +98,11 @@ namespace Opm {
// effective wellbore volume of the top segment
double m_volume_top;
// type of the tubing length and depth information
WellSegment::LengthDepthEnum m_length_depth_type;
LengthDepth m_length_depth_type;
// components of the pressure drop to be included
WellSegment::CompPressureDropEnum m_comp_pressure_drop;
CompPressureDrop m_comp_pressure_drop;
// multi-phase flow model
WellSegment::MultiPhaseModelEnum m_multiphase_model;
MultiPhaseModel m_multiphase_model;
// There are X and Y cooridnate of the nodal point of the top segment
// Since they are not used for simulations and we are not supporting plotting,
// we are not handling them at the moment.

View File

@ -135,33 +135,6 @@ namespace Opm {
namespace WellSegment{
enum LengthDepthEnum {
INC = 0,
ABS = 1
};
const std::string LengthDepthEnumToString(LengthDepthEnum enumValue);
LengthDepthEnum LengthDepthEnumFromString(const std::string& stringValue);
enum CompPressureDropEnum {
HFA = 0,
HF_ = 1,
H__ = 2
};
const std::string CompPressureDropEnumToString(CompPressureDropEnum enumValue);
CompPressureDropEnum CompPressureDropEnumFromString(const std::string& stringValue);
enum MultiPhaseModelEnum {
HO = 0,
DF = 1
};
const std::string MultiPhaseModelEnumToString(MultiPhaseModelEnum enumValue);
MultiPhaseModelEnum MultiPhaseModelEnumFromString(const std::string& stringValue);
}
}
#endif

View File

@ -57,11 +57,11 @@ namespace Opm {
}
WellSegment::CompPressureDropEnum WellSegments::compPressureDrop() const {
WellSegments::CompPressureDrop WellSegments::compPressureDrop() const {
return m_comp_pressure_drop;
}
WellSegment::MultiPhaseModelEnum WellSegments::multiPhaseModel() const {
WellSegments::MultiPhaseModel WellSegments::multiPhaseModel() const {
return m_multiphase_model;
}
@ -105,19 +105,19 @@ namespace Opm {
m_depth_top = record1.getItem("DEPTH").getSIDouble(0);
m_length_top = record1.getItem("LENGTH").getSIDouble(0);
m_length_depth_type = WellSegment::LengthDepthEnumFromString(record1.getItem("INFO_TYPE").getTrimmedString(0));
m_length_depth_type = LengthDepthFromString(record1.getItem("INFO_TYPE").getTrimmedString(0));
m_volume_top = record1.getItem("WELLBORE_VOLUME").getSIDouble(0);
m_comp_pressure_drop = WellSegment::CompPressureDropEnumFromString(record1.getItem("PRESSURE_COMPONENTS").getTrimmedString(0));
m_multiphase_model = WellSegment::MultiPhaseModelEnumFromString(record1.getItem("FLOW_MODEL").getTrimmedString(0));
m_comp_pressure_drop = CompPressureDropFromString(record1.getItem("PRESSURE_COMPONENTS").getTrimmedString(0));
m_multiphase_model = MultiPhaseModelFromString(record1.getItem("FLOW_MODEL").getTrimmedString(0));
// the main branch is 1 instead of 0
// the segment number for top segment is also 1
if (m_length_depth_type == WellSegment::INC) {
if (m_length_depth_type == LengthDepth::INC) {
m_segments.emplace_back( 1, 1, 0, 0., 0.,
invalid_value, invalid_value, invalid_value,
m_volume_top, false );
} else if (m_length_depth_type == WellSegment::ABS) {
} else if (m_length_depth_type == LengthDepth::ABS) {
m_segments.emplace_back( 1, 1, 0, m_length_top, m_depth_top,
invalid_value, invalid_value, invalid_value,
m_volume_top, true );
@ -160,7 +160,7 @@ namespace Opm {
double volume;
if (itemVolume.hasValue(0)) {
volume = itemVolume.getSIDouble(0);
} else if (m_length_depth_type == WellSegment::INC) {
} else if (m_length_depth_type == LengthDepth::INC) {
volume = area * segment_length;
} else {
volume = invalid_value; // A * L, while L is not determined yet
@ -178,7 +178,7 @@ namespace Opm {
outlet_segment = i - 1;
}
if (m_length_depth_type == WellSegment::INC) {
if (m_length_depth_type == LengthDepth::INC) {
m_segments.emplace_back( i, branch, outlet_segment, segment_length, depth_change,
diameter, roughness, area, volume, false );
} else if (i == segment2) {
@ -223,9 +223,9 @@ namespace Opm {
}
void WellSegments::process(bool first_time) {
if (this->m_length_depth_type == WellSegment::ABS)
if (this->m_length_depth_type == LengthDepth::ABS)
this->processABS();
else if (this->m_length_depth_type == WellSegment::INC)
else if (this->m_length_depth_type == LengthDepth::INC)
this->processINC(first_time);
else
throw std::logic_error("Invalid llength/depth/type in segment data structure");
@ -429,4 +429,75 @@ namespace Opm {
" V: " << well_segments.volumeTopSegment() << " }}";
}
const std::string WellSegments::LengthDepthToString(LengthDepth enumValue) {
switch (enumValue) {
case LengthDepth::INC:
return "INC";
case LengthDepth::ABS:
return "ABS";
default:
throw std::invalid_argument("unhandled LengthDepth value");
}
}
WellSegments::LengthDepth WellSegments::LengthDepthFromString(const std::string& string_value ) {
if (string_value == "INC") {
return LengthDepth::INC;
} else if (string_value == "ABS") {
return LengthDepth::ABS;
} else {
throw std::invalid_argument("Unknown enum string_value: " + string_value + " for LengthDepth");
}
}
const std::string WellSegments::CompPressureDropToString(CompPressureDrop enumValue) {
switch (enumValue) {
case CompPressureDrop::HFA:
return "HFA";
case CompPressureDrop::HF_:
return "HF-";
case CompPressureDrop::H__:
return "H--";
default:
throw std::invalid_argument("unhandled CompPressureDrop value");
}
}
WellSegments::CompPressureDrop WellSegments::CompPressureDropFromString( const std::string& string_value ) {
if (string_value == "HFA") {
return CompPressureDrop::HFA;
} else if (string_value == "HF-") {
return CompPressureDrop::HF_;
} else if (string_value == "H--") {
return CompPressureDrop::H__;
} else {
throw std::invalid_argument("Unknown enum string_value: " + string_value + " for CompPressureDrop");
}
}
const std::string WellSegments::MultiPhaseModelToString(MultiPhaseModel enumValue) {
switch (enumValue) {
case MultiPhaseModel::HO:
return "HO";
case MultiPhaseModel::DF:
return "DF";
default:
throw std::invalid_argument("unhandled MultiPhaseModel value");
}
}
WellSegments::MultiPhaseModel WellSegments::MultiPhaseModelFromString(const std::string& string_value ) {
if ((string_value == "HO") || (string_value == "H0")) {
return MultiPhaseModel::HO;
} else if (string_value == "DF") {
return MultiPhaseModel::DF;
} else {
throw std::invalid_argument("Unknown enum string_value: " + string_value + " for MultiPhaseModel");
}
}
}

View File

@ -262,79 +262,6 @@ namespace Opm {
}
}
namespace WellSegment{
const std::string LengthDepthEnumToString(LengthDepthEnum enumValue) {
switch (enumValue) {
case INC:
return "INC";
case ABS:
return "ABS";
default:
throw std::invalid_argument("unhandled LengthDepthEnum value");
}
}
LengthDepthEnum LengthDepthEnumFromString(const std::string& string ) {
if (string == "INC") {
return INC;
} else if (string == "ABS") {
return ABS;
} else {
throw std::invalid_argument("Unknown enum string: " + string + " for LengthDepthEnum");
}
}
const std::string CompPressureDropEnumToString(CompPressureDropEnum enumValue) {
switch (enumValue) {
case HFA:
return "HFA";
case HF_:
return "HF-";
case H__:
return "H--";
default:
throw std::invalid_argument("unhandled CompPressureDropEnum value");
}
}
CompPressureDropEnum CompPressureDropEnumFromString( const std::string& string ) {
if (string == "HFA") {
return HFA;
} else if (string == "HF-") {
return HF_;
} else if (string == "H--") {
return H__;
} else {
throw std::invalid_argument("Unknown enum string: " + string + " for CompPressureDropEnum");
}
}
const std::string MultiPhaseModelEnumToString(MultiPhaseModelEnum enumValue) {
switch (enumValue) {
case HO:
return "HO";
case DF:
return "DF";
default:
throw std::invalid_argument("unhandled MultiPhaseModelEnum value");
}
}
MultiPhaseModelEnum MultiPhaseModelEnumFromString(const std::string& string ) {
if ((string == "HO") || (string == "H0")) {
return HO;
} else if (string == "DF") {
return DF;
} else {
throw std::invalid_argument("Unknown enum string: " + string + " for MultiPhaseModelEnum");
}
}
}
GroupType operator|(GroupType lhs, GroupType rhs) {
return static_cast<GroupType>(static_cast<std::underlying_type<GroupType>::type>(lhs) | static_cast<std::underlying_type<GroupType>::type>(rhs));

View File

@ -465,19 +465,19 @@ BOOST_AUTO_TEST_CASE( MULTISEGMENT_ABS ) {
const double depth_top = rec1.getItem("DEPTH").get< double >(0);
const double length_top = rec1.getItem("LENGTH").get< double >(0);
const double volume_top = rec1.getItem("WELLBORE_VOLUME").get< double >(0);
const WellSegment::LengthDepthEnum length_depth_type = WellSegment::LengthDepthEnumFromString(rec1.getItem("INFO_TYPE").getTrimmedString(0));
const WellSegment::CompPressureDropEnum comp_pressure_drop = WellSegment::CompPressureDropEnumFromString(rec1.getItem("PRESSURE_COMPONENTS").getTrimmedString(0));
const WellSegment::MultiPhaseModelEnum multiphase_model = WellSegment::MultiPhaseModelEnumFromString(rec1.getItem("FLOW_MODEL").getTrimmedString(0));
const WellSegments::LengthDepth length_depth_type = WellSegments::LengthDepthFromString(rec1.getItem("INFO_TYPE").getTrimmedString(0));
const WellSegments::CompPressureDrop comp_pressure_drop = WellSegments::CompPressureDropFromString(rec1.getItem("PRESSURE_COMPONENTS").getTrimmedString(0));
const WellSegments::MultiPhaseModel multiphase_model = WellSegments::MultiPhaseModelFromString(rec1.getItem("FLOW_MODEL").getTrimmedString(0));
BOOST_CHECK_EQUAL( "PROD01", well_name );
BOOST_CHECK_EQUAL( 2512.5, depth_top );
BOOST_CHECK_EQUAL( 2512.5, length_top );
BOOST_CHECK_EQUAL( 1.0e-5, volume_top );
const std::string length_depth_type_string = WellSegment::LengthDepthEnumToString(length_depth_type);
const std::string length_depth_type_string = WellSegments::LengthDepthToString(length_depth_type);
BOOST_CHECK_EQUAL( length_depth_type_string, "ABS" );
const std::string comp_pressure_drop_string = WellSegment::CompPressureDropEnumToString(comp_pressure_drop);
const std::string comp_pressure_drop_string = WellSegments::CompPressureDropToString(comp_pressure_drop);
BOOST_CHECK_EQUAL( comp_pressure_drop_string, "H--" );
const std::string multiphase_model_string = WellSegment::MultiPhaseModelEnumToString(multiphase_model);
const std::string multiphase_model_string = WellSegments::MultiPhaseModelToString(multiphase_model);
BOOST_CHECK_EQUAL( multiphase_model_string, "HO" );
}