Optistruct crash after starting an analysis with user-defined material
My goal is to create a material law that accounts for the adaptive behavior of bone in response to stress. Since I couldn't find any suitable material in Optistruct, I decided to program it myself in C++ using the USERMAT (User-Defined Material) tool.
However, a few seconds after starting the analysis, I receive an error message informing me that Optistruct has stopped working and the analysis stops abruptly. Yet, the .out file of the simulation assures me that the library has been successfully exported and that the analysis has terminated correctly (.out & .stat files attached to the post).
- I managed to export it as a dynamic library following the documentation on this subject. (I activated the /MT and /LD options correctly). The only exception is that I did not use
__declspec(dllexport) int <subroutine name> (<arguments>)
as the Microsoft tutorial on dynamic library export recommended the following method:// BoneUsermat.h - Contains declarations of BoneUsermat functions #pragma once #ifdef BONEUSERMAT_EXPORTS #define BONEUSERMAT_API __declspec(dllexport) #else #define BONEUSERMAT_API __declspec(dllimport) #endif #include <array> #include <string> #include <iostream> #include <numeric> #include<cmath> extern "C" BONEUSERMAT_API void usermaterial(int idu, std::array<double, 6>&stress, std::array<double, 6>&strain, std::array<double, 6>&dstrain, double stater[], double state[], int nstate, std::array<std::array<double, 3>, 3>&drot, double props[], int nprops, int ndi, int nshear, int ntens, double temp, double dtemp, int ieuid, int kinc, double dt, double t_step, double t_total, std::array<std::array<double, 6>, 6>&cdev, double cbulk, std::string & userdata, int ierr); extern "C" BONEUSERMAT_API void smatusr(int idu, int nprop, double prop[], int ndi, int nshear, int ntens, std::array<double, 21>&smat, std::string userdata, int ierr);
- If I choose a classic material law (MAT1), the simulation runs normally, which suggests that the problem is indeed isolated to the MATUSR law.
- I tried to reprogram a simple MATUSR law (linear elastic) in the subroutine, and then even an entirely empty subroutine, to check if the problem didn't come from my modeling. Optistruct crashes in all cases.
I have two possible explanations for the problem, but feel free to share yours:
- The types of arguments in my subroutine are not defined correctly. Since I don't have an example of a subroutine in C++, I don't know how strict the software is on this subject.
void usermaterial(int idu, std::array<double, 6>& stress, std::array<double, 6>& strain, std::array<double, 6>& dstrain, double stater[], double state[], int nstate, std::array<std::array<double, 3>, 3>& drot, double props[], int nprops, int ndi, int nshear, int ntens, double temp, double dtemp, int ieuid, int kinc, double dt, double t_step, double t_total, std::array<std::array<double, 6>, 6>& cdev, double cbulk, std::string& userdata, int ierr) // Explanation: // Converted the data types from Fortran to C++ equivalents: // - Changed integer to int. // - Changed double precision arrays to std::array if the length is fixed, or standard tables if not // - Changed character*32000 to std::string.
- The version of the compiler used to export the program as a .dll library is too recent compared to the compiler used for Optistruct: If this is the case, it means that I need to get an older version of Visual Studio or an Intel compiler to use it on Code::Blocks. In any case, it requires a significant investment...
So, my question is: Do you have any idea where the problem might be coming from? Is there a way to obtain more information about the Optistruct crash that would allow me to pinpoint the exact error? I would be reluctant to purchase an expensive Visual Studio subscription only to realize that the problem does not come from there...
PS : I know it would have probably helped, but I am unfortunately not allowed to share the content of the script or the Hyperworks model.
PPS : I figured that depending on the computer I launch the analysis, Optistruct may not always crash but would still end the simulation abruptly, without exporting results...
Answers
-
I have partially resolved my problem.
For anyone interested, it seems you can't use std::array or std::string, you should define your variables respectively as table and char
For example,double cdev[6][6]
,char userdata[]
...Now the analysis output basic results, but it doesn't seem to save or output the state variables.
0 -
Update : It doesn't work because the analysis uses the smatusr subroutine for linear analysis even though I parametered the simulation as Non-Linear Static...
I don't know why but I hope it can help other people better understand how MATUSR works.
Now the goal is to find a way to force the solver to use the non-linear subroutine.0