3 This script transforms the coordinates in a plot3D file. We support three modes: scale, translate, or rotate
7 python dafoam_plot3dscale.py scale plot3d_file_input.xyz plot3d_file_output.xyz 2 2 2
8 This will scale the x, y, and z coordinates by a factor of 2
10 python dafoam_plot3dscale.py translate plot3d_file_input.xyz plot3d_file_output.xyz 1 2 3
11 This will translate the x, y, and z coordinates by 1, 2, and 3
13 python dafoam_plot3dscale.py rotate plot3d_file_input.xyz plot3d_file_output.xyz x 10
14 This will rotate the x, y, and z coordinates with respect to the x axis by 10 degree
23 inputFileName = sys.argv[2]
24 outputFileName = sys.argv[3]
27 scaleX = float(sys.argv[4])
28 scaleY = float(sys.argv[5])
29 scaleZ = float(sys.argv[6])
32 "Scaling %s to %s with scaleX: %g scaleY: %g scaleZ: %g ...."
33 % (inputFileName, outputFileName, scaleX, scaleY, scaleZ)
36 ffd = pyBlock(
"plot3d", fileName=inputFileName, FFD=
True)
38 for ivol
in range(ffd.nVol):
39 vals = ffd.vols[ivol].coef
40 vals[:, :, :, 0] = vals[:, :, :, 0] * scaleX
41 vals[:, :, :, 1] = vals[:, :, :, 1] * scaleY
42 vals[:, :, :, 2] = vals[:, :, :, 2] * scaleZ
43 ffd.writePlot3dCoef(outputFileName)
46 "Scaling %s to %s with scaleX: %g scaleY: %g scaleZ: %g Done!"
47 % (inputFileName, outputFileName, scaleX, scaleY, scaleZ)
49 elif mode ==
"translate":
50 dX = float(sys.argv[4])
51 dY = float(sys.argv[5])
52 dZ = float(sys.argv[6])
55 "Translating %s to %s with dX: %g dY: %g dZ: %g ...."
56 % (inputFileName, outputFileName, dX, dY, dZ)
59 ffd = pyBlock(
"plot3d", fileName=inputFileName, FFD=
True)
61 for ivol
in range(ffd.nVol):
62 vals = ffd.vols[ivol].coef
63 vals[:, :, :, 0] = vals[:, :, :, 0] + dX
64 vals[:, :, :, 1] = vals[:, :, :, 1] + dY
65 vals[:, :, :, 2] = vals[:, :, :, 2] + dZ
66 ffd.writePlot3dCoef(outputFileName)
69 "Translating %s to %s with dX: %g dT: %g dZ: %g Done!"
70 % (inputFileName, outputFileName, dX, dY, dZ)
72 elif mode ==
"rotate":
73 axis = str(sys.argv[4])
74 deg = float(sys.argv[5])
77 "Rotating %s to %s wrt to the %s axis by %g degree...."
78 % (inputFileName, outputFileName, axis, deg)
81 ffd = pyBlock(
"plot3d", fileName=inputFileName, FFD=
True)
83 theta = deg * np.pi / 180.0
85 for ivol
in range(ffd.nVol):
86 vals = ffd.vols[ivol].coef
87 for i
in range(vals.shape[0]):
88 for j
in range(vals.shape[1]):
89 for k
in range(vals.shape[2]):
91 yRef = vals[i, j, k, 1]
92 zRef = vals[i, j, k, 2]
93 vals[i, j, k, 1] = np.cos(theta) * yRef - np.sin(theta) * zRef
94 vals[i, j, k, 2] = np.sin(theta) * yRef + np.cos(theta) * zRef
96 xRef = vals[i, j, k, 0]
97 zRef = vals[i, j, k, 2]
98 vals[i, j, k, 0] = np.cos(theta) * xRef + np.sin(theta) * zRef
99 vals[i, j, k, 2] = -np.sin(theta) * xRef + np.cos(theta) * zRef
101 xRef = vals[i, j, k, 0]
102 yRef = vals[i, j, k, 1]
103 vals[i, j, k, 0] = np.cos(theta) * xRef - np.sin(theta) * yRef
104 vals[i, j, k, 1] = np.sin(theta) * xRef + np.cos(theta) * yRef
106 print(
"Axis %s not supported! Options are: x, y, or z"%s)
108 ffd.writePlot3dCoef(outputFileName)
111 "Rotating %s to %s wrt to the %s axis by %g degree Done!"
112 % (inputFileName, outputFileName, axis, deg)
115 print(
"Mode %s not supported! Options are: scale, translate, or rotate"%s)