Tips are displayed if you "mouse-over" black keywords
#!/bin/csh -f
# $Id: aero_csh.html,v 1.19 2024/11/27 19:19:29 mnemec Exp $
# AERO: Adjoint Error Optimization
# Script to drive adjoint-based mesh refinement
# ATTENTION: requires Cart3D release 1.5 or newer
# M. Nemec, Marian.Nemec@nasa.gov
# Oct 2006, last update: Oct 2021
# Help:
# ------
# % ./aero.csh help
# Read tips, hints and documentation in $CART3D/doc/adjoint
# See examples in $CART3D/cases/samples_adapt
# Set user specified options below, defaults are suggested
# -------------
# Basic options
# -------------
# Number of adaptation cycles, e.g. if you pick 8 then the run will terminate
# after the flow solve in adapt08. Min value is 0, max value is 99.
set n_adapt_cycles = 9
# maxR for initial mesh (cubes)
set maxR = 7
# Spanwise orientation (-y_is_spanwise flag in flowCart)
set y_is_spanwise = 0 # {Yes, No} = {1, 0}
# Set mesh2d = 1 for 2D cases, mesh2d = 0 for 3D cases
set mesh2d = 0
# ----------------
# Advanced options
# ----------------
# Uncomment next line to control thread affinity (improve parallel performance)
# on linux machines
# ...generally safer on hyperthreaded systems
#setenv KMP_AFFINITY scatter
# ...may be slightly faster when not hyperthreaded
#setenv KMP_AFFINITY compact
# ----- Flow and adjoint solver settings -----
# Number of fine-grid flowCart iterations on initial mesh
set it_fc = 150
# Additional flowCart iterations on each new mesh
# cycle 1 2 3 4 5 6 7 8 9 10
set ws_it = ( 150 150 150 200 200 200 200 200 250 250 )
# Number of fine-grid adjointCart iterations on each mesh
set it_ad = 150
# Number of flowCart multigrid levels (default=3)
set mg_fc = 3
# Number of adjointCart multigrid levels (usually same as flowCart)
set mg_ad = 3
# Limiter: default 1 (Barth-Jespersen) is the most accurate, 2 (van Leer) is
# smoother and may offer deeper convergence. Limiter 5 (minmod) is most robust
# and 0 means no limiter.
set limiter = 1
# Functional averaging window in terms of flowCart mg-cycles. This is useful
# for cases that do not converge to steady-state. The averaged functional is
# reported in the fourth column of fun_con.dat and in all_outputs.avg.dat
# (default: avg_window = 1).
set avg_window = 1
# ----- Mesh adaptation settings ------
# Maximum number of cells in the penultimate mesh, i.e. number of cells allowed
# in the working mesh for the final embedding. The error estimation step
# requires ~6.9 GB per million cells. You can use this to gauge the largest
# mesh your memory resources allow. Default value is 9M, which assumes a
# machine with 64 GB of memory.
set max_cells2embed = 9000000
# Specify mesh growth for each adaptation cycle. Mesh growth should be greater
# than 1 and less than or equal to 8. Specifying 8 means that you allow
# refinement of every cell in the mesh. Recommended minimum growth is 1.1. We
# found the sequence below to work well for many problems: if your initial mesh
# has roughly 10,000 cells, then after 10 adaptations it will surpass 10
# million cells. (For 2D cases, we recommend growth factors of 1.2 for first
# two cycles and 1.4 for the rest.) If you enter 0 for any cycle, then the mesh
# growth is selected automatically in that cycle.
# cycle 0 1 2 3 4 5 6 7 8 9 10
set mesh_growth = ( 1.5 1.5 2.0 2.0 2.0 2.0 2.0 2.5 2.5 2.5 2.5 )
# Mesh growth can be selected automatically by enabling the auto_growth
# option. This is a new feature, where aero.csh sets the refinement threshold
# to the mean of the error distribution. This feature frequently yields better
# results than the default mesh_growth array.
set auto_growth = 0 # 0=no, 1=yes, default=0
# Set apc: adapt or interface propagation cycle
# a = adapt
# p = propagate interfaces (adapt mesh without reducing finest cell size)
# Use p-cycles sparingly. We recommend using one initial p-cycle to reduce
# the bias of the initial mesh. P-cycles should also be used once the volume
# mesh over-refines your surface triangulation.
# cycle 0 1 2 3 4 5 6 7 8 9 10
set apc = ( p a a a a a a a a a a )
# ----- Customization of initial mesh -----
# Use file name preSpec.c3d.cntl for preSpec regions (either BBoxes or XLevs
# for cubes or ABoxes for adapt) 0=no, 1=yes, default=0
set use_preSpec = 0
# Initial mesh parameters (cubes)
set cubes_a = 10 # angle criterion (-a)
set cubes_b = 3 # buffer layers (-b)
# Remesh: use refMesh.{mg.c3d,c3d.Info} to guide cell density of initial mesh
# (cubes -remesh option). If turned on, we recommend increasing mg_init
# (initial number of multigrid levels, see flag below) to 3 or 4. Note that the
# cubes_a flag is automatically set to 20 if it is less than 20. 0=no, 1=yes,
# default=0
set use_remesh = 0
# Internal mesh (cubes): 0=no, 1=yes, default=0
set Internal = 0
# ----- Run control -----
# Do error analysis on finest mesh? 0=no, 1=yes, default=0
set error_on_finest = 0
# Exit on reaching the finest mesh, do not flow solve there. This is useful if
# you wish to run a different solver (e.g. the MPI version) on the finest mesh.
# The final adapt?? directory holds the final mesh, all the input files, as
# well as a FLOWCART file that contains the appropriate command line.
set skip_finest = 0 # 0=no, 1=yes, default=0
# Maximum level of refinement allowed in the mesh. This controls the size of
# the smallest cell in the mesh. Default value is 21, which is the maximum
# supported by Cart3D. The run terminates when either max_ref_level or
# n_adapt_cycles is satisfied, whichever is smaller.
set max_ref_level = 21
# Set extra refinement levels for the final mesh. This allows you to adapt the
# mesh multiple times with the same error map in the last adapt cycle, thereby
# bypassing the flow, adjoint, and error estimation steps. Use with caution:
# the mesh should be fine enough so that the error estimate is decreasing -
# preferably the solution should be in the Richardson region. This helps
# circumvent the memory limitations of the error estimation code. Default value
# is 0 and maximum allowed value is 3.
set final_mesh_xref = 0
# ---------------------------------------------------
# EXPERT user options: flags below are rarely changed
# ---------------------------------------------------
# Cut-cell gradients: 0=best robustness (default), 1=best accuracy
# If mesh2d=1, then we set tm=1 automatically
set tm = 0
# CFL number: usually ~1.1 but with power may be lower, i.e. 0.8
set cfl = 1.0
# Minimum CFL number, used in case of convergence problems with flowCart
set cflmin = 0.2
# Adaptation error tolerance. Run terminates if the error estimate falls
# below this value. At least 2 cycles will be run before terminating based on
# this tolerance to avoid triggering based on an inappropriate initial mesh.
set etol = 0.0000001
# Grid sequencing (-gs) or multigrid (-mg) (-mg default)
# flowCart
set mg_gs_fc = '-mg'
# adjointCart
set mg_gs_ad = '-mg'
# Full multigrid: default is to use full multigrid, except in cases with power
# boundary conditions (automatic with warm starts)
set fmg = 1 # 0=no, 1=yes, default=1
# Polynomial multigrid, helps certain tough cases converge deeper
set pmg = 0 # 0=no, 1=yes, default=0
# Buffer limiter: improves stability for flows with strong off-body shocks
set buffLim = 0 # 0=no, 1=yes, default=0
# Number of multigrid levels for initial mesh (default 2, ramps up to mg_fc/ad)
set mg_init = 2
# Set names of executables (must be in path)
set flowCart = flowCart
set xsensit = xsensit
set adjointCart = adjointCart
set adjointErrorEst = adjointErrorEst_quad
# MPI prefix: uncomment next line and also remember to set the correct flowCart
# executable above. If not running MPI, comment out next line.
# set mpi_prefix = 'mpiexec -n 16'
# Flow solver warm-starts: 0=no, 1=yes, default=1
set use_warm_starts = 1
# Subcell resolution: 0=no, 1=yes, default=0
set subcell = 0
# Run adjoint solver in 1st-order mode. In hard cases where aero.csh
# consistently falls back on 1st-order mode after trying more accurate
# settings, this setting will short-circuit the process and go directly to
# 1st-order adjoints. The flow solution remains 2nd-order. The adjoints should
# still provide a consistent set of error estimates, which is probably safe for
# _relative_ errors and adaptive meshing. However, use caution: the error
# estimates may be inaccurate with respect to a 2nd-order run.
# default 0=auto, 1=force 1st order
set adj_first_order = 0
# In 3D cases with tm=1, error estimation is still done with tm=0 for
# robustness. This flag forces aero.csh to use tm=1 in error estimation. This
# is recommended only for simple (academic) cases that converge well. In
# general, the default (0) setting is _strongly_ recommended.
set err_TM1 = 0 # default 0=off, 1=force tm 1 for error estimation
# In 3D cases with tm=1, adjoint solutions are still done with tm=0 for
# robustness. This flag forces aero.csh to use tm=1 for the adjoint solves. In
# general, the default (0) setting is _strongly_ recommended. Note that
# adjoint convergence is monitored, so if divergence occurs then tm=0 is set
# during runtime.
set adj_TM1 = 0 # default 0=off, 1=force tm 1 for adjoint solutions
# When running optimization with adaptive meshing, this flag allows different
# levels of adjoint convergence for the mesh adaptation functional vs. the
# design functionals. The iterations for the adjoint solutions used in gradient
# computations are it_ad + delta_it_ad. The main idea is to use fewer
# iterations when building the mesh (for speed) and go for deeper converge in
# the gradient adjoints (for better accuracy). Default value is 0.
set delta_it_ad = 0
# Keep final error map in EMBED/Restart.XX.file, useful for cubes -remesh
set keep_error_maps = 0 # default 0=no, 1=yes
# Refine all cells: useful for uniform mesh refinement studies. This overrides
# the error map and forces adapt to refine all cells. The adjoint correction
# term and error estimate are reported.
set refine_all_cells = 0 # default 0=no, 1=yes
# adapt buffers (default 1)
set buf = 1
# Set the number of multigrid levels when aero.csh drops down to pMG due to
# convergence problems. Default value is 2, which means no geometric
# multigrid. In subsonic cases, 3 multigrid levels may be better. Note that
# this flag has no effect on the pmg multigrid levels when the pmg flag is
# selected above. It influences only the automatic run control of aero.csh.
set mg_pmg_auto = 2
# Fine tuning of mesh growth when performing extra refinements on the final
# mesh, i.e. when $final_mesh_xref>0 and $mesh_growth are being used.
# The mesh growth for each extra refinement is given by:
# ($mesh_growth-1)*$xref_fraction+1
# The main idea is that as extra refinement cycles are performed, the
# adaptation focuses on only the highest error cells. This is where the error
# map is most accurate and most adaptation is required. Each value should be
# between 0.2 and 1, and at most three extra refinements are allowed.
set xref_fraction = ( 1.0 1.0 0.8 )
# Safety factor used in aero_getResults.pl to terminate the run if the error
# indicator value increases by more than this factor in successive
# cycles. Default value is 8.
set error_safety_factor = 8
# Adaptation restart: Alternative to command line argument 'restart'
set adapt_restart = 0
# Adaptation jumpstart from existing mesh: Alternative to command line
# argument jumpstart
set adapt_jumpstart = 0
# Write Tecplot output files in binary format
set binaryIO = 1 # default 1=yes, 0=no
# Verbose mode for executables [flowCart/xsensit/adjointCart/adjointErrorEst]
# 0=no, 1=yes, default=0
set verb = 0
# Adaptation threshold array: To set ath manually, unset mesh_growth
# and set the ath array (uncomment following two lines):
# cycle 0 1 2 3 4 5 6 7 8 9 10
#set ath = ( 32 16 8 4 2 1 1 1 1 1 1 )
#unset mesh_growth
# Output cell-wise errors, useful for making histograms: 0=off, 1=yes,
# default=0
set histo = 0
# ---------------------------------------------
# STOP: no user specified parameters below here
# ---------------------------------------------
.
.
.
echo 'Done aero.csh'
exit 0
ERROR:
exit 1