// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- // vi: set et ts=4 sw=4 sts=4: /* 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 2 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 . Consult the COPYING file in the top-level source directory of this module for the precise wording of the license and the list of copyright holders. */ #ifndef EWOMS_ALU_CARTESIANINDEXMAPPER_HH #define EWOMS_ALU_CARTESIANINDEXMAPPER_HH #include #include #include #include #include #include #include #include #include namespace Ewoms { /** \brief Interface class to access the logical Cartesian grid as used in industry standard simulator decks. */ template< class Grid > class AluCartesianIndexMapper { public: // data handle for communicating global ids during load balance and communication template class GlobalIndexDataHandle : public Dune::CommDataHandleIF< GlobalIndexDataHandle, int > { // global id class GlobalCellIndex { int idx_; public: GlobalCellIndex() : idx_(-1) {} GlobalCellIndex& operator= ( const int index ) { idx_ = index; return *this; } int index() const { return idx_; } }; typedef typename Dune::PersistentContainer< Grid, GlobalCellIndex > GlobalIndexContainer; GridView gridView_; GlobalIndexContainer globalIndex_; std::vector& cartesianIndex_; public: // constructor copying cartesian index to persistent container GlobalIndexDataHandle( const GridView& gridView, std::vector& cartesianIndex ) : gridView_( gridView ), globalIndex_( gridView.grid(), 0 ), cartesianIndex_( cartesianIndex ) { globalIndex_.resize(); initialize(); } // constructor copying cartesian index to persistent container GlobalIndexDataHandle( const GlobalIndexDataHandle& other ) = delete ; // destrcutor writing load balanced cartesian index back to vector ~GlobalIndexDataHandle() { finalize(); //std::cout << "CartesianIndex " << cartesianIndex_.size() << std::endl; //for( size_t i=0; i std::unique_ptr< GlobalIndexDataHandle< GridView > > dataHandle( const GridView& gridView ) { typedef GlobalIndexDataHandle< GridView > DataHandle ; assert( &grid_ == &gridView.grid() ); return std::unique_ptr< DataHandle > (new DataHandle( gridView, cartesianIndex_ )); } protected: int computeCartesianSize() const { int size = cartesianDimensions()[ 0 ]; for( int d=1; d cartesianDimensions_; std::vector cartesianIndex_; const int cartesianSize_ ; }; } // end namespace Opm #endif