SubDomain.hpp
Go to the documentation of this file.
1/*
2 Copyright 2021 Total SE
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_SUBDOMAIN_HEADER_INCLUDED
21#define OPM_SUBDOMAIN_HEADER_INCLUDED
22
23#include <opm/grid/common/SubGridPart.hpp>
24
25#include <fmt/format.h>
26
27#include <algorithm>
28#include <iterator>
29#include <stdexcept>
30#include <string_view>
31#include <utility>
32#include <vector>
33
34namespace Opm
35{
38 Jacobi,
40 };
41
47 };
48
49 inline DomainOrderingMeasure domainOrderingMeasureFromString(const std::string_view measure)
50 {
51 if (measure == "residual") {
53 } else if (measure == "maxpressure") {
55 } else if (measure == "averagepressure") {
57 } else {
58 throw std::runtime_error(fmt::format(fmt::runtime("Invalid domain ordering '{}' specified"), measure));
59 }
60 }
61
71 {
72 // The index of a subdomain is arbitrary, but can be used by the
73 // solvers to keep track of well locations etc.
74 int index;
75 // All cells of the local problem (interior and overlap), sorted, stored
76 // as cell indices in the local numbering of the current MPI rank.
77 std::vector<int> cells;
78 // The cells owned by this subdomain, sorted. Equal to cells when there
79 // is no overlap.
80 std::vector<int> interior_cells;
81 // Flag for each cell of the current MPI rank, true if the cell is owned
82 // by the subdomain. If empty, assumed to be all true. Not required for
83 // all nonlinear solver algorithms.
84 std::vector<bool> interior;
85 // Flag indicating if this domain should be skipped during solves
86 bool skip;
87 // Enables subdomain solves and linearization using the generic linearization
88 // approach (i.e. FvBaseLinearizer as opposed to TpfaLinearizer).
89 SubDomainIndices(const int i, std::vector<int>&& c, std::vector<bool>&& in, bool s)
90 : SubDomainIndices(i, std::move(c), {}, std::move(in), s)
91 {}
92 // The interior cells c and the overlap cells ov may be given in any
93 // order, but must not have cells in common. Both are sorted here and
94 // merged into cells: extracting the local matrix
95 // (Details::extractMatrix) requires sorted cells, and wells are
96 // assigned to subdomains by binary search in interior_cells.
97 SubDomainIndices(const int i, std::vector<int>&& c, std::vector<int>&& ov,
98 std::vector<bool>&& in, bool s)
99 : index(i), interior_cells(std::move(c)), interior(std::move(in)), skip(s)
100 {
101 // The interior cells normally arrive sorted, so check first.
102 if (!std::ranges::is_sorted(interior_cells)) {
103 std::ranges::sort(interior_cells);
104 }
105 if (ov.empty()) {
107 } else {
108 std::ranges::sort(ov);
109 cells.reserve(interior_cells.size() + ov.size());
110 std::ranges::merge(interior_cells, ov, std::back_inserter(cells));
111 }
112 }
113
114 bool hasOverlap() const
115 {
116 return cells.size() != interior_cells.size();
117 }
118 };
119
122 template <class Grid>
124 {
125 // View of all cells of the local problem. Every entity of the view
126 // reports Dune::InteriorEntity, including overlap cells, since all of
127 // them are solved for; use SubDomainIndices::interior for ownership.
128 Dune::SubGridPart<Grid> view;
129 // Constructor that moves from its argument.
130 SubDomain(const int i, std::vector<int>&& c, std::vector<bool>&& in, Dune::SubGridPart<Grid>&& v, bool s)
131 : SubDomainIndices(i, std::move(c), std::move(in), s)
132 , view(std::move(v))
133 {}
134 SubDomain(const int i, std::vector<int>&& c, std::vector<int>&& ov,
135 std::vector<bool>&& in, Dune::SubGridPart<Grid>&& v, bool s)
136 : SubDomainIndices(i, std::move(c), std::move(ov), std::move(in), s)
137 , view(std::move(v))
138 {}
139 };
140
141} // namespace Opm
142
143
144#endif // OPM_SUBDOMAIN_HEADER_INCLUDED
Definition: blackoilbioeffectsmodules.hh:45
DomainOrderingMeasure
Measure to use for domain ordering.
Definition: SubDomain.hpp:43
DomainOrderingMeasure domainOrderingMeasureFromString(const std::string_view measure)
Definition: SubDomain.hpp:49
DomainSolveApproach
Solver approach for NLDD.
Definition: SubDomain.hpp:37
Definition: SubDomain.hpp:71
std::vector< bool > interior
Definition: SubDomain.hpp:84
std::vector< int > cells
Definition: SubDomain.hpp:77
bool skip
Definition: SubDomain.hpp:86
int index
Definition: SubDomain.hpp:74
SubDomainIndices(const int i, std::vector< int > &&c, std::vector< bool > &&in, bool s)
Definition: SubDomain.hpp:89
std::vector< int > interior_cells
Definition: SubDomain.hpp:80
bool hasOverlap() const
Definition: SubDomain.hpp:114
SubDomainIndices(const int i, std::vector< int > &&c, std::vector< int > &&ov, std::vector< bool > &&in, bool s)
Definition: SubDomain.hpp:97
Definition: SubDomain.hpp:124
SubDomain(const int i, std::vector< int > &&c, std::vector< int > &&ov, std::vector< bool > &&in, Dune::SubGridPart< Grid > &&v, bool s)
Definition: SubDomain.hpp:134
SubDomain(const int i, std::vector< int > &&c, std::vector< bool > &&in, Dune::SubGridPart< Grid > &&v, bool s)
Definition: SubDomain.hpp:130
Dune::SubGridPart< Grid > view
Definition: SubDomain.hpp:128