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

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