To use the solver API you need to compile it into a native shared library on the platform where you will be running the solver.
If you need a compiler, Microsoft Visual Studio Express is a free download from http://www.visualstudio.com/en-us/downloads.
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#define STDCALL __stdcall
#else
#define DLLEXPORT
#define STDCALL
#endif
// Required functions.
DLLEXPORT double STDCALL SolverUserHb3dViscosity(double temperature, double shearRate, double pressure);
// Optional functions.
DLLEXPORT void STDCALL SolverUserHb3dInitialize();
DLLEXPORT void STDCALL SolverUserHb3dAnalysisSetup();
DLLEXPORT void STDCALL SolverUserHb3dTimeStepComplete(double time);
DLLEXPORT void STDCALL SolverUserHb3dCleanup();
DLLEXPORT double STDCALL SolverUserHb3dViscosityAtNode(double temperature, double shearRate, double pressure, size_t nodeId);
DLLEXPORT double STDCALL SolverUserHb3dViscosityAtLaminateOfNode(double temperature, double shearRate, double pressure, size_t nodeId, unsigned int laminateId);
#ifdef __cplusplus
}
#endif
If you have enabled the user library for thermoplastic viscosity, then you must define the SolverUserHb3dViscosity function. The others are optional.
On Windows, build your library as a 64-bit Release DLL. The example Microsoft Visual Studio 2012 projects, MoldflowUserFunctions_xxx.vcxproj, can be compiled directly and installed with no changes.
The resulting DLL must be called MoldflowUserFunctions.dll and must be copied (by an administrator) to the same directory as mhb3d.exe, typically C:\Program Files\Autodesk\Moldflow Insight 20xx\bin. This DLL will be opened only if you have enabled the user library in the advanced solver parameters.
On Linux, build your library as a 64-bit ELF shared object (.so). The data/solverapi directory contains examples with source code and makefiles. Compile these examples with a command like:
make -f Makefile_Example1
The resulting shared library must be called MoldflowUserFunctions.so (with that capitalization) and must be copied (by a user with write permission) to the lib directory of the installation, typically in the Workstation installation, /opt/Autodesk/moldflow/20YY/lib. This library will be opened only if you have enabled the user library in the advanced solver parameters.
The SolverUserHb3dViscosity, PVT, and cores shift functions may be called millions of times in an analysis. They need to be thread-safe, so take care when accessing global state. Due to the nature of the 3D Flow solver, the functions may be called out of chronological order within a time step, so do not assume that time increases monotonically.
If you call the SolverUtilityHb3dFail function from within multithreaded code (including the SolverUserHb3dViscosity functions), the solver will not immediately exit. It will continue running until the end of the current time step. This guarantee allows your code to access resources in the knowledge that they can be properly freed.