oftest

class oftest.utils.Case_modifiers(case_modifiers: Dict, dir_name: str, meta_data: Optional[Dict] = {})[source]

Bases: object

modifes and openfoam case by modifying the case files :Parameters: * case_modifiers (Dict) – dict format filename : list of (keyword , value)

  • e.g.

  • {

    “system/controlDict”: [ (“stopAt”,”writeNow”),

    (“endTime”,10.1) ],

    “constant/transportProperties”: [ (“water/transportModel”,”Newtonian”),

    (“air/transportModel”,”Newtonian”) ]

  • }

  • subdicts are seperated by /

  • dir_name (str) – dir of openfoam case

  • meta_data (Optional[Dict], optional) – stores additional information. Defaults to {}.

add_mod(file_path: str, key: str, val: Any)[source]

add new file modification

Parameters
  • file_path (str) – path to file

  • key (str) – keyword

  • val (Any) – value

revert_change()[source]

revert changes

update_case()[source]

update the based on the specified modifiers

class oftest.utils.Parser(filename: str)[source]

Bases: object

abstract parser class

set(keyword: str)[source]
value(keyword: str)[source]
writeFile()[source]
class oftest.utils.Pyfoam_parser(filename: str)[source]

Bases: oftest.utils.Parser

pyfoam based openfoam dict parser that modifes a file

Parameters

Parser ([type]) – abstract class

set(keyword: str, value: Any)[source]

set value

Parameters
  • keyword (str) – keyword as string e.g. application

  • or in case of a nested dictionary dict1/subDict1/keyword1

  • value (Any) – new value

value(keyword: str)[source]

get value of key word

Parameters
  • keyword (str) – keyword as string e.g. application

  • or in case of a nested dictionary dict1/subDict1/keyword1

Returns

[type] – return value

writeFile()[source]
oftest.utils.base_dir()str[source]

directory of curren test

Returns

str – directory path of the test

oftest.utils.check_type(c_mod)oftest.utils.Case_modifiers[source]
oftest.utils.clean_case(request)[source]

cleans case by running Allcean

Yields

[type] – case modifier

oftest.utils.modify_case(request)[source]

modifies the case without running it

The case can be modified by passing the Case_modifiers class

Yields

[Case_modifiers] – Case_modifiers information

oftest.utils.path_log(app_name: str = '')str[source]

path of the log file

reads controlDict to get application if app_name not specified

Parameters

app_name (str, optional) – name of the application. Defaults to read controlDict to get application.

Returns

str – path to the log file

oftest.utils.run_case(request)[source]

fixture that runs case by exectuting a bash script

The case can be modified by passing the Case_modifiers class

Default name is script name Allrun can be modified by storing the script name in the meta_data of the Case_modifiers:

c_mod.meta_data[“script”] = “SomeScriptName”

Yields

[Case_modifiers] – Case_modifiers information

oftest.utils.run_reset_case(request)[source]

fixture that runs case by exectuting a bash script and reset the case by calling Allclean

The case can be modified by passing the Case_modifiers class

Default name is script name Allrun can be modified by storing the script name in the meta_data of the Case_modifiers:

c_mod.meta_data[“script”] = “SomeScriptName”

Yields

[Case_modifiers] – Case_modifiers information

oftest.load_data.case_status(log: str, nbytes: int = 8192)str[source]

read the end of the log file and return the status by reading the logfile backwards

completed -> case finished error -> fatal error running -> running

Parameters
  • log (str) – path to log file

  • nbytes (int, optional) – number of bytes to read. Defaults to 8*1024.

Returns

str – return status

oftest.load_data.head_log(log: str, N: int = 10)List[str][source]

read first N lines of log file

Parameters
  • log (str) – path to log file

  • N (int, optional) – number of lines to read. Defaults to 10.

Returns

List[str] – list of lines read

oftest.load_data.read_csv_geoField(filename: str)pandas.core.frame.DataFrame[source]

reads csv geofile create by the writeCsvGeoField

Parameters

filename (str) – path to csv file

Returns

pd.DataFrame – geo field in csv format

oftest.load_data.read_functionObject(filename: str)pandas.core.frame.DataFrame[source]

read function object file and converts it to a pandas dataframe

Parameters

filename (str) – path to file e.g. (postProcessing/forces/0/force.dat)

Returns

pd.DataFrame – returns the created dataframe

oftest.load_data.run_time(log: str, nbytes: int = 8192)List[float][source]

return execution and clocktime from log file by reading the logfile backwards

Parameters
  • log (str) – path to log file

  • nbytes (int, optional) – number of bytes to read. Defaults to 8*1024.

Returns

List[float] – ExecutionTime, clockTime

oftest.load_data.tail_log(log: str, nbytes: int = 8192)List[str][source]

read the end of the log file

Parameters
  • log (str) – path of the log file

  • nbytes (int, optional) – number of bytes to read. Defaults to 1024.

Returns

List[str] – list of lines read