CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > ANSYS Meshing & Geometry

[ICEM] Scripting - For loops, expr function, integration

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 19, 2018, 13:44
Default Scripting - For loops, expr function, integration
  #1
New Member
 
Alex
Join Date: Mar 2018
Posts: 4
Rep Power: 8
ayoung94 is on a distinguished road
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.
ayoung94 is offline   Reply With Quote

Old   March 20, 2018, 05:02
Default
  #2
Senior Member
 
Sebastian Engel
Join Date: Jun 2011
Location: Germany
Posts: 566
Rep Power: 20
bluebase will become famous soon enough
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

Last edited by bluebase; March 20, 2018 at 05:22. Reason: better link
bluebase is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 11:04
[blockMesh] Errors during blockMesh meshing Madeleine P. Vincent OpenFOAM Meshing & Mesh Conversion 51 May 30, 2016 10:51
[blockMesh] non-orthogonal faces and incorrect orientation? nennbs OpenFOAM Meshing & Mesh Conversion 7 April 17, 2013 05:42
how to write an integration function in fluent self_shattered FLUENT 1 May 31, 2011 16:04
Droplet Evaporation Christian Main CFD Forum 2 February 27, 2007 06:27


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