September 10, 2021 at 10:18 pmgreg2835Subscriber
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.September 15, 2021 at 2:53 pmgreg2835SubscriberSo 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 :)
September 16, 2021 at 5:30 pmAniketForum ModeratorThanks 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.
How to access Ansys help links
Guidelines for Posting on Ansys Learning Forum
September 18, 2021 at 2:19 pmgreg2835SubscriberSure 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.
September 18, 2021 at 2:20 pmgreg2835SubscriberThe 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).
September 19, 2021 at 7:58 amApril 14, 2022 at 11:05 amMichaelKrausSubscriberHey 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
April 25, 2022 at 1:48 amDinofoursSubscriberHi Michael I've sent you an e-mail. Really keen to get something like this going.
April 25, 2022 at 1:52 amDinofoursSubscriberHi 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.
April 25, 2022 at 2:27 pmgreg2835Subscriber
Sure please direct message me and I will provide my info.
April 27, 2022 at 1:49 amDinofoursSubscriberHi 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:
April 27, 2022 at 7:10 amMichaelKrausSubscriberHi 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
Ansys Innovation Space
- The topic ‘USERMAT and Trained Neural Networks’ is closed to new replies.
Boost Ansys Fluent Simulations with AWS
Computational Fluid Dynamics (CFD) helps engineers design products in which the flow of fluid components is a significant challenge. These different use cases often require large complex models to solve on a traditional workstation. Click here to join this event to learn how to leverage Ansys Fluids on the cloud, thanks to Ansys Gateway powered by AWS.
Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.Trending discussions
- How to do the frequency response of the nonlinear vibration of a flexible PCB?
- Importing Line and Solid Bodies from SpaceClaim to Mechanical
- how to open SendCommand in Ansys
- problems facing during solution
- Still facing the same issue
- Failed to move file from solver directory to scratch directory: file.rst
- Adaptive Sizing
- Stiffness factor
- Import DAT file
- Import pressure data (coordinates and value) to ansys workbench through excel
Top Rated Tags
© 2023 Copyright ANSYS, Inc. All rights reserved.Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.