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

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