# Fidelity Pointwise 2023.2.3 Journal file - Tue Jun 17 16:19:19 2025
# =============================================================
# SECTION 0.0 –  Global Settings
# =============================================================
puts "▶ Aktuelles Arbeitsverzeichnis: [pwd]"

set cfg(prof_path)                "{{ PWS_PROF_PATH }}"
set cfg(grid_path)                "{{ PWS_GRID_PATH }}"
set cfg(proj_path)                "{{ PWS_PROJ_PATH }}"

set cfg(chord_length)             {{ PWS_CHORD_LENGTH }}
set cfg(split_percentage)         {{ PWS_SPLIT_PERCENTAGE }}
set cfg(ff_factor)                {{ PWS_FF_FACTOR }}
set cfg(ff_radius)                [expr {$cfg(ff_factor)*$cfg(chord_length)}]
set cfg(ff_center)                {0 0 0}
set cfg(ff_dimension)             {{ PWS_FF_DIMENSION }}

# Dimensions
set cfg(dim_back_connectors)      {{ PWS_DIM_BACK_CONNECTORS }}
set cfg(upper_front_dim)          {{ PWS_UPPER_FRONT_DIM }}
set cfg(upper_back_dim)           {{ PWS_UPPER_BACK_DIM }}
set cfg(lower_front_dim)          {{ PWS_LOWER_FRONT_DIM }}
set cfg(lower_back_dim)           {{ PWS_LOWER_BACK_DIM }}
set cfg(te_dim)                   {{ PWS_TE_DIM }}

set cfg(spacing_1)                {{ PWS_SPACING_1 }}
set cfg(spacing_2)                {{ PWS_SPACING_2 }}
set cfg(refinement)               {{ PWS_REFINEMENT }}

set cfg(spacing_1)  [expr $cfg(spacing_1)*$cfg(refinement)]
set cfg(spacing_2)  [expr $cfg(spacing_2)*$cfg(refinement)]

# Global Spacings
set cfg(upper_front_glb_spacing)  $cfg(spacing_1)
set cfg(upper_back_glb_spacing)   $cfg(spacing_2)
set cfg(lower_front_glb_spacing)  $cfg(spacing_1)
set cfg(lower_back_glb_spacing)   $cfg(spacing_2)

# Spacings
set cfg(upper_front_spacing_front)  $cfg(spacing_1)
set cfg(upper_front_spacing_back)   $cfg(spacing_2)
set cfg(upper_back_spacing_front)   $cfg(spacing_2)
set cfg(upper_back_spacing_back)    $cfg(spacing_2)
set cfg(lower_front_spacing_front)  $cfg(spacing_1)
set cfg(lower_front_spacing_back)   $cfg(spacing_2)
set cfg(lower_back_spacing_front)   $cfg(spacing_2)
set cfg(lower_back_spacing_back)    $cfg(spacing_2)

#trex
set cfg(trex_first_height)        {{ PWS_TREX_FIRST_HEIGHT }}
set cfg(trex_growth_rate_cond)    {{ PWS_TREX_GROWTH_RATE_COND }}
set cfg(trex_max_layers)          {{ PWS_TREX_MAX_LAYERS }}
set cfg(trex_full_layers)         {{ PWS_TREX_FULL_LAYERS }}
set cfg(trex_growth_rate_attr)    {{ PWS_TREX_GROWTH_RATE_ATTR }}
set cfg(size_field_decay)         {{ PWS_SIZE_FIELD_DECAY }}

#extrusion
set cfg(z_distance)               {{ PWS_EXTRUSION_Z_DISTANCE }}

# =============================================================
# SECTION 1 - Main Program
# =============================================================

package require PWI_Glyph 8.23.2

pw::Application setUndoMaximumLevels 5
pw::Application reset
pw::Application markUndoLevel {Journal Reset}

pw::Application clearModified

pw::Application setCAESolver {ANSYS Fluent} 3
pw::Application markUndoLevel {Select Solver}

# =============================================================
# SECTION 1 - Import
# =============================================================
set _TMP(mode_1) [pw::Application begin DatabaseImport]
  $_TMP(mode_1) initialize -strict -type Automatic $cfg(prof_path)
  $_TMP(mode_1) read
  $_TMP(mode_1) convert
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel {Import Database}
# =============================================================
# SECTION 1 - Set Spline
# =============================================================
set _DB(1) [pw::DatabaseEntity getByName curve-1]
set _TMP(mode_1) [pw::Application begin Modify [list $_DB(1)]]
  $_DB(1) spline
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel Spline
# =============================================================
# SECTION 1 - Set Chord Length
# =============================================================
set _TMP(mode_1) [pw::Application begin Modify [list $_DB(1)]]
  set scaleVec [list $cfg(chord_length) $cfg(chord_length) $cfg(chord_length)]
  pw::Entity transform [pwu::Transform scaling -anchor {0 0 0} $scaleVec] [$_TMP(mode_1) getEntities]
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel Scale
# =============================================================
# SECTION  - Convert to Connector
# =============================================================
set _TMP(PW_1) [pw::Connector createOnDatabase -parametricConnectors Aligned -merge 0 -type Unstructured -reject _TMP(unused) [list $_DB(1)]]
unset _TMP(unused)
unset _TMP(PW_1)
pw::Application markUndoLevel {Connectors On DB Entities}
# =============================================================
# SECTION  - Create TE
# =============================================================
pw::Display setShowDatabase 0
set _TMP(mode_1) [pw::Application begin Create]
  set _CN(1) [pw::GridEntity getByName con-1]
  set _TMP(PW_1) [pw::SegmentSpline create]
  $_TMP(PW_1) addPoint [$_CN(1) getPosition -arc 0]
  $_TMP(PW_1) addPoint [$_CN(1) getPosition -arc 1]
  set _CN(2) [pw::Connector create]
  $_CN(2) addSegment $_TMP(PW_1)
  unset _TMP(PW_1)
  $_CN(2) calculateDimension
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel {Create 2 Point Connector}
# =============================================================
# SECTION  - Split in upper/lower surface
# =============================================================
set _TMP(mode_1) [pw::Application begin Create]
  set _TMP(PW_1) [pw::SegmentSpline create]
  $_TMP(PW_1) delete
  unset _TMP(PW_1)
$_TMP(mode_1) abort
unset _TMP(mode_1)
set _TMP(split_params) [list]
lappend _TMP(split_params) [$_CN(1) getParameter -closest [pw::Application getXYZ [$_CN(1) closestPoint {0 0 0}]]]
set _TMP(PW_1) [$_CN(1) split $_TMP(split_params)]
unset _TMP(PW_1)
unset _TMP(split_params)
pw::Application markUndoLevel Split
# =============================================================
# SECTION  - Split upper again at 40 percent
# =============================================================
set _CN(3) [pw::GridEntity getByName con-1-split-1]
set _TMP(split_params) [list]
set _TMP(opp_split_percentage) [expr {1-$cfg(split_percentage)}]
lappend _TMP(split_params) [$_CN(3) getParameter -arc $_TMP(opp_split_percentage)]
set _TMP(PW_1) [$_CN(3) split $_TMP(split_params)]
unset _TMP(PW_1)
unset _TMP(split_params)
pw::Application markUndoLevel Split
# =============================================================
# SECTION  - Split lower again at 40 percent
# =============================================================
set _CN(4) [pw::GridEntity getByName con-1-split-2]
set _TMP(split_params) [list]
lappend _TMP(split_params) [$_CN(4) getParameter -arc [expr $cfg(split_percentage)]]
set _TMP(PW_1) [$_CN(4) split $_TMP(split_params)]
unset _TMP(PW_1)
unset _TMP(split_params)
pw::Application markUndoLevel Split
# =============================================================
# SECTION  - Farfield connector
# =============================================================
set _TMP(mode_1) [pw::Application begin Create]
  set _TMP(PW_1) [pw::SegmentCircle create]
  $_TMP(PW_1) addPoint "$cfg(ff_radius) 0 0"
  $_TMP(PW_1) addPoint $cfg(ff_center)
  $_TMP(PW_1) setEndAngle 360 {0 0 1}
  set _CN(6) [pw::Connector create]
  $_CN(6) addSegment $_TMP(PW_1)
  $_CN(6) calculateDimension
  unset _TMP(PW_1)
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel {Create Connector}

# =============================================================
# SECTION  - DIMESNIONS
# =============================================================
# TRAILING EDGE
set _CN(1) [pw::GridEntity getByName con-2]
$_CN(1) setDimension $cfg(te_dim)
pw::CutPlane refresh
pw::Application markUndoLevel Dimension

# $_CN(1) setDimensionFromSpacing -resetDistribution $cfg(lower_back_dim)
# pw::CutPlane refresh
# pw::Application markUndoLevel Dimension

# UPPER BACK
set _CN(2) [pw::GridEntity getByName con-1-split-1-split-1]
$_CN(2) setDimension $cfg(upper_back_dim)
pw::CutPlane refresh
pw::Application markUndoLevel Dimension

$_CN(2) setDimensionFromSpacing -resetDistribution $cfg(upper_back_glb_spacing)
pw::CutPlane refresh
pw::Application markUndoLevel Dimension

# UPPER FRONT
set _CN(3) [pw::GridEntity getByName con-1-split-1-split-2]
$_CN(3) setDimension $cfg(upper_front_dim)
pw::CutPlane refresh
pw::Application markUndoLevel Dimension

$_CN(3) setDimensionFromSpacing -resetDistribution $cfg(upper_front_glb_spacing)
pw::CutPlane refresh
pw::Application markUndoLevel Dimension

# LOWER FRONT
set _CN(4) [pw::GridEntity getByName con-1-split-2-split-1]
$_CN(4) setDimension $cfg(lower_front_dim)
pw::CutPlane refresh
pw::Application markUndoLevel Dimension

$_CN(4) setDimensionFromSpacing -resetDistribution $cfg(lower_front_glb_spacing)
pw::CutPlane refresh
pw::Application markUndoLevel Dimension

# LOWER BACK
set _CN(5) [pw::GridEntity getByName con-1-split-2-split-2]
$_CN(5) setDimension $cfg(lower_back_dim)
pw::CutPlane refresh
pw::Application markUndoLevel Dimension

$_CN(5) setDimensionFromSpacing -resetDistribution $cfg(lower_back_glb_spacing)
pw::CutPlane refresh
pw::Application markUndoLevel Dimension

# FARFIELD
set _CN(6) [pw::GridEntity getByName con-3]
$_CN(6) setDimension $cfg(ff_dimension)
pw::CutPlane refresh
pw::Application markUndoLevel Dimension

# $_CN(6) setDimensionFromSpacing -resetDistribution $cfg(lower_back_glb_spacing)
# pw::CutPlane refresh
# pw::Application markUndoLevel Dimension

# =============================================================
# SECTION  - SPACINGS
# =============================================================

set _TMP(mode_1) [pw::Application begin Modify [list $_CN(2)]]
  set _TMP(PW_1) [$_CN(2) getDistribution 1]
  $_TMP(PW_1) setBeginSpacing $cfg(upper_back_spacing_back)
  unset _TMP(PW_1)
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel {Change Spacing}

set _TMP(mode_1) [pw::Application begin Modify [list $_CN(2)]]
  set _TMP(PW_1) [$_CN(2) getDistribution 1]
  $_TMP(PW_1) setEndSpacing $cfg(upper_back_spacing_front)
  unset _TMP(PW_1)
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel {Change Spacing}


set _TMP(mode_1) [pw::Application begin Modify [list $_CN(3)]]
  set _TMP(PW_1) [$_CN(3) getDistribution 1]
  $_TMP(PW_1) setBeginSpacing $cfg(upper_front_spacing_back)
  unset _TMP(PW_1)
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel {Change Spacing}

set _TMP(mode_1) [pw::Application begin Modify [list $_CN(3)]]
  set _TMP(PW_1) [$_CN(3) getDistribution 1]
  $_TMP(PW_1) setEndSpacing $cfg(upper_front_spacing_front)
  unset _TMP(PW_1)
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel {Change Spacing}


set _TMP(mode_1) [pw::Application begin Modify [list $_CN(4)]]
  set _TMP(PW_1) [$_CN(4) getDistribution 1]
  $_TMP(PW_1) setBeginSpacing $cfg(lower_front_spacing_front)
  unset _TMP(PW_1)
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel {Change Spacing}

set _TMP(mode_1) [pw::Application begin Modify [list $_CN(4)]]
  set _TMP(PW_1) [$_CN(4) getDistribution 1]
  $_TMP(PW_1) setEndSpacing $cfg(lower_front_spacing_back)
  unset _TMP(PW_1)
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel {Change Spacing}


set _TMP(mode_1) [pw::Application begin Modify [list $_CN(5)]]
  set _TMP(PW_1) [$_CN(5) getDistribution 1]
  $_TMP(PW_1) setBeginSpacing $cfg(lower_back_spacing_front)
  unset _TMP(PW_1)
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel {Change Spacing}

set _TMP(mode_1) [pw::Application begin Modify [list $_CN(5)]]
  set _TMP(PW_1) [$_CN(5) getDistribution 1]
  $_TMP(PW_1) setEndSpacing $cfg(lower_back_spacing_back)
  unset _TMP(PW_1)
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel {Change Spacing}

# =============================================================
# SECTION  - Assemble special domain
# =============================================================

set _TMP(mode_1) [pw::Application begin Create]
  set _TMP(edge_1) [pw::Edge create]
  $_TMP(edge_1) addConnector $_CN(6)
  set _TMP(edge_2) [pw::Edge create]
  $_TMP(edge_2) addConnector $_CN(1)
  $_TMP(edge_2) addConnector $_CN(2)
  $_TMP(edge_2) addConnector $_CN(3)
  $_TMP(edge_2) addConnector $_CN(4)
  $_TMP(edge_2) addConnector $_CN(5)
  $_TMP(edge_2) reverse
  set _DM(1) [pw::DomainUnstructured create]
  $_DM(1) addEdge $_TMP(edge_1)
  $_DM(1) addEdge $_TMP(edge_2)
  unset _TMP(edge_2)
  unset _TMP(edge_1)
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel {Assemble Domain}

# =============================================================
# SECTION  - TREX
# =============================================================

set _TMP(mode_1) [pw::Application begin UnstructuredSolver [list $_DM(1)]]
  set _TMP(PW_1) [pw::TRexCondition create]
  unset _TMP(PW_1)
  set _TMP(PW_1) [pw::TRexCondition getByName bc-2]
  $_TMP(PW_1) setName wall
  $_TMP(PW_1) setConditionType Wall
  $_TMP(PW_1) apply [list [list $_DM(1) $_CN(2) Opposite] [list $_DM(1) $_CN(3) Opposite] [list $_DM(1) $_CN(4) Opposite] [list $_DM(1) $_CN(5) Opposite] [list $_DM(1) $_CN(1) Same]]
  $_TMP(PW_1) setValue $cfg(trex_first_height)
  $_TMP(PW_1) setGrowthRate $cfg(trex_growth_rate_cond)
  $_DM(1) setUnstructuredSolverAttribute TRexMaximumLayers $cfg(trex_max_layers)
  $_DM(1) setUnstructuredSolverAttribute TRexFullLayers $cfg(trex_full_layers)
  $_DM(1) setUnstructuredSolverAttribute TRexGrowthRate $cfg(trex_growth_rate_attr)
  $_DM(1) setUnstructuredSolverAttribute TRexCellType TriangleQuad
  $_DM(1) setSizeFieldDecay $cfg(size_field_decay)
  $_TMP(mode_1) run Initialize
$_TMP(mode_1) end
unset _TMP(mode_1)
pw::Application markUndoLevel Solve

unset _TMP(PW_1)
pw::Application markUndoLevel Solve

# =============================================================
# SECTION  - Extrude Domain
# =============================================================

set _TMP(mode_1) [pw::Application begin Create]
  set _TMP(PW_1) [pw::FaceUnstructured createFromDomains [list $_DM(1)]]
  set _TMP(face_1) [lindex $_TMP(PW_1) 0]
  unset _TMP(PW_1)
  set _BL(1) [pw::BlockExtruded create]
  $_BL(1) addFace $_TMP(face_1)
$_TMP(mode_1) end
unset _TMP(mode_1)
set _TMP(mode_1) [pw::Application begin ExtrusionSolver [list $_BL(1)]]
  $_TMP(mode_1) setKeepFailingStep true
  $_BL(1) setExtrusionSolverAttribute Mode Translate
  $_BL(1) setExtrusionSolverAttribute TranslateDirection {1 0 0}
  $_BL(1) setExtrusionSolverAttribute TranslateDirection {0 0 1}
  $_BL(1) setExtrusionSolverAttribute TranslateDistance $cfg(z_distance)
  $_TMP(mode_1) run 1
$_TMP(mode_1) end
unset _TMP(mode_1)
unset _TMP(face_1)
pw::Application markUndoLevel {Extrude, Translate}

set _TMP(PW_1) [pw::BoundaryCondition create]
pw::Application markUndoLevel {Create BC}

unset _TMP(PW_1)
set _TMP(PW_1) [pw::BoundaryCondition create]
pw::Application markUndoLevel {Create BC}

unset _TMP(PW_1)
set _TMP(PW_1) [pw::BoundaryCondition create]
pw::Application markUndoLevel {Create BC}

unset _TMP(PW_1)
set _TMP(PW_1) [pw::BoundaryCondition getByName bc-2]
$_TMP(PW_1) setName wall
pw::Application markUndoLevel {Name BC}

set _TMP(PW_2) [pw::BoundaryCondition getByName bc-3]
$_TMP(PW_2) setName symm
pw::Application markUndoLevel {Name BC}

set _TMP(PW_3) [pw::BoundaryCondition getByName bc-4]
$_TMP(PW_3) setName farf
pw::Application markUndoLevel {Name BC}

$_TMP(PW_1) setPhysicalType -usage CAE Wall
pw::Application markUndoLevel {Change BC Type}

$_TMP(PW_2) setPhysicalType -usage CAE Symmetry
pw::Application markUndoLevel {Change BC Type}

$_TMP(PW_3) setPhysicalType -usage CAE {Pressure Inlet}
pw::Application markUndoLevel {Change BC Type}

set _DM(2) [pw::GridEntity getByName dom-8]
$_TMP(PW_2) apply [list [list $_BL(1) $_DM(2)]]
pw::Application markUndoLevel {Set BC}

$_TMP(PW_2) apply [list [list $_BL(1) $_DM(1)]]
pw::Application markUndoLevel {Set BC}

set _DM(3) [pw::GridEntity getByName dom-2]
$_TMP(PW_3) apply [list [list $_BL(1) $_DM(3)]]
pw::Application markUndoLevel {Set BC}

set _DM(4) [pw::GridEntity getByName dom-6]
set _DM(5) [pw::GridEntity getByName dom-5]
set _DM(6) [pw::GridEntity getByName dom-3]
set _DM(7) [pw::GridEntity getByName dom-7]
set _DM(8) [pw::GridEntity getByName dom-4]
$_TMP(PW_1) apply [list [list $_BL(1) $_DM(4)] [list $_BL(1) $_DM(5)] [list $_BL(1) $_DM(6)] [list $_BL(1) $_DM(7)] [list $_BL(1) $_DM(8)]]
pw::Application markUndoLevel {Set BC}

unset _TMP(PW_1)
unset _TMP(PW_2)
unset _TMP(PW_3)

# =============================================================
# SECTION  - Save
# =============================================================
pw::Application save $cfg(proj_path)
set _TMP(mode_1) [pw::Application begin CaeExport]
  $_TMP(mode_1) addAllEntities
  $_TMP(mode_1) initialize -strict -type CAE $cfg(grid_path)
  $_TMP(mode_1) verify
  $_TMP(mode_1) write
$_TMP(mode_1) end
unset _TMP(mode_1)
