cape.pylch.varsfile: Interface for Loci/CHEM .vars files

This module provides the class VarsFile that reads, modifies, and writes instances of the Loci/CHEM primary input file with the extension .vars.

class cape.pylch.varsfile.VFileFunction(a, name: str)

Section for reading “functions” marked by regular parentheses

class cape.pylch.varsfile.VFileList(a=None)

Section for reading subsections marked by angle-brackets

class cape.pylch.varsfile.VFileSubsec(a: str | dict | None = None)

Section for reading subsections marked by angle-brackets

Call:
>>> sec = VFileSubsec(a=None)
>>> sec = VFileSubsec(fp)
Inputs:
a: {None} | dict

Dictionary to inherit information from

fp: IOBase

File to read subsection from

Outputs:
sec: VFileSubsec

Vars file subsection instance

class cape.pylch.varsfile.VarsFile(*args, **kw)
apply_dict(d: dict)

Apply a dict of settings simultaneously

Call:
>>> opts.apply_dict(d)
Inputs:
opts: VarsFile

Chem .vars file interface

d: dict

Dictionary of options to set

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

find_function(name: str, nmax: int | None = None) dict

Find function(s) by name within .vars file

Call:
>>> funcs = opts.find_function(name, nmax=None)
Inputs:
opts: VarsFile

Chem .vars file interface

name: str

Name of function to find

nmax: {None} | int

Maximum number of times to find name functions

Outputs:
funcs: dict

Each instance of name function found; key of each item says where the function was located w/i data

Versions:
  • 2024-02-24 @ddalle: v1.0

get_alpha(name: str = 'farfield', comp: str | None = None) float | None

Get current angle of attack for one BC, in degrees

Call:
>>> m = opts.get_alpha(name="farfield", comp=None)
Inputs:
opts: VarsFile

Chem .vars file interface

name: {"farfield"} | str

Name of function to find

comp: {None} | str

Optional name of component to query

Outputs:
a: float | None

Angle of attack [deg]

Versions:
  • 2024-10-21 @ddalle: v1.0

get_beta(name: str = 'farfield', comp: str | None = None) float | None

Get current angle of attack for one BC, in degrees

Call:
>>> m = opts.get_beta(name="farfield", comp=None)
Inputs:
opts: VarsFile

Chem .vars file interface

name: {"farfield"} | str

Name of function to find

comp: {None} | str

Optional name of component to query

Outputs:
b: float | None

Sideslip angle [deg]

Versions:
  • 2024-10-21 @ddalle: v1.0

get_iter() int | None

Get number of iterations from stop_iter setting

Call:
>>> niter = opts.get_iter()
Inputs:
opts: VarsFile

Chem .vars file interface

Outputs:
niter: int

Number of iterations to run

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

get_mach(name: str = 'farfield', comp: str | None = None) float | None

Get current Mach number, usually from “farifled” BC

Call:
>>> m = opts.get_mach(name="farfield", comp=None)
Inputs:
opts: VarsFile

Chem .vars file interface

name: {"farfield"} | str

Name of function to find

comp: {None} | str

Optional name of component to query

Outputs:
m: float | None

Mach number from first farfield() function, if any

Versions:
  • 2024-02-26 @ddalle: v1.0

  • 2024-10-21 @ddalle: v2.0

get_rho(name: str = 'farfield', comp: str | None = None) float | None

Get current density, usually from “farifled” BC

Call:
>>> rho = opts.get_rho(name="farfield", comp=None)
Inputs:
opts: VarsFile

Chem .vars file interface

name: {"farfield"} | str

Name of function to find

comp: {None} | str

Optional name of component to query

Outputs:
rho: float | None

Density from first name function, if any [kg/m^3]

Versions:
  • 2024-10-21 @ddalle: v1.0

get_temperature(name: str = 'farfield', comp: str | None = None) float | None

Get current density, usually from “farifled” BC

Call:
>>> t = opts.get_temperature(name="farfield", comp=None)
Inputs:
opts: VarsFile

Chem .vars file interface

name: {"farfield"} | str

Name of function to find

comp: {None} | str

Optional name of component to query

Outputs:
t: float | None

Temperature from first name function, if any [K]

Versions:
  • 2024-10-21 @ddalle: v1.0

read_varsfile(fname: str)

Read a Chem .vars file

Call:
>>> opts.read_varsfile(fname)
Inputs:
fname: str

Name of file to read

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

set_alpha(a: float, name: str = 'farfield', comp: str | None = None)

Set the angle of attack for one or more farfield condition

Call:
>>> opts.set_alpha(a, name="farfield")
Inputs:
opts: VarsFile

Chem .vars file interface

a: float | None

Angle of attack [deg]

name: {"farfield"} | str

Name of function to find

comp: {None} | str

Optional name of component to which to apply BC

Versions:
  • 2024-02-26 @ddalle: v1.0

  • 2024-10-21 @ddalle: v2.0

set_beta(b: float, name: str = 'farfield', comp: str | None = None)

Set the sideslip angle for one or more farfield condition

Call:
>>> opts.set_alpha(a, name="farfield")
Inputs:
opts: VarsFile

Chem .vars file interface

b: float | None

Sideslip angle [deg]

name: {"farfield"} | str

Name of function to find

comp: {None} | str

Optional name of component to which to apply BC

Versions:
  • 2024-10-21 @ddalle: v1.0

set_iter(niter: int)

Set number of iterations using stop_iter setting

Call:
>>> opts.set_iter(niter)
Inputs:
opts: VarsFile

Chem .vars file interface

niter: int

Number of iterations to run

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

set_mach(m: float, name: str = 'farfield', comp: str | None = None)

Set the Mach number for one or more farfield condition

Call:
>>> opts.set_mach(m, name="farfield")
Inputs:
opts: VarsFile

Chem .vars file interface

m: float | None

Mach number from first farfield() function, if any

name: {"farfield"} | str

Name of function to find

comp: {None} | str

Optional name of component to which to apply BC

Versions:
  • 2024-02-26 @ddalle: v1.0

  • 2024-10-21 @ddalle: v2.0

set_rho(rho: float, name: str = 'farfield', comp: str | None = None)

Set the Mach number for one or more farfield condition

Call:
>>> opts.set_rho(rho, name="farfield")
Inputs:
opts: VarsFile

Chem .vars file interface

rho: float | None

Density to set [kg/m^3]

name: {"farfield"} | str

Name of function to find

comp: {None} | str

Optional name of component to which to apply BC

Versions:
  • 2024-10-21 @ddalle: v1.0

set_temperature(t: float, name: str = 'farfield', comp: str | None = None)

Set the Mach number for one or more farfield condition

Call:
>>> opts.set_temperature(t, name="farfield")
Inputs:
opts: VarsFile

Chem .vars file interface

t: float | None

Temperature [K]

name: {"farfield"} | str

Name of function to find

comp: {None} | str

Optional name of component to which to apply BC

Versions:
  • 2024-10-21 @ddalle: v1.0

write(fname: str | None = None)

Write contents to .vars file

Call:
>>> opts.write(fname=None)
Inputs:
opts: VarsFile

Chem .vars file interface

fname: {None} | str

File name to write

Versions:
  • 2024-02-24 @ddalle: v1.0

cape.pylch.varsfile.assert_nextstr(c: str, target: str, desc=None)

Check if a string matches a specified target

Call:
>>> assert_nextstr(c, target, desc=None)
Inputs:
c: str

Any string

target: str

Target value for c

desc: {None} | str

Optional description for what is being tested

Raises:
Versions:
  • 2024-02-23 @ddalle: v1.0

cape.pylch.varsfile.assert_regex(c: str, regex, desc=None)

Check if a string matches a compiled regular expression

Call:
>>> assert_regex(c, regex, desc=None)
Inputs:
c: str

Any string

regex: re.Pattern

A compiled regular expression

desc: {None} | str

Optional description for what is being tested

Raises:
Versions:
  • 2024-02-23 @ddalle: v1.0

cape.pylch.varsfile.get_magnitude(v) float

Get magnitude of a scalar, polar() function, or vector

Call:
>>> a = get_magnitude(v)
Inputs:
v: float | list | dict

Suitable Loci/CHEM “vector”

Outputs:
a: float

Magnitude, first arg of polar() function

Versions:
  • 2024-02-26 @ddalle: v1.0

cape.pylch.varsfile.set_func_arg(func: dict | None, funcname: str, j: int, v: Any, args: list | None = None) dict

Set an argument value by position

Call:
>>> newfunc = set_func_arg(func, funcname, j, v, args=None)
Inputs:
func: None | dict

Original “function” specification

funcname: str

Name of function

j: int

Position of argument to set

v: object

Value of object to set

args: {None} | list

Default list of function args if not present

Outputs:
newfunc: dict

Modified func, in-place unless func is None

cape.pylch.varsfile.set_polar_arg(func: dict | None, j: int, v: Any, args: list | None = None) dict

Set an argument value by position

Call:
>>> newfunc = set_polar_arg(func, j, v, args=None)
Inputs:
func: None | dict

Original “function” specification

j: int

Position of argument to set

v: object

Value of object to set

args: {None} | list

Default list of function args if not present

Outputs:
newfunc: dict

Modified func, in-place unless func is None

cape.pylch.varsfile.to_text(val: object) str

Convert appropriate Python value to .vars file text

Call:
>>> txt = to_text(val)
Inputs:
val: object

One of several appropriate values for .vars files

Outputs:
txt: str

Converted text

Versions:
  • 2024-02-24 @ddalle: v1.0

cape.pylch.varsfile.to_val(txt: str)

Convert .vars file text to a Python value

This only applies to single entries and does not parse lists, etc.

Call:
>>> v = to_val(txt)
Inputs:
txt: str

Any valid text for a single value in a .vars file

Outputs:
v: str | int | float

Interpreted value

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