gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Cell.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 //
6 // Contributed by Matti Pellikka <matti.pellikka@gmail.com>.
7 
8 #ifndef CELL_H
9 #define CELL_H
10 
11 #include <map>
12 #include <vector>
13 #include "MElement.h"
14 
15 class Cell;
16 
18 public:
19  bool operator()(const Cell *c1, const Cell *c2) const;
20 };
21 
22 // Class to save cell boundary orientation information
23 class BdInfo {
24 private:
25  signed char _ori[2];
26 
27 public:
28  BdInfo(int ori)
29  {
30  _ori[0] = ori;
31  _ori[1] = 0;
32  }
33 
34  int get() const { return _ori[0]; }
35  void reset() { _ori[0] = _ori[1]; }
36  void init() { _ori[1] = _ori[0]; }
37  void set(int ori) { _ori[0] = ori; }
38  int geto() const { return _ori[1]; }
39 };
40 
41 // Class representing an elementary cell of a cell complex.
42 class Cell {
43 protected:
44  static int _globalNum;
45 
46  int _num;
47  char _domain;
48 
49  // whether this cell a combinded cell of elementary cells
50  bool _combined;
51  // for some algorithms to omit this cell
52  bool _immune;
53 
54  // list of cells on the boundary and on the coboundary of this cell
55  std::map<Cell *, BdInfo, CellPtrLessThan> _bd;
56  std::map<Cell *, BdInfo, CellPtrLessThan> _cbd;
57 
58  Cell() {}
59 
60 private:
61  char _dim;
62  std::vector<MVertex *> _v;
63  // sorted vertices of this cell (used for ordering of the cells)
64  std::vector<char> _si;
65 
66  inline bool _sortVertexIndices();
67 
68 public:
69  static std::pair<Cell *, bool> createCell(MElement *element, int domain);
70  static std::pair<Cell *, bool> createCell(Cell *parent, int i);
71 
72  Cell(MElement *element, int domain);
73  Cell(Cell *parent, int i);
74 
75  virtual ~Cell() {}
76 
77  int getDomain() const { return _domain; }
78  void setDomain(int domain) { _domain = domain; }
79  int getNum() const { return _num; }
80  void setNum(int num) { _num = num; };
81  int getTypeMSH() const;
82  virtual int getDim() const { return _dim; }
83  bool inSubdomain() const { return _domain ? true : false; }
84  void getMeshVertices(std::vector<MVertex *> &v) const { v = _v; }
85 
86  void setImmune(bool immune) { _immune = immune; };
87  bool getImmune() const { return _immune; };
88 
89  int getNumSortedVertices() const { return _si.size(); }
90  inline int getSortedVertex(int vertex) const;
91  int getNumVertices() const { return _v.size(); }
92  MVertex *getMeshVertex(int vertex) const { return _v.at(vertex); }
93 
94  void findBdElement(int i, std::vector<MVertex *> &vertices) const;
95  int getNumBdElements() const;
96  int findBdCellOrientation(Cell *cell, int i) const;
97 
99 
100  // save/restore the original boundary information of the cell
101  void saveCellBoundary();
102  void restoreCellBoundary();
103 
104  // true if this cell has given vertex
105  virtual bool hasVertex(int vertex) const;
106 
107  // (co)boundary cell iterator
108  typedef std::map<Cell *, BdInfo, CellPtrLessThan>::iterator biter;
109 
110  // iterators to (first/last (co)boundary cells of this cell
111  // (orig: to original (co)boundary cells of this cell)
112  biter firstBoundary(bool orig = false);
114  biter firstCoboundary(bool orig = false);
116 
117  int getBoundarySize(bool orig = false);
118  int getCoboundarySize(bool orig = false);
119 
120  // get the (orig: original) cell boundary
121  void getBoundary(std::map<Cell *, short int, CellPtrLessThan> &boundary,
122  bool orig = false);
123  void getCoboundary(std::map<Cell *, short int, CellPtrLessThan> &coboundary,
124  bool orig = false);
125 
126  // add (co)boundary cell
127  // (other: reciprocally also add this cell from the other cell's (co)boundary)
128  void addBoundaryCell(int orientation, Cell *cell, bool other);
129  void addCoboundaryCell(int orientation, Cell *cell, bool other);
130 
131  // remove (co)boundary cell
132  // (other: reciprocally also revove this cell from the other cell's
133  // (co)boundary)
134  void removeBoundaryCell(Cell *cell, bool other);
135  void removeCoboundaryCell(Cell *cell, bool other);
136 
137  // true if has given cell on (orig: original) (co)boundary
138  bool hasBoundary(Cell *cell, bool orig = false);
139  bool hasCoboundary(Cell *cell, bool orig = false);
140 
141  // print cell debug info
142  virtual void printCell();
143  virtual void printBoundary();
144  virtual void printCoboundary();
145 
146  // tools for combined cells
147  bool isCombined() const { return _combined; }
148 
149  typedef std::map<Cell *, int, CellPtrLessThan>::iterator citer;
150  virtual void getCells(std::map<Cell *, int, CellPtrLessThan> &cells)
151  {
152  cells.clear();
153  cells[this] = 1;
154  }
155  virtual int getNumCells() const { return 1; }
156 
157  bool operator==(const Cell &c2) const
158  {
159  return (this->getNum() == c2.getNum());
160  }
161 };
162 
163 // A cell that is a combination of cells of same dimension
164 class CombinedCell : public Cell {
165 private:
166  // list of cells this cell is a combination of
167  std::map<Cell *, int, CellPtrLessThan> _cells;
168 
169 public:
170  CombinedCell(Cell *c1, Cell *c2, bool orMatch, bool co = false);
171  CombinedCell(std::vector<Cell *> &cells);
173 
174  int getDim() const { return _cells.begin()->first->getDim(); }
175  void getCells(std::map<Cell *, int, CellPtrLessThan> &cells)
176  {
177  cells = _cells;
178  }
179  int getNumCells() const { return _cells.size(); }
180  bool hasVertex(int vertex) const;
181 
182  bool operator==(const Cell &c2) const
183  {
184  return (this->getNum() == c2.getNum());
185  }
186 };
187 
188 #endif
Cell::getNumSortedVertices
int getNumSortedVertices() const
Definition: Cell.h:89
Cell::_globalNum
static int _globalNum
Definition: Cell.h:44
Cell::_cbd
std::map< Cell *, BdInfo, CellPtrLessThan > _cbd
Definition: Cell.h:56
Cell::getCoboundarySize
int getCoboundarySize(bool orig=false)
Definition: Cell.cpp:661
Cell::operator==
bool operator==(const Cell &c2) const
Definition: Cell.h:157
Cell::_si
std::vector< char > _si
Definition: Cell.h:64
Cell::isCombined
bool isCombined() const
Definition: Cell.h:147
CombinedCell::CombinedCell
CombinedCell(Cell *c1, Cell *c2, bool orMatch, bool co=false)
Definition: Cell.cpp:719
Cell::_bd
std::map< Cell *, BdInfo, CellPtrLessThan > _bd
Definition: Cell.h:55
CombinedCell::_cells
std::map< Cell *, int, CellPtrLessThan > _cells
Definition: Cell.h:167
MVertex
Definition: MVertex.h:24
Cell::hasBoundary
bool hasBoundary(Cell *cell, bool orig=false)
Definition: Cell.cpp:597
Cell::saveCellBoundary
void saveCellBoundary()
Definition: Cell.cpp:517
CombinedCell::operator==
bool operator==(const Cell &c2) const
Definition: Cell.h:182
Cell::setNum
void setNum(int num)
Definition: Cell.h:80
Cell::removeCoboundaryCell
void removeCoboundaryCell(Cell *cell, bool other)
Definition: Cell.cpp:587
Cell::hasCoboundary
bool hasCoboundary(Cell *cell, bool orig=false)
Definition: Cell.cpp:611
Cell::~Cell
virtual ~Cell()
Definition: Cell.h:75
Cell::printCoboundary
virtual void printCoboundary()
Definition: Cell.cpp:707
Cell::getMeshVertex
MVertex * getMeshVertex(int vertex) const
Definition: Cell.h:92
BdInfo::_ori
signed char _ori[2]
Definition: Cell.h:25
Cell::removeBoundaryCell
void removeBoundaryCell(Cell *cell, bool other)
Definition: Cell.cpp:577
Cell::_num
int _num
Definition: Cell.h:46
Cell::increaseGlobalNum
void increaseGlobalNum()
Definition: Cell.h:98
Cell::getCells
virtual void getCells(std::map< Cell *, int, CellPtrLessThan > &cells)
Definition: Cell.h:150
CellPtrLessThan
Definition: Cell.h:17
Cell::firstBoundary
biter firstBoundary(bool orig=false)
Definition: Cell.cpp:625
Cell::addCoboundaryCell
void addCoboundaryCell(int orientation, Cell *cell, bool other)
Definition: Cell.cpp:560
BdInfo::reset
void reset()
Definition: Cell.h:35
Cell::findBdElement
void findBdElement(int i, std::vector< MVertex * > &vertices) const
Definition: Cell.cpp:122
Cell::_immune
bool _immune
Definition: Cell.h:52
Cell::biter
std::map< Cell *, BdInfo, CellPtrLessThan >::iterator biter
Definition: Cell.h:108
Cell::getImmune
bool getImmune() const
Definition: Cell.h:87
Cell::_sortVertexIndices
bool _sortVertexIndices()
Definition: Cell.cpp:99
Cell::getDim
virtual int getDim() const
Definition: Cell.h:82
Cell::inSubdomain
bool inSubdomain() const
Definition: Cell.h:83
Cell::getBoundarySize
int getBoundarySize(bool orig=false)
Definition: Cell.cpp:649
Cell::citer
std::map< Cell *, int, CellPtrLessThan >::iterator citer
Definition: Cell.h:149
BdInfo::get
int get() const
Definition: Cell.h:34
Cell::_combined
bool _combined
Definition: Cell.h:50
Cell::getSortedVertex
int getSortedVertex(int vertex) const
Definition: Cell.cpp:117
CombinedCell::~CombinedCell
~CombinedCell()
Definition: Cell.h:172
Cell::findBdCellOrientation
int findBdCellOrientation(Cell *cell, int i) const
Definition: Cell.cpp:194
Cell::lastCoboundary
biter lastCoboundary()
Definition: Cell.cpp:647
CellPtrLessThan::operator()
bool operator()(const Cell *c1, const Cell *c2) const
Definition: Cell.cpp:16
Cell
Definition: Cell.h:42
Cell::_dim
char _dim
Definition: Cell.h:61
Cell::hasVertex
virtual bool hasVertex(int vertex) const
Definition: Cell.cpp:485
MElement
Definition: MElement.h:30
Cell::getBoundary
void getBoundary(std::map< Cell *, short int, CellPtrLessThan > &boundary, bool orig=false)
Definition: Cell.cpp:673
Cell::getNum
int getNum() const
Definition: Cell.h:79
element
Definition: shapeFunctions.h:12
Cell::getTypeMSH
int getTypeMSH() const
Definition: Cell.cpp:462
Cell::_domain
char _domain
Definition: Cell.h:47
CombinedCell::getDim
int getDim() const
Definition: Cell.h:174
Cell::_v
std::vector< MVertex * > _v
Definition: Cell.h:62
Cell::setImmune
void setImmune(bool immune)
Definition: Cell.h:86
Cell::addBoundaryCell
void addBoundaryCell(int orientation, Cell *cell, bool other)
Definition: Cell.cpp:543
Cell::printCell
virtual void printCell()
Definition: Cell.cpp:506
CombinedCell::getNumCells
int getNumCells() const
Definition: Cell.h:179
Cell::firstCoboundary
biter firstCoboundary(bool orig=false)
Definition: Cell.cpp:637
Cell::getMeshVertices
void getMeshVertices(std::vector< MVertex * > &v) const
Definition: Cell.h:84
CombinedCell::getCells
void getCells(std::map< Cell *, int, CellPtrLessThan > &cells)
Definition: Cell.h:175
Cell::createCell
static std::pair< Cell *, bool > createCell(MElement *element, int domain)
Definition: Cell.cpp:45
BdInfo::set
void set(int ori)
Definition: Cell.h:37
MElement.h
Cell::getCoboundary
void getCoboundary(std::map< Cell *, short int, CellPtrLessThan > &coboundary, bool orig=false)
Definition: Cell.cpp:684
Cell::restoreCellBoundary
void restoreCellBoundary()
Definition: Cell.cpp:527
Cell::Cell
Cell()
Definition: Cell.h:58
BdInfo
Definition: Cell.h:23
CombinedCell
Definition: Cell.h:164
BdInfo::geto
int geto() const
Definition: Cell.h:38
Cell::lastBoundary
biter lastBoundary()
Definition: Cell.cpp:635
Cell::getNumBdElements
int getNumBdElements() const
Definition: Cell.cpp:171
BdInfo::BdInfo
BdInfo(int ori)
Definition: Cell.h:28
Cell::getNumVertices
int getNumVertices() const
Definition: Cell.h:91
Cell::setDomain
void setDomain(int domain)
Definition: Cell.h:78
BdInfo::init
void init()
Definition: Cell.h:36
c1
const double c1
Definition: GaussQuadratureHex.cpp:16
Cell::getNumCells
virtual int getNumCells() const
Definition: Cell.h:155
Cell::printBoundary
virtual void printBoundary()
Definition: Cell.cpp:695
Cell::getDomain
int getDomain() const
Definition: Cell.h:77
CombinedCell::hasVertex
bool hasVertex(int vertex) const
Definition: Cell.cpp:498