cape.pyfun.case: FUN3D case control module

This module contains the important function casecntl.run_fun3d(), which actually runs nodet or nodet_mpi, along with the utilities that support it.

It also contains FUN3D-specific versions of some of the generic methods from cape.case. For instance the function GetCurrentIter() determines how many FUN3D iterations have been run in the current folder, which is obviously a solver-specific task. It also contains the function LinkPLT(), which creates links to fixed Tecplot file names from the most recent output created by FUN3D.

All of the functions from cape.case are imported here. Thus they are available unless specifically overwritten by specific cape.pyfun versions.

class cape.pyfun.casecntl.CaseRunner(fdir=None)
copy_hist(j: int)

Copy all FM and residual histories

Call:
>>> runner.copy_hist(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number to use for storing histories

Versions:
  • 2016-10-28 @ddalle: v1.0 (CopyHist)

  • 2023-07-06 @ddalle: v1.1; instance method

finalize_files(j: int)

Clean up files after running one cycle of phase j

Call:
>>> runner.finalize_files(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number

Versions:
  • 2016-04-14 @ddalle: v1.0 (FinalizeFiles)

  • 2023-07-06 @ddalle: v1.1; instance method

get_plt_file(stem: str = 'tec_boundary')

Get most recent boundary plt file and its metadata

Call:
>>> fplt, n, i0, i1 = runner.get_plt_file()
>>> fplt, n, i0, i1 = runner.get_plt_file(stem)
Inputs:
runner: CaseRunner

Controller to run one case of solver

Outputs:
fplt: str

Name of plt file

n: int

Number of iterations included

i0: int

First iteration in the averaging

i1: int

Last iteration in the averaging

Versions:
  • 2016-12-20 @ddalle: v1.0 (GetPltFile)

  • 2023-07-06 @ddalle: v1.1; instance method

  • 2024-03-25 @ddalle: v2.0
    • add stem imput

    • search for files w/o _timestep{n} in name

    • include previous runs in n if appropriate

    • more accurate accounting for FUN3D/s iter resets

get_project_baserootname() str

Read namelist and return base project name w/o adapt counter

This would be "pyfun" instead of "pyfun03", for example.

Call:
>>> rname = runner.get_project_baserootname()
Inputs:
runner: CaseRunner

Controller to run one case of solver

Outputs:
rname: str

Project rootname

Versions:
  • 2024-03-22 @ddalle: v1.0

get_project_rootname(j: int | None = None) str

Read namelist and return project namelist

Call:
>>> rname = runner.get_project_rootname(j=None)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: {None} | int

Phase number

Outputs:
rname: str

Project rootname

Versions:
  • 2015-10-19 @ddalle: v1.0

  • 2023-07-05 @ddalle: v1.1; instance method

get_reportfiles() list

Generate list of report files

Call:
>>> filelist = runner.get_reportfiles()
Inputs:
runner: CaseRunner

Controller to run one case of solver

Outputs:
filelist: list[str]

List of files to protect

Verions:
  • 2024-09-25 @ddalle: v1.0

get_restart_file(j: int | None = None) str

Get the most recent .flow file for phase j

Call:
>>> restartfile = runner.get_restart_file(j=None)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: {None} | int

Phase number

Versions:
  • 2024-11-05 @ddalle: v1.0

get_restartfiles() list

Get recent .flow and grid files to protect from clean

Call:
>>> restartfiles = runner.get_restartfiles()
Inputs:
runner: CaseRunner

Controller to run one case of solver

Outputs:
restartfiles: list[str]

List of files not to delete during --clean

Versions:
  • 2024-12-12 @ddalle: v1.0

get_returncode()

Check for errors before continuing

Currently the following checks are performed.

  • Check for NaN residual in the output file

Call:
>>> ierr = runner.get_returncode())
Inputs:
runner: CaseRunner

Controller to run one case of solver

Outputs:
ierr: int

Return code

Versions:
  • 2016-04-18 @ddalle: v1.0

  • 2023-06-02 @ddalle: v1.1; return bool; don’t raise

  • 2023-07-06 @ddalle: v1.2; instance method

  • 2024-06-17 @ddalle: v1.3; was check_error()

  • 2024-07-16 @ddalle: v1.4; use self.returncode

get_stdoutfiles() list

Get list of STDOUT files in order they were run

Call:
>>> runfiles = runner.get_stdoutfiles()
Inputs:
runner: CaseRunner

Controller to run one case of solver

Outputs:
runfiles: list[str]

List of run files, in ascending order

Versions:
  • 2024-08-09 @ddalle: v1.0

get_triq_file(stem: str = 'tec_boundary')

Get name of .triq file, creating it if necessary

Call:
>>> ftriq, n, i0, i1 = runner.get_triq_file(stem)
Inputs:
runner: CaseRunner

Controller to run one case of solver

stem: {"tec_boundary"} | str

Base name of surface/manifold to read

Outputs:
ftriq: str

Name of triq file

n: int

Number of iterations included

i0: int

First iteration in the averaging

i1: int

Last iteration in the averaging

Versions:
  • 2024-12-03 @ddalle: v1.0

get_working_folder() str

Get working folder, ., or Flow/

Call:
>>> fdir = runner.get_working_folder()
Inputs:
runner: CaseRunner

Controller to run one case of solver

Outputs:
fdir: "Flow" | "."

Location (relative to runner.root_dir) where nodet will be run next

Versions:
  • 2024-07-29 @ddalle: v1.0

getx_iter()

Calculate most recent FUN3D iteration

Call:
>>> n = runner.getx_iter()
Inputs:
runner: CaseRunner

Controller to run one case of solver

Outputs:
n: int

Iteration number

Versions:
  • 2015-10-19 @ddalle: v1.0

  • 2016-04-28 @ddalle: v1.1; Flow/ folder

  • 2023-06-27 @ddalle: v2.0; instance method

  • 2024-08-10 @ddalle: v2.1; mostly getx_iter_running()

getx_iter_histfile(fname: str)

Get the most recent iteration number from a history file

Call:
>>> n = runner.getx_iter_histfile(fname)
Inputs:
fname: {"pyfun_hist.dat"} | str

Name of file to read

Outputs:
n: int | None

Most recent iteration number

Versions:
  • 2016-05-04 @ddalle: v1.0; from GetHistoryIter()

  • 2023-06-27 @ddalle: v2.0; rename GetHistoryIterFile

getx_iter_history()

Get the most recent iteration number for a history file

Call:
>>> nh, n = runner.getx_history_iter()
Inputs:
runner: CaseRunner

Controller to run one case of solver

Outputs:
nh: int

Iterations from previous cases before Fun3D deleted history

n: int | None

Most recent iteration number

Versions:
  • 2015-10-20 @ddalle: v1.0

  • 2016-04-28 @ddalle: v1.1; for Flow/ folder

  • 2016-10-29 @ddalle: v1.2; handle Fun3D iteration reset

  • 2017-02-23 @ddalle: v1.3; handle adapt project shift

  • 2023-06-27 @ddalle: v2.0; instance method

getx_iter_running() int | None

Get the most recent iteration number for a running file

Call:
>>> n = runner.getx_iter_running()
Outputs:
runner: CaseRunner

Controller to run one case of solver

n: int | None

Most recent iteration number

Versions:
  • 2015-10-19 @ddalle: v1.0

  • 2016-04-28 @ddalle: v1.1; handle Flow/ folder

  • 2023-05-27 @ddalle: v2.0; instance method

  • 2024-07-29 @ddalle: v3.0
    • use fileutils.readline_reverse()

    • eliminate on_nohistorykept check

    • check for multiple files (was just fun3d.out)

  • 2024-08-09 @ddalle: v3.1; fix run.??.* sorting

  • 2024-08-10 @ddalle: v3.2; check all run.??.* for rstrt

  • 2024-08-21 @ddalle: v3.3; read prev file for ‘off’

getx_phase(n: int)

Determine the phase number based on files in folder

Call:
>>> i = casecntl.GetPhaseNumber(rc)
Inputs:
rc: RunControlOpts

Options interface for run control

Outputs:
i: int

Most appropriate phase number for a restart

Versions:
  • 2014-10-02 @ddalle: v1.0 (cape.pycart)

  • 2015-10-19 @ddalle: v1.0 (GetPhaseNumber)

  • 2023-07-06 @ddalle: v1.1; instance method

getx_restart_iter()

Calculate number of iteration if case should restart

Call:
>>> nr = runner.gets_restart_iter()
Inputs:
runner: CaseRunner

Controller to run one case of solver

Outputs:
nr: int

Restart iteration number

Versions:
  • 2015-10-19 @ddalle: v1.0

  • 2016-04-19 @ddalle: v1.1; check STDIO

  • 2020-01-15 @ddalle: v1.2; sort globs better

  • 2023-07-05 @ddalle: v1.3; moved to instance method

init_post()

Custom initialization for pyfun

Call:
>>> runner.init_post()
Inputs:
runner: CaseRunner

Controller to run one case of solver

Versions:
  • 2023-06-28 @ddalle: v1.0

Link the most recent Tecplot files to fixed file names

Call:
>>> runner.link_plt()
Inputs:
runner: CaseRunner

Controller to run one case of solver

Versions:
  • 2016-10-24 @ddalle: v1.0 (LinkPLT)

  • 2023-07-06 @ddalle: v1.1; instance method

prep_adapt(j: int)

Prepare required nml options for ‘refine/three’ adapt

Call:
>>> runner.prep_adapt(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number

Versions:
  • 2024-09-04 @aburkhea: v1.0

prepare_files(j: int)

Prepare file names appropriate to run phase i of FUN3D

Call:
>>> runner.prepare_files(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number

Versions:
  • 2016-04-14 @ddalle: v1.0

  • 2023-07-06 @ddalle: v1.1; instance method

prepare_warmstart()

Process WarmStart settings and copy files if appropriate

Call:
>>> warmstart = runner.prepare_warmstart()
Inputs:
runner: CaseRunner

Controller to run one case of solver

Outputs:
warmstart: True | False

Whether or not case is a valid warm-start

Versions:
  • 2023-03-14 @ddalle: v1.0 (PrepareWarmStart)

  • 2023-07-06 @ddalle: v1.1; instance method

read_mach() float

Read Mach number from namelist file

Call:
>>> mach = runner.get_mach()
Inputs:
runner: CaseRunner

Controller to run one case of solver

key: str

Name of run matrix key to query

f: True | {False}

Option to force re-read

Outputs:
mach: float

Mach number

Versions:
  • 2024-12-03 @ddalle: v1.0

read_namelist(j=None)

Read case namelist file

Call:
>>> nml = runner.read_namelist(j=None)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: {None} | int

Phase number

Outputs:
nml: cape.pyfun.namelist.Namelist

Namelist interface

Versions:
  • 2015-10-19 @ddalle: v1.0

  • 2023-06-27 @ddalle: v2.0; instance method

run_aflr3_fun3d(j: int)

Create volume mesh using aflr3

This version is customized for FUN3D in order to take a single argument.

Call:
>>> runner.run_aflr3_fun3d(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number

Versions:
  • 2024-08-22 @ddalle: v1.0

run_intersect_fun3d(j: int)

Run intersect to combine surface triangulations

This version is customized for FUN3D in order to take a single argument.

Call:
>>> runner.run_intersect_fun3d(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number

See also:
Versions:
  • 2024-08-22 @ddalle: v1.0

run_nodet(j: int)

Run nodet, the main FUN3D executable

Call:
>>> runner.run_nodet(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number

Versions:
  • 2024-08-23 @ddalle: v1.0

run_nodet_adapt(j: int)

Run Fun3D nodet with adaptation for refine/one

Call:
>>> runner.prepare_files(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number

Versions:
  • 2023-07-12 @jmeeroff: v1.0; from run_phase

run_phase(j: int)

Run one phase using appropriate commands

Call:
>>> runner.run_phase(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number

Versions:
  • 2016-04-13 @ddalle: v1.0 (RunPhase())

  • 2023-06-02 @ddalle: v2.0

  • 2023-06-27 @ddalle: v3.0, instance method

  • 2024-08-23 @ddalle: v3.1; toward simple run_phase()

run_refine_distance(j: int)

Run refine distance to create distances reqd for adaptation

Call:
>>> runner.prepare_files(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number

Versions:
  • 2024-06-07 @aburkhea: v1.0; from run_phase

run_refine_loop(j: int)

Run refine loop to adapt grid to target complexity

Call:
>>> runner.prepare_files(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number

Versions:
  • 2024-06-07 @aburkhea: v1.0; from run_phase

run_refine_translate(j: int)

Run refine transalte to create input meshb file for adaptation

Call:
>>> runner.prepare_files(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number

Versions:
  • 2023-07-17 @jmeeroff: v1.0; from run_phase

run_verify_fun3d(j: int)

Run verify to check triangulation if appropriate

This version is customized for FUN3D in order to take a single argument.

Call:
>>> runner.run_verify_fun3d(j)
Inputs:
runner: CaseRunner

Controller to run one case of solver

j: int

Phase number

Versions:
  • 2024-08-22 @ddalle: v1.0

set_restart_iter(n=None)

Set a given check file as the restart point

Call:
>>> runner.set_restart_iter(n=None)
Inputs:
rc: RunControlOpts

Run control options

n: {None} int

Restart iteration number, defaults to latest available

Versions:
  • 2014-10-02 @ddalle: v1.0 (SetRestartIter)

  • 2023-03-14 @ddalle: v1.1; add WarmStart

  • 2023-07-06 @ddalle: v1.2; instance method

cape.pyfun.casecntl.GetFromGlob(fglb, fname=None)

Find the most recently edited file matching a glob

Call:
>>> fname = casecntl.GetFromGlob(fglb, fname=None)
>>> fname = casecntl.GetFromGlob(fglbs, fname=None)
Inputs:
fglb: str

Glob for targeted file names

fglbs: list[str]

Multiple glob file name patterns

fname: {None} | str

Optional alternate file name to consider

Outputs:
fbest: str

Name of file matching glob that was most recently modified

Versions:
  • 2016-12-19 @ddalle: v1.0

  • 2023-02-03 @ddalle: v1.1; add fname input

  • 2023-03-26 @ddalle: v1.2; multiple fglbs

  • 2024-06-21 @ddalle: v1.3; disallow links to match globs

cape.pyfun.casecntl.GetPltFile()

Get most recent boundary plt file and its metadata

Call:
>>> fplt, n, i0, i1 = GetPltFile()
Outputs:
fplt: str

Name of plt file

n: int

Number of iterations included

i0: int

First iteration in the averaging

i1: int

Last iteration in the averaging

Versions:
  • 2016-12-20 @ddalle: v1.0 (GetPltFile)

  • 2023-07-06 @ddalle: v1.1; use CaseRunner

cape.pyfun.casecntl.GetTriqFile()

Get (create) most recent boundary triq file and its metadata

Call:
>>> ftriq, n, i0, i1 = GetTriqFile()
Outputs:
ftriq: str

Name of triq file

n: int

Number of iterations included

i0: int

First iteration in the averaging

i1: int

Last iteration in the averaging

Versions:
  • 2024-12-03 @ddalle: v1.0

cape.pyfun.casecntl.LinkFromGlob(fname, fglb)

Link the most recent file to a generic Tecplot file name

Call:
>>> casecntl.LinkFromGlob(fname, fglb)
>>> casecntl.LinkFromGlob(fname, fglbs)
Inputs:
fname: str

Name of unmarked file, like Components.i.plt

fglb: str

Glob for marked file names

fglbs: list[str]

Multiple glob file name patterns

Versions:
  • 2016-10-24 @ddalle: v1.0

  • 2023-03-26 @ddalle: v1.1; multiple fglbs

cape.pyfun.casecntl.LinkPLT()

Link the most recent Tecplot files to fixed file names

Call:
>>> LinkPLT()
Versions:
  • 2016-10-24 @ddalle: v1.0

  • 2023-07-06 @ddalle: v1.1; use CaseRunner

cape.pyfun.casecntl.run_fun3d()

Setup and run the appropriate FUN3D command

Call:
>>> run_fun3d()
Versions:
  • 2015-10-19 @ddalle: v1.0

  • 2016-04-05 @ddalle: v1.1; add AFLR3 hook

  • 2023-07-06 @ddalle: v2.0; use CaseRunner