Merge pull request #4368 from akva2/wellconnections_hpp_include

Avoid WellConnections.hpp in simulator objects
This commit is contained in:
Bård Skaflestad 2023-01-12 14:28:44 +01:00 committed by GitHub
commit 0078dd5df6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 138 additions and 83 deletions

View File

@ -113,6 +113,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/simulators/wells/VFPInjProperties.cpp
opm/simulators/wells/WellAssemble.cpp
opm/simulators/wells/WellBhpThpCalculator.cpp
opm/simulators/wells/WellConnectionAuxiliaryModule.cpp
opm/simulators/wells/WellConstraints.cpp
opm/simulators/wells/WellConvergence.cpp
opm/simulators/wells/WellGroupConstraints.cpp

View File

@ -34,6 +34,7 @@
#include <opm/input/eclipse/Schedule/RFTConfig.hpp>
#include <opm/input/eclipse/Schedule/Schedule.hpp>
#include <opm/input/eclipse/Schedule/SummaryState.hpp>
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
#include <opm/input/eclipse/Units/Units.hpp>
#include <algorithm>

View File

@ -44,6 +44,7 @@
#include <opm/input/eclipse/Schedule/UDQ/UDQASTNode.hpp>
#include <opm/input/eclipse/Schedule/UDQ/UDQConfig.hpp>
#include <opm/input/eclipse/Schedule/Well/NameOrder.hpp>
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
#include <opm/input/eclipse/Schedule/Well/WList.hpp>
#include <opm/input/eclipse/Schedule/Well/WListManager.hpp>
#include <opm/input/eclipse/Schedule/Well/WellTestState.hpp>

View File

@ -37,6 +37,7 @@
#include <opm/input/eclipse/Schedule/Network/Balance.hpp>
#include <opm/input/eclipse/Schedule/Network/ExtNetwork.hpp>
#include <opm/input/eclipse/Schedule/Schedule.hpp>
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
#include <opm/input/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
#include <opm/simulators/utils/DeferredLogger.hpp>
@ -1238,4 +1239,24 @@ shouldIterateNetwork(const int reportStepIdx,
network_imbalance > balance.pressure_tolerance();
}
std::vector<int>
BlackoilWellModelGeneric::
getCellsForConnections(const Well& well) const
{
std::vector<int> wellCells;
// All possible connections of the well
const auto& connectionSet = well.getConnections();
wellCells.reserve(connectionSet.size());
for (const auto& connection : connectionSet)
{
int compressed_idx = compressedIndexForInterior(connection.global_index());
if (compressed_idx >= 0) { // Ignore connections in inactive/remote cells.
wellCells.push_back(compressed_idx);
}
}
return wellCells;
}
}

View File

@ -343,6 +343,7 @@ protected:
/// \brief get compressed index for interior cells (-1, otherwise
virtual int compressedIndexForInterior(int cartesian_cell_idx) const = 0;
std::vector<int> getCellsForConnections(const Well& well) const;
Schedule& schedule_;
const SummaryState& summaryState_;

View File

@ -128,20 +128,7 @@ namespace Opm {
// initialize the additional cell connections introduced by wells.
for (const auto& well : schedule_wells)
{
std::vector<int> wellCells;
// All possible connections of the well
const auto& connectionSet = well.getConnections();
wellCells.reserve(connectionSet.size());
for (std::size_t c = 0; c < connectionSet.size(); c++)
{
const auto& connection = connectionSet.get(c);
int compressed_idx = compressedIndexForInterior(connection.global_index());
if ( compressed_idx >= 0 ) { // Ignore connections in inactive/remote cells.
wellCells.push_back(compressed_idx);
}
}
std::vector<int> wellCells = this->getCellsForConnections(well);
for (int cellIdx : wellCells) {
neighbors[cellIdx].insert(wellCells.begin(),
wellCells.end());
@ -630,7 +617,7 @@ namespace Opm {
for (int w = 0; w < nw; ++w) {
const Well& well_ecl = wells_ecl_[w];
if (well_ecl.getConnections().empty()) {
if (!well_ecl.hasConnections()) {
// No connections in this well. Nothing to do.
continue;
}
@ -1288,19 +1275,7 @@ namespace Opm {
// initialize the additional cell connections introduced by wells.
for ( const auto& well : schedule_wells )
{
std::vector<int> compressed_well_perforations;
// All possible completions of the well
const auto& completionSet = well.getConnections();
compressed_well_perforations.reserve(completionSet.size());
for (const auto& connection: well.getConnections())
{
const int compressed_idx = compressedIndexForInterior(connection.global_index());
if ( compressed_idx >= 0 ) // Ignore completions in inactive/remote cells.
{
compressed_well_perforations.push_back(compressed_idx);
}
}
std::vector<int> compressed_well_perforations = this->getCellsForConnections(well);
// also include wells with no perforations in case
std::sort(compressed_well_perforations.begin(),
@ -1642,7 +1617,7 @@ namespace Opm {
// corresponding "this->wells_ecl_[shutWell]".
for (const auto& shutWell : this->local_shut_wells_) {
if (this->wells_ecl_[shutWell].getConnections().empty()) {
if (!this->wells_ecl_[shutWell].hasConnections()) {
// No connections in this well. Nothing to do.
continue;
}

View File

@ -23,6 +23,8 @@
#include <opm/common/ErrorMacros.hpp>
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
#include <opm/material/densead/EvaluationFormat.hpp>
#include <opm/material/fluidsystems/BlackOilDefaultIndexTraits.hpp>

View File

@ -21,6 +21,7 @@
#include <opm/common/ErrorMacros.hpp>
#include <opm/input/eclipse/Schedule/Well/Well.hpp>
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
namespace Dune
{

View File

@ -0,0 +1,82 @@
/*
Copyright 2017 Dr. Blatt - HPC-Simulation-Software & Services
Copyright 2017 Statoil ASA.
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>
#include <opm/simulators/wells/WellConnectionAuxiliaryModule.hpp>
#include <opm/grid/CpGrid.hpp>
#include <opm/input/eclipse/Schedule/Schedule.hpp>
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
#include <algorithm>
namespace Opm
{
WellConnectionAuxiliaryModuleGeneric::
WellConnectionAuxiliaryModuleGeneric(const Schedule& schedule,
const Dune::CpGrid& grid)
{
// Create cartesian to compressed mapping
const auto& globalCell = grid.globalCell();
const auto& cartesianSize = grid.logicalCartesianSize();
auto size = cartesianSize[0] * cartesianSize[1] * cartesianSize[2];
std::vector<int> cartesianToCompressed(size, -1);
auto begin = globalCell.begin();
for (auto cell = begin, end = globalCell.end(); cell != end; ++cell)
{
cartesianToCompressed[ *cell ] = cell - begin;
}
const auto& schedule_wells = schedule.getWellsatEnd();
wells_.reserve(schedule_wells.size());
// initialize the additional cell connections introduced by wells.
for (const auto& well : schedule_wells)
{
std::vector<int> compressed_well_perforations;
// All possible completions of the well
const auto& completionSet = well.getConnections();
compressed_well_perforations.reserve(completionSet.size());
for (const auto& completion : completionSet)
{
int compressed_idx = cartesianToCompressed[completion.global_index()];
if (compressed_idx >= 0) // Ignore completions in inactive/remote cells.
{
compressed_well_perforations.push_back(compressed_idx);
}
}
if (!compressed_well_perforations.empty())
{
std::sort(compressed_well_perforations.begin(),
compressed_well_perforations.end());
wells_.push_back(compressed_well_perforations);
}
}
}
} // end namespace Opm

View File

@ -23,15 +23,28 @@
#include <opm/models/discretization/common/baseauxiliarymodule.hh>
#include <opm/grid/CpGrid.hpp>
#include <vector>
#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
namespace Dune { class CpGrid; }
namespace Opm
{
class Schedule;
class WellConnectionAuxiliaryModuleGeneric
{
protected:
WellConnectionAuxiliaryModuleGeneric(const Schedule& schedule,
const Dune::CpGrid& grid);
std::vector<std::vector<int> > wells_;
};
template<class TypeTag>
class WellConnectionAuxiliaryModule
: public BaseAuxiliaryModule<TypeTag>
, private WellConnectionAuxiliaryModuleGeneric
{
using GlobalEqVector = GetPropType<TypeTag, Properties::GlobalEqVector>;
using SparseMatrixAdapter = GetPropType<TypeTag, Properties::SparseMatrixAdapter>;
@ -43,55 +56,8 @@ public:
WellConnectionAuxiliaryModule(const Schedule& schedule,
const Dune::CpGrid& grid)
: WellConnectionAuxiliaryModuleGeneric(schedule, grid)
{
// Create cartesian to compressed mapping
const auto& globalCell = grid.globalCell();
const auto& cartesianSize = grid.logicalCartesianSize();
auto size = cartesianSize[0]*cartesianSize[1]*cartesianSize[2];
std::vector<int> cartesianToCompressed(size, -1);
auto begin = globalCell.begin();
for ( auto cell = begin, end= globalCell.end(); cell != end; ++cell )
{
cartesianToCompressed[ *cell ] = cell - begin;
}
const auto& schedule_wells = schedule.getWellsatEnd();
wells_.reserve(schedule_wells.size());
// initialize the additional cell connections introduced by wells.
for ( const auto& well : schedule_wells )
{
std::vector<int> compressed_well_perforations;
// All possible completions of the well
const auto& completionSet = well.getConnections();
compressed_well_perforations.reserve(completionSet.size());
for ( size_t c=0; c < completionSet.size(); c++ )
{
const auto& completion = completionSet.get(c);
int i = completion.getI();
int j = completion.getJ();
int k = completion.getK();
int cart_grid_idx = i + cartesianSize[0]*(j + cartesianSize[1]*k);
int compressed_idx = cartesianToCompressed[cart_grid_idx];
if ( compressed_idx >= 0 ) // Ignore completions in inactive/remote cells.
{
compressed_well_perforations.push_back(compressed_idx);
}
}
if ( ! compressed_well_perforations.empty() )
{
std::sort(compressed_well_perforations.begin(),
compressed_well_perforations.end());
wells_.push_back(compressed_well_perforations);
}
}
}
unsigned numDofs() const
@ -102,9 +68,9 @@ public:
void addNeighbors(std::vector<NeighborSet>& neighbors) const
{
for(const auto& well_perforations : wells_)
for (const auto& well_perforations : wells_)
{
for(const auto& perforation : well_perforations)
for (const auto& perforation : well_perforations)
neighbors[perforation].insert(well_perforations.begin(),
well_perforations.end());
}
@ -119,8 +85,6 @@ public:
}
private:
std::vector<std::vector<int> > wells_;
};
} // end namespace OPM

View File

@ -22,6 +22,7 @@
#include <config.h>
#include <opm/simulators/wells/WellInterfaceGeneric.hpp>
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
#include <opm/input/eclipse/Schedule/Well/WellTestState.hpp>
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
#include <opm/simulators/wells/PerforationData.hpp>

View File

@ -24,6 +24,7 @@
#include <opm/common/ErrorMacros.hpp>
#include <opm/input/eclipse/Schedule/Schedule.hpp>
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
#include <opm/simulators/utils/ParallelCommunication.hpp>
#include <opm/simulators/wells/ParallelWellInfo.hpp>

View File

@ -22,6 +22,7 @@
#include <config.h>
#include <opm/simulators/wells/WellTest.hpp>
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
#include <opm/input/eclipse/Schedule/Well/WellTestState.hpp>
#include <opm/simulators/utils/DeferredLogger.hpp>

View File

@ -95,6 +95,7 @@
#include <opm/input/eclipse/Schedule/Well/NameOrder.hpp>
#include <opm/input/eclipse/Schedule/Well/PAvg.hpp>
#include <opm/input/eclipse/Schedule/Well/Well.hpp>
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
#include <opm/input/eclipse/Schedule/Well/WellFoamProperties.hpp>
#include <opm/input/eclipse/Schedule/Well/WellPolymerProperties.hpp>
#include <opm/input/eclipse/Schedule/Well/WellTracerProperties.hpp>

View File

@ -32,6 +32,7 @@
#include <opm/input/eclipse/Parser/Parser.hpp>
#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
#include <opm/input/eclipse/Schedule/SummaryState.hpp>
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
#include <opm/input/eclipse/Deck/Deck.hpp>
#include <opm/input/eclipse/EclipseState/Tables/TableManager.hpp>
#include <opm/input/eclipse/Python/Python.hpp>

View File

@ -43,6 +43,7 @@
#include <opm/input/eclipse/Parser/ParseContext.hpp>
#include <opm/input/eclipse/Schedule/Schedule.hpp>
#include <opm/input/eclipse/Schedule/SummaryState.hpp>
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
#include <opm/input/eclipse/Units/Units.hpp>
#include <opm/common/utility/TimeService.hpp>