Commit a375d073 authored by Martin Nolte's avatar Martin Nolte

also use grid factory for AlbertaGrid

[[Imported from SVN: r222]]
parent 055d0ff3
......@@ -4,6 +4,115 @@
#define UNITCUBE_HH
#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>
......
......@@ -5,47 +5,38 @@
#if HAVE_ALBERTA
#include <dune/grid/albertagrid.hh>
#include <dune/grid/albertagrid/gridfactory.hh>
// AlbertaGrid 2d, variant 1 (2 triangles) specialization
#if ALBERTA_DIM == 2 && ALBERTA_WORLD_DIM == 2
template<>
class UnitCube<Dune::AlbertaGrid<2,2>,1>
template< int dim >
class UnitCube< Dune::AlbertaGrid< dim, dim >, 1 >
: public BasicUnitCube< dim >
{
public:
typedef Dune::AlbertaGrid<2,2> GridType;
UnitCube () : grid_("grids/2dgrid.al")
{}
Dune::AlbertaGrid<2,2>& grid ()
{
return grid_;
}
typedef Dune::AlbertaGrid< dim, dim > GridType;
private:
Dune::AlbertaGrid<2,2> grid_;
};
#endif
GridType *grid_;
// AlbertaGrid 3d, variant 1 (6 tetrahedra) specialization
#if ALBERTA_DIM == 3 && ALBERTA_WORLD_DIM == 3
template<>
class UnitCube<Dune::AlbertaGrid<3,3>,1>
{
public:
typedef Dune::AlbertaGrid<3,3> GridType;
UnitCube () : grid_("grids/3dgrid.al")
{}
UnitCube ()
{
Dune::GridFactory< GridType > factory;
BasicUnitCube< dim >::insertVertices( factory );
BasicUnitCube< dim >::insertSimplices( factory );
grid_ = factory.createGrid( "UnitCube", true );
}
Dune::AlbertaGrid<3,3>& grid ()
~UnitCube ()
{
return grid_;
Dune::GridFactory< GridType >::destroyGrid( grid_ );
}
private:
Dune::AlbertaGrid<3,3> grid_;
GridType &grid ()
{
return *grid_;
}
};
#endif
#endif
#endif // #if HAVE_ALBERTA
#endif
......@@ -6,138 +6,41 @@
#if HAVE_UG
#include <dune/grid/uggrid.hh>
// UGGrid 3d, variant 1 (hexahedra) specialization
template<int variant>
class UnitCube<Dune::UGGrid<3>,variant>
template< int dim, int variant >
class UnitCube< Dune::UGGrid< dim >, variant >
: public BasicUnitCube< dim >
{
public:
typedef Dune::UGGrid<3> GridType;
UnitCube ()
{
// Start grid creation
Dune::GridFactory<GridType> factory;
// Insert vertices
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);
if (variant==1) {
// Insert element
std::vector<unsigned int> cornerIDs(8);
for (int i=0; i<8; i++)
cornerIDs[i] = i;
factory.insertElement(Dune::GeometryType(Dune::GeometryType::cube,3), cornerIDs);
} else {
// Insert elements
std::vector<unsigned int> cornerIDs(4);
cornerIDs[0] = 0; cornerIDs[1] = 1; cornerIDs[2] = 2; cornerIDs[3] = 4;
factory.insertElement(Dune::GeometryType(Dune::GeometryType::simplex,3), cornerIDs);
cornerIDs[0] = 1; cornerIDs[1] = 3; cornerIDs[2] = 2; cornerIDs[3] = 7;
factory.insertElement(Dune::GeometryType(Dune::GeometryType::simplex,3), cornerIDs);
cornerIDs[0] = 1; cornerIDs[1] = 7; cornerIDs[2] = 2; cornerIDs[3] = 4;
factory.insertElement(Dune::GeometryType(Dune::GeometryType::simplex,3), cornerIDs);
cornerIDs[0] = 1; cornerIDs[1] = 7; cornerIDs[2] = 4; cornerIDs[3] = 5;
factory.insertElement(Dune::GeometryType(Dune::GeometryType::simplex,3), cornerIDs);
cornerIDs[0] = 4; cornerIDs[1] = 7; cornerIDs[2] = 2; cornerIDs[3] = 6;
factory.insertElement(Dune::GeometryType(Dune::GeometryType::simplex,3), cornerIDs);
}
// Finish initialization
grid_ = factory.createGrid();
}
GridType& grid ()
{
return *grid_;
}
typedef Dune::UGGrid< dim > GridType;
private:
GridType* grid_;
};
// UGGrid 2d,
template<int variant>
class UnitCube<Dune::UGGrid<2>, variant>
{
public:
typedef Dune::UGGrid<2> GridType;
UnitCube ()
{
// Start grid creation
Dune::GridFactory<GridType> factory;
// Insert vertices
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);
if (variant==1) {
// Insert element
std::vector<unsigned int> cornerIDs(4);
cornerIDs[0] = 0;
cornerIDs[1] = 1;
cornerIDs[2] = 2;
cornerIDs[3] = 3;
factory.insertElement(Dune::GeometryType(Dune::GeometryType::cube,2), cornerIDs);
} else {
// Insert element
std::vector<unsigned int> cornerIDs(3);
cornerIDs[0] = 0; cornerIDs[1] = 1; cornerIDs[2] = 2;
factory.insertElement(Dune::GeometryType(Dune::GeometryType::simplex,2), cornerIDs);
cornerIDs[0] = 2; cornerIDs[1] = 1; cornerIDs[2] = 3;
factory.insertElement(Dune::GeometryType(Dune::GeometryType::simplex,2), cornerIDs);
}
// Finish initialization
Dune::GridFactory< GridType > factory;
BasicUnitCube< dim >::insertVertices( factory );
if( variant == 1 )
BasicUnitCube< dim >::insertCubes( factory );
else if( variant == 2 )
BasicUnitCube< dim >::insertSimplices( factory );
else
DUNE_THROW( Dune::NotImplemented, "Variant " << variant << " of UG unit cube not implemented." );
grid_ = factory.createGrid();
}
GridType& grid ()
~UnitCube ()
{
return *grid_;
delete grid_;
}
private:
GridType* grid_;
GridType &grid ()
{
return *grid_;
}
};
#endif
#endif // #if HAVE_UG
#endif
......@@ -14,15 +14,21 @@
#include "functors.hh"
#include "unitcube.hh"
#ifdef GRIDDIM
const int dimGrid = GRIDDIM;
#endif
//! supply functor
template<class Grid>
void dowork (Grid& grid)
void dowork ( Grid &grid, int refSteps = 5 )
{
// make function object
Exp<typename Grid::ctype,Grid::dimension> f;
// refine the grid
grid.globalRefine(5);
grid.globalRefine( refSteps );
// call the visualization functions
elementdata(grid,f);
......@@ -35,29 +41,32 @@ int main(int argc, char **argv)
Dune::MPIHelper::instance(argc,argv);
// start try/catch block to get error messages from dune
try {
try
{
/*
UnitCube<Dune::OneDGrid,1> uc0;
UnitCube<Dune::YaspGrid<3>,1> uc1;
UnitCube<Dune::YaspGrid<2>,1> uc2;
UnitCube<Dune::SGrid<1,1>,1> uc3;
UnitCube<Dune::SGrid<2,2>,1> uc4;
UnitCube<Dune::SGrid<3,3>,1> uc5;
#if HAVE_UG
UnitCube<Dune::UGGrid<3>,2> uc6;
#endif
#if HAVE_ALBERTA
#if ALBERTA_DIM==2
UnitCube<Dune::AlbertaGrid<2,2>,1> uc7;
#endif
#endif
*/
UnitCube<Dune::SGrid<2,2>,1> uc4;
dowork(uc4.grid());
#if HAVE_UG
UnitCube< Dune::UGGrid< dimGrid >, 2 > uc6;
dowork( uc6.grid(), 3 );
#endif
#ifdef GRIDDIM
#if HAVE_ALBERTA
UnitCube< Dune::AlbertaGrid< dimGrid, dimGrid >, 1 > uc7;
// note: The 3d cube cannot be bisected recursively
dowork( uc7.grid(), (dimGrid < 3 ? 6 : 0 ) );
#endif
#endif
UnitCube< Dune::SGrid< dimGrid, dimGrid >, 1 > uc4;
dowork( uc4.grid(), 3 );
#if HAVE_ALUGRID
UnitCube<Dune::ALUSimplexGrid<3,3> ,1> uc8;
dowork(uc8.grid());
UnitCube< Dune::ALUSimplexGrid< dimGrid, dimGrid > , 1 > uc8;
dowork( uc8.grid(), 3 );
#endif
}
catch (std::exception & e) {
......
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