How best to automate batches of structural experiments using Mecway's Python API?

I'd like to use Mecway to run batches (say, 50-500 at a time) of FEA experiments e.g. to find the best variant(s) out of a set of related structures. My plan is to use IronPython inside Mecway to generate structures (rather than externally generate inp files, Abaqus-style).

Can I use a script launched from the command line (using mecway script myfile.py) to set a big batch of solves in motion?

Or is there a better way of using Mecway to achieve the same thing? Thanks!

Comments

  • Two ways:

    Python script like you suggested:
    • Easy to modify some aspects of the model such as node locations and most load values but not everything is available through the API.
    • Access to some tools like mesh refinement and integration of field variables.
    • Can read the solution between solves to inform subsequent changes.
    • Doesn't show progress while solving.


    Modify the .liml files externally and solve from command line using a batch file or your own program:
    • Maximum freedom to modify anything in the input file.
    • More coding required to modify the input and read the solution using your own program.
    • Does show progress while solving.
    • You can get the solution from a csv file exported by Table.
  • I am probably never going to do this, but can you potentially show progress by using two instances of Mecway, one running the Iron python script to run the problems save them, and alter run and save again with an incremented name, and another instance of Mecway to sequentially open and show the output? (I know... a lot of memory and storage).
  • Hi Victor, thanks for the quick reply!

    I've already tried building some geometry from scratch via a Python script, and that worked perfectly. However, there doesn't seem to be ways to create loads or constraints via the API, only ways to modify pre-existing ones: which I'm guessing may well be an example of what you mention about not everything being available via the API.

    So, it's looking to me as though it isn't (yet) possible to build geometry, add loads and constraints, and then pass the whole lot through to a solver purely via Mecway's Python API. Is that basically correct? If so, are there any plans to extend that Python API to allow it to do that, or is the Python API essentially frozen?

    If the API is indeed frozen and incomplete, is there any documentation on the .liml file format that you can point me at? Unsurprisingly, I was really hoping Mecway would be smart enough that I could avoid that whole (fairly stinky) Abaqus inp-generating-Python route, but I guess what I'm doing isn't (yet) the mainstream use case for Mecway.

    Thanks again, Nick
  • Yes, you can't currently build a model from scratch with the API. Maybe start with one having placeholder loads?

    The API isn't frozen, and I'm frequently adding to it to make it more complete. It was a late addition to Mecway that hasn't caught up with the GUI yet.

    No documentation for the .liml format, sorry. However, it's XML with descriptive names for most things so shouldn't be too hard to work out by looking at examples. You could use an XML library to operate on it, or treat it as plain text.
  • Hi Victor,

    I'm very pleased to hear that you plan to make the API more complete over time! My use case is pure R&D structural optimisation using straightforward (isotropic) materials, where the final shape gets evolved over numerous generations of experiments.

    Role-playing that through a little, all the Python API seems to be missing to support that is the ability to create/delete loads and constraints. Are there other facilities that would be needed beyond that?

    Thanks, Nick
  • I think there is a similar example in FreeCAD.
    https://youtube.com/watch?v=VQINrNWdOHo

  • MikeMcMullen: FreeCAD does indeed offer a (essentially) complete API, yes. However, my experience of FreeCAD hasn't been even half as good as my experience of Mecway, and I'd rather use the latter as my primary platform if possible.
  • I agree, but my thinking is that looking into the python used for the freedad examples may give a clue to what needs to be done in Mecway. I think the Freecad uses Calculix for this exasmple, but I am not sure.
  • MikeMcMullen: ah, good point! I'll build a simple example in FreeCAD and see what steps are needed to get it working... 👍
  • edited November 2023
    MikeMcMullen: well, I've gone down the rabbit hole you suggested and written a FreeCAD FEM script. FreeCAD's part module is actually sensationally good, but the rest is quite hard work, and I've yet to extract the results I want out of a Solver session.

    Update: I should add that its material integration is basically non-existent, its gmmsh mesh handling often yields meshes that Calculix errors on, and the fem:: constraint scale issue has been an embarrassment for years. But... maybe I've missed something. 😬
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!