__assume for switch (element_type)

This commit is contained in:
Joachim Schöberl 2016-01-07 13:37:48 +01:00
parent b3451ed2e4
commit 1d6c7b283a
7 changed files with 62 additions and 63 deletions

View File

@ -35,6 +35,22 @@
#endif #endif
#ifndef __assume
#ifdef __GNUC__
#define __assume(cond) if (!(cond)) __builtin_unreachable(); else;
#else
#define __assume(cond)
#endif
#endif
#define noDEMOVERSION #define noDEMOVERSION
#define noDEVELOP #define noDEVELOP
#define noSTEP #define noSTEP

View File

@ -251,7 +251,11 @@ namespace netgen
namespace netgen namespace netgen
{ {
#ifdef __GNUC__
#define NGX_INLINE __attribute__ ((__always_inline__)) inline
#else
#define NGX_INLINE inline #define NGX_INLINE inline
#endif
#include <nginterface_v2_impl.hpp> #include <nginterface_v2_impl.hpp>
} }

View File

@ -114,6 +114,7 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (int nr) const
Ng_Element ret; Ng_Element ret;
ret.type = NG_ELEMENT_TYPE(el.GetType()); ret.type = NG_ELEMENT_TYPE(el.GetType());
ret.index = el.GetIndex(); ret.index = el.GetIndex();
ret.points.num = el.GetNP(); ret.points.num = el.GetNP();
ret.points.ptr = (int*)&el[0]; ret.points.ptr = (int*)&el[0];
@ -126,8 +127,6 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (int nr) const
ret.faces.num = MeshTopology::GetNFaces (el.GetType()); ret.faces.num = MeshTopology::GetNFaces (el.GetType());
ret.faces.ptr = (T_FACE2*)mesh->GetTopology().GetElementFacesPtr (nr); ret.faces.ptr = (T_FACE2*)mesh->GetTopology().GetElementFacesPtr (nr);
// ret.is_curved = mesh->GetCurvedElements().IsElementCurved(nr);
ret.is_curved = el.IsCurved(); ret.is_curved = el.IsCurved();
return ret; return ret;
} }

View File

@ -100,7 +100,7 @@ namespace netgen
mutable int elementsearchtreets; mutable int elementsearchtreets;
/// element -> face, element -> edge etc ... /// element -> face, element -> edge etc ...
class MeshTopology * topology; MeshTopology * topology;
/// methods for high order elements /// methods for high order elements
class CurvedElements * curvedelems; class CurvedElements * curvedelems;
@ -655,19 +655,19 @@ namespace netgen
DLL_HEADER bool PureTrigMesh (int faceindex = 0) const; DLL_HEADER bool PureTrigMesh (int faceindex = 0) const;
DLL_HEADER bool PureTetMesh () const; DLL_HEADER bool PureTetMesh () const;
const class MeshTopology & GetTopology () const const MeshTopology & GetTopology () const
{ return *topology; } { return *topology; }
DLL_HEADER void UpdateTopology(); DLL_HEADER void UpdateTopology();
class CurvedElements & GetCurvedElements () const class CurvedElements & GetCurvedElements () const
{ return *curvedelems; } { return *curvedelems; }
DLL_HEADER void BuildCurvedElements (const class Refinement * ref, int aorder, bool arational = false); DLL_HEADER void BuildCurvedElements (const class Refinement * ref, int aorder, bool arational = false);
const class AnisotropicClusters & GetClusters () const const class AnisotropicClusters & GetClusters () const
{ return *clusters; } { return *clusters; }

View File

@ -22,6 +22,7 @@ namespace netgen
#include "msghandler.hpp" #include "msghandler.hpp"
#include "meshtype.hpp" #include "meshtype.hpp"
#include "localh.hpp" #include "localh.hpp"
#include "topology.hpp"
#include "meshclass.hpp" #include "meshclass.hpp"
#include "global.hpp" #include "global.hpp"
@ -48,7 +49,6 @@ namespace netgen
#include "findip.hpp" #include "findip.hpp"
#include "findip2.hpp" #include "findip2.hpp"
#include "topology.hpp"
#include "curvedelems.hpp" #include "curvedelems.hpp"
#include "clusters.hpp" #include "clusters.hpp"

View File

@ -17,7 +17,7 @@ namespace netgen
enum ELEMENT_TYPE { enum ELEMENT_TYPE : unsigned char {
SEGMENT = 1, SEGMENT3 = 2, SEGMENT = 1, SEGMENT3 = 2,
TRIG = 10, QUAD=11, TRIG6 = 12, QUAD6 = 13, QUAD8 = 14, TRIG = 10, QUAD=11, TRIG6 = 12, QUAD6 = 13, QUAD8 = 14,
TET = 20, TET10 = 21, TET = 20, TET10 = 21,
@ -292,7 +292,7 @@ namespace netgen
/// surface nr /// surface nr
int index:16; int index:16;
/// ///
ELEMENT_TYPE typ:6; ELEMENT_TYPE typ;
/// number of points /// number of points
unsigned int np:4; unsigned int np:4;
bool badel:1; bool badel:1;
@ -545,7 +545,7 @@ namespace netgen
/// point numbers /// point numbers
PointIndex pnum[ELEMENT_MAXPOINTS]; PointIndex pnum[ELEMENT_MAXPOINTS];
/// ///
ELEMENT_TYPE typ:6; ELEMENT_TYPE typ;
/// number of points (4..tet, 5..pyramid, 6..prism, 8..hex, 10..quad tet, 12..quad prism) /// number of points (4..tet, 5..pyramid, 6..prism, 8..hex, 10..quad tet, 12..quad prism)
int np:5; int np:5;
/// ///
@ -601,27 +601,27 @@ namespace netgen
/// ///
int GetNP () const { return np; } int GetNP () const { return np; }
/// ///
int GetNV() const short int GetNV() const
{ {
__assume(typ >= TET && typ <= HEX);
switch (typ) switch (typ)
{ {
case TET: case TET:
case TET10: case TET10:
return 4; return 4;
case PRISM12: case PRISM12:
case PRISM: case PRISM:
return 6; return 6;
case PYRAMID: case PYRAMID:
return 5; return 5;
case HEX: case HEX:
return 8; return 8;
default: default: // not a 3D element
#ifdef DEBUG #ifdef DEBUG
PrintSysError ("Element3d::GetNV not implemented for typ ", typ) PrintSysError ("Element3d::GetNV not implemented for typ ", typ)
#endif #endif
; return -1;
} }
return np;
} }
bool operator==(const Element & el2) const; bool operator==(const Element & el2) const;

View File

@ -12,6 +12,8 @@
(Elements, Faces, Edges, Vertices (Elements, Faces, Edges, Vertices
*/ */
namespace netgen
{
struct T_EDGE struct T_EDGE
{ {
@ -67,10 +69,10 @@ public:
int GetNEdges () const { return edge2vert.Size(); } int GetNEdges () const { return edge2vert.Size(); }
int GetNFaces () const { return face2vert.Size(); } int GetNFaces () const { return face2vert.Size(); }
static inline int GetNVertices (ELEMENT_TYPE et); static inline short int GetNVertices (ELEMENT_TYPE et);
static inline int GetNPoints (ELEMENT_TYPE et); static inline short int GetNPoints (ELEMENT_TYPE et);
static inline int GetNEdges (ELEMENT_TYPE et); static inline short int GetNEdges (ELEMENT_TYPE et);
static inline int GetNFaces (ELEMENT_TYPE et); static inline short int GetNFaces (ELEMENT_TYPE et);
static const Point3d * GetVertices (ELEMENT_TYPE et); static const Point3d * GetVertices (ELEMENT_TYPE et);
inline static const ELEMENT_EDGE * GetEdges1 (ELEMENT_TYPE et); inline static const ELEMENT_EDGE * GetEdges1 (ELEMENT_TYPE et);
@ -78,19 +80,11 @@ public:
inline static const ELEMENT_FACE * GetFaces1 (ELEMENT_TYPE et); inline static const ELEMENT_FACE * GetFaces1 (ELEMENT_TYPE et);
inline static const ELEMENT_FACE * GetFaces0 (ELEMENT_TYPE et); inline static const ELEMENT_FACE * GetFaces0 (ELEMENT_TYPE et);
// int GetSegmentEdge (int segnr) const { return abs(segedges[segnr-1]); }
// int GetSegmentEdgeOrientation (int segnr) const { return sgn(segedges[segnr-1]); }
// int GetEdge (SegmentIndex segnr) const { return abs(segedges[segnr])-1; }
int GetSegmentEdge (int segnr) const { return segedges[segnr-1].nr+1; } int GetSegmentEdge (int segnr) const { return segedges[segnr-1].nr+1; }
int GetEdge (SegmentIndex segnr) const { return segedges[segnr].nr; } int GetEdge (SegmentIndex segnr) const { return segedges[segnr].nr; }
void GetSegmentEdge (int segnr, int & enr, int & orient) const void GetSegmentEdge (int segnr, int & enr, int & orient) const
{ {
/*
enr = abs(segedges.Get(segnr));
orient = segedges.Get(segnr) > 0 ? 1 : -1;
*/
enr = segedges.Get(segnr).nr+1; enr = segedges.Get(segnr).nr+1;
orient = segedges.Get(segnr).orient; orient = segedges.Get(segnr).orient;
} }
@ -160,7 +154,7 @@ public:
inline int MeshTopology :: GetNVertices (ELEMENT_TYPE et) inline short int MeshTopology :: GetNVertices (ELEMENT_TYPE et)
{ {
switch (et) switch (et)
{ {
@ -198,7 +192,7 @@ inline int MeshTopology :: GetNVertices (ELEMENT_TYPE et)
} }
inline int MeshTopology :: GetNPoints (ELEMENT_TYPE et) inline short int MeshTopology :: GetNPoints (ELEMENT_TYPE et)
{ {
switch (et) switch (et)
{ {
@ -240,8 +234,9 @@ inline int MeshTopology :: GetNPoints (ELEMENT_TYPE et)
inline int MeshTopology :: GetNEdges (ELEMENT_TYPE et) inline short int MeshTopology :: GetNEdges (ELEMENT_TYPE et)
{ {
__assume(et >= SEGMENT && et <= HEX);
switch (et) switch (et)
{ {
case SEGMENT: case SEGMENT:
@ -270,16 +265,18 @@ inline int MeshTopology :: GetNEdges (ELEMENT_TYPE et)
case HEX: case HEX:
return 12; return 12;
default:
return 0;
// default: // default:
// cerr << "Ng_ME_GetNEdges, illegal element type " << et << endl; // cerr << "Ng_ME_GetNEdges, illegal element type " << et << endl;
} }
return 0; // return 0;
} }
inline int MeshTopology :: GetNFaces (ELEMENT_TYPE et) inline short int MeshTopology :: GetNFaces (ELEMENT_TYPE et)
{ {
__assume(et >= SEGMENT && et <= HEX);
switch (et) switch (et)
{ {
case SEGMENT: case SEGMENT:
@ -309,10 +306,11 @@ inline int MeshTopology :: GetNFaces (ELEMENT_TYPE et)
case HEX: case HEX:
return 6; return 6;
default:
return -99;
// default: // default:
// cerr << "Ng_ME_GetNVertices, illegal element type " << et << endl; // cerr << "Ng_ME_GetNVertices, illegal element type " << et << endl;
} }
return 0;
} }
@ -683,24 +681,6 @@ inline const ELEMENT_FACE * MeshTopology :: GetFaces0 (ELEMENT_TYPE et)
return 0; return 0;
} }
}
#endif #endif