In this tutorial we show again an application of free form deformation method, now to a CAD file. These files, that are often adopted to model complex geometries, require an additional pre- and post-processing of the surfaces to perform the deformation.
The CAD submodule of PyGeM takes care of the deformation to all CAD files (.step, .iges, etc.), so first of all we import from the submodule the FFD
class.
from pygem.cad import FFD
Since the visualisation of CAD files may be tricky (depending by the operating system, the graphical front-end, ...), we avoid for this tutorial any graphical renderer, letting to the reader the possibility to implement by himself the needed plotting routines.
The FFD
class in the CAD module shares the same interface with the original FFD
class (for discrete geometries). We can simply parse a parameter file to set everything like we want (remember you can do the same directly setting the object attributes).
ffd = FFD()
ffd.read_parameters('../tests/test_datasets/parameters_test_ffd_iges.prm')
print(ffd)
conversion_unit = 1.0 n_control_points = [2 2 2] box_length = [2200. 2200. 5100.] box_origin = [-1100. -1100. 5000.] rot_angle = [0. 0. 0.] array_mu_x = [[[0. 0. ] [0. 0. ]] [[0. 0. ] [0. 0.3]]] array_mu_y = [[[0. 0. ] [0. 0. ]] [[0. 0. ] [0. 0.4]]] array_mu_z = [[[0. 0.5] [0. 0.5]] [[0. 0.2] [0. 0.2]]] rotation_matrix = [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]] position_vertices = [[-1100. -1100. 5000.] [ 1100. -1100. 5000.] [-1100. 1100. 5000.] [-1100. -1100. 10100.]]
Almost already completed! We now specify the input file (the one which contains the shape to deform) and the output file: these are the two input argument to pass to the object in order to perform the deformation.
input_cad_file_name = "../tests/test_datasets/test_pipe.iges"
modified_cad_file_name = "test_pipe_deformed.iges"
ffd(input_cad_file_name, modified_cad_file_name)
The output file is created and the deformed shape is stored into it. We skip any visual check because of the CAD format file, so as final proof we simply show the differences, lines by lines, between the input and the output. Even if we can't be sure about the correctness of the results, in this way we ensure the outcome is different from the original inpuit.
!diff -y ../tests/test_datasets/test_pipe.iges test_pipe_deformed.iges
,,31HOpen CASCADE IGES processor 7.3,13HFilename.iges, | ,,31HOpen CASCADE IGES processor 7.4,13HFilename.iges, 16HOpen CASCADE 7.3,31HOpen CASCADE IGES processor 7.3,32,308 | 16HOpen CASCADE 7.4,31HOpen CASCADE IGES processor 7.4,32,308 ,1.,6,1HM,1,0.01,15H20200505.194413,1E-05,10.,5Hamola,,11,0, | ,1.,2,2HMM,1,0.01,15H20201103.113126,1E-07,12431.818182,5Hnde 15H20200505.194413,; | 15H20201103.113126,; 402 1 0 0 0 0 0 402 1 0 0 0 0 0 402 0 0 1 1 402 0 0 1 1 144 2 0 0 0 0 0 144 2 0 0 0 0 0 144 0 0 1 0 144 0 0 1 0 120 3 0 0 0 0 0 | 128 3 0 0 0 0 0 120 0 0 1 0 | 128 0 0 10 0 110 4 0 0 0 0 0 | 142 13 0 0 0 0 0 110 0 0 1 0 | 142 0 0 1 0 110 5 0 0 0 0 0 | 126 14 0 0 0 0 0 110 0 0 1 0 | 126 0 0 14 0 142 6 0 0 0 0 0 | 144 28 0 0 0 0 0 142 0 0 1 0 | 144 0 0 1 0 102 7 0 0 0 0 0 | 128 29 0 0 0 0 0 102 0 0 1 0 | 128 0 0 10 0 110 8 0 0 0 0 0 | 142 39 0 0 0 0 0 110 0 0 1 0 | 142 0 0 1 0 110 9 0 0 0 0 0 | 126 40 0 0 0 0 0 110 0 0 1 0 | 126 0 0 14 0 110 10 0 0 0 0 0 | 144 54 0 0 0 0 0 110 0 0 1 0 | 144 0 0 1 0 110 11 0 0 0 0 0 | 128 55 0 0 0 0 0 110 0 0 1 0 | 128 0 0 5 0 102 12 0 0 0 0 0 | 142 60 0 0 0 0 0 102 0 0 1 0 | 142 0 0 1 0 100 13 0 0 0 0 27 | 126 61 0 0 0 0 0 100 0 0 1 0 | 126 0 0 12 0 124 14 0 0 0 0 0 | 144 73 0 0 0 0 0 124 0 0 1 0 | 144 0 0 1 0 110 15 0 0 0 0 0 | 128 74 0 0 0 0 0 110 0 0 1 0 | 128 0 0 4 0 100 16 0 0 0 0 0 | 142 78 0 0 0 0 0 100 0 0 1 0 | 142 0 0 1 0 126 17 0 0 0 0 0 | 126 79 0 0 0 0 0 126 0 0 2 0 | 126 0 0 8 0 144 19 0 0 0 0 0 | 402,4,3,11,19,27; 144 0 0 1 0 | 144,5,1,0,7; 120 20 0 0 0 0 0 | 128,4,1,2,1,0,0,0,0,0,0.,0.,0.,1.570796327,1.570796327, 120 0 0 1 0 | 3.141592654,3.141592654,3.141592654,0.,0.,1.E+04,1.E+04,1., 110 21 0 0 0 0 0 | 0.707106781,1.,0.707106781,1.,1.,0.707106781,1.,0.707106781,1 110 0 0 1 0 | 1.E+03,1.795861237E-07,0.,999.99999982,1.E+03,0., 110 22 0 0 0 0 0 | -1.795860127E-07,1.E+03,0.,-1.E+03,999.99999982,0.,-1.E+03, 110 0 0 1 0 | -1.795860013E-07,0.,1.308823529E+03,411.764706129, 142 23 0 0 0 0 0 | 1.106818182E+04,1.589572192E+03,1.786096257E+03,1.106818182E+ 142 0 0 1 0 | 308.823529182,1.411764706E+03,1.175E+04,-971.925133922, 102 24 0 0 0 0 0 | 1.037433155E+03,1.243181818E+04,-985.294117649,19.607842954, 102 0 0 1 0 | 1.243181818E+04,0.,3.141592654,0.,1.E+04; 110 25 0 0 0 0 0 | 142,0,5,0,9,2; 110 0 0 1 0 | 126,12,2,0,1,0,0,-7.965614692,-7.965614692,-7.965614692, 110 26 0 0 0 0 0 | -6.394818365,-6.394818365,-4.824022038,-4.824022038,6.2831853 110 0 0 1 0 | 6.283185307,7.853981634,7.853981634,9.424777961,9.424777961, 110 27 0 0 0 0 0 | 20.531985306,20.531985306,20.531985306,1.,0.707106781,1., 110 0 0 1 0 | 0.707106781,1.,1.,1.,0.707106781,1.,0.707106781,1.,1.,1., 110 28 0 0 0 0 0 | -1.E+03,1.224646799E-13,0.,-1000.,1.E+03,0.,6.123233996E-14, 110 0 0 1 0 | 1.E+03,0.,1.E+03,1000.,0.,1.E+03,0.,0.,1.E+03,-2.449293598E-1 102 29 0 0 0 0 0 | 5.E+03,1.308823529E+03,411.764705882,1.106818182E+04, 102 0 0 1 0 | 1.589572193E+03,1.786096257E+03,1.106818182E+04,308.823529412 100 30 0 0 0 0 0 | 1.411764706E+03,1.175E+04,-971.92513369,1.037433155E+03, 100 0 0 1 0 | 1.243181818E+04,-985.294117647,19.607843137,1.243181818E+04, 110 31 0 0 0 0 0 | -1.E+03,1.224646799E-13,5.E+03,-1.E+03,1.224646799E-13,0., 110 0 0 1 0 | -7.965614692,20.531985306,0.123925629,-0.99103112, 100 32 0 0 0 0 63 | 4.999758142E-02; 100 0 0 1 0 | 144,13,1,0,15; 124 33 0 0 0 0 0 | 128,4,1,2,1,0,0,0,0,0,0.,0.,0.,1.570796327,1.570796327, 124 0 0 1 0 | 3.141592654,3.141592654,3.141592654,0.,0.,1.E+04,1.E+04,1., 126 34 0 0 0 0 0 | 0.707106781,1.,0.707106781,1.,1.,0.707106781,1.,0.707106781,1 126 0 0 2 0 | -1.E+03,4.10207102E-07,0.,-1.E+03,-999.999999795,0., 144 36 0 0 0 0 0 | -2.051053886E-07,-1.E+03,0.,1000.,-1.E+03,0.,1.E+03, 144 0 0 1 0 | -3.797643039E-12,0.,-985.294117642,19.607843555,1.243181818E+ 108 37 0 0 0 0 0 | -998.663102017,-998.217468604,1.243181818E+04,14.705882145, 108 0 0 1 0 | -980.392156866,1.175E+04,1.028074866E+03,-962.566845202, 142 38 0 0 0 0 0 | 1.106818182E+04,1.308823529E+03,411.764705882,1.106818182E+04 142 0 0 1 0 | 0.,3.141592654,0.,1.E+04; 102 39 0 0 0 0 0 | 142,0,13,0,17,2; 102 0 0 1 0 | 126,12,2,0,1,0,0,-7.965614692,-7.965614692,-7.965614692, 100 40 0 0 0 0 77 | -6.394818365,-6.394818365,-4.824022038,-4.824022038,6.2831853 100 0 0 1 0 | 6.283185307,7.853981634,7.853981634,9.424777961,9.424777961, 124 41 0 0 0 0 0 | 20.531985306,20.531985306,20.531985306,1.,0.707106781,1., 124 0 0 1 0 | 0.707106781,1.,1.,1.,0.707106781,1.,0.707106781,1.,1.,1., 100 42 0 0 0 0 81 | -985.294117647,19.607843137,1.243181818E+04,-998.663101604, 100 0 0 1 0 | -998.217468806,1.243181818E+04,14.705882353,-980.392156863, 124 43 0 0 0 0 0 | 1.175E+04,1.028074866E+03,-962.56684492,1.106818182E+04, 124 0 0 1 0 | 1.308823529E+03,411.764705882,1.106818182E+04,1.E+03, 144 44 0 0 0 0 0 | -2.449293598E-13,5.E+03,1.E+03,-2.449293598E-13,0.,1000., 144 0 0 1 0 | -1.E+03,0.,-1.836970199E-13,-1.E+03,0.,-1.E+03,-1000.,0., 108 45 0 0 0 0 0 | -1.E+03,1.224646799E-13,0.,-1.E+03,1.224646799E-13,5.E+03, 108 0 0 1 0 | -985.294117647,19.607843137,1.243181818E+04,-7.965614692, 142 46 0 0 0 0 0 | 20.531985306,6.574038599E-03,0.999966055,4.967051386E-03; 142 0 0 1 0 | 144,21,1,0,23; 102 47 0 0 0 0 0 | 128,1,1,1,1,0,0,1,0,0,-1.E+03,-1.E+03,1.E+03,1.E+03,-1.E+03, 102 0 0 1 0 | -1.E+03,1.E+03,1.E+03,1.,1.,1.,1.,-998.663101604,-998.2174688 100 48 0 0 0 0 93 | 1.243181818E+04,1.028074866E+03,-962.56684492,1.106818182E+04 100 0 0 1 0 | -971.92513369,1.037433155E+03,1.243181818E+04,1.589572193E+03 124 49 0 0 0 0 0 | 1.786096257E+03,1.106818182E+04,-1.E+03,1.E+03,-1.E+03,1.E+03 124 0 0 1 0 | 142,0,21,0,25,2; 100 50 0 0 0 0 97 | 126,8,2,0,1,0,0,-3.141592654,-3.141592654,-3.141592654, 100 0 0 1 0 | -1.570796327,-1.570796327,-8.881784197E-16,-8.881784197E-16, 124 51 0 0 0 0 0 | 1.570796327,1.570796327,3.141592654,3.141592654,3.141592654,1 124 0 0 1 0 | 0.707106781,1.,0.707106781,1.,0.707106781,1.,0.707106781,1., 402,4,3,35,67,83; | -985.294117647,19.607843137,1.243181818E+04,-971.92513369, 144,5,1,0,11; | 1.037433155E+03,1.243181818E+04,308.823529412,1.411764706E+03 120,7,9,3.141592654,6.283185307; | 1.175E+04,1.589572193E+03,1.786096257E+03,1.106818182E+04, 110,0.,0.,1.,0.,0.,0.; | 1.308823529E+03,411.764705882,1.106818182E+04,1.028074866E+03 110,1.,0.,0.,1.,0.,10.; | -962.56684492,1.106818182E+04,14.705882353,-980.392156863, 142,0,5,13,23,3; | 1.175E+04,-998.663101604,-998.217468806,1.243181818E+04, 102,4,15,17,19,21; | -985.294117647,19.607843137,1.243181818E+04,-3.141592654, 110,1.,3.141592654,0.,1.,6.283185307,0.; | 3.141592654,0.517939535,-6.36810904E-02,0.853043584; 110,1.,6.283185307,0.,0.,6.283185307,0.; | 144,29,1,0,31; 110,0.,6.283185307,0.,-6.975736996E-17,3.141592654,0.; | 128,1,1,1,1,0,0,1,0,0,-1.E+03,-1.E+03,1.E+03,1.E+03,-1.E+03, 110,-6.975736996E-17,3.141592654,0.,1.,3.141592654,0.; | -1.E+03,1.E+03,1.E+03,1.,1.,1.,1.,1.E+03,-1.E+03,0.,-1.E+03, 102,4,25,29,31,33; | -1.E+03,0.,1.E+03,1.E+03,0.,-1.E+03,1.E+03,0.,-1.E+03,1.E+03, 100,0.,0.,0.,-1.,1.224646799E-16,1.,-2.449293598E-16; | -1.E+03,1.E+03; 124,1.,0.,0.,0.,0.,-1.,0.,0.,0.,0.,-1.,10.; | 142,0,29,0,33,2; 110,1.,-2.449293598E-16,10.,1.,-2.449293598E-16,0.; | 126,8,2,1,1,0,0,4.440892099E-16,4.440892099E-16,4.440892099E- 100,0.,0.,0.,1.,0.,-1.,1.224646799E-16; | 1.570796327,1.570796327,3.141592654,3.141592654,4.71238898, 126,1,1,1,0,1,0,0.,0.,10.,10.,1.,1.,-1.,1.224646799E-16,0.,-1 | 4.71238898,6.283185307,6.283185307,6.283185307,1.,0.707106781 1.224646799E-16,10.,0.,10.,-1.,0.,-0.; | 1.,0.707106781,1.,0.707106781,1.,0.707106781,1.,1.E+03, 144,37,1,0,43; | 2.449293598E-13,0.,1000.,1.E+03,0.,-1.836970199E-13,1.E+03,0. 120,39,41,0.,3.141592654; | -1.E+03,1000.,0.,-1.E+03,-1.224646799E-13,0.,-1000.,-1.E+03,0 110,0.,0.,1.,0.,0.,0.; | 6.123233996E-14,-1.E+03,0.,1.E+03,-1000.,0.,1.E+03,0.,0., 110,1.,0.,0.,1.,0.,10.; | 4.440892099E-16,6.283185307,0.,0.,1.; 142,0,37,45,55,3; | S 1G 4D 34P 86 102,4,47,49,51,53; < 110,-6.975736996E-17,3.141592654,0.,-1.395147399E-16,0.,0.; < 110,-1.395147399E-16,1.776356839E-15,0.,1.,3.996802889E-15,0. < 110,1.,1.776356839E-15,0.,1.,3.141592654,0.; < 110,1.,3.141592654,0.,-6.975736996E-17,3.141592654,0.; < 102,4,57,59,61,65; < 100,0.,0.,0.,-1.,1.224646799E-16,1.,-2.449293598E-16; < 110,1.,-2.449293598E-16,0.,1.,-2.449293598E-16,10.; < 100,0.,0.,0.,1.,0.,-1.,1.224646799E-16; < 124,1.,0.,0.,0.,0.,-1.,0.,0.,0.,0.,-1.,10.; < 126,1,1,1,0,1,0,0.,0.,10.,10.,1.,1.,-1.,1.224646799E-16,10.,- < 1.224646799E-16,0.,0.,10.,1.,0.,-0.; < 144,69,1,0,71; < 108,0.,0.,1.,10.,0,0.,0.,10.,0.; < 142,0,69,0,73,2; < 102,2,75,79; < 100,0.,0.,0.,1.,0.,-1.,1.224646799E-16; < 124,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.,10.; < 100,0.,0.,0.,-1.,1.224646799E-16,1.,-2.449293598E-16; < 124,1.,0.,0.,0.,0.,1.,0.,0.,0.,0.,1.,10.; < 144,85,1,0,87; < 108,-0.,-0.,-1.,-0.,0,0.,0.,0.,0.; < 142,0,85,0,89,2; < 102,2,91,95; < 100,0.,0.,0.,-1.,1.224646799E-16,1.,-2.449293598E-16; < 124,1.,0.,0.,0.,0.,-1.,0.,0.,0.,0.,-1.,0.; < 100,0.,0.,0.,1.,0.,-1.,1.224646799E-16; < 124,1.,0.,0.,0.,0.,-1.,0.,0.,0.,0.,-1.,0.; < S 1G 4D 98P 51 <