Actual source code: Mesh.hh
1: #ifndef included_ALE_Mesh_hh
2: #define included_ALE_Mesh_hh
4: #ifndef included_ALE_Completion_hh
5: #include <Completion.hh>
6: #endif
8: namespace ALE {
9: class Mesh {
10: public:
11: typedef int point_type;
12: typedef std::vector<point_type> PointArray;
13: typedef ALE::Sieve<point_type,int,int> sieve_type;
14: typedef ALE::Point patch_type;
15: typedef ALE::New::Topology<int, sieve_type> topology_type;
16: typedef ALE::New::Atlas<topology_type, ALE::Point> atlas_type;
17: typedef ALE::New::Section<atlas_type, double> section_type;
18: typedef std::map<std::string, Obj<section_type> > SectionContainer;
19: typedef ALE::New::NewNumbering<atlas_type> numbering_type;
20: typedef std::map<int, Obj<numbering_type> > NumberingContainer;
21: typedef std::map<std::string, Obj<numbering_type> > OrderContainer;
22: typedef ALE::New::Section<atlas_type, ALE::pair<int,double> > foliated_section_type;
23: typedef struct {double x, y, z;} split_value;
24: typedef ALE::New::Section<atlas_type, ALE::pair<point_type, split_value> > split_section_type;
25: typedef ALE::New::Completion<topology_type, point_type>::send_overlap_type send_overlap_type;
26: typedef ALE::New::Completion<topology_type, point_type>::recv_overlap_type recv_overlap_type;
27: typedef ALE::New::Completion<topology_type, point_type>::atlas_type comp_atlas_type;
28: typedef ALE::New::OverlapValues<send_overlap_type, comp_atlas_type, point_type> send_section_type;
29: typedef ALE::New::OverlapValues<recv_overlap_type, comp_atlas_type, point_type> recv_section_type;
30: int debug;
31: private:
32: Obj<sieve_type> topology;
33: SectionContainer sections;
34: NumberingContainer localNumberings;
35: NumberingContainer numberings;
36: OrderContainer orders;
37: Obj<topology_type> _topology;
38: Obj<foliated_section_type> _boundaries;
39: Obj<split_section_type> _splitField;
40: Obj<send_overlap_type> _vertexSendOverlap;
41: Obj<recv_overlap_type> _vertexRecvOverlap;
42: MPI_Comm _comm;
43: int _commRank;
44: int _commSize;
45: int dim;
46: //FIX:
47: public:
48: bool distributed;
49: public:
50: Mesh(MPI_Comm comm, int dimension, int debug = 0) : debug(debug), dim(dimension) {
51: this->setComm(comm);
52: this->topology = new sieve_type(comm, debug);
53: this->_boundaries = new foliated_section_type(comm, debug);
54: this->distributed = false;
55: };
57: MPI_Comm comm() const {return this->_comm;};
58: void setComm(MPI_Comm comm) {this->_comm = comm; MPI_Comm_rank(comm, &this->_commRank); MPI_Comm_size(comm, &this->_commSize);};
59: int commRank() const {return this->_commRank;};
60: int commSize() const {return this->_commSize;};
61: Obj<sieve_type> getTopology() const {return this->topology;};
62: void setTopology(const Obj<sieve_type>& topology) {this->topology = topology;};
63: int getDimension() const {return this->dim;};
64: void setDimension(int dim) {this->dim = dim;};
65: const Obj<foliated_section_type>& getBoundariesNew() const {return this->_boundaries;};
66: const Obj<section_type>& getSection(const std::string& name) {
67: if (this->sections.find(name) == this->sections.end()) {
68: Obj<section_type> section = new section_type(this->_comm, this->debug);
69: section->getAtlas()->setTopology(this->_topology);
71: std::cout << "Creating new section: " << name << std::endl;
72: this->sections[name] = section;
73: }
74: return this->sections[name];
75: };
76: Obj<std::set<std::string> > getSections() {
77: Obj<std::set<std::string> > names = std::set<std::string>();
79: for(SectionContainer::iterator s_iter = this->sections.begin(); s_iter != this->sections.end(); ++s_iter) {
80: names->insert(s_iter->first);
81: }
82: return names;
83: }
84: bool hasSection(const std::string& name) const {
85: return(this->sections.find(name) != this->sections.end());
86: };
87: const Obj<numbering_type>& getNumbering(const int depth) {
88: if (this->numberings.find(depth) == this->numberings.end()) {
89: Obj<numbering_type> numbering = new numbering_type(new atlas_type(this->getTopologyNew()), "depth", depth);
90: numbering->construct();
92: std::cout << "Creating new numbering: " << depth << std::endl;
93: this->numberings[depth] = numbering;
94: }
95: return this->numberings[depth];
96: };
97: const Obj<numbering_type>& getLocalNumbering(const int depth) {
98: if (this->localNumberings.find(depth) == this->localNumberings.end()) {
99: Obj<numbering_type> numbering = new numbering_type(new atlas_type(this->getTopologyNew()), "depth", depth);
100: numbering->constructLocalOrder(numbering->getSendOverlap());
102: std::cout << "Creating new local numbering: " << depth << std::endl;
103: this->localNumberings[depth] = numbering;
104: }
105: return this->localNumberings[depth];
106: };
107: const Obj<numbering_type>& getGlobalOrder(const std::string& name) {
108: if (this->orders.find(name) == this->orders.end()) {
109: Obj<numbering_type> numbering = ALE::New::GlobalOrder::createIndices(this->getSection(name)->getAtlas(), this->getNumbering(0));
111: std::cout << "Creating new global order: " << name << std::endl;
112: this->orders[name] = numbering;
113: }
114: return this->orders[name];
115: };
116: const Obj<topology_type>& getTopologyNew() const {return this->_topology;};
117: void setTopologyNew(const Obj<topology_type>& topology) {this->_topology = topology;};
118: const Obj<split_section_type>& getSplitSection() const {return this->_splitField;};
119: void setSplitSection(const Obj<split_section_type>& splitField) {this->_splitField = splitField;};
120: const Obj<send_overlap_type>& getVertexSendOverlap() const {return this->_vertexSendOverlap;};
121: void setVertexSendOverlap(const Obj<send_overlap_type>& vertexOverlap) {this->_vertexSendOverlap = vertexOverlap;};
122: const Obj<recv_overlap_type>& getVertexRecvOverlap() const {return this->_vertexRecvOverlap;};
123: void setVertexRecvOverlap(const Obj<recv_overlap_type>& vertexOverlap) {this->_vertexRecvOverlap = vertexOverlap;};
124: // Printing
125: template <typename Stream_>
126: friend Stream_& operator<<(Stream_& os, const split_value& v) {
127: os << "(" << v.x << "," << v.y << "," << v.z << ")";
128: return os;
129: };
130: void view(const std::string& name, MPI_Comm comm = MPI_COMM_NULL) {
131: if (comm == MPI_COMM_NULL) {
132: comm = this->comm();
133: }
134: if (name == "") {
135: PetscPrintf(comm, "viewing a Mesh\n");
136: } else {
137: PetscPrintf(comm, "viewing Mesh '%s'\n", name.c_str());
138: }
139: this->getTopologyNew()->view("mesh topology", comm);
140: this->getSection("coordinates")->view("mesh coordinates", comm);
141: };
142: };
143: } // namespace ALE
145: #endif