DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
test_basic_geom.py
Go to the documentation of this file.
1# import DNDS
2# import Geom
3
4
5from DNDSR import DNDS as DNDS
6from DNDSR import Geom as Geom
7from DNDSR.Geom.utils import create_mesh_from_CGNS, create_bnd_mesh
8import os
9import matplotlib.pyplot as plt
10import matplotlib.patches as patches
11import numpy as np
12
13print(DNDS.__file__)
14
15
17 mpi = DNDS.MPIInfo()
18 mpi.setWorld()
19
20 # mesh, reader, name2Id = create_mesh_from_CGNS(
21 # os.path.join(
22 # os.path.dirname(__file__), "..", "..", "data", "mesh", "NACA0012_H2.cgns"
23 # ),
24 # mpi,
25 # 2,
26 # )
27
28 mesh, reader, name2Id = create_mesh_from_CGNS(
29 os.path.join(
30 os.path.dirname(__file__),
31 "..",
32 "..",
33 "data",
34 "mesh",
35 "Uniform32_Periodic.cgns",
36 ),
37 mpi,
38 2,
39 inner_process_parts=4,
40 second_level_parts=4,
41 )
42
43 # mesh, reader, name2Id = create_mesh_from_CGNS(
44 # os.path.join(
45 # os.path.dirname(__file__), "..", "..", "data", "mesh", "UP3D_128.cgns"
46 # ),
47 # mpi,
48 # 3,
49 # )
50
51 n2idmap = name2Id.n2id_map
52 id2nmap = {k: v for v, k in n2idmap.items()}
53
54 def name_is_wall(name: str):
55 name = name.capitalize()
56 if "WALL" in name:
57 return True
58 if "bc-4".capitalize() in name:
59 return True
60
61 def id_is_wall(id: int):
62 # print(id2nmap[id])
63 if id in id2nmap and name_is_wall(id2nmap[id]):
64 return True
65 return False
66
67 wallDistOptions = Geom.UnstructuredMesh.WallDistOptions()
68 wallDistOptions.method = 1
69 wallDistOptions.subdivide_quad = 5
70 wallDistOptions.verbose = 10
71 wallDistOptions.wallDistExecution = 4
72 mesh.BuildNodeWallDist(id_is_wall, wallDistOptions)
73
74 meshBnd, readerBnd = create_bnd_mesh(mesh)
75
76 mesh_bytes = mesh.getArrayBytes()
77 mesh_nCell = mesh.NumCellGlobal()
78
79 if mpi.rank == 0:
80 print(f"mesh num cell: {mesh_nCell}")
81 print(f"mesh size total: {mesh_bytes / (1024 * 1024):.4g} MB")
82
83 mesh.coords.to_device("CUDA")
84 mesh.to_device("CUDA")
85 # while True:
86 # pass
87
88 # fig, ax = plt.subplots(figsize=(16, 16), dpi=320)
89 # xymaxs = np.array([-1e100, -1e100], dtype=np.double)
90 # xymins = np.array([1e100, 1e100], dtype=np.double)
91 # for iCell in range(mesh.cell2node.Size()):
92 # c2n = mesh.cell2node[iCell].tolist()
93 # nodes = []
94 # # print(mesh.cell2node[iCell].tolist())
95
96 # for iNode in c2n:
97 # nodes.append(np.array(mesh.coords[iNode]))
98 # nodes = np.array(nodes)
99
100 # vertices = nodes[:, 0:2]
101 # xymaxs = np.maximum(vertices.max(axis=0), xymaxs)
102 # xymins = np.minimum(vertices.min(axis=0), xymins)
103 # # print(vertices.max(axis=0))
104 # polygon = patches.Polygon(
105 # vertices,
106 # closed=True,
107 # edgecolor="black",
108 # facecolor="blue" if iCell < mesh.cell2node.father.Size() else "red",
109 # lw=1,
110 # )
111 # ax.add_patch(polygon)
112
113 # # Maintain aspect ratio
114 # ax.set_aspect("equal")
115 # ax.set_xlim(xymins[0], xymaxs[0])
116 # ax.set_ylim(xymins[1], xymaxs[1])
117 # ax.set_title(f"part_{mpi.rank}")
118
119 # # Show the plot
120 # # plt.show(block=False)
121 # plt.figure(fig)
122 # plt.savefig(f"test_print_part_{mpi.rank}.png")
123
124
125if __name__ == "__main__":
126 test_mesh0()
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
Definition MPI.hpp:215