[Dune] [Dune-Commit] dune-grid r6566 - trunk/dune/grid/genericgeometry
Oliver Sander
sander at mi.fu-berlin.de
Tue Apr 6 10:17:51 CEST 2010
Hi Martin!
Sorry for screwing up. However, I must say that I don't feel much guilt.
I did run a few tests (UGGrid among them), and everything worked fine.
Requiring Alberta to test for correctness of the GenericGeometries seems
a bit far-fetched to me. Also, putting comments in the code now and
then would really help people understand the design decisions.
For example: What does the template parameter of
template< bool > struct AllTypes;
do? It doesn't even have a name.
best,
Oliver
mnolte at dune-project.org schrieb:
> Author: mnolte
> Date: 2010-04-06 07:58:08 +0200 (Tue, 06 Apr 2010)
> New Revision: 6566
>
> Modified:
> trunk/dune/grid/genericgeometry/mappingprovider.hh
> Log:
> revert patch 6565
>
> I agree with Oliver, that the code would look nicer. The problem with static
> ifs, though, is that both branches have to be instanciated. Conversion< prism, 0 >
> then instanciates Conversion< simplex, -1 > and so on.
>
> In my opinion, we should discuss the future of the GeometryType before we start
> discussing how the geometry type conversion stuff can be beautified.
>
> Oh, yes, and thanks for extensive testing. The bug could have been found by
> configurung with ALBERTA.
>
>
> Modified: trunk/dune/grid/genericgeometry/mappingprovider.hh
> ===================================================================
> --- trunk/dune/grid/genericgeometry/mappingprovider.hh 2010-04-05 07:30:38 UTC (rev 6565)
> +++ trunk/dune/grid/genericgeometry/mappingprovider.hh 2010-04-06 05:58:08 UTC (rev 6566)
> @@ -46,6 +46,8 @@
> typedef HybridMapping< dim, GeometryTraits > Mapping;
>
> private:
> + template< bool > struct AllTypes;
> + template< bool > struct OnlySimplexCube;
>
> template< GeometryType :: BasicType type, class CoordVector >
> static Mapping *virtualMapping ( const CoordVector &coords )
> @@ -60,49 +62,66 @@
> mapping ( const GeometryType &type, const CoordVector &coords )
> {
> assert( type.dim() == Mapping :: dimension );
> + typedef typename SelectType< (Mapping :: dimension >= 3), AllTypes<true>, OnlySimplexCube<false> >::Type Switch;
> + return Switch :: mapping( type.basicType(), coords );
> + }
> + };
>
> - if (Mapping :: dimension >= 3) { // static if: can be evaluated at compile time
>
> - // If our dimension is at least 3 there are four possible types of elements
> - switch( type.basicType() )
> - {
> - case GeometryType :: simplex:
> - return virtualMapping< GeometryType :: simplex, CoordVector >( coords );
> -
> - case GeometryType :: cube:
> - return virtualMapping< GeometryType :: cube, CoordVector >( coords );
> -
> - case GeometryType :: prism:
> - return virtualMapping< GeometryType :: prism, CoordVector >( coords );
> -
> - case GeometryType :: pyramid:
> - return virtualMapping< GeometryType :: pyramid, CoordVector >( coords );
> -
> - default:
> - DUNE_THROW( RangeError, "Unknown basic geometry type: " << type );
> - }
> + template< unsigned int dim, class GeometryTraits >
> + template< bool >
> + struct VirtualMappingFactory< dim, GeometryTraits > :: AllTypes
> + {
> + template< class CoordVector >
> + static Mapping *
> + mapping ( GeometryType :: BasicType type, const CoordVector &coords )
> + {
> + switch( type )
> + {
> + case GeometryType :: simplex:
> + return virtualMapping< GeometryType :: simplex, CoordVector >( coords );
>
> + case GeometryType :: cube:
> + return virtualMapping< GeometryType :: cube, CoordVector >( coords );
> +
> + case GeometryType :: prism:
> + return virtualMapping< GeometryType :: prism, CoordVector >( coords );
> +
> + case GeometryType :: pyramid:
> + return virtualMapping< GeometryType :: pyramid, CoordVector >( coords );
> +
> + default:
> + DUNE_THROW( RangeError, "Unknown basic geometry type: " << type );
> }
> + }
> + };
>
> - // Our dimension is less than 3. There can be only triangles or quadrilaterals.
> - /** \todo The case dim=1 is actually missing */
> - switch( type.basicType() )
> - {
> - case GeometryType :: simplex:
> - return virtualMapping< GeometryType :: simplex, CoordVector >( coords );
> -
> - case GeometryType :: cube:
> - return virtualMapping< GeometryType :: cube, CoordVector >( coords );
> -
> - default:
> - DUNE_THROW( RangeError, "Unknown basic geometry type: " << type );
> - }
>
> + template< unsigned int dim, class GeometryTraits >
> + template< bool >
> + struct VirtualMappingFactory< dim, GeometryTraits > :: OnlySimplexCube
> + {
> + template< class CoordVector >
> + static Mapping *
> + mapping ( GeometryType :: BasicType type, const CoordVector &coords )
> + {
> + switch( type )
> + {
> + case GeometryType :: simplex:
> + return virtualMapping< GeometryType :: simplex, CoordVector >( coords );
> +
> + case GeometryType :: cube:
> + return virtualMapping< GeometryType :: cube, CoordVector >( coords );
> +
> + default:
> + DUNE_THROW( RangeError, "Unknown basic geometry type: " << type );
> + }
> }
> };
>
>
>
> +
> // MappingProvider
> // ---------------
>
>
>
> _______________________________________________
> 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