Nektar++
Loading...
Searching...
No Matches
Macros | Functions | Variables
MakeTwistedPrismRing.cpp File Reference
#include <cgnslib.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>

Go to the source code of this file.

Macros

#define N   12
 
#define NV   (3 * N)
 
#define NNODE   (9 * N)
 
#define V(k, j)   ((k) * 3 + (j))
 
#define TM(k, j)   (NV + (k) * 3 + (j))
 
#define AM(k, j)   (NV + 3 * N + (k) * 3 + (j))
 

Functions

static void chk (int ier, const char *w)
 
static void mid (int m, int a, int b)
 
int main (int argc, char **argv)
 

Variables

static double X [NNODE]
 
static double Y [NNODE]
 
static double Z [NNODE]
 
static constexpr double kPi = 3.14159265358979323846
 

Macro Definition Documentation

◆ AM

#define AM (   k,
  j 
)    (NV + 3 * N + (k) * 3 + (j))

Definition at line 80 of file MakeTwistedPrismRing.cpp.

◆ N

#define N   12

Definition at line 72 of file MakeTwistedPrismRing.cpp.

◆ NNODE

#define NNODE   (9 * N)

Definition at line 74 of file MakeTwistedPrismRing.cpp.

◆ NV

#define NV   (3 * N)

Definition at line 73 of file MakeTwistedPrismRing.cpp.

◆ TM

#define TM (   k,
  j 
)    (NV + (k) * 3 + (j))

Definition at line 79 of file MakeTwistedPrismRing.cpp.

◆ V

#define V (   k,
  j 
)    ((k) * 3 + (j))

Definition at line 78 of file MakeTwistedPrismRing.cpp.

Function Documentation

◆ chk()

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

Definition at line 88 of file MakeTwistedPrismRing.cpp.

89{
90 if (ier)
91 {
92 printf("FAILED: %s\n", w);
93 cg_error_print();
94 exit(1);
95 }
96}

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 105 of file MakeTwistedPrismRing.cpp.

106{
107 if (argc != 3)
108 {
109 printf("usage: %s <out.cgns> <order 1|2>\n", argv[0]);
110 return 1;
111 }
112
113 const int order = atoi(argv[2]);
114 const double R = 3.0, r = 0.7;
115
116 for (int k = 0; k < N; ++k)
117 {
118 const double th = 2.0 * kPi * k / N;
119 const double cx = R * std::cos(th), cy = R * std::sin(th);
120 const double ux = std::cos(th), uy = std::sin(th);
121
122 for (int j = 0; j < 3; ++j)
123 {
124 /* the cross-section turns through a third over the whole ring */
125 const double a = 2.0 * kPi * j / 3.0 + (2.0 * kPi / 3.0) * k / N;
126 const int n = V(k, j);
127 X[n] = cx + r * std::cos(a) * ux;
128 Y[n] = cy + r * std::cos(a) * uy;
129 Z[n] = r * std::sin(a);
130 }
131 }
132
133 for (int k = 0; k < N; ++k)
134 {
135 const int nx = (k + 1) % N, sh = (k == N - 1) ? 1 : 0;
136 for (int j = 0; j < 3; ++j)
137 {
138 mid(TM(k, j), V(k, j), V(k, (j + 1) % 3));
139 mid(AM(k, j), V(k, j), V(nx, (j + sh) % 3));
140 }
141 }
142
143 const int nnode = (order == 2) ? NNODE : NV;
144
145 int fn, B, Z_, C, S;
146 chk(cg_open(argv[1], CG_MODE_WRITE, &fn), "open");
147 chk(cg_base_write(fn, "Base", 3, 3, &B), "base");
148
149 cgsize_t size[3] = {nnode, N, 0};
150 chk(cg_zone_write(fn, B, "fluid", size, Unstructured, &Z_), "zone");
151 chk(cg_coord_write(fn, B, Z_, RealDouble, "CoordinateX", X, &C), "x");
152 chk(cg_coord_write(fn, B, Z_, RealDouble, "CoordinateY", Y, &C), "y");
153 chk(cg_coord_write(fn, B, Z_, RealDouble, "CoordinateZ", Z, &C), "z");
154
155 /* The corners run the other way round from the order they were built in,
156 so that each prism comes out the right way out. */
157 const int np = (order == 2) ? 15 : 6;
158 static cgsize_t p[N * 15];
159
160 for (int k = 0; k < N; ++k)
161 {
162 const int nx = (k + 1) % N, sh = (k == N - 1) ? 1 : 0;
163 cgsize_t *e = p + k * np;
164
165 for (int j = 0; j < 3; ++j)
166 {
167 e[j] = V(k, (3 - j) % 3) + 1;
168 e[3 + j] = V(nx, ((3 - j) % 3 + sh) % 3) + 1;
169 }
170
171 if (order == 2)
172 {
173 e[6] = TM(k, 2) + 1;
174 e[7] = TM(k, 1) + 1;
175 e[8] = TM(k, 0) + 1;
176 e[9] = AM(k, 0) + 1;
177 e[10] = AM(k, 2) + 1;
178 e[11] = AM(k, 1) + 1;
179 e[12] = TM(nx, (2 + sh) % 3) + 1;
180 e[13] = TM(nx, (1 + sh) % 3) + 1;
181 e[14] = TM(nx, (0 + sh) % 3) + 1;
182 }
183 }
184
185 chk(cg_section_write(fn, B, Z_, "volume", (order == 2) ? PENTA_15 : PENTA_6,
186 1, N, 0, p, &S),
187 "penta");
188
189 /* Every quadrilateral face is on the outside of the ring; the triangular
190 ones are all interior, which is what makes the ring close. */
191 const int nq = (order == 2) ? 8 : 4;
192 static cgsize_t q[N * 3 * 8];
193 cgsize_t *w = q;
194
195 for (int k = 0; k < N; ++k)
196 {
197 const int nx = (k + 1) % N, sh = (k == N - 1) ? 1 : 0;
198 for (int j = 0; j < 3; ++j)
199 {
200 const int j2 = (j + 1) % 3;
201 *w++ = V(k, j) + 1;
202 *w++ = V(k, j2) + 1;
203 *w++ = V(nx, (j2 + sh) % 3) + 1;
204 *w++ = V(nx, (j + sh) % 3) + 1;
205
206 if (order == 2)
207 {
208 *w++ = TM(k, j) + 1;
209 *w++ = AM(k, j2) + 1;
210 *w++ = TM(nx, (j + sh) % 3) + 1;
211 *w++ = AM(k, j) + 1;
212 }
213 }
214 }
215
216 chk(cg_section_write(fn, B, Z_, "skin", (order == 2) ? QUAD_8 : QUAD_4,
217 N + 1, N + 3 * N, 0, q, &S),
218 "quad");
219 chk(cg_close(fn), "close");
220
221 printf("wrote %s: %d nodes, %d prisms, order %d\n", argv[1], nnode, N,
222 order);
223 (void)nq;
224 return 0;
225}
#define N
static double Z[NNODE]
static double Y[NNODE]
#define V(k, j)
#define AM(k, j)
#define NNODE
static void chk(int ier, const char *w)
static constexpr double kPi
#define TM(k, j)
static double X[NNODE]
static void mid(int m, int a, int b)
#define NV
std::vector< double > p(NPUPPER)

References AM, chk(), kPi, mid(), N, NNODE, NV, TM, V, X, Y, and Z.

◆ mid()

static void mid ( int  m,
int  a,
int  b 
)
static

Definition at line 98 of file MakeTwistedPrismRing.cpp.

99{
100 X[m] = 0.5 * (X[a] + X[b]);
101 Y[m] = 0.5 * (Y[a] + Y[b]);
102 Z[m] = 0.5 * (Z[a] + Z[b]);
103}

References X, Y, and Z.

Referenced by Nektar::LibUtilities::PtsIOHdf5::FindRestartRow(), and main().

Variable Documentation

◆ kPi

constexpr double kPi = 3.14159265358979323846
staticconstexpr

Definition at line 86 of file MakeTwistedPrismRing.cpp.

Referenced by main().

◆ X

double X[NNODE]
static

◆ Y

double Y[NNODE]
static

Definition at line 82 of file MakeTwistedPrismRing.cpp.

Referenced by Polylib::gammaFracGammaF(), main(), and mid().

◆ Z

double Z[NNODE]
static