Skip to content
Snippets Groups Projects
Commit 4b2fb962 authored by Christian Engwer's avatar Christian Engwer
Browse files

first capabilities and a gridcheck that takes these capabilities into account

[[Imported from SVN: r1080]]
parent e16d38ac
No related branches found
No related tags found
No related merge requests found
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef __DUNE_CAPABILITIES_HH__
#define __DUNE_CAPABILITIES_HH__
namespace Dune
{
namespace Capabilities
{
template<class Grid>
struct hasLeafIterator
{
static const bool v = false;
};
template<class Grid, class Entity>
struct hasEntity
{
static const bool v = false;
};
template<class Grid>
struct isParallel
{
static const bool v = false;
};
}
}
#endif // __DUNE_CAPABILITIES_HH__
......@@ -38,5 +38,19 @@ template<class T1, class T2, class T3 = T1> struct Can_multiply {
Can_multiply() { void (*p)(T1,T2,T3) = constraints; }
};
/*
helper template so that compilation fails if condition is not true
*/
template <bool condition>
struct IsTrue
{
static void no() {};
};
template <>
struct IsTrue<true>
{
static void yes() {};
};
#endif
......@@ -33,9 +33,10 @@ check_PROGRAMS = $(NORMALTESTS) $(YPROG)
# define the programs
test_sgrid_SOURCES = test-sgrid.cc
test_sgrid_LDFLAGS = ../../common/libcommon.la
test_yaspgrid_SOURCES = test-yaspgrid.cc
test_yaspgrid_CPPFLAGS = $(AM_CPPFLAGS) $(MPI_CPPFLAGS)
test_yaspgrid_CXXFLAGS = $(AM_CPPFLAGS) $(MPI_CPPFLAGS)
# !! last lib a bit weird...
test_yaspgrid_LDFLAGS = $(MPI_LDFLAGS) $(MPI_LIBS) ../../common/libcommon.la
......
......@@ -11,17 +11,8 @@
*/
// helper template so that compilation fails if two constants are not
// equal
template <int a, int b>
struct Is_equal_int
{};
template <int a>
struct Is_equal_int<a, a>
{
static void yes() {};
};
#include "../../common/capabilities.hh"
#include "../../common/helpertemplates.hh"
// --- compile-time check of element-interface
......@@ -30,8 +21,8 @@ struct ElementInterface
{
static void check(Element &e)
{
Is_equal_int<dimw, Element::dimension>::yes();
Is_equal_int<dimw, Element::dimensionworld>::yes();
IsTrue<dimw == Element::dimension>::yes();
IsTrue<dimw == Element::dimensionworld>::yes();
typedef typename Element::ctype ctype;
......@@ -60,8 +51,8 @@ struct ElementInterface <Element, dimw, dimw>
{
static void check(Element &e)
{
Is_equal_int<dimw, Element::dimension>::yes();
Is_equal_int<dimw, Element::dimensionworld>::yes();
IsTrue<dimw == Element::dimension>::yes();
IsTrue<dimw == Element::dimensionworld>::yes();
// vertices have only a subset of functionality
e.type();
......@@ -108,8 +99,8 @@ struct EntityInterface
static void check (Entity &e)
{
// consistent?
Is_equal_int<codim, Entity::codimension>::yes();
Is_equal_int<dim, Entity::dimension>::yes();
IsTrue<codim == Entity::codimension>::yes();
IsTrue<dim == Entity::dimension>::yes();
// do the checking
DoEntityInterfaceCheck(e);
......@@ -125,9 +116,12 @@ struct EntityInterface
};
// recursive check of codim-0-entity methods count(), entity(), subIndex()
template <class Entity, int cd>
template <class Grid, int cd, bool hasEntity>
struct ZeroEntityMethodCheck
{
typedef typename Grid::template Traits<0>::Entity Entity;
typedef typename Grid::template Traits<cd>::Entity SubEntity;
typedef typename Grid::template Traits<cd-1>::Entity NextSubEntity;
static void check(Entity &e)
{
e.template count<cd>();
......@@ -135,7 +129,28 @@ struct ZeroEntityMethodCheck
e.template subIndex<cd>(0);
// recursively check on
ZeroEntityMethodCheck<Entity, cd - 1>();
ZeroEntityMethodCheck<Grid, cd - 1,
Dune::Capabilities::hasEntity<Grid, NextSubEntity>::v >();
}
ZeroEntityMethodCheck ()
{
c = check;
}
void (*c)(Entity &e);
};
// just the recursion if the grid does not know about this codim-entity
template<class Grid, int cd>
struct ZeroEntityMethodCheck<Grid, cd, false>
{
typedef typename Grid::template Traits<0>::Entity Entity;
typedef typename Grid::template Traits<cd>::Entity SubEntity;
typedef typename Grid::template Traits<cd-1>::Entity NextSubEntity;
static void check(Entity &e)
{
// recursively check on
ZeroEntityMethodCheck<Grid, cd - 1,
Dune::Capabilities::hasEntity<Grid, NextSubEntity>::v >();
}
ZeroEntityMethodCheck ()
{
......@@ -145,9 +160,29 @@ struct ZeroEntityMethodCheck
};
// end recursive checking
template <class Entity>
struct ZeroEntityMethodCheck<Entity, 0>
template <class Grid>
struct ZeroEntityMethodCheck<Grid, 0, true>
{
typedef typename Grid::template Traits<0>::Entity Entity;
static void check(Entity &e)
{
e.template count<0>();
e.template entity<0>(0);
e.template subIndex<0>(0);
}
ZeroEntityMethodCheck ()
{
c = check;
}
void (*c)(Entity &e);
};
// end recursive checking - same as true
// ... codim 0 is always needed
template <class Grid>
struct ZeroEntityMethodCheck<Grid, 0, false>
{
typedef typename Grid::template Traits<0>::Entity Entity;
static void check(Entity &e)
{
e.template count<0>();
......@@ -166,18 +201,20 @@ template <class Grid, int dim>
struct EntityInterface<Grid, 0, dim>
{
typedef typename Grid::template Traits<0>::Entity Entity;
typedef typename Grid::template Traits<dim>::Entity SubEntity;
static void check (Entity &e)
{
// consistent?
Is_equal_int<0, Entity::codimension>::yes();
Is_equal_int<dim, Entity::dimension>::yes();
IsTrue<0 == Entity::codimension>::yes();
IsTrue<dim == Entity::dimension>::yes();
// do the common checking
DoEntityInterfaceCheck(e);
// special codim-0-entity methods which are parametrized by a codimension
ZeroEntityMethodCheck<Entity, dim>();
ZeroEntityMethodCheck
<Grid, dim, Dune::Capabilities::hasEntity<Grid, SubEntity>::v >();
// grid hierarchy
e.father();
......@@ -217,8 +254,8 @@ struct EntityInterface<Grid, dim, dim>
static void check (Entity &e)
{
// consistent?
Is_equal_int<dim, Entity::codimension>::yes();
Is_equal_int<dim, Entity::dimension>::yes();
IsTrue<dim == Entity::codimension>::yes();
IsTrue<dim == Entity::dimension>::yes();
// run common test
DoEntityInterfaceCheck(e);
......@@ -231,6 +268,31 @@ struct EntityInterface<Grid, dim, dim>
void (*c)(Entity&);
};
template<class Grid, bool hasLeaf>
struct LeafInterface
{
static void check(Grid &g)
{
g.leafbegin(0);
g.leafend(0);
}
LeafInterface()
{
c = check;
}
void (*c)(Grid&);
};
template<class Grid>
struct LeafInterface<Grid, false>
{
static void check(Grid &g) {}
LeafInterface()
{
c = check;
}
void (*c)(Grid&);
};
template <class Grid>
struct GridInterface
{
......@@ -256,8 +318,7 @@ struct GridInterface
g.template lbegin<0>(0);
g.template lend<0>(0);
g.leafbegin(0);
g.leafend(0);
LeafInterface< Grid, Dune::Capabilities::hasLeafIterator<Grid>::v >();
// recursively check entity-interface
EntityInterface<Grid, 0, Grid::dimension>();
......@@ -292,5 +353,5 @@ void gridcheck (Grid &g)
/*
* now the runtime-tests
*/
g.checkIF();
// g.checkIF();
};
#!/bin/sh
# run lamboot if possible
lamboot 2>&1 > /dev/null
if which lamboot; then
lamboot 2>&1 > /dev/null
fi
# start test and abort on fail
set -e
......@@ -9,4 +11,6 @@ mpirun -np 1 test-yaspgrid
set +e
# possibly stop LAM again
lamhalt 2>&1 > /dev/null
if which lamhalt; then
lamhalt 2>&1 > /dev/null
fi
\ No newline at end of file
......@@ -8,6 +8,8 @@
#include "common/grid.hh" // the grid base classes
#include "yaspgrid/grids.hh" // the yaspgrid base classes
#include "../common/stack.hh" // the stack class
#include "../common/capabilities.hh" // the capabilities
#include "../../common/helpertemplates.hh"
/*! \file yaspgrid.hh
Yasppergrid stands for yet another structured parallel grid.
......@@ -33,7 +35,6 @@ namespace Dune {
@{
*/
//************************************************************************
/*! define name for floating point type used for coordinates in yaspgrid.
You can change the type for coordinates by changing this single typedef.
......@@ -529,6 +530,7 @@ namespace Dune {
template<int cc>
YaspLevelIterator<cc,dim,dimworld,All_Partition> entity (int i)
{
IsTrue< ( cc == dim || cc == 0 ) >::yes();
// coordinates of the cell == coordinates of lower left corner
if (cc==dim)
{
......@@ -1255,6 +1257,7 @@ namespace Dune {
template<int cd, PartitionIteratorType pitype>
YaspLevelIterator<cd,dim,dimworld,pitype> lbegin (int level)
{
IsTrue< ( cd == dim || cd == 0 ) >::yes();
YGLI g = _mg.begin(level);
if (cd==0) // the elements
{
......@@ -1275,6 +1278,7 @@ namespace Dune {
template<int cd, PartitionIteratorType pitype>
YaspLevelIterator<cd,dim,dimworld,pitype> lend (int level)
{
IsTrue< ( cd == dim || cd == 0 ) >::yes();
YGLI g = _mg.begin(level);
if (cd==0) // the elements
{
......@@ -1295,6 +1299,7 @@ namespace Dune {
template<int cd>
YaspLevelIterator<cd,dim,dimworld,All_Partition> lbegin (int level)
{
IsTrue< ( cd == dim || cd == 0 ) >::yes();
YGLI g = _mg.begin(level);
if (cd==0) // the elements
{
......@@ -1311,6 +1316,7 @@ namespace Dune {
template<int cd>
YaspLevelIterator<cd,dim,dimworld,All_Partition> lend (int level)
{
IsTrue< ( cd == dim || cd == 0 ) >::yes();
YGLI g = _mg.begin(level);
if (cd==0) // the elements
{
......@@ -1331,15 +1337,15 @@ namespace Dune {
}
//! return size (= distance in graph) of ghost region
int ghost_size (int level, int codim)
int ghost_size (int level, int codim) const
{
return 0;
}
//! number of grid entities per level and codim
int size (int level, int codim)
int size (int level, int codim) const
{
YGLI g = _mg.begin(level);
YGLI g = const_cast<YaspGrid<dim, dimworld>*>(this)->_mg.begin(level);
if (codim==0)
{
return g.cell_overlap().totalsize();
......@@ -1365,6 +1371,7 @@ namespace Dune {
template<class T, template<class> class P, int codim>
void communicate (T& t, InterfaceType iftype, CommunicationDirection dir, int level)
{
IsTrue< ( codim == dim || codim == 0 ) >::yes();
// access to grid level
YGLI g = _mg.begin(level);
......@@ -1484,9 +1491,30 @@ namespace Dune {
YMG _mg;
};
/** @} end documentation group */
namespace Capabilities
{
template<int dim,int dimw>
struct hasLeafIterator< YaspGrid<dim,dimw> >
{
static const bool v = false;
};
/** @} end documentation group */
template<int dim, int dimw>
struct hasEntity< YaspGrid<dim,dimw>, YaspEntity<0,dim,dimw> >
{
static const bool v = true;
};
template<int dim, int dimw>
struct hasEntity< YaspGrid<dim,dimw>, YaspEntity<dim,dim,dimw> >
{
static const bool v = true;
};
}
} // end namespace
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment