Nektar++
Loading...
Searching...
No Matches
Functions
MakeTwoImpossiblePyramids.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 argc, char **argv)
 

Function Documentation

◆ chk()

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

Definition at line 62 of file MakeTwoImpossiblePyramids.cpp.

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

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 72 of file MakeTwoImpossiblePyramids.cpp.

73{
74 if (argc != 3)
75 {
76 printf("usage: %s <in.cgns> <out.cgns>\n", argv[0]);
77 return 1;
78 }
79
80 int in;
81 chk(cg_open(argv[1], CG_MODE_READ, &in), "open in");
82
83 char zname[33];
84 cgsize_t size[9];
85 chk(cg_zone_read(in, 1, 1, zname, size), "zone_read");
86
87 const cgsize_t nnode = size[0], ncell = size[1];
88
89 int ncoords;
90 chk(cg_ncoords(in, 1, 1, &ncoords), "ncoords");
91
92 std::vector<double> x[3];
93 char cname[3][33];
94 for (int C = 1; C <= ncoords; ++C)
95 {
96 DataType_t dt;
97 chk(cg_coord_info(in, 1, 1, C, &dt, cname[C - 1]), "coord_info");
98 x[C - 1].resize(nnode * 2);
99 cgsize_t one = 1;
100 chk(cg_coord_read(in, 1, 1, cname[C - 1], RealDouble, &one, &nnode,
101 x[C - 1].data()),
102 "coord_read");
103 }
104
105 /* The second copy is shifted clear of the first along x. */
106 double xmin = x[0][0], xmax = x[0][0];
107 for (cgsize_t i = 1; i < nnode; ++i)
108 {
109 xmin = x[0][i] < xmin ? x[0][i] : xmin;
110 xmax = x[0][i] > xmax ? x[0][i] : xmax;
111 }
112 const double shift = 2.0 * (xmax - xmin) + 1.0;
113
114 for (int c = 0; c < ncoords; ++c)
115 {
116 for (cgsize_t i = 0; i < nnode; ++i)
117 {
118 x[c][nnode + i] = x[c][i] + (c == 0 ? shift : 0.0);
119 }
120 }
121
122 int out, B, Z, C, S;
123 chk(cg_open(argv[2], CG_MODE_WRITE, &out), "open out");
124 chk(cg_base_write(out, "Base", 3, 3, &B), "base_write");
125
126 cgsize_t osize[3] = {nnode * 2, ncell * 2, 0};
127 chk(cg_zone_write(out, B, zname, osize, Unstructured, &Z), "zone_write");
128
129 for (int c = 0; c < ncoords; ++c)
130 {
131 chk(cg_coord_write(out, B, Z, RealDouble, cname[c], x[c].data(), &C),
132 "coord_write");
133 }
134
135 int nsections;
136 chk(cg_nsections(in, 1, 1, &nsections), "nsections");
137
138 cgsize_t next = 1;
139 for (int Sin = 1; Sin <= nsections; ++Sin)
140 {
141 char sname[33];
142 ElementType_t type;
143 cgsize_t start, end;
144 int nbndry, parent;
145 chk(cg_section_read(in, 1, 1, Sin, sname, &type, &start, &end, &nbndry,
146 &parent),
147 "section_read");
148
149 cgsize_t ndata;
150 chk(cg_ElementDataSize(in, 1, 1, Sin, &ndata), "ElementDataSize");
151
152 const cgsize_t nelem = end - start + 1;
153 std::vector<cgsize_t> conn(ndata * 2);
154
155 if (type == MIXED)
156 {
157 /* A MIXED section is read with an offset per element, since its
158 elements are not all the same size. */
159 std::vector<cgsize_t> off(nelem * 2 + 1);
160 cgsize_t pd;
161 chk(cg_poly_elements_read(in, 1, 1, Sin, conn.data(), off.data(),
162 &pd),
163 "poly_elements_read");
164
165 cgsize_t i = 0, j = ndata;
166 while (i < ndata)
167 {
168 int npe;
169 chk(cg_npe((ElementType_t)conn[i], &npe), "npe");
170 conn[j++] = conn[i++];
171 for (int k = 0; k < npe; ++k)
172 {
173 conn[j++] = conn[i++] + nnode;
174 }
175 }
176
177 for (cgsize_t e = 1; e <= nelem; ++e)
178 {
179 off[nelem + e] = off[nelem] + off[e];
180 }
181
182 chk(cg_poly_section_write(out, B, Z, sname, type, next,
183 next + nelem * 2 - 1, nbndry, conn.data(),
184 off.data(), &S),
185 "poly_section_write");
186 }
187 else
188 {
189 cgsize_t pd;
190 chk(cg_elements_read(in, 1, 1, Sin, conn.data(), &pd),
191 "elements_read");
192
193 for (cgsize_t i = 0; i < ndata; ++i)
194 {
195 conn[ndata + i] = conn[i] + nnode;
196 }
197
198 chk(cg_section_write(out, B, Z, sname, type, next,
199 next + nelem * 2 - 1, nbndry, conn.data(), &S),
200 "section_write");
201 }
202
203 next += nelem * 2;
204 }
205
206 chk(cg_close(in), "close in");
207 chk(cg_close(out), "close out");
208 printf("wrote %s: %lld nodes, %lld cells\n", argv[2],
209 (long long)(nnode * 2), (long long)(ncell * 2));
210 return 0;
211}
static double Z[NNODE]
static void chk(int ier, const char *what)
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT in
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT out

References chk(), and Z.