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])
54 print(
"Translating %s to %s with dX: %g dY: %g dZ: %g ...." % (inputFileName, outputFileName, dX, dY, dZ))
56 ffd = pyBlock(
"plot3d", fileName=inputFileName, FFD=
True)
58 for ivol
in range(ffd.nVol):
59 vals = ffd.vols[ivol].coef
60 vals[:, :, :, 0] = vals[:, :, :, 0] + dX
61 vals[:, :, :, 1] = vals[:, :, :, 1] + dY
62 vals[:, :, :, 2] = vals[:, :, :, 2] + dZ
63 ffd.writePlot3dCoef(outputFileName)
65 print(
"Translating %s to %s with dX: %g dT: %g dZ: %g Done!" % (inputFileName, outputFileName, dX, dY, dZ))
66 elif mode ==
"rotate":
67 axis = str(sys.argv[4])
68 deg = float(sys.argv[5])
70 print(
"Rotating %s to %s wrt to the %s axis by %g degree...." % (inputFileName, outputFileName, axis, deg))
72 ffd = pyBlock(
"plot3d", fileName=inputFileName, FFD=
True)
74 theta = deg * np.pi / 180.0
76 for ivol
in range(ffd.nVol):
77 vals = ffd.vols[ivol].coef
78 for i
in range(vals.shape[0]):
79 for j
in range(vals.shape[1]):
80 for k
in range(vals.shape[2]):
82 yRef = vals[i, j, k, 1]
83 zRef = vals[i, j, k, 2]
84 vals[i, j, k, 1] = np.cos(theta) * yRef - np.sin(theta) * zRef
85 vals[i, j, k, 2] = np.sin(theta) * yRef + np.cos(theta) * zRef
87 xRef = vals[i, j, k, 0]
88 zRef = vals[i, j, k, 2]
89 vals[i, j, k, 0] = np.cos(theta) * xRef + np.sin(theta) * zRef
90 vals[i, j, k, 2] = -np.sin(theta) * xRef + np.cos(theta) * zRef
92 xRef = vals[i, j, k, 0]
93 yRef = vals[i, j, k, 1]
94 vals[i, j, k, 0] = np.cos(theta) * xRef - np.sin(theta) * yRef
95 vals[i, j, k, 1] = np.sin(theta) * xRef + np.cos(theta) * yRef
97 print(
"Axis %s not supported! Options are: x, y, or z" % s)
99 ffd.writePlot3dCoef(outputFileName)
101 print(
"Rotating %s to %s wrt to the %s axis by %g degree Done!" % (inputFileName, outputFileName, axis, deg))
103 print(
"Mode %s not supported! Options are: scale, translate, or rotate" % s)