21#ifndef OPM_WELLCONNECTIONAUXILIARYMODULE_HEADER_INCLUDED
22#define OPM_WELLCONNECTIONAUXILIARYMODULE_HEADER_INCLUDED
26#include <opm/simulators/flow/SubDomain.hpp>
28#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
29#include <opm/simulators/utils/ParallelCommunication.hpp>
32#include <opm/simulators/utils/MPISerializer.hpp>
37template<
class TypeTag,
class Model>
45 using NeighborSet = typename
46 ::Opm::BaseAuxiliaryModule<TypeTag>::NeighborSet;
50 WellConnectionAuxiliaryModule(Model& model, Parallel::Communication comm)
52 , lin_comm_(std::move(comm))
62 void addNeighbors(std::vector<NeighborSet>& neighbors)
const override
64 if (!model_.addMatrixContributions()) {
69 const auto& schedule_wells = model_.schedule().getWellsatEnd();
70 auto possibleFutureConnections = model_.schedule().getPossibleFutureConnections();
78 for (
const auto& well : schedule_wells)
80 std::vector<int> wellCells = model_.getCellsForConnections(well);
82 const auto possibleFutureConnectionSetIt = possibleFutureConnections.find(well.name());
83 if (possibleFutureConnectionSetIt != possibleFutureConnections.end()) {
84 for (
const auto& global_index : possibleFutureConnectionSetIt->second) {
85 int compressed_idx = model_.compressedIndexForInterior(global_index);
86 if (compressed_idx >= 0) {
87 wellCells.push_back(compressed_idx);
91 for (
int cellIdx : wellCells) {
92 neighbors[cellIdx].insert(wellCells.begin(),
101 void linearize(SparseMatrixAdapter& jacobian, GlobalEqVector& res)
override
103 OPM_BEGIN_PARALLEL_TRY_CATCH();
104 for (
const auto& well : model_) {
105 this->linearizeSingleWell(jacobian, res, well);
107 OPM_END_PARALLEL_TRY_CATCH(
"BlackoilWellModel::linearize failed: ", lin_comm_);
112 model_.recoverWellSolutionAndUpdateWellState(deltaX);
115 void linearizeDomain(
const Domain& domain,
116 SparseMatrixAdapter& jacobian,
119 OPM_TIMEBLOCK(wellLinearizeDomain);
123 for (
const auto& well : model_) {
124 if (model_.well_domain().at(well->name()) == domain.index) {
125 this->linearizeSingleWell(jacobian, res, well);
130 void postSolveDomain(
const GlobalEqVector& deltaX,
const Domain& domain)
132 model_.recoverWellSolutionAndUpdateWellStateDomain(deltaX, domain.index);
135 template <
class Restarter>
136 void deserialize(Restarter& )
145 template <
class Restarter>
152 template<
class WellType>
153 void linearizeSingleWell(SparseMatrixAdapter& jacobian,
155 const WellType& well)
157 if (model_.addMatrixContributions()) {
158 well->addWellContributions(jacobian);
161 const auto& cells = well->cells();
162 linearize_res_local_.resize(cells.size());
164 for (
size_t i = 0; i < cells.size(); ++i) {
165 linearize_res_local_[i] = res[cells[i]];
168 well->apply(linearize_res_local_);
170 for (
size_t i = 0; i < cells.size(); ++i) {
171 res[cells[i]] = linearize_res_local_[i];
176 GlobalEqVector linearize_res_local_{};
177 Parallel::Communication lin_comm_;
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:38
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:146
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 blackoilbioeffectsmodules.hh:43
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:233
Avoid mistakes in calls to broadcast() by wrapping the root argument in an explicit type.
Definition MPISerializer.hpp:33
Representing a part of a grid, in a way suitable for performing local solves.
Definition SubDomain.hpp:85