Loading...
Searching...
No Matches
findOverlapRowsAndColumns.hpp
/*
Copyright 2018 Andreas Thune
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/>.
*/
#ifndef OPM_FINDOVERLAPROWSANDCOLUMNS_HEADER_INCLUDED
#define OPM_FINDOVERLAPROWSANDCOLUMNS_HEADER_INCLUDED
#include <opm/grid/common/WellConnections.hpp>
#include <opm/grid/common/CartesianIndexMapper.hpp>
#include <cstddef>
#include <utility>
#include <vector>
namespace Dune {
template<class Grid> class CartesianIndexMapper;
}
namespace Opm
{
namespace detail
{
template<class Grid, class CartMapper, class W>
void setWellConnections(const Grid& grid, const CartMapper& cartMapper, const W& wells, const std::unordered_map<std::string, std::set<int>>& possibleFutureConnections, bool useWellConn, std::vector<std::set<int>>& wellGraph, int numJacobiBlocks)
{
if ( grid.comm().size() > 1 || numJacobiBlocks > 1)
{
const int numCells = cartMapper.compressedSize(); // grid.numCells()
wellGraph.resize(numCells);
if (useWellConn) {
const auto& cpgdim = cartMapper.cartesianDimensions();
std::vector<int> cart(cpgdim[0]*cpgdim[1]*cpgdim[2], -1);
for( int i=0; i < numCells; ++i )
cart[ cartMapper.cartesianIndex( i ) ] = i;
Dune::cpgrid::WellConnections well_indices;
well_indices.init(wells, possibleFutureConnections, cpgdim, cart);
for (auto& well : well_indices)
{
for (auto perf = well.begin(); perf != well.end(); ++perf)
{
auto perf2 = perf;
for (++perf2; perf2 != well.end(); ++perf2)
{
wellGraph[*perf].insert(*perf2);
wellGraph[*perf2].insert(*perf);
}
}
}
}
}
}
template<class Grid, class Mapper>
void findOverlapAndInterior(const Grid& grid, const Mapper& mapper, std::vector<int>& overlapRows,
std::vector<int>& interiorRows)
{
//only relevant in parallel case.
if ( grid.comm().size() > 1)
{
//Numbering of cells
const auto& gridView = grid.leafGridView();
//loop over cells in mesh
for (const auto& elem : elements(gridView))
{
int lcell = mapper.index(elem);
if (elem.partitionType() != Dune::InteriorEntity)
{
//add row to list
overlapRows.push_back(lcell);
} else {
interiorRows.push_back(lcell);
}
}
}
}
template <class Grid>
std::size_t numMatrixRowsToUseInSolver(const Grid& grid, bool ownerFirst)
{
std::size_t numInterior = 0;
if (!ownerFirst || grid.comm().size()==1)
return grid.leafGridView().size(0);
const auto& gridView = grid.leafGridView();
// loop over cells in mesh
const auto& range = elements(gridView, Dune::Partitions::interior);
numInterior = std::distance(range.begin(), range.end());
return numInterior;
}
} // namespace detail
} // namespace Opm
#endif // OPM_FINDOVERLAPROWSANDCOLUMNS_HEADER_INCLUDED
Dune::CartesianIndexMapper
Definition CollectDataOnIORank.hpp:49
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43