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;
00094 typedef CopyArray DgCopies;
00095
00103 class Mesh
00104 {
00105 public:
00110 void init(FieldShape* s);
00115 virtual ~Mesh();
00117 virtual int getDimension() = 0;
00119 virtual std::size_t count(int dimension) = 0;
00121 virtual MeshIterator* begin(int dimension) = 0;
00124 virtual MeshEntity* iterate(MeshIterator* it) = 0;
00128 virtual void end(MeshIterator* it) = 0;
00129
00130
00131 virtual bool hasAdjacency(int from_dim, int to_dim) = 0;
00132
00133 virtual void createAdjacency(int from_dim, int to_dim) = 0;
00134
00135 virtual void deleteAdjacency(int from_dim, int to_dim) = 0;
00136
00138 virtual bool isShared(MeshEntity* e) = 0;
00139
00140 virtual bool isGhosted(MeshEntity* e) = 0;
00141 virtual bool isGhost(MeshEntity* e) = 0;
00144 virtual bool isOwned(MeshEntity* e) = 0;
00146 virtual int getOwner(MeshEntity* e) = 0;
00148 enum Type {
00150 VERTEX,
00152 EDGE,
00154 TRIANGLE,
00156 QUAD,
00158 TET,
00160 HEX,
00162 PRISM,
00164 PYRAMID,
00166 TYPES };
00169 static int const adjacentCount[TYPES][4];
00171 static int const typeDimension[TYPES];
00173 static char const* const typeName[TYPES];
00175 static Type const simplexTypes[4];
00182 virtual void getAdjacent(MeshEntity* e, int dimension,
00183 Adjacent& adjacent) = 0;
00192 virtual int getDownward(MeshEntity* e, int dimension,
00193 MeshEntity** adjacent) = 0;
00195 virtual int countUpward(MeshEntity* e) = 0;
00197 virtual MeshEntity* getUpward(MeshEntity* e, int i) = 0;
00199 virtual void getUp(MeshEntity* e, Up& up) = 0;
00201 virtual bool hasUp(MeshEntity* e) = 0;
00210 void getPoint(MeshEntity* e, int node, Vector3& point);
00212 virtual void getPoint_(MeshEntity* e, int node, Vector3& point) = 0;
00214 virtual void getParam(MeshEntity* e, Vector3& p) = 0;
00217 virtual Type getType(MeshEntity* e) = 0;
00219 virtual void getRemotes(MeshEntity* e, Copies& remotes) = 0;
00220
00221 virtual int getGhosts(MeshEntity* e, Copies& ghosts) = 0;
00225 virtual void getResidence(MeshEntity* e, Parts& residence) = 0;
00227 virtual MeshTag* createDoubleTag(const char* name, int size) = 0;
00229 virtual MeshTag* createIntTag(const char* name, int size) = 0;
00231 virtual MeshTag* createLongTag(const char* name, int size) = 0;
00233 virtual MeshTag* findTag(const char* name) = 0;
00235 virtual void destroyTag(MeshTag* tag) = 0;
00237 virtual void getTags(DynamicArray<MeshTag*>& tags) = 0;
00239 virtual void getDoubleTag(MeshEntity* e, MeshTag* tag, double* data) = 0;
00241 virtual void setDoubleTag(MeshEntity* e, MeshTag* tag, double const* data) = 0;
00243 virtual void getIntTag(MeshEntity* e, MeshTag* tag, int* data) = 0;
00245 virtual void setIntTag(MeshEntity* e, MeshTag* tag, int const* data) = 0;
00247 virtual void getLongTag(MeshEntity* e, MeshTag* tag, long* data) = 0;
00249 virtual void setLongTag(MeshEntity* e, MeshTag* tag, long const* data) = 0;
00252 virtual void removeTag(MeshEntity* e, MeshTag* tag) = 0;
00254 virtual bool hasTag(MeshEntity* e, MeshTag* tag) = 0;
00256 virtual void renameTag(MeshTag* tag, const char* newName) = 0;
00258 virtual unsigned getTagChecksum(MeshTag* tag, int type) = 0;
00260 enum TagType {
00262 DOUBLE,
00264 INT,
00266 LONG };
00269 virtual int getTagType(MeshTag* t) = 0;
00271 virtual int getTagSize(MeshTag* t) = 0;
00275 virtual const char* getTagName(MeshTag* t) = 0;
00277 virtual ModelEntity* toModel(MeshEntity* e) = 0;
00279 virtual gmi_model* getModel() = 0;
00281 int getModelType(ModelEntity* e);
00283 int getModelTag(ModelEntity* e);
00285 ModelEntity* findModelEntity(int type, int tag);
00287 bool canSnap();
00289 void snapToModel(ModelEntity* m, Vector3 const& p, Vector3& x);
00291 void getParamOn(ModelEntity* g, MeshEntity* e, Vector3& p);
00295 bool getPeriodicRange(ModelEntity* g, int axis,
00296 double range[2]);
00298 void getClosestPoint(ModelEntity* g, Vector3 const& from,
00299 Vector3& to, Vector3& p);
00301 void getNormal(ModelEntity* g, Vector3 const& p, Vector3& n);
00303 void getFirstDerivative(ModelEntity* g, Vector3 const& p,
00304 Vector3& t0, Vector3& t1);
00307 bool isParamPointInsideModel(ModelEntity* g,
00308 Vector3 const& param, Vector3& x);
00310 bool isInClosureOf(ModelEntity* g, ModelEntity* target);
00312 FieldShape* getShape() const;
00314 Field* getCoordinateField() {return coordinateField;}
00316 void setCoordinateField(Field* field);
00319 void changeShape(FieldShape* newShape, bool project = true);
00323 virtual void migrate(Migration* plan) = 0;
00325 virtual int getId() = 0;
00327 virtual void writeNative(const char* fileName) = 0;
00329 virtual void destroyNative() = 0;
00332 virtual void verify() = 0;
00334 virtual bool hasMatching() = 0;
00336 virtual void getMatches(MeshEntity* e, Matches& m) = 0;
00338 virtual void getDgCopies(MeshEntity* e, DgCopies& dgCopies, ModelEntity* me = 0) = 0;
00344 virtual double getElementBytes(int) {return 1.0;}
00348 void addField(Field* f);
00352 void removeField(Field* f);
00354 Field* findField(const char* name);
00356 int countFields();
00358 Field* getField(int i);
00362 void addNumbering(Numbering* f);
00366 void removeNumbering(Numbering* f);
00368 Numbering* findNumbering(const char* name);
00370 int countNumberings();
00372 Numbering* getNumbering(int i);
00373 void addGlobalNumbering(GlobalNumbering* f);
00374 void removeGlobalNumbering(GlobalNumbering* f);
00375 int countGlobalNumberings();
00377 GlobalNumbering* findGlobalNumbering(const char* name);
00378
00379 GlobalNumbering* getGlobalNumbering(int i);
00381 bool hasFrozenFields;
00382 protected:
00383 Field* coordinateField;
00384 std::vector<Field*> fields;
00385 std::vector<Numbering*> numberings;
00386 std::vector<GlobalNumbering*> globalNumberings;
00387 };
00388
00392 void verify(Mesh* m, bool abort_on_error=true);
00393
00394 long verifyVolumes(Mesh* m, bool printVolumes = true);
00395
00397 int getDimension(Mesh* m, MeshEntity* e);
00398
00401 void unite(Parts& into, Parts const& from);
00402
00404 void removeTagFromDimension(Mesh* m, MeshTag* tag, int d);
00405
00408 MeshEntity* findUpward(Mesh* m, int type, MeshEntity** down);
00409
00411 MeshEntity* findElement(
00412 Mesh* m,
00413 int type,
00414 MeshEntity** verts);
00415
00417 MeshEntity* getEdgeVertOppositeVert(Mesh* m, MeshEntity* edge, MeshEntity* v);
00418
00420 void getBridgeAdjacent(Mesh* m, MeshEntity* origin,
00421 int bridgeDimension, int targetDimension, Adjacent& result);
00422
00424 int countEntitiesOfType(Mesh* m, int type);
00425
00427 bool isSimplex(int type);
00428
00432 Vector3 getLinearCentroid(Mesh* m, MeshEntity* e);
00433
00435 class Migration
00436 {
00437 public:
00440 Migration(Mesh* m);
00441 Migration(Mesh* m, MeshTag* existingTag);
00442 ~Migration();
00444 int count();
00446 MeshEntity* get(int i);
00448 bool has(MeshEntity* e);
00450 void send(MeshEntity* e, int to);
00452 int sending(MeshEntity* e);
00453 Mesh* getMesh() {return mesh;}
00454 private:
00455 Mesh* mesh;
00456 MeshTag* tag;
00457 std::vector<MeshEntity*> elements;
00458 };
00459
00465 struct Sharing
00466 {
00467 virtual ~Sharing() {}
00469 virtual bool isOwned(MeshEntity* e) = 0;
00471 virtual int getOwner(MeshEntity* e) = 0;
00473 virtual void getCopies(MeshEntity* e,
00474 CopyArray& copies) = 0;
00475 virtual bool isShared(MeshEntity* e) = 0;
00476 };
00477
00478 struct NormalSharing : public Sharing
00479 {
00480 NormalSharing(Mesh* m);
00481 virtual int getOwner(MeshEntity* e);
00482 virtual bool isOwned(MeshEntity* e);
00483 virtual void getCopies(MeshEntity* e,
00484 CopyArray& copies);
00485 virtual bool isShared(MeshEntity* e);
00486 private:
00487 Mesh* mesh;
00488 };
00489
00490 struct MatchedSharing : public Sharing
00491 {
00492 MatchedSharing(Mesh* m);
00493 Copy getOwnerCopy(MeshEntity* e);
00494 virtual int getOwner(MeshEntity* e);
00495 virtual bool isOwned(MeshEntity* e);
00496 virtual void getCopies(MeshEntity* e,
00497 CopyArray& copies);
00498 virtual bool isShared(MeshEntity* e);
00499 Mesh* mesh;
00500 private:
00501 size_t getNeighborCount(int peer);
00502 bool isLess(Copy const& a, Copy const& b);
00503 void getNeighbors(Parts& neighbors);
00504 void formCountMap();
00505 NormalSharing helper;
00506 std::map<int, size_t> countMap;
00507 };
00508
00514 Sharing* getSharing(Mesh* m);
00515
00517 extern int const tri_edge_verts[3][2];
00519 extern int const quad_edge_verts[4][2];
00521 extern int const tet_edge_verts[6][2];
00523 extern int const prism_edge_verts[9][2];
00525 extern int const pyramid_edge_verts[8][2];
00527 extern int const tet_tri_verts[4][3];
00529 extern int const hex_quad_verts[6][4];
00531 extern int const prism_tri_verts[2][3];
00533 extern int const prism_quad_verts[3][4];
00535 extern int const pyramid_tri_verts[4][3];
00536
00538 void getPeers(Mesh* m, int d, Parts& peers);
00539
00542 int findIn(MeshEntity** a, int n, MeshEntity* e);
00543
00546 void findTriDown(
00547 Mesh* m,
00548 MeshEntity** verts,
00549 MeshEntity** down);
00550
00552 void changeMeshShape(Mesh* m, FieldShape* newShape, bool project = true);
00553
00556 void unfreezeFields(Mesh* m);
00557
00559 int countEntitiesOn(Mesh* m, ModelEntity* me, int dim);
00560
00562 int countOwned(Mesh* m, int dim);
00563
00565 void printStats(Mesh* m);
00566
00568 void warnAboutEmptyParts(Mesh* m);
00569
00571 Copy getOtherCopy(Mesh* m, MeshEntity* s);
00572
00573 class ElementVertOp
00574 {
00575 public:
00576 virtual MeshEntity* apply(int type, MeshEntity** down) = 0;
00577 MeshEntity* run(int type, MeshEntity** verts);
00578 void runDown(int type, MeshEntity** verts, MeshEntity** down);
00579 };
00580
00582 int getFirstType(Mesh* m, int dim);
00583
00592 void getAlignment(Mesh* m, MeshEntity* elem, MeshEntity* boundary,
00593 int& which, bool& flip, int& rotate);
00594
00595 void packString(std::string s, int to);
00596 std::string unpackString();
00597 void packTagInfo(Mesh* m, MeshTag* t, int to);
00598 void unpackTagInfo(std::string& name, int& type, int& size);
00599
00600 extern char const* const dimName[4];
00601
00602 }
00603
00604 #endif