From 04a3a9ada57ef5abc1e672021833819c351feda3 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 26 Jun 2018 09:45:50 +0200 Subject: [PATCH] WIP: cleaun up access methods --- .../EclipseState/Schedule/Connection.hpp | 18 ++++++------ .../EclipseState/Schedule/MSW/Segment.hpp | 2 +- .../Schedule/MSW/WellSegments.hpp | 2 +- .../output/eclipse/WellDataSerializers.cpp | 2 +- .../EclipseState/Schedule/Connection.cpp | 17 +++-------- .../EclipseState/Schedule/MSW/Compsegs.cpp | 28 +++++++++---------- .../EclipseState/Schedule/MSW/Compsegs.hpp | 4 +-- .../EclipseState/Schedule/MSW/Segment.cpp | 10 +++---- .../Schedule/MSW/WellSegments.cpp | 24 ++++++++-------- .../eclipse/EclipseState/Schedule/Well.cpp | 2 +- .../EclipseState/Schedule/WellConnections.cpp | 4 +-- tests/parser/MultisegmentWellTests.cpp | 20 ++++++------- tests/parser/integration/ParseKEYWORD.cpp | 16 +++++------ tests/test_serialize_ICON.cpp | 2 +- 14 files changed, 71 insertions(+), 80 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Connection.hpp b/opm/parser/eclipse/EclipseState/Schedule/Connection.hpp index ff18b2306..5d982730b 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Connection.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Connection.hpp @@ -61,21 +61,21 @@ namespace Opm { int getSatTableId() const; void fixDefaultIJ(int wellHeadI , int wellHeadJ); void shift_complnum( int ); - int getSegmentNumber() const; - double getCenterDepth() const; bool attachedToSegment() const; WellCompletion::DirectionEnum getDirection() const; bool operator==( const Connection& ) const; bool operator!=( const Connection& ) const; - // related segment number - // -1 means the completion is not related to segment - int m_segment_number = -1; - double m_center_depth; - int complnum; - WellCompletion::StateEnum state; - double wellPi = 1.0; + + // related segment number + // -1 means the completion is not related to segment + int segment_number = -1; + + double center_depth; + int complnum; + WellCompletion::StateEnum state; + double wellPi = 1.0; private: int m_i, m_j, m_k; diff --git a/opm/parser/eclipse/EclipseState/Schedule/MSW/Segment.hpp b/opm/parser/eclipse/EclipseState/Schedule/MSW/Segment.hpp index dc6f11ece..e6fa1b0d6 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/MSW/Segment.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/MSW/Segment.hpp @@ -58,7 +58,7 @@ namespace Opm { private: // segment number // it should work as a ID. - int m_segment_number; + int segment_number; // branch number // for top segment, it should always be 1 int m_branch; diff --git a/opm/parser/eclipse/EclipseState/Schedule/MSW/WellSegments.hpp b/opm/parser/eclipse/EclipseState/Schedule/MSW/WellSegments.hpp index c14a35ce2..12b8d0ab2 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/MSW/WellSegments.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/MSW/WellSegments.hpp @@ -91,7 +91,7 @@ namespace Opm { std::vector< Segment > m_segments; // the mapping from the segment number to the // storage index in the vector - std::map m_segment_number_to_index; + std::map segment_number_to_index; }; } diff --git a/src/opm/output/eclipse/WellDataSerializers.cpp b/src/opm/output/eclipse/WellDataSerializers.cpp index 5dfc348a2..cfaf029f5 100644 --- a/src/opm/output/eclipse/WellDataSerializers.cpp +++ b/src/opm/output/eclipse/WellDataSerializers.cpp @@ -104,7 +104,7 @@ serialize_ICON(int lookup_step, 1 : -1000; data[ offset + ICON_SEGMENT_INDEX ] = connection.attachedToSegment() ? - connection.getSegmentNumber() : 0; + connection.segment_number : 0; connection_offset += niconz; } diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Connection.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Connection.cpp index c581c094f..6adbdf0ab 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Connection.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Connection.cpp @@ -54,7 +54,7 @@ namespace Opm { m_satTableId(satTableId), state(state), m_direction(direction), - m_center_depth( depth ) + center_depth( depth ) {} bool Connection::sameCoordinate(const Connection& other) const { @@ -133,19 +133,10 @@ namespace Opm { } - int Connection::getSegmentNumber() const { - if (!attachedToSegment()) { - throw std::runtime_error(" the completion is not attached to a segment!\n "); - } - return m_segment_number; - } - double Connection::getCenterDepth() const { - return m_center_depth; - } bool Connection::attachedToSegment() const { - return (m_segment_number > 0); + return (segment_number > 0); } bool Connection::operator==( const Connection& rhs ) const { @@ -161,8 +152,8 @@ namespace Opm { && this->m_satTableId == rhs.m_satTableId && this->state == rhs.state && this->m_direction == rhs.m_direction - && this->m_segment_number == rhs.m_segment_number - && this->m_center_depth == rhs.m_center_depth; + && this->segment_number == rhs.segment_number + && this->center_depth == rhs.center_depth; } bool Connection::operator!=( const Connection& rhs ) const { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.cpp index 99e37a833..bbf91d4b3 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.cpp @@ -41,8 +41,8 @@ namespace Opm { m_distance_start(distance_start_in), m_distance_end(distance_end_in), m_dir(dir_in), - m_center_depth(center_depth_in), - m_segment_number(segment_number_in) + center_depth(center_depth_in), + segment_number(segment_number_in) { } @@ -141,7 +141,7 @@ namespace Opm { for( auto& compseg : compsegs ) { // need to determine the related segment number first - if (compseg.m_segment_number != 0) continue; + if (compseg.segment_number != 0) continue; const double center_distance = (compseg.m_distance_start + compseg.m_distance_end) / 2.0; const int branch_number = compseg.m_branch_number; @@ -164,15 +164,15 @@ namespace Opm { throw std::runtime_error("The perforation failed in finding a related segment \n"); } - if (compseg.m_center_depth < 0.) { + if (compseg.center_depth < 0.) { throw std::runtime_error("Obtaining perforation depth from COMPDAT data is not supported yet"); } - compseg.m_segment_number = segment_number; + compseg.segment_number = segment_number; // when depth is default or zero, we obtain the depth of the connection based on the information // of the related segments - if (compseg.m_center_depth == 0.) { + if (compseg.center_depth == 0.) { compseg.calculateCenterDepthWithSegments(segment_set); } } @@ -181,13 +181,13 @@ namespace Opm { void Compsegs::calculateCenterDepthWithSegments(const WellSegments& segment_set) { // the depth and distance of the segment to the well head - const Segment& segment = segment_set.getFromSegmentNumber(m_segment_number); + const Segment& segment = segment_set.getFromSegmentNumber(segment_number); const double segment_depth = segment.depth(); const double segment_distance = segment.totalLength(); // for top segment, no interpolation is needed - if (m_segment_number == 1) { - m_center_depth = segment_depth; + if (segment_number == 1) { + center_depth = segment_depth; return; } @@ -211,7 +211,7 @@ namespace Opm { if (interpolation_segment_number == 0) { throw std::runtime_error("Failed in finding a segment to do the interpolation with segment " - + std::to_string(m_segment_number)); + + std::to_string(segment_number)); } // performing the interpolation @@ -224,10 +224,10 @@ namespace Opm { if (segment_length == 0.) { throw std::runtime_error("Zero segment length is botained when doing interpolation between segment " - + std::to_string(m_segment_number) + " and segment " + std::to_string(interpolation_segment_number) ); + + std::to_string(segment_number) + " and segment " + std::to_string(interpolation_segment_number) ); } - m_center_depth = segment_depth + (center_distance - segment_distance) / segment_length * depth_change_segment; + center_depth = segment_depth + (center_distance - segment_distance) / segment_length * depth_change_segment; } void Compsegs::updateConnectionsWithSegment(const std::vector< Compsegs >& compsegs, @@ -239,8 +239,8 @@ namespace Opm { const int k = compseg.m_k; Connection& connection = connection_set.getFromIJK( i, j, k ); - connection.m_segment_number = compseg.m_segment_number; - connection.m_center_depth = compseg.m_center_depth; + connection.segment_number = compseg.segment_number; + connection.center_depth = compseg.center_depth; } for (size_t ic = 0; ic < connection_set.size(); ++ic) { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.hpp b/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.hpp index 5fdb06284..b5b5631b8 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.hpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Compsegs.hpp @@ -44,10 +44,10 @@ namespace Opm { double m_distance_end; WellCompletion::DirectionEnum m_dir; - double m_center_depth; + double center_depth; // we do not handle thermal length for the moment // double m_thermal_length; - int m_segment_number; + int segment_number; Compsegs(int i_in, int j_in, int k_in, int branch_number_in, double distance_start_in, double distance_end_in, WellCompletion::DirectionEnum dir_in, double center_depth_in, int segment_number_in); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Segment.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Segment.cpp index 24a8b16ff..550e2d53e 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Segment.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/MSW/Segment.cpp @@ -22,7 +22,7 @@ namespace Opm { Segment::Segment() - : m_segment_number(-1), + : segment_number(-1), m_branch(-1), m_outlet_segment(-1), m_total_length(invalid_value), @@ -39,7 +39,7 @@ namespace Opm { Segment::Segment(int segment_number_in, int branch_in, int outlet_segment_in, double length_in, double depth_in, double internal_diameter_in, double roughness_in, double cross_area_in, double volume_in, bool data_ready_in) - : m_segment_number(segment_number_in), + : segment_number(segment_number_in), m_branch(branch_in), m_outlet_segment(outlet_segment_in), m_total_length(length_in), @@ -53,7 +53,7 @@ namespace Opm { } int Segment::segmentNumber() const { - return m_segment_number; + return segment_number; } @@ -122,7 +122,7 @@ namespace Opm { } bool Segment::operator==( const Segment& rhs ) const { - return this->m_segment_number == rhs.m_segment_number + return this->segment_number == rhs.segment_number && this->m_branch == rhs.m_branch && this->m_outlet_segment == rhs.m_outlet_segment && this->m_total_length == rhs.m_total_length @@ -135,7 +135,7 @@ namespace Opm { } bool Segment::operator!=( const Segment& rhs ) const { - return this->m_segment_number == rhs.m_segment_number + return this->segment_number == rhs.segment_number && this->m_branch == rhs.m_branch && this->m_outlet_segment == rhs.m_outlet_segment && this->m_total_length == rhs.m_total_length diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/MSW/WellSegments.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/MSW/WellSegments.cpp index 9808a8fab..5a13e5c99 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/MSW/WellSegments.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/MSW/WellSegments.cpp @@ -76,8 +76,8 @@ namespace Opm { } int WellSegments::segmentNumberToIndex(const int segment_number) const { - const auto it = m_segment_number_to_index.find(segment_number); - if (it != m_segment_number_to_index.end()) { + const auto it = segment_number_to_index.find(segment_number); + if (it != segment_number_to_index.end()) { return it->second; } else { return -1; @@ -91,7 +91,7 @@ namespace Opm { const int segment_index = segmentNumberToIndex(segment_number); if (segment_index < 0) { // it is a new segment - m_segment_number_to_index[segment_number] = size(); + segment_number_to_index[segment_number] = size(); m_segments.push_back(new_segment); } else { // the segment already exists m_segments[segment_index] = new_segment; @@ -203,7 +203,7 @@ namespace Opm { if (index >= 0) { // found in the existing m_segments already throw std::logic_error("Segments with same segment number are found!\n"); } - m_segment_number_to_index[segment_number] = i_segment; + segment_number_to_index[segment_number] = i_segment; } for (size_t i_segment = 0; i_segment < m_segments.size(); ++i_segment) { @@ -212,7 +212,7 @@ namespace Opm { if (outlet_segment <= 0) { // no outlet segment continue; } - const int outlet_segment_index = m_segment_number_to_index[outlet_segment]; + const int outlet_segment_index = segment_number_to_index[outlet_segment]; m_segments[outlet_segment_index].addInletSegment(segment_number); } @@ -350,9 +350,9 @@ namespace Opm { int current_index= 1; // clear the mapping from segment number to store index - m_segment_number_to_index.clear(); + segment_number_to_index.clear(); // for the top segment - m_segment_number_to_index[1] = 0; + segment_number_to_index[1] = 0; while (current_index< size()) { // the branch number of the last segment that is done re-ordering @@ -390,7 +390,7 @@ namespace Opm { std::swap(m_segments[current_index], m_segments[target_segment_index]); } const int segment_number = m_segments[current_index].segmentNumber(); - m_segment_number_to_index[segment_number] = current_index; + segment_number_to_index[segment_number] = current_index; current_index++; } } @@ -405,13 +405,13 @@ namespace Opm { && this->m_comp_pressure_drop == rhs.m_comp_pressure_drop && this->m_multiphase_model == rhs.m_multiphase_model && this->m_segments.size() == rhs.m_segments.size() - && this->m_segment_number_to_index.size() == rhs.m_segment_number_to_index.size() + && this->segment_number_to_index.size() == rhs.segment_number_to_index.size() && std::equal( this->m_segments.begin(), this->m_segments.end(), rhs.m_segments.begin() ) - && std::equal( this->m_segment_number_to_index.begin(), - this->m_segment_number_to_index.end(), - rhs.m_segment_number_to_index.begin() ); + && std::equal( this->segment_number_to_index.begin(), + this->segment_number_to_index.end(), + rhs.segment_number_to_index.begin() ); } bool WellSegments::operator!=( const WellSegments& rhs ) const { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp index 00c6cd8b3..49854d7f7 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp @@ -337,7 +337,7 @@ namespace Opm { + ". Can not infer reference depth" ); } - return completions.get( 0 ).getCenterDepth(); + return completions.get( 0 ).center_depth; } void Well::setRefDepth( size_t timestep, double depth ) { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp index e1881f03f..065346983 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/WellConnections.cpp @@ -247,7 +247,7 @@ namespace Opm { for (size_t pos = 1; pos < m_connections.size() - 1; ++pos) { const auto& prev = m_connections[pos - 1]; - const double prevz = prev.getCenterDepth(); + const double prevz = prev.center_depth; size_t next_index = findClosestConnection(prev.getI(), prev.getJ(), prevz, pos); std::swap(m_connections[next_index], m_connections[pos]); } @@ -263,7 +263,7 @@ namespace Opm { for (size_t pos = start_pos; pos < m_connections.size(); ++pos) { const auto& connection = m_connections[ pos ]; - const double depth = connection.getCenterDepth(); + const double depth = connection.center_depth; const int ci = connection.getI(); const int cj = connection.getJ(); // Using square of distance to avoid non-integer arithmetics. diff --git a/tests/parser/MultisegmentWellTests.cpp b/tests/parser/MultisegmentWellTests.cpp index ab29aeec4..13e2bfb5a 100644 --- a/tests/parser/MultisegmentWellTests.cpp +++ b/tests/parser/MultisegmentWellTests.cpp @@ -91,32 +91,32 @@ BOOST_AUTO_TEST_CASE(MultisegmentWellTest) { BOOST_CHECK_EQUAL(7U, new_connection_set->size()); const Opm::Connection& connection1 = new_connection_set->get(0); - const int segment_number_connection1 = connection1.getSegmentNumber(); - const double center_depth_connection1 = connection1.getCenterDepth(); + const int segment_number_connection1 = connection1.segment_number; + const double center_depth_connection1 = connection1.center_depth; BOOST_CHECK_EQUAL(segment_number_connection1, 1); BOOST_CHECK_EQUAL(center_depth_connection1, 2512.5); const Opm::Connection& connection3 = new_connection_set->get(2); - const int segment_number_connection3 = connection3.getSegmentNumber(); - const double center_depth_connection3 = connection3.getCenterDepth(); + const int segment_number_connection3 = connection3.segment_number; + const double center_depth_connection3 = connection3.center_depth; BOOST_CHECK_EQUAL(segment_number_connection3, 3); BOOST_CHECK_EQUAL(center_depth_connection3, 2562.5); const Opm::Connection& connection5 = new_connection_set->get(4); - const int segment_number_connection5 = connection5.getSegmentNumber(); - const double center_depth_connection5 = connection5.getCenterDepth(); + const int segment_number_connection5 = connection5.segment_number; + const double center_depth_connection5 = connection5.center_depth; BOOST_CHECK_EQUAL(segment_number_connection5, 6); BOOST_CHECK_CLOSE(center_depth_connection5, 2538.83, 0.001); const Opm::Connection& connection6 = new_connection_set->get(5); - const int segment_number_connection6 = connection6.getSegmentNumber(); - const double center_depth_connection6 = connection6.getCenterDepth(); + const int segment_number_connection6 = connection6.segment_number; + const double center_depth_connection6 = connection6.center_depth; BOOST_CHECK_EQUAL(segment_number_connection6, 6); BOOST_CHECK_CLOSE(center_depth_connection6, 2537.83, 0.001); const Opm::Connection& connection7 = new_connection_set->get(6); - const int segment_number_connection7 = connection7.getSegmentNumber(); - const double center_depth_connection7 = connection7.getCenterDepth(); + const int segment_number_connection7 = connection7.segment_number; + const double center_depth_connection7 = connection7.center_depth; BOOST_CHECK_EQUAL(segment_number_connection7, 7); BOOST_CHECK_EQUAL(center_depth_connection7, 2534.5); } diff --git a/tests/parser/integration/ParseKEYWORD.cpp b/tests/parser/integration/ParseKEYWORD.cpp index f47d3c3e5..620c51415 100644 --- a/tests/parser/integration/ParseKEYWORD.cpp +++ b/tests/parser/integration/ParseKEYWORD.cpp @@ -577,26 +577,26 @@ BOOST_AUTO_TEST_CASE( MULTISEGMENT_ABS ) { BOOST_CHECK_EQUAL(7U, connections.size()); const Connection& connection5 = connections.get(4); - const int seg_number_connection5 = connection5.getSegmentNumber(); - const double connection5_depth = connection5.getCenterDepth(); + const int seg_number_connection5 = connection5.segment_number; + const double connection5_depth = connection5.center_depth; BOOST_CHECK_EQUAL(seg_number_connection5, 6); BOOST_CHECK_CLOSE(connection5_depth, 2538.83, 0.001); const Connection& connection6 = connections.get(5); - const int seg_number_connection6 = connection6.getSegmentNumber(); - const double connection6_depth = connection6.getCenterDepth(); + const int seg_number_connection6 = connection6.segment_number; + const double connection6_depth = connection6.center_depth; BOOST_CHECK_EQUAL(seg_number_connection6, 6); BOOST_CHECK_CLOSE(connection6_depth, 2537.83, 0.001); const Connection& connection1 = connections.get(0); - const int seg_number_connection1 = connection1.getSegmentNumber(); - const double connection1_depth = connection1.getCenterDepth(); + const int seg_number_connection1 = connection1.segment_number; + const double connection1_depth = connection1.center_depth; BOOST_CHECK_EQUAL(seg_number_connection1, 1); BOOST_CHECK_EQUAL(connection1_depth, 2512.5); const Connection& connection3 = connections.get(2); - const int seg_number_connection3 = connection3.getSegmentNumber(); - const double connection3_depth = connection3.getCenterDepth(); + const int seg_number_connection3 = connection3.segment_number; + const double connection3_depth = connection3.center_depth; BOOST_CHECK_EQUAL(seg_number_connection3, 3); BOOST_CHECK_EQUAL(connection3_depth, 2562.5); } diff --git a/tests/test_serialize_ICON.cpp b/tests/test_serialize_ICON.cpp index ceb7d110c..977753c9e 100644 --- a/tests/test_serialize_ICON.cpp +++ b/tests/test_serialize_ICON.cpp @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE( serialize_icon_test ) if (c.attachedToSegment()) BOOST_CHECK_EQUAL(icondata[offset + ICON_SEGMENT_INDEX], - c.getSegmentNumber()); + c.segment_number); else BOOST_CHECK_EQUAL(icondata[offset + ICON_SEGMENT_INDEX], 0);