Add utility constructors and testing to UDQWellSet

This commit is contained in:
Joakim Hove
2019-03-07 10:44:31 +01:00
parent 568506627e
commit ccba767b24
3 changed files with 66 additions and 26 deletions

View File

@@ -32,6 +32,8 @@ namespace Opm {
class UDQWellSet : public UDQSet {
public:
UDQWellSet(const std::string& name, const std::vector<std::string>& wells);
UDQWellSet(const std::string& name, const std::vector<std::string>& wells, const UDQSet& values);
UDQWellSet(const std::string& name, const std::vector<std::string>& wells, double scalar_value);
void assign(const std::string& well, double value);
void assign(double value);
const UDQScalar& operator[](const std::string& well) const;

View File

@@ -30,6 +30,29 @@ UDQWellSet::UDQWellSet(const std::string& name, const std::vector<std::string>&
this->well_index.emplace( std::make_pair(wells[index], index));
}
UDQWellSet::UDQWellSet(const std::string& name, const std::vector<std::string>& wells, const UDQSet& values) :
UDQWellSet(name, wells)
{
if (wells.size() != values.size())
throw std::invalid_argument("Size mismatch");
for (std::size_t index = 0; index < values.size(); index++) {
const auto& value = values[index];
if (value)
UDQSet::assign(index, values[index].value());
}
}
UDQWellSet::UDQWellSet(const std::string& name, const std::vector<std::string>& wells, double scalar_value) :
UDQWellSet(name, wells)
{
if (wells.size() != this->size())
throw std::invalid_argument("Size mismatch");
for (std::size_t index = 0; index < wells.size(); index++)
UDQSet::assign(index, scalar_value);
}
void UDQWellSet::assign(const std::string& well, double value) {
if (well.find('*') == std::string::npos) {

View File

@@ -49,6 +49,47 @@ Schedule make_schedule(const std::string& input) {
return Schedule(deck, grid , eclipseProperties, runspec);
}
BOOST_AUTO_TEST_CASE(UDQWellSetTest) {
std::vector<std::string> wells = {"P1", "P2", "I1", "I2"};
UDQWellSet ws("NAME", wells);
UDQWellSet ws2("NAME", wells, 100.0);
BOOST_CHECK_EQUAL(4, ws.size());
ws.assign("P1", 1.0);
const auto& value = ws["P1"];
BOOST_CHECK_EQUAL(value.value(), 1.0);
BOOST_CHECK_EQUAL(ws["P1"].value(), 1.0);
BOOST_REQUIRE_THROW(ws.assign("NO_SUCH_WELL", 1.0), std::invalid_argument);
ws.assign("*", 2.0);
for (const auto& w : wells)
BOOST_CHECK_EQUAL(ws[w].value(), 2.0);
ws.assign(3.0);
for (const auto& w : wells)
BOOST_CHECK_EQUAL(ws[w].value(), 3.0);
ws.assign("P*", 4.0);
BOOST_CHECK_EQUAL(ws["P1"].value(), 4.0);
BOOST_CHECK_EQUAL(ws["P2"].value(), 4.0);
ws.assign("I2", 5.0);
BOOST_CHECK_EQUAL(ws["I2"].value(), 5.0);
for (const auto& w : wells)
BOOST_CHECK_EQUAL(ws2[w].value(), 100.0);
UDQSet us("NAME", wells.size());
for (std::size_t i=0; i < wells.size(); i++)
us.assign(i, 1.0 * i);
UDQWellSet ws3("name", wells, us);
for (std::size_t i=0; i < wells.size(); i++)
BOOST_CHECK_EQUAL(ws3[wells[i]].value(), i*1.0);
}
BOOST_AUTO_TEST_CASE(KEYWORDS) {
const std::string input = R"(
@@ -675,32 +716,6 @@ BOOST_AUTO_TEST_CASE(UDQ_SET_DIV) {
BOOST_AUTO_TEST_CASE(UDQWellSetTest) {
std::vector<std::string> wells = {"P1", "P2", "I1", "I2"};
UDQWellSet ws("NAME", wells);
BOOST_CHECK_EQUAL(4, ws.size());
ws.assign("P1", 1.0);
const auto& value = ws[std::string("P1")];
BOOST_CHECK_EQUAL(value.value(), 1.0);
BOOST_CHECK_EQUAL(ws["P1"].value(), 1.0);
BOOST_REQUIRE_THROW(ws.assign("NO_SUCH_WELL", 1.0), std::invalid_argument);
ws.assign("*", 2.0);
for (const auto& w : wells)
BOOST_CHECK_EQUAL(ws[w].value(), 2.0);
ws.assign(3.0);
for (const auto& w : wells)
BOOST_CHECK_EQUAL(ws[w].value(), 3.0);
ws.assign("P*", 4.0);
BOOST_CHECK_EQUAL(ws["P1"].value(), 4.0);
BOOST_CHECK_EQUAL(ws["P2"].value(), 4.0);
}
BOOST_AUTO_TEST_CASE(UDQASSIGN_TEST) {
UDQAssign as1("WUPR", {}, 1.0);