gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
CGNSCommon.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 // Contributor(s):
7 // Thomas Toulorge
8 
9 #include "GmshConfig.h"
10 #include "GmshMessage.h"
11 #include "ElementType.h"
12 #include "BergotBasis.h"
13 #include "fullMatrix.h"
14 #include "CGNSCommon.h"
15 
16 #if defined(HAVE_LIBCGNS)
17 
18 int cgnsError(const char *file, const int line, const int fileIndex)
19 {
20  if(Msg::GetVerbosity() < 99)
21  Msg::Error("CGNS error %s", cg_get_error());
22  else
23  Msg::Error("CGNS error %s (%s:%i)", cg_get_error(), file, line);
24  if(fileIndex != -1) {
25  if(cg_close(fileIndex)) { Msg::Error("Unable to close CGNS file"); }
26  }
27  return 0;
28 }
29 
30 void printProgress(const char *cstr, std::size_t i, std::size_t num)
31 {
32  if(num > 100) {
33  if(i % 100 == 1) { Msg::Info("%s %d/%d", cstr, i, num); }
34  }
35  else {
36  Msg::Info("%s %d/%d", cstr, i, num);
37  }
38 }
39 
40 #if defined(HAVE_LIBCGNS_CPEX0045)
41 
42 int evalMonomialBasis(int mshType, const std::vector<double> &u,
43  const std::vector<double> &v,
44  const std::vector<double> &w, fullMatrix<double> &val)
45 {
46  // get parent type and order
47  const int parentType = ElementType::getParentType(mshType);
48  const int order = ElementType::getOrder(mshType);
49 
50  // get serendipity
51  const int serend = ElementType::getSerendipity(mshType);
52  if(serend > 1) {
53  Msg::Error("Serendipity elements are not supported in CPEX0045 mode in "
54  "CGNS reader");
55  return 0;
56  }
57 
58  // compute values of monomials at given points
59  int nbPt = u.size();
60  if(parentType == TYPE_PNT) { val(0, 0) = 1.; }
61  else if(parentType == TYPE_LIN) {
62  for(int iPt = 0; iPt < nbPt; iPt++) {
63  val(0, iPt) = 1.;
64  for(int i = 1; i <= order; i++) val(i, iPt) = u[iPt] * val(i - 1, iPt);
65  }
66  }
67  else if(parentType == TYPE_TRI) {
68  for(int iPt = 0; iPt < nbPt; iPt++) {
69  int iSF = 0;
70  for(int i = 0; i <= order; i++) {
71  for(int j = 0; j <= i; j++) {
72  val(iSF, iPt) = std::pow(u[iPt], i - j) * std::pow(v[iPt], j);
73  iSF++;
74  }
75  }
76  }
77  }
78  else if(parentType == TYPE_QUA) {
79  for(int iPt = 0; iPt < nbPt; iPt++) {
80  int iSF = 0;
81  for(int i = 0; i <= order; i++) {
82  for(int j = 0; j <= order; j++) {
83  val(iSF, iPt) = std::pow(u[iPt], i) * std::pow(v[iPt], j);
84  iSF++;
85  }
86  }
87  }
88  }
89  else if(parentType == TYPE_TET) {
90  for(int iPt = 0; iPt < nbPt; iPt++) {
91  int iSF = 0;
92  for(int i = 0; i <= order; i++) {
93  for(int j = 0; j <= i; j++) {
94  for(int k = 0; k <= i - j; k++) {
95  val(iSF, iPt) = std::pow(u[iPt], i - j - k) * std::pow(v[iPt], k) *
96  std::pow(w[iPt], j);
97  iSF++;
98  }
99  }
100  }
101  }
102  }
103  else if(parentType == TYPE_PYR) {
104  int nbSF = ElementType::getNumVertices(mshType);
105  BergotBasis bb(order);
106  for(int iPt = 0; iPt < nbPt; iPt++) {
107  double oneVal[385];
108  const double ww = 0.5 * (w[iPt] + 1.); // use Gmsh coord for BergotBasis
109  bb.f(u[iPt], v[iPt], ww, oneVal);
110  for(int iSF = 0; iSF < nbSF; iSF++) val(iSF, iPt) = oneVal[iSF];
111  }
112  }
113  else if(parentType == TYPE_PRI) {
114  for(int iPt = 0; iPt < nbPt; iPt++) {
115  int iSF = 0;
116  for(int i = 0; i <= order; i++) {
117  for(int j = 0; j <= i; j++) {
118  for(int k = 0; k <= order; k++) {
119  val(iSF, iPt) = std::pow(u[iPt], i - j) * std::pow(v[iPt], j) *
120  std::pow(w[iPt], k); // TODO: to be clarified
121  iSF++;
122  }
123  }
124  }
125  }
126  }
127  else if(parentType == TYPE_HEX) {
128  for(int iPt = 0; iPt < nbPt; iPt++) {
129  int iSF = 0;
130  for(int i = 0; i <= order; i++) {
131  for(int j = 0; j <= order; j++) {
132  for(int k = 0; k <= order; k++) {
133  val(iSF, iPt) =
134  std::pow(u[iPt], i) * std::pow(v[iPt], j) * std::pow(w[iPt], k);
135  iSF++;
136  }
137  }
138  }
139  }
140  }
141  else {
142  Msg::Error("Element of parent type %i is not supported in CPEX0045 mode "
143  "in CGNS reader",
144  parentType);
145  return 0;
146  }
147 
148  return 1;
149 }
150 
151 #endif // HAVE_LIBCGNS_CPEX0045
152 
153 template <int DIM>
154 void StructuredIndexing<DIM>::entFromRange(const cgsize_t *range,
155  const cgsize_t *nbEntIJK,
156  std::vector<cgsize_t> &elt)
157 {
158  elt.resize(nbEntInRange(range));
159 
160  // range of IJK indices
161  const cgsize_t ijkStart[3] = {range[0] - 1, range[1] - 1,
162  (DIM == 3) ? range[2] - 1 : 0};
163  const cgsize_t ijkEnd[3] = {range[DIM] - 1, range[DIM + 1] - 1,
164  (DIM == 3) ? range[5] - 1 : 0};
165  const cgsize_t ijkInc[3] = {(range[DIM] >= range[0]) ? 1 : -1,
166  (range[DIM + 1] >= range[1]) ? 1 : -1,
167  ((DIM < 3) || (range[5] >= range[2])) ? 1 : -1};
168 
169  // compute list of elements from range
170  std::size_t iElt = 0;
171  cgsize_t ijk[3], &i = ijk[0], &j = ijk[1], &k = ijk[2];
172  for(k = ijkStart[2]; k <= ijkEnd[2]; k += ijkInc[2]) {
173  for(j = ijkStart[1]; j <= ijkEnd[1]; j += ijkInc[1]) {
174  for(i = ijkStart[0]; i <= ijkEnd[0]; i += ijkInc[0]) {
175  elt[iElt] = ijk2Ind<DIM>(ijk, nbEntIJK);
176  iElt++;
177  }
178  }
179  }
180 }
181 
182 template <int DIM>
183 void StructuredIndexing<DIM>::entFromList(const std::vector<cgsize_t> &list,
184  const cgsize_t *nbEntIJK,
185  std::vector<cgsize_t> &elt)
186 {
187  std::size_t nb = list.size() / DIM;
188  elt.resize(nb);
189 
190  for(std::size_t i = 0; i < nb; i++) {
191  cgsize_t ijk[3];
192  for(int d = 0; d < DIM; d++) ijk[d] = list[i * DIM + d] - 1;
193  elt[i] = ijk2Ind<DIM>(ijk, nbEntIJK);
194  ;
195  }
196 }
197 
198 // explicit instantiation of StructuredIndexing
199 template struct StructuredIndexing<2>;
200 template struct StructuredIndexing<3>;
201 
202 #endif // HAVE_LIBCGNS
Msg::GetVerbosity
static int GetVerbosity()
Definition: GmshMessage.cpp:254
TYPE_LIN
#define TYPE_LIN
Definition: GmshDefines.h:65
Msg::Info
static void Info(const char *fmt,...)
Definition: GmshMessage.cpp:587
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
BergotBasis.h
TYPE_PNT
#define TYPE_PNT
Definition: GmshDefines.h:64
ElementType::getSerendipity
int getSerendipity(int type)
Definition: ElementType.cpp:598
TYPE_TRI
#define TYPE_TRI
Definition: GmshDefines.h:66
GmshMessage.h
TYPE_PRI
#define TYPE_PRI
Definition: GmshDefines.h:70
fullMatrix< double >
CGNSCommon.h
TYPE_PYR
#define TYPE_PYR
Definition: GmshDefines.h:69
TYPE_QUA
#define TYPE_QUA
Definition: GmshDefines.h:67
BergotBasis
Definition: BergotBasis.h:17
ElementType::getOrder
int getOrder(int type)
Definition: ElementType.cpp:158
TYPE_HEX
#define TYPE_HEX
Definition: GmshDefines.h:71
TYPE_TET
#define TYPE_TET
Definition: GmshDefines.h:68
ElementType::getNumVertices
int getNumVertices(int type)
Definition: ElementType.cpp:456
line
Definition: shapeFunctions.h:342
ElementType.h
ElementType::getParentType
int getParentType(int type)
Definition: ElementType.cpp:10
fullMatrix.h