[Dune-devel] [Dune-Commit] [Commit] dune-grid - 37332f1: Add gridfactory check

Christian Engwer christian.engwer at uni-muenster.de
Tue Oct 13 17:47:56 CEST 2015


Hi Tobias,

under doc/grids/gridfactory we already have hand crafted meshes
created via the grid factory. I think it would be nice to merge tem
with your mesh.hh (and perhaps use a less generic name) and update
everything to have a common interface. By this we keep the example
grids in one place and allow others to also use the simplicial meshes.

Christian

On Mon, Oct 12, 2015 at 03:28:47PM +0200, Tobias Malkmus wrote:
> New commit, appeared at Mon Oct 12 15:28:47 2015 +0200
> as part of the following ref changes:
> 
>     branch refs/heads/feature/FS1474-add-insertionindex-check    created as              37332f1
> 
> Browsable version: http://cgit.dune-project.org/repositories/dune-grid/commit/?id=37332f1fa361eeab2d7e781ce87c3cb0e2da551e
> 
> ======================================================================
> 
> commit 37332f1fa361eeab2d7e781ce87c3cb0e2da551e
> Author: Tobias Malkmus <tomalk at mathematik.uni-freiburg.de>
> Date:   Mon Oct 12 15:21:30 2015 +0200
> 
>     Add gridfactory check
>     
>     First all elements and vertices are inserted into the grid factory as stored within the mesh structure.
>     After creation of the grid, insertion indices are checked against the ordering of the mesh structure.
>     
>     For simplicial meshes, mesh.hh provids some simple mesh structurs (2D and 3D).
>     
>     call the gridfactory check as follows (2d simplex):
>     Kuhn2dSimplexMesh mesh;
>     checkGridFactory< 2DSimplexGridType >( mesh );
>     
>     An exception will be thrown if the check is not successful.
> 
>  dune/grid/test/CMakeLists.txt      |  2 +
>  dune/grid/test/Makefile.am         |  2 +
>  dune/grid/test/checkgridfactory.hh | 75 +++++++++++++++++++++++++++++
>  dune/grid/test/mesh.hh             | 97 ++++++++++++++++++++++++++++++++++++++
>  4 files changed, 176 insertions(+)
>  create mode 100644 dune/grid/test/checkgridfactory.hh
>  create mode 100644 dune/grid/test/mesh.hh
> 
> 
> 
> diff --git a/dune/grid/test/CMakeLists.txt b/dune/grid/test/CMakeLists.txt
> index b329019..f5d7eb9 100644
> --- a/dune/grid/test/CMakeLists.txt
> +++ b/dune/grid/test/CMakeLists.txt
> @@ -151,6 +151,7 @@ set(SOURCES
>    checkgeometry.hh
>    checkgeometryinfather.cc
>    checkgeometryinfather.hh
> +  checkgridfactory.hh
>    checkindexset.cc
>    checkindexset.hh
>    checkintersectionit.cc
> @@ -167,6 +168,7 @@ set(SOURCES
>    functions.hh
>    gridcheck.cc
>    gridcheck.hh
> +  mesh.hh
>    staticcheck.hh)
>  
>  # install the tests as we want to support testing 3rdparty grids with installed dune-grid
> diff --git a/dune/grid/test/Makefile.am b/dune/grid/test/Makefile.am
> index ba73c8f..5a8eecd 100644
> --- a/dune/grid/test/Makefile.am
> +++ b/dune/grid/test/Makefile.am
> @@ -224,6 +224,7 @@ SOURCES = basicunitcube.hh                      \
>            checkgeometry.hh                      \
>            checkgeometryinfather.cc              \
>            checkgeometryinfather.hh              \
> +					checkgridfactory.hh										\
>            checkindexset.cc                      \
>            checkindexset.hh                      \
>            checkintersectionit.cc                \
> @@ -240,6 +241,7 @@ SOURCES = basicunitcube.hh                      \
>            functions.hh                          \
>            gridcheck.cc                          \
>            gridcheck.hh                          \
> +					mesh.hh																\
>            staticcheck.hh
>  
>  NORMALTESTS += testiteratorranges
> diff --git a/dune/grid/test/checkgridfactory.hh b/dune/grid/test/checkgridfactory.hh
> new file mode 100644
> index 0000000..ef94b81
> --- /dev/null
> +++ b/dune/grid/test/checkgridfactory.hh
> @@ -0,0 +1,75 @@
> +#ifndef DUNE_GRID_TEST_CHECKGRIDFACTORY_HH
> +#define DUNE_GRID_TEST_CHECKGRIDFACTORY_HH
> +
> +#include <algorithm>
> +#include <vector>
> +
> +#include <dune/common/fvector.hh>
> +#include <dune/grid/common/gridfactory.hh>
> +
> +namespace Dune
> +{
> +
> +  // checkGridFactory
> +  // ----------------
> +
> +  template< class Grid, class Mesh >
> +  void checkGridFactory ( const Mesh &mesh )
> +  {
> +    GridFactory< Grid > factory;
> +
> +    // create grid from mesh
> +    typedef FieldVector< typename Grid::ctype, Grid::dimensionworld > Vertex;
> +
> +    for( Vertex vertex : mesh.vertices() )
> +      factory.insertVertex( vertex );
> +
> +    for( const auto &element : mesh.elements() )
> +      factory.insertElement( element.type(), element.vertices() );
> +
> +    std::unique_ptr< Grid > gridptr( factory.createGrid() );
> +    Grid &grid = *gridptr;
> +
> +    // check insertion indices
> +
> +    // check vertex insertion index
> +    for( const auto vertex : vertices( grid.leafGridView() ) )
> +    {
> +      std::size_t idx = factory.insertionIndex( vertex );
> +      Vertex v = mesh.vertices()[ idx ];
> +      if( (v - vertex.geometry().center() ).two_norm() > 1e-8 )
> +        DUNE_THROW( GridError, "GridFactor error, Vertex insertion Index wrong!" );
> +    }
> +
> +    // check element insertion index
> +    std::vector< unsigned int > insertIndices, indices;
> +    for( const auto element : elements( grid.leafGridView() ) )
> +    {
> +      indices.clear();
> +      insertIndices.clear();
> +
> +      std::size_t idx = factory.insertionIndex( element );
> +      unsigned int numSubeEntitites = element.subEntities( Grid::dimension );
> +
> +      if( numSubeEntitites != mesh.elements()[ idx ].vertices().size() )
> +        DUNE_THROW( GridError, "GridFactor error, wrong number of subEntities inserted!" );
> +
> +      for( unsigned int i = 0; i < numSubeEntitites; ++i )
> +      {
> +        indices.push_back( factory.insertionIndex( element.template subEntity< Grid::dimension >( i ) ) );
> +        insertIndices.push_back( mesh.elements()[ idx ].vertices()[ i ] );
> +      }
> +
> +      std::sort( insertIndices.begin(), insertIndices.end() );
> +      std::sort( indices.begin(), indices.end() );
> +
> +      for( unsigned int i = 0; i < indices.size(); ++i )
> +        if( indices[ i ] != insertIndices[ i ] )
> +          DUNE_THROW( GridError, "GridFactor error, Element insertion index wrong!" );
> +    }
> +
> +  }
> +
> +} // namespace Dune
> +
> +#endif // #ifndef DUNE_GRID_TEST_CHECKGRIDFACTORY_HH
> diff --git a/dune/grid/test/mesh.hh b/dune/grid/test/mesh.hh
> new file mode 100644
> index 0000000..8d61e35
> --- /dev/null
> +++ b/dune/grid/test/mesh.hh
> @@ -0,0 +1,97 @@
> +#ifndef DUNE_GRID_TEST_MESH_HH
> +#define DUNE_GRID_TEST_MESH_HH
> +
> +#include <array>
> +#include <initializer_list>
> +#include <utility>
> +#include <vector>
> +
> +#include <dune/common/fvector.hh>
> +#include <dune/geometry/type.hh>
> +
> +
> +namespace Dune
> +{
> +
> +  template< int dim >
> +  struct BasicSimplexElement
> +  {
> +    BasicSimplexElement () {}
> +    BasicSimplexElement ( const BasicSimplexElement & ) = default;
> +
> +    BasicSimplexElement ( std::initializer_list< unsigned int > const &l ) : vertices_( l ) {}
> +
> +
> +    GeometryType type () const { return GeometryType( Dune::GeometryType::simplex, dim ); }
> +    const std::vector< unsigned int > &vertices () const { return vertices_; }
> +
> +  private:
> +    std::vector< unsigned int > vertices_;
> +  };
> +
> +
> +
> +  struct Kuhn2dSimplexMesh
> +  {
> +    typedef Dune::FieldVector< double, 2 > Vertex;
> +    typedef std::vector< Vertex > Vertices;
> +    typedef BasicSimplexElement< 2 > Element;
> +    typedef std::vector< Element > Elements;
> +
> +    Kuhn2dSimplexMesh ()
> +    {
> +      vertices_.push_back( {{ 0.0, 0.0 }} );
> +      vertices_.push_back( {{ 1.0, 0.0 }} );
> +      vertices_.push_back( {{ 0.0, 1.0 }} );
> +      vertices_.push_back( {{ 1.0, 1.0 }} );
> +
> +      elements_.push_back( {{ 0, 1, 2 }} );
> +      elements_.push_back( {{ 3, 2, 0 }} );
> +    }
> +
> +    const Vertices &vertices () const { return vertices_; }
> +    const Elements &elements () const { return elements_; }
> +
> +  protected:
> +    Vertices vertices_;
> +    Elements elements_;
> +  };
> +
> +
> +  struct Kuhn3dSimplexMesh
> +  {
> +    typedef Dune::FieldVector< double, 3 > Vertex;
> +    typedef std::vector< Vertex > Vertices;
> +    typedef BasicSimplexElement< 3 > Element;
> +    typedef std::vector< Element > Elements;
> +
> +    Kuhn3dSimplexMesh ()
> +    {
> +      vertices_.push_back( {{0.0, 0.0, 0.0}} );
> +      vertices_.push_back( {{0.0, 0.0, 1.0}} );
> +      vertices_.push_back( {{0.0, 1.0, 0.0}} );
> +      vertices_.push_back( {{0.0, 1.0, 1.0}} );
> +      vertices_.push_back( {{1.0, 0.0, 0.0}} );
> +      vertices_.push_back( {{1.0, 0.0, 1.0}} );
> +      vertices_.push_back( {{1.0, 1.0, 0.0}} );
> +      vertices_.push_back( {{1.0, 1.0, 1.0}} );
> +
> +      elements_.push_back( {{ 0, 1, 3, 7 }} );
> +      elements_.push_back( {{ 0, 1, 5, 7 }} );
> +      elements_.push_back( {{ 0, 2, 3, 7 }} );
> +      elements_.push_back( {{ 0, 2, 6, 7 }} );
> +      elements_.push_back( {{ 0, 4, 6, 7 }} );
> +      elements_.push_back( {{ 0, 4, 5, 7 }} );
> +    }
> +
> +    const Vertices &vertices () const { return vertices_; }
> +    const Elements &elements () const { return elements_; }
> +
> +  protected:
> +    Vertices vertices_;
> +    Elements elements_;
> +  };
> +
> +} // namespace Dune
> +
> +#endif // #ifndef DUNE_GRID_TEST_MESH_HH
> 
> _______________________________________________
> Dune-Commit mailing list
> Dune-Commit at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-commit
> 

-- 
Prof. Dr. Christian Engwer 
Institut für Numerische und Angewandte Mathematik
Fachbereich Mathematik und Informatik der Universität Münster
Einsteinstrasse 62
48149 Münster

E-Mail  christian.engwer at uni-muenster.de
Telefon +49 251 83-35067
FAX     +49 251 83-32729




More information about the Dune-devel mailing list