Nektar++
Loading...
Searching...
No Matches
Classes | Macros | Functions
MakeMixedPidMesh.cpp File Reference
#include <cgnslib.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>

Go to the source code of this file.

Classes

struct  Elem
 

Macros

#define MAXE   16
 

Functions

static void chk (int ier, const char *what)
 
int main (int, char **argv)
 

Macro Definition Documentation

◆ MAXE

#define MAXE   16

Definition at line 66 of file MakeMixedPidMesh.cpp.

Function Documentation

◆ chk()

static void chk ( int  ier,
const char *  what 
)
static

Definition at line 75 of file MakeMixedPidMesh.cpp.

76{
77 if (ier)
78 {
79 printf("FAILED: %s\n", what);
80 cg_error_print();
81 exit(1);
82 }
83}

Referenced by main().

◆ main()

int main ( int  ,
char **  argv 
)

Definition at line 85 of file MakeMixedPidMesh.cpp.

86{
87 int fn, nz, ns, nbc;
88 cgsize_t sz[9];
89 char zname[33];
90
91 chk(cg_open(argv[1], CG_MODE_READ, &fn), "open in");
92 cg_nzones(fn, 1, &nz);
93 chk(cg_zone_read(fn, 1, 1, zname, sz), "zone read");
94 cgsize_t nvert = sz[0];
95
96 std::vector<double> x(nvert), y(nvert), z(nvert);
97 cgsize_t rmin = 1, rmax = nvert;
98 chk(cg_coord_read(fn, 1, 1, "CoordinateX", RealDouble, &rmin, &rmax,
99 x.data()),
100 "x");
101 chk(cg_coord_read(fn, 1, 1, "CoordinateY", RealDouble, &rmin, &rmax,
102 y.data()),
103 "y");
104 chk(cg_coord_read(fn, 1, 1, "CoordinateZ", RealDouble, &rmin, &rmax,
105 z.data()),
106 "z");
107
108 /* Read every section into a flat element list indexed by CGNS element
109 number, so that a boundary condition's point list can be followed. */
110 cg_nsections(fn, 1, 1, &ns);
111 cgsize_t maxid = 0;
112 for (int S = 1; S <= ns; ++S)
113 {
114 char n[33];
115 CGNS_ENUMT(ElementType_t) et;
116 cgsize_t st, en;
117 int nb, pf;
118 cg_section_read(fn, 1, 1, S, n, &et, &st, &en, &nb, &pf);
119 if (en > maxid)
120 {
121 maxid = en;
122 }
123 }
124 std::vector<Elem> all(maxid + 1);
125
126 for (int S = 1; S <= ns; ++S)
127 {
128 char n[33];
129 CGNS_ENUMT(ElementType_t) et;
130 cgsize_t st, en;
131 int nb, pf, npe;
132 cg_section_read(fn, 1, 1, S, n, &et, &st, &en, &nb, &pf);
133 cgsize_t eds;
134 cg_ElementDataSize(fn, 1, 1, S, &eds);
135 std::vector<cgsize_t> c(eds);
136 cgsize_t pd;
137 chk(cg_elements_read(fn, 1, 1, S, c.data(), &pd), "elements read");
138 cg_npe(et, &npe);
139 for (cgsize_t e = st; e <= en; ++e)
140 {
141 all[e].type = (int)et;
142 all[e].n = npe;
143 memcpy(all[e].v, &c[(e - st) * npe], npe * sizeof(cgsize_t));
144 }
145 printf(" read section '%s' %s %ld..%ld\n", n, ElementTypeName[et],
146 (long)st, (long)en);
147 }
148
149 /* Surface parts come from the boundary conditions of the source. */
150 cg_nbocos(fn, 1, 1, &nbc);
151 std::vector<cgsize_t> bclist[MAXE];
152 cgsize_t bcn[MAXE];
153 for (int I = 1; I <= nbc; ++I)
154 {
155 char n[33];
156 CGNS_ENUMT(BCType_t) bt;
157 CGNS_ENUMT(PointSetType_t) ps;
158 cgsize_t np, nls;
159 int ni[3], nd;
160 CGNS_ENUMT(DataType_t) ndt;
161 cg_boco_info(fn, 1, 1, I, n, &bt, &ps, &np, ni, &nls, &ndt, &nd);
162 bclist[I - 1].resize(np);
163 bcn[I - 1] = np;
164 chk(cg_boco_read(fn, 1, 1, I, bclist[I - 1].data(), nullptr),
165 "boco read");
166 printf(" read bc '%s' %ld faces\n", n, (long)np);
167 }
168 cg_close(fn);
169
170 /* Parts, in the order they will be written. Source BC order on this mesh
171 is Wall, Inlet, Outlet; the wall is split so that one part ends up with
172 no boundary condition. */
173 const char *pname[5] = {"inlet", "outlet", "periodic1", "wall", nullptr};
174 int phasbc[4] = {1, 1, 0, 1};
175 cgsize_t *psrc[4];
176 cgsize_t pcnt[4];
177 psrc[0] = bclist[1].data();
178 pcnt[0] = bcn[1]; /* inlet 104 */
179 psrc[1] = bclist[2].data();
180 pcnt[1] = bcn[2]; /* outlet 100 */
181 psrc[2] = bclist[0].data();
182 pcnt[2] = 100; /* wall[0..100) */
183 psrc[3] = bclist[0].data() + 100;
184 pcnt[3] = bcn[0] - 100; /* wall[100..] */
185
186 chk(cg_open(argv[2], CG_MODE_WRITE, &fn), "open out");
187 int B, Z, F, S, BC;
188 chk(cg_base_write(fn, "Base", 3, 3, &B), "base");
189 for (int p = 0; p < 4; ++p)
190 {
191 if (phasbc[p])
192 {
193 chk(cg_family_write(fn, B, pname[p], &F), "family");
194 }
195 }
196
197 cgsize_t nvol = 0;
198 for (cgsize_t e = 1; e <= maxid; ++e)
199 {
200 int t = all[e].type;
201 if (t != CGNS_ENUMV(TRI_3) && t != CGNS_ENUMV(QUAD_4))
202 {
203 ++nvol;
204 }
205 }
206 cgsize_t zs[3] = {nvert, nvol, 0};
207 chk(cg_zone_write(fn, B, "fluid", zs, CGNS_ENUMV(Unstructured), &Z),
208 "zone");
209 chk(cg_coord_write(fn, B, Z, RealDouble, "CoordinateX", x.data(), &F),
210 "wx");
211 chk(cg_coord_write(fn, B, Z, RealDouble, "CoordinateY", y.data(), &F),
212 "wy");
213 chk(cg_coord_write(fn, B, Z, RealDouble, "CoordinateZ", z.data(), &F),
214 "wz");
215
216 /* One MIXED section per part, then one for the volume. */
217 cgsize_t next = 1;
218 cgsize_t prange[4][2];
219 std::vector<cgsize_t> conn(32 * (maxid + 1));
220 std::vector<cgsize_t> offs(maxid + 2);
221
222 for (int p = 0; p < 4; ++p)
223 {
224 cgsize_t k = 0;
225 for (cgsize_t i = 0; i < pcnt[p]; ++i)
226 {
227 Elem *el = &all[psrc[p][i]];
228 offs[i] = k;
229 conn[k++] = el->type;
230 for (int j = 0; j < el->n; ++j)
231 {
232 conn[k++] = el->v[j];
233 }
234 }
235 offs[pcnt[p]] = k;
236 prange[p][0] = next;
237 prange[p][1] = next + pcnt[p] - 1;
238 chk(cg_poly_section_write(fn, B, Z, pname[p], CGNS_ENUMV(MIXED),
239 prange[p][0], prange[p][1], 0, conn.data(),
240 offs.data(), &S),
241 "poly section");
242 printf(" wrote section '%s' MIXED %ld..%ld\n", pname[p],
243 (long)prange[p][0], (long)prange[p][1]);
244 next += pcnt[p];
245 }
246
247 cgsize_t k = 0, nv = 0;
248 for (cgsize_t e = 1; e <= maxid; ++e)
249 {
250 int t = all[e].type;
251 if (t == CGNS_ENUMV(TRI_3) || t == CGNS_ENUMV(QUAD_4))
252 {
253 continue;
254 }
255 offs[nv++] = k;
256 conn[k++] = t;
257 for (int j = 0; j < all[e].n; ++j)
258 {
259 conn[k++] = all[e].v[j];
260 }
261 }
262 offs[nv] = k;
263 chk(cg_poly_section_write(fn, B, Z, "VolumeElements", CGNS_ENUMV(MIXED),
264 next, next + nv - 1, 0, conn.data(), offs.data(),
265 &S),
266 "vol");
267 printf(" wrote section 'VolumeElements' MIXED %ld..%ld\n", (long)next,
268 (long)(next + nv - 1));
269
270 /* Boundary conditions over the new element numbering. */
271 for (int p = 0; p < 4; ++p)
272 {
273 if (!phasbc[p])
274 {
275 continue;
276 }
277 std::vector<cgsize_t> pl(pcnt[p]);
278 for (cgsize_t i = 0; i < pcnt[p]; ++i)
279 {
280 pl[i] = prange[p][0] + i;
281 }
282 char bcname[64];
283 snprintf(bcname, sizeof(bcname), "%s_1", pname[p]);
284 chk(cg_boco_write(fn, B, Z, bcname, CGNS_ENUMV(BCTypeUserDefined),
285 CGNS_ENUMV(PointList), pcnt[p], pl.data(), &BC),
286 "boco");
287 chk(cg_boco_gridlocation_write(fn, B, Z, BC, CGNS_ENUMV(FaceCenter)),
288 "gridloc");
289 chk(cg_goto(fn, B, "Zone_t", Z, "ZoneBC_t", 1, "BC_t", BC, "end"),
290 "goto bc");
291 chk(cg_famname_write(pname[p]), "famname");
292 printf(" wrote bc '%s' %ld faces, family '%s'\n", bcname,
293 (long)pcnt[p], pname[p]);
294 }
295
296 cg_close(fn);
297 printf("done\n");
298 return 0;
299}
static void chk(int ier, const char *what)
#define MAXE
static double Z[NNODE]
SpatialDomains::Geometry * el
std::vector< double > p(NPUPPER)

References chk(), el, MAXE, Elem::type, and Z.