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

>From the metting minutes:

- GeometryType vs. topologyId
  Both shall be merged into GeometryType
    * method id() shall return the topologyId
    * method basicType() shall be extended to return not presentable

Changes:
- GeometryType uses the topologyId internally to represent all types
  covered by topologyId
- an additional flag marks none-state
- new BasicType extended for all topologyId-types not coverd by BasicType
- new method id()

Tested with current dune-grid tests

[[Imported from SVN: r6255]]
parent 69b40ce1
No related branches found
No related tags found
No related merge requests found
...@@ -28,69 +28,154 @@ namespace Dune { ...@@ -28,69 +28,154 @@ namespace Dune {
cube, //!< Cube element in any nonnegative dimension cube, //!< Cube element in any nonnegative dimension
pyramid, //!< Four sided pyramid in three dimensions pyramid, //!< Four sided pyramid in three dimensions
prism, //!< Prism element in three dimensions prism, //!< Prism element in three dimensions
extended, //!< Other, more general geometry, representable as topologyId
none //!< Generic element in any nonnegative dimension none //!< Generic element in any nonnegative dimension
}; };
private: private:
/** \brief Basic type of the element */ /** \brief Topology Id element */
BasicType basicType_; unsigned int topologyId_;
/** \brief Dimension of the element */ /** \brief Dimension of the element */
unsigned int dim_; unsigned char dim_ : 7;
/** \brief bool if this is none-type */
bool none_ : 1;
public: public:
/** \brief Default constructor, not initializing anything */ /** \brief Default constructor, not initializing anything */
GeometryType () GeometryType ()
: topologyId_(0), dim_(0), none_(true)
{} {}
/** \brief Constructor */ /** \brief Constructor */
GeometryType(BasicType basicType, unsigned int dim) GeometryType(BasicType basicType, unsigned int dim)
: basicType_(basicType), dim_(dim) : topologyId_(0), dim_(dim), none_(false)
{
if (dim < 2)
return;
switch( basicType )
{
case GeometryType::simplex :
makeSimplex(dim);
break;
case GeometryType::cube :
makeCube(dim);
break;
case GeometryType::pyramid :
if (dim == 3)
makePyramid();
break;
case GeometryType::prism :
if (dim == 3)
makePrism();
break;
case GeometryType::none :
makeNone(dim);
break;
default :
DUNE_THROW( RangeError,
"Invalid basic geometry type: " << basicType << " for dimension " << dim << "." );
}
}
/** \brief Constructor */
GeometryType(unsigned int topologyId, unsigned int dim)
: topologyId_(topologyId), dim_(dim), none_(false)
{} {}
/** \brief Constructor for vertices and segments /** \brief Constructor */
\todo Add check for dim={0,1} when compiled with a suitable flag template<class TopologyType>
*/ GeometryType(TopologyType t)
explicit GeometryType(unsigned int dim) : topologyId_(TopologyType::id), dim_(TopologyType::dimension), none_(false)
: basicType_(cube), dim_(dim)
{} {}
/** \brief Constructor for vertices and segments */
explicit GeometryType(unsigned int dim)
: topologyId_(0), dim_(dim), none_(false)
{
assert(dim < 2);
}
/** \brief Constructor for vertices and segments */
explicit GeometryType(int dim)
: topologyId_(0), dim_(dim), none_(false)
{
assert(dim < 2);
}
/** @name Setup Methods */ /** @name Setup Methods */
/*@{*/ /*@{*/
/** \brief Make a vertex */ /** \brief Make a vertex */
void makeVertex() {dim_ = 0;} void makeVertex() {
none_ = false;
dim_ = 0;
topologyId_ = 0;
}
/** \brief Make a line segment */ /** \brief Make a line segment */
void makeLine() {dim_ = 1;} void makeLine() {
none_ = false;
dim_ = 1;
topologyId_ = 0;
}
/** \brief Make a triangle */ /** \brief Make a triangle */
void makeTriangle() {basicType_ = simplex; dim_ = 2;} void makeTriangle() {
makeSimplex(2);
}
/** \brief Make a quadrilateral */ /** \brief Make a quadrilateral */
void makeQuadrilateral() {basicType_ = cube; dim_ = 2;} void makeQuadrilateral() {
makeCube(2);
}
/** \brief Make a tetrahedron */ /** \brief Make a tetrahedron */
void makeTetrahedron() {basicType_ = simplex; dim_ = 3;} void makeTetrahedron() {
makeSimplex(3);
}
/** \brief Make a pyramid */ /** \brief Make a pyramid */
void makePyramid() {basicType_ = pyramid; dim_ = 3;} void makePyramid() {
none_ = false;
dim_ = 3;
topologyId_ = 0b0011;
}
/** \brief Make a prism */ /** \brief Make a prism */
void makePrism() {basicType_ = prism; dim_ = 3;} void makePrism() {
none_ = false;
dim_ = 3;
topologyId_ = 0b0101; // (1 << (dim_-1)) - 1;
}
/** \brief Make a hexahedron */ /** \brief Make a hexahedron */
void makeHexahedron() {basicType_ = cube; dim_ = 3;} void makeHexahedron() {
makeCube(3);
}
/** \brief Make a simplex of given dimension */ /** \brief Make a simplex of given dimension */
void makeSimplex(unsigned int dim) {basicType_ = simplex; dim_ = dim;} void makeSimplex(unsigned int dim) {
none_ = false;
dim_ = dim;
topologyId_ = 0;
}
/** \brief Make a hypercube of given dimension */ /** \brief Make a hypercube of given dimension */
void makeCube(unsigned int dim) {basicType_ = cube; dim_ = dim;} void makeCube(unsigned int dim) {
none_ = false;
dim_ = dim;
topologyId_ = ((dim>1) ? ((1 << dim) - 1) : 0);
}
/** \brief Make a singular of given dimension */ /** \brief Make a singular of given dimension */
void makeNone(unsigned int dim) {basicType_ = none; dim_ = dim;} void makeNone(unsigned int dim) {
none_ = true;
dim_ = dim;
topologyId_ = 0;
}
/*@}*/ /*@}*/
...@@ -98,43 +183,84 @@ namespace Dune { ...@@ -98,43 +183,84 @@ namespace Dune {
/** @name Query Methods */ /** @name Query Methods */
/*@{*/ /*@{*/
/** \brief Return true if entity is a vertex */ /** \brief Return true if entity is a vertex */
bool isVertex() const {return dim_==0;} bool isVertex() const {
return dim_==0;
}
/** \brief Return true if entity is a line segment */ /** \brief Return true if entity is a line segment */
bool isLine() const {return dim_==1;} bool isLine() const {
return dim_==1;
}
/** \brief Return true if entity is a triangle */ /** \brief Return true if entity is a triangle */
bool isTriangle() const {return basicType_==simplex && dim_==2;} bool isTriangle() const {
return ! none_ && dim_==2 && (topologyId_ | 1) == 0b0001;
}
/** \brief Return true if entity is a quadrilateral */ /** \brief Return true if entity is a quadrilateral */
bool isQuadrilateral() const {return basicType_==cube && dim_==2;} bool isQuadrilateral() const {
return ! none_ && dim_==2 && (topologyId_ | 1) == 0b0011;
}
/** \brief Return true if entity is a tetrahedron */ /** \brief Return true if entity is a tetrahedron */
bool isTetrahedron() const {return basicType_==simplex && dim_==3;} bool isTetrahedron() const {
return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0001;
}
/** \brief Return true if entity is a pyramid */ /** \brief Return true if entity is a pyramid */
bool isPyramid() const {return basicType_==pyramid;} bool isPyramid() const {
return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0011;
}
/** \brief Return true if entity is a prism */ /** \brief Return true if entity is a prism */
bool isPrism() const {return basicType_==prism;} bool isPrism() const {
return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0101;
}
/** \brief Return true if entity is a hexahedron */ /** \brief Return true if entity is a hexahedron */
bool isHexahedron() const {return basicType_==cube && dim_==3;} bool isHexahedron() const {
return ! none_ && dim_==3 && (topologyId_ | 1) == 0b0111;
}
/** \brief Return true if entity is a simplex of any dimension */ /** \brief Return true if entity is a simplex of any dimension */
bool isSimplex() const {return basicType_==simplex || dim_ < 2;} bool isSimplex() const {
return ! none_ && (topologyId_ | 1) == 1;
}
/** \brief Return true if entity is a cube of any dimension */ /** \brief Return true if entity is a cube of any dimension */
bool isCube() const {return basicType_==cube || dim_ < 2;} bool isCube() const {
return ! none_ && (topologyId_ | 1) == (unsigned int)((1<<dim_)-1);
}
/** \brief Return true if entity is a singular of any dimension */ /** \brief Return true if entity is a singular of any dimension */
bool isNone() const {return basicType_==none;} bool isNone() const {
return none_;
}
/** \brief Return dimension of the type */
unsigned int dim() const {
return dim_;
}
/** \brief Return dimension of the entity */ /** \brief Return the basic type of the type */
unsigned int dim() const {return dim_;} BasicType basicType() const DUNE_DEPRECATED {
if (isSimplex())
return GeometryType::simplex;
if (isCube())
return GeometryType::cube;
if (isPyramid())
return GeometryType::pyramid;
if (isPrism())
return GeometryType::prism;
if (isNone())
return GeometryType::none;
return GeometryType::extended;
}
/** \brief Return the basic type of the entity */ /** \brief Return the topology id the type */
BasicType basicType() const {return basicType_;} unsigned int id() const {
return topologyId_;
}
/*@}*/ /*@}*/
...@@ -142,9 +268,15 @@ namespace Dune { ...@@ -142,9 +268,15 @@ namespace Dune {
all BasicTypes are equal. all BasicTypes are equal.
*/ */
bool operator==(const GeometryType& other) const { bool operator==(const GeometryType& other) const {
return ( (dim()==0 && other.dim()==0) return ( ( none_ == other.none_ )
|| (dim()==1 && other.dim()==1) && ( ( none_ == true )
|| (dim()==other.dim() && basicType_==other.basicType_) ); || ( ( dim_ == other.dim_ )
&& ( ( dim_ < 2 )
|| ( topologyId_ == other.topologyId_ )
)
)
)
);
} }
/** \brief Check for inequality */ /** \brief Check for inequality */
...@@ -154,39 +286,46 @@ namespace Dune { ...@@ -154,39 +286,46 @@ namespace Dune {
/** \brief lesser operation for use with maps */ /** \brief lesser operation for use with maps */
bool operator < (const GeometryType& other) const { bool operator < (const GeometryType& other) const {
if (dim() != other.dim()) if (none)
return dim() < other.dim();
else if (dim()==0 || dim()==1)
return false; return false;
if (other.none)
return basicType_ < other.basicType_; return true;
return ( ( dim_ < other.dim_ )
|| ( !( other.dim_ < dim_ )
&& ( topologyId_ < other.topologyId_ ) )
);
} }
friend inline std::ostream& operator<< (std::ostream& s, const GeometryType& a);
}; };
/** \brief Prints the type to an output stream */ /** \brief Prints the type to an output stream */
inline std::ostream& operator<< (std::ostream& s, const GeometryType& a) inline std::ostream& operator<< (std::ostream& s, const GeometryType& a)
{ {
switch (a.basicType_) { if (a.isSimplex())
case GeometryType::simplex : {
s << "(simplex, " << a.dim_ << ")"; s << "(__simplex, " << a.dim() << ")";
break; return s;
case GeometryType::cube : }
s << "(cube, " << a.dim_ << ")"; if (a.isCube())
break; {
case GeometryType::pyramid : s << "(cube, " << a.dim() << ")";
s << "pyramid"; return s;
break; }
case GeometryType::prism : if (a.isPyramid())
s << "prism"; {
break; s << "(pyramid, 3)";
case GeometryType::none : return s;
s << "(none, " << a.dim_ << ")"; }
break; if (a.isPrism())
default : {
s << "invalid geometry type"; s << "(prism, 3)";
return s;
}
if (a.isNone())
{
s << "(none, " << a.dim() << ")";
return s;
} }
s << "(other [" << a.id() << "], " << a.dim() << ")";
return s; return s;
} }
...@@ -206,11 +345,13 @@ namespace Dune { ...@@ -206,11 +345,13 @@ namespace Dune {
case GeometryType::prism : case GeometryType::prism :
s << "prism"; s << "prism";
break; break;
case GeometryType::extended :
s << "other";
case GeometryType::none : case GeometryType::none :
s << "none"; s << "none";
break; break;
default : default :
s << "[unknown GeometryType::BasicType: " << int(type) << "]"; DUNE_THROW(Exception, "invalid GeometryType::BasicType");
} }
return s; return s;
} }
......
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