From 84485dde53e0cf10d0e5e8075c33fb65cd2f380a Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 17 Feb 2016 10:04:13 +0100 Subject: [PATCH] Changes in SimulatorState: 1. Added method setCellDataComponent() 2. Removed setFirstSat() Implemented saturation initialisation using setCellDataComponent() instead of setFirstSat(). This way the template has been removed from the SimulatorState class. --- opm/core/simulator/BlackoilState.cpp | 10 ----- opm/core/simulator/BlackoilState.hpp | 8 ---- opm/core/simulator/TwophaseState.hpp | 4 -- opm/core/simulator/TwophaseState_impl.hpp | 7 ---- opm/core/simulator/initState_impl.hpp | 46 +++++++++++++++++++---- 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/opm/core/simulator/BlackoilState.cpp b/opm/core/simulator/BlackoilState.cpp index 46b9d3a50..5084a1fd4 100644 --- a/opm/core/simulator/BlackoilState.cpp +++ b/opm/core/simulator/BlackoilState.cpp @@ -23,16 +23,6 @@ BlackoilState::init(const UnstructuredGrid& g, int num_phases) { init(g.number_of_cells, g.number_of_faces, num_phases); } -/// Set the first saturation to either its min or max value in -/// the indicated cells. The second saturation value s2 is set -/// to (1.0 - s1) for each cell. Any further saturation values -/// are unchanged. -void -BlackoilState::setFirstSat(const std::vector& cells, - const Opm::BlackoilPropertiesInterface& props, - ExtremalSat es) { - SimulatorState::setFirstSat(cells, props, es); -} bool BlackoilState::equals(const SimulatorState& other, diff --git a/opm/core/simulator/BlackoilState.hpp b/opm/core/simulator/BlackoilState.hpp index b6622e198..ce7655a8d 100644 --- a/opm/core/simulator/BlackoilState.hpp +++ b/opm/core/simulator/BlackoilState.hpp @@ -39,14 +39,6 @@ namespace Opm virtual void init(int number_of_cells, int number_of_faces, int num_phases); - /// Set the first saturation to either its min or max value in - /// the indicated cells. The second saturation value s2 is set - /// to (1.0 - s1) for each cell. Any further saturation values - /// are unchanged. - void setFirstSat(const std::vector& cells, - const Opm::BlackoilPropertiesInterface& props, - ExtremalSat es); - virtual bool equals(const SimulatorState& other, double epsilon = 1e-8) const; diff --git a/opm/core/simulator/TwophaseState.hpp b/opm/core/simulator/TwophaseState.hpp index 21e51d5c2..c8bcf23ba 100644 --- a/opm/core/simulator/TwophaseState.hpp +++ b/opm/core/simulator/TwophaseState.hpp @@ -30,10 +30,6 @@ namespace Opm class TwophaseState : public SimulatorState { public: - void setFirstSat(const std::vector& cells, - const Opm::IncompPropertiesInterface& props, - ExtremalSat es); - virtual bool equals (const SimulatorState& other, double epsilon = 1e-8) const; }; diff --git a/opm/core/simulator/TwophaseState_impl.hpp b/opm/core/simulator/TwophaseState_impl.hpp index d54ecae58..6dbf9b36f 100644 --- a/opm/core/simulator/TwophaseState_impl.hpp +++ b/opm/core/simulator/TwophaseState_impl.hpp @@ -4,13 +4,6 @@ namespace Opm { -inline void -TwophaseState::setFirstSat(const std::vector& cells, - const Opm::IncompPropertiesInterface& props, - ExtremalSat es) { - SimulatorState::setFirstSat(cells, props, es); -} - inline bool TwophaseState::equals (const SimulatorState& other, double epsilon) const { diff --git a/opm/core/simulator/initState_impl.hpp b/opm/core/simulator/initState_impl.hpp index d411d6136..8134b8b92 100644 --- a/opm/core/simulator/initState_impl.hpp +++ b/opm/core/simulator/initState_impl.hpp @@ -76,6 +76,34 @@ namespace Opm #endif /* __clang__ */ enum WaterInit { WaterBelow, WaterAbove }; + enum ExtremalSat { MinSat, MaxSat }; + + /// Will initialize the first and second component of the + /// SATURATION field in all the cells in the set @cells. The + /// @props object will be queried, and depending on the value + /// @satType either the minimum or the maximum saturation is + /// applied to thee first component in the SATURATION field. + /// For the second component (1 - first_sat) is used. + + template + static void initSaturation(const std::vector& cells , const Props& props , State& state , ExtremalSat satType) { + std::vector min_sat(cells.size()); + std::vector max_sat(cells.size()); + std::vector second_sat(cells.size()); + std::vector* first_sat; + + props.satRange(cells.size() ,cells.data() , min_sat.data() , max_sat.data()); + if (satType == MinSat) { + first_sat = &min_sat; + } else { + first_sat = &max_sat; + } + + std::transform( first_sat->begin() , first_sat->end() , second_sat.begin() , [](double s) { return 1 - s; }); + state.setCellDataComponent( "SATURATION" , 0 , cells , *first_sat ); + state.setCellDataComponent( "SATURATION" , 1 , cells , second_sat ); + } + // Initialize saturations so that there is water below woc, // and oil above. @@ -106,9 +134,9 @@ namespace Opm cellsBelowAbove(number_of_cells, begin_cell_centroids, dimensions, woc, oil, water); } - // Set saturations. - state.setFirstSat(oil, props, State::MinSat); - state.setFirstSat(water, props, State::MaxSat); + + initSaturation( oil , props , state , MinSat ); + initSaturation( water , props , state , MaxSat ); } @@ -380,7 +408,10 @@ namespace Opm for (int i = 0; i < num_cells; ++i) { all_cells[i] = i; } - state.setFirstSat(all_cells, props, State::MinSat); + + initSaturation( all_cells , props , state , MinSat ); + + const bool convection_testcase = param.getDefault("convection_testcase", false); const bool segregation_testcase = param.getDefault("segregation_testcase", false); if (convection_testcase) { @@ -394,7 +425,8 @@ namespace Opm left_cells.push_back(cell); } } - state.setFirstSat(left_cells, props, State::MaxSat); + + initSaturation( left_cells , props , state , MaxSat ); const double init_p = param.getDefault("ref_pressure", 100.0)*unit::barsa; std::fill(state.pressure().begin(), state.pressure().end(), init_p); } else if (segregation_testcase) { @@ -501,7 +533,7 @@ namespace Opm for (int i = 0; i < num_cells; ++i) { all_cells[i] = i; } - state.setFirstSat(all_cells, props, State::MinSat); + initSaturation(all_cells , props , state , MinSat); const bool convection_testcase = param.getDefault("convection_testcase", false); if (convection_testcase) { // Initialise water saturation to max in the 'left' part. @@ -514,7 +546,7 @@ namespace Opm left_cells.push_back(cell); } } - state.setFirstSat(left_cells, props, State::MaxSat); + initSaturation(left_cells , props , state , MaxSat ); const double init_p = param.getDefault("ref_pressure", 100.0)*unit::barsa; std::fill(state.pressure().begin(), state.pressure().end(), init_p); } else if (param.has("water_oil_contact")) {