Nektar++
Loading...
Searching...
No Matches
MakePeriodicConnMesh.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: MakePeriodicConnMesh.cpp
4//
5// For more information, please see: http://www.nektar.info/
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Generates periodic_conn.cgns from
32// linear_tet_prism_pyra_mesh.cgns.
33//
34////////////////////////////////////////////////////////////////////////////////
35// Adds a pair of periodic GridConnectivity_t nodes, which is how a mesher
36// states that two surfaces are periodic images of each other and which none of
37// the other test meshes here contains. The faces are addressed at FaceCenter,
38// i.e. by element number, as exporters write them, and it is reading them as
39// anything else that this fixture is here to catch.
40//
41// The two sides are the outlet patch of the source mesh and an equal number of
42// faces taken from its inlet. They are not true periodic images of one another
43// and nothing here claims they are; CGNS requires only that an Abutting1to1
44// pair name the same number of faces on each side. Taking fewer faces than the
45// inlet holds is deliberate, so that the inlet keeps a remainder of its own:
46// the three counts that result can only come out right if the declared sets
47// were read as the elements they name.
48//
49// Built by utilities/NekMesh/CMakeLists.txt wherever CGNS is enabled, which
50// also adds a test that reruns this and checks the result against the
51// fixture committed beside it. To build it by hand instead:
52//
53// c++ MakePeriodicConnMesh.cpp -I<cgns>/include -L<cgns>/lib -lcgns \
54// -o MakePeriodicConnMesh
55// cp linear_tet_prism_pyra_mesh.cgns periodic_conn.cgns
56// ./MakePeriodicConnMesh periodic_conn.cgns
57//
58#include <cgnslib.h>
59#include <cstdio>
60#include <cstdlib>
61#include <cstring>
62#include <vector>
63
64static void chk(int ier, const char *what)
65{
66 if (ier)
67 {
68 printf("FAILED: %s\n", what);
69 cg_error_print();
70 exit(1);
71 }
72}
73
74int main(int, char **argv)
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)
Definition main.py:1