gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
CGNSCommon.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 // Contributor(s):
7 // Thomas Toulorge
8 
9 #ifndef CGNS_COMMON_H
10 #define CGNS_COMMON_H
11 
12 #include "GmshConfig.h"
13 
14 #if defined(HAVE_LIBCGNS)
15 
16 #include <cgnslib.h>
17 #if CGNS_VERSION < 3100
18 typedef int cgsize_t
19 #endif
20 
21 template <class scalar>
22 class fullMatrix;
23 
24 int cgnsError(const char *file, const int line, const int fileIndex = -1);
25 
26 void printProgress(const char *cstr, std::size_t i, std::size_t num);
27 
28 #if defined(HAVE_LIBCGNS_CPEX0045)
29 int evalMonomialBasis(int mshType, const std::vector<double> &u,
30  const std::vector<double> &v,
31  const std::vector<double> &w, fullMatrix<double> &val);
32 #endif
33 
34 // Multi-D (IJ/IJK) to linear index conversion (indices start at 0)
35 template <int DIM>
36 inline cgsize_t ijk2Ind(const cgsize_t *ijk, const cgsize_t *nijk);
37 
38 // 2D (IJ) to linear index conversion (indices start at 0)
39 template <>
40 inline cgsize_t ijk2Ind<2>(const cgsize_t *ijk, const cgsize_t *nijk)
41 {
42  return ijk[1] * nijk[0] + ijk[0];
43 }
44 
45 // 3D (IJK) to linear index conversion (indices start at 0)
46 template <>
47 inline cgsize_t ijk2Ind<3>(const cgsize_t *ijk, const cgsize_t *nijk)
48 {
49  return (ijk[2] * nijk[1] + ijk[1]) * nijk[0] + ijk[0];
50 }
51 
52 // Multi-D (IJ/IJK) to linear number of entities
53 template <int DIM> inline cgsize_t nbTotFromIJK(const cgsize_t *nijk);
54 
55 // 2D (IJ) to linear number of entities
56 template <> inline cgsize_t nbTotFromIJK<2>(const cgsize_t *nijk)
57 {
58  return nijk[0] * nijk[1];
59 }
60 
61 // 3D (IJK) to linear number of entities
62 template <> inline cgsize_t nbTotFromIJK<3>(const cgsize_t *nijk)
63 {
64  return nijk[0] * nijk[1] * nijk[2];
65 }
66 
67 // class to manage indexing in CGNS unstructured zones (starting from 1)
68 struct UnstructuredIndexing {
69  static cgsize_t nbEntInRange(const cgsize_t *range);
70  static void entFromRange(const cgsize_t *range, std::vector<cgsize_t> &elt);
71  static void entFromList(const std::vector<cgsize_t> &list,
72  std::vector<cgsize_t> &elt);
73 };
74 
75 inline cgsize_t UnstructuredIndexing::nbEntInRange(const cgsize_t *range)
76 {
77  return range[1] - range[0] + 1;
78 }
79 
80 inline void UnstructuredIndexing::entFromRange(const cgsize_t *range,
81  std::vector<cgsize_t> &ent)
82 {
83  std::size_t nb = range[1] - range[0] + 1;
84  ent.resize(nb);
85  cgsize_t iMin = range[0] - 1;
86  for(std::size_t i = 0; i < nb; i++) ent[i] = iMin + i;
87 }
88 
89 inline void UnstructuredIndexing::entFromList(const std::vector<cgsize_t> &list,
90  std::vector<cgsize_t> &ent)
91 {
92  std::size_t nb = list.size();
93  ent.resize(nb);
94  for(std::size_t i = 0; i < nb; i++) ent[i] = list[i] - 1;
95 }
96 
97 // class to manage indexing in CGNS structured zones (starting from (1, 1, 1)),
98 // explicitly instantiated for 2D and 3D in .cpp file
99 template <int DIM> struct StructuredIndexing {
100  static cgsize_t nbEntInRange(const cgsize_t *range);
101  static void entFromRange(const cgsize_t *range, const cgsize_t *nbEntIJK,
102  std::vector<cgsize_t> &elt);
103  static void entFromList(const std::vector<cgsize_t> &list,
104  const cgsize_t *nbEntIJK, std::vector<cgsize_t> &elt);
105 };
106 
107 template <int DIM>
108 inline cgsize_t StructuredIndexing<DIM>::nbEntInRange(const cgsize_t *range)
109 {
110  cgsize_t nb = 1;
111  for(int d = 0; d < DIM; d++) {
112  const cgsize_t diff = range[DIM + d] - range[d];
113  nb *= (diff >= 0) ? diff + 1 : -diff + 1;
114  }
115  return nb;
116 }
117 
118 #endif // HAVE_LIBCGNS
119 
120 #endif // CGNS_COMMON_H
fullMatrix
Definition: MElement.h:27
line
Definition: shapeFunctions.h:342