From 063de95365967af388e0cc65264b90b512c845e7 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 4 May 2016 08:05:41 +0200 Subject: [PATCH] Changed grid initialisation. The routines invoking EclipseGrids parsing are implemented here in opm-upscaling. --- CMakeLists_files.cmake | 2 + examples/known_answer_test.cpp | 8 ++- examples/mimetic_periodic_test.cpp | 10 ++- examples/upscale_elasticity.cpp | 18 ++++-- opm/porsol/blackoil/BlackoilSimulator.hpp | 4 +- opm/porsol/common/setupGridAndProps.hpp | 10 ++- opm/upscaling/initCPGrid.cpp | 79 +++++++++++++++++++++++ opm/upscaling/initCPGrid.hpp | 31 +++++++++ 8 files changed, 149 insertions(+), 13 deletions(-) create mode 100644 opm/upscaling/initCPGrid.cpp create mode 100644 opm/upscaling/initCPGrid.hpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 699b545..ceb6e00 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -47,6 +47,7 @@ list(APPEND MAIN_SOURCE_FILES opm/porsol/euler/ImplicitCapillarity.cpp opm/upscaling/ParserAdditions.cpp opm/upscaling/RelPermUtils.cpp + opm/upscaling/initCPGrid.cpp ) # originally generated with the command: @@ -218,4 +219,5 @@ list (APPEND PUBLIC_HEADER_FILES opm/upscaling/UpscalerBase.hpp opm/upscaling/UpscalerBase_impl.hpp opm/upscaling/UpscalingTraits.hpp + opm/upscaling/initCPGrid.hpp ) diff --git a/examples/known_answer_test.cpp b/examples/known_answer_test.cpp index a07d9c1..7a82426 100644 --- a/examples/known_answer_test.cpp +++ b/examples/known_answer_test.cpp @@ -66,6 +66,10 @@ #include #include +#include + + + #include #include #include @@ -74,6 +78,8 @@ #include + + // ------------ Specifying the solution ------------ typedef Dune::FieldVector Vec; @@ -249,7 +255,7 @@ try // Make a Dune::CpGrid. typedef Dune::CpGrid Grid; Grid grid; - grid.init(param); + Opm::initCPGrid(grid , param); grid.setUniqueBoundaryIds(true); // Make the grid interface diff --git a/examples/mimetic_periodic_test.cpp b/examples/mimetic_periodic_test.cpp index 83fd34c..c539692 100644 --- a/examples/mimetic_periodic_test.cpp +++ b/examples/mimetic_periodic_test.cpp @@ -47,9 +47,16 @@ #include #include +#include + + + #include #include + + + int main(int argc, char** argv) try { @@ -63,8 +70,7 @@ try Dune::CpGrid grid; { Opm::parameter::ParameterGroup param(argc, argv); - - grid.init(param); + Opm::initCPGrid(grid , param); grid.setUniqueBoundaryIds(true); } diff --git a/examples/upscale_elasticity.cpp b/examples/upscale_elasticity.cpp index 9fb371d..d25c3a1 100644 --- a/examples/upscale_elasticity.cpp +++ b/examples/upscale_elasticity.cpp @@ -32,6 +32,10 @@ #include #endif +#include +#include +#include + #include #include @@ -289,13 +293,13 @@ int run(Params& p) cellsize[1] = p.max[1] > -1?p.max[1]/cells[1]:1.0; cellsize[2] = p.max[2] > -1?p.max[2]/cells[2]:1.0; grid.createCartesian(cells,cellsize); - } else -#ifdef HAVE_OLD_CPGRID_API - grid.readEclipseFormat(p.file,p.ctol,false); -#else - grid.readEclipseFormat(p.file,false); -#endif - + } else { + Opm::ParseContext parseContext; + Opm::ParserPtr parser(new Opm::Parser()); + Opm::DeckConstPtr deck(parser->parseFile(p.file , parseContext)); + std::shared_ptr inputGrid = std::make_shared(deck , nullptr); + grid.processEclipseFormat(inputGrid, false); + } ElasticityUpscale upscale(grid, p.ctol, p.Emin, p.file, p.rocklist, p.verbose); diff --git a/opm/porsol/blackoil/BlackoilSimulator.hpp b/opm/porsol/blackoil/BlackoilSimulator.hpp index 84ec637..55e734d 100644 --- a/opm/porsol/blackoil/BlackoilSimulator.hpp +++ b/opm/porsol/blackoil/BlackoilSimulator.hpp @@ -125,10 +125,12 @@ init(const Opm::parameter::ParameterGroup& param) Opm::ParseContext parseContext; Opm::ParserPtr parser(new Opm::Parser()); Opm::DeckConstPtr deck = parser->parseFile(param.get("filename") , parseContext); + std::shared_ptr inputGrid = std::make_shared( deck , nullptr ); + double z_tolerance = param.getDefault("z_tolerance", 0.0); bool periodic_extension = param.getDefault("periodic_extension", false); bool turn_normals = param.getDefault("turn_normals", false); - grid_.processEclipseFormat(deck, z_tolerance, periodic_extension, turn_normals); + grid_.processEclipseFormat(inputGrid, z_tolerance, periodic_extension, turn_normals); double perm_threshold_md = param.getDefault("perm_threshold_md", 0.0); double perm_threshold = Opm::unit::convert::from(perm_threshold_md, Opm::prefix::milli*Opm::unit::darcy); rock_.init(deck, grid_.globalCell(), perm_threshold); diff --git a/opm/porsol/common/setupGridAndProps.hpp b/opm/porsol/common/setupGridAndProps.hpp index 14fff0c..5ba082e 100644 --- a/opm/porsol/common/setupGridAndProps.hpp +++ b/opm/porsol/common/setupGridAndProps.hpp @@ -43,6 +43,7 @@ #include #include #include +#include #include @@ -90,7 +91,10 @@ namespace Opm } bool periodic_extension = param.getDefault("periodic_extension", false); bool turn_normals = param.getDefault("turn_normals", false); - grid.processEclipseFormat(deck, periodic_extension, turn_normals); + { + std::shared_ptr state = std::make_shared(deck , parseContext); + grid.processEclipseFormat(state->getInputGrid(), periodic_extension, turn_normals); + } // Save EGRID file in case we are writing ECL output. if (param.getDefault("output_ecl", false)) { OPM_THROW(std::runtime_error, "Saving to EGRID files is not yet implemented"); @@ -157,8 +161,10 @@ namespace Opm Dune::CpGrid& grid, ResProp<3>& res_prop) { - grid.processEclipseFormat(deck, periodic_extension, turn_normals, clip_z); + Opm::ParseContext parseContext; + std::shared_ptr state = std::make_shared(deck , parseContext); const std::string* rl_ptr = (rock_list == "no_list") ? 0 : &rock_list; + grid.processEclipseFormat(state->getInputGrid(), periodic_extension, turn_normals, clip_z); res_prop.init(deck, grid.globalCell(), perm_threshold, rl_ptr, use_jfunction_scaling, sigma, theta); if (unique_bids) { grid.setUniqueBoundaryIds(true); diff --git a/opm/upscaling/initCPGrid.cpp b/opm/upscaling/initCPGrid.cpp new file mode 100644 index 0000000..5f4ec76 --- /dev/null +++ b/opm/upscaling/initCPGrid.cpp @@ -0,0 +1,79 @@ +/* + Copyright 2016 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 "config.h" +#include +#include + +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2,3) +#include +#else +#include +#endif + +#include + +#include + +#include +#include +#include + +#include + +#include + +#include + + +void Opm::initCPGrid(Dune::CpGrid& grid, const Opm::parameter::ParameterGroup& param) { + std::string fileformat = param.get("fileformat"); + if (fileformat == "sintef_legacy") { + std::string grid_prefix = param.get("grid_prefix"); + grid.readSintefLegacyFormat(grid_prefix); + } else if (fileformat == "eclipse") { + std::string filename = param.get("filename"); + if (param.has("z_tolerance")) { + std::cerr << "****** Warning: z_tolerance parameter is obsolete, use PINCH in deck input instead\n"; + } + bool periodic_extension = param.getDefault("periodic_extension", false); + bool turn_normals = param.getDefault("turn_normals", false); + Opm::ParserPtr parser(new Opm::Parser()); + Opm::ParseContext parseContext; + Opm::DeckConstPtr deck = parser->parseFile(filename, parseContext); + std::shared_ptr inputGrid = std::make_shared(deck, nullptr); + grid.processEclipseFormat(inputGrid, periodic_extension , turn_normals ); + } else if (fileformat == "cartesian") { + std::array dims = {{ param.getDefault("nx", 1), + param.getDefault("ny", 1), + param.getDefault("nz", 1) }}; + std::array cellsz = {{ param.getDefault("dx", 1.0), + param.getDefault("dy", 1.0), + param.getDefault("dz", 1.0) }}; + grid.createCartesian(dims, cellsz); + } else { + OPM_THROW(std::runtime_error, "Unknown file format string: " << fileformat); + } +} + diff --git a/opm/upscaling/initCPGrid.hpp b/opm/upscaling/initCPGrid.hpp new file mode 100644 index 0000000..3969528 --- /dev/null +++ b/opm/upscaling/initCPGrid.hpp @@ -0,0 +1,31 @@ +/* + Copyright 2016 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 INIT_CPGRID_HPP +#define INIT_CPGRID_HPP + +#include +#include + +namespace Opm { + + void initCPGrid(Dune::CpGrid& grid, const parameter::ParameterGroup& param); + +} +#endif