ogstools.ogs6py.project module#
ogs6py is a python-API for the OpenGeoSys finite element software. Its main functionalities include creating and altering OGS6 input files as well as executing OGS.
- class ogstools.ogs6py.project.Project[source]#
Bases:
StorageBaseClass for handling an OGS6 project.
In this class everything for an OGS6 project can be specified.
Create a new Project instance.
- Parameters:
input_file (
str|Path|None) – Filename of the input project fileoutput_file (
str|Path|None) – Filename of the output project fileoutput_dir (
str|Path) – Directory of the simulation outputlogfile (
str|Path) – Filename into which the log is writtenverbose (
bool) – If True, show verbose output
- Optional Keyword Arguments:
- OMP_NUM_THREADS: int, sets the environment variable before OGS
execution to restrict number of OMP Threads
- OGS_ASM_THREADS: int, sets the environment variable before OGS
execution to restrict number of OMP Threads
- __init__(input_file=None, output_file=None, output_dir=Path(), logfile='out.log', verbose=False, xml_string=None, id=None, **kwargs)[source]#
Create a new Project instance.
- Parameters:
input_file (
str|Path|None) – Filename of the input project fileoutput_file (
str|Path|None) – Filename of the output project fileoutput_dir (
str|Path) – Directory of the simulation outputlogfile (
str|Path) – Filename into which the log is writtenverbose (
bool) – If True, show verbose output
- Optional Keyword Arguments:
- OMP_NUM_THREADS: int, sets the environment variable before OGS
execution to restrict number of OMP Threads
- OGS_ASM_THREADS: int, sets the environment variable before OGS
execution to restrict number of OMP Threads
- classmethod from_id(project_id)[source]#
Load Project from the user storage path using its ID. StorageBase.Userpath must be set.
- Parameters:
project_id (
str) – The unique ID of the Project to load.- Return type:
Self- Returns:
A Project instance restored from disk.
- static dependencies_of_file(input_file, mesh_dir=None, check=False, include_meshes=True, include_python_file=True, include_xml_includes=True)[source]#
Searches a (partial) project file for included files (e.g. xml snippets, meshes (vtu,gml), python scripts) Can be used before constructing a Project object (static function).
- Parameters:
- Return type:
- Returns:
A list of dependency file paths (order-preserving, de-duplicated).
- Raises:
AssertionError – If check=True and at least one referenced file is missing.
- add_element(parent_xpath='./', tag=None, text=None, attrib_list=None, attrib_value_list=None)[source]#
General method to add an Entry.
An element is a single tag containing ‘text’, attributes and anttribute values.
- add_block(blocktag, block_attrib=None, parent_xpath='./', taglist=None, textlist=None)[source]#
General method to add a Block.
A block consists of an enclosing tag containing a number of subtags retaining a key-value structure.
- Parameters:
- Return type:
- replace_text(value, xpath='.', occurrence=-1)[source]#
General method for replacing text between opening and closing tags.
- replace_block_by_include(xpath='./', filename='include.xml', occurrence=0)[source]#
General method for replacing a block by an include.
- replace_parameter(name='', parametertype='', taglist=None, textlist=None)[source]#
Replacing parametertypes and values.
- replace_phase_property_value(mediumid=0, phase='AqueousLiquid', component=None, name='', value=0, propertytype='Constant', valuetag='value')[source]#
Replaces properties in medium phases.
- Parameters:
- Return type:
- replace_medium_property_value(mediumid=0, name='', value=0, propertytype='Constant', valuetag='value')[source]#
Replaces properties in medium (not belonging to any phase).
- set(**args)[source]#
Sets directly a uniquely defined property. List of properties is given in the dictionary below.
- Return type:
- run_model(logfile=Path('out.log'), path=None, args=None, container_path=None, wrapper=None, write_logs=True, background=False)[source]#
Command to run OGS.
Runs OGS with the project file specified as output_file.
- Parameters:
logfile (
Path|None) – Name of the file to write STDOUT of ogspath (
Path|None) – Path of the directory in which the ogs executable can be found. Ifcontainer_pathis given: Path to the directory in which the Apptainer executable can be found.args (
Any|None) – additional arguments for the ogs executablecontainer_path (
Path|str|None) – Path of the OGS container file.write_logs (
bool) – set False to omit loggingwrite_prj_to_pvd – write the prj file as a comment in the pvd
background (
bool) – Run the simulation in a background process
- Return type:
- save(target=None, overwrite=None, dry_run=False, archive=False, keep_includes=False, id=None)[source]#
Saves the project file and referenced files (except meshes)
- Parameters:
target (
Path|str|None) – Optional path to the project folder. If None, a temporary folder will be used.overwrite (
bool|None) – If True, existing prj file(s) will be overwritten. If False, an error is raised if any file already exists.dry_run (
bool) – If True: Writes no files, but returns the list of files expected to be created If False: Writes files and returns the list of created files.archive (
bool) – If True: The folder specified by path contains no symlinks. It copies all referenced data (which might take time and space).id (
str|None) – Optional identifier. Mutually exclusive with target.
- Return type:
- Returns:
A list of Paths pointing to the saved prj file(s)
- property_dataframe(mediamapping=None)[source]#
Returns a dataframe containing most properties defined in the Material Property (MPL) section of the input file.
- write_property_latextable(latexfile=Path('property_dataframe.tex'), mediamapping=None, float_format='{:.2e}')[source]#
Write material properties to disc as latex table.
- meshpaths(mesh_dir=None)[source]#
Returns the filepaths to the given meshes in the Project.
This does not include meshes defined via a .gml file.
- constraints()[source]#
Creates a dict of boundary conditions and source terms.
Structured in the following way: {meshname: {process_variable_name: [constraint_data]}}