2015-12-07 09:03:46 -06:00
|
|
|
/*
|
|
|
|
Copyright 2015 SINTEF ICT, Applied Mathematics.
|
|
|
|
|
|
|
|
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_GRIDINIT_HEADER_INCLUDED
|
|
|
|
#define OPM_GRIDINIT_HEADER_INCLUDED
|
|
|
|
|
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
2018-02-09 06:42:16 -06:00
|
|
|
#include <opm/grid/GridManager.hpp>
|
2015-12-07 09:03:46 -06:00
|
|
|
|
2016-04-05 08:17:17 -05:00
|
|
|
#if HAVE_OPM_GRID
|
2018-02-09 06:42:16 -06:00
|
|
|
#include <opm/grid/polyhedralgrid.hh>
|
|
|
|
#include <opm/grid/CpGrid.hpp>
|
2015-12-07 09:03:46 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
|
|
|
/// A class intended to give a generic interface to
|
|
|
|
/// initializing and accessing UnstructuredGrid and CpGrid,
|
|
|
|
/// using specialized templates to accomplish this.
|
|
|
|
template <class Grid>
|
|
|
|
class GridInit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Initialize from a deck and/or an eclipse state and (logical cartesian) specified pore volumes.
|
2016-10-14 02:23:26 -05:00
|
|
|
GridInit(const EclipseState&, const std::vector<double>&)
|
2015-12-07 09:03:46 -06:00
|
|
|
{
|
|
|
|
OPM_THROW(std::logic_error, "Found no specialization for GridInit for the requested Grid class.");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Specialization for UnstructuredGrid.
|
|
|
|
template <>
|
|
|
|
class GridInit<UnstructuredGrid>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Initialize from a deck and/or an eclipse state and (logical cartesian) specified pore volumes.
|
2016-10-14 02:23:26 -05:00
|
|
|
GridInit(const EclipseState& eclipse_state, const std::vector<double>& porv)
|
|
|
|
: grid_manager_(eclipse_state.getInputGrid(), porv)
|
2015-12-07 09:03:46 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
/// Access the created grid.
|
|
|
|
const UnstructuredGrid& grid()
|
|
|
|
{
|
|
|
|
return *grid_manager_.c_grid();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
GridManager grid_manager_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-04-05 08:17:17 -05:00
|
|
|
#if HAVE_OPM_GRID
|
2017-04-05 06:54:12 -05:00
|
|
|
/// Specialization for PolyhedralGrid.
|
|
|
|
template < int dim, int dimworld >
|
|
|
|
class GridInit< Dune::PolyhedralGrid< dim, dimworld > >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef Dune::PolyhedralGrid< dim, dimworld > Grid;
|
|
|
|
/// Initialize from a deck and/or an eclipse state and (logical cartesian) specified pore volumes.
|
|
|
|
GridInit(const EclipseState& eclipse_state, const std::vector<double>& porv)
|
|
|
|
: grid_manager_(eclipse_state.getInputGrid(), porv),
|
|
|
|
grid_( *grid_manager_.c_grid() )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Access the created grid.
|
|
|
|
const Grid& grid()
|
|
|
|
{
|
|
|
|
return grid_;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
GridManager grid_manager_;
|
|
|
|
Grid grid_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-12-07 09:03:46 -06:00
|
|
|
/// Specialization for CpGrid.
|
|
|
|
template <>
|
|
|
|
class GridInit<Dune::CpGrid>
|
|
|
|
{
|
|
|
|
public:
|
2016-11-22 07:09:06 -06:00
|
|
|
GridInit()
|
|
|
|
{
|
|
|
|
gridSelfManaged_ = false;
|
|
|
|
}
|
|
|
|
|
2015-12-07 09:03:46 -06:00
|
|
|
/// Initialize from a deck and/or an eclipse state and (logical cartesian) specified pore volumes.
|
2016-10-14 02:23:26 -05:00
|
|
|
GridInit(const EclipseState& eclipse_state, const std::vector<double>& porv)
|
2015-12-07 09:03:46 -06:00
|
|
|
{
|
2016-11-22 07:09:06 -06:00
|
|
|
gridSelfManaged_ = true;
|
|
|
|
|
|
|
|
grid_ = new Dune::CpGrid;
|
|
|
|
grid_->processEclipseFormat(eclipse_state.getInputGrid(), false, false, false, porv);
|
|
|
|
}
|
|
|
|
|
|
|
|
~GridInit()
|
|
|
|
{
|
|
|
|
if (gridSelfManaged_)
|
|
|
|
delete grid_;
|
2015-12-07 09:03:46 -06:00
|
|
|
}
|
2016-11-22 07:09:06 -06:00
|
|
|
|
2015-12-07 09:03:46 -06:00
|
|
|
/// Access the created grid. Note that mutable access may be required for load balancing.
|
|
|
|
Dune::CpGrid& grid()
|
|
|
|
{
|
2016-11-22 07:09:06 -06:00
|
|
|
return *grid_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// set the grid from the outside
|
|
|
|
void setGrid(Dune::CpGrid& newGrid)
|
|
|
|
{
|
|
|
|
gridSelfManaged_ = false;
|
|
|
|
grid_ = &newGrid;
|
2015-12-07 09:03:46 -06:00
|
|
|
}
|
2016-11-22 07:09:06 -06:00
|
|
|
|
2015-12-07 09:03:46 -06:00
|
|
|
private:
|
2016-11-22 07:09:06 -06:00
|
|
|
Dune::CpGrid* grid_;
|
|
|
|
bool gridSelfManaged_;
|
2015-12-07 09:03:46 -06:00
|
|
|
};
|
2016-04-05 08:17:17 -05:00
|
|
|
#endif // HAVE_OPM_GRID
|
2015-12-07 09:03:46 -06:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace Opm
|
|
|
|
|
|
|
|
#endif // OPM_GRIDINIT_HEADER_INCLUDED
|