Skip to content
Snippets Groups Projects
Commit 6831d9ef authored by Robert K's avatar Robert K
Browse files

[cleanup] Remove output stream overloading.

parent 833f0216
No related branches found
No related tags found
No related merge requests found
#ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH #ifndef DUNE_ALUGRIDGEOMETRYSTORAGE_HH
#define DUNE_ALUGRIDGEOMETRYSTORAGE_HH #define DUNE_ALUGRIDGEOMETRYSTORAGE_HH
#include <array>
#include <dune/common/exceptions.hh> #include <dune/common/exceptions.hh>
#include <dune/grid/common/grid.hh> #include <dune/grid/common/grid.hh>
...@@ -17,7 +19,7 @@ namespace Dune ...@@ -17,7 +19,7 @@ namespace Dune
typedef ALULocalGeometryStorage< GridImp, GeometryImpl, nChild > ThisType; typedef ALULocalGeometryStorage< GridImp, GeometryImpl, nChild > ThisType;
// array with pointers to the geometries // array with pointers to the geometries
Dune::array< GeometryImpl *, nChild > geoms_; std::array< GeometryImpl*, nChild > geoms_;
// count local geometry creation // count local geometry creation
int count_; int count_;
...@@ -153,7 +155,7 @@ namespace Dune ...@@ -153,7 +155,7 @@ namespace Dune
: count_( 0 ), initialized_( false ) : count_( 0 ), initialized_( false )
{ {
// nullify geometries // nullify geometries
geoms_.fill( (GeometryImpl *) 0 ); geoms_.fill( nullptr );
// initialize geometries // initialize geometries
initialize( type, nonConform ); initialize( type, nonConform );
...@@ -164,7 +166,7 @@ namespace Dune ...@@ -164,7 +166,7 @@ namespace Dune
: count_( 0 ), initialized_( false ) : count_( 0 ), initialized_( false )
{ {
// nullify geometries // nullify geometries
geoms_.fill( (GeometryImpl *) 0 ); geoms_.fill( nullptr );
} }
// desctructor deleteing geometries // desctructor deleteing geometries
...@@ -179,17 +181,14 @@ namespace Dune ...@@ -179,17 +181,14 @@ namespace Dune
{ {
alugrid_assert ( geomCreated(child) ); alugrid_assert ( geomCreated(child) );
// this method is not thread safe yet // this method is not thread safe yet
assert( GridImp :: thread() == 0 );
return *(geoms_[child]); return *(geoms_[child]);
} }
//! access local geometries //! access local geometries
static const GeometryImpl& geom( const GeometryType type, const bool nonConforming, const int child ) static const GeometryImpl& geom( const GeometryType type, const bool nonConforming, const int child )
{ {
// this method is not thread safe yet // create static variable for this thread
assert( GridImp :: thread() == 0 ); static thread_local ThisType instance( type, nonConforming );
// create static variable on heap
static ThisType instance( type, nonConforming );
// make sure the geometry type is the same // make sure the geometry type is the same
alugrid_assert ( type == instance[ child ].type() ); alugrid_assert ( type == instance[ child ].type() );
return instance[ child ]; return instance[ child ];
...@@ -200,8 +199,8 @@ namespace Dune ...@@ -200,8 +199,8 @@ namespace Dune
{ {
if( type.isSimplex() ) if( type.isSimplex() )
{ {
// create static variable on heap // create static variable for this thread
static ThisType simplexGeoms; static thread_local ThisType simplexGeoms;
// initialize (only done once), note that this is called recursively during initialize // initialize (only done once), note that this is called recursively during initialize
// so only check geoms when they were actually really created // so only check geoms when they were actually really created
if( simplexGeoms.initialize( type, nonConforming ) ) if( simplexGeoms.initialize( type, nonConforming ) )
...@@ -216,8 +215,8 @@ namespace Dune ...@@ -216,8 +215,8 @@ namespace Dune
// should be a cube geometry a this point // should be a cube geometry a this point
alugrid_assert( type.isCube() ); alugrid_assert( type.isCube() );
// create static variable on heap // create static variable
static ThisType cubeGeoms; static thread_local ThisType cubeGeoms;
// initialize (only done once), note that this is called recursively during initialize // initialize (only done once), note that this is called recursively during initialize
// so only check geoms when they were actually really created // so only check geoms when they were actually really created
if( cubeGeoms.initialize( type, nonConforming ) ) if( cubeGeoms.initialize( type, nonConforming ) )
...@@ -254,11 +253,11 @@ namespace Dune ...@@ -254,11 +253,11 @@ namespace Dune
template < class Grid > template < class Grid >
void createGeometries(const GeometryType& type) void createGeometries(const GeometryType& type)
{ {
static thread_local bool firstCall = true ;
static bool firstCall = true ;
if( firstCall ) if( firstCall )
{ {
firstCall = false ; firstCall = false ;
// create factory without verbosity // create factory without verbosity
GridFactory< Grid > factory( false ); GridFactory< Grid > factory( false );
...@@ -284,26 +283,26 @@ namespace Dune ...@@ -284,26 +283,26 @@ namespace Dune
factory.insertElement(type, vertices); factory.insertElement(type, vertices);
// save original sbuf // save original sbuf
std::streambuf* cerr_sbuf = std::cerr.rdbuf(); //std::streambuf* cerr_sbuf = std::cerr.rdbuf();
std::stringstream tempout; //std::stringstream tempout;
// redirect 'cerr' to a 'fout' to avoid unnecessary output in constructors // redirect 'cerr' to a 'fout' to avoid unnecessary output in constructors
std::cerr.rdbuf(tempout.rdbuf()); //std::cerr.rdbuf(tempout.rdbuf());
Grid* gridPtr = factory.createGrid(); Grid* gridPtr = factory.createGrid();
Grid& grid = *gridPtr; Grid& grid = *gridPtr;
// restore the original stream buffer // restore the original stream buffer
std::cerr.rdbuf(cerr_sbuf); //std::cerr.rdbuf(cerr_sbuf);
//std::cerr = savecerr; //std::cerr = savecerr;
// refine once to get children // refine once to get children in the reference element
const int level = 1; const int level = 1;
grid.globalRefine( level ); grid.globalRefine( level );
{ {
typedef typename Grid :: template Partition< All_Partition >:: LevelGridView MacroGridView; typedef typename Grid :: MacroGridView MacroGridView;
MacroGridView macroView = grid.template levelView< All_Partition > ( 0 ); MacroGridView macroView = grid.template macroGridView< All_Partition > ();
typedef typename MacroGridView :: template Codim< 0 > :: Iterator Iterator; typedef typename MacroGridView :: template Codim< 0 > :: Iterator Iterator;
Iterator it = macroView.template begin<0> (); Iterator it = macroView.template begin<0> ();
...@@ -329,7 +328,6 @@ namespace Dune ...@@ -329,7 +328,6 @@ namespace Dune
// delete grid // delete grid
delete gridPtr; delete gridPtr;
} }
} }
// create local geometry // create local geometry
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment