00001
00002
00003
00004
00005
00006
00007
00008 #ifndef APF_MESH_H
00009 #define APF_MESH_H
00010
00014 #include <vector>
00015 #include <map>
00016 #include <set>
00017 #include "apfVector.h"
00018 #include "apfDynamicArray.h"
00019
00020 struct gmi_model;
00021
00022 namespace apf {
00023
00024 class FieldShape;
00025 class Field;
00026 template <class T>
00027 class NumberingOf;
00029 typedef NumberingOf<int> Numbering;
00030 typedef NumberingOf<long> GlobalNumbering;
00031
00032 class MeshEntity;
00033 class MeshIterator;
00034 class MeshTag;
00035
00036 class ModelEntity;
00037
00041 typedef std::map<int,MeshEntity*> Copies;
00043 typedef std::set<int> Parts;
00046 typedef DynamicArray<MeshEntity*> Adjacent;
00052 typedef MeshEntity* Downward[12];
00053
00054 class Migration;
00055
00063 struct Up
00064 {
00066 int n;
00068 MeshEntity* e[400];
00069 };
00070
00075 struct Copy
00076 {
00078 Copy():peer(0),entity(0) {}
00080 Copy(int p, MeshEntity* e):peer(p),entity(e) {}
00082 int peer;
00084 MeshEntity* entity;
00085 };
00087 typedef Copy Match;
00088
00090 typedef DynamicArray<Copy> CopyArray;
00092 typedef CopyArray Matches;
00093
00101 class Mesh
00102 {
00103 public:
00108 void init(FieldShape* s);
00113 virtual ~Mesh();
00115 virtual int getDimension() = 0;
00117 virtual std::size_t count(int dimension) = 0;
00119 virtual MeshIterator* begin(int dimension) = 0;
00122 virtual MeshEntity* iterate(MeshIterator* it) = 0;
00126 virtual void end(MeshIterator* it) = 0;
00128 virtual bool isShared(MeshEntity* e) = 0;
00129
00130 virtual bool isGhosted(MeshEntity* e) = 0;
00131 virtual bool isGhost(MeshEntity* e) = 0;
00134 virtual bool isOwned(MeshEntity* e) = 0;
00136 virtual int getOwner(MeshEntity* e) = 0;
00138 enum Type {
00140 VERTEX,
00142 EDGE,
00144 TRIANGLE,
00146 QUAD,
00148 TET,
00150 HEX,
00152 PRISM,
00154 PYRAMID,
00156 TYPES };
00159 static int const adjacentCount[TYPES][4];
00161 static int const typeDimension[TYPES];
00163 static char const* const typeName[TYPES];
00165 static Type const simplexTypes[4];
00172 virtual void getAdjacent(MeshEntity* e, int dimension,
00173 Adjacent& adjacent) = 0;
00182 virtual int getDownward(MeshEntity* e, int dimension,
00183 MeshEntity** adjacent) = 0;
00185 virtual int countUpward(MeshEntity* e) = 0;
00187 virtual MeshEntity* getUpward(MeshEntity* e, int i) = 0;
00189 virtual void getUp(MeshEntity* e, Up& up) = 0;
00191 virtual bool hasUp(MeshEntity* e) = 0;
00200 void getPoint(MeshEntity* e, int node, Vector3& point);
00202 virtual void getPoint_(MeshEntity* e, int node, Vector3& point) = 0;
00204 virtual void getParam(MeshEntity* e, Vector3& p) = 0;
00207 virtual Type getType(MeshEntity* e) = 0;
00209 virtual void getRemotes(MeshEntity* e, Copies& remotes) = 0;
00210
00211 virtual void getGhosts(MeshEntity* e, Copies& ghosts) = 0;
00215 virtual void getResidence(MeshEntity* e, Parts& residence) = 0;
00217 virtual MeshTag* createDoubleTag(const char* name, int size) = 0;
00219 virtual MeshTag* createIntTag(const char* name, int size) = 0;
00221 virtual MeshTag* createLongTag(const char* name, int size) = 0;
00223 virtual MeshTag* findTag(const char* name) = 0;
00225 virtual void destroyTag(MeshTag* tag) = 0;
00227 virtual void getTags(DynamicArray<MeshTag*>& tags) = 0;
00229 virtual void getDoubleTag(MeshEntity* e, MeshTag* tag, double* data) = 0;
00231 virtual void setDoubleTag(MeshEntity* e, MeshTag* tag, double const* data) = 0;
00233 virtual void getIntTag(MeshEntity* e, MeshTag* tag, int* data) = 0;
00235 virtual void setIntTag(MeshEntity* e, MeshTag* tag, int const* data) = 0;
00237 virtual void getLongTag(MeshEntity* e, MeshTag* tag, long* data) = 0;
00239 virtual void setLongTag(MeshEntity* e, MeshTag* tag, long const* data) = 0;
00242 virtual void removeTag(MeshEntity* e, MeshTag* tag) = 0;
00244 virtual bool hasTag(MeshEntity* e, MeshTag* tag) = 0;
00246 virtual void renameTag(MeshTag* tag, const char* newName) = 0;
00248 enum TagType {
00250 DOUBLE,
00252 INT,
00254 LONG };
00257 virtual int getTagType(MeshTag* t) = 0;
00259 virtual int getTagSize(MeshTag* t) = 0;
00263 virtual const char* getTagName(MeshTag* t) = 0;
00265 virtual ModelEntity* toModel(MeshEntity* e) = 0;
00267 virtual gmi_model* getModel() = 0;
00269 int getModelType(ModelEntity* e);
00271 int getModelTag(ModelEntity* e);
00273 ModelEntity* findModelEntity(int type, int tag);
00275 bool canSnap();
00277 void snapToModel(ModelEntity* m, Vector3 const& p, Vector3& x);
00279 void getParamOn(ModelEntity* g, MeshEntity* e, Vector3& p);
00283 bool getPeriodicRange(ModelEntity* g, int axis,
00284 double range[2]);
00286 void getClosestPoint(ModelEntity* g, Vector3 const& from,
00287 Vector3& to, Vector3& p);
00289 void getNormal(ModelEntity* g, Vector3 const& p, Vector3& n);
00291 void getFirstDerivative(ModelEntity* g, Vector3 const& p,
00292 Vector3& t0, Vector3& t1);
00294 FieldShape* getShape() const;
00296 Field* getCoordinateField() {return coordinateField;}
00298 void setCoordinateField(Field* field);
00301 void changeShape(FieldShape* newShape, bool project = true);
00305 virtual void migrate(Migration* plan) = 0;
00307 virtual int getId() = 0;
00309 virtual void writeNative(const char* fileName) = 0;
00311 virtual void destroyNative() = 0;
00314 virtual void verify() = 0;
00316 virtual bool hasMatching() = 0;
00318 virtual void getMatches(MeshEntity* e, Matches& m) = 0;
00324 virtual double getElementBytes(int) {return 1.0;}
00328 void addField(Field* f);
00332 void removeField(Field* f);
00334 Field* findField(const char* name);
00336 int countFields();
00338 Field* getField(int i);
00342 void addNumbering(Numbering* f);
00346 void removeNumbering(Numbering* f);
00348 Numbering* findNumbering(const char* name);
00350 int countNumberings();
00352 Numbering* getNumbering(int i);
00353 void addGlobalNumbering(GlobalNumbering* f);
00354 void removeGlobalNumbering(GlobalNumbering* f);
00355 int countGlobalNumberings();
00356 GlobalNumbering* getGlobalNumbering(int i);
00358 bool hasFrozenFields;
00359 protected:
00360 Field* coordinateField;
00361 std::vector<Field*> fields;
00362 std::vector<Numbering*> numberings;
00363 std::vector<GlobalNumbering*> globalNumberings;
00364 };
00365
00369 void verify(Mesh* m);
00370
00371 long verifyVolumes(Mesh* m, bool printVolumes = true);
00372
00374 int getDimension(Mesh* m, MeshEntity* e);
00375
00378 void unite(Parts& into, Parts const& from);
00379
00381 void removeTagFromDimension(Mesh* m, MeshTag* tag, int d);
00382
00385 MeshEntity* findUpward(Mesh* m, int type, MeshEntity** down);
00386
00388 MeshEntity* findElement(
00389 Mesh* m,
00390 int type,
00391 MeshEntity** verts);
00392
00394 MeshEntity* getEdgeVertOppositeVert(Mesh* m, MeshEntity* edge, MeshEntity* v);
00395
00397 void getBridgeAdjacent(Mesh* m, MeshEntity* origin,
00398 int bridgeDimension, int targetDimension, Adjacent& result);
00399
00401 int countEntitiesOfType(Mesh* m, int type);
00402
00404 bool isSimplex(int type);
00405
00409 Vector3 getLinearCentroid(Mesh* m, MeshEntity* e);
00410
00412 class Migration
00413 {
00414 public:
00417 Migration(Mesh* m);
00418 Migration(Mesh* m, MeshTag* existingTag);
00419 ~Migration();
00421 int count();
00423 MeshEntity* get(int i);
00425 bool has(MeshEntity* e);
00427 void send(MeshEntity* e, int to);
00429 int sending(MeshEntity* e);
00430 Mesh* getMesh() {return mesh;}
00431 private:
00432 Mesh* mesh;
00433 MeshTag* tag;
00434 std::vector<MeshEntity*> elements;
00435 };
00436
00442 struct Sharing
00443 {
00444 virtual ~Sharing() {}
00446 virtual bool isOwned(MeshEntity* e) = 0;
00448 virtual void getCopies(MeshEntity* e,
00449 CopyArray& copies) = 0;
00450 virtual bool isShared(MeshEntity* e) = 0;
00451 };
00452
00453 struct NormalSharing : public Sharing
00454 {
00455 NormalSharing(Mesh* m);
00456 virtual bool isOwned(MeshEntity* e);
00457 virtual void getCopies(MeshEntity* e,
00458 CopyArray& copies);
00459 virtual bool isShared(MeshEntity* e);
00460 private:
00461 Mesh* mesh;
00462 };
00463
00464 struct MatchedSharing : public Sharing
00465 {
00466 MatchedSharing(Mesh* m);
00467 Copy getOwner(MeshEntity* e);
00468 virtual bool isOwned(MeshEntity* e);
00469 virtual void getCopies(MeshEntity* e,
00470 CopyArray& copies);
00471 virtual bool isShared(MeshEntity* e);
00472 Mesh* mesh;
00473 private:
00474 size_t getNeighborCount(int peer);
00475 bool isLess(Copy const& a, Copy const& b);
00476 void getNeighbors(Parts& neighbors);
00477 void formCountMap();
00478 NormalSharing helper;
00479 std::map<int, size_t> countMap;
00480 };
00481
00487 Sharing* getSharing(Mesh* m);
00488
00490 extern int const tri_edge_verts[3][2];
00492 extern int const quad_edge_verts[4][2];
00494 extern int const tet_edge_verts[6][2];
00496 extern int const prism_edge_verts[9][2];
00498 extern int const pyramid_edge_verts[8][2];
00500 extern int const tet_tri_verts[4][3];
00502 extern int const hex_quad_verts[6][4];
00504 extern int const prism_tri_verts[2][3];
00506 extern int const prism_quad_verts[3][4];
00508 extern int const pyramid_tri_verts[4][3];
00509
00511 void getPeers(Mesh* m, int d, Parts& peers);
00512
00515 int findIn(MeshEntity** a, int n, MeshEntity* e);
00516
00519 void findTriDown(
00520 Mesh* m,
00521 MeshEntity** verts,
00522 MeshEntity** down);
00523
00525 void changeMeshShape(Mesh* m, FieldShape* newShape, bool project = true);
00526
00529 void unfreezeFields(Mesh* m);
00530
00532 int countEntitiesOn(Mesh* m, ModelEntity* me, int dim);
00533
00535 int countOwned(Mesh* m, int dim);
00536
00538 void printStats(Mesh* m);
00539
00541 void warnAboutEmptyParts(Mesh* m);
00542
00544 Copy getOtherCopy(Mesh* m, MeshEntity* s);
00545
00546 class ElementVertOp
00547 {
00548 public:
00549 virtual MeshEntity* apply(int type, MeshEntity** down) = 0;
00550 MeshEntity* run(int type, MeshEntity** verts);
00551 void runDown(int type, MeshEntity** verts, MeshEntity** down);
00552 };
00553
00555 int getFirstType(Mesh* m, int dim);
00556
00565 void getAlignment(Mesh* m, MeshEntity* elem, MeshEntity* boundary,
00566 int& which, bool& flip, int& rotate);
00567
00568 void packString(std::string s, int to);
00569 std::string unpackString();
00570 void packTagInfo(Mesh* m, MeshTag* t, int to);
00571 void unpackTagInfo(std::string& name, int& type, int& size);
00572
00573 extern char const* const dimName[4];
00574
00575 }
00576
00577 #endif