Topology optimization workflow with PyANSYS

268 Views Asked by At

I want to set up a topology optimization (TO) workflow using PyANSYS. In this workflow, I want to parametrically create a geometry, mesh it, solve the static and TO parts, and finally post-process some results. Everything is in a loop, where I can analyze different geometries and their respective outcomes. My problem is how to find the right workflow and (ANSYS-)tools to accomplish this task. I am not even sure if it is possible at all. Also, my Python knowledge is somewhere around beginner level.

First of all, a pure implementation in APDL did not look promising, because the TO-solver is not accessible (anymore) in MAPDL (I found some old commands, which have been deprecated long ago). Therefore I have to use ANSYS Mechanical somehow. Now there seem to be two ways, either use the IronPython stuff within the Workbench/Mechanical GUI or use PyANSYS (in the form of PyMechanical). I settled with PyANSYS. The struggle here is, that I found that the documentation lacks some important topics, for example how to get geometry into the software for further processing (the examples only load pre-existing geometries based on ANSYS specific agdb-files, see here). Has anyone here tips on how to set something like this up? Even a MWE of creating a user-defined geometry, meshing, and solving would help a lot, to be honest. Maybe you also have some tips on how to integrate the TO part into the PyMechanical script.

1

There are 1 best solutions below

1
Mike R On

TO is its own program now - Workbench Mechanical is just calling it like it does Mechanical APDL to solve a model. I've not tried either of these but you could investigate:

  1. Set up a TO in WB Mechanical and for the structural analysis in chose to 'Write Input File' (upper right of UI in Solution tab) instead of actually solving. Right-click the Solution object and choose to open the folder containing the files. Then inspect the files. You should see where the MAPDL input file is set up to launch the TO. And there will be supporting files (for the TO) in addition to the typical ds.dat MAPDL input file. You may be able to work out a way of implementing in PyMAPDL.

  2. With just a structural system in WB Mechanical open the Scripting tool and turn on the "Start Recording" then proceed to add the TO (from Mechanical); set it up; solve etc and stop the recording. This should record what Mechanical did (in the scripting window) and you can copy/paste that and use it as a starting point of a PyMechanical script.

The PyMechanical way of getting geometry is a little odd; you upload it to the Mechanical instance. See the following PyMech Doc Then you can import it...but import is a Mechanical functionality. So again in scripting record while you import and update geometry manually from within Mechanical.