Simcenter STAR-CCM+ provides a built-in capability to interpolate tabular data as field function. This functionality is meant to interpolate a dependent variable against a single independent variable. This article shows a method and provides an automation script that can be used to handle interpolation of a dependent variable from a table against two independent variables.
Simcenter STAR-CCM+ provides a built-in capability to interpolate tabular data as field function. This functionality is meant to interpolate a dependent variable against a single independent variable. This article shows a method and provides an automation script that can be used to handle interpolation of a dependent variable from a table against two independent variables. A simple example is chosen for demonstration purposes.
One-dimensional interpolation can be handled within STAR-CCM+ using the interpolate field function. Consider that we have a table of variable A and D as shown below. We are interested in linearly interpolating the value of "D" against the values of "A", using a field function value of "$A".
A | D |
---|---|
1 | 2 |
2 | 4 |
3 | 6 |
4 | 8 |
This can be handled using the following field function syntax:
interpolateTable(@Table("<tablename>"), "<x-column>", {LINEAR | STEP | SPLINE}, "<phi-column>", <scalar_expression>)
For our example this becomes:
interpolateTable(@Table("table-1"), "A", LINEAR, "D", $A)
Now lets consider that our dependent variable "D" depends on two independent variables. 1st independent variable "A" and 2nd independent variable "B" as shown in the table and plot below. We are interested in interpolating the value of D from a table against two field functions called "$A" and "$B".
A\B | 300 | 320 | 340 | 360 |
---|---|---|---|---|
1 | 2 | 4 | 6 | 8 |
2 | 4 | 6 | 8 | 10 |
3 | 6 | 8 | 10 | 12 |
4 | 8 | 10 | 12 | 14 |
To handle this 2D interpolation, we will convert this 2D table into a series of 1D tables as shown below.
A | D |
---|---|
1 | 2 |
2 | 4 |
3 | 6 |
4 | 8 |
A | D |
---|---|
1 | 4 |
2 | 6 |
3 | 8 |
4 | 10 |
We import a 1D table corresponding to each value of the 2nd independent variable "B". We write a 1D interpolation field function (FF) that interpolates the value of dependent variable D against each 1st independent variable A, using the field function $A as shown below.
FF name = A_at_B_300 FF definition = interpolateTable(@Table("1D Table - at B=300"), "A", LINEAR, "D", $A) FF name = A_at_B_320 FF definition = interpolateTable(@Table("1D Table - at B=320"), "A", LINEAR, "D", $A) FF name = A_at_B_340 FF definition = interpolateTable(@Table("1D Table - at B=340"), "A", LINEAR, "D", $A) FF name = A_at_B_360 FF definition = interpolateTable(@Table("1D Table - at B=360"), "A", LINEAR, "D", $A)
Now we can use these interpolations with the 1st independent variable A to write another field function that interpolates linearly with the 2nd independent variable B as shown below.
FF name = final_interp_FF FF definition = $B<=300 ? $A_at_B_300 : $B>300 && $B<=320 ? (($A_at_B_320-$A_at_B_300)/(320-300))*($B-300) + $A_at_B_300 : $B>320 && $B<=340 ? (($A_at_B_340-$A_at_B_320)/(340-320))*($B-320) + $A_at_B_320 : $B>340 && $B<=360 ? (($A_at_B_360-$A_at_B_340)/(360-340))*($B-340) + $A_at_B_340 : $B>=360 ? $A_at_B_360 : 0
An example simulation file is attached with the demonstrated implementation of the field function. A user input for field functions $A = 3.5, $B=350; results in a 2D interpolated value of 12.0.
Writing these field functions can be a daunting task. A macro has been provided to write all the interpolation field functions. The macro provides detailed description of the user inputs and has been commented well for understanding.
The attached compressed file contains two example sim files with the sample data shown in this article. The "Example_final.sim" contains the field functions already implemented, the "Example_start.sim" can be used to run the macro to generated the field functions automatically.
See also: