File: IOConfigTests.cpp

package info (click to toggle)
opm-common 2024.10%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 98,420 kB
  • sloc: cpp: 263,013; python: 3,155; sh: 198; xml: 174; pascal: 136; makefile: 12
file content (303 lines) | stat: -rw-r--r-- 8,117 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
  Copyright 2015 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/>.
 */



#define BOOST_TEST_MODULE IOConfigTests

#include <boost/test/unit_test.hpp>

#include <filesystem>
#include <fstream>
#include <iostream>
#include <opm/input/eclipse/Deck/Deck.hpp>
#include <opm/input/eclipse/Parser/Parser.hpp>
#include <opm/input/eclipse/EclipseState/IOConfig/IOConfig.hpp>

#include "tests/WorkArea.hpp"
namespace fs = std::filesystem;

using namespace Opm;

const std::string& deckStr =  R"(
RUNSPEC

DIMENS
 10 10 10 /
GRID
GRIDFILE
 0 1 /

START
 21 MAY 1981 /

SCHEDULE
DATES
 22 MAY 1981 /              -- timestep 1
 23 MAY 1981 /              -- timestep 2
 24 MAY 1981 /              -- timestep 3
 25 MAY 1981 /              -- timestep 4
 26 MAY 1981 /              -- timestep 5
 1 JAN 1982 /               -- timestep 6
 1 JAN 1982 13:55:44 /      -- timestep 7
 3 JAN 1982 14:56:45.123 /  -- timestep 8
 4 JAN 1982 14:56:45.123 /  -- timestep 9
 5 JAN 1982 14:56:45.123 /  -- timestep 10
 6 JAN 1982 14:56:45.123 /  -- timestep 11
 7 JAN 1982 14:56:45.123 /  -- timestep 12
 8 JAN 1982 14:56:45.123 /  -- timestep 13
 9 JAN 1982 14:56:45.123 /  -- timestep 14
 10 JAN 1982 14:56:45.123 / -- timestep 15
 11 JAN 1982 14:56:45.123 / -- timestep 16
 1 JAN 1983 /               -- timestep 17
 2 JAN 1983 /               -- timestep 18
 3 JAN 1983 /               -- timestep 19
 1 JAN 1984 /               -- timestep 20
 2 JAN 1984 /               -- timestep 21
 1 JAN 1985 /               -- timestep 22
 3 JAN 1986 14:56:45.123 /  -- timestep 23
 4 JAN 1986 14:56:45.123 /  -- timestep 24
 5 JAN 1986 14:56:45.123 /  -- timestep 25
 1 JAN 1987 /               -- timestep 26
 1 JAN 1988 /               -- timestep 27
 2 JAN 1988 /               -- timestep 28
 3 JAN 1988 /               -- timestep 29
 1 JAN 1989 /               -- timestep 30
 2 JAN 1989 /               -- timestep 31
 2 JAN 1990 /               -- timestep 32
 2 JAN 1991 /               -- timestep 33
 3 JAN 1991 /               -- timestep 34
 4 JAN 1991 /               -- timestep 35
 1 JAN 1992 /               -- timestep 36
 1 FEB 1992 /               -- timestep 37
 1 MAR 1992 /               -- timestep 38
 2 MAR 1992 /               -- timestep 39
 3 MAR 1992 /               -- timestep 40
 4 MAR 1992 /               -- timestep 41
 1 APR 1992 /               -- timestep 42
 2 APR 1992 /               -- timestep 43
 1 MAY 1992 /               -- timestep 44
 2 MAY 1992 /               -- timestep 45
 3 MAY 1992 /               -- timestep 46
 3 JUN 1992 /               -- timestep 47
 3 JUL 1992 /               -- timestep 48
 3 AUG 1992 /               -- timestep 49
 4 AUG 1992 /               -- timestep 50
 5 AUG 1992 /               -- timestep 51
 6 AUG 1992 /               -- timestep 52
 7 AUG 1992 /               -- timestep 53
 8 AUG 1992 /               -- timestep 54
 9 AUG 1992 /               -- timestep 55
 10 AUG 1992 /              -- timestep 56
 11 AUG 1992 /              -- timestep 57
 12 AUG 1992 /              -- timestep 58
 13 AUG 1992 /              -- timestep 59
 14 AUG 1992 /              -- timestep 60
 15 AUG 1992 /              -- timestep 61
/)";

const std::string deckStr_RFT = R"(
RUNSPEC
OIL
GAS
WATER
DIMENS
 10 10 10 /
GRID
DXV
10*0.25 /
DYV
10*0.25 /
DZV
10*0.25 /
TOPS
100*0.25 /

"START             -- 0
1 NOV 1979 /
SCHEDULE
DATES             -- 1
 1 DES 1979/
/
WELSPECS
    'OP_1'       'OP'   9   9 1*     'OIL' 1*      1*  1*   1*  1*   1*  1*  /
    'OP_2'       'OP'   4   4 1*     'OIL' 1*      1*  1*   1*  1*   1*  1*  /
/
COMPDAT
 'OP_1'  9  9   1   1 'OPEN' 1*   32.948   0.311  3047.839 1*  1*  'X'  22.100 /
 'OP_1'  9  9   2   2 'OPEN' 1*   46.825   0.311  4332.346 1*  1*  'X'  22.123 /
 'OP_1'  9  9   3  9 'OPEN' 1*   32.948   0.311  3047.839 1*  1*  'X'  22.100 /
 'OP_2'  4  4   4  9 'OPEN' 1*   32.948   0.311  3047.839 1*  1*  'X'  22.100 /
/
DATES             -- 2
 10  OKT 2008 /
/
WRFT
/
WELOPEN
 'OP_1' OPEN /
 'OP_2' OPEN /
/
DATES             -- 3
 10  NOV 2008 /
/
)";






BOOST_AUTO_TEST_CASE(DefaultProperties) {
    const char* data =  R"(
RUNSPEC
DIMENS
 10 10 10 /
GRID
START
 21 MAY 1981 /

SCHEDULE
RPTRST
'BASIC = 1'
/
DATES
 22 MAY 1981 /
/
RPTSCHED
RESTART=0
/
DATES
 23 MAY 1981 /
 24 MAY 1981 /
 23 MAY 1982 /
 24 MAY 1982 /
 24 MAY 1983 /
 25 MAY 1984 /
 26 MAY 1984 /
 26 MAY 1985 /
 27 MAY 1985 /
 1 JAN 1986 /
/
)";

    auto deck = Parser().parseString( data);
    IOConfig ioConfig( deck );

    /*If no GRIDFILE nor NOGGF keywords are specified, default output an EGRID file*/
    BOOST_CHECK( ioConfig.getWriteEGRIDFile() );
    /*If no INIT keyword is specified, verify no write of INIT file*/
    BOOST_CHECK( !ioConfig.getWriteINITFile() );
    /*If no UNIFIN keyword is specified, verify UNIFIN false (default is multiple) */
    BOOST_CHECK( !ioConfig.getUNIFIN() );
    /*If no UNIFOUT keyword is specified, verify UNIFOUT false (default is multiple) */
    BOOST_CHECK( !ioConfig.getUNIFOUT() );
    /*If no FMTIN keyword is specified, verify FMTIN false (default is unformatted) */
    BOOST_CHECK( !ioConfig.getFMTIN() );
    /*If no FMTOUT keyword is specified, verify FMTOUT false (default is unformatted) */
    BOOST_CHECK( !ioConfig.getFMTOUT() );
}

BOOST_AUTO_TEST_CASE(OutputProperties) {
    const std::string data = R"(
RUNSPEC
UNIFIN
UNIFOUT
FMTIN
FMTOUT
DIMENS
 10 10 10 /
GRID
NOGGF
INIT
START
 21 MAY 1981 /

SCHEDULE
)";


    auto deck = Parser().parseString( data );
    IOConfig ioConfig( deck );

    BOOST_CHECK( !ioConfig.getWriteEGRIDFile() );
    /*If INIT keyword is specified, verify write of INIT file*/
    BOOST_CHECK( ioConfig.getWriteINITFile() );
    /*If UNIFOUT keyword is specified, verify unified write*/
    BOOST_CHECK( ioConfig.getUNIFOUT() );
    /*If FMTOUT keyword is specified, verify formatted write*/
    BOOST_CHECK( ioConfig.getFMTOUT() );
}

BOOST_AUTO_TEST_CASE(NoGRIDFILE) {
    const char* data =  R"(
RUNSPEC

DIMENS
10 10 10 /
GRID
GRIDFILE
 0 0 /
)";

    auto deck = Parser().parseString( data );
    IOConfig ioConfig( deck );

    /*If GRIDFILE 0 0 is specified, no EGRID file is written */
    BOOST_CHECK( !ioConfig.getWriteEGRIDFile() );
}

void touch_file(const fs::path& file) {
    if (!fs::exists(file)) {
        if (file.has_parent_path()) {
            const auto& parent_path = file.parent_path();
            if (!fs::is_directory(parent_path))
                fs::create_directories(parent_path);
        }
        std::ofstream os{file};
    }
}

BOOST_AUTO_TEST_CASE(OutputPaths) {
    WorkArea wa;

    IOConfig config1( "" );
    BOOST_CHECK_EQUAL("", config1.getBaseName() );

    Deck deck2;
    touch_file("testString.DATA");
    deck2.setDataFile( "testString.DATA" );
    IOConfig config2( deck2 );
    std::string output_dir2 =  ".";
    BOOST_CHECK_EQUAL( output_dir2,  config2.getOutputDir() );
    BOOST_CHECK_EQUAL( "TESTSTRING", config2.getBaseName() );

    namespace fs = std::filesystem;

    Deck deck3;
    touch_file("path/to/testString.DATA");
    deck3.setDataFile( "path/to/testString.DATA" );
    IOConfig config3( deck3 );
    std::string output_dir3 =  "/path/to";
    config3.setOutputDir( output_dir3 );
    auto testpath = fs::path( "/path/to/TESTSTRING" ).make_preferred().string();
    BOOST_CHECK_EQUAL( output_dir3,  config3.getOutputDir() );
    BOOST_CHECK_EQUAL( "TESTSTRING", config3.getBaseName() );
    BOOST_CHECK_EQUAL( testpath, config3.fullBasePath() );
}