[Dune] [Dune-Commit] dune-grid r4771 - trunk/grid/albertagrid

Oliver Sander sander at mi.fu-berlin.de
Fri Jan 23 10:26:59 CET 2009


Hi Martin!
Hübsch!  Aber sollte das nicht eher nach grid/io/file/... ?
Mit AlbertaGrid hat es ja eigentlich nichts zu tun.

Viele Grüße,
Oliver

mnolte at dune-project.org schrieb:
> Author: mnolte
> Date: 2009-01-23 10:09:50 +0100 (Fri, 23 Jan 2009)
> New Revision: 4771
>
> Added:
>    trunk/grid/albertagrid/albertareader.hh
> Modified:
>    trunk/grid/albertagrid/Makefile.am
>    trunk/grid/albertagrid/gridfactory.hh
>    trunk/grid/albertagrid/macrodata.hh
> Log:
> added AlbertaReader (able to read alberta grid files into any factory)
>
>
> Modified: trunk/grid/albertagrid/Makefile.am
> ===================================================================
> --- trunk/grid/albertagrid/Makefile.am	2009-01-23 08:22:07 UTC (rev 4770)
> +++ trunk/grid/albertagrid/Makefile.am	2009-01-23 09:09:50 UTC (rev 4771)
> @@ -11,6 +11,6 @@
>    geometry.hh  geometry.cc  hierarchiciterator.hh \
>    leveliterator.hh  leafiterator.hh  treeiterator.hh  treeiterator.cc \
>    intersection.hh  intersection.cc  capabilities.hh \
> -  gridfactory.hh  dgfparser.hh
> +  gridfactory.hh  dgfparser.hh  albertareader
>  
>  include $(top_srcdir)/am/global-rules
>
> Added: trunk/grid/albertagrid/albertareader.hh
> ===================================================================
> --- trunk/grid/albertagrid/albertareader.hh	                        (rev 0)
> +++ trunk/grid/albertagrid/albertareader.hh	2009-01-23 09:09:50 UTC (rev 4771)
> @@ -0,0 +1,89 @@
> +#ifndef DUNE_ALBERTA_ALBERTAREADER_HH
> +#define DUNE_ALBERTA_ALBERTAREADER_HH
> +
> +#include <dune/grid/common/grid.hh>
> +#include <dune/grid/common/gridfactory.hh>
> +
> +#include <dune/grid/utility/grapedataioformattypes.hh>
> +
> +#include <dune/grid/albertagrid/macrodata.hh>
> +
> +#if HAVE_ALBERTA
> +
> +namespace Dune
> +{
> +
> +  template< class Grid >
> +  class AlbertaReader
> +  {
> +    typedef AlbertaReader< Grid > This;
> +
> +  public:
> +    typedef Dune::GridFactory< Grid > GridFactory;
> +
> +    typedef typename Grid::ctype ctype;
> +
> +    static const int dimension = Grid::dimension;
> +    static const int dimensionworld = Grid::dimensionworld;
> +
> +  private:
> +    dune_static_assert( dimensionworld == Alberta::dimWorld,
> +                        "AlbertaReader: world dimension must match ALBERTA's world dimension." );
> +
> +    typedef Alberta::MacroData< dimension > MacroData;
> +
> +    MacroData macroData_;
> +
> +    AlbertaReader ( const This & );
> +    This &operator= ( const This & );
> +
> +  public:
> +    AlbertaReader ()
> +    {}
> +
> +    template< GrapeIOFileFormatType type >
> +    void readGrid ( const std::string &fileName, GridFactory &factory )
> +    {
> +      dune_static_assert( type != pgm, "AlbertaReader: reading pgm format is not supported." );
> +
> +      // read ALBERTA macro triangulation
> +      macroData_.read( fileName, (type == xdr) );
> +
> +      // insert all vertices into the factory
> +      const int numVertices = macroData_.vertexCount();
> +      for( int i = 0; i < numVertices; ++i )
> +      {
> +        FieldVector< ctype, dimensionworld > v;
> +        const Alberta::GlobalVector &coords = macroData_.vertex( i );
> +        for( int j = 0; j < dimensionworld; ++j )
> +          v[ j ] = coords[ j ];
> +        factory.insertVertex( v );
> +      }
> +
> +      // insert all elements into the factory
> +      const GeometryType geoType( GeometryType::simplex, dimension );
> +      std::vector< unsigned int > vertices( dimension+1 );
> +      const int numElements = macroData_.elementCount();
> +      for( int i = 0; i < numElements; ++i )
> +      {
> +        const typename MacroData::ElementId &id = macroData_.element( i );
> +        for( int j = 0; j <= dimension; ++j )
> +          vertices[ j ] = id[ j ];
> +        factory.insertElement( geoType, vertices );
> +      }
> +
> +      // release ALBERTA macro data
> +      macroData_.release();
> +    }
> +
> +    void readGrid ( const std::string &filename, GridFactory &factory )
> +    {
> +      readGrid< ascii >( filename, factory );
> +    }
> +  };
> +
> +}
> +
> +#endif // #if HAVE_ALBERTA
> +
> +#endif
>
> Modified: trunk/grid/albertagrid/gridfactory.hh
> ===================================================================
> --- trunk/grid/albertagrid/gridfactory.hh	2009-01-23 08:22:07 UTC (rev 4770)
> +++ trunk/grid/albertagrid/gridfactory.hh	2009-01-23 09:09:50 UTC (rev 4771)
> @@ -105,6 +105,11 @@
>        macroData_.finalize();
>        return macroData_.write( filename, (type == xdr) );
>      }
> +
> +    bool write ( const std::string &filename )
> +    {
> +      return write< ascii >( filename );
> +    }
>    };
>  
>  }
>
> Modified: trunk/grid/albertagrid/macrodata.hh
> ===================================================================
> --- trunk/grid/albertagrid/macrodata.hh	2009-01-23 08:22:07 UTC (rev 4770)
> +++ trunk/grid/albertagrid/macrodata.hh	2009-01-23 09:09:50 UTC (rev 4771)
> @@ -26,10 +26,12 @@
>        static const int numVertices = NumSubEntities< dimension, dimension >::value;
>        static const int numEdges = NumSubEntities< dimension, dimension-1 >::value;
>  
> +      static const int initialSize = 4096;
> +
> +    public:
>        typedef int ElementId[ numVertices ];
>  
> -      static const int initialSize = 4096;
> -
> +    private:
>        Data *data_;
>        int vertexCount_;
>        int elementCount_;
> @@ -46,6 +48,16 @@
>          return data_;
>        }
>  
> +      int vertexCount () const
> +      {
> +        return (vertexCount_ < 0 ? data_->n_total_vertices : vertexCount_);
> +      }
> +
> +      int elementCount () const
> +      {
> +        return (elementCount_ < 0 ? data_->n_macro_elements : elementCount_);
> +      }
> +
>        ElementId &element ( int i ) const;
>        GlobalVector &vertex ( int i ) const;
>        int &neighbor ( int element, int i ) const;
> @@ -376,7 +388,7 @@
>        if( dimension == 1 )
>          return;
>  
> -      const int count = (elementCount_ >= 0 ? elementCount_ : data_->n_macro_elements);
> +      const int count = elementCount();
>        for( int i = 0; i < count; ++i )
>        {
>          const int refEdge = RefinementEdge< dimension >::value;
>
>
> _______________________________________________
> Dune-Commit mailing list
> Dune-Commit at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-commit
>   


-- 
************************************************************************
* Oliver Sander                ** email: sander at mi.fu-berlin.de        *
* Freie Universität Berlin     ** phone: + 49 (30) 838 75348           *
* Institut für Mathematik      ** URL  : page.mi.fu-berlin.de/~sander  *
* Arnimallee 6                 ** -------------------------------------*
* 14195 Berlin, Germany        ** Member of MATHEON (www.matheon.de)   *
************************************************************************





More information about the Dune mailing list