DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
draw_meshes_2D.py
Go to the documentation of this file.
1from DNDSR import DNDS, Geom
2import os
3import matplotlib.pyplot as plt
4import matplotlib.patches as patches
5import numpy as np
6
7
9 mpi = DNDS.MPIInfo()
10 mpi.setWorld()
11
12 mesh = Geom.UnstructuredMesh(mpi, 2)
13 meshReader = Geom.UnstructuredMeshSerialRW(mesh, 0)
14 name2ID = meshReader.ReadFromCGNSSerial(
15 os.path.join(
16 os.path.dirname(__file__), "..", "..", "data", "mesh", "NACA0012_H2.cgns"
17 )
18 )
19 print(name2ID.n2id_map)
20 meshReader.Deduplicate1to1Periodic(1e-9)
21 meshReader.BuildCell2Cell()
22 meshReader.MeshPartitionCell2Cell({"metisUfactor": 5})
23 meshReader.PartitionReorderToMeshCell2Cell()
24
25 mesh.RecoverNode2CellAndNode2Bnd()
26 mesh.RecoverCell2CellAndBnd2Cell()
27 mesh.BuildGhostPrimary()
28 mesh.AdjGlobal2LocalPrimary()
29 mesh.InterpolateFace()
30 mesh.AssertOnFaces()
31
32 fig, ax = plt.subplots(figsize=(16, 16), dpi=320)
33 xymaxs = np.array([-1e100, -1e100], dtype=np.double)
34 xymins = np.array([1e100, 1e100], dtype=np.double)
35 for iCell in range(mesh.cell2node.Size()):
36 c2n = mesh.cell2node[iCell].tolist()
37 nodes = []
38 # print(mesh.cell2node[iCell].tolist())
39
40 for iNode in c2n:
41 nodes.append(np.array(mesh.coords[iNode]))
42 nodes = np.array(nodes)
43
44 vertices = nodes[:, 0:2]
45 xymaxs = np.maximum(vertices.max(axis=0), xymaxs)
46 xymins = np.minimum(vertices.min(axis=0), xymins)
47 # print(vertices.max(axis=0))
48 polygon = patches.Polygon(
49 vertices,
50 closed=True,
51 edgecolor="black",
52 facecolor="blue" if iCell < mesh.cell2node.father.Size() else "red",
53 lw=1,
54 )
55 ax.add_patch(polygon)
56
57 # Maintain aspect ratio
58 ax.set_aspect("equal")
59 ax.set_xlim(xymins[0], xymaxs[0])
60 ax.set_ylim(xymins[1], xymaxs[1])
61 ax.set_title(f"part_{mpi.rank}")
62
63 # Show the plot
64 # plt.show(block=False)
65 plt.figure(fig)
66 plt.savefig(f"test_print_part_{mpi.rank}.png")
67
68
69if __name__ == "__main__":
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
Definition MPI.hpp:215