[Dune] [Dune-Commit] dune-grid r5060 - in trunk/grid: common genericgeometry genericgeometry/test

Christian Engwer christi at uni-hd.de
Tue Apr 21 22:30:13 CEST 2009


Hi Martin,

may I suggest to use this transition for the switch to _real_
singletons (see fs#227)

I also volunteer to implement these.

Christian

On Tue, Apr 21, 2009 at 09:43:32PM +0200, mnolte at dune-project.org wrote:
> Author: mnolte
> Date: 2009-04-21 21:43:32 +0200 (Tue, 21 Apr 2009)
> New Revision: 5060
> 
> Added:
>    trunk/grid/common/genericreferenceelements.cc
>    trunk/grid/genericgeometry/test/grefelement.cc
> Modified:
>    trunk/grid/common/Makefile.am
>    trunk/grid/common/genericreferenceelements.hh
>    trunk/grid/genericgeometry/cachedmapping.hh
>    trunk/grid/genericgeometry/cornermapping.hh
>    trunk/grid/genericgeometry/hybridmapping.hh
>    trunk/grid/genericgeometry/test/
>    trunk/grid/genericgeometry/test/Makefile.am
> Log:
> Fix a linker error caused by using GenericReferenceElements::general
> 
> Note: This is a hack - the generic reference elements are only instantiated for
>       ctype = float / double and dim = 0 / 1 / 2 / 3.
> 
> 
> Modified: trunk/grid/common/Makefile.am
> ===================================================================
> --- trunk/grid/common/Makefile.am	2009-04-21 10:02:21 UTC (rev 5059)
> +++ trunk/grid/common/Makefile.am	2009-04-21 19:43:32 UTC (rev 5060)
> @@ -1,7 +1,7 @@
>  # $Id$
>  
>  noinst_LTLIBRARIES = libgridcommon.la
> -libgridcommon_la_SOURCES = referenceelements.cc
> +libgridcommon_la_SOURCES = referenceelements.cc genericreferenceelements.cc
>  libgridcommon_la_LIBADD = quadraturerules/libquadraturerules.la \
>    $(DUNE_COMMON_LIBS)
>  
> 
> Added: trunk/grid/common/genericreferenceelements.cc
> ===================================================================
> --- trunk/grid/common/genericreferenceelements.cc	                        (rev 0)
> +++ trunk/grid/common/genericreferenceelements.cc	2009-04-21 19:43:32 UTC (rev 5060)
> @@ -0,0 +1,45 @@
> +#include <config.h>
> +
> +#include <dune/grid/common/genericreferenceelements.hh>
> +
> +namespace Dune
> +{
> +
> +  template< typename ctype, int dim >
> +  GenericReferenceElementContainer< ctype, dim > GenericReferenceElements< ctype, dim>::general;
> +
> +  // we use an empty namespace to initialize the singleton,
> +  // so that this code is hidden
> +  namespace
> +  {
> +
> +    template< class ctype >
> +    struct InitReferenceElements
> +    {
> +      template< int dim >
> +      struct Dimension
> +      {
> +        static void apply ( void *&v )
> +        {
> +          v = &GenericReferenceElements< ctype, dim >::general;
> +        }
> +      };
> +
> +      template< int dim >
> +      static void *apply ()
> +      {
> +        void *v;
> +        GenericGeometry::ForLoop< Dimension, 0, dim >::apply( v );
> +        return v;
> +      }
> +    };
> +
> +    void initReferenceElements ()
> +    {
> +      InitReferenceElements< double >::apply< 3 >();
> +      InitReferenceElements< float >::apply< 3 >();
> +    }
> +
> +  }
> +
> +}
> 
> Modified: trunk/grid/common/genericreferenceelements.hh
> ===================================================================
> --- trunk/grid/common/genericreferenceelements.hh	2009-04-21 10:02:21 UTC (rev 5059)
> +++ trunk/grid/common/genericreferenceelements.hh	2009-04-21 19:43:32 UTC (rev 5060)
> @@ -21,30 +21,24 @@
>      template< class Topology > struct Initialize;
>  
>      struct GeometryTraits
> -    : public GenericGeometry :: DefaultGeometryTraits< ctype, dim, dim >
> +    : public GenericGeometry::DefaultGeometryTraits< ctype, dim, dim >
>      {
> -      typedef GenericGeometry :: DefaultGeometryTraits< ctype, dim, dim > Base;
> +      typedef GenericGeometry::DefaultGeometryTraits< ctype, dim, dim > Base;
>  
> -      typedef typename Base :: CoordTraits CoordTraits;
> +      typedef typename Base::CoordTraits CoordTraits;
>  
>        template< class Topology >
>        struct Mapping
>        {
> -        typedef GenericGeometry :: CornerMapping
> -          < CoordTraits, Topology, dim, CornerStorage< Topology >, true >
> -          type;
> +        typedef GenericGeometry::CornerMapping< CoordTraits, Topology, dim, CornerStorage< Topology >, true > type;
>        };
>  
>        struct Caching
>        {
> -        static const GenericGeometry :: EvaluationType evaluateJacobianTransposed
> -          = GenericGeometry :: PreCompute;
> -        static const GenericGeometry :: EvaluationType evaluateJacobianInverseTransposed
> -          = GenericGeometry :: PreCompute;
> -        static const GenericGeometry :: EvaluationType evaluateIntegrationElement
> -          = GenericGeometry :: PreCompute;
> -        static const GenericGeometry :: EvaluationType evaluateNormal
> -          = GenericGeometry :: PreCompute;
> +        static const GenericGeometry::EvaluationType evaluateJacobianTransposed = GenericGeometry::PreCompute;
> +        static const GenericGeometry::EvaluationType evaluateJacobianInverseTransposed = GenericGeometry::PreCompute;
> +        static const GenericGeometry::EvaluationType evaluateIntegrationElement = GenericGeometry::PreCompute;
> +        static const GenericGeometry::EvaluationType evaluateNormal = GenericGeometry::PreCompute;
>        };
>      };
>  
> @@ -52,18 +46,18 @@
>      template< int codim >
>      struct Codim
>      {
> -      typedef GenericGeometry :: HybridMapping< dim-codim, GeometryTraits > Mapping;
> +      typedef GenericGeometry::HybridMapping< dim-codim, GeometryTraits > Mapping;
>      };
>  
>    private:
>      template< int codim >
>      class MappingArray
> -    : public std :: vector< typename Codim< codim > :: Mapping * >
> +    : public std::vector< typename Codim< codim >::Mapping * >
>      {};
>  
> -    typedef GenericGeometry :: CodimTable< MappingArray, dim > MappingsTable;
> +    typedef GenericGeometry::CodimTable< MappingArray, dim > MappingsTable;
>  
> -    std :: vector< SubEntityInfo > info_[ dim+1 ];
> +    std::vector< SubEntityInfo > info_[ dim+1 ];
>      double volume_;
>      MappingsTable mappings_;
>  
> @@ -110,7 +104,7 @@
>      }
>  
>      template< int codim >
> -    typename Codim< codim > :: Mapping &mapping( int i ) const
> +    typename Codim< codim >::Mapping &mapping( int i ) const
>      {
>        Int2Type< codim > codimVariable;
>        return *(mappings_[ codimVariable ][ i ]);
> @@ -127,20 +121,19 @@
>        return volume_;
>      }
>  
> -    template< GeometryType :: BasicType type >
> +    template< GeometryType::BasicType geoType >
>      void initialize ()
>      {
> -      typedef typename GenericGeometry :: Convert< type, dim > :: type Topology;
> +      typedef typename GenericGeometry::Convert< geoType, dim >::type Topology;
>        typedef Initialize< Topology > Init;
> -      typedef GenericGeometry :: VirtualMapping< Topology, GeometryTraits > VirtualMapping;
> +      typedef GenericGeometry::VirtualMapping< Topology, GeometryTraits > VirtualMapping;
>  
>        Int2Type< 0 > codim0Variable;
>        mappings_[ codim0Variable ].resize( 1 );
>        mappings_[ codim0Variable ][ 0 ]  = new VirtualMapping( codim0Variable );
>  
> -
> -      GenericGeometry :: ForLoop< Init :: template Codim, 0, dim > :: apply( info_, mappings_ );
> -      volume_ = GenericGeometry :: ReferenceDomain< Topology > :: template volume< double >();
> +      GenericGeometry::ForLoop< Init::template Codim, 0, dim >::apply( info_, mappings_ );
> +      volume_ = GenericGeometry::ReferenceDomain< Topology >::template volume< double >();
>      }
>    };
>  
> @@ -196,26 +189,28 @@
>  
>    template< class ctype, int dim >
>    template< class Topology >
> -  class GenericReferenceElement< ctype, dim > :: CornerStorage
> +  class GenericReferenceElement< ctype, dim >::CornerStorage
>    {
> -    typedef GenericGeometry :: ReferenceElement< Topology, ctype > RefElement;
> +    typedef GenericGeometry::ReferenceElement< Topology, ctype > RefElement;
>  
>    public:
> -    static const unsigned int size = Topology :: numCorners;
> +    static const unsigned int size = Topology::numCorners;
>  
> -  private:
> -    FieldVector< ctype, dim > coords_[ size ];
> +    template< class SubTopology >
> +    struct SubStorage
> +    {
> +      typedef CornerStorage< SubTopology > type;
> +    };
>  
> -  public:
>      explicit CornerStorage ( const Int2Type< 0 > & )
>      {
>        for( unsigned int i = 0; i < size; ++i )
> -        coords_[ i ] = RefElement :: corner( i );
> +        coords_[ i ] = RefElement::corner( i );
>      }
>  
>      template< class Mapping, unsigned int codim >
>      explicit
> -    CornerStorage ( const GenericGeometry :: SubMappingCoords< Mapping, codim > &coords )
> +    CornerStorage ( const GenericGeometry::SubMappingCoords< Mapping, codim > &coords )
>      {
>        for( unsigned int i = 0; i < size; ++i )
>          coords_[ i ] = coords[ i ];
> @@ -225,45 +220,41 @@
>      {
>        return coords_[ i ];
>      }
> +
> +  private:
> +    FieldVector< ctype, dim > coords_[ size ];
>    };
>  
>  
>    template< class ctype, int dim >
>    template< class Topology, int codim >
>    template< int subcodim >
> -  struct GenericReferenceElement< ctype, dim >
> -    :: SubEntityInfo :: Initialize< Topology, codim > :: SubCodim
> +  struct GenericReferenceElement< ctype, dim >::SubEntityInfo::Initialize< Topology, codim >::SubCodim
>    {
> -    typedef GenericGeometry :: ReferenceElement< Topology, ctype > RefElement;
> +    typedef GenericGeometry::ReferenceElement< Topology, ctype > RefElement;
>      
> -    static void apply ( unsigned int i, std :: vector< int > (&numbering)[ dim+1 ] )
> +    static void apply ( unsigned int i, std::vector< int > (&numbering)[ dim+1 ] )
>      {
> -      const unsigned int size = RefElement :: template size< codim, subcodim >( i );
> +      const unsigned int size = RefElement::template size< codim, subcodim >( i );
>        numbering[ codim+subcodim ].resize( size );
>        for( unsigned int j = 0; j < size; ++j )
> -      {
> -        numbering[ codim+subcodim ][ j ]
> -          = RefElement ::  template subNumbering< codim, subcodim >[ i ][ j ];
> -      }
> +        numbering[ codim+subcodim ][ j ] = RefElement::template subNumbering< codim, subcodim >( i, j );
>      }
>    };
>  
>  
>    template< class ctype, int dim >
>    template< class Topology >
> -  struct GenericReferenceElement< ctype, dim > :: Initialize
> +  struct GenericReferenceElement< ctype, dim >::Initialize
>    {
> -    typedef Dune :: GenericReferenceElement< ctype, dim > GenericReferenceElement;
> +    typedef Dune::GenericReferenceElement< ctype, dim > GenericReferenceElement;
>  
> -    typedef typename GenericReferenceElement :: template Codim< 0 > :: Mapping
> -      ReferenceMapping;
> +    typedef typename GenericReferenceElement::template Codim< 0 >::Mapping ReferenceMapping;
>  
>      template< int codim >
>      struct Codim
>      {
> -      typedef typename GenericReferenceElement
> -        :: template Codim< codim > :: Mapping :: CachingType
> -        Caching;
> +      //typedef typename GenericReferenceElement::template Codim< codim >::Mapping::Caching Caching;
>        
>        static void apply ( std :: vector< SubEntityInfo > (&info)[ dim+1 ],
>                            MappingsTable &mappings )
> @@ -275,15 +266,15 @@
>  
>          if( codim > 0 )
>          {
> -          const Int2Type< 0 > codim0Variable;
> +          Int2Type< 0 > codim0Variable;
>            const ReferenceMapping &refMapping = *(mappings[ codim0Variable ][ 0 ]);
>  
> -          const Int2Type< codim > codimVariable;
> +          Int2Type< codim > codimVariable;
>            mappings[ codimVariable ].resize( size );
>            for( unsigned int i = 0; i < size; ++i )
>            {
>              mappings[ codimVariable ][ i ]
> -              = refMapping.template subMapping< codim >( i, Caching() );
> +              = refMapping.template trace< codim >( i );
>            }
>          }
>        }
> @@ -300,42 +291,41 @@
>    {
>      typedef GenericReferenceElement< ctype, dim > value_type;
>  
> -  private:
> -    value_type simplex;
> -    value_type cube;
> -    value_type pyramid;
> -    value_type prism;
> -    
>      GenericReferenceElementContainer ()
>      {
> -      simplex.template initialize< GeometryType :: simplex >();
> -      cube.template initialize< GeometryType :: cube >();
> -      pyramid.template initialize< GeometryType :: pyramid >();
> -      prism.template initialize< GeometryType :: prism >();
> +      simplex_.template initialize< GeometryType::simplex >();
> +      cube_.template initialize< GeometryType::cube >();
> +      pyramid_.template initialize< GeometryType::pyramid >();
> +      prism_.template initialize< GeometryType::prism >();
>      }
>      
> -  public:
>      const value_type &operator() ( const GeometryType &type ) const
>      {
>        assert( type.dim() == dim );
>        switch( type.basicType() )
>        {
> -      case GeometryType :: simplex:
> -        return simplex;
> +      case GeometryType::simplex:
> +        return simplex_;
>  
> -      case GeometryType :: cube:
> -        return cube;
> +      case GeometryType::cube:
> +        return cube_;
>          
> -      case GeometryType :: pyramid:
> -        return pyramid;
> +      case GeometryType::pyramid:
> +        return pyramid_;
>          
> -      case GeometryType :: prism:
> -        return prism;
> +      case GeometryType::prism:
> +        return prism_;
>          
>        default:
>          DUNE_THROW( RangeError, "Unknown geometry type: " << type );
>        }
>      }
> +
> +  private:
> +    value_type simplex_;
> +    value_type cube_;
> +    value_type pyramid_;
> +    value_type prism_;
>    };
>  
>    template< class ctype >
> @@ -343,57 +333,55 @@
>    {
>      typedef GenericReferenceElement< ctype, 2 > value_type;
>  
> -  private:
> -    value_type simplex;
> -    value_type cube;
> -    
>      GenericReferenceElementContainer ()
>      {
> -      simplex.template initialize< GeometryType :: simplex >();
> -      cube.template initialize< GeometryType :: cube >();
> +      simplex_.template initialize< GeometryType::simplex >();
> +      cube_.template initialize< GeometryType::cube >();
>      }
>      
> -  public:
>      const value_type &operator() ( const GeometryType &type ) const
>      {
>        assert( type.dim() == 2 );
>        switch( type.basicType() )
>        {
> -      case GeometryType :: simplex:
> -        return simplex;
> +      case GeometryType::simplex:
> +        return simplex_;
>  
> -      case GeometryType :: cube:
> -        return cube;
> +      case GeometryType::cube:
> +        return cube_;
>          
> -      case GeometryType :: pyramid:
> -      case GeometryType :: prism:
> +      case GeometryType::pyramid:
> +      case GeometryType::prism:
>          DUNE_THROW( RangeError, "Invalid geometry type: " << type );
>          
>        default:
>          DUNE_THROW( RangeError, "Unknown geometry type: " << type );
>        }
>      }
> +
> +  private:
> +    value_type simplex_;
> +    value_type cube_;
>    };
>    
>    template< class ctype >
>    struct GenericReferenceElementContainer< ctype, 1 >
>    {
>      typedef GenericReferenceElement< ctype, 1 > value_type;
> -
> -  private:
> -    value_type line;
>      
>      GenericReferenceElementContainer ()
>      {
> -      line.template initialize< GeometryType :: simplex >();
> +      line_.template initialize< GeometryType::simplex >();
>      }
>      
> -  public:
>      const value_type &operator() ( const GeometryType &type ) const
>      {
>        assert( type.dim() == 1 );
> -      return line;
> +      return line_;
>      }
> +
> +  private:
> +    value_type line_;
>    };
>    
>    template< class ctype >
> @@ -401,20 +389,19 @@
>    {
>      typedef GenericReferenceElement< ctype, 0 > value_type;
>  
> -  private:
> -    value_type point;
> -    
>      GenericReferenceElementContainer ()
>      {
> -      point.template initialize< GeometryType :: simplex >();
> +      point_.template initialize< GeometryType::simplex >();
>      }
>      
> -  public:
>      const value_type &operator() ( const GeometryType &type ) const
>      {
>        assert( type.dim() == 0 );
> -      return point;
> +      return point_;
>      }
> +
> +  private:
> +    value_type point_;
>    };
>  
>  
> 
> Modified: trunk/grid/genericgeometry/cachedmapping.hh
> ===================================================================
> --- trunk/grid/genericgeometry/cachedmapping.hh	2009-04-21 10:02:21 UTC (rev 5059)
> +++ trunk/grid/genericgeometry/cachedmapping.hh	2009-04-21 19:43:32 UTC (rev 5060)
> @@ -59,9 +59,10 @@
>          typedef typename TraceProvider< Topology, GeometryTraits, codim, false > :: Trace
>            Trace;
>        };
> +
> +      typedef typename GeometryTraits::Caching Caching;
>    
>      private:
> -      typedef typename GeometryTraits :: Caching Caching;
>        typedef typename Traits :: MatrixHelper MatrixHelper;
>  
>      public:
> 
> Modified: trunk/grid/genericgeometry/cornermapping.hh
> ===================================================================
> --- trunk/grid/genericgeometry/cornermapping.hh	2009-04-21 10:02:21 UTC (rev 5059)
> +++ trunk/grid/genericgeometry/cornermapping.hh	2009-04-21 19:43:32 UTC (rev 5060)
> @@ -542,7 +542,7 @@
>        struct SubTopology
>        {
>          typedef typename GenericGeometry :: SubTopology< Topo, codim, i > :: type Topology;
> -        typedef typename CStorage :: template SubStorage< Topology > :: type CornerStorage;
> +        typedef typename CStorage::template SubStorage< Topology >::type CornerStorage;
>          typedef CornerMapping< CoordTraits, Topology, dimWorld, CornerStorage, affine > Trace;
>        };
>  
> 
> Modified: trunk/grid/genericgeometry/hybridmapping.hh
> ===================================================================
> --- trunk/grid/genericgeometry/hybridmapping.hh	2009-04-21 10:02:21 UTC (rev 5059)
> +++ trunk/grid/genericgeometry/hybridmapping.hh	2009-04-21 19:43:32 UTC (rev 5060)
> @@ -92,6 +92,8 @@
>          typedef HybridMapping< dimension - codim, GeometryTraits > Trace;
>        };
>  
> +      typedef typename GeometryTraits::Caching Caching;
> +
>        unsigned int referenceCount;
>  
>        virtual ~HybridMapping ()
> @@ -210,6 +212,8 @@
>          typedef HybridMapping< dimension - codim, GeometryTraits > Trace;
>        };
>  
> +      typedef typename GeometryTraits::Caching Caching;
> +
>      private:
>        Mapping mapping_;
>  
> 
> 
> Property changes on: trunk/grid/genericgeometry/test
> ___________________________________________________________________
> Name: svn:ignore
>    - testsubtopologies
> testmapping
> testgeo
> 
> Makefile
> Makefile.in
> 
> .deps
> .libs
> 
> *.dgf.*
> *.log
> *.so.*
> *.swp
> *.tmp*
> 
>    + testsubtopologies
> testmapping
> testgeo
> grefelement
> 
> Makefile
> Makefile.in
> 
> .deps
> .libs
> 
> *.dgf.*
> *.log
> *.so.*
> *.swp
> *.tmp*
> 
> 
> Modified: trunk/grid/genericgeometry/test/Makefile.am
> ===================================================================
> --- trunk/grid/genericgeometry/test/Makefile.am	2009-04-21 10:02:21 UTC (rev 5059)
> +++ trunk/grid/genericgeometry/test/Makefile.am	2009-04-21 19:43:32 UTC (rev 5060)
> @@ -7,7 +7,7 @@
>  #WORLDDIM = 3
>  DIMENSION = 3
>  
> -check_PROGRAMS = testsubtopologies testmapping testgeo
> +check_PROGRAMS = testsubtopologies testmapping testgeo grefelement
>  
>  testsubtopologies_SOURCES = testsubtopologies.cc
>  testsubtopologies_CPPFLAGS = $(ALL_PKG_CPPFLAGS) -DGEOMETRYTYPE=$(GEOMETRYTYPE) -DDIMENSION=$(DIMENSION)
> @@ -20,4 +20,8 @@
>  testgeo_CPPFLAGS = $(ALL_PKG_CPPFLAGS) $(PSGINC)
>  testgeo_LDADD = $(LOCAL_LIBS) $(ALL_PKG_LDFLAGS) $(ALL_PKG_LIBS)
>  
> +grefelement_SOURCES = grefelement.cc
> +grefelement_CPPFLAGS = $(ALL_PKG_CPPFLAGS)
> +grefelement_LDADD = $(LOCAL_LIBS) $(ALL_PKG_LDFLAGS) $(ALL_PKG_LIBS)
> +
>  include $(top_srcdir)/am/global-rules
> 
> Added: trunk/grid/genericgeometry/test/grefelement.cc
> ===================================================================
> --- trunk/grid/genericgeometry/test/grefelement.cc	                        (rev 0)
> +++ trunk/grid/genericgeometry/test/grefelement.cc	2009-04-21 19:43:32 UTC (rev 5060)
> @@ -0,0 +1,18 @@
> +#include <config.h>
> +
> +#include <iostream>
> +
> +#include <dune/grid/common/genericreferenceelements.hh>
> +
> +using namespace Dune;
> +
> +int main ( int argc, char **argv )
> +{
> +  const GeometryType type( GeometryType::simplex, 3 );
> +  const GenericReferenceElement< double, 3 > &refElement
> +    = GenericReferenceElements< double, 3 >::general( type );
> +
> +  std::cout << refElement.size( 0 ) << std::endl;
> +
> +  return 0;
> +}
> 
> 
> _______________________________________________
> Dune-Commit mailing list
> Dune-Commit at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-commit
> 
> 




More information about the Dune mailing list