![]() |
KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
|
Buffered dict container with buffered data ability. More...
Public Member Functions | |
def | __init__ (self, int buffer_size=1, bool clear_buffer_when_advancing=True) |
Creates an instance of BufferedDict with specified buffer size. More... | |
int | GetBufferSize (self) |
Returns the buffer size of current isntance of buffered data. More... | |
None | AdvanceStep (self, recursive=True) |
Advances the buffered data containers. More... | |
bool | HasValue (self, str key, int step_index=0) |
Checks whether key exists in the given step_index. More... | |
Any | GetValue (self, str key, int step_index=0) |
Get the value given by the key at the specified step_index. More... | |
None | SetValue (self, str key, Any value, int step_index=0, bool overwrite=False) |
Sets a value for specified key at specified step_index. More... | |
None | RemoveValue (self, str key, int step_index=0) |
Remove value at the key in the specified step_index. More... | |
'dict[str, Any]' | GetValueItems (self, int step_index=0) |
'dict[str, BufferedDict]' | GetSubItems (self) |
'dict[str, Any]' | GetMap (self, int step_index=0) |
Generates (str, Any) pair map with recursively collecting all items in the BufferedDict. More... | |
BufferedDict | GetParent (self) |
Get the parent of the current buffered data. More... | |
BufferedDict | GetRoot (self) |
Get the root parent of the current buffered data. More... | |
str | PrintData (self, int step_index=-1, tabbing="") |
Prints containing data in a json like structure. More... | |
Any | __getitem__ (self, str key) |
None | __setitem__ (self, str key, Any value) |
None | __delitem__ (self, str key) |
str | __str__ (self) |
Buffered dict container with buffered data ability.
Instances of this can hold (str, Any) data pairs in hierachychal data structure where each sub item can have their own buffer sizes. Hence, Different sub structures can have their own buffers and can be advanced seperately or all together. Overwriting of the existing data is not allowed because, this is used as a central place to store data from various objects, hence allowing overwriting will make difficult to track the changes. Buffer size setting can only be done at the construction time of the instance to not to allow re sizing because then it is not clear how to handle the connected steps. The buffered data is stored in a cyclic buffer.
def buffered_dict.BufferedDict.__init__ | ( | self, | |
int | buffer_size = 1 , |
||
bool | clear_buffer_when_advancing = True |
||
) |
Creates an instance of BufferedDict with specified buffer size.
This creates an instance of buffered data with given buffer size. Args: buffer_size (int, optional): Cyclic buffer size. Defaults to 1. clear_buffer_when_advancing (bool): Clears the buffer and sub item buffers when advancing.
None buffered_dict.BufferedDict.__delitem__ | ( | self, | |
str | key | ||
) |
Any buffered_dict.BufferedDict.__getitem__ | ( | self, | |
str | key | ||
) |
None buffered_dict.BufferedDict.__setitem__ | ( | self, | |
str | key, | ||
Any | value | ||
) |
str buffered_dict.BufferedDict.__str__ | ( | self | ) |
None buffered_dict.BufferedDict.AdvanceStep | ( | self, | |
recursive = True |
|||
) |
Advances the buffered data containers.
Advances to the next index of the buffer in the cyclic buffer making the current index accesible as a past value indes (step_index = 1) Clears the values in the current step after advancement. Args: recursive (bool, optional): Advance step recursively in sub items. Defaults to True.
int buffered_dict.BufferedDict.GetBufferSize | ( | self | ) |
Returns the buffer size of current isntance of buffered data.
Returns: int: Buffer size of the cyclic buffer
'dict[str, Any]' buffered_dict.BufferedDict.GetMap | ( | self, | |
int | step_index = 0 |
||
) |
Generates (str, Any) pair map with recursively collecting all items in the BufferedDict.
This method recursively collects all items in the buffered data and returns a dict with (str, Any) pairs. All the sub_items are also added as (str, BufferedDict) pairs. Args: step_index (int, optional): Step index the value should be looked at. Defaults to 0. Returns: dict[str, Any]: (str, Any) map of all the items.
BufferedDict buffered_dict.BufferedDict.GetParent | ( | self | ) |
Get the parent of the current buffered data.
Returns: BufferedDict: Returns parent of the current instance.
BufferedDict buffered_dict.BufferedDict.GetRoot | ( | self | ) |
Get the root parent of the current buffered data.
Get the root parent of the current buffered data by recursive calls. Returns: BufferedDict: Root parent of the current buffered data.
'dict[str, BufferedDict]' buffered_dict.BufferedDict.GetSubItems | ( | self | ) |
Any buffered_dict.BufferedDict.GetValue | ( | self, | |
str | key, | ||
int | step_index = 0 |
||
) |
Get the value given by the key at the specified step_index.
This method retrieves the value given by the key at the specified step_index. The key must be the relative path w.r.t. current instance of the BufferedDict. It can include "/" seperators to get a value which is in sub items. In this case, it will be retrieved by recursive calls. Args: key (str): Relative path to the value. step_index (int, optional): Step index the value should be retrieved. Defaults to 0. Raises: RuntimeError: If the given key is not found. RuntimeError: If parent keys are not found. Returns: Any: Value stored at the key for the specified step_index.
'dict[str, Any]' buffered_dict.BufferedDict.GetValueItems | ( | self, | |
int | step_index = 0 |
||
) |
bool buffered_dict.BufferedDict.HasValue | ( | self, | |
str | key, | ||
int | step_index = 0 |
||
) |
Checks whether key exists in the given step_index.
The key in here should always be relative to the instance it is called upon. Hence, this key can have "/" seperations for subitems, then this method will navigate through the sub items as well to check whether given key is available. Args: key (str): Relative path of the key to be checked for. step_index (int, optional): Step index to be looked for. Defaults to 0. Returns: bool: True if the key is found in given step index. False otherwise.
str buffered_dict.BufferedDict.PrintData | ( | self, | |
int | step_index = -1 , |
||
tabbing = "" |
|||
) |
Prints containing data in a json like structure.
This method prints containing data and sub_item data recursively. If the step_index == -1 then, it prints all the values on all the steps of the buffer in current and all the sub_items recursively. If the step_index > 0 then, it will only print values at that specified buffer index for current instance as well as all the sub_items. Args: step_index (int, optional): Step index to be printed. Defaults to -1. tabbing (str, optional): Initial tabbing for json output.. Defaults to "". Returns: str: String will all the containing values formatted like json.
None buffered_dict.BufferedDict.RemoveValue | ( | self, | |
str | key, | ||
int | step_index = 0 |
||
) |
Remove value at the key in the specified step_index.
This method removes value at the key specified at the step_index. The key must be the relative path w.r.t. current instance of the BufferedDict. It can include "/" seperators to remove a value which is in sub items. In this case, it will be removed by recursive calls. Args: key (str): Relative path to the value. step_index (int, optional): Step index the value should be removed from. Defaults to 0. Raises: RuntimeError: If the given key is not found. RuntimeError: If the given parents of the key is not found.
None buffered_dict.BufferedDict.SetValue | ( | self, | |
str | key, | ||
Any | value, | ||
int | step_index = 0 , |
||
bool | overwrite = False |
||
) |
Sets a value for specified key at specified step_index.
This method sets the value at the key at the specified step_index. The key must be the relative path w.r.t. current instance of the BufferedDict. It can include "/" seperators to set a value which is in sub items. In this case, it will be set by recursive calls. Args: key (str): Relative path to the value. value (Any): value to be set step_index (int, optional): Step index the value should be set. Defaults to 0. overwrite (bool): Overwrites if existing key is found with the new value, otherwise creates a key with the value. Raises: RuntimeError: If a value is overwritten.