diff --git a/src/core/Set.h b/src/core/Set.h index b7587439c000204efde7b54404a2e2f532bac187..4eb4a96df4c253406d0c272a9852a417b09228fb 100644 --- a/src/core/Set.h +++ b/src/core/Set.h @@ -1,15 +1,15 @@ //====================================================================================================================== // -// This file is part of waLBerla. waLBerla is free software: you can +// This file is part of waLBerla. waLBerla 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 +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// waLBerla 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 +// +// waLBerla 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 waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -145,7 +145,7 @@ public: inline const_iterator end() const { return set_.end(); } inline iterator end() { return set_.end(); } - + inline const std::set<T> & get() const { return set_; } inline std::set<T> & get() { return set_; } @@ -283,6 +283,68 @@ inline std::ostream& operator<<( std::ostream& os, const Set<T>& set ) { return os; } +template< typename T > +inline std::istream& operator>>( std::istream& is, Set<T>& set ) { + + if( !is ) return is; + + const std::istream::pos_type pos( is.tellg() ); + const std::istream::fmtflags oldFlags( is.flags() ); + + is >> std::skipws; + + char character; + if( !( is >> character ) || character != '{' ) + { + is.clear(); + is.seekg( pos ); + is.setstate( std::istream::failbit ); + is.flags( oldFlags ); + return is; + } + + T x; // temporary set item + + do { + + // read set item + if( !( is >> x ) ) + { + is.clear(); + is.seekg( pos ); + is.setstate( std::istream::failbit ); + is.flags( oldFlags ); + return is; + } + + // insert set item + set.insert( x ); + + // read comma + if( !( is >> character ) ) + { + is.clear(); + is.seekg( pos ); + is.setstate( std::istream::failbit ); + is.flags( oldFlags ); + return is; + } + + } while( character == ',' ); + + if( character != '}' ) + { + is.clear(); + is.seekg( pos ); + is.setstate( std::istream::failbit ); + is.flags( oldFlags ); + return is; + } + + is.flags( oldFlags ); + return is; +} + /// \cond internal namespace set { diff --git a/src/core/cell/CellSet.h b/src/core/cell/CellSet.h index 09696492c422a4ed8d521031caea2f76064af44e..49c619926f235db39750379ba32386ada4f07e52 100644 --- a/src/core/cell/CellSet.h +++ b/src/core/cell/CellSet.h @@ -1,15 +1,15 @@ //====================================================================================================================== // -// This file is part of waLBerla. waLBerla is free software: you can +// This file is part of waLBerla. waLBerla 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 +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// waLBerla 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 +// +// waLBerla 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 waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -50,6 +50,11 @@ public: Set<Cell>::insert( *cell ); } + CellSet( const CellInterval& cells ) { + for( CellInterval::const_iterator cell = cells.begin(); cell != cells.end(); ++cell ) + Set<Cell>::insert( *cell ); + } + using Set<Cell>::insert; void insert( const cell_idx_t x, const cell_idx_t y, const cell_idx_t z ) { Set<Cell>::insert( Cell(x,y,z) ); } @@ -64,9 +69,36 @@ public: void pushToCellVector( CellVector& cellVector ) const { for( auto cell = begin(); cell != end(); ++cell ) cellVector.push_back( *cell ); } + inline CellSet & shift( const cell_idx_t x, const cell_idx_t y, const cell_idx_t z ); ///< diagonal shift + inline CellSet & shift( const uint_t x, const uint_t y, const uint_t z ); ///< diagonal shift + inline CellSet & shift( const Cell & offset ); + }; // class CellSet +inline CellSet & CellSet::shift( const cell_idx_t x, const cell_idx_t y, const cell_idx_t z ) +{ + return shift( Cell( x, y, z ) ); +} + +inline CellSet & CellSet::shift( const uint_t x, const uint_t y, const uint_t z ) +{ + WALBERLA_ASSERT_GREATER_EQUAL( cell_idx_c(x), 0 ); + WALBERLA_ASSERT_GREATER_EQUAL( cell_idx_c(y), 0 ); + WALBERLA_ASSERT_GREATER_EQUAL( cell_idx_c(z), 0 ); + + return shift( Cell( x, y, z ) ); +} + +inline CellSet & CellSet::shift( const Cell & offset ) +{ + for( auto cell : *this ) + cell += offset; + + return *this; +} + + //====================================================================================================================== // diff --git a/src/core/config/Config.h b/src/core/config/Config.h index d83f9baa1922c43c4cfa8fe39c8f47146a9e80bd..1d2a286a4701aeecb8dd535699015f08526692a8 100644 --- a/src/core/config/Config.h +++ b/src/core/config/Config.h @@ -943,7 +943,6 @@ inline Config::Parameter<bool> Config::Block::getParameter<bool>( std::string ke //********************************************************************************************************************** - //********************************************************************************************************************** /*!\fn Config::Parameter<unsigned int> Config::Block::getParameter<unsigned int>( std::string key ) const // \brief Returns an extracted unsigned integer parameter. @@ -968,6 +967,30 @@ inline Config::Parameter<unsigned int> Config::Block::getParameter<unsigned int> //********************************************************************************************************************** +//********************************************************************************************************************** +/*!\fn Config::Parameter<unsigned char> Config::Block::getParameter<unsigned char>( std::string key ) const +// \brief Returns an extracted unsigned char parameter. +// +// \param key The key of the unsigned char parameter. +// \return The extracted unsigned char parameter. + */ +template<> +inline Config::Parameter<unsigned char> Config::Block::getParameter<unsigned char>( std::string key ) const +{ + Map::const_iterator it = params_.find( key ); + + if( it != params_.end() ) { + int tmp; + std::istringstream iss( it->second ); + if( !(iss >> tmp) || tmp < 0 ) + return Parameter<unsigned char>( 0, badcast, key ); + else return Parameter<unsigned char>( static_cast<unsigned char>( tmp ), noerror, key ); + } + else return Parameter<unsigned char>( 0, undefined, key ); +} +//********************************************************************************************************************** + + //********************************************************************************************************************** /*!\fn bool Config::Block::setParameter( const std::string& key, const std::string& value ) // \brief Sets a given parameter to a given value.