Commit 342705e5 authored by Christian Engwer's avatar Christian Engwer

moved BasicUnitCube into a new source file,

 use the GridFactory for ALU3dGrids
 and delete unnecessary grid files from the grids directory

creadits to Martin Drohmann

[[Imported from SVN: r234]]
parent 873b2f2a
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef BASICUNITCUBE_HH
#define BASICUNITCUBE_HH
#include <dune/grid/common/gridfactory.hh>
// declaration of a basic unit cube that uses the GridFactory
template< int dim >
class BasicUnitCube;
// unit cube in two dimensions with 2 variants: triangle and rectangle elements
template<>
class BasicUnitCube< 2 >
{
protected:
template< class Grid >
static void insertVertices ( Dune::GridFactory< Grid > &factory )
{
Dune::FieldVector<double,2> pos;
pos[0] = 0; pos[1] = 0;
factory.insertVertex(pos); /*@\label{uc:iv}@*/
pos[0] = 1; pos[1] = 0;
factory.insertVertex(pos);
pos[0] = 0; pos[1] = 1;
factory.insertVertex(pos);
pos[0] = 1; pos[1] = 1;
factory.insertVertex(pos);
}
template< class Grid >
static void insertSimplices ( Dune::GridFactory< Grid > &factory )
{
const Dune::GeometryType type( Dune::GeometryType::simplex, 2 );
std::vector< unsigned int > cornerIDs( 3 );
cornerIDs[0] = 0; cornerIDs[1] = 1; cornerIDs[2] = 2;
factory.insertElement( type, cornerIDs ); /*@\label{uc:ie}@*/
cornerIDs[0] = 2; cornerIDs[1] = 1; cornerIDs[2] = 3;
factory.insertElement( type, cornerIDs );
}
template< class Grid >
static void insertCubes ( Dune::GridFactory< Grid > &factory )
{
const Dune::GeometryType type( Dune::GeometryType::cube, 2 );
std::vector< unsigned int > cornerIDs( 4 );
for( int i = 0; i < 4; ++i )
cornerIDs[ i ] = i;
factory.insertElement( type, cornerIDs );
}
};
// unit cube in 3 dimensions with two variants: tetraheda and hexahedra
template<>
class BasicUnitCube< 3 >
{
protected:
template< class Grid >
static void insertVertices ( Dune::GridFactory< Grid > &factory )
{
Dune::FieldVector< double, 3 > pos;
pos[0] = 0; pos[1] = 0; pos[2] = 0; factory.insertVertex(pos);
pos[0] = 1; pos[1] = 0; pos[2] = 0; factory.insertVertex(pos);
pos[0] = 0; pos[1] = 1; pos[2] = 0; factory.insertVertex(pos);
pos[0] = 1; pos[1] = 1; pos[2] = 0; factory.insertVertex(pos);
pos[0] = 0; pos[1] = 0; pos[2] = 1; factory.insertVertex(pos);
pos[0] = 1; pos[1] = 0; pos[2] = 1; factory.insertVertex(pos);
pos[0] = 0; pos[1] = 1; pos[2] = 1; factory.insertVertex(pos);
pos[0] = 1; pos[1] = 1; pos[2] = 1; factory.insertVertex(pos);
}
template< class Grid >
static void insertSimplices ( Dune::GridFactory< Grid > &factory )
{
const Dune::GeometryType type( Dune::GeometryType::simplex, 3 );
std::vector< unsigned int > cornerIDs( 4 );
cornerIDs[0] = 0; cornerIDs[1] = 1; cornerIDs[2] = 2; cornerIDs[3] = 4;
factory.insertElement( type, cornerIDs );
cornerIDs[0] = 1; cornerIDs[1] = 3; cornerIDs[2] = 2; cornerIDs[3] = 7;
factory.insertElement( type, cornerIDs );
cornerIDs[0] = 1; cornerIDs[1] = 7; cornerIDs[2] = 2; cornerIDs[3] = 4;
factory.insertElement( type, cornerIDs );
cornerIDs[0] = 1; cornerIDs[1] = 7; cornerIDs[2] = 4; cornerIDs[3] = 5;
factory.insertElement( type, cornerIDs );
cornerIDs[0] = 4; cornerIDs[1] = 7; cornerIDs[2] = 2; cornerIDs[3] = 6;
factory.insertElement( type, cornerIDs );
}
template< class Grid >
static void insertCubes ( Dune::GridFactory< Grid > &factory )
{
const Dune::GeometryType type( Dune::GeometryType::cube, 3 );
std::vector< unsigned int > cornerIDs( 8 );
for( int i = 0; i < 8; ++i )
cornerIDs[ i ] = i;
factory.insertElement( type, cornerIDs );
}
};
#endif /*BASICUNITCUBE_HH*/
DIM: 3
DIM_OF_WORLD: 3
number of vertices: 8
number of elements: 6
vertex coordinates:
0.0 0.0 0.0
1.0 0.0 0.0
0.0 0.0 1.0
1.0 0.0 1.0
1.0 1.0 0.0
1.0 1.0 1.0
0.0 1.0 0.0
0.0 1.0 1.0
element vertices:
0 5 4 1
0 5 3 1
0 5 3 2
0 5 4 6
0 5 7 6
0 5 7 2
element boundaries:
1 1 0 0
1 1 0 0
1 1 0 0
1 1 0 0
1 1 0 0
1 1 0 0
element neighbours:
-1 -1 1 3
-1 -1 0 2
-1 -1 5 1
-1 -1 4 0
-1 -1 3 5
-1 -1 2 4
EXTRA_DIST = 2dgrid.al 2dsimplex.alu 3dgrid.al cube.hexa cube.tetra \
EXTRA_DIST = 2dgrid.al 2dsimplex.alu \
unitcube1.dgf unitcube2.dgf unitcube3.dgf
griddir = $(datadir)/doc/dune-grid-howto/examples/grids
......
!Hexahedra
8
0.000000 0.000000 0.000000
1.000000 0.000000 0.000000
1.000000 1.000000 0.000000
0.000000 1.000000 0.000000
0.000000 0.000000 1.000000
1.000000 0.000000 1.000000
1.000000 1.000000 1.000000
0.000000 1.000000 1.000000
1
0 1 2 3 4 5 6 7
6
-2 4 0 3 7 4
-3 4 1 5 6 2
-1 4 0 4 5 1
-1 4 3 2 6 7
-1 4 0 1 2 3
-1 4 5 4 7 6
0 -1
1 -1
2 -1
3 -1
4 -1
5 -1
6 -1
7 -1
!Tetrahedra
8
0.000000 0.000000 0.000000
1.000000 0.000000 0.000000
0.000000 1.000000 1.000000
0.000000 0.000000 1.000000
0.000000 1.000000 0.000000
1.000000 0.000000 1.000000
1.000000 1.000000 0.000000
1.000000 1.000000 1.000000
6
0 1 2 3
0 2 1 4
1 5 2 3
1 6 4 2
1 6 2 7
1 7 2 5
12
-2 3 3 2 0
-2 3 1 3 0
-1 3 4 1 0
-2 3 2 4 0
-1 3 2 3 5
-2 3 5 3 1
-2 3 4 2 6
-1 3 4 6 1
-2 3 2 7 6
-2 3 6 7 1
-1 3 2 5 7
-2 3 7 5 1
0 -1
1 -1
2 -1
3 -1
4 -1
5 -1
6 -1
7 -1
......@@ -6,116 +6,8 @@
#include <dune/common/exceptions.hh>
#include <dune/common/fvector.hh>
#include <dune/grid/common/gridfactory.hh>
// UGGrid 3d, variant 2 (tetrahedra) specialization
template< int dim >
class BasicUnitCube;
template<>
class BasicUnitCube< 2 >
{
protected:
template< class Grid >
static void insertVertices ( Dune::GridFactory< Grid > &factory )
{
Dune::FieldVector<double,2> pos;
pos[0] = 0; pos[1] = 0;
factory.insertVertex(pos);
pos[0] = 1; pos[1] = 0;
factory.insertVertex(pos);
pos[0] = 0; pos[1] = 1;
factory.insertVertex(pos);
pos[0] = 1; pos[1] = 1;
factory.insertVertex(pos);
}
template< class Grid >
static void insertSimplices ( Dune::GridFactory< Grid > &factory )
{
const Dune::GeometryType type( Dune::GeometryType::simplex, 2 );
std::vector< unsigned int > cornerIDs( 3 );
cornerIDs[0] = 0; cornerIDs[1] = 1; cornerIDs[2] = 2;
factory.insertElement( type, cornerIDs );
cornerIDs[0] = 2; cornerIDs[1] = 1; cornerIDs[2] = 3;
factory.insertElement( type, cornerIDs );
}
template< class Grid >
static void insertCubes ( Dune::GridFactory< Grid > &factory )
{
const Dune::GeometryType type( Dune::GeometryType::cube, 2 );
std::vector< unsigned int > cornerIDs( 4 );
for( int i = 0; i < 4; ++i )
cornerIDs[ i ] = i;
factory.insertElement( type, cornerIDs );
}
};
template<>
class BasicUnitCube< 3 >
{
protected:
template< class Grid >
static void insertVertices ( Dune::GridFactory< Grid > &factory )
{
Dune::FieldVector< double, 3 > pos;
pos[0] = 0; pos[1] = 0; pos[2] = 0; factory.insertVertex(pos);
pos[0] = 1; pos[1] = 0; pos[2] = 0; factory.insertVertex(pos);
pos[0] = 0; pos[1] = 1; pos[2] = 0; factory.insertVertex(pos);
pos[0] = 1; pos[1] = 1; pos[2] = 0; factory.insertVertex(pos);
pos[0] = 0; pos[1] = 0; pos[2] = 1; factory.insertVertex(pos);
pos[0] = 1; pos[1] = 0; pos[2] = 1; factory.insertVertex(pos);
pos[0] = 0; pos[1] = 1; pos[2] = 1; factory.insertVertex(pos);
pos[0] = 1; pos[1] = 1; pos[2] = 1; factory.insertVertex(pos);
}
template< class Grid >
static void insertSimplices ( Dune::GridFactory< Grid > &factory )
{
const Dune::GeometryType type( Dune::GeometryType::simplex, 3 );
std::vector< unsigned int > cornerIDs( 4 );
cornerIDs[0] = 0; cornerIDs[1] = 1; cornerIDs[2] = 2; cornerIDs[3] = 4;
factory.insertElement( type, cornerIDs );
cornerIDs[0] = 1; cornerIDs[1] = 3; cornerIDs[2] = 2; cornerIDs[3] = 7;
factory.insertElement( type, cornerIDs );
cornerIDs[0] = 1; cornerIDs[1] = 7; cornerIDs[2] = 2; cornerIDs[3] = 4;
factory.insertElement( type, cornerIDs );
cornerIDs[0] = 1; cornerIDs[1] = 7; cornerIDs[2] = 4; cornerIDs[3] = 5;
factory.insertElement( type, cornerIDs );
cornerIDs[0] = 4; cornerIDs[1] = 7; cornerIDs[2] = 2; cornerIDs[3] = 6;
factory.insertElement( type, cornerIDs );
}
template< class Grid >
static void insertCubes ( Dune::GridFactory< Grid > &factory )
{
const Dune::GeometryType type( Dune::GeometryType::cube, 3 );
std::vector< unsigned int > cornerIDs( 8 );
for( int i = 0; i < 8; ++i )
cornerIDs[ i ] = i;
factory.insertElement( type, cornerIDs );
}
};
// default implementation for any template parameter
template<typename T, int variant>
template<typename T, int variant> /*@\label{uc:uc0}@*/
class UnitCube
{
public:
......@@ -135,7 +27,10 @@ public:
private:
// the constructed grid object
T grid_;
};
}; /*@\label{uc:uc1}@*/
// include basic unitcube using GridFactory concept
#include "basicunitcube.hh"
// include specializations
#include "unitcube_onedgrid.hh"
......
......@@ -5,25 +5,38 @@
#if HAVE_ALUGRID
#include <dune/grid/alugrid.hh>
#include <dune/grid/alugrid/3d/alu3dgridfactory.hh>
// ALU3dGrid tetrahedra specialization. Note: element type determined by type
// ALU3dGrid and ALU2dGrid simplex specialization.
// Note: element type determined by type
template<>
class UnitCube<Dune::ALUSimplexGrid<3,3>,1>
: public BasicUnitCube< 3 >
{
public:
typedef Dune::ALUSimplexGrid<3,3> GridType;
UnitCube () : filename("grids/cube.tetra"), grid_(filename.c_str())
{}
private:
GridType * grid_;
GridType& grid ()
public:
UnitCube ()
{
return grid_;
Dune::GridFactory< GridType > factory;
BasicUnitCube< 3 >::insertVertices( factory );
BasicUnitCube< 3 >::insertSimplices( factory );
grid_ = factory.createGrid( );
}
private:
std::string filename;
GridType grid_;
~UnitCube()
{
delete grid_;
}
GridType &grid ()
{
return *grid_;
}
};
// ALU2SimplexGrid 2d specialization. Note: element type determined by type
......@@ -49,21 +62,32 @@ private:
// ALU3dGrid hexahedra specialization. Note: element type determined by type
template<>
class UnitCube<Dune::ALUCubeGrid<3,3>,1>
: public BasicUnitCube< 3 >
{
public:
typedef Dune::ALUCubeGrid<3,3> GridType;
UnitCube () : filename("grids/cube.hexa"), grid_(filename.c_str())
{}
private:
GridType * grid_;
GridType& grid ()
public:
UnitCube ()
{
return grid_;
Dune::GridFactory< GridType > factory;
BasicUnitCube< 3 >::insertVertices( factory );
BasicUnitCube< 3 >::insertCubes( factory );
grid_ = factory.createGrid( );
}
private:
std::string filename;
GridType grid_;
~UnitCube()
{
delete grid_;
}
GridType &grid ()
{
return *grid_;
}
};
#endif
......
......@@ -26,7 +26,8 @@ public:
else if( variant == 2 )
BasicUnitCube< dim >::insertSimplices( factory );
else
DUNE_THROW( Dune::NotImplemented, "Variant " << variant << " of UG unit cube not implemented." );
DUNE_THROW( Dune::NotImplemented, "Variant "
<< variant << " of UG unit cube not implemented." );
grid_ = factory.createGrid();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment