diff --git a/dune/alugrid/src/duneinterface/gitter_dune_impl.cc b/dune/alugrid/src/duneinterface/gitter_dune_impl.cc index b77533cc1e7307e8596cfd9191e097ef42b5d94e..7795f4e30487245f444163ff4bbb79caa1e47318 100644 --- a/dune/alugrid/src/duneinterface/gitter_dune_impl.cc +++ b/dune/alugrid/src/duneinterface/gitter_dune_impl.cc @@ -2,112 +2,98 @@ #ifndef GITTER_DUNE_IMPL_CC_INCLUDED #define GITTER_DUNE_IMPL_CC_INCLUDED +#include <fstream> + #include "gitter_dune_impl.h" -IteratorSTI < Gitter :: helement_STI > * GitterDuneImpl :: +IteratorSTI < Gitter::helement_STI > * GitterDuneImpl:: leafIterator (const helement_STI *) { - return new Insert < PureElementAccessIterator < Gitter :: helement_STI > :: Handle, - TreeIterator < Gitter :: helement_STI, is_leaf < Gitter :: helement_STI> > > (container ()) ; + return new Insert < PureElementAccessIterator < Gitter::helement_STI >::Handle, + TreeIterator < Gitter::helement_STI, is_leaf < Gitter::helement_STI> > > (container ()); } -IteratorSTI < Gitter :: helement_STI > * GitterDuneImpl :: +IteratorSTI < Gitter::helement_STI > * GitterDuneImpl:: leafIterator (const IteratorSTI < helement_STI > * p) { - return new Insert < PureElementAccessIterator < Gitter :: helement_STI > :: Handle, - TreeIterator < Gitter :: helement_STI, is_leaf < Gitter :: helement_STI> > > - (*(const Insert < PureElementAccessIterator < Gitter :: helement_STI > :: Handle, - TreeIterator < Gitter :: helement_STI, is_leaf < Gitter :: helement_STI> > > *) p) ; + return new Insert < PureElementAccessIterator < Gitter::helement_STI >::Handle, + TreeIterator < Gitter::helement_STI, is_leaf < Gitter::helement_STI> > > + (*(const Insert < PureElementAccessIterator < Gitter::helement_STI >::Handle, + TreeIterator < Gitter::helement_STI, is_leaf < Gitter::helement_STI> > > *) p); } // wird von Dune verwendet -void GitterDuneBasis :: duneBackup (const char * fileName) +void GitterDuneBasis::duneBackup (const char * fileName) { // diese Methode wird von der Dune Schnittstelle aufgerufen und ruft // intern lediglich backup (siehe oben) und backupCMode des Makrogitters // auf, allerdings wird hier der path und filename in einer variablen // uebergeben - assert (debugOption (20) ? (cout << "**INFO GitterDuneBasis :: duneBackup (const char * = \"" - << fileName << "\") " << endl, 1) : 1) ; + assert (debugOption (20) ? (cout << "**INFO GitterDuneBasis::duneBackup (const char * = \"" + << fileName << "\") " << std::endl, 1) : 1); - ofstream out (fileName) ; - if (!out) { - cerr << "**WARNUNG (IGNORIERT) GitterDuneBasis :: duneBackup (const char *, double) Fehler beim Anlegen von < " - << (fileName ? fileName : "null") << " >" << endl ; + std::ofstream out( fileName ); + if( !out ) + { + std::cerr << "WARNING (ignored): Error creating '" << (fileName ? fileName : "") << "' in GitterDuneBasis::duneBackup( const char *, double )." << std::endl; } else { - Gitter :: backup (out) ; + Gitter::backup (out); - backupIndices ( out ) ; + backupIndices ( out ); { - char *fullName = new char[strlen(fileName)+20]; - if(!fullName) - { - cerr << "**WARNUNG GitterDuneBasis :: duneBackup (, const char *, double) :"; - cerr << "couldn't allocate fullName! " << endl; - abort(); - } - sprintf(fullName,"%s.macro",fileName); - ofstream macro (fullName) ; - - if(!macro) - { - cerr << "**WARNUNG (IGNORIERT) GitterDuneBasis :: duneBackup (const char *, const char *) Fehler beim Anlegen von < " - << (fullName ? fullName : "null") << " >" << endl ; - } + std::string fullName = std::string( fileName ) + std::string( ".macro" ); + std::ofstream macro( fullName.c_str() ); + if( !macro ) + std::cerr << "WARNING (ignored): Cannot create '" << fullName << "' in GitterDuneBasis::duneBackup( const char *, const char * )." << std::endl; else - { - container ().backupCMode (macro) ; - } - delete [] fullName; + container ().backupCMode( macro ); } } - return ; } // wird von Dune verwendet -void GitterDuneBasis :: duneRestore (const char * fileName) +void GitterDuneBasis::duneRestore (const char * fileName) { // diese Methode wird von der Dune Schnittstelle aufgerufen // diese Methode ruft intern restore auf, hier wird lediglich // der path und filename in einer variablen uebergeben - assert (debugOption (20) ? (cout << "**INFO GitterDuneBasis :: duneRestore (const char * = \"" - << fileName << "\") " << endl, 1) : 1) ; + assert (debugOption (20) ? (cout << "**INFO GitterDuneBasis::duneRestore (const char * = \"" + << fileName << "\") " << std::endl, 1) : 1); - ifstream in (fileName) ; - if (!in) { - cerr << "**WARNUNG (IGNORIERT) GitterDuneBasis :: duneRestore (const char *, double & ) Fehler beim \"Offnen von < " - << (fileName ? fileName : "null") << " > " << endl ; - } else { - Gitter :: restore (in) ; - this->restoreIndices (in); + std::ifstream in( fileName ); + if( !in ) + std::cerr << "WARNING (ignored): Cannot open '" << (fileName ? fileName : "") << "' in GitterDuneBasis::duneRestore( const char *, double & )." << std::endl; + else + { + Gitter::restore( in ); + this->restoreIndices( in ); } - return ; } -int GitterDuneBasis :: preCoarsening (Gitter::helement_STI & elem) +int GitterDuneBasis::preCoarsening (Gitter::helement_STI & elem) { // if _arp is set then the extrenal preCoarsening is called return (_arp) ? (*_arp).preCoarsening(elem) : 0; } -int GitterDuneBasis :: postRefinement (Gitter::helement_STI & elem) +int GitterDuneBasis::postRefinement (Gitter::helement_STI & elem) { // if _arp is set then the extrenal postRefinement is called return (_arp) ? (*_arp).postRefinement(elem) : 0; } -int GitterDuneBasis :: preCoarsening (Gitter::hbndseg_STI & bnd) +int GitterDuneBasis::preCoarsening (Gitter::hbndseg_STI & bnd) { // if _arp is set then the extrenal preCoarsening is called return (_arp) ? (*_arp).preCoarsening( bnd ) : 0; } -int GitterDuneBasis :: postRefinement (Gitter::hbndseg_STI & bnd) +int GitterDuneBasis::postRefinement (Gitter::hbndseg_STI & bnd) { // if _arp is set then the extrenal postRefinement is called return (_arp) ? (*_arp).postRefinement( bnd ) : 0; @@ -116,21 +102,19 @@ int GitterDuneBasis :: postRefinement (Gitter::hbndseg_STI & bnd) void GitterDuneBasis :: setAdaptRestrictProlongOp( AdaptRestrictProlongType & arp ) { - if(_arp) - { - cerr<< "WARNING: GitterDuneBasis :: setAdaptRestrictProlongOp: _arp not NULL! in:" << __FILE__ << " line="<<__LINE__ << endl; - } + if( _arp ) + std::cerr << "WARNING (ignored): _arp not null in GitterDuneBasis::setAdaptRestrictProlongOp." << std::endl; _arp = &arp; } -void GitterDuneBasis :: removeAdaptRestrictProlongOp() +void GitterDuneBasis::removeAdaptRestrictProlongOp() { _arp = 0; } -bool GitterDuneBasis :: duneAdapt (AdaptRestrictProlongType & arp) +bool GitterDuneBasis::duneAdapt (AdaptRestrictProlongType & arp) { - assert (debugOption (20) ? (cout << "**INFO GitterDuneBasis :: duneAdapt ()" << endl, 1) : 1) ; + assert (debugOption (20) ? (cout << "**INFO GitterDuneBasis::duneAdapt ()" << std::endl, 1) : 1); // set restriction-prolongation callback obj setAdaptRestrictProlongOp(arp); // call adapt method @@ -139,4 +123,4 @@ bool GitterDuneBasis :: duneAdapt (AdaptRestrictProlongType & arp) removeAdaptRestrictProlongOp (); return refined; } -#endif +#endif // #ifndef GITTER_DUNE_IMPL_CC_INCLUDED diff --git a/dune/alugrid/src/duneinterface/gitter_dune_impl.h b/dune/alugrid/src/duneinterface/gitter_dune_impl.h index 4388c8214fbbd22e979d7b5e8363a4c73e15b20b..983d8c83bc055f75c9699c408cc1318bda27c709 100644 --- a/dune/alugrid/src/duneinterface/gitter_dune_impl.h +++ b/dune/alugrid/src/duneinterface/gitter_dune_impl.h @@ -1,34 +1,37 @@ #ifndef GITTER_DUNE_IMPL_H_INCLUDED #define GITTER_DUNE_IMPL_H_INCLUDED +#include <iomanip> +#include <sstream> + #include "../serial/gitter_impl.h" #include "../serial/lock.h" template < class A > class PureElementAccessIterator : public AccessIterator <A> { public : - Refcount ref ; - virtual IteratorSTI < A > * pureElementIterator (const A *) const = 0 ; - virtual IteratorSTI < A > * pureElementIterator (const IteratorSTI < A > *) const = 0 ; + Refcount ref; + virtual IteratorSTI < A > * pureElementIterator (const A *) const = 0; + virtual IteratorSTI < A > * pureElementIterator (const IteratorSTI < A > *) const = 0; public : // the only difference to AccessIterator is, that in the Constructors of this class // the method pureElementIterator is called instead of iterator, which gives an iterator // that doesn't iterator over periodic elements - class Handle : public AccessIterator <A> :: Handle { + class Handle : public AccessIterator <A>::Handle { // type of handle - typedef typename PureElementAccessIterator < A > :: Handle ThisType; + typedef typename PureElementAccessIterator < A >::Handle ThisType; public : - inline Handle (AccessIterator < A > &) ; - inline Handle (const ThisType &) ; + inline Handle (AccessIterator < A > &); + inline Handle (const ThisType &); inline Handle (); - } ; + }; protected : PureElementAccessIterator () {} - virtual ~PureElementAccessIterator () { assert (!ref) ; } -} ; + virtual ~PureElementAccessIterator () { assert (!ref); } +}; template < class A > class PureElementLeafIterator; @@ -54,10 +57,10 @@ protected: // maxlevel of the grid int maxlevel_; - friend class PureElementLeafIterator < Gitter :: helement_STI >; + friend class PureElementLeafIterator < Gitter::helement_STI >; // return leafIterator using pureElement Iterators - virtual IteratorSTI < Gitter :: helement_STI > * leafIterator (const Gitter :: helement_STI *) = 0 ; - virtual IteratorSTI < Gitter :: helement_STI > * leafIterator (const IteratorSTI < Gitter :: helement_STI > *) = 0 ; + virtual IteratorSTI < Gitter::helement_STI > * leafIterator (const Gitter::helement_STI *) = 0; + virtual IteratorSTI < Gitter::helement_STI > * leafIterator (const IteratorSTI < Gitter::helement_STI > *) = 0; public: GitterDuneBasis() : _arp(0), maxlevel_(0) {} @@ -69,16 +72,16 @@ public: void restoreIndices (istream_t & in ); // write status of grid - void duneBackup (const char*) ; + void duneBackup (const char*); // write status of grid - void duneBackup ( ostream& out ); + void duneBackup ( std::ostream &out ); // read status of grid - void duneRestore (const char*) ; + void duneRestore (const char*); // read status of grid - void duneRestore ( istream& in ) ; + void duneRestore ( std::istream &in ); // done call notify and loadBalancer bool duneAdapt (AdaptRestrictProlongType & arp); @@ -87,15 +90,15 @@ public: class GitterDuneImpl : public GitterBasisImpl , public GitterDuneBasis { // return LeafIterator which only iterates over elements - virtual IteratorSTI < Gitter :: helement_STI > * leafIterator (const Gitter :: helement_STI *) ; - virtual IteratorSTI < Gitter :: helement_STI > * leafIterator (const IteratorSTI < Gitter :: helement_STI > *) ; + virtual IteratorSTI < Gitter::helement_STI > * leafIterator (const Gitter::helement_STI *); + virtual IteratorSTI < Gitter::helement_STI > * leafIterator (const IteratorSTI < Gitter::helement_STI > *); - friend class PureElementLeafIterator < Gitter :: helement_STI > ; + friend class PureElementLeafIterator < Gitter::helement_STI >; public: //! constructor creating grid from std::istream - inline GitterDuneImpl ( istream& in, ProjectVertex* ppv = 0 ) - : GitterBasisImpl ( in, ppv ) + GitterDuneImpl ( std::istream &in, ProjectVertex *ppv = 0 ) + : GitterBasisImpl ( in, ppv ) {} //! constructor creating grid from ObjectStream @@ -120,14 +123,14 @@ public: std::stringstream backup; // backup grid grd->duneBackup( backup ); - delete grd ; grd = 0 ; + delete grd; grd = 0; // free allocated memory (only works if all grids are deleted at this point) - MyAlloc :: clearFreeMemory () ; + MyAlloc::clearFreeMemory (); // restore saved grid grd = new GitterDuneImpl( backup ); assert( grd ); grd->duneRestore( backup ); - return grd ; + return grd; } }; @@ -135,19 +138,19 @@ public: // this LeafIterator only iterates over elements, i.e. tetra,hexa template < class A > class PureElementLeafIterator : public MyAlloc { - GitterDuneBasis * _grd ; - IteratorSTI < A > * _w ; - const A * _a ; - void * operator new (size_t) { return 0 ; } + GitterDuneBasis * _grd; + IteratorSTI < A > * _w; + const A * _a; + void * operator new (size_t) { return 0; } void operator delete (void *) {} - inline PureElementLeafIterator () ; + inline PureElementLeafIterator (); public : - inline PureElementLeafIterator (GitterDuneBasis &) ; - inline PureElementLeafIterator (const PureElementLeafIterator < A > & ) ; - inline ~PureElementLeafIterator () ; - inline IteratorSTI < A > * operator -> () const ; - inline IteratorSTI < A > & operator * () const ; -} ; + inline PureElementLeafIterator (GitterDuneBasis &); + inline PureElementLeafIterator (const PureElementLeafIterator < A > & ); + inline ~PureElementLeafIterator (); + inline IteratorSTI < A > * operator -> () const; + inline IteratorSTI < A > & operator * () const; +}; // // # # # # # # # ###### @@ -159,23 +162,23 @@ template < class A > class PureElementLeafIterator : public MyAlloc { // template <class ostream_t> -inline void GitterDuneBasis :: backupIndices (ostream_t & out) +inline void GitterDuneBasis::backupIndices (ostream_t & out) { // get byte order of stream - out.put( RestoreInfo :: systemByteOrder() ); + out.put( RestoreInfo::systemByteOrder() ); // backup indices, our index type is hierarchic_index unsigned char indices = hierarchic_index; out.put( indices ); - enum { numOfIndexManager = Gitter :: Geometric :: BuilderIF :: numOfIndexManager }; + enum { numOfIndexManager = Gitter::Geometric::BuilderIF:: numOfIndexManager }; // store max indices - for(int i=0; i< numOfIndexManager ; ++i) + for(int i=0; i< numOfIndexManager; ++i) this->indexManager(i).backupIndexSet(out); { // backup index of elements - AccessIterator <helement_STI> :: Handle ew (container ()) ; - for (ew.first () ; ! ew.done () ; ew.next ()) ew.item ().backupIndex (out) ; + AccessIterator <helement_STI>::Handle ew (container ()); + for (ew.first (); ! ew.done (); ew.next ()) ew.item ().backupIndex (out); } // TODO: backup face and edge indices @@ -183,10 +186,10 @@ inline void GitterDuneBasis :: backupIndices (ostream_t & out) { // backup index of vertices LeafIterator < vertex_STI > w ( *this ); - for( w->first(); ! w->done() ; w->next () ) w->item().backupIndex(out); + for( w->first(); ! w->done(); w->next () ) w->item().backupIndex(out); } - return ; + return; } template <class istream_t> @@ -199,11 +202,11 @@ inline void GitterDuneBasis ::restoreIndices (istream_t & in) indices = in.get(); // set VERBOSE to 20 and you have the indices value printed - assert (debugOption (20) ? (cout << "**INFO GitterDuneBasis :: restoreIndices: index flag = " << (int)indices << " file: " - << __FILE__ << " line: " << __LINE__ <<") " << endl, 1) : 1) ; + assert (debugOption (20) ? (cout << "**INFO GitterDuneBasis::restoreIndices: index flag = " << (int)indices << " file: " + << __FILE__ << " line: " << __LINE__ <<") " << endl, 1) : 1); - typedef Gitter :: Geometric :: BuilderIF BuilderIF; - enum { numOfIndexManager = BuilderIF :: numOfIndexManager }; + typedef Gitter::Geometric::BuilderIF BuilderIF; + enum { numOfIndexManager = BuilderIF::numOfIndexManager }; // restore dune indices (see backUpIndices method) if(indices == hierarchic_index) @@ -212,7 +215,7 @@ inline void GitterDuneBasis ::restoreIndices (istream_t & in) // elements to vertices RestoreInfo restoreInfo( byteOrder ); - for(int i=0; i< numOfIndexManager ; ++i) + for(int i=0; i< numOfIndexManager; ++i) this->indexManager(i).restoreIndexSet( in, restoreInfo ); // will fail if numbering was changed @@ -235,22 +238,22 @@ inline void GitterDuneBasis ::restoreIndices (istream_t & in) // mark all visited items as not a hole { LeafIterator < vertex_STI > w ( *this ); - for( w->first(); ! w->done() ; w->next () ) w->item().restoreIndex(in, restoreInfo ); + for( w->first(); ! w->done(); w->next () ) w->item().restoreIndex(in, restoreInfo ); } // reconstruct holes { - IndexManagerType& elementManager = this->indexManager(BuilderIF :: IM_Elements); - elementManager.generateHoles( restoreInfo( BuilderIF :: IM_Elements ) ); + IndexManagerType& elementManager = this->indexManager(BuilderIF::IM_Elements); + elementManager.generateHoles( restoreInfo( BuilderIF::IM_Elements ) ); } // TODO indices for faces and edges { - IndexManagerType& vertexManager = this->indexManager(BuilderIF :: IM_Vertices); + IndexManagerType& vertexManager = this->indexManager(BuilderIF::IM_Vertices); vertexManager.generateHoles( restoreInfo( BuilderIF ::IM_Vertices ) ); } - return ; + return; } if(indices == leaf_index) // convert indices to leafindices @@ -263,89 +266,88 @@ inline void GitterDuneBasis ::restoreIndices (istream_t & in) ++idx; } this->indexManager(0).setMaxIndex ( idx ); - assert (debugOption (20) ? (cout << endl << "**INFO GitterDuneBasis :: restoreIndices: create new leaf indices with size = " << idx << " ! file: "<< __FILE__ << ", line: " << __LINE__ << endl, 1) : 1) ; - return ; + assert (debugOption (20) ? (cout << endl << "**INFO GitterDuneBasis::restoreIndices: create new leaf indices with size = " << idx << " ! file: "<< __FILE__ << ", line: " << __LINE__ << endl, 1) : 1); + return; } - cerr<< "**WARNING: GitterDuneBasis :: restoreIndices: indices (id = " << indices << ") not read! file: "<< __FILE__ << ", line: " << __LINE__ << "\n"; - return ; + std::cerr << "WARNING (ignored0: indices (id = " << indices << ") not read in GitterDuneBasis::restoreIndices." << std::endl; } // wird von Dune verwendet -inline void GitterDuneBasis :: duneBackup ( ostream& out ) +inline void GitterDuneBasis::duneBackup ( std::ostream &out ) { // backup macro grid - container ().backupCMode ( out ) ; + container ().backupCMode ( out ); // backup hierarchy - Gitter :: backup ( out ) ; + Gitter::backup ( out ); // backup indices - backupIndices ( out ) ; + backupIndices ( out ); } // wird von Dune verwendet -inline void GitterDuneBasis :: duneRestore ( istream& in ) +inline void GitterDuneBasis::duneRestore ( std::istream &in ) { // macro grid is created during grid creation // restore hierarchy - Gitter :: restore (in) ; + Gitter::restore (in); // restore indices restoreIndices (in); } -template < class A > inline PureElementAccessIterator < A > :: -Handle :: Handle (AccessIterator < A > & f) - : AccessIterator < A > :: Handle () +template < class A > inline PureElementAccessIterator < A >:: +Handle::Handle (AccessIterator < A > & f) + : AccessIterator < A >::Handle () { this->removeObj(); this->_fac = &f; - this->_fac->ref ++ ; + this->_fac->ref ++; assert( this->_w == 0 ); // this is the difference to the normal AccessIterator, we insert // pureElementIterator, all other things are the same - this->_w = this->_fac->iterator(this->_a) ; - return ; + this->_w = this->_fac->iterator(this->_a); + return; } -template < class A > inline PureElementAccessIterator < A > :: Handle :: +template < class A > inline PureElementAccessIterator < A >::Handle:: Handle (const ThisType& p) - : AccessIterator < A > :: Handle (p) + : AccessIterator < A >::Handle (p) { } -template < class A > inline PureElementAccessIterator < A > :: Handle :: Handle () - : AccessIterator < A > :: Handle () {} +template < class A > inline PureElementAccessIterator < A >::Handle::Handle () + : AccessIterator < A >::Handle () {} -template < class A > PureElementLeafIterator < A > :: PureElementLeafIterator () : _grd (0), _w (0) { - return ; +template < class A > PureElementLeafIterator < A >::PureElementLeafIterator () : _grd (0), _w (0) { + return; } // new LEafIterator which only iterates over elements -template < class A > inline PureElementLeafIterator < A > :: +template < class A > inline PureElementLeafIterator < A >:: PureElementLeafIterator (GitterDuneBasis & g) : _grd (&g), _w (0) , _a(0) { - _w = _grd->leafIterator (_a) ; - return ; + _w = _grd->leafIterator (_a); + return; } -template < class A > inline PureElementLeafIterator < A > :: PureElementLeafIterator (const PureElementLeafIterator < A > & x) : _grd (x._grd), _w (0) { - _w = _grd->leafIterator (x._w) ; - return ; +template < class A > inline PureElementLeafIterator < A >::PureElementLeafIterator (const PureElementLeafIterator < A > & x) : _grd (x._grd), _w (0) { + _w = _grd->leafIterator (x._w); + return; } -template < class A > inline PureElementLeafIterator < A > :: ~PureElementLeafIterator () { - if(_w) delete _w ; - return ; +template < class A > inline PureElementLeafIterator < A >::~PureElementLeafIterator () { + if(_w) delete _w; + return; } -template < class A > inline IteratorSTI < A > * PureElementLeafIterator < A > :: operator -> () const { - return _w ; +template < class A > inline IteratorSTI < A > * PureElementLeafIterator < A >::operator -> () const { + return _w; } -template < class A > inline IteratorSTI < A > & PureElementLeafIterator < A > :: operator * () const { - return * _w ; +template < class A > inline IteratorSTI < A > & PureElementLeafIterator < A >::operator * () const { + return * _w; } namespace { @@ -357,4 +359,4 @@ std::string ZeroPadNumber(int num) } } -#endif +#endif // #ifndef GITTER_DUNE_IMPL_H_INCLUDED diff --git a/lib/Makefile.am b/lib/Makefile.am index 9d25a325182959b5126069a49bd4fd82d3539667..10aeec9ee60c29d5281c77876a3b12ce6284f0b3 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -11,7 +11,8 @@ libalugrid_serial_la_SOURCES = \ $(top_srcdir)/dune/alugrid/src/serial/gitter_tetra_top.cc \ $(top_srcdir)/dune/alugrid/src/serial/mapp_cube_3d.cc \ $(top_srcdir)/dune/alugrid/src/serial/mapp_tetra_3d.cc \ - $(top_srcdir)/dune/alugrid/src/serial/myalloc.cc + $(top_srcdir)/dune/alugrid/src/serial/myalloc.cc \ + $(top_srcdir)/dune/alugrid/src/duneinterface/gitter_dune_impl.cc libalugrid_serial_la_CPPFLAGS = $(AM_CPPFLAGS) libalugrid_serial_la_LDFLAGS = $(AM_LDFLAGS)