carputils
Doxygen code documentation for the python framework controlling openCARP
Classes | Functions | Variables
carputils.tools Namespace Reference

Functions for creating run scripts for openCARP simulations and other tools. More...

Classes

class  MaxNPAction
 Class to check that the maximum number of processes is not exceeded. More...
 
class  PrintAction
 Class to print a unformatted message like '–help' and exit. More...
 

Functions

def basic_parser (showdefault=True, overwrite_behaviour=OVERWRITE_BEHAVIOUR[0], formatter_cls=None)
 
def standard_parser (showdefault=True)
 Generate a standard argument parser for collection of common options. More...
 
def basic_job_id (args)
 Generate default job ID. More...
 
def basicexample (parser=basic_parser, job_id=basic_job_id, summary=True, temp=False)
 Generate a decorator for openCARP example run function. More...
 
def carp_job_id (args)
 Generate default job ID. More...
 
def carpexample (parser=standard_parser, job_id=carp_job_id, meshdir=None, clean_pattern=r'^(\d{4}-\d{2}-\d{2})|(mesh)', simple=False, summary=True, temp=False, mkdir=True)
 Generate a decorator for openCARP example run function. More...
 
def carp_cmd (parfile=None, mech_symmetric=False)
 Construct the basic openCARP command line. More...
 
def list_to_string (pl)
 
def gen_physics_opts (ExtraTags=None, IntraTags=None, EikonalTags=None, MechTags=None, FluidTags=None, EMI=False)
 
def simfile_path (path, mesh=False)
 Deprecated alias for bundle_include. More...
 
def bundle_include (path, mesh=False, caller_name='bundle_include')
 Use this function to indicate that the file given as an argument has to be included in the experiment bundles. More...
 
def resolve_bundle_include (path, mesh)
 Helper function for copying files marked with bundle_include within the bundle. More...
 

Variables

 OVERWRITE_BEHAVIOUR = tuple(clean.OVERWRITE_MODES.keys())
 
 maxnp = None
 

Detailed Description

Functions for creating run scripts for openCARP simulations and other tools.

Function Documentation

◆ basic_job_id()

def carputils.tools.basic_job_id (   args)

Generate default job ID.

◆ basic_parser()

def carputils.tools.basic_parser (   showdefault = True,
  overwrite_behaviour = OVERWRITE_BEHAVIOUR[0],
  formatter_cls = None 
)

◆ basicexample()

def carputils.tools.basicexample (   parser = basic_parser,
  job_id = basic_job_id,
  summary = True,
  temp = False 
)

Generate a decorator for openCARP example run function.

The decorator sets up sensible defaults for argv and sequence for an openCARP example's run function, and executes the command sequence on exit, where required.

◆ bundle_include()

def carputils.tools.bundle_include (   path,
  mesh = False,
  caller_name = 'bundle_include' 
)

Use this function to indicate that the file given as an argument has to be included in the experiment bundles.

The value returned by this function is the same as the input 'path' value. This function should encapsulate the paths to external files required to run the experiment (and that should consequently be included in the experiment bundles). If the command line option –bundle is not set, the function is passive and simply returns the 'path' argument. If the command line option –bundle is set, the function will in addition:

  • Copy the file given as an argument in the bundle.
  • Modify the path in the run script within the bundle, so that it refers to the file copied in the bundle.

The mesh option indicates if the file given by the path is a mesh file or not. Mesh files are copied in a dedicated subfolder within the bundle.

Warning. For now, this function call can't be split over multiple lines, i.e.

>>> bundle_include('/path/to/file')
def bundle_include(path, mesh=False, caller_name='bundle_include')
Use this function to indicate that the file given as an argument has to be included in the experiment...
Definition: tools.py:752

is allowed, but

>>> '/path/to/file'
>>> )

is not allowed. This is due to the way the function parses and modifies the run script.

Parameters
pathPath to a file that should be included in bundles.
meshif True, the file is labeled as a mesh file.
caller_nameshould not be modified by the user. Used for retrocompatibility with the old function name.
Returns
The path parameter given as an input.
Exceptions
SyntaxErrorif the function call is split over multiple lines.

◆ carp_cmd()

def carputils.tools.carp_cmd (   parfile = None,
  mech_symmetric = False 
)

Construct the basic openCARP command line.

Constructs a list of command line arguments. This will automatically include the loading of the correct options for the specified solvers.

Parameters
parfilestr, optional The openCARP parameter file to be used, if any.
Returns
list of str The initial openCARP command line.

◆ carp_job_id()

def carputils.tools.carp_job_id (   args)

Generate default job ID.

◆ carpexample()

def carputils.tools.carpexample (   parser = standard_parser,
  job_id = carp_job_id,
  meshdir = None,
  clean_pattern = r'^(\d{4}-\d{2}-\d{2})|(mesh)',
  simple = False,
  summary = True,
  temp = False,
  mkdir = True 
)

Generate a decorator for openCARP example run function.

The decorator sets up sensible defaults for argv and sequence for a openCARP example's run function, and executes the command sequence on exit, where required.

◆ gen_physics_opts()

def carputils.tools.gen_physics_opts (   ExtraTags = None,
  IntraTags = None,
  EikonalTags = None,
  MechTags = None,
  FluidTags = None,
  EMI = False 
)

◆ list_to_string()

def carputils.tools.list_to_string (   pl)

◆ resolve_bundle_include()

def carputils.tools.resolve_bundle_include (   path,
  mesh 
)

Helper function for copying files marked with bundle_include within the bundle.

This function is not meant to be used directly by the user.

This function:

  • resolves the relative path where the file given as an argument will be located within the bundle,
  • copies the file within the bundle,
  • returns the path to the file within the bundle
Parameters
pathpath to a file (filename can be given without its extension)
meshset to true if the path is leading to a mesh file
Returns
path to the file within the bundle

◆ simfile_path()

def carputils.tools.simfile_path (   path,
  mesh = False 
)

Deprecated alias for bundle_include.

◆ standard_parser()

def carputils.tools.standard_parser (   showdefault = True)

Generate a standard argument parser for collection of common options.

Returns ArgumentParser The parser object from the python standard library argparse module. See the online documentation <https://docs.python.org/3/library/argparse.html>_ for information on adding additional options to this parser in a run script. To actually parse the command line, use the parse_args method of the returned parser object.

Variable Documentation

◆ maxnp

carputils.tools.maxnp = None

◆ OVERWRITE_BEHAVIOUR

carputils.tools.OVERWRITE_BEHAVIOUR = tuple(clean.OVERWRITE_MODES.keys())