ogs5py.fileclasses.ic

Class for the ogs INITIAL_CONDITION file.

File Classes

IC(**OGS_Config) Class for the ogs INITIAL_CONDITION file.
RFR([variables, data, units, headers, name, …]) Class for the ogs RESTART file, if the DIS_TYPE in IC is set to RESTART.

class IC(**OGS_Config)[source]

Bases: ogs5py.fileclasses.base.BlockFile

Class for the ogs INITIAL_CONDITION file.

Parameters:
  • task_root (str, optional) – Path to the destiny model folder. Default: cwd+”ogs5model”
  • task_id (str, optional) – Name for the ogs task. Default: “model”

Notes

Main-Keywords (#):
  • INITIAL_CONDITION
Sub-Keywords ($) per Main-Keyword:
  • INITIAL_CONDITION

    • PCS_TYPE
    • PRIMARY_VARIABLE
    • COMP_NAME
    • STORE_VALUES
    • DIS_TYPE
    • GEO_TYPE
Standard block:
PCS_TYPE:“GROUNDWATER_FLOW”
PRIMARY_VARIABLE:
 “HEAD”
GEO_TYPE:“DOMAIN”
DIS_TYPE:[“CONSTANT”, 0.0]
Keyword documentation:
https://ogs5-keywords.netlify.com/ogs/wiki/public/doc-auto/by_ext/ic
Reading routines:
https://github.com/ufz/ogs5/blob/master/FEM/rf_ic_new.cpp#L222

See also

add_block

Attributes:
block_no

Number of blocks in the file.

file_name

str: base name of the file with extension.

file_path

str: save path of the file.

force_writing

bool: state if the file is written even if empty.

is_empty

State if the OGS file is empty.

name

str: name of the file without extension.

Methods

add_block(self[, index, main_key]) Add a new Block to the actual file.
add_content(self, content[, main_index, …]) Add single-line content to the actual file.
add_copy_link(self, path[, symlink]) Add a link to copy a file instead of writing.
add_main_keyword(self, key[, main_index]) Add a new main keyword (#key) to the actual file.
add_multi_content(self, content[, …]) Add multiple content to the actual file.
add_sub_keyword(self, key[, main_index, …]) Add a new sub keyword ($key) to the actual file.
append_to_block(self[, index]) Append data to an existing Block in the actual file.
check(self[, verbose]) Check if the given file is valid.
del_block(self[, index, del_all]) Delete a block by its index.
del_content(self[, main_index, sub_index, …]) Delete content by its position.
del_copy_link(self) Remove a former given link to an external file.
del_main_keyword(self[, main_index, del_all]) Delete a main keyword (#key) by its position.
del_sub_keyword(self[, main_index, …]) Delete a sub keyword ($key) by its position.
get_block(self[, index, as_dict]) Get a Block from the actual file.
get_block_no(self) Get the number of blocks in the file.
get_file_type(self) Get the OGS file class name.
get_multi_keys(self[, index]) State if a block has a unique set of sub keywords.
is_block_unique(self[, index]) State if a block has a unique set of sub keywords.
read_file(self, path[, encoding, verbose]) Read an existing OGS input file.
reset(self) Delete every content.
save(self, path, \*\*kwargs) Save the actual OGS input file in the given path.
update_block(self[, index, main_key]) Update a Block from the actual file.
write_file(self) Write the actual OGS input file to the given folder.
add_block(self, index=None, main_key=None, **block)

Add a new Block to the actual file.

Keywords are the sub keywords of the actual file type:

#MAIN_KEY
$SUBKEY1
content1 …
$SUBKEY2
content2 …

which looks like the following:

FILE.add_block(SUBKEY1=content1, SUBKEY2=content2)

Parameters:
  • index (int or None, optional) – Positional index, where to insert the given Block. As default, it will be added at the end. Default: None.
  • main_key (string, optional) – Main keyword of the block that should be added (see: MKEYS) Default: the first main keyword of the file-type
  • **block (keyword dict) – here the dict-keywords are the ogs-subkeywords and the value is the content that should be added with this ogs-subkeyword If a block should contain content directly connected to a main keyword, use this main keyword as input-keyword and the content as value: SUBKEY=content
add_content(self, content, main_index=None, sub_index=None, line_index=None)

Add single-line content to the actual file.

Parameters:
  • content (list) – list containing one line of content given as a list of single statements
  • main_index (int, optional) – index of the corresponding main keyword where the sub keyword should be added. As default, the last main keyword is taken.
  • sub_index (int, optional) – index of the corresponding sub keyword where the content should be added. As default, the last sub keyword is taken.
  • line_index (int, optional) – position, where the new line of content should be added between the existing ones. As default, it is placed at the end.

Notes

There needs to be at least one main keyword, otherwise the content is not added.

If no sub keyword is present, a blank one (“”) will be added and the content is then directly connected to the actual main keyword.

Add a link to copy a file instead of writing.

Instead of writing a file, you can give a path to an existing file, that will be copied/linked to the target folder.

Parameters:
  • path (str) – path to the existing file that should be copied
  • symlink (bool, optional) – on UNIX systems it is possible to use a symbolic link to save time if the file is big. Default: False
add_main_keyword(self, key, main_index=None)

Add a new main keyword (#key) to the actual file.

Parameters:
  • key (string) – key name
  • main_index (int, optional) – position, where the new main keyword should be added between the existing ones. As default, it is placed at the end.
add_multi_content(self, content, main_index=None, sub_index=None)

Add multiple content to the actual file.

Parameters:
  • content (list) – list containing lines of content, each given as a list of single statements
  • main_index (int, optional) – index of the corresponding main keyword where the sub keyword should be added. As default, the last main keyword is taken.
  • sub_index (int, optional) – index of the corresponding sub keyword where the content should be added. As default, the last sub keyword is taken.

Notes

There needs to be at least one main keyword, otherwise the content is not added.

The content will be added at the end of the actual subkeyword.

If no sub keyword is present, a blank one (“”) will be added and the content is then directly connected to the actual main keyword.

add_sub_keyword(self, key, main_index=None, sub_index=None)

Add a new sub keyword ($key) to the actual file.

Parameters:
  • key (string) – key name
  • main_index (int, optional) – index of the corresponding main keyword where the sub keyword should be added. As default, the last main keyword is taken.
  • sub_index (int, optional) – position, where the new sub keyword should be added between the existing ones. As default, it is placed at the end.

Notes

There needs to be at least one main keyword, otherwise the subkeyword is not added.

append_to_block(self, index=None, **block)

Append data to an existing Block in the actual file.

Keywords are the sub keywords of the actual file type:

#MAIN_KEY
$SUBKEY1
content1 …
$SUBKEY2
content2 …

which looks like the following:

FILE.append_to_block(SUBKEY1=content1, SUBKEY2=content2)

Parameters:
  • index (int or None, optional) – Positional index, where to insert the given Block. As default, it will be added at the end. Default: None.
  • **block (keyword dict) – here the dict-keywords are the ogs-subkeywords and the value is the content that should be added with this ogs-subkeyword If a block should contain content directly connected to a main keyword, use this main keyword as input-keyword and the content as value: SUBKEY=content
check(self, verbose=True)

Check if the given file is valid.

Parameters:verbose (bool, optional) – Print information for the executed checks. Default: True
Returns:result – Validity of the given file.
Return type:bool
del_block(self, index=None, del_all=False)

Delete a block by its index.

Parameters:
  • index (int or None, optional) – Positional index of the block of interest. As default, the last one is returned. Default: None
  • del_all (bool, optional) – State, if all blocks shall be deleted. Default: False
del_content(self, main_index=-1, sub_index=-1, line_index=-1, del_all=False)

Delete content by its position.

Parameters:
  • main_index (int, optional) – index of the corresponding main keyword where the sub keyword should be deleted. As default, the last main keyword is taken.
  • sub_index (int, optional) – index of the corresponding sub keyword where the content should be deleted. As default, the last sub keyword is taken.
  • line_index (int, optional) – position of the content line, that should be deleted. Default: -1
  • del_all (bool, optional) – State, if all content shall be deleted. Default: False

Remove a former given link to an external file.

del_main_keyword(self, main_index=None, del_all=False)

Delete a main keyword (#key) by its position.

Parameters:
  • main_index (int, optional) – position, which main keyword should be deleted. Default: -1
  • del_all (bool, optional) – State, if all main keywords shall be deleted. Default: False
del_sub_keyword(self, main_index=-1, sub_index=-1, del_all=False)

Delete a sub keyword ($key) by its position.

Parameters:
  • main_index (int, optional) – index of the corresponding main keyword where the sub keyword should be deleted. As default, the last main keyword is taken.
  • pos (int, optional) – position, which sub keyword should be deleted. Default: -1
  • del_all (bool, optional) – State, if all sub keywords shall be deleted. Default: False
get_block(self, index=None, as_dict=True)

Get a Block from the actual file.

Parameters:
  • index (int or None, optional) – Positional index of the block of interest. As default, the last one is returned. Default: None
  • as_dict (bool, optional) – Here you can state of you want the output as a dictionary, which can be used as key-word-arguments for add_block. If False, you get the main-key, a list of sub-keys and a list of content. Default: True
get_block_no(self)

Get the number of blocks in the file.

get_file_type(self)

Get the OGS file class name.

get_multi_keys(self, index=None)

State if a block has a unique set of sub keywords.

is_block_unique(self, index=None)

State if a block has a unique set of sub keywords.

read_file(self, path, encoding=None, verbose=False)

Read an existing OGS input file.

Parameters:
  • path (str) – path to the existing file that should be read
  • encoding (str or None, optional) – encoding of the given file. If None is given, the system standard is used. Default: None
  • verbose (bool, optional) – Print information of the reading process. Default: False
reset(self)

Delete every content.

save(self, path, **kwargs)

Save the actual OGS input file in the given path.

Parameters:
  • path (str) – path to where to file should be saved
  • update (bool, optional) – state if the content should be updated before saving. Default: True
update_block(self, index=None, main_key=None, **block)

Update a Block from the actual file.

Parameters:
  • index (int or None, optional) – Positional index of the block of interest. As default, the last one is used. Default: None
  • main_key (string, optional) – Main keyword of the block that should be updated (see: MKEYS) This shouldn’t be done. Default: None
  • **block (keyword dict) – here the dict-keywords are the ogs-subkeywords and the value is the content that should be added with this ogs-subkeyword If a block should contain content directly connected to a main keyword, use this main keyword as input-keyword and the content as value: SUBKEY=content
write_file(self)

Write the actual OGS input file to the given folder.

Its path is given by “task_root+task_id+file_ext”.

MKEYS = ['INITIAL_CONDITION']
SKEYS = [['PCS_TYPE', 'PRIMARY_VARIABLE', 'COMP_NAME', 'STORE_VALUES', 'DIS_TYPE', 'GEO_TYPE']]
STD = {'DIS_TYPE': ['CONSTANT', 0.0], 'GEO_TYPE': 'DOMAIN', 'PCS_TYPE': 'GROUNDWATER_FLOW', 'PRIMARY_VARIABLE': 'HEAD'}
block_no

Number of blocks in the file.

file_name

base name of the file with extension.

Type:str
file_path

save path of the file.

Type:str
force_writing

state if the file is written even if empty.

Type:bool
is_empty

State if the OGS file is empty.

name

name of the file without extension.

Type:str
class RFR(variables=None, data=None, units=None, headers=None, name=None, file_ext='.rfr', task_root=None, task_id='model')[source]

Bases: ogs5py.fileclasses.base.File

Class for the ogs RESTART file, if the DIS_TYPE in IC is set to RESTART.

Parameters:
  • variables (list of str, optional) – List of variable names. Default: None
  • data (numpy.ndarray, optional) – RFR data. 2D array, where the first dimension is the number of variables. Default: None
  • units (list of str, optional) – List of units for the occurring variables. Can be None. OGS5 ignores them anyway. Default: None
  • headers (str or None, optional) – First four lines of the RFR file. If None, a standard header is written. Default: None
  • name (str, optional) – File name for the RFR file. If None, the task_id is used. Default: None
  • file_ext (str, optional) – extension of the file (with leading dot “.rfr”) Default: “.rfr”
  • task_root (str, optional) – Path to the destiny model folder. Default: cwd+”ogs5model”
  • task_id (str, optional) – Name for the ogs task. Default: “model”

Notes

First line (ignored):
  • #0#0#0#1#100000#0… (don’t ask why)
Second line (ignored):
  • 1 1 4 (don’t ask why)
Third line (information about Variables):
  • (No. of Var.) (No of data of 1. Var) (No of data of 2. Var) …
  • 1 1 (example: 1 Variable with 1 component)
  • 2 1 1 (example: 2 Variables with 1 component each)
  • only 1 scalar per Variable allowed (bug in OGS5). See: https://github.com/ufz/ogs5/issues/151
Fourth line (Variable names and units):
  • (Name1), (Unit1), (Name2), (Unit2), …
  • units are ignored
Data (multiple lines):
  • (index) (Var1data1) .. (Var1dataN1) (Var2data1) .. (Var2dataN2) …
Keyword documentation:
https://ogs5-keywords.netlify.com/ogs/wiki/public/doc-auto/by_ext/ic
Reading routines:
https://github.com/ufz/ogs5/blob/master/FEM/rf_ic_new.cpp#L932
Attributes:
data

Data in the RFR file.

file_name

str: base name of the file with extension.

file_path

str: save path of the file.

force_writing

bool: state if the file is written even if empty.

is_empty

State if the OGS file is empty.

name

str: name of the file without extension.

units

List of variable-units in the RFR file.

var_count

Count of variables in the RFR file (line 3).

var_info

Infos about variables and units in the RFR file (line 4).

variables

List of variables in the RFR file.

Methods

add_copy_link(self, path[, symlink]) Add a link to copy a file instead of writing.
check(self[, verbose]) Check if the external geometry definition is valid.
del_copy_link(self) Remove a former given link to an external file.
get_file_type(self) Get the OGS file class name.
read_file(self, path[, encoding, verbose]) Write the actual RFR input file to the given folder.
reset(self) Delete every content.
save(self, path, \*\*kwargs) Save the actual RFR external file in the given path.
write_file(self) Write the actual OGS input file to the given folder.

Add a link to copy a file instead of writing.

Instead of writing a file, you can give a path to an existing file, that will be copied/linked to the target folder.

Parameters:
  • path (str) – path to the existing file that should be copied
  • symlink (bool, optional) – on UNIX systems it is possible to use a symbolic link to save time if the file is big. Default: False
check(self, verbose=True)[source]

Check if the external geometry definition is valid.

In the sence, that the contained data is consistent.

Parameters:verbose (bool, optional) – Print information for the executed checks. Default: True
Returns:result – Validity of the given gli.
Return type:bool

Remove a former given link to an external file.

get_file_type(self)

Get the OGS file class name.

read_file(self, path, encoding=None, verbose=False)[source]

Write the actual RFR input file to the given folder.

reset(self)

Delete every content.

save(self, path, **kwargs)[source]

Save the actual RFR external file in the given path.

Parameters:path (str) – path to where to file should be saved
write_file(self)

Write the actual OGS input file to the given folder.

Its path is given by “task_root+task_id+file_ext”.

data

Data in the RFR file.

file_name

base name of the file with extension.

Type:str
file_path

save path of the file.

Type:str
force_writing

state if the file is written even if empty.

Type:bool
is_empty

State if the OGS file is empty.

name

name of the file without extension.

Type:str
units

List of variable-units in the RFR file.

var_count

Count of variables in the RFR file (line 3).

var_info

Infos about variables and units in the RFR file (line 4).

variables

List of variables in the RFR file.