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

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