Learn thermal plugin basics

Learn how to compile the plugin and use it in Simcenter 3D.

Download the files from the installation directory under THERMALFLOW\tmgsolver\plugin_examples.

Introduction

A thermal plugin is a collection of user-defined functions compiled into a .dll file and referenced within a simulation. These functions can include heat transfer windage and pumping or any other custom correlations and relationships relevant to your modeled physics.

For example, consider a function that computes a heat transfer coefficient based on mass flow, flow area, and characteristic length: HTC(M,A,L), where mass flow, flow area and characteristic length are externally supplied arguments.

In this workshop, you will:

  • Open a sample plugin in Visual Studio.
  • Compile the plugin into a .dll.
  • Open a model that references the plugin.
  • Modify the code to output debug messages.
  • Inspect unit handling.
  • Review header files to understand available solver data.

Open the Visual Studio project and compile

Set the required environment variable, open the Visual Studio project, and compile the sample thermal plugin into a .dll file.

  1. Set an environment variable UGII_BASE_DIR to point to the main installation directory of Simcenter 3D on your computer.
  2. Open Visual Studio and load the .sln file located in the thermal_solver/ExpressionsVS2019 folder of the workshop files. If any migration prompts appear, click OK to proceed.
  3. In the Solution Explorer, open ExpressionsPlugin.cpp. This file contains the expressions that will be reviewed and modified during the workshop.
  4. Ensure you specify to compile the Release version of the plugin in the drop down in the top border.


  5. Select Build > Build Solution to compile the code to .dll.
    You should see a message similar to the one shown below, indicating the full path of the compiled .dll file. This path will be used when configuring the customer default in Simcenter 3D.

Load the thermal plugin in Simcenter 3D

Load the thermal plugin.

  1. Open Simcenter 3D.
  2. Choose File > Utilities > Customer Defaults.
  3. Click Simulation, expand Pre/Post, and click Expressions.
  4. On the Plugin tab, select the Use Custom Plugin check box.
  5. Type the path to ExpressionsPlugin.dll retrieved from your Visual Studio output.
  6. Click Ok to exit the dialogue
  7. Exit Simcenter 3D and restart it to load the connection to the .dll.

Load the sample model and solve

Load the sample model and solve.

  1. Choose FileOpen and open THERMALFLOW\tmgsolver\plugin_examples\thermal_solver\Model\model.sim.
  2. Inspect the stream to see that it references HTCCustom() from the thermal plugin.
  3. Define results options to include convection coefficients.
  4. Solve the model.
  5. Display convection coefficients.


  6. Inspect the log file and observe that there are no debug messages.

Write out messages to better debug the plugin

It is good practice to verify that your thermal plugin is returning the expected values. To assist with this validation, you can print the variables used within the function to confirm they contain reasonable values. This will be demonstrated in the next step.

  1. Return to the visual studio project.
  2. Scroll to line 325 under HTCCustom, and replace #if 0 with #if 1.

    This activates the printouts in the solution monitor as they are shown in lines 326 to 333.



  3. Select Release from the top border bar to write out a debug version of the plugin.
  4. Select Build > Build Solution to compile the code.
  5. Verify that the .dll file has been compiled.

Re-load the sample model and solve

  1. In Simcenter 3D, change the plugin expression to reference the newly compiled version of the plugin.
  2. Exit Simcenter 3D and reload to load the new plugin.
  3. Clone the Solution as Solution 2 Debug, and re-run the model.
  4. Inspect some debug messages in the log file as shown below.


Check units

In the HTCCustom() function, the units must be explicitly defined so that Simcenter correctly interprets the quantity returned by the function. In this case, the heat transfer coefficient is typically expressed in W/m²·°C (or W/m²·K). The following section explains how the units are specified within the function definition.
  1. Open Visual Studio and check the ExpressionsPlugin.cpp file.
  2. Observe line 341. This defines a new measurement system called meas.
  3. Observe line 342. This sets the units for meas, which is then used in line 345 when defining the function.


    In the meas.Set fields, each number represents the exponent of a fundamental unit in the following order: Mass, Length, Time, Temperature, Charge, Angle, DeltaT, Intensity, Amount of Substance. The values shown correspond to to [m/s3∆T] which is equivalent to [W/m2C].

    In Simcenter 3D, Temperature (T) and Temperature Difference (ΔT) are treated as distinct units. Therefore, it is important to define the exponent for ΔT correctly to ensure proper unit handling within the function.

Explore header files

  1. Inspect lines 209 to 217 of ExpressionsPlugin.cpp.

    The block of code checks if fluid pressure exist. If fluid pressure exists, the magnitude is assigned to fluidPressure, and if it doesn’t, a message is produced to the solution monitor.



  2. The GetFluidPressure() function can be found in CaeUtils_Exp_IContext.hxx header file found in External Dependencies.




  3. Thermal property utility functions can be found under CaeUtils_Exp_IMaterial.hxx as shown.


  4. Inspect the line 109 in ExpressionsPlugin.cpp.
    Here, the function pGetDistance is initialized. This initialization is required because the function is available in the thermal solver environment, but not in Simcenter 3D. A complete list of additional functions that are available only in the thermal solver can be found in AdditionalFunctions.h, located under the Header Files folder.



Additional notes

  • The sample plugin is updated with each thermal solver patch release and is located in the installation directory: THERMALFLOW\tmgsolver\plugin_examples\thermal_solver\ExpressionsVS2019\ExpressionsPlugin.
  • If you prefer to compile the plugin using a script rather than Visual Studio, a .cmd file is available in: THERMALFLOW\tmgsolver\plugin_examples\thermal_solver\ExpressionsShell