simplified blayer generation
[engrid.git] / src / meshpartition.h
blobcb13713a50aa097fdebeda2870faeaad904466f4
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008,2009 Oliver Gloth +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 #ifndef MESHPARTITION_H
25 #define MESHPARTITION_H
27 class MeshPartition;
29 #include "egvtkobject.h"
31 class MeshPartition : public EgVtkObject
34 private: // attributes
37 vtkUnstructuredGrid* m_Grid; ///< the grid underlying this mesh partition
38 QVector<vtkIdType> m_Cells; ///< all cells of the mesh partition
39 QVector<int> m_LCells; ///< inverse indexing for the cells
40 QVector<vtkIdType> m_Nodes; ///< all nodes of the mesh partition
41 QVector<int> m_LNodes; ///< inverse indexing for the nodes
42 QVector<QVector<int> > m_N2C; ///< node to cell information
43 QVector<QVector<int> > m_N2N; ///< node to node information
44 QVector<QVector<int> > m_C2C; ///< cell to cell information
46 int m_CellsStamp; ///< "time"-stamp
47 int m_LCellsStamp; ///< "time"-stamp
48 int m_NodesStamp; ///< "time"-stamp
49 int m_LNodesStamp; ///< "time"-stamp
50 int m_N2NStamp; ///< "time"-stamp
51 int m_N2CStamp; ///< "time"-stamp
52 int m_C2CStamp; ///< "time"-stamp
54 private: // methods
56 void resetTimeStamps();
57 void checkNodes();
58 void checkLCells();
59 void checkLNodes();
60 void checkN2N();
61 void checkN2C();
62 void checkC2C();
64 public: // methods
66 /// Create an empty (undefined) mesh partition
67 MeshPartition();
69 /**
70 * Create a mesh partition with the grid set. Optionally all cells can be selected.
71 * @param grid the grid to use
72 * @param use_all_cells if set to true all cells will be selected;
74 MeshPartition(vtkUnstructuredGrid *grid, bool use_all_cells = false);
76 /**
77 * Create a mesh partition from a global volume definition
78 * @param volume_name the name of the volume
80 MeshPartition(QString volume_name);
82 /**
83 * Set the grid.
84 * @param a pointer to the grid
86 void setGrid(vtkUnstructuredGrid *grid) { m_Grid = grid; }
88 /**
89 * Access to the grid.
90 * @return a pointer to the grid
92 vtkUnstructuredGrid* getGrid() const { return m_Grid; }
94 /**
95 * Define the mesh partition by defining its cells.
96 * @param cls the cells of the subset
98 template <class C>
99 void setCells(const C& cls);
102 * Define the mesh partition by defining all its cells.
104 void setAllCells();
107 * Define the mesh partition by giving a symbolic volume name.
108 * The grid will be changed to the default (main) grid that is currently loaded into ENGRID.
109 * @param volume_name the symbolic volume name
111 void setVolume(QString volume_name);
114 * Define the mesh partition as the remainder of an existing partition.
115 * @param part the existing partition
117 void setRemainder(const MeshPartition& part);
119 const QVector<vtkIdType>& getCells() const; ///< Access to the cell indices
120 const QVector<int>& getLocalCells(); ///< Access to the local cell indices
121 const QVector<vtkIdType>& getNodes(); ///< Access to the node indices
122 const QVector<int>& getLocalNodes(); ///< Access to the local node indices
123 const QVector<QVector<int> >& getN2N(); ///< Access to the local node to node structure
124 const QVector<QVector<int> >& getN2C(); ///< Access to the local node to cell structure
125 const QVector<QVector<int> >& getC2C(); ///< Access to the local cell to cell structure
127 void setVolumeOrientation(); ///< change the face orientation to match the volume definition
128 void setOriginalOrientation(); ///< change the orientation to match the original orientation
131 * Copy the partition to a VTK grid.
132 * @param new_grid the grid to copy the partition to (will be resized accordingly).
134 void extractToVtkGrid(vtkUnstructuredGrid *new_grid);
137 * Add another partition to this one.
138 * At the moment overlapping partitions on two different grids will not be handled well.
139 * If both partitions do not have the same underlying grid the grid will be extended in order
140 * to add the other partition.
141 * @param part the partition to add
143 void addPartition(const MeshPartition& part);
146 * compute the smallest edge length of the partition
147 * @return the smallest edge length
149 double getSmallestEdgeLength() const;
152 * Get the number of nodes in the partition.
153 * @return the number of nodes
155 int getNumberOfNodes();
158 * Get the number of cells in the partition.
159 * @return the number of cells
161 int getNumberOfCells();
163 int localNode(vtkIdType id_node);
164 vtkIdType globalNode(int i);
165 int localCell(vtkIdType id_cell);
166 vtkIdType globalCell(int i);
169 int n2nLSize(int i_nodes);
170 int n2nLL(int i_nodes, int j);
171 vtkIdType n2nLG(int i_nodes, int j);
172 int n2nGSize(vtkIdType id_node);
173 int n2nGL(vtkIdType id_node, int j);
174 vtkIdType n2nGG(vtkIdType id_node, int j);
175 int n2cLSize(int i_nodes);
176 int n2cLL(int i_nodes, int j);
177 vtkIdType n2cLG(int i_nodes, int j);
178 int n2cGSize(vtkIdType id_node);
179 int n2cGL(vtkIdType id_node, int j);
180 vtkIdType n2cGG(vtkIdType id_node, int j);
181 int c2cLSize(int i_cells);
182 int c2cLL(int i_cells, int j);
183 vtkIdType c2cLG(int i_cells, int j);
184 int c2cGSize(vtkIdType id_cell);
185 int c2cGL(vtkIdType id_cell, int j);
186 vtkIdType c2cGG(vtkIdType id_cell, int j);
191 template <class C>
192 inline void MeshPartition::setCells(const C& cls)
194 m_Cells.resize(cls.size());
195 qCopy(cls.begin(), cls.end(), m_Cells.begin());
196 ++m_CellsStamp;
199 inline void MeshPartition::setAllCells() {
200 QVector <vtkIdType> all_cells;
201 getAllCells(all_cells, m_Grid);
202 this->setCells(all_cells);
205 inline void MeshPartition::checkNodes()
207 if (m_CellsStamp > m_NodesStamp) {
208 getNodesFromCells(m_Cells, m_Nodes, m_Grid);
209 m_NodesStamp = m_CellsStamp;
213 inline void MeshPartition::checkLCells()
215 if (m_CellsStamp > m_LCellsStamp) {
216 createCellMapping(m_Cells, m_LCells, m_Grid);
217 m_LCellsStamp = m_CellsStamp;
221 inline void MeshPartition::checkLNodes()
223 checkNodes();
224 if (m_NodesStamp > m_LNodesStamp) {
225 createNodeMapping(m_Nodes, m_LNodes, m_Grid);
226 m_LNodesStamp = m_NodesStamp;
230 inline void MeshPartition::checkN2N()
232 checkLNodes();
233 if (m_LNodesStamp > m_N2NStamp) {
234 createNodeToNode(m_Cells, m_Nodes, m_LNodes, m_N2N, m_Grid);
235 m_N2NStamp = m_LNodesStamp;
239 inline void MeshPartition::checkN2C()
241 checkLNodes();
242 if (m_LNodesStamp > m_N2CStamp) {
243 createNodeToCell(m_Cells, m_Nodes, m_LNodes, m_N2C, m_Grid);
244 m_N2CStamp = m_LNodesStamp;
248 inline void MeshPartition::checkC2C()
250 if (m_CellsStamp > m_C2CStamp) {
251 createCellToCell(m_Cells, m_C2C, m_Grid);
252 m_C2CStamp = m_CellsStamp;
256 inline const QVector<vtkIdType>& MeshPartition::getCells() const
258 return m_Cells;
261 inline const QVector<int>& MeshPartition::getLocalCells()
263 checkLCells();
264 return m_LCells;
267 inline const QVector<vtkIdType>& MeshPartition::getNodes()
269 checkNodes();
270 return m_Nodes;
273 inline const QVector<int>& MeshPartition::getLocalNodes()
275 checkLNodes();
276 return m_LNodes;
279 inline const QVector<QVector<int> >& MeshPartition::getN2N()
281 checkN2N();
282 return m_N2N;
285 inline const QVector<QVector<int> >& MeshPartition::getN2C()
287 checkN2C();
288 return m_N2C;
291 inline const QVector<QVector<int> >& MeshPartition::getC2C()
293 checkC2C();
294 return m_C2C;
297 inline int MeshPartition::n2nLSize(int i_nodes)
299 checkN2N();
300 return m_N2N[i_nodes].size();
303 inline int MeshPartition::n2nLL(int i_nodes, int j)
305 checkN2N();
306 return m_N2N[i_nodes][j];
309 inline vtkIdType MeshPartition::n2nLG(int i_nodes, int j)
311 checkN2N();
312 return m_Nodes[m_N2N[i_nodes][j]];
315 inline int MeshPartition::n2nGSize(vtkIdType id_node)
317 checkN2N();
318 return m_N2N[m_LNodes[id_node]].size();
321 inline int MeshPartition::n2nGL(vtkIdType id_node, int j)
323 checkN2N();
324 return m_N2N[m_LNodes[id_node]][j];
327 inline vtkIdType MeshPartition::n2nGG(vtkIdType id_node, int j)
329 checkN2N();
330 return m_Nodes[m_N2N[m_LNodes[id_node]][j]];
333 inline int MeshPartition::n2cLSize(int i_nodes)
335 checkN2C();
336 return m_N2C[i_nodes].size();
339 inline int MeshPartition::n2cLL(int i_nodes, int j)
341 checkN2C();
342 return m_N2C[i_nodes][j];
345 inline vtkIdType MeshPartition::n2cLG(int i_nodes, int j)
347 checkN2C();
348 int i_cell = m_N2C[i_nodes][j];
349 if(i_cell<0) return(-1);
350 else return m_Cells[i_cell];
353 inline int MeshPartition::n2cGSize(vtkIdType id_node)
355 checkN2C();
356 return m_N2C[m_LNodes[id_node]].size();
359 inline int MeshPartition::n2cGL(vtkIdType id_node, int j)
361 checkN2C();
362 return m_N2C[m_LNodes[id_node]][j];
365 inline vtkIdType MeshPartition::n2cGG(vtkIdType id_node, int j)
367 checkN2C();
368 int i_cell = m_N2C[m_LNodes[id_node]][j];
369 if(i_cell<0) return(-1);
370 else return m_Cells[i_cell];
373 inline int MeshPartition::c2cLSize(int i_cells)
375 checkC2C();
376 return m_C2C[i_cells].size();
379 inline int MeshPartition::c2cLL(int i_cells, int j)
381 checkC2C();
382 return m_C2C[i_cells][j];
385 inline vtkIdType MeshPartition::c2cLG(int i_cells, int j)
387 checkC2C();
388 int i_cell = m_C2C[i_cells][j];
389 if(i_cell<0) return(-1);
390 else return m_Cells[i_cell];
393 inline int MeshPartition::c2cGSize(vtkIdType id_cell)
395 checkC2C();
396 checkLCells();
397 return m_C2C[m_LCells[id_cell]].size();
400 inline int MeshPartition::c2cGL(vtkIdType id_cell, int j)
402 checkC2C();
403 checkLCells();
404 return m_C2C[m_LCells[id_cell]][j];
407 inline vtkIdType MeshPartition::c2cGG(vtkIdType id_cell, int j)
409 checkC2C();
410 checkLCells();
411 int i_cell = m_C2C[m_LCells[id_cell]][j];
412 if(i_cell<0) return(-1);
413 else return m_Cells[i_cell];
416 inline int MeshPartition::getNumberOfCells()
418 return m_Cells.size();
421 inline int MeshPartition::getNumberOfNodes()
423 checkNodes();
424 return m_Nodes.size();
427 inline int MeshPartition::localNode(vtkIdType id_node)
429 checkLNodes();
430 return m_LNodes[id_node];
433 inline vtkIdType MeshPartition::globalNode(int i)
435 checkNodes();
436 return m_Nodes[i];
439 inline int MeshPartition::localCell(vtkIdType id_cell)
441 checkLCells();
442 return m_LCells[id_cell];
445 inline vtkIdType MeshPartition::globalCell(int i)
447 if(i<0) return(-1);
448 else return m_Cells[i];
451 #endif // MESHPARTITION_H