call code aster from python

Hi all,

my question may already have been answered. But after some reasearch I did not find an answer to it.

I am wondering how to call aster from python.

I just need to call aster to make some simple actions (compute linear modes or nonlinear static analysis) inside an existing python class. Is there a simple way to plug aster inside it ?

I don’t know which aster install is the most adapted for it : full install (but how ? I was used to aster website but it seems a bit abandonned), sif or docker.

I tried the docker way as it is exposed in simvia dockerhub.

Just ran docker run -it -v $(pwd):/home/user/data simvia/code_aster:stable which lead to docker prompt.

There is a python inside. Good.

But impossible to import code_aster as it done here : No module named 'code_aster'. Quick look at python -m pip list, no code_aster.

Is there a simple way to call code_aster from a python file ? Or should I necessarily use a .comm file written with python code ?

Best

Edit : I am working from WSL ubuntu

Hi,

Calling python directly and then doing:

import code_aster

will not work in the Docker image. code_aster is not installed as a regular Python package available from the default Python environment, so it will not appear in pip list.

The intended entry point is run_aster. It is mainly a wrapper around the Python executable used by code_aster, with the proper environment, paths and execution context.

For example, if you create a file demo.py:

import code_aster

print(“Hello from code_aster”)

and run it with:

run_aster demo.py

then the import should work.

So, in practice, there are two possible approaches:

If you want to drive code_aster from an external Python application, the most robust way is usually to generate a .comm or Python command file and call run_aster from your Python code, for example using subprocess.

If you want your script itself to import code_aster, then this script must be executed through run_aster, not through the standard python command.

A .comm file in code_aster is already Python-based, so for most use cases such as linear modal analysis or nonlinear static analysis, the usual workflow is still to write or generate a command file and execute it with run_aster.

Best,

@basile-simvia

Hi Basile,

thank you for your answer.

For the moment I stick to the classic approach run_aster on export file.

I still have to experience how to write structured code, like classes, associated with aster commands defined in a different file from the .comm one. I don’t know if it possible with this approach or if it needs from code_aster import CA.

Best,

Adrien