diff --git a/opm/simulators/wells/MultisegmentWellSegments.cpp b/opm/simulators/wells/MultisegmentWellSegments.cpp index 73a707457..95d2a893f 100644 --- a/opm/simulators/wells/MultisegmentWellSegments.cpp +++ b/opm/simulators/wells/MultisegmentWellSegments.cpp @@ -864,7 +864,7 @@ accelerationPressureLossContribution(const int seg, template void MultisegmentWellSegments:: -copyPhaseDensities(const PhaseUsage& pu, SegmentState& segSol) const +copyPhaseDensities(const PhaseUsage& pu, SegmentState& segSol) const { auto* rho = segSol.phase_density.data(); diff --git a/opm/simulators/wells/MultisegmentWellSegments.hpp b/opm/simulators/wells/MultisegmentWellSegments.hpp index 43ecc49f8..4ae2d75c9 100644 --- a/opm/simulators/wells/MultisegmentWellSegments.hpp +++ b/opm/simulators/wells/MultisegmentWellSegments.hpp @@ -31,7 +31,7 @@ namespace Opm { class AutoICD; struct PhaseUsage; - class SegmentState; + template class SegmentState; class UnitSystem; class WellInterfaceGeneric; class SummaryState; @@ -131,7 +131,7 @@ public: } void copyPhaseDensities(const PhaseUsage& pu, - SegmentState& segSol) const; + SegmentState& segSol) const; private: // TODO: trying to use the information from the Well opm-parser as much @@ -141,8 +141,8 @@ private: // the completions's ids are their index in the vector well_index_, well_cell_ // This is also assuming the order of the completions in Well is the same with // the order of the completions in wells. - // it is for convinience reason. we can just calcuate the inforation for segment once then using it for all the perofrations - // belonging to this segment + // it is for convenience reason. we can just calculate the information for segment once + // then using it for all the perforations belonging to this segment std::vector> perforations_; // depth difference between the segment and the perforation diff --git a/opm/simulators/wells/SegmentState.cpp b/opm/simulators/wells/SegmentState.cpp index bcbbefe9e..861bbbd83 100644 --- a/opm/simulators/wells/SegmentState.cpp +++ b/opm/simulators/wells/SegmentState.cpp @@ -50,10 +50,10 @@ std::vector make_segment_number(const Opm::WellSegments& segments) } // Anonymous namespace -namespace Opm -{ +namespace Opm { -SegmentState::SegmentState(int num_phases, const WellSegments& segments) +template +SegmentState::SegmentState(int num_phases, const WellSegments& segments) : rates (segments.size() * num_phases) , dissolved_gas_rate (segments.size()) , vaporized_oil_rate (segments.size()) @@ -69,7 +69,8 @@ SegmentState::SegmentState(int num_phases, const WellSegments& segments) , m_segment_number (make_segment_number(segments)) {} -SegmentState SegmentState::serializationTestObject() +template +SegmentState SegmentState::serializationTestObject() { SegmentState result; result.rates = {1.0, 2.0}; @@ -89,19 +90,27 @@ SegmentState SegmentState::serializationTestObject() return result; } -double SegmentState::pressure_drop(std::size_t index) const { +template +Scalar SegmentState::pressure_drop(std::size_t index) const +{ return this->pressure_drop_friction[index] + this->pressure_drop_hydrostatic[index] + this->pressure_drop_accel[index]; } -bool SegmentState::empty() const { +template +bool SegmentState::empty() const +{ return this->rates.empty(); } -std::size_t SegmentState::size() const { +template +std::size_t SegmentState::size() const +{ return this->pressure.size(); } -void SegmentState::scale_pressure(const double bhp) { +template +void SegmentState::scale_pressure(const Scalar bhp) +{ if (this->empty()) throw std::logic_error("Tried to pressure scale empty SegmentState"); @@ -110,14 +119,18 @@ void SegmentState::scale_pressure(const double bhp) { std::transform(this->pressure.begin(), this->pressure.end(), this->pressure.begin(), - [pressure_change] (const double& p) { return p + pressure_change;}); + [pressure_change] (const Scalar& p) { return p + pressure_change;}); } -const std::vector& SegmentState::segment_number() const { +template +const std::vector& +SegmentState::segment_number() const +{ return this->m_segment_number; } -bool SegmentState::operator==(const SegmentState& rhs) const +template +bool SegmentState::operator==(const SegmentState& rhs) const { return this->rates == rhs.rates && this->dissolved_gas_rate == rhs.dissolved_gas_rate && @@ -134,4 +147,6 @@ bool SegmentState::operator==(const SegmentState& rhs) const this->m_segment_number == rhs.m_segment_number; } +template class SegmentState; + } // namespace Opm diff --git a/opm/simulators/wells/SegmentState.hpp b/opm/simulators/wells/SegmentState.hpp index 4b27d51e7..7c6724bb1 100644 --- a/opm/simulators/wells/SegmentState.hpp +++ b/opm/simulators/wells/SegmentState.hpp @@ -23,14 +23,13 @@ #include #include -namespace Opm -{ +namespace Opm { class WellSegments; } // namespace Opm -namespace Opm -{ +namespace Opm { +template class SegmentState { public: @@ -39,9 +38,9 @@ public: static SegmentState serializationTestObject(); - double pressure_drop(std::size_t index) const; + Scalar pressure_drop(std::size_t index) const; bool empty() const; - void scale_pressure(double bhp); + void scale_pressure(Scalar bhp); const std::vector& segment_number() const; std::size_t size() const; @@ -66,21 +65,21 @@ public: bool operator==(const SegmentState&) const; - std::vector rates; - std::vector dissolved_gas_rate; - std::vector vaporized_oil_rate; + std::vector rates; + std::vector dissolved_gas_rate; + std::vector vaporized_oil_rate; /// Segment condition volume flow rates through segment (per phase) - std::vector phase_resv_rates; + std::vector phase_resv_rates; /// Segment condition flow velocity through segment (per phase) - std::vector phase_velocity; + std::vector phase_velocity; /// Segment condition holdup fractions through segment (per phase) - std::vector phase_holdup; + std::vector phase_holdup; /// Segment condition phase viscosities. - std::vector phase_viscosity; + std::vector phase_viscosity; /// Segment condition phase densities. /// @@ -98,12 +97,12 @@ public: /// { p0, p1, ..., (np - 1), mixture, mixture_with_exponents }, /// ... /// { p0, p1, ..., (np - 1), mixture, mixture_with_exponents }] - std::vector phase_density; + std::vector phase_density; - std::vector pressure; - std::vector pressure_drop_friction; - std::vector pressure_drop_hydrostatic; - std::vector pressure_drop_accel; + std::vector pressure; + std::vector pressure_drop_friction; + std::vector pressure_drop_hydrostatic; + std::vector pressure_drop_accel; private: std::vector m_segment_number; diff --git a/opm/simulators/wells/SingleWellState.hpp b/opm/simulators/wells/SingleWellState.hpp index 02b110610..9d1c7f149 100644 --- a/opm/simulators/wells/SingleWellState.hpp +++ b/opm/simulators/wells/SingleWellState.hpp @@ -107,7 +107,7 @@ public: std::vector prev_surface_rates; PerfData perf_data; bool trivial_target; - SegmentState segments; + SegmentState segments; Events events; WellInjectorCMode injection_cmode{WellInjectorCMode::CMODE_UNDEFINED}; WellProducerCMode production_cmode{WellProducerCMode::CMODE_UNDEFINED}; diff --git a/opm/simulators/wells/WellState.cpp b/opm/simulators/wells/WellState.cpp index 06b6c4132..d831e8ec3 100644 --- a/opm/simulators/wells/WellState.cpp +++ b/opm/simulators/wells/WellState.cpp @@ -677,7 +677,7 @@ void WellState::initWellStateMSWell(const std::vector& wells_ecl, // assuming the order of the perforations in well_ecl is the same with Wells const WellConnections& completion_set = well_ecl.getConnections(); // number of segment for this single well - ws.segments = SegmentState{np, segment_set}; + ws.segments = SegmentState{np, segment_set}; const int well_nseg = segment_set.size(); int n_activeperf = 0; diff --git a/tests/test_RestartSerialization.cpp b/tests/test_RestartSerialization.cpp index 81fdb575c..310ca2e90 100644 --- a/tests/test_RestartSerialization.cpp +++ b/tests/test_RestartSerialization.cpp @@ -109,7 +109,8 @@ namespace Opm { using PerfD = PerfData; } TEST_FOR_TYPE_NAMED(PerfD, PerfData) TEST_FOR_TYPE(PIDAndIterationCountTimeStepControl) TEST_FOR_TYPE(PIDTimeStepControl) -TEST_FOR_TYPE(SegmentState) +namespace Opm { using SegmState = SegmentState; } +TEST_FOR_TYPE_NAMED(SegmState, SegmentState) TEST_FOR_TYPE(SimpleIterationCountTimeStepControl) TEST_FOR_TYPE(SimulatorReport) TEST_FOR_TYPE(SimulatorReportSingle) diff --git a/tests/test_wellstate.cpp b/tests/test_wellstate.cpp index 3c8eda326..8517cae5c 100644 --- a/tests/test_wellstate.cpp +++ b/tests/test_wellstate.cpp @@ -511,8 +511,8 @@ BOOST_AUTO_TEST_CASE(TESTSegmentState) { const Setup setup{ "msw.data" }; const auto& well = setup.sched.getWell("PROD01", 0); const auto& segments = well.getSegments(); - Opm::SegmentState ss1(3, segments); - Opm::SegmentState ss2; + Opm::SegmentState ss1(3, segments); + Opm::SegmentState ss2; ss1.pressure_drop_hydrostatic[0] = 1;