gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
BasisFactory.cpp
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 #include "BasisFactory.h"
7 #include "GmshDefines.h"
8 #include "polynomialBasis.h"
9 #include "pyramidalBasis.h"
10 #include "bezierBasis.h"
11 #include "miniBasis.h"
12 #include "CondNumBasis.h"
13 #include "JacobianBasis.h"
14 #include <map>
15 #include <cstddef>
16 
17 std::map<int, nodalBasis *> BasisFactory::fs;
18 std::map<int, CondNumBasis *> BasisFactory::cs;
19 std::map<FuncSpaceData, JacobianBasis *> BasisFactory::js;
20 std::map<FuncSpaceData, bezierBasis *> BasisFactory::bs;
21 std::map<FuncSpaceData, GradientBasis *> BasisFactory::gs;
22 
24 {
25  // If the Basis has already been built, return it.
26  auto it = fs.find(tag);
27  if(it != fs.end()) { return it->second; }
28  // Get the parent type to see which kind of basis
29  // we want to create
30  nodalBasis *F = nullptr;
31  if(tag == MSH_TRI_MINI)
32  F = new miniBasisTri();
33  else if(tag == MSH_TET_MINI)
34  F = new miniBasisTet();
35  else {
36  int parentType = ElementType::getParentType(tag);
37  switch(parentType) {
38  case(TYPE_PNT):
39  case(TYPE_LIN):
40  case(TYPE_TRI):
41  case(TYPE_QUA):
42  case(TYPE_PRI):
43  case(TYPE_TET):
44  case(TYPE_HEX): F = new polynomialBasis(tag); break;
45  case(TYPE_PYR): F = new pyramidalBasis(tag); break;
46  default:
47  Msg::Error("Unknown type of element %d (in BasisFactory)", tag);
48  return nullptr;
49  }
50  }
51 
52  std::pair<std::map<int, nodalBasis *>::const_iterator, bool> inserted;
53 #pragma omp critical
54  {
55  inserted = fs.insert(std::make_pair(tag, F));
56  if(!inserted.second) delete F;
57  }
58 
59  return inserted.first->second;
60 }
61 
63 {
65 
66  auto it = js.find(data);
67  if(it != js.end()) return it->second;
68 
69  JacobianBasis *J = new JacobianBasis(tag, data);
70  js.insert(std::make_pair(data, J));
71  return J;
72 }
73 
75 {
76  const int type = ElementType::getParentType(tag);
77  if(type != TYPE_PYR)
78  return getJacobianBasis(tag, FuncSpaceData(type, order, false));
79  else
80  return getJacobianBasis(
81  tag, FuncSpaceData(type, false, order + 1, order, false));
82 }
83 
85 {
86  const int jacOrder = JacobianBasis::jacobianOrder(tag);
87  const int type = ElementType::getParentType(tag);
88  if(type != TYPE_PYR)
89  return getJacobianBasis(tag, FuncSpaceData(type, jacOrder, false));
90  else
91  return getJacobianBasis(
92  tag, FuncSpaceData(type, false, jacOrder + 2, jacOrder, false));
93 }
94 
95 const CondNumBasis *BasisFactory::getCondNumBasis(int tag, int cnOrder)
96 {
97  auto it = cs.find(tag);
98  if(it != cs.end()) return it->second;
99 
100  CondNumBasis *M = new CondNumBasis(tag, cnOrder);
101  cs.insert(std::make_pair(tag, M));
102  return M;
103 }
104 
106 {
108 
109  auto it = gs.find(data);
110  if(it != gs.end()) return it->second;
111 
112  GradientBasis *G = new GradientBasis(tag, data);
113  gs.insert(std::make_pair(data, G));
114  return G;
115 }
116 
118 {
119  const int type = ElementType::getParentType(tag);
120  return getGradientBasis(tag, FuncSpaceData(type, order, false));
121 }
122 
124 {
125  return getGradientBasis(tag, FuncSpaceData(tag));
126 }
127 
129 {
131 
132  auto it = bs.find(data);
133  if(it != bs.end()) return it->second;
134 
135  bezierBasis *B = new bezierBasis(data);
136  bs.insert(std::make_pair(data, B));
137  return B;
138 }
139 
140 const bezierBasis *BasisFactory::getBezierBasis(int parentType, int order)
141 {
142  return getBezierBasis(FuncSpaceData(parentType, order, false));
143 }
144 
146 {
147  return getBezierBasis(FuncSpaceData(tag));
148 }
149 
151 {
152  auto itF = fs.begin();
153  while(itF != fs.end()) {
154  delete itF->second;
155  itF++;
156  }
157  fs.clear();
158 
159  auto itJ = js.begin();
160  while(itJ != js.end()) {
161  delete itJ->second;
162  itJ++;
163  }
164  js.clear();
165 
166  auto itC = cs.begin();
167  while(itC != cs.end()) {
168  delete itC->second;
169  itC++;
170  }
171  cs.clear();
172 
173  auto itG = gs.begin();
174  while(itG != gs.end()) {
175  delete itG->second;
176  itG++;
177  }
178  gs.clear();
179 
180  auto itB = bs.begin();
181  while(itB != bs.end()) {
182  delete itB->second;
183  itB++;
184  }
185  bs.clear();
186 }
BasisFactory::fs
static std::map< int, nodalBasis * > fs
Definition: BasisFactory.h:19
BasisFactory::getJacobianBasis
static const JacobianBasis * getJacobianBasis(int tag, FuncSpaceData)
Definition: BasisFactory.cpp:62
miniBasis.h
pyramidalBasis.h
TYPE_LIN
#define TYPE_LIN
Definition: GmshDefines.h:65
F
#define F
Definition: DefaultOptions.h:23
bezierBasis
Definition: bezierBasis.h:20
BasisFactory::js
static std::map< FuncSpaceData, JacobianBasis * > js
Definition: BasisFactory.h:21
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
CondNumBasis
Definition: CondNumBasis.h:14
TYPE_PNT
#define TYPE_PNT
Definition: GmshDefines.h:64
MSH_TET_MINI
#define MSH_TET_MINI
Definition: GmshDefines.h:225
TYPE_TRI
#define TYPE_TRI
Definition: GmshDefines.h:66
FuncSpaceData::getForNonSerendipitySpace
FuncSpaceData getForNonSerendipitySpace() const
Definition: FuncSpaceData.cpp:90
TYPE_PRI
#define TYPE_PRI
Definition: GmshDefines.h:70
BasisFactory::gs
static std::map< FuncSpaceData, GradientBasis * > gs
Definition: BasisFactory.h:23
BasisFactory::getNodalBasis
static const nodalBasis * getNodalBasis(int tag)
Definition: BasisFactory.cpp:23
JacobianBasis::jacobianOrder
static int jacobianOrder(int tag)
Definition: JacobianBasis.cpp:813
BasisFactory::getBezierBasis
static const bezierBasis * getBezierBasis(FuncSpaceData)
Definition: BasisFactory.cpp:128
CondNumBasis.h
BasisFactory::getGradientBasis
static const GradientBasis * getGradientBasis(int tag, FuncSpaceData)
Definition: BasisFactory.cpp:105
GmshDefines.h
JacobianBasis.h
pyramidalBasis
Definition: pyramidalBasis.h:13
BasisFactory::cs
static std::map< int, CondNumBasis * > cs
Definition: BasisFactory.h:20
TYPE_PYR
#define TYPE_PYR
Definition: GmshDefines.h:69
FuncSpaceData
Definition: FuncSpaceData.h:16
TYPE_QUA
#define TYPE_QUA
Definition: GmshDefines.h:67
miniBasisTet
Definition: miniBasis.h:17
polynomialBasis.h
nodalBasis
Definition: nodalBasis.h:12
JacobianBasis
Definition: JacobianBasis.h:60
BasisFactory::getCondNumBasis
static const CondNumBasis * getCondNumBasis(int tag, int cnOrder=-1)
Definition: BasisFactory.cpp:95
MSH_TRI_MINI
#define MSH_TRI_MINI
Definition: GmshDefines.h:224
TYPE_HEX
#define TYPE_HEX
Definition: GmshDefines.h:71
TYPE_TET
#define TYPE_TET
Definition: GmshDefines.h:68
miniBasisTri
Definition: miniBasis.h:13
polynomialBasis
Definition: polynomialBasis.h:16
BasisFactory::clearAll
static void clearAll()
Definition: BasisFactory.cpp:150
bezierBasis.h
GradientBasis
Definition: JacobianBasis.h:12
ElementType::getParentType
int getParentType(int type)
Definition: ElementType.cpp:10
BasisFactory::bs
static std::map< FuncSpaceData, bezierBasis * > bs
Definition: BasisFactory.h:22
BasisFactory.h