


{"id":364688,"date":"2024-04-29T12:52:53","date_gmt":"2024-04-29T12:52:53","guid":{"rendered":"\/forum\/forums\/topic\/memory-leak-pymapdl\/"},"modified":"2024-05-01T07:07:38","modified_gmt":"2024-05-01T07:07:38","slug":"memory-leak-pymapdl","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/memory-leak-pymapdl\/","title":{"rendered":"Memory Leak PyMapdl"},"content":{"rendered":"<p>Hello everyone,&nbsp;<br \/>does anyone have experience with simulating in a loop? I am running many (&gt;1000) simple simulations within an optimization algorithm. I use PyMapdl for this. With each simulation the required RAM in Python increases. If I do not run the simulations, the problem does not occur. Enclosed is a highly simplified Psyeudocode where the problem also occurs. Even starting and closing Ansys in each run does not solve the problem (apart from a considerable increase in runtime).<\/p>\n<div>\n<div>import os<\/div>\n<div>from ansys.mapdl.core import launch_mapdl<\/div>\n<div>path = os.path.abspath(__file__)<\/div>\n<div>directory = os.path.dirname(path)<\/div>\n<div>temp_dir = os.path.join(directory, &#8216;temp_ansys&#8217;)<\/div>\n<div>if not os.path.exists(temp_dir):<\/div>\n<div>&nbsp; &nbsp; os.makedirs(temp_dir)<\/div>\n<div>mapdl = launch_mapdl(nproc=4,run_location=temp_dir, override=True)<\/div>\n<p><\/p>\n<div>def calculate_energy():<\/div>\n<div>&nbsp; &nbsp; mapdl.clear()<\/div>\n<div>&nbsp; &nbsp; mapdl.prep7()<\/div>\n<div>&nbsp; &nbsp; mapdl.blc4(0, 0, 1000, 1000)<\/div>\n<div>&nbsp; &nbsp; mapdl.blc4(1000, 0, 1000, 1000)<\/div>\n<div>&nbsp; &nbsp; mapdl.aglue(&#8216;ALL&#8217;)<\/div>\n<div>&nbsp; &nbsp; # BC<\/div>\n<div>&nbsp; &nbsp; mapdl.ksel(&#8220;S&#8221;, &#8220;LOC&#8221;, &#8220;X&#8221;, 0)<\/div>\n<div>&nbsp; &nbsp; mapdl.ksel(&#8220;A&#8221;, &#8220;LOC&#8221;, &#8220;X&#8221;, 1000)<\/div>\n<div>&nbsp; &nbsp; mapdl.ksel(&#8220;R&#8221;, &#8220;LOC&#8221;, &#8220;Y&#8221;, 0)<\/div>\n<div>&nbsp; &nbsp; mapdl.dk(&#8220;ALL&#8221;, &#8216;UX&#8217;, 0)<\/div>\n<div>&nbsp; &nbsp; mapdl.dk(&#8220;ALL&#8221;, &#8220;UY&#8221;, 0) &nbsp;<\/div>\n<div>&nbsp; &nbsp; mapdl.allsel()<\/div>\n<div>&nbsp; &nbsp; mapdl.clear()<\/div>\n<p><\/p>\n<div>&nbsp; &nbsp; return 1<\/div>\n<div>for i in range(0,1000):<\/div>\n<div>&nbsp; &nbsp; a = calculate_energy()<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"template":"","class_list":["post-364688","topic","type-topic","status-closed","hentry","topic-tag-pyansys-1","topic-tag-PyMAPDL-1","topic-tag-python"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["346742","58821","170445"],"_bbp_author_ip":["23.196.2.137"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_bbp_likes_count":["1"],"_btv_view_count":["184"],"_bbp_topic_status":["unanswered"],"_bbp_status":["publish"],"_bbp_topic_id":["364688"],"_bbp_forum_id":["27791"],"_bbp_engagement":["58821","170445","346742"],"_bbp_voice_count":["3"],"_bbp_reply_count":["2"],"_bbp_reply_count_hidden":["1"],"_bbp_last_reply_id":["364851"],"_bbp_last_active_id":["364851"],"_bbp_last_active_time":["2024-04-30 10:14:40"]},"test":"luca-dannemannrub-de"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/364688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/364688\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=364688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}