My Project
Loading...
Searching...
No Matches
WellConnectionAuxiliaryModule.hpp
1/*
2 Copyright 2017 Dr. Blatt - HPC-Simulation-Software & Services
3 Copyright 2017 Statoil ASA.
4
5 This file is part of the Open Porous Media project (OPM).
6
7 OPM is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 OPM is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with OPM. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef OPM_WELLCONNECTIONAUXILIARYMODULE_HEADER_INCLUDED
22#define OPM_WELLCONNECTIONAUXILIARYMODULE_HEADER_INCLUDED
23
25
26#include <opm/simulators/flow/SubDomain.hpp>
27
28#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
29#include <opm/simulators/utils/ParallelCommunication.hpp>
30
31#if HAVE_MPI
32#include <opm/simulators/utils/MPISerializer.hpp>
33#endif
34
35namespace Opm {
36
37template<class TypeTag, class Model>
39{
43
44public:
45 using NeighborSet = typename
46 ::Opm::BaseAuxiliaryModule<TypeTag>::NeighborSet;
47
48 using Domain = SubDomain<Grid>;
49
50 WellConnectionAuxiliaryModule(Model& model, Parallel::Communication comm)
51 : model_(model)
52 , lin_comm_(std::move(comm))
53 {
54 }
55
56 unsigned numDofs() const override
57 {
58 // No extra dofs are inserted for wells.
59 return 0;
60 }
61
62 void addNeighbors(std::vector<NeighborSet>& neighbors) const override
63 {
64 if (!model_.addMatrixContributions()) {
65 return;
66 }
67
68 // Create cartesian to compressed mapping
69 const auto& schedule_wells = model_.schedule().getWellsatEnd();
70 auto possibleFutureConnections = model_.schedule().getPossibleFutureConnections();
71
72#if HAVE_MPI
73 // Communicate Map to other processes, since it is only available on rank 0
76#endif
77 // initialize the additional cell connections introduced by wells.
78 for (const auto& well : schedule_wells)
79 {
80 std::vector<int> wellCells = model_.getCellsForConnections(well);
81 // Now add the cells of the possible future connections
82 const auto possibleFutureConnectionSetIt = possibleFutureConnections.find(well.name());
84 for (const auto& global_index : possibleFutureConnectionSetIt->second) {
85 int compressed_idx = model_.compressedIndexForInterior(global_index);
86 if (compressed_idx >= 0) { // Ignore connections in inactive/remote cells.
87 wellCells.push_back(compressed_idx);
88 }
89 }
90 }
91 for (int cellIdx : wellCells) {
92 neighbors[cellIdx].insert(wellCells.begin(),
93 wellCells.end());
94 }
95 }
96 }
97
98 void applyInitial() override
99 {}
100
101 void linearize(SparseMatrixAdapter& jacobian, GlobalEqVector& res) override
102 {
103 OPM_BEGIN_PARALLEL_TRY_CATCH();
104 for (const auto& well : model_) {
105 this->linearizeSingleWell(jacobian, res, well);
106 }
107 OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::linearize failed: ", lin_comm_);
108 }
109
110 void postSolve(GlobalEqVector& deltaX) override
111 {
112 model_.recoverWellSolutionAndUpdateWellState(deltaX);
113 }
114
115 void linearizeDomain(const Domain& domain,
116 SparseMatrixAdapter& jacobian,
117 GlobalEqVector& res)
118 {
119 // Note: no point in trying to do a parallel gathering
120 // try/catch here, as this function is not called in
121 // parallel but for each individual domain of each rank.
122 for (const auto& well : model_) {
123 if (model_.well_domain().at(well->name()) == domain.index) {
124 this->linearizeSingleWell(jacobian, res, well);
125 }
126 }
127 }
128
129 void postSolveDomain(const GlobalEqVector& deltaX, const Domain& domain)
130 {
131 model_.recoverWellSolutionAndUpdateWellStateDomain(deltaX, domain.index);
132 }
133
134 template <class Restarter>
135 void deserialize(Restarter& /* res */)
136 {
137 // TODO (?)
138 }
139
144 template <class Restarter>
145 void serialize(Restarter& /* res*/)
146 {
147 // TODO (?)
148 }
149
150private:
151 template<class WellType>
152 void linearizeSingleWell(SparseMatrixAdapter& jacobian,
153 GlobalEqVector& res,
154 const WellType& well)
155 {
156 if (model_.addMatrixContributions()) {
157 well->addWellContributions(jacobian);
158 }
159
160 const auto& cells = well->cells();
161 linearize_res_local_.resize(cells.size());
162
163 for (size_t i = 0; i < cells.size(); ++i) {
164 linearize_res_local_[i] = res[cells[i]];
165 }
166
167 well->apply(linearize_res_local_);
168
169 for (size_t i = 0; i < cells.size(); ++i) {
170 res[cells[i]] = linearize_res_local_[i];
171 }
172 }
173
174 Model& model_;
175 GlobalEqVector linearize_res_local_{};
176 Parallel::Communication lin_comm_;
177};
178
179} // end namespace OPM
180#endif
Base class for specifying auxiliary equations.
Base class for specifying auxiliary equations.
Definition baseauxiliarymodule.hh:56
Class for serializing and broadcasting data using MPI.
Definition MPISerializer.hpp:31
Definition WellConnectionAuxiliaryModule.hpp:39
unsigned numDofs() const override
Returns the number of additional degrees of freedom required for the auxiliary module.
Definition WellConnectionAuxiliaryModule.hpp:56
void linearize(SparseMatrixAdapter &jacobian, GlobalEqVector &res) override
Linearize the auxiliary equation.
Definition WellConnectionAuxiliaryModule.hpp:101
void serialize(Restarter &)
This method writes the complete state of the well to the harddisk.
Definition WellConnectionAuxiliaryModule.hpp:145
void addNeighbors(std::vector< NeighborSet > &neighbors) const override
Specify the additional neighboring correlations caused by the auxiliary module.
Definition WellConnectionAuxiliaryModule.hpp:62
void postSolve(GlobalEqVector &deltaX) override
This method is called after the linear solver has been called but before the solution is updated for ...
Definition WellConnectionAuxiliaryModule.hpp:110
void applyInitial() override
Set the initial condition of the auxiliary module in the solution vector.
Definition WellConnectionAuxiliaryModule.hpp:98
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition propertysystem.hh:235
Representing a part of a grid, in a way suitable for performing local solves.
Definition SubDomain.hpp:85