How to Write a Thermal Plugin in Simcenter 3D Thermal

A step-by-step guide for engineers who would rather be matching test data

If you’re anything like me, you care more about thermal gradients and test data than you do about learning how to code, referencing libraries, and compiling.

Good news! This step-by-step guide will show you how to quickly to write a thermal plugin so you can spend more time on the tasks you enjoy.

What is a thermal plugin?

A thermal plugin is a collection of functions that can be compiled into a .dll and referenced in a simulation. These functions could include heat transfer correlations, windage correlations, and any others you find useful in your design space.

For example, imagine something that returns heat transfer coefficient based on mass flow, flow area, and length [i.e., HTC(M,A,L)]. With a function like that, you would be able to access parameters such as fluid temperature and density during the solve to calculate parameters that would be useful in your correlations.

Advantages of a thermal plugin

A thermal plugin makes it possible to:

  • Include complex custom expressions and access solver variables.
  • Keep your correlations confidential.
  • Keep your model inputs clean and limit characters in an expression.
  • Reduce the risk of user input error.

How to compile a thermal plugin

You can compile a thermal plugin using either Visual Studio (in Windows) or a script (in Windows or Linux). Follow the steps for your preferred method below.

1. Visual Studio (Windows)

The advantage of using Visual Studio is that you have access to all of your files in one interface, as opposed to having to manually open text files in a folder.

Compile the code in Visual Studio
  1. To ensure the compiler knows where to look, first define an environment variable.
  2. Set UGII_BASE_DIR to point to the installation directory of Simcenter 3D (the parent directory of NXCAE_EXTRAS).
  3. Go into your installation directory and locate the following folder: \NXCAE_EXTRAS\tmg\plugin_examples\thermal_solver\ExpressionsVS2017
  4. Copy the whole folder to a location where you have write access.
  5. In Visual Studio, open the sln file in the first level directory. Find supported versions and compilers for Simcenter 3D 2212
  6. Inspect the cppfile under Source Files.  Inspect the following to become familiar with the structure and syntax:
    1. HTCCustom()header and definition (lines 164-315)
    2. Optional output text (lines 304-311); for debugging
    3. Set()(line 320); this defines the units for the function
    4. std::couttext (lines 304-311); this exports parameter values into the solution monitor for debugging
  7. Compile the code using Build >> Build Solution; this creates the dllfile

That’s it for compiling the code.

Reference the plugin in customer defaults in Simcenter
  1. Go to File >> Utilities >> Customer Defaults
  2. Navigate to Simulation >> Pre/Post >> Expressions
  3. Check the box and define your full path to the .dll file.
  4. Restart your Simcenter session.
  5. Open the simulation file (.sim) from .\NXCAE_EXTRAS\tmg\plugin_examples\thermal_solver\Model
  6. Inspect Thermal Stream (1).  Notice the reference to HTCCustom()
  7. Run the model and verify your plugin is working.

You’ve successfully compiled code and verified the .dll is working.

Now, you can make modifications as needed in the ExpressionsPlugin.cpp file.

How do you call quantities from the thermal solver?

For instance, let’s say you want to call swirl velocity into your plugin, or maybe a material quantity like thermal conductivity.

The following files provide the necessary syntax and function names for calling various quantities:

  1. h  >>  various thermal solver quantities (e.g., fluid temperature)
    .\nxcae_extras\tmg\plugin_examples\thermal_solver\ExpressionsVS2017\ExpressionsPlugin\AdditionalFunctions.h 
  2. hxx  >>  NX quantities (e.g., spatial coordinates) .\ugstructures\evalplugin\src\CaeUtils_Exp_Icontext.hxx
  3. hxx  >> NX Material properties (e.g., thermal conductivity)
    .\ugstructures\evalplugin\src\CaeUtils_Exp_Imaterial.hxx 

 

2. Script (Windows or Linux)

This approach is the same, whether you are working in Windows or in Linux. Only the build file used is different.

  • For Windows, use build_windows.cmd
  • For Linux, use build_linux.com

Compile the code with a build script:

  1. To ensure the compiler knows where to look, first define an environment variable.
  2. Set UGII_BASE_DIRto point to the installation directory of Simcenter 3D (the parent directory of NXCAE_EXTRAS).
  3. Go into your installation directory and locate the following folder: .\NXCAE_EXTRAS\tmg\plugin_examples\thermal_solver\ExpressionsShell
  4. Copy the whole folder to a location where you have write access.
  5. To compile, execute the build file. This will generate the .dll file that you can then reference in Simcenter 3D.

Note: The plugin source code is contained in UserFunctions.cpp.  All other steps for inspecting and modifying the code are the same as described for the Visual Studio compiling approach.

Start writing your thermal plugins

These steps should be enough guidance for you to dip your toes into using thermal plugins in Simcenter 3D. Hopefully you now feel enabled to write some complex plugins and compile them into a .dll to enhance your models in terms of physics and simplicity of expressions.

Looking for a little more hands-on guidance with plugins for Simcenter 3D? Contact a Maya HTT expert today.

Subscribe to our newsletter