diff --git a/Makefile.am b/Makefile.am
index b22474f1..d10c0bad 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -52,6 +52,7 @@ opm/core/utility/cpgpreprocess/uniquepoints.c \
opm/core/utility/StopWatch.cpp \
opm/core/utility/newwells.c \
opm/core/utility/writeVtkData.cpp \
+opm/core/GridManager.cpp \
opm/core/linalg/sparse_sys.c \
opm/core/pressure/cfsh.c \
opm/core/pressure/flow_bc.c \
@@ -137,7 +138,6 @@ opm/core/utility/Units.hpp \
opm/core/utility/buildUniformMonotoneTable.hpp \
opm/core/utility/linInt.hpp \
opm/core/utility/linearInterpolation.hpp \
-opm/core/newwells.h \
opm/core/utility/cpgpreprocess/readvector.hpp \
opm/core/utility/cpgpreprocess/uniquepoints.h \
opm/core/utility/cpgpreprocess/preprocess.h \
@@ -148,11 +148,13 @@ opm/core/utility/cpgpreprocess/facetopology.h \
opm/core/utility/cpgpreprocess/grdecl.h \
opm/core/utility/cart_grid.h \
opm/core/utility/writeVtkData.hpp \
-opm/core/well.h \
opm/core/linalg/sparse_sys.h \
opm/core/linalg/blas_lapack.h \
opm/core/grid.h \
+opm/core/well.h \
+opm/core/newwells.h \
opm/core/GridAdapter.hpp \
+opm/core/GridManager.hpp \
opm/core/pressure/fsh.h \
opm/core/pressure/HybridPressureSolver.hpp \
opm/core/pressure/TPFAPressureSolver.hpp \
diff --git a/opm/core/GridManager.cpp b/opm/core/GridManager.cpp
new file mode 100644
index 00000000..50bee274
--- /dev/null
+++ b/opm/core/GridManager.cpp
@@ -0,0 +1,114 @@
+/*
+ Copyright 2012 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 .
+*/
+
+#include
+#include
+#include
+#include
+#include
+
+
+
+namespace Opm
+{
+
+
+
+ /// Construct a 3d corner-point grid from a deck.
+ GridManager::GridManager(const Opm::EclipseGridParser& deck)
+ {
+ // Extract data from deck.
+ const std::vector& zcorn = deck.getFloatingPointValue("ZCORN");
+ const std::vector& coord = deck.getFloatingPointValue("COORD");
+ const std::vector& actnum = deck.getIntegerValue("ACTNUM");
+ std::vector dims;
+ if (deck.hasField("DIMENS")) {
+ dims = deck.getIntegerValue("DIMENS");
+ } else if (deck.hasField("SPECGRID")) {
+ dims = deck.getSPECGRID().dimensions;
+ } else {
+ THROW("Deck must have either DIMENS or SPECGRID.");
+ }
+
+ // Collect in input struct for preprocessing.
+ struct grdecl grdecl;
+ grdecl.zcorn = &zcorn[0];
+ grdecl.coord = &coord[0];
+ grdecl.actnum = &actnum[0];
+ grdecl.dims[0] = dims[0];
+ grdecl.dims[1] = dims[1];
+ grdecl.dims[2] = dims[2];
+
+ // Process and compute.
+ ug_ = preprocess(&grdecl, 0.0);
+ compute_geometry(ug_);
+ }
+
+
+
+
+ /// Construct a 2d cartesian grid with cells of unit size.
+ GridManager::GridManager(int nx, int ny)
+ {
+ ug_ = create_cart_grid_2d(nx, ny);
+ }
+
+
+
+
+ /// Construct a 3d cartesian grid with cells of unit size.
+ GridManager::GridManager(int nx, int ny, int nz)
+ {
+ ug_ = create_cart_grid_3d(nx, ny, nz);
+ }
+
+
+
+
+ /// Construct a 3d cartesian grid with cells of size [dx, dy, dz].
+ GridManager::GridManager(int nx, int ny, int nz,
+ double dx, double dy, double dz)
+ {
+ ug_ = create_hexa_grid_3d(nx, ny, nz, dx, dy, dz);
+ }
+
+
+
+
+ /// Destructor.
+ GridManager::~GridManager()
+ {
+ free_grid(ug_);
+ }
+
+
+
+
+ /// Access the managed UnstructuredGrid.
+ /// The method is named similarly to c_str() in std::string,
+ /// to make it clear that we are returning a C-compatible struct.
+ const UnstructuredGrid* GridManager::c_grid() const
+ {
+ return ug_;
+ }
+
+
+
+
+} // namespace Opm
diff --git a/opm/core/GridManager.hpp b/opm/core/GridManager.hpp
new file mode 100644
index 00000000..97dd84fd
--- /dev/null
+++ b/opm/core/GridManager.hpp
@@ -0,0 +1,73 @@
+/*
+ Copyright 2012 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 .
+*/
+
+#ifndef OPM_GRIDMANAGER_HEADER_INCLUDED
+#define OPM_GRIDMANAGER_HEADER_INCLUDED
+
+
+struct UnstructuredGrid;
+
+
+namespace Opm
+{
+
+ class EclipseGridParser;
+
+ /// This class manages an Opm::UnstructuredGrid in the sense that it
+ /// encapsulates creation and destruction of the grid.
+ /// The following grid types can be constructed:
+ /// - 3d corner-point grids (from deck input)
+ /// - 2d cartesian grids
+ /// - 3d cartesian grids
+ /// The resulting UnstructuredGrid is available through the c_grid() method.
+ class GridManager
+ {
+ public:
+ /// Construct a 3d corner-point grid from a deck.
+ GridManager(const Opm::EclipseGridParser& deck);
+
+ /// Construct a 2d cartesian grid with cells of unit size.
+ GridManager(int nx, int ny);
+
+ /// Construct a 3d cartesian grid with cells of unit size.
+ GridManager(int nx, int ny, int nz);
+
+ /// Construct a 3d cartesian grid with cells of size [dx, dy, dz].
+ GridManager(int nx, int ny, int nz,
+ double dx, double dy, double dz);
+
+ /// Destructor.
+ ~GridManager();
+
+ /// Access the managed UnstructuredGrid.
+ /// The method is named similarly to c_str() in std::string,
+ /// to make it clear that we are returning a C-compatible struct.
+ const UnstructuredGrid* c_grid() const;
+
+ private:
+ // Disable copying and assignment.
+ GridManager(const GridManager& other);
+ GridManager& operator=(const GridManager& other);
+ // The managed UnstructuredGrid.
+ UnstructuredGrid* ug_;
+ };
+
+} // namespace Opm
+
+#endif // OPM_GRIDMANAGER_HEADER_INCLUDED