Share

Building the user library

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 Community is a free download from https://visualstudio.microsoft.com/free-developer-offers/.

Note: Be sure to select the Desktop development with C++ component during installation of Visual Studio.

Your functions must have C name mangling rules (extern "C") and use the C calling convention (__stdcall on Windows). The below header file (provided in the sample project as ViscosityUserFunctions.h) is a good place to start.

Note: Example code is provided in the installed directory folder. Using Windows Explorer, navigate to the installed directory folder, typically C:\Program Files\Autodesk\Moldflow Insight 20XX\data\solverapi.
#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

Building the user library on Windows

On Windows, build your library as a 64-bit Release DLL. The example Microsoft Visual Studio 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.

If you create a new Visual Studio project, ensure that the following options are set:

  • General > Target Name = MoldflowUserFunctions
  • General > Configuration Type = Dynamic Library (.dll)
  • General > Character Set = Use Unicode Character Set
  • C/C++ > Code Generation > Runtime Library = Multi-threaded (/MT)
  • Linker > Advanced > Target Machine = MachineX64 (/MACHINE:X64)

Building the user library on Linux

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.

Development advice

The SolverUserHb3dViscosity, PVT, solidification, additional heat source, heat transfer coefficient 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 (such as 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.

Was this information helpful?