Télécharger top_mma_infill.dgibi

Retour à la liste

Numérotation des lignes :

  1. ************************************************************************
  2. * Example of topological optimization *
  3. * Density method + penalization (SIMP) *
  4. * *
  5. * This test case is based on the following article and reproduces *
  6. * the case in fig. 5 : *
  7. * Wu, Aage, Westermann, Sigmund (2018) *
  8. * "Infill Optimization for Additive Manufacturing - Approaching *
  9. * Bone-like Porous Structures" *
  10. * IEEE Transactions on Visualization and Computer Graphics, *
  11. * vol. 24, no. 2, pp. 1127-1140 *
  12. * https://doi.org/10.1109/TVCG.2017.2655523 *
  13. * *
  14. * Application to a beam under bending in 2D plane stresses *
  15. * with an additional infill constraint *
  16. * *
  17. * Optimization algorithm: Method of Moving Asymptotes *
  18. * *
  19. * Problem: minimize the compliance with: *
  20. * a constraint on the global volume fraction *
  21. * a constraint on the local volume fraction *
  22. * *
  23. * min C(x) = u^T.F *
  24. * s.t. G1(x) = vf(x)/volfrac - 1 < 0 *
  25. * G2(x) = p-norm(vf)/alpha - 1 < 0 *
  26. * *
  27. * /+----------------------------------------------+ *
  28. * /| | *
  29. * /| | *
  30. * /| | *
  31. * /| | *
  32. * /| p2 + | *
  33. * /| | | *
  34. * /| | | *
  35. * /| | v Force *
  36. * /| | *
  37. * /+----------------------------------------------+ *
  38. * *
  39. ************************************************************************
  40.  
  41.  
  42. ** Filtering procedure
  43. DEBP HFILT cham1*'MCHAML' mo*'MMODEL' mf*'RIGIDITE' mpt*'MAILLAGE' ;
  44. chp1 = MANU 'CHPO' mpt 'SCAL' (EXTR cham1 'VALE' 'SCAL') ;
  45. chp2 = mf * chp1 ;
  46. cham2 = MANU 'CHML' mo 'REPA' 'SCAL' (EXTR chp2 'VALE' mpt) 'TYPE' 'SCALAIRE' 'GRAVITE' ;
  47. FINP cham2 ;
  48.  
  49. ** Global parameters
  50. itrac = FAUX ;
  51. pal1 = PALE 'GRIS' ;
  52. OPTI 'DIME' 2 'MODE' 'PLAN' 'CONT' 'ELEM' 'QUA4' 'PALE' pal1 'ECHO' 0 ;
  53.  
  54. ** Geometrical parameters (width and height) / choose 400 and 200 to match the case in the article
  55. l = 120. ;
  56. h = 60. ;
  57. e = 1. ;
  58.  
  59. ** Mesh parameters / choose 400 and 200 to match the case in the article
  60. nelx = 120 ;
  61. nely = 60 ;
  62.  
  63. ** Material parameters (isotropic elasticity)
  64. e0 = 1. ;
  65. emin = e0 / 1.E9 ;
  66. nu = 0.3 ;
  67.  
  68. ** Topology optimization parameters
  69. * penal : SIMP penalization coefficient
  70. * volfrac : minimal volume fraction
  71. * ft : = 1 apply filter on the compliance sensitivity field
  72. * = 2 apply spatial filter on the density field
  73. * = 3 apply spatial filter on the density field + thresholding by heaviside function
  74. * rmin : filter radius (in m)
  75. * beta : initial value of the slope of the heaviside function (only for ft = 3)
  76. * will be doubled every 50 iterations
  77. * move : limit of the maximal increment of density
  78. * changmax : optimization stop criterion
  79. * xmin/xmax : min and max density bounds
  80. * rinfill : radius of the local volume fraction constraint
  81. * ainfill : upper bound for the local volume fraction
  82. * pinfill : aggregation coefficient of the local volume fraction constrainsts
  83. penal = 3. ;
  84. volfrac = 0.5 ;
  85. ft = 2 ;
  86. rmin = 1.5 * l / nelx ;
  87. beta = 1 ;
  88. move = 0.2 ;
  89. changmax = 0.01 ;
  90. xmin = 0. ;
  91. xmax = 1. ;
  92. rinfill = 6. * l / nelx ;
  93. ainfill = 0.6 ;
  94. pinfill = 16. ;
  95.  
  96. ** Mesh
  97. p0 = 0. 0. ;
  98. p1 = 0. h ;
  99. ll = DROI nely p0 p1 ;
  100. mesh = ll TRAN nelx (l 0.) ;
  101. con = CONT mesh ;
  102. p2 = con POIN 'PROC' (l (h / 2.)) ;
  103.  
  104. ** Mechanical model
  105. mod = MODE mesh 'MECANIQUE' ;
  106.  
  107. ** Material properties field with a unit Young modulus
  108. maun = MATE mod 'YOUN' 1. 'NU' nu ;
  109.  
  110. ** Boundary conditions
  111. blo = BLOQ 'UX' 'UY' ll ;
  112.  
  113. ** Load (local force)
  114. f = FORC (0. -1.) p2 ;
  115.  
  116. ** Volume of each element (ve) and total volume (vtot)
  117. un = MANU 'CHML' mod 'SCAL' 1. 'GRAVITE' ;
  118. ve = INTG 'ELEM' mod un maun ;
  119. vtot = INTG mod un maun ;
  120.  
  121. ** Initial density field
  122. xini = volfrac ;
  123. x = MANU 'CHML' mod 'SCAL' xini 'GRAVITE' ;
  124. change = 1. ;
  125.  
  126. ** Physical density field
  127. SI ((ft EGA 1) OU (ft EGA 2)) ;
  128. xphys = x ;
  129. FINSI ;
  130. SI (ft EGA 3) ;
  131. xtilde = x ;
  132. xphys = 1. - (EXP (-1. * beta * xtilde)) + (xtilde * (EXP (-1. * beta))) ;
  133. FINSI ;
  134.  
  135. ** Initial volume fraction
  136. vfx = (INTG mod xphys maun) / vtot ;
  137.  
  138. ** Gravity centers and filtering matrix
  139. * the weight depends on the volume of each element
  140. ptg = un POIN 'SUPERIEUR' 0. ;
  141. wg = MANU 'CHPO' ptg 'SCAL' (EXTR ve 'VALE' 'SCAL') ;
  142. kfil = MFIL wg rmin 1. 0. ;
  143. ung = MANU 'CHPO' ptg 1 'SCAL' 1. ;
  144. ks = kfil * ung ;
  145. kfil = NFIL kfil ks ;
  146.  
  147. ** Filtering matrix for the infill constraint
  148. kin = MFIL wg rinfill 0. 0. ;
  149. ks = kin * ung ;
  150. kin = NFIL kin ks ;
  151.  
  152. ** Initialization of the table for the MMA
  153. nx = NBEL mesh ;
  154. tmma = TABL ;
  155. * initial values of the design variables x
  156. lx = EXTR x 'VALE' 'SCAL' ;
  157. tmma . 'X' = lx ;
  158. * bounds for x
  159. tmma . 'XMIN' = xmin ;
  160. tmma . 'XMAX' = xmax ;
  161. * other parameters
  162. tmma . 'MOVE' = move ;
  163.  
  164. ** Lets's start a timer
  165.  
  166. ** Topology optimization loop
  167. liso = PROG 0. 'PAS' 0.05 1. ;
  168. loopbeta = 0 ;
  169. liter = PROG ;
  170. lobj = PROG ;
  171. lvf = PROG ;
  172. lchange = PROG ;
  173. REPE b1 150 ;
  174. loopbeta = loopbeta + 1 ;
  175. * penalization of the stiffness matrix (modified SIMP)
  176. ep = emin + ((xphys ** penal) * (e0 - emin)) ;
  177. map = MATE mod 'YOUN' ep 'NU' nu 'DIM3' e ;
  178. k = RIGI mod map ;
  179. * resolution of the FE problem
  180. kbc = k ET blo ;
  181. u = RESO kbc f ;
  182. * objective function: compliance = u^T.F
  183. * value
  184. c = MAXI (RESU (PSCA u f (MOTS 'UX' 'UY') (MOTS 'FX' 'FY'))) ;
  185. * sensitivity (gradient with respect to the physical variable)
  186. eps = EPSI 'LINE' mod u ;
  187. sigun = ELAS mod maun eps ;
  188. eneun = ENER mod eps sigun ;
  189. eneun = INTG 'ELEM' mod eneun ;
  190. dc = -1. * penal * (xphys ** (penal - 1.)) * (e0 - emin) * eneun ;
  191. * constraint function: g1 = vf(x)/volfrac - 1
  192. * value
  193. g1 = (vfx / volfrac) - 1. ;
  194. * sensitivity (gradient with respect to the physical variable)
  195. dg1 = ve / vtot / volfrac ;
  196. * constraint function: g2 = p-norm(vf(x))/alpha - 1
  197. * value
  198. xbar = HFILT xphys mod kin ptg ;
  199. lxbar = EXTR xbar 'VALE' 'SCAL' ;
  200. gpmoy = AGRE 'PMOY' lxbar pinfill ;
  201. g2 = (gpmoy / ainfill) - 1. ;
  202. * sensitivity (gradient with respect to the physical variable)
  203. tmp = gpmoy / ((AGRE 'PMOM' lxbar pinfill) / nx) ;
  204. dg2 = (1. / (nx * ainfill)) * tmp * (xbar ** (pinfill - 1.)) ;
  205. * ft = 1 --> filtering the complicance sensitivity
  206. SI (ft EGA 1) ;
  207. dc = (HFILT (x * dc) mod kfil ptg) / (BORN x 'MINIMUM' 1.E-3) ;
  208. FINSI ;
  209. * ft = 2,3 --> updating the sensitivies (to become gradients with respect to the design variable)
  210. SI (ft EGA 2) ;
  211. dc = HFILT dc mod kfil ptg ;
  212. dg1 = HFILT dg1 mod kfil ptg ;
  213. dg2 = HFILT dg2 mod kfil ptg ;
  214. FINSI ;
  215. SI (ft EGA 3) ;
  216. dx = (beta * (EXP (-1. * beta * xtilde))) + (EXP (-1. * beta)) ;
  217. dctilde = dc * dx ;
  218. dc = HFILT dctilde mod kfil ptg ;
  219. dg1tilde = dg1 * dx ;
  220. dg1 = HFILT dg1tilde mod kfil ptg ;
  221. dg2tilde = dg2 * dx ;
  222. dg2 = HFILT dg2tilde mod kfil ptg ;
  223. FINSI ;
  224. * information about the current topology
  225. info = CHAI 'It:' (&b1 - 1) / 5 'Obj:' / 10 c > 1 'Vol. frac:' > 4 vfx > 1 'Change:' > 4 change > 1 'Beta:' > 4 beta > 2 ;
  226. SI itrac ;
  227. TRAC xphys mod con liso 'TITR' info 'NCLK' ;
  228. FINSI ;
  229. * update the topology by optimization
  230. tmma . 'F0VAL' = c ;
  231. tmma . 'DF0DX' = EXTR dc 'VALE' 'SCAL' ;
  232. tmma . 'FVAL' = PROG g1 g2 ;
  233. tmma . 'DFDX' = ENUM (EXTR dg1 'VALE' 'SCAL') (EXTR dg2 'VALE' 'SCAL') ;
  234. MMA tmma ;
  235. lxnew = tmma . 'X' ;
  236. xnew = MANU 'CHML' mod 'REPA' 'SCAL' lxnew 'TYPE' 'SCALAIRE' 'GRAVITE' ;
  237. * update the physical density (by filtering and thresholding)
  238. SI (ft EGA 1) ;
  239. xphys = xnew ;
  240. FINSI ;
  241. SI (ft EGA 2) ;
  242. xphys = HFILT xnew mod kfil ptg ;
  243. FINSI ;
  244. SI (ft EGA 3) ;
  245. xtilde = HFILT xnew mod kfil ptg ;
  246. xphys = 1. - (EXP (-1. * beta * xtilde)) + (xtilde * (EXP (-1. * beta))) ;
  247. FINSI ;
  248. * updating the volume fraction
  249. vfx = (INTG mod xphys maun) / vtot ;
  250. * summary of the current iteration
  251. change = MINI (MAXI 'ABS' (lxnew - (tmma . 'XOLD1')))
  252. (MAXI 'ABS' (lxnew - (tmma . 'XOLD2'))) ;
  253. liter = liter ET &b1 ;
  254. lobj = lobj ET c ;
  255. lvf = lvf ET vfx ;
  256. lchange = lchange ET change ;
  257. * preparing the next iteration
  258. x = xnew ;
  259. lx = lxnew ;
  260. * ft = 3 --> updatind the slope of the thresholding function
  261. SI (ft EGA 3) ;
  262. SI ((beta < 128) ET ((loopbeta >EG 50) OU (change &lt;EG changmax))) ;
  263. beta = 2 * beta ;
  264. loopbeta = 0 ;
  265. change = 1. ;
  266. FINSI ;
  267. FINSI ;
  268. * stop criterion
  269. SI (change < changmax) ;
  270. info = CHAI 'It:' &b1 / 5 'Obj:' / 10 c > 1 'Vol. frac:' > 4 vfx > 1 'Change:' > 4 change > 1 'Beta:' > 4 beta > 2 ;
  271. QUIT b1 ;
  272. FINSI ;
  273. FIN b1 ;
  274.  
  275. ** Elapsed time
  276. TEMP 'IMPR' 'SOMM' 'HORL' ;
  277.  
  278. ** Plotting the final topology
  279. evobj = EVOL 'ROUG' 'MANU' 'Iterations' liter 'Compliance' lobj ;
  280. evvf = EVOL 'ORAN' 'MANU' 'Iterations' liter 'Frac. vol.' lvf ;
  281. evchange = EVOL 'VERT' 'MANU' 'Iterations' liter 'Max. change' lchange ;
  282. SI itrac ;
  283. info = CHAI '[Final topology]' ' ' info ;
  284. TRAC xphys mod con liso 'TITR' info ;
  285. DESS evobj 'TITR' 'Objective function' ;
  286. DESS evvf 'TITR' 'Volume fraction' ;
  287. DESS evchange 'TITR' 'Max. change' ;
  288. FINSI ;
  289.  
  290.  
  291. FIN ;
  292.  
  293.  
  294.  
  295.  
  296.  

© Cast3M 2003 - Tous droits réservés.
Mentions légales