File: WriteRestartFileEventsTests.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 (267 lines) | stat: -rw-r--r-- 9,419 bytes parent folder | download | duplicates (3)
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
/*
  Copyright 2021 Equinor.

  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 Restart File Events
#include <boost/test/unit_test.hpp>

#include <opm/input/eclipse/Schedule/WriteRestartFileEvents.hpp>

#include <cstddef>

BOOST_AUTO_TEST_SUITE(Basic_Operations)

BOOST_AUTO_TEST_CASE(Default_Constructor)
{
    const auto events = Opm::WriteRestartFileEvents{};

    BOOST_CHECK_MESSAGE(!events.writeRestartFile(0),
                        "Default constructed events object must not "
                        "have events at report step zero");

    BOOST_CHECK_MESSAGE(!events.writeRestartFile(11),
                        "Default constructed events object must not "
                        "have events at report step 11");

    BOOST_CHECK_MESSAGE(!events.writeRestartFile(1729),
                        "Default constructed events object must not "
                        "have events at report step 1729");
}

BOOST_AUTO_TEST_CASE(Add_Events)
{
    auto events = Opm::WriteRestartFileEvents{};

    events.addRestartOutput(11);
    events.addRestartOutput(22);
    events.addRestartOutput(33);
    events.addRestartOutput(59);
    events.addRestartOutput(64);
    BOOST_CHECK_MESSAGE(events.writeRestartFile(11),
                        "Events object must have restart event at "
                        "report step 11 after 'add'");

    BOOST_CHECK_MESSAGE(events.writeRestartFile(22),
                        "Events object must have restart event at "
                        "report step 22 after 'add'");

    BOOST_CHECK_MESSAGE(events.writeRestartFile(33),
                        "Events object must have restart event at "
                        "report step 33 after 'add'");

    BOOST_CHECK_MESSAGE(events.writeRestartFile(59),
                        "Events object must have restart event at "
                        "report step 59 after 'add'");

    BOOST_CHECK_MESSAGE(events.writeRestartFile(64),
                        "Events object must have restart event at "
                        "report step 64 after 'add'");

    BOOST_CHECK_MESSAGE(!events.writeRestartFile(0),
                        "Events object must have NOT restart event at "
                        "report step 0 after 'add(64)'");

    BOOST_CHECK_MESSAGE(!events.writeRestartFile(42),
                        "Events object must have NOT restart event at "
                        "report step 42 after 'add(64)'");

    BOOST_CHECK_MESSAGE(!events.writeRestartFile(65),
                        "Events object must have NOT restart event at "
                        "report step 65 after 'add(64)'");

    BOOST_CHECK_MESSAGE(!events.writeRestartFile(1729),
                        "Events object must have NOT restart event at "
                        "report step 1729 after 'add(64)'");
}

BOOST_AUTO_TEST_CASE(Clear_Remaining_Events)
{
    auto events = Opm::WriteRestartFileEvents{};

    events.addRestartOutput(11);
    events.addRestartOutput(22);
    events.addRestartOutput(33);
    events.addRestartOutput(59);

    events.clearRemainingEvents(33);

    BOOST_CHECK_MESSAGE(events.writeRestartFile(11),
                        "Events object must have restart event at "
                        "report step 11 after 'add'");

    BOOST_CHECK_MESSAGE(events.writeRestartFile(22),
                        "Events object must have restart event at "
                        "report step 22 after 'add'");

    for (auto i = 33; i < 64; ++i) {
        BOOST_CHECK_MESSAGE(!events.writeRestartFile(i),
                            "Events object must have NOT restart event at "
                            "report step " << i << " after 'clearRemainingEvents(33)'");
    }

    events.addRestartOutput(33);
    events.clearRemainingEvents(34);

    BOOST_CHECK_MESSAGE(events.writeRestartFile(33),
                        "Events object must have restart event at "
                        "report step 33 after 'clearRemainingEvents(34)'");

    for (auto i = 34; i < 64; ++i) {
        BOOST_CHECK_MESSAGE(!events.writeRestartFile(i),
                            "Events object must have NOT restart event at "
                            "report step " << i << " after 'clearRemainingEvents(34)'");
    }
}

BOOST_AUTO_TEST_CASE(Last_Restart_Event_Before)
{
    auto events = Opm::WriteRestartFileEvents{};

    {
        const auto event = events.lastRestartEventBefore(271828);
        BOOST_CHECK_MESSAGE(!event.has_value(), "There must be no output events before report step 271828");
    }

    events.addRestartOutput(11);
    events.addRestartOutput(22);
    events.addRestartOutput(33);
    events.addRestartOutput(59);

    {
        const auto event = events.lastRestartEventBefore(11);
        BOOST_CHECK_MESSAGE(!event.has_value(), "There must be no output events before report step 11");
    }

    {
        const auto event = events.lastRestartEventBefore(12);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 12");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{11});
    }

    {
        const auto event = events.lastRestartEventBefore(22);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 22");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{11});
    }

    {
        const auto event = events.lastRestartEventBefore(23);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 23");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{22});
    }

    {
        const auto event = events.lastRestartEventBefore(28);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 28");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{22});
    }

    {
        const auto event = events.lastRestartEventBefore(33);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 33");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{22});
    }

    {
        const auto event = events.lastRestartEventBefore(34);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 34");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{33});
    }

    {
        const auto event = events.lastRestartEventBefore(50);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 50");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{33});
    }

    {
        const auto event = events.lastRestartEventBefore(59);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 59");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{33});
    }

    {
        const auto event = events.lastRestartEventBefore(60);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 60");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{59});
    }

    {
        const auto event = events.lastRestartEventBefore(64);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 64");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{59});
    }

    {
        const auto event = events.lastRestartEventBefore(1729);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 1729");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{59});
    }

    events.addRestartOutput(42);

    {
        const auto event = events.lastRestartEventBefore(42);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 42");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{33});
    }

    {
        const auto event = events.lastRestartEventBefore(43);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 43");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{42});
    }

    events.addRestartOutput(128);

    {
        const auto event = events.lastRestartEventBefore(1729);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 1729");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{128});
    }

    {
        const auto event = events.lastRestartEventBefore(128);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 128");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{59});
    }

    {
        const auto event = events.lastRestartEventBefore(129);
        BOOST_CHECK_MESSAGE(event.has_value(), "There must be an output event before report step 129");

        BOOST_CHECK_EQUAL(event.value(), std::size_t{128});
    }
}

BOOST_AUTO_TEST_SUITE_END()    // Basic_Operations