From 4526cce41b648207238d5f8949254a85b1010f88 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Mon, 12 Oct 2015 15:13:42 +0200 Subject: [PATCH 1/3] Setup a distributed material law manager and copy values. Since the refactoring to using opm-material a material law manager for the global grid was used. This meant that the properties used for elements of the local grid were wrong. With this commit we set up a manager that is based on the local grid only. --- examples/flow.cpp | 2 +- opm/autodiff/BlackoilPropsAdFromDeck.cpp | 3 ++- opm/autodiff/BlackoilPropsAdFromDeck.hpp | 5 +++- opm/autodiff/RedistributeDataHandles.hpp | 29 ++++++++++++++++++++++-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/examples/flow.cpp b/examples/flow.cpp index 971014e2e..ee2e3e8cc 100644 --- a/examples/flow.cpp +++ b/examples/flow.cpp @@ -364,7 +364,7 @@ try // and initilialize new properties and states for it. if( mpi_size > 1 ) { - Opm::distributeGridAndData( grid, eclipseState, state, new_props, geoprops, parallel_information, use_local_perm ); + Opm::distributeGridAndData( grid, deck, eclipseState, state, new_props, geoprops, materialLawManager, parallel_information, use_local_perm ); } // create output writer after grid is distributed, otherwise the parallel output diff --git a/opm/autodiff/BlackoilPropsAdFromDeck.cpp b/opm/autodiff/BlackoilPropsAdFromDeck.cpp index 15ab005ce..718ff4d12 100644 --- a/opm/autodiff/BlackoilPropsAdFromDeck.cpp +++ b/opm/autodiff/BlackoilPropsAdFromDeck.cpp @@ -118,6 +118,7 @@ namespace Opm /// Constructor for properties on a subgrid BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck(const BlackoilPropsAdFromDeck& props, + std::shared_ptr materialLawManager, const int number_of_cells) : rock_(number_of_cells) { @@ -129,7 +130,7 @@ BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck(const BlackoilPropsAdFromDeck& OPM_THROW(std::runtime_error, "The number of cells is has to be larger than 0."); } - materialLawManager_ = props.materialLawManager_; + materialLawManager_ = materialLawManager; // Copy properties that do not depend on the postion within the grid. satprops_ = props.satprops_; diff --git a/opm/autodiff/BlackoilPropsAdFromDeck.hpp b/opm/autodiff/BlackoilPropsAdFromDeck.hpp index bd44f52ad..dd412036f 100644 --- a/opm/autodiff/BlackoilPropsAdFromDeck.hpp +++ b/opm/autodiff/BlackoilPropsAdFromDeck.hpp @@ -138,8 +138,11 @@ namespace Opm /// the correct size but the values will be undefined. /// /// \param props The property object to copy from. - /// \paramm number_of_cells The number of cells of the subgrid. + /// \param materialLawManager The container for the material law parameter objects. + /// Initialized only for the subgrid + /// \param number_of_cells The number of cells of the subgrid. BlackoilPropsAdFromDeck(const BlackoilPropsAdFromDeck& props, + std::shared_ptr materialLawManager, const int number_of_cells); diff --git a/opm/autodiff/RedistributeDataHandles.hpp b/opm/autodiff/RedistributeDataHandles.hpp index 353e7899d..0e3ba6146 100644 --- a/opm/autodiff/RedistributeDataHandles.hpp +++ b/opm/autodiff/RedistributeDataHandles.hpp @@ -34,10 +34,12 @@ namespace Opm template inline void distributeGridAndData( Grid& , + Opm::DeckConstPtr deck , EclipseStateConstPtr , BlackoilState& , BlackoilPropsAdFromDeck& , DerivedGeology&, + std::shared_ptr&, boost::any& , const bool ) { @@ -327,10 +329,12 @@ private: inline void distributeGridAndData( Dune::CpGrid& grid, + Opm::DeckConstPtr deck, EclipseStateConstPtr eclipseState, BlackoilState& state, BlackoilPropsAdFromDeck& properties, DerivedGeology& geology, + std::shared_ptr& material_law_manager, boost::any& parallelInformation, const bool useLocalPerm) { @@ -342,8 +346,29 @@ void distributeGridAndData( Dune::CpGrid& grid, // distribute the grid and switch to the distributed view grid.loadBalance(eclipseState); grid.switchToDistributedView(); + std::vector compressedToCartesianIdx; + Opm::createGlobalCellArray(grid, compressedToCartesianIdx); + typedef BlackoilPropsAdFromDeck::MaterialLawManager MaterialLawManager; + auto distributed_material_law_manager = std::make_shared(); + distributed_material_law_manager->initFromDeck(deck, eclipseState, compressedToCartesianIdx); + // copy the values from the global to the local MaterialLawManager + // We should actually communicate these to be future proof. But that is + // really, really cumbersome for the underlying vector + // where the classes pointed to even have more shared_ptr stored in them. + typedef Dune::CpGrid::ParallelIndexSet IndexSet; + typedef IndexSet::IndexPair Pair; + const IndexSet& local_indices = grid.getCellIndexSet(); + for(auto index : local_indices) + { + distributed_material_law_manager->materialLawParamsPointer(index.local()) = + material_law_manager->materialLawParamsPointer(index.global()); - BlackoilPropsAdFromDeck distributed_props(properties, grid.numCells()); + distributed_material_law_manager->oilWaterScaledEpsInfoDrainagePointer(index.local()) = + material_law_manager->oilWaterScaledEpsInfoDrainagePointer(index.global()); + } + BlackoilPropsAdFromDeck distributed_props(properties, + distributed_material_law_manager, + grid.numCells()); distributed_state.init(grid.numCells(), grid.numFaces(), state.numPhases()); // init does not resize surfacevol. Do it manually. distributed_state.surfacevol().resize(grid.numCells()*state.numPhases(), @@ -367,7 +392,7 @@ void distributeGridAndData( Dune::CpGrid& grid, properties = distributed_props; geology = distributed_geology; state = distributed_state; - + material_law_manager = distributed_material_law_manager; extractParallelGridInformationToISTL(grid, parallelInformation); } #endif From 134b47a5e24619d70ef70ee9bc11ec93f02849ce Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Tue, 27 Oct 2015 00:43:43 +0100 Subject: [PATCH 2/3] Fixes SaturationPropsFromDeck handling during redistribution. It needs a material law manager that works on the processes local grid partition. Therfore copying the one from the global representation does not work. Instead we now create an new SaturationPropsFromDeck and initialize it with the local material law manager. --- opm/autodiff/BlackoilPropsAdFromDeck.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opm/autodiff/BlackoilPropsAdFromDeck.cpp b/opm/autodiff/BlackoilPropsAdFromDeck.cpp index 718ff4d12..3134b651f 100644 --- a/opm/autodiff/BlackoilPropsAdFromDeck.cpp +++ b/opm/autodiff/BlackoilPropsAdFromDeck.cpp @@ -120,7 +120,7 @@ namespace Opm BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck(const BlackoilPropsAdFromDeck& props, std::shared_ptr materialLawManager, const int number_of_cells) - : rock_(number_of_cells) + : rock_(number_of_cells), satprops_(new SaturationPropsFromDeck()) { const int original_size = props.cellPvtRegionIdx_.size(); if (number_of_cells > original_size) { @@ -133,7 +133,6 @@ BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck(const BlackoilPropsAdFromDeck& materialLawManager_ = materialLawManager; // Copy properties that do not depend on the postion within the grid. - satprops_ = props.satprops_; phase_usage_ = props.phase_usage_; props_ = props.props_; densities_ = props.densities_; @@ -143,6 +142,7 @@ BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck(const BlackoilPropsAdFromDeck& // For data that is dependant on the subgrid we simply allocate space // and initialize with obviously bogus numbers. cellPvtRegionIdx_.resize(number_of_cells, std::numeric_limits::min()); + satprops_->init(phase_usage_, materialLawManager_); } /// Initializes the properties. From f167d321aad1bae99428beca55227be18952daf4 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Wed, 28 Oct 2015 16:33:58 +0100 Subject: [PATCH 3/3] Added some spaces around parenthesis. --- opm/autodiff/RedistributeDataHandles.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/autodiff/RedistributeDataHandles.hpp b/opm/autodiff/RedistributeDataHandles.hpp index 0e3ba6146..3a7b94f29 100644 --- a/opm/autodiff/RedistributeDataHandles.hpp +++ b/opm/autodiff/RedistributeDataHandles.hpp @@ -358,7 +358,7 @@ void distributeGridAndData( Dune::CpGrid& grid, typedef Dune::CpGrid::ParallelIndexSet IndexSet; typedef IndexSet::IndexPair Pair; const IndexSet& local_indices = grid.getCellIndexSet(); - for(auto index : local_indices) + for ( auto index : local_indices ) { distributed_material_law_manager->materialLawParamsPointer(index.local()) = material_law_manager->materialLawParamsPointer(index.global());