Skip to content

Commit 68cefc6

Browse files
committed
Throw invalid ref-factor or non-default trans_mult
1 parent 86fa686 commit 68cefc6

File tree

3 files changed

+103
-32
lines changed

3 files changed

+103
-32
lines changed

opm/input/eclipse/EclipseState/Grid/AutoRefinement.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <opm/input/eclipse/EclipseState/Grid/AutoRefinement.hpp>
1717

1818

19+
#include <stdexcept>
20+
1921
namespace Opm {
2022

2123

@@ -25,12 +27,20 @@ AutoRefinement::AutoRefinement()
2527
AutoRefinement::AutoRefinement(int nx,
2628
int ny,
2729
int nz,
28-
double option_trans_mult)
29-
: nx_{nx},
30-
ny_{ny},
31-
nz_{nz},
32-
option_trans_mult_{option_trans_mult}
33-
{}
30+
double option_trans_mult)
31+
{
32+
bool invalid = invalidRefinementFactor(nx) || invalidRefinementFactor(ny) || invalidRefinementFactor(nz);
33+
bool notYet = (option_trans_mult>0);
34+
if (invalid) {
35+
throw std::invalid_argument("Refinement factors must be odd and positive.");
36+
}
37+
else if (notYet) {
38+
throw std::invalid_argument("Only OPTION_TRANS_MULT 0 is supported for now.");
39+
}
40+
nx_ = nx;
41+
ny_ = ny;
42+
nz_ = nz;
43+
}
3444

3545
int AutoRefinement::NX() const
3646
{

opm/input/eclipse/EclipseState/Grid/AutoRefinement.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ class AutoRefinement {
3838
int nz_;
3939
double option_trans_mult_{0.};
4040

41+
bool invalidRefinementFactor(int n)
42+
{
43+
return (n<=0) || (n%2 == 0);
44+
}
45+
46+
4147
};
4248
}
4349

tests/parser/AutorefTests.cpp

Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ using namespace Opm;
3232

3333

3434
BOOST_AUTO_TEST_CASE(ReadAutoref) {
35-
36-
35+
3736
const std::string deck_string = R"(
3837
RUNSPEC
3938
@@ -54,32 +53,8 @@ DZ
5453
TOPS
5554
100*1 /
5655
57-
PORO
58-
1000*0.15 /
59-
60-
PERMX
61-
1000*1 /
62-
63-
COPY
64-
PERMX PERMZ /
65-
PERMX PERMY /
66-
/
67-
68-
EDIT
69-
70-
OIL
71-
GAS
72-
73-
TITLE
74-
The title
75-
76-
START
77-
16 JUN 1988 /
78-
7956
PROPS
8057
81-
REGIONS
82-
8358
SOLUTION
8459
8560
SCHEDULE
@@ -101,3 +76,83 @@ SCHEDULE
10176
BOOST_CHECK_EQUAL( autoRef.NZ(), 1);
10277
BOOST_CHECK_EQUAL( autoRef.OPTION_TRANS_MULT(), 0.);
10378
}
79+
80+
BOOST_AUTO_TEST_CASE(ThrowEvenRefinementFactor) {
81+
82+
const std::string deck_string = R"(
83+
RUNSPEC
84+
85+
DIMENS
86+
1 1 1 /
87+
88+
AUTOREF
89+
3 2 1 0. /
90+
91+
GRID
92+
93+
DX
94+
1*1 /
95+
DY
96+
1*1 /
97+
DZ
98+
1*1 /
99+
TOPS
100+
1*0 /
101+
102+
PROPS
103+
104+
SOLUTION
105+
106+
SCHEDULE
107+
)";
108+
109+
Opm::Parser parser;
110+
Opm::Deck deck = parser.parseString(deck_string);
111+
Opm::EclipseState state(deck);
112+
113+
const auto& autoref_keyword = deck["AUTOREF"][0];
114+
115+
Opm::AutoRefManager autoRefManager{};
116+
117+
BOOST_CHECK_THROW(Opm::readKeywordAutoRef(autoref_keyword.getRecord(0), autoRefManager), std::invalid_argument);
118+
}
119+
120+
BOOST_AUTO_TEST_CASE(ThrowNonDefaultOptionTransMult) {
121+
122+
const std::string deck_string = R"(
123+
RUNSPEC
124+
125+
DIMENS
126+
1 1 1 /
127+
128+
AUTOREF
129+
3 5 7 1 /
130+
131+
GRID
132+
133+
DX
134+
1*1 /
135+
DY
136+
1*1 /
137+
DZ
138+
1*1 /
139+
TOPS
140+
1*0 /
141+
142+
PROPS
143+
144+
SOLUTION
145+
146+
SCHEDULE
147+
)";
148+
149+
Opm::Parser parser;
150+
Opm::Deck deck = parser.parseString(deck_string);
151+
Opm::EclipseState state(deck);
152+
153+
const auto& autoref_keyword = deck["AUTOREF"][0];
154+
155+
Opm::AutoRefManager autoRefManager{};
156+
157+
BOOST_CHECK_THROW(Opm::readKeywordAutoRef(autoref_keyword.getRecord(0), autoRefManager), std::invalid_argument);
158+
}

0 commit comments

Comments
 (0)