Remove homemade optional - use std::optional
This commit is contained in:
@@ -376,7 +376,6 @@ if(ENABLE_ECL_INPUT)
|
||||
tests/parser/TuningTests.cpp
|
||||
tests/parser/UDQTests.cpp
|
||||
tests/parser/UnitTests.cpp
|
||||
tests/parser/ValueTests.cpp
|
||||
tests/parser/WellSolventTests.cpp
|
||||
tests/parser/WellTracerTests.cpp
|
||||
tests/parser/WellTests.cpp
|
||||
@@ -567,7 +566,6 @@ if(ENABLE_ECL_INPUT)
|
||||
opm/parser/eclipse/EclipseState/InitConfig/InitConfig.hpp
|
||||
opm/parser/eclipse/EclipseState/InitConfig/Equil.hpp
|
||||
opm/parser/eclipse/EclipseState/InitConfig/FoamConfig.hpp
|
||||
opm/parser/eclipse/EclipseState/Util/Value.hpp
|
||||
opm/parser/eclipse/EclipseState/Util/IOrderSet.hpp
|
||||
opm/parser/eclipse/EclipseState/Util/OrderedMap.hpp
|
||||
opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#define OPM_PARSER_ECLIPSE_GRID_HPP
|
||||
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Util/Value.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/MinpvMode.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/PinchMode.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/GridDims.hpp>
|
||||
@@ -32,6 +31,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace Opm {
|
||||
@@ -194,7 +194,7 @@ namespace Opm {
|
||||
private:
|
||||
std::vector<double> m_minpvVector;
|
||||
MinpvMode::ModeEnum m_minpvMode;
|
||||
Value<double> m_pinch;
|
||||
std::optional<double> m_pinch;
|
||||
PinchMode::ModeEnum m_pinchoutMode;
|
||||
PinchMode::ModeEnum m_multzMode;
|
||||
PinchMode::ModeEnum m_pinchGapMode;
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/FaceDir.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Util/Value.hpp>
|
||||
|
||||
|
||||
namespace Opm {
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <optional>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Util/Value.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef OPM_VALUE_HPP
|
||||
#define OPM_VALUE_HPP
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
|
||||
/*
|
||||
The simple class Value<T> keeps track of a named scalar variable;
|
||||
the purpose of this class is to keep strick track of whether the
|
||||
value has been assigned or not. Will throw an exception if trying to
|
||||
use an unitialized value.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
namespace Opm {
|
||||
|
||||
template <typename T>
|
||||
class Value {
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
bool m_initialized = false;
|
||||
T m_value;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
Value() = default;
|
||||
explicit Value(const std::string& name) :
|
||||
m_name( name ),
|
||||
m_initialized( false )
|
||||
{ }
|
||||
|
||||
|
||||
Value(const std::string& name ,T value) :
|
||||
m_name( name )
|
||||
{
|
||||
setValue( value );
|
||||
}
|
||||
|
||||
|
||||
bool hasValue() const {
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
|
||||
T getValue() const {
|
||||
if (m_initialized)
|
||||
return m_value;
|
||||
else
|
||||
throw std::logic_error("The value has: " + m_name + " has not been initialized");
|
||||
}
|
||||
|
||||
|
||||
void setValue( T value ) {
|
||||
m_initialized = true;
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
Will return true if both value instances have been initialized
|
||||
to the same value; or none of the values have been
|
||||
initialized. Does not compare names.
|
||||
*/
|
||||
bool equal( const Value<T>& other) const {
|
||||
if (m_initialized == other.m_initialized) {
|
||||
if (m_initialized) {
|
||||
if (m_value == other.m_value)
|
||||
return true; // Have been initialized to same value
|
||||
else
|
||||
return false;
|
||||
} else
|
||||
return true; // Both undefined
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==( const Value& rhs ) const {
|
||||
return this->equal( rhs );
|
||||
}
|
||||
|
||||
bool operator!=( const Value& rhs ) const {
|
||||
return !(*this == rhs );
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -66,7 +66,6 @@ EclipseGrid::EclipseGrid(std::array<int, 3>& dims ,
|
||||
const double * mapaxes)
|
||||
: GridDims(dims),
|
||||
m_minpvMode(MinpvMode::ModeEnum::Inactive),
|
||||
m_pinch("PINCH"),
|
||||
m_pinchoutMode(PinchMode::ModeEnum::TOPBOT),
|
||||
m_multzMode(PinchMode::ModeEnum::TOP),
|
||||
m_pinchGapMode(PinchMode::ModeEnum::GAP)
|
||||
@@ -83,7 +82,6 @@ EclipseGrid::EclipseGrid(std::array<int, 3>& dims ,
|
||||
EclipseGrid::EclipseGrid(const std::string& fileName )
|
||||
: GridDims(),
|
||||
m_minpvMode(MinpvMode::ModeEnum::Inactive),
|
||||
m_pinch("PINCH"),
|
||||
m_pinchoutMode(PinchMode::ModeEnum::TOPBOT),
|
||||
m_multzMode(PinchMode::ModeEnum::TOP),
|
||||
m_pinchGapMode(PinchMode::ModeEnum::GAP)
|
||||
@@ -99,7 +97,6 @@ EclipseGrid::EclipseGrid(size_t nx, size_t ny , size_t nz,
|
||||
double dx, double dy, double dz)
|
||||
: GridDims(nx, ny, nz),
|
||||
m_minpvMode(MinpvMode::ModeEnum::Inactive),
|
||||
m_pinch("PINCH"),
|
||||
m_pinchoutMode(PinchMode::ModeEnum::TOPBOT),
|
||||
m_multzMode(PinchMode::ModeEnum::TOP),
|
||||
m_pinchGapMode(PinchMode::ModeEnum::GAP)
|
||||
@@ -208,7 +205,6 @@ EclipseGrid::EclipseGrid(const EclipseGrid& src, const std::vector<int>& actnum)
|
||||
EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum)
|
||||
: GridDims(deck),
|
||||
m_minpvMode(MinpvMode::ModeEnum::Inactive),
|
||||
m_pinch("PINCH"),
|
||||
m_pinchoutMode(PinchMode::ModeEnum::TOPBOT),
|
||||
m_multzMode(PinchMode::ModeEnum::TOP),
|
||||
m_pinchGapMode(PinchMode::ModeEnum::GAP)
|
||||
@@ -306,7 +302,7 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum)
|
||||
if (deck.hasKeyword<ParserKeywords::PINCH>()) {
|
||||
const auto& record = deck.getKeyword<ParserKeywords::PINCH>( ).getRecord(0);
|
||||
const auto& item = record.getItem<ParserKeywords::PINCH::THRESHOLD_THICKNESS>( );
|
||||
m_pinch.setValue( item.getSIDouble(0) );
|
||||
m_pinch = item.getSIDouble(0);
|
||||
|
||||
auto pinchoutString = record.getItem<ParserKeywords::PINCH::PINCHOUT_OPTION>().get< std::string >(0);
|
||||
m_pinchoutMode = PinchMode::PinchModeFromString(pinchoutString);
|
||||
@@ -471,11 +467,11 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum)
|
||||
|
||||
|
||||
bool EclipseGrid::isPinchActive( ) const {
|
||||
return m_pinch.hasValue();
|
||||
return m_pinch.has_value();
|
||||
}
|
||||
|
||||
double EclipseGrid::getPinchThresholdThickness( ) const {
|
||||
return m_pinch.getValue();
|
||||
return m_pinch.value();
|
||||
}
|
||||
|
||||
PinchMode::ModeEnum EclipseGrid::getPinchOption( ) const {
|
||||
@@ -1326,7 +1322,7 @@ std::vector<double> EclipseGrid::createDVector(const std::array<int,3>& dims, st
|
||||
if (m_mapaxes != other.m_mapaxes)
|
||||
return false;
|
||||
|
||||
bool status = (m_pinch.equal( other.m_pinch ) && (m_minpvMode == other.getMinpvMode()));
|
||||
bool status = ((m_pinch == other.m_pinch) && (m_minpvMode == other.getMinpvMode()));
|
||||
|
||||
if(m_minpvMode!=MinpvMode::ModeEnum::Inactive) {
|
||||
status = status && (m_minpvVector == other.getMinpvVector());
|
||||
|
||||
@@ -34,8 +34,6 @@
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well/Connection.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Util/Value.hpp>
|
||||
|
||||
|
||||
namespace Opm {
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
@@ -825,7 +826,7 @@ BOOST_AUTO_TEST_CASE(ConstructorNORUNSPEC_PINCH) {
|
||||
BOOST_CHECK(!grid1.equal( grid2 ));
|
||||
|
||||
BOOST_CHECK(!grid1.isPinchActive());
|
||||
BOOST_CHECK_THROW(grid1.getPinchThresholdThickness(), std::logic_error);
|
||||
BOOST_CHECK_THROW(grid1.getPinchThresholdThickness(), std::bad_optional_access);
|
||||
BOOST_CHECK(grid2.isPinchActive());
|
||||
BOOST_CHECK_EQUAL(grid2.getPinchThresholdThickness(), 0.2);
|
||||
BOOST_CHECK_EQUAL(grid2.getPinchGapMode(), Opm::PinchMode::ModeEnum::GAP);
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Util/Value.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#define BOOST_TEST_MODULE VALUETESTS
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Util/Value.hpp>
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( check_default_constructor ) {
|
||||
Opm::Value<int> v("Value");
|
||||
|
||||
BOOST_CHECK_EQUAL( false , v.hasValue() );
|
||||
BOOST_CHECK_THROW( v.getValue() , std::logic_error );
|
||||
|
||||
v.setValue( 70 );
|
||||
BOOST_CHECK_EQUAL( 70 , v.getValue());
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( check_value_constructor ) {
|
||||
Opm::Value<int> v("Value" , 100);
|
||||
|
||||
BOOST_CHECK_EQUAL( true , v.hasValue() );
|
||||
BOOST_CHECK_EQUAL( 100 , v.getValue());
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( check_equal1 ) {
|
||||
Opm::Value<int> v1("v1" , 100);
|
||||
Opm::Value<int> v2("v2" , 100);
|
||||
|
||||
BOOST_CHECK(v1.equal( v2 ));
|
||||
|
||||
v1.setValue(110);
|
||||
BOOST_CHECK_EQUAL( false , v1.equal(v2));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( check_equal2 ) {
|
||||
Opm::Value<int> v1("v1");
|
||||
Opm::Value<int> v2("v2");
|
||||
|
||||
BOOST_CHECK_EQUAL(true , v1.equal( v2 ));
|
||||
|
||||
v1.setValue(110);
|
||||
BOOST_CHECK_EQUAL( false , v1.equal(v2));
|
||||
v2.setValue(110);
|
||||
BOOST_CHECK_EQUAL( true , v1.equal(v2));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( check_assign) {
|
||||
Opm::Value<int> v1("v1",100);
|
||||
Opm::Value<int> v2(v1);
|
||||
|
||||
BOOST_CHECK(v1.equal(v2));
|
||||
}
|
||||
Reference in New Issue
Block a user