Télécharger top_oc.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: Optimality Criteria *
  14. * *
  15. * Problem: minimize the compliance with a constraint *
  16. * on the volume fraction *
  17. * *
  18. * min C(x) = u^T.F *
  19. * s.t. G(x) = vf(x) = volfrac *
  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. ** Lets's start a timer
  133.  
  134. ** Topology optimization loop
  135. liso = PROG 0. 'PAS' 0.05 1. ;
  136. loopbeta = 0 ;
  137. liter = PROG ;
  138. lobj = PROG ;
  139. lvf = PROG ;
  140. lchange = PROG ;
  141. REPE b1 500 ;
  142. loopbeta = loopbeta + 1 ;
  143. * penalization of the stiffness matrix (modified SIMP)
  144. ep = emin + ((xphys ** penal) * (e0 - emin)) ;
  145. map = MATE mod 'YOUN' ep 'NU' nu 'DIM3' e ;
  146. k = RIGI mod map ;
  147. * resolution of the FE problem
  148. kbc = k ET blo ;
  149. u = RESO kbc f ;
  150. * objective function: compliance = u^T.K.u
  151. * value
  152. c = MAXI (RESU (PSCA u f (MOTS 'UX' 'UY') (MOTS 'FX' 'FY'))) ;
  153. * sensitivity (gradient with respect to the physical variable)
  154. eps = EPSI 'LINE' mod u ;
  155. sigun = ELAS mod maun eps ;
  156. eneun = ENER mod eps sigun ;
  157. eneun = INTG 'ELEM' mod eneun ;
  158. dc = -1. * penal * (xphys ** (penal - 1.)) * (e0 - emin) * eneun ;
  159. * constraint function: g = vf(x)
  160. * value
  161. g = vfx ;
  162. * sensitivity (gradient with respect to the physical variable)
  163. dg = ve / vtot ;
  164. * ft = 1 --> filtering the complicance sensitivity
  165. SI (ft EGA 1) ;
  166. dc = (HFILT (x * dc) mod kfil ptg) / (BORN x 'MINIMUM' 1.E-3) ;
  167. FINSI ;
  168. * ft = 2,3 --> updating the sensitivies (to become gradients with respect to the design variable)
  169. SI (ft EGA 2) ;
  170. dc = HFILT dc mod kfil ptg ;
  171. dg = HFILT dg mod kfil ptg ;
  172. FINSI ;
  173. SI (ft EGA 3) ;
  174. dx = (beta * (EXP (-1. * beta * xtilde))) + (EXP (-1. * beta)) ;
  175. dctilde = dc * dx ;
  176. dc = HFILT dctilde mod kfil ptg ;
  177. dgtilde = dg * dx ;
  178. dg = HFILT dgtilde mod kfil ptg ;
  179. FINSI ;
  180. * information about the current topology
  181. info = CHAI 'It:' (&b1 - 1) / 5 'Obj:' / 10 c > 1 'Vol. frac:' > 4 vfx > 1 'Change:' > 4 change > 1 'Beta:' > 4 beta > 2 ;
  182. SI itrac ;
  183. def1 = DEFO mesh u 0.05 ;
  184. TRAC xphys mod con def1 liso 'TITR' info 'NCLK' ;
  185. FINSI ;
  186. * update the topology by optimization
  187. l1 = 0. ;
  188. l2 = 1.E9 ;
  189. REPE b2 200 ;
  190. SI (((l2 - l1) / (l1 + l2)) < 0.001) ;
  191. QUIT b2 ;
  192. FINSI ;
  193. lmid = 0.5 * (l1 + l2) ;
  194. b = -1. * dc / (lmid * dg) ;
  195. xinf = BORN (x - move) 'MINIMUM' xmin ;
  196. xsup = BORN (x + move) 'MAXIMUM' xmax ;
  197. xnew = x * (b ** 0.5) ;
  198. minf = (xnew - xinf) MASQ 'INFERIEUR' 0. ;
  199. mmil = ((xnew - xinf) MASQ 'SUPERIEUR' 0.) * ((xnew - xsup) MASQ 'INFERIEUR' 0.) ;
  200. msup = (xnew - xsup) MASQ 'SUPERIEUR' 0. ;
  201. xnew = (xinf * minf) + (xnew * mmil) + (xsup * msup) ;
  202. * update the physical density (by filtering and thresholding)
  203. SI (ft EGA 1) ;
  204. xphys = xnew ;
  205. FINSI ;
  206. SI (ft EGA 2) ;
  207. xphys = HFILT xnew mod kfil ptg ;
  208. FINSI ;
  209. SI (ft EGA 3) ;
  210. xtilde = HFILT xnew mod kfil ptg ;
  211. xphys = 1. - (EXP (-1. * beta * xtilde)) + (xtilde * (EXP (-1. * beta))) ;
  212. FINSI ;
  213. * updating the volume fraction
  214. vfx = (INTG mod xphys maun) / vtot ;
  215. SI (vfx > volfrac) ;
  216. l1 = lmid ;
  217. SINON ;
  218. l2 = lmid ;
  219. FINSI ;
  220. FIN b2 ;
  221. * summary of the current iteration
  222. change = MAXI 'ABS' (xnew - x) ;
  223. liter = liter ET &b1 ;
  224. lobj = lobj ET c ;
  225. lvf = lvf ET vfx ;
  226. lchange = lchange ET change ;
  227. * preparing the next iteration
  228. x = xnew ;
  229. * ft = 3 --> updatind the slope of the thresholding function
  230. SI (ft EGA 3) ;
  231. SI ((beta < 512) ET ((loopbeta >EG 50) OU (change &lt;EG changmax))) ;
  232. beta = 2 * beta ;
  233. loopbeta = 0 ;
  234. change = 1. ;
  235. FINSI ;
  236. FINSI ;
  237. * stop criterion
  238. SI (change < changmax) ;
  239. info = CHAI 'It:' &b1 / 5 'Obj:' / 10 c > 1 'Vol. frac:' > 4 vfx > 1 'Change:' > 4 change > 1 'Beta:' > 4 beta > 2 ;
  240. QUIT b1 ;
  241. FINSI ;
  242. FIN b1 ;
  243.  
  244. ** Elapsed time
  245. TEMP 'IMPR' 'SOMM' 'HORL' ;
  246.  
  247. ** Plotting the final topology
  248. evobj = EVOL 'ROUG' 'MANU' 'Iterations' liter 'Compliance' lobj ;
  249. evvf = EVOL 'ORAN' 'MANU' 'Iterations' liter 'Frac. vol.' lvf ;
  250. evchange = EVOL 'VERT' 'MANU' 'Iterations' liter 'Max. change' lchange ;
  251. SI itrac ;
  252. info = CHAI '[Final topology]' ' ' info ;
  253. TRAC xphys mod con liso 'TITR' info ;
  254. DESS evobj 'TITR' 'Objective function' ;
  255. DESS evvf 'TITR' 'Volume fraction' ;
  256. DESS evchange 'TITR' 'Max. change' ;
  257. FINSI ;
  258.  
  259. ** Mesh of the final topology
  260. tab1 = TABL ;
  261. tab1 . 'EPAISSEUR' = e ;
  262. tab1 . 'MODELE' = mod ;
  263. tab1 . 'TOPOLOGIE' = xphys ;
  264. meshf = (TOPOSURF tab1) COUL 'GRIS' ;
  265. edge = ARET meshf ;
  266. SI itrac ;
  267. TRAC 'FACE' meshf 'ARET' edge 'TITR' 'Mesh of the final topology' ;
  268. FINSI ;
  269.  
  270. FIN ;
  271.  
  272.  
  273.  

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