General Mechanical

General Mechanical

Topics relate to Mechanical Enterprise, Motion, Additive Print and more

USERMAT and Trained Neural Networks

    • greg2835
      Subscriber

      I know this might be a bit niche but hoping to get some sort of help.

      So I have a "trained neural network", which ultimately is just a matrix that can take inputs and predict outputs. This neural network (NN) is used as a specific constitutive equation sig = NN*eps. I'd like to use this in the Ansys solver, and came across USERMAT subroutines that are used for making custom constitutive equations.

      My question is if anyone has done something similar and how you went about implementing it. The NN is "trained" in Python so I have a Python executable for making predictions. My first thought was to couple USERMAT with Python, but I have zero experience with doing this (I just have bolts for brains). I know USERMAT is written in FORTRAN, but doing some digging I didn't see anything straight forward for coupling FORTRAN with Python.

      So maybe people on here much smarter than me have suggestions for tacking this? The NN is pretty big, over a million elements in the matrix, but maybe there is a not-so-painstaking way of outputting the Python matrix into a FORTRAN executable? I know that's a better question to ask on a FORTRAN/Python forum which I have, I'm just grasping at straws trying to figure out how I'm going to do this.

    • greg2835
      Subscriber
      So I was able to work around this by linking USERMAT with MATLAB to do the ML. Seems like there are no solid features for doing ML in Fortran (from what I can tell) and linking with Python seems to be not a straightforward thing (but is in reverse). MATLAB is most likely much slower but for now it's working :)
    • Aniket
      Forum Moderator
      Thanks for sharing your questions as well as the answer! For the greater good of the community in up and coming area, if you can shed some more light on the solution you found would be great for others!
      Also, I don't think there is a FORTRAN library to read ML models and that is what you may need. But an easy option may be to create an executable of your python code and calling that executable from USERMAT whenever you want to evaluate. The input and output data would need to be exchanged through files. For example, the executable will read the inputs through a file containing the input data written by USERMAT, evaluate the ML model, and write a file with outputs that are again read by USERMAT to modify the Ansys Solver routine.
      -Aniket
      How to access Ansys help links
      Guidelines for Posting on Ansys Learning Forum
    • greg2835
      Subscriber
      Sure thing Aniket, I actually had to do a similar work around as you described. Though MATLAB has a way of communicating to FORTRAN through MEX files, I actually used MATLAB Compiler to create a .exe file with a feed forward network built in. In USERMAT I call the .exe with 3 strain inputs (plane strain problem) which processes and writes to an output .dat file, which then USERMAT reads these 3 stress and 1 state value. USERMAT then proceeds as usual. Albeit is a bit slow but for our purposes it is working fine.
    • greg2835
      Subscriber
      The reason for doing it this way is my fortran compiler is Intel oneAPI, which MATLAB 2021 is currently not compatible with (still works with Intel Parallel).
    • Aniket
      Forum Moderator
    • MichaelKraus
      Subscriber
      Hey all! anyone up for a short zoom meeting on that topic?
      I would like to team up on NNs as material model within ANSYS.

      Please drop me an email:
      Dr. Michael Anton Kraus ÔÇô Massiv- und Br├╝ckenbau | ETH Z├╝rich
    • Dinofours
      Subscriber
      Hi Michael I've sent you an e-mail. Really keen to get something like this going.
    • Dinofours
      Subscriber
      Hi Greg Do you have any contact information? I'd love to talk more about this as I'm trying to run a Neural Network and script Ansys Mechanical using python.
      Thank you!

    • greg2835
      Subscriber

      Sure please direct message me and I will provide my info.
    • Dinofours
      Subscriber
      Hi Greg I'm not sure if it is possible to send a direct message in this forum. At least I can't find a way to do it.
      Please e-mail me at:
      rmor479@aucklanduni.ac.nz
    • MichaelKraus
      Subscriber
      Hi Greg and Rafael let's team up on that! i also could not find the direct messaging option here?
      Let's meet via Zoom next week? Both: drop me an email with availabilities.
Viewing 11 reply threads
  • The topic ‘USERMAT and Trained Neural Networks’ is closed to new replies.