File: test_convergencereport.cpp

package info (click to toggle)
opm-simulators 2025.10%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,552 kB
  • sloc: cpp: 193,037; sh: 1,807; python: 1,704; lisp: 1,108; makefile: 31; awk: 10
file content (128 lines) | stat: -rw-r--r-- 5,154 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
/*
  Copyright 2018 SINTEF Digital, Mathematics and Cybernetics.
  Copyright 2018 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/>.
*/

#include <config.h>
#define BOOST_TEST_MODULE ConvergenceReportTest
#include <boost/test/unit_test.hpp>

#include <opm/simulators/timestepping/ConvergenceReport.hpp>

using CR = Opm::ConvergenceReport;

BOOST_AUTO_TEST_CASE(DefaultConstructor)
{
    Opm::ConvergenceReport s;
    BOOST_CHECK(s.converged());
    BOOST_CHECK(!s.reservoirFailed());
    BOOST_CHECK(!s.wellFailed());
    BOOST_CHECK(s.severityOfWorstFailure() == CR::Severity::None);
}

BOOST_AUTO_TEST_CASE(Failures)
{
    Opm::ConvergenceReport s1;
    s1.setReservoirFailed({CR::ReservoirFailure::Type::Cnv, CR::Severity::Normal, 2});
    {
        BOOST_CHECK(!s1.converged());
        BOOST_CHECK(s1.reservoirFailed());
        BOOST_CHECK(!s1.wellFailed());
        BOOST_REQUIRE(s1.reservoirFailures().size() == 1);
        const auto f = s1.reservoirFailures()[0];
        BOOST_CHECK(f.type() == CR::ReservoirFailure::Type::Cnv);
        BOOST_CHECK(f.severity() == CR::Severity::Normal);
        BOOST_CHECK(f.phase() == 2);
        BOOST_CHECK(s1.wellFailures().empty());
        BOOST_CHECK(s1.severityOfWorstFailure() == CR::Severity::Normal);
    }

    Opm::ConvergenceReport s2;
    s2.setWellFailed({CR::WellFailure::Type::ControlTHP, CR::Severity::Normal, -1, "PRODUCER-123"});
    s2.setWellFailed({CR::WellFailure::Type::MassBalance, CR::Severity::TooLarge, 2, "INJECTOR-XYZ"});
    {
        BOOST_CHECK(!s2.converged());
        BOOST_CHECK(!s2.reservoirFailed());
        BOOST_CHECK(s2.wellFailed());
        BOOST_CHECK(s2.reservoirFailures().empty());
        BOOST_REQUIRE(s2.wellFailures().size() == 2);
        const auto f0 = s2.wellFailures()[0];
        BOOST_CHECK(f0.type() == CR::WellFailure::Type::ControlTHP);
        BOOST_CHECK(f0.severity() == CR::Severity::Normal);
        BOOST_CHECK(f0.phase() == -1);
        BOOST_CHECK(f0.wellName() == "PRODUCER-123");
        const auto f1 = s2.wellFailures()[1];
        BOOST_CHECK(f1.type() == CR::WellFailure::Type::MassBalance);
        BOOST_CHECK(f1.severity() == CR::Severity::TooLarge);
        BOOST_CHECK(f1.phase() == 2);
        BOOST_CHECK(f1.wellName() == "INJECTOR-XYZ");
        BOOST_CHECK(s2.severityOfWorstFailure() == CR::Severity::TooLarge);
    }

    s1 += s2;
    {
        BOOST_CHECK(!s1.converged());
        BOOST_CHECK(s1.reservoirFailed());
        BOOST_CHECK(s1.wellFailed());
        BOOST_REQUIRE(s1.reservoirFailures().size() == 1);
        const auto f = s1.reservoirFailures()[0];
        BOOST_CHECK(f.type() == CR::ReservoirFailure::Type::Cnv);
        BOOST_CHECK(f.severity() == CR::Severity::Normal);
        BOOST_CHECK(f.phase() == 2);
        BOOST_REQUIRE(s1.wellFailures().size() == 2);
        const auto f0 = s1.wellFailures()[0];
        BOOST_CHECK(f0.type() == CR::WellFailure::Type::ControlTHP);
        BOOST_CHECK(f0.severity() == CR::Severity::Normal);
        BOOST_CHECK(f0.phase() == -1);
        BOOST_CHECK(f0.wellName() == "PRODUCER-123");
        const auto f1 = s1.wellFailures()[1];
        BOOST_CHECK(f1.type() == CR::WellFailure::Type::MassBalance);
        BOOST_CHECK(f1.severity() == CR::Severity::TooLarge);
        BOOST_CHECK(f1.phase() == 2);
        BOOST_CHECK(f1.wellName() == "INJECTOR-XYZ");
        BOOST_CHECK(s1.severityOfWorstFailure() == CR::Severity::TooLarge);
    }

    s1.clear();
    {
        BOOST_CHECK(s1.converged());
        BOOST_CHECK(!s1.reservoirFailed());
        BOOST_CHECK(!s1.wellFailed());
        BOOST_CHECK(s1.severityOfWorstFailure() == CR::Severity::None);
    }

    s1 += s2;
    {
        BOOST_CHECK(!s1.converged());
        BOOST_CHECK(!s1.reservoirFailed());
        BOOST_CHECK(s1.wellFailed());
        BOOST_CHECK(s1.reservoirFailures().empty());
        BOOST_REQUIRE(s1.wellFailures().size() == 2);
        const auto f0 = s1.wellFailures()[0];
        BOOST_CHECK(f0.type() == CR::WellFailure::Type::ControlTHP);
        BOOST_CHECK(f0.severity() == CR::Severity::Normal);
        BOOST_CHECK(f0.phase() == -1);
        BOOST_CHECK(f0.wellName() == "PRODUCER-123");
        const auto f1 = s1.wellFailures()[1];
        BOOST_CHECK(f1.type() == CR::WellFailure::Type::MassBalance);
        BOOST_CHECK(f1.severity() == CR::Severity::TooLarge);
        BOOST_CHECK(f1.phase() == 2);
        BOOST_CHECK(f1.wellName() == "INJECTOR-XYZ");
        BOOST_CHECK(s1.severityOfWorstFailure() == CR::Severity::TooLarge);
    }
}