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

Go to the source code of this file.

Functions

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

Function Documentation

◆ chk()

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

Definition at line 64 of file MakePeriodicConnMesh.cpp.

65{
66 if (ier)
67 {
68 printf("FAILED: %s\n", what);
69 cg_error_print();
70 exit(1);
71 }
72}

Referenced by main().

◆ main()

int main ( int  ,
char **  argv 
)

Definition at line 74 of file MakePeriodicConnMesh.cpp.

75{
76 int fn, ns;
77 char zname[33];
78 cgsize_t sz[9];
79
80 chk(cg_open(argv[1], CG_MODE_MODIFY, &fn), "open");
81 chk(cg_zone_read(fn, 1, 1, zname, sz), "zone read");
82 chk(cg_nsections(fn, 1, 1, &ns), "nsections");
83
84 /* Take the two sides from the boundary conditions that already name them.
85 */
86 int nbc;
87 chk(cg_nbocos(fn, 1, 1, &nbc), "nbocos");
88
89 std::vector<cgsize_t> side[2];
90 cgsize_t count[2] = {0, 0};
91 for (int I = 1; I <= nbc; ++I)
92 {
93 char bn[33];
94 CGNS_ENUMT(BCType_t) bt;
95 CGNS_ENUMT(PointSetType_t) ps;
96 cgsize_t np, nls;
97 int ni[3], nd;
98 CGNS_ENUMT(DataType_t) ndt;
99 chk(cg_boco_info(fn, 1, 1, I, bn, &bt, &ps, &np, ni, &nls, &ndt, &nd),
100 "boco info");
101 int w = strstr(bn, "Inlet") ? 0 : (strstr(bn, "Outlet") ? 1 : -1);
102 if (w < 0)
103 {
104 continue;
105 }
106 side[w].resize(np);
107 count[w] = np;
108 chk(cg_boco_read(fn, 1, 1, I, side[w].data(), nullptr), "boco read");
109 printf("side %d from '%s': %ld faces\n", w, bn, (long)np);
110 }
111 if (side[0].empty() || side[1].empty())
112 {
113 printf("inlet/outlet not found\n");
114 return 1;
115 }
116
117 /* Abutting1to1 pairs face for face, so both sides are the same length. */
118 cgsize_t *a = side[0].data(), *b = side[1].data();
119 cgsize_t n = count[0] < count[1] ? count[0] : count[1];
120 printf("zone '%s': periodic pair declared over %ld + %ld faces, leaving "
121 "%ld of the inlet and %ld of the outlet to their conditions\n",
122 zname, (long)n, (long)n, (long)(count[0] - n), (long)(count[1] - n));
123
124 float centre[3] = {0, 0, 0}, angle[3] = {0, 0, 0};
125 float fwd[3] = {0, 0, 1}, rev[3] = {0, 0, -1};
126
127 int J;
128 chk(cg_conn_write(fn, 1, 1, "periodic_a", CGNS_ENUMV(FaceCenter),
129 CGNS_ENUMV(Abutting1to1), CGNS_ENUMV(PointList), n, a,
130 zname, CGNS_ENUMV(Unstructured),
131 CGNS_ENUMV(PointListDonor), CGNS_ENUMV(LongInteger), n, b,
132 &J),
133 "conn a");
134 chk(cg_conn_periodic_write(fn, 1, 1, J, centre, angle, fwd), "periodic a");
135
136 chk(cg_conn_write(fn, 1, 1, "periodic_b", CGNS_ENUMV(FaceCenter),
137 CGNS_ENUMV(Abutting1to1), CGNS_ENUMV(PointList), n, b,
138 zname, CGNS_ENUMV(Unstructured),
139 CGNS_ENUMV(PointListDonor), CGNS_ENUMV(LongInteger), n, a,
140 &J),
141 "conn b");
142 chk(cg_conn_periodic_write(fn, 1, 1, J, centre, angle, rev), "periodic b");
143
144 chk(cg_close(fn), "close");
145 printf("done\n");
146 return 0;
147}
static void chk(int ier, const char *what)

References chk().