CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ANSYS Meshing & Geometry (https://www.cfd-online.com/Forums/ansys-meshing/)
-   -   [ICEM] Scripting - For loops, expr function, integration (https://www.cfd-online.com/Forums/ansys-meshing/199929-scripting-loops-expr-function-integration.html)

ayoung94 March 19, 2018 13:44

Scripting - For loops, expr function, integration
 
I am having trouble generating point geometry based around a curve equation. I wish to create several points to describe the curve, and want to do this via a for loop, as part of a project on automating geometry and mesh for given input parameters.

However, my current code returns several errors, including the For loop not being closed, and the 'integralExpr' function not being a valid command.

Code:

ic_geo_new_family GEOM
ic_empty_tetin
set d_throat 0.1288
set d_ef 0.1524
set n_profiles 6
set x_duct 0.4572
set l_curve 0.481613
for {set i 0} {$i<$n_profiles} {set i [expr $i+1]} {
set x_l [expr $i / ($n_profiles - 1)]
set x_curve [expr $l_curve * $x_l]
set x_global [integralExpr 0 $x_curve 10 sqrt(1 + (0.0225 * 3.14159 * 3.14159 * sin(3.14159 * $x_l) * sin(3.14159 * $x_l)))]
set y_global 0
set z_global [expr -0.15 * $x_duct * (1 - cos(3.14159 * $x_l))]
ic_point {} GEOM pnt.1 $x_global,$y_global,$z_global
}

Any suggestions and corrections are most welcome. Thanks in advance.

bluebase March 20, 2018 05:02

Hi Alex,

before you continue, i suggest you to do a quick introduction into the scripting language "Tcl".

There are indeed a few problems in your script.

  1. Let's start with the obvious.
    integralExpr is not a built-in function. It's probably coming from the additional calculus package. You need to import that package into your script. See the help page.
  2. The error that the for loop is not closed might be caused by the file format ICEM assumes. For your code, use the file extension ".tcl". ICEM is very picky in ".rpl" format. The Replay Format assumes one complete command per line only. Usually, multi-line code does not work. (I did not bother to find a workaround.) Save and load your script with a plain ".tcl" extension.
  3. Now, the less obvious. Because tcl uses implicit variable types, there is only one difference between an integer and a decimal number. It's the decimal point ("."). Let's examine the following line:
    Code:

    set x_l [expr $i / ($n_profiles - 1)]
    If you check each component there are only integer in this expression. i, n_profiles, and 1 don't have a decimal point, therefore they are considered as integer. Dividing an integer by an integer will result in an integer, not a decimal number... This will result in losing the fractional part of x_l.
    Changing the "1" to "1." will force converting the denominator into a decimal number, which will result to x_l also being a decimal number.
    Code:

    set x_l [expr $i / ($n_profiles - 1.)]
  4. Some minor improvements:
    • This part can be simplified
      Code:

      {set i [expr $i+1]}
      to
      {incr i}

    • Modify the new point name to a dynamic new name, and make a proper coordinate list
      Code:

      ic_point {} GEOM pnt.1 $x_global,$y_global,$z_global
      to
      ic_point {} GEOM pnt.$i "$x_global, $y_global, $z_global"

    • This part can be simplified
      Code:

      3.14159 * 3.14159 * sin(3.14159 * $x_l) * sin(3.14159 * $x_l)
       to
      (3.14159 * sin(3.14159 * $x_l))**2



All times are GMT -4. The time now is 16:08.