From 11cce23ab7093c2638da977e2aff168b0a0cc1b3 Mon Sep 17 00:00:00 2001 From: ThaHobbyist Date: Thu, 18 Jul 2024 15:08:24 +0530 Subject: [PATCH] Fixed naming convention for methods, classes and files --- README.md | 44 +++---- .../__init__.py | 0 .../keyData.py => Container/key.py} | 52 ++++---- .../{DictionaryElement => Container}/list.py | 100 +++++++-------- .../list_backup.py | 72 +++++------ .../foamDS.py => Container/node.py} | 40 +++--- .../obj_constructor.py | 6 +- pyvnt/Converter/Writer/writer.py | 4 +- pyvnt/Reference/basic.py | 120 +++++++++--------- .../Reference/{dimSet.py => dimension_set.py} | 38 +++--- .../{errorClasses.py => error_classes.py} | 0 pyvnt/Reference/tensor.py | 98 +++++++------- pyvnt/Reference/vector.py | 52 ++++---- pyvnt/__init__.py | 10 +- pyvnt/utils/{makeIndent.py => make_indent.py} | 2 +- pyvnt/utils/{showTree.py => show_tree.py} | 6 +- tests/test_basic.py | 64 +++++----- tests/test_dimm.py | 12 +- tests/test_key.py | 57 +++++++++ tests/test_keyData.py | 57 --------- tests/test_list.py | 54 ++++---- tests/test_node.py | 20 +-- tests/test_tensor.py | 44 +++---- tests/test_vector.py | 28 ++-- 24 files changed, 490 insertions(+), 490 deletions(-) rename pyvnt/{DictionaryElement => Container}/__init__.py (100%) rename pyvnt/{DictionaryElement/keyData.py => Container/key.py} (82%) rename pyvnt/{DictionaryElement => Container}/list.py (73%) rename pyvnt/{DictionaryElement => Container}/list_backup.py (75%) rename pyvnt/{DictionaryElement/foamDS.py => Container/node.py} (82%) rename pyvnt/{DictionaryElement => Container}/obj_constructor.py (84%) rename pyvnt/Reference/{dimSet.py => dimension_set.py} (64%) rename pyvnt/Reference/{errorClasses.py => error_classes.py} (100%) rename pyvnt/utils/{makeIndent.py => make_indent.py} (60%) rename pyvnt/utils/{showTree.py => show_tree.py} (83%) create mode 100644 tests/test_key.py delete mode 100644 tests/test_keyData.py diff --git a/README.md b/README.md index 8241f96..1d2f488 100644 --- a/README.md +++ b/README.md @@ -39,12 +39,12 @@ $ python setup.py install There are different classes in the package for different kinds of data in OpenFOAM: -- `ValueProperty` class is used to represent basic values. There are three children classes under `ValueProperty`: - - `EnumProp` class is used to represent string values. The reason for it being an enum is that the fields that have string values usually have a vew options for the string values, and a enum helps to reinforce those options and prevent the user from entering incorrect values. +- `Value_P` class is used to represent basic values. There are three children classes under `Value_P`: + - `Enm_P` class is used to represent string values. The reason for it being an enum is that the fields that have string values usually have a vew options for the string values, and a enum helps to reinforce those options and prevent the user from entering incorrect values. - `IntProperty` class is used to represent Integer values. - `FloatProperty` class is used to represent Floating point values -- `KeyData` class is used to store keys for the OpenFOAM distionary data types +- `Key_C` class is used to store keys for the OpenFOAM distionary data types - `Foam` class is used to represent the OpenFOAM dictionary data type. @@ -77,17 +77,17 @@ solvers solvers(Foam) └── p(Foam) { - solver(KeyData) : PCG(EnumProp), BNR(EnumProp) - preconditioner(KeyData) : DIC(EnumProp), - tolerance(KeyData) : 1e-06(FloatProperty), - relTol(KeyData) : 0.05(FloatProperty), + solver(Key_C) : PCG(Enm_P), BNR(Enm_P) + preconditioner(Key_C) : DIC(Enm_P), + tolerance(Key_C) : 1e-06(FloatProperty), + relTol(Key_C) : 0.05(FloatProperty), } -As shown above, the `Foam` and `KeyData` classes are used to represent the basic elements of the OpenFOAM Dictionary data structure. While the `ValueProperty` classe and its children classes are used to represent the basic property values in OpenFOAM. +As shown above, the `Foam` and `Key_C` classes are used to represent the basic elements of the OpenFOAM Dictionary data structure. While the `Value_P` classe and its children classes are used to represent the basic property values in OpenFOAM. ## Sample Use Case @@ -150,35 +150,35 @@ head = Foam('fvSolutions') sl = Foam('solvers', parent = head) -s = KeyData('solver', EnumProp('val1', items={'PCG', 'PBiCG', 'PBiCGStab'}, default='PCG')) -pc = KeyData('preconditioner', EnumProp('val1', items={'DIC', 'DILU', 'FDIC'}, default='DIC')) -tol = KeyData('tolerance', PropertyFloat('val1', minimum=0, maximum=1000, default=1e-06)) -rt = KeyData('relTol', PropertyFloat('val1', minimum=0, maximum=100, default=0.05)) +s = Key_C('solver', Enm_P('val1', items={'PCG', 'PBiCG', 'PBiCGStab'}, default='PCG')) +pc = Key_C('preconditioner', Enm_P('val1', items={'DIC', 'DILU', 'FDIC'}, default='DIC')) +tol = Key_C('tolerance', Flt_P('val1', minimum=0, maximum=1000, default=1e-06)) +rt = Key_C('relTol', Flt_P('val1', minimum=0, maximum=100, default=0.05)) p = Foam('p', sl, None, pc, s, tol, rt) -relTol2 = KeyData('relTol', PropertyFloat('val1', minimum=0, maximum=100, default=0)) +relTol2 = Key_C('relTol', Flt_P('val1', minimum=0, maximum=100, default=0)) pf = Foam('pFinal', sl, None, relTol2) -sol2 = KeyData('solver', EnumProp('val1', items={'smoothSolver'}, default='smoothSolver')) -sm = KeyData('smoother', EnumProp('val1', items={'symGaussSeidel', 'gaussSeidel'}, default = 'symGaussSeidel')) -tol2 = KeyData('tolerance', PropertyFloat('val1', minimum=0, maximum=1000, default=1e-05)) -relTol3 = KeyData('relTol', PropertyFloat('val1', minimum=0, maximum=100, default=0)) +sol2 = Key_C('solver', Enm_P('val1', items={'smoothSolver'}, default='smoothSolver')) +sm = Key_C('smoother', Enm_P('val1', items={'symGaussSeidel', 'gaussSeidel'}, default = 'symGaussSeidel')) +tol2 = Key_C('tolerance', Flt_P('val1', minimum=0, maximum=1000, default=1e-05)) +relTol3 = Key_C('relTol', Flt_P('val1', minimum=0, maximum=100, default=0)) u = Foam('U', sl, None, sol2, sm, tol2, relTol3) -ncorr = KeyData('nCorrectors', PropertyInt('int_prop_1', minimum=0, maximum=100, default=2)) -nnoc = KeyData('nNonOrthogonalCorrectors', PropertyInt('int_prop_2', minimum=0, maximum=100, default=0)) -prc = KeyData('pRefCell', PropertyInt('int_prop_3', minimum=0, maximum=100, default=0)) -prv = KeyData('pRefValue', PropertyInt('int_prop_4', minimum=0, maximum=100, default=0)) +ncorr = Key_C('nCorrectors', Int_P('int_prop_1', minimum=0, maximum=100, default=2)) +nnoc = Key_C('nNonOrthogonalCorrectors', Int_P('int_prop_2', minimum=0, maximum=100, default=0)) +prc = Key_C('pRefCell', Int_P('int_prop_3', minimum=0, maximum=100, default=0)) +prv = Key_C('pRefValue', Int_P('int_prop_4', minimum=0, maximum=100, default=0)) piso = Foam('PISO', head, None, ncorr, nnoc, prc, prv) -showTree(head) +show_tree(head) ``` diff --git a/pyvnt/DictionaryElement/__init__.py b/pyvnt/Container/__init__.py similarity index 100% rename from pyvnt/DictionaryElement/__init__.py rename to pyvnt/Container/__init__.py diff --git a/pyvnt/DictionaryElement/keyData.py b/pyvnt/Container/key.py similarity index 82% rename from pyvnt/DictionaryElement/keyData.py rename to pyvnt/Container/key.py index a9e2136..e4420eb 100755 --- a/pyvnt/DictionaryElement/keyData.py +++ b/pyvnt/Container/key.py @@ -2,7 +2,7 @@ from collections import OrderedDict from anytree import NodeMixin from pyvnt.Reference.basic import * -from pyvnt.utils.makeIndent import makeIndent +from pyvnt.utils.make_indent import make_indent ''' @@ -12,7 +12,7 @@ 3. the attributed should not be accesible through . operator -- done by name mangling(__var) ''' -class KeyParent(ABC): +class Key_Parent(ABC): ''' Abstract class to make sure that attributes cannot be inserted into the child class directly Do not make objects of this class @@ -28,22 +28,22 @@ def instance_restricted(self): # TODO: prevent access of attributes from outside the class -- done # Currently the attributes can be edited from outside the class, which should not be possible # TODO: Modify such that constructor takes in no attribute by default. After making the constructor, use a method to insert attributes -- done -class KeyData(KeyParent): +class Key_C(Key_Parent): def instance_restricted(self): pass - # def old__init__(self, name=None, **kwargs: ValueProperty): # old init method, - # super(KeyData, self).__init__(name) + # def old__init__(self, name=None, **kwargs: Value_P): # old init method, + # super(Key_C, self).__init__(name) # self.__dict__.update(kwargs) # # self.__toggle_freeze() - def __init__(self, name: str = None, *args: ValueProperty): - super(KeyData, self).__init__(name) + def __init__(self, name: str = None, *args: Value_P): + super(Key_C, self).__init__(name) tmp = {} for e in args: - tmp[e._ValueProperty__name] = e + tmp[e._Value_P__name] = e self._privateDict = OrderedDict(tmp) @@ -69,14 +69,14 @@ def __setattr__(self, key, value): else : raise AttributeError(key) - def appendVal(self, key: "str", val: ValueProperty): + def append_val(self, key: "str", val: Value_P): self._privateDict[key] = val ''' - # TODO: Take input of the object to be replaced or the obejct name instead of the variable name as the string. -- done in replaceVal2 + # TODO: Take input of the object to be replaced or the obejct name instead of the variable name as the string. -- done in replace_val2 This piece of code is here to remind devs about what not to do - def replaceVal(self, oldKey: str, newKey: str, newVal: ValueProperty): + def replace_val(self, oldKey: str, newKey: str, newVal: Value_P): if oldKey == newKey: self.__dict__[newKey] = newVal @@ -90,13 +90,13 @@ def replaceVal(self, oldKey: str, newKey: str, newVal: ValueProperty): self.__dict__[newKey] = newVal - def replaceVal2(self, old: ValueProperty | str, new: ValueProperty): + def replace_val2(self, old: Value_P | str, new: Value_P): if type(old) == str: oldKey = old else: - oldKey = old._ValueProperty__name + oldKey = old._Value_P__name - newKey = new._ValueProperty__name + newKey = new._Value_P__name if oldKey == newKey: self.__dict__[newKey] = new @@ -110,7 +110,7 @@ def replaceVal2(self, old: ValueProperty | str, new: ValueProperty): self.__dict__[newKey] = new ''' - def replaceVal(self, old: ValueProperty or str, new: ValueProperty): # uses orderedDict instead of regular Dictionary + def replace_val(self, old: Value_P or str, new: Value_P): # uses orderedDict instead of regular Dictionary ''' Function to insert and edit values in the class object once it is created @@ -125,9 +125,9 @@ def replaceVal(self, old: ValueProperty or str, new: ValueProperty): # uses orde if type(old) == str: oldKey = old else: - oldKey = old._ValueProperty__name + oldKey = old._Value_P__name - newKey = new._ValueProperty__name + newKey = new._Value_P__name if oldKey == newKey: # self.__dict__[newKey] = new @@ -138,7 +138,7 @@ def replaceVal(self, old: ValueProperty or str, new: ValueProperty): # uses orde else: self._privateDict = OrderedDict([(newKey, new) if k == oldKey else (k, v) for k, v in self._privateDict.items()]) - def delVal(self, key: str): + def delete_val(self, key: str): ''' Function to delete a given key from the object @@ -149,7 +149,7 @@ def delVal(self, key: str): def __repr__(self): last_elem = list(self._privateDict.keys())[-1] - res_str = f"KeyData(" + res_str = f"Key_C(" for key, val in self._privateDict.items(): res_str = res_str + f"{key} : {val}" if key != last_elem: @@ -158,7 +158,7 @@ def __repr__(self): return res_str - def giveVal(self): + def give_val(self): ''' Function to get all the keys and values stored in the object in a text format ''' @@ -169,36 +169,36 @@ def giveVal(self): if key == 'name': continue else: - res = res + f"{val.giveVal()}" + res = res + f"{val.give_val()}" if key != last_elem: res = res + ", " return res - def writeOut(self, file, indent = 0): + def write_out(self, file, indent = 0): ''' Function to write the object to a file ''' col_width = 16 last_elem = list(self._privateDict.keys())[-1] - makeIndent(file, indent) + make_indent(file, indent) if len(self._privateDict.values()) == 1 : try: file.write(f"{self.name}\n") for key, val in self._privateDict.items(): - val.writeOut(file, indent, True) + val.write_out(file, indent, True) except e: file.write(f"{self.name.ljust(col_width)}") for key, val in self._privateDict.items(): - val.writeOut(file) + val.write_out(file) if key != last_elem: file.write(" ") else: file.write(f"{self.name.ljust(col_width)}") for key, val in self._privateDict.items(): - val.writeOut(file) + val.write_out(file) if key != last_elem: file.write(" ") diff --git a/pyvnt/DictionaryElement/list.py b/pyvnt/Container/list.py similarity index 73% rename from pyvnt/DictionaryElement/list.py rename to pyvnt/Container/list.py index 243b07c..e4805dd 100644 --- a/pyvnt/DictionaryElement/list.py +++ b/pyvnt/Container/list.py @@ -1,11 +1,11 @@ from pyvnt.Reference.basic import * -from pyvnt.DictionaryElement.foamDS import Foam +from pyvnt.Container.Node_C import Foam from anytree import Node, RenderTree, AsciiStyle, NodeMixin -from pyvnt.Reference.errorClasses import SizeError, NoPlaceholdersError, NoValueError, KeyRepeatError -from pyvnt.utils.makeIndent import makeIndent +from pyvnt.Reference.error_classes import SizeError, NoPlaceholdersError, NoValueError, KeyRepeatError +from pyvnt.utils.make_indent import make_indent import warnings -class PropertyList(ValueProperty, NodeMixin): +class List_CP(Value_P, NodeMixin): ''' A property that holds a list of elements. @@ -31,22 +31,22 @@ class PropertyList(ValueProperty, NodeMixin): isNode: If the list is a list of nodes. Class constructor can be called in the following ways: - PropertyList(name, size, values) - PropertyList(name, values) - PropertyList(name, size, default) + List_CP(name, size, values) + List_CP(name, values) + List_CP(name, size, default) ''' - __slots__ = ['_ValueProperty__name', '_PropertyList__values', '_PropertyList__isNode'] + __slots__ = ['_Value_P__name', '_List_CP__values', '_List_CP__isNode'] - def __init__(self, name: int, size: int = None, values: [Foam] = [], elems: [[ValueProperty]] = [], default: ValueProperty = None, isNode: bool = False, parent: Foam = None): - super(PropertyList, self).__init__() + def __init__(self, name: int, size: int = None, values: [Foam] = [], elems: [[Value_P]] = [], default: Value_P = None, isNode: bool = False, parent: Foam = None): + super(List_CP, self).__init__() self.__isNode = isNode if not self.__isNode: - self.setProperties(name, size, elems, default) # TODO: Change the method such that the class takes inputs in elements and the class stores list of elements when not acting as a node. + self.set_properties(name, size, elems, default) # TODO: Change the method such that the class takes inputs in elements and the class stores list of elements when not acting as a node. else: - self.checkType(values = values) # All values needs to be of the type Foam as the values are all the children nodes + self.check_type(values = values) # All values needs to be of the type Foam as the values are all the children nodes self.name = name self.__values = [] self.data = [] @@ -61,13 +61,13 @@ def __init__(self, name: int, size: int = None, values: [Foam] = [], elems: [[Va def instance_restricted(self): pass - def totLen(self, ar: [[ValueProperty]]= [[]]) -> int: + def total_len(self, ar: [[Value_P]]= [[]]) -> int: res = 0 for elem in ar: res += len(elem) return res - def checkType(self, elems: [[ValueProperty]] = None, values: [ValueProperty] = None, value: ValueProperty = None): + def check_type(self, elems: [[Value_P]] = None, values: [Value_P] = None, value: Value_P = None): ''' Checks if all the values are of the same type. ''' @@ -78,8 +78,8 @@ def checkType(self, elems: [[ValueProperty]] = None, values: [ValueProperty] = N else: pass else: - if not isinstance(value, ValueProperty): - raise TypeError("Value should be of type ValueProperty") + if not isinstance(value, Value_P): + raise TypeError("Value should be of type Value_P") else: pass elif elems: @@ -91,8 +91,8 @@ def checkType(self, elems: [[ValueProperty]] = None, values: [ValueProperty] = N pass else: for v in elems: - if not all(isinstance(i, ValueProperty) for i in v): - raise TypeError("All values should be of type ValueProperty") + if not all(isinstance(i, Value_P) for i in v): + raise TypeError("All values should be of type Value_P") else: pass elif values: @@ -102,23 +102,23 @@ def checkType(self, elems: [[ValueProperty]] = None, values: [ValueProperty] = N else: pass else: - if not all(isinstance(i, ValueProperty) for i in values): - raise TypeError("All values should be of type ValueProperty") + if not all(isinstance(i, Value_P) for i in values): + raise TypeError("All values should be of type Value_P") else: pass else: raise NoValueError("No values given for type checking") - def setProperties(self, name: int, size: int, values: [[ValueProperty]], default: ValueProperty = None): + def set_properties(self, name: int, size: int, values: [[Value_P]], default: Value_P = None): ''' Sets the values of the list is it is not a node. values: it is the list of elements that are stored in the List class ''' - self._ValueProperty__name = name + self._Value_P__name = name - self.checkType(elems = values) + self.check_type(elems = values) if size and values != []: ''' @@ -129,7 +129,7 @@ def setProperties(self, name: int, size: int, values: [[ValueProperty]], default else: pass - if size != self.totLen(values): + if size != self.total_len(values): raise SizeError(size) else: self.__values = values @@ -167,7 +167,7 @@ def setProperties(self, name: int, size: int, values: [[ValueProperty]], default ''' raise NoValueError("No values given for list construction") - def getItem(self, elem: int, index: int = None): + def get_item(self, elem: int, index: int = None): ''' Returns the value at the given index. @@ -181,7 +181,7 @@ def getItem(self, elem: int, index: int = None): else: return self.__values[elem] - def append_value(self, elem: int, val: ValueProperty): + def append_value(self, elem: int, val: Value_P): ''' Appends a value to the list. @@ -189,11 +189,11 @@ def append_value(self, elem: int, val: ValueProperty): elem: The index of the element in which the value is to be appended. val: The value to be appended. ''' - self.checkType(value = val) + self.check_type(value = val) self.__values[elem].append(val) - def append_uniq_value(self, elem: int, val: ValueProperty): + def append_uniq_value(self, elem: int, val: Value_P): ''' Appends a value to the element of the list if it is not already present. @@ -203,32 +203,32 @@ def append_uniq_value(self, elem: int, val: ValueProperty): ''' - self.checkType(value = val) + self.check_type(value = val) if val not in self.__values[elem]: self.__values[elem].append(val) else: raise KeyRepeatError(val) - def append_elem(self, elem: [ValueProperty]): + def append_elem(self, elem: [Value_P]): ''' Appends an element to the list. Parameters: elem: The element to be appended. ''' - self.checkType(values = elem) + self.check_type(values = elem) self.__values.append(elem) - def append_uniq_elem(self, elem: [ValueProperty]): + def append_uniq_elem(self, elem: [Value_P]): ''' Appends an element to the list if it is not already present. Parameters: elem: The element to be appended. ''' - self.checkType(values = elem) + self.check_type(values = elem) if elem not in self.__values: self.__values.append(elem) @@ -239,11 +239,11 @@ def __repr__(self): if not self.__isNode: tval = [] for elem in self.__values: - tval.append([val.giveVal() for val in elem]) + tval.append([val.give_val() for val in elem]) - return f"PropertyList(name : {self._ValueProperty__name}, values : {tval})" + return f"List_CP(name : {self._Value_P__name}, values : {tval})" else: - return f"PropertyList(name : {self.name}, values : {self.children})" + return f"List_CP(name : {self.name}, values : {self.children})" def size(self): ''' @@ -254,7 +254,7 @@ def size(self): s = s + len(elem) return s - def giveVal(self): + def give_val(self): ''' Returns the list. ''' @@ -262,18 +262,18 @@ def giveVal(self): for elem in self.__values: for val in elem: - res = res + (val.giveVal(),) + res = res + (val.give_val(),) print(res) return res - def checkSimilarData(self): + def check_similar_data(self): ''' Checks if all the items inside the list are of the same type. ''' return all(isinstance(i, type(self.__values[0][0])) for i in elem for elem in self.__values) - def writeOut(self, file, indent: int = 0, vert: bool = False): + def write_out(self, file, indent: int = 0, vert: bool = False): ''' Writes the list to a file ''' @@ -284,40 +284,40 @@ def writeOut(self, file, indent: int = 0, vert: bool = False): # If the syntax of every keyword is known, a method can be written to generate the files according to the syntax. if self.__isNode: - makeIndent(file, indent) + make_indent(file, indent) file.write(f"{self.name}\n") - makeIndent(file, indent) + make_indent(file, indent) file.write("(\n") for child in self.children: - child.writeOut(file, indent+1) + child.write_out(file, indent+1) file.write("\n") - makeIndent(file, indent) + make_indent(file, indent) file.write(")\n") elif vert: - makeIndent(file, indent) + make_indent(file, indent) file.write("(\n") for elem in self.__values: - makeIndent(file, indent+1) + make_indent(file, indent+1) for val in elem: - val.writeOut(file) + val.write_out(file) file.write(" ") file.write("\n") - makeIndent(file, indent) + make_indent(file, indent) file.write(")") else: res = "( " for elem in self.__values: for val in elem: - res = res + f"{val.giveVal()} " + res = res + f"{val.give_val()} " res += ")" file.write(res) def __eq__(self, other): - return self.giveVal() == other.giveVal() + return self.give_val() == other.give_val() def __ne__(self, other): return not self.__eq__(other) \ No newline at end of file diff --git a/pyvnt/DictionaryElement/list_backup.py b/pyvnt/Container/list_backup.py similarity index 75% rename from pyvnt/DictionaryElement/list_backup.py rename to pyvnt/Container/list_backup.py index 0791a48..7c8413a 100644 --- a/pyvnt/DictionaryElement/list_backup.py +++ b/pyvnt/Container/list_backup.py @@ -1,10 +1,10 @@ from pyvnt.Reference.basic import * -from pyvnt.DictionaryElement.foamDS import Foam +from pyvnt.Container.Node_C import Foam from anytree import Node, RenderTree, AsciiStyle, NodeMixin -from pyvnt.Reference.errorClasses import SizeError, NoPlaceholdersError, NoValueError, KeyRepeatError +from pyvnt.Reference.error_classes import SizeError, NoPlaceholdersError, NoValueError, KeyRepeatError import warnings -class PropertyList(ValueProperty, NodeMixin): +class List_CP(Value_P, NodeMixin): ''' A property that holds a list of elements. @@ -30,22 +30,22 @@ class PropertyList(ValueProperty, NodeMixin): isNode: If the list is a list of nodes. Class constructor can be called in the following ways: - PropertyList(name, size, values) - PropertyList(name, values) - PropertyList(name, size, default) + List_CP(name, size, values) + List_CP(name, values) + List_CP(name, size, default) ''' - __slots__ = ['_ValueProperty__name', '_PropertyList__values', '_PropertyList__isNode'] + __slots__ = ['_Value_P__name', '_List_CP__values', '_List_CP__isNode'] - def __init__(self, name: int, size: int = None, values: [ValueProperty] = [], elems: [[ValueProperty]] or [Foam] = [], default: ValueProperty = None, isNode: bool = False, parent: Foam = None): - super(PropertyList, self).__init__() + def __init__(self, name: int, size: int = None, values: [Value_P] = [], elems: [[Value_P]] or [Foam] = [], default: Value_P = None, isNode: bool = False, parent: Foam = None): + super(List_CP, self).__init__() self.__isNode = isNode if not self.__isNode: - self.setProperties(name, size, elems, default) # TODO: Change the method such that the class takes inputs in elements and the class stores list of elements when not acting as a node. + self.set_properties(name, size, elems, default) # TODO: Change the method such that the class takes inputs in elements and the class stores list of elements when not acting as a node. else: - self.checkType(values = values) + self.check_type(values = values) self.name = name self.__values = [] self.data = [] @@ -60,7 +60,7 @@ def __init__(self, name: int, size: int = None, values: [ValueProperty] = [], el def instance_restricted(self): pass - def checkType(self, values: [ValueProperty] = None, value: ValueProperty = None): + def check_type(self, values: [Value_P] = None, value: Value_P = None): ''' Checks if all the values are of the same type. ''' @@ -71,8 +71,8 @@ def checkType(self, values: [ValueProperty] = None, value: ValueProperty = None) else: pass else: - if not isinstance(value, ValueProperty): - raise TypeError("Value should be of type ValueProperty") + if not isinstance(value, Value_P): + raise TypeError("Value should be of type Value_P") else: pass elif values: @@ -82,20 +82,20 @@ def checkType(self, values: [ValueProperty] = None, value: ValueProperty = None) else: pass else: - if not all(isinstance(i, ValueProperty) for i in values): - raise TypeError("All values should be of type ValueProperty") + if not all(isinstance(i, Value_P) for i in values): + raise TypeError("All values should be of type Value_P") else: pass else: raise NoValueError("No values given for type checking") - def setProperties(self, name: int, size: int, values: [[ValueProperty]], default: ValueProperty = None): + def set_properties(self, name: int, size: int, values: [[Value_P]], default: Value_P = None): ''' Sets the values of the list is it is not a node. ''' - self._ValueProperty__name = name + self._Value_P__name = name - # self.checkType(values = values) + # self.check_type(values = values) if size and values != []: ''' @@ -144,7 +144,7 @@ def setProperties(self, name: int, size: int, values: [[ValueProperty]], default ''' raise NoValueError("No values given for list construction") - def getItem(self, elem: int, index: int = None): + def get_item(self, elem: int, index: int = None): ''' Returns the value at the given index. @@ -158,7 +158,7 @@ def getItem(self, elem: int, index: int = None): else: return self.__values[elem] - def append_value(self, elem: int, val: ValueProperty): + def append_value(self, elem: int, val: Value_P): ''' Appends a value to the list. @@ -166,11 +166,11 @@ def append_value(self, elem: int, val: ValueProperty): elem: The index of the element in which the value is to be appended. val: The value to be appended. ''' - self.checkType(value = val) + self.check_type(value = val) self.__values.append(val) - def append_uniq_value(self, elem: int, val: ValueProperty): + def append_uniq_value(self, elem: int, val: Value_P): ''' Appends a value to the element of the list if it is not already present. @@ -180,32 +180,32 @@ def append_uniq_value(self, elem: int, val: ValueProperty): ''' - self.checkType(value = val) + self.check_type(value = val) if val not in self.__values[elem]: self.__values[elem].append(val) else: raise KeyRepeatError(val) - def append_elem(self, elem: [ValueProperty]): + def append_elem(self, elem: [Value_P]): ''' Appends an element to the list. Parameters: elem: The element to be appended. ''' - self.checkType(values = elem) + self.check_type(values = elem) self.__values.append(elem) - def append_uniq_elem(self, elem: [ValueProperty]): + def append_uniq_elem(self, elem: [Value_P]): ''' Appends an element to the list if it is not already present. Parameters: elem: The element to be appended. ''' - self.checkType(values = elem) + self.check_type(values = elem) if elem not in self.__values: self.__values.append(elem) @@ -214,9 +214,9 @@ def append_uniq_elem(self, elem: [ValueProperty]): def __repr__(self): if not self.__isNode: - return f"PropertyList(name : {self._ValueProperty__name}, values : {self.__values})" + return f"List_CP(name : {self._Value_P__name}, values : {self.__values})" else: - return f"PropertyList(name : {self.name}, values : {self.children})" + return f"List_CP(name : {self.name}, values : {self.children})" def size(self): ''' @@ -227,7 +227,7 @@ def size(self): s = s + len(elem) return s - def giveVal(self): + def give_val(self): ''' Returns the list. ''' @@ -235,17 +235,17 @@ def giveVal(self): for elem in self.__values: for val in elem: - res = res + (val.giveVal(),) + res = res + (val.give_val(),) return res - def checkSimilarData(self): + def check_similar_data(self): ''' Checks if all the items inside the list are of the same type. ''' return all(isinstance(i, type(self.__values[0][0])) for i in elem for elem in self.__values) - def writeOut(self, file, indent = 0): + def write_out(self, file, indent = 0): ''' Writes the list to a file ''' @@ -258,12 +258,12 @@ def writeOut(self, file, indent = 0): res = "" for elem in self.__values: for val in elem: - res = res + f"{val.giveVal()} " + res = res + f"{val.give_val()} " res = res + "\n" file.write(res) def __eq__(self, other): - return self.giveVal() == other.giveVal() + return self.give_val() == other.give_val() def __ne__(self, other): return not self.__eq__(other) diff --git a/pyvnt/DictionaryElement/foamDS.py b/pyvnt/Container/node.py similarity index 82% rename from pyvnt/DictionaryElement/foamDS.py rename to pyvnt/Container/node.py index fadc543..053aa9b 100755 --- a/pyvnt/DictionaryElement/foamDS.py +++ b/pyvnt/Container/node.py @@ -1,9 +1,9 @@ from anytree import Node, RenderTree, AsciiStyle, NodeMixin from anytree.search import find_by_attr from typing import Any, Type -from pyvnt.DictionaryElement.keyData import KeyData -from pyvnt.Reference.errorClasses import * -from pyvnt.utils.makeIndent import makeIndent +from pyvnt.Container.Key_C import Key_C +from pyvnt.Reference.error_classes import * +from pyvnt.utils.make_indent import make_indent ''' Criteria for classes: @@ -24,7 +24,7 @@ class Foam(NodeMixin): # __slots__ = ('name', 'parent', 'children', 'data') - def __init__(self, name: str, parent = None, children: [] = None, *args: KeyData): + def __init__(self, name: str, parent = None, children: [] = None, *args: Key_C): super(Foam, self).__init__() # self._privateDict = kwargs @@ -70,7 +70,7 @@ def __getattr__(self, key): # print(treestr.ljust(8), s) - def addChild(self, node): + def add_child(self, node): ''' Function to add a child node to the current node @@ -80,7 +80,7 @@ def addChild(self, node): self.children += (node, ) - def setParent(self, node): + def set_Parent(self, node): ''' Function to set the parent node to the current node @@ -96,7 +96,7 @@ def __repr__(self): res_str = res_str + ")" return res_str - def getChild(self, val: str): + def get_child(self, val: str): ''' Function to find a child node with the given attribute @@ -105,9 +105,9 @@ def getChild(self, val: str): ''' return find_by_attr(self, val, maxlevel = 2) - def addData(self, data: KeyData, pos: int = None): + def add_data(self, data: Key_C, pos: int = None): ''' - Function to add KeyData attributes to the existing Node + Function to add Key_C attributes to the existing Node ''' if pos != None: @@ -115,9 +115,9 @@ def addData(self, data: KeyData, pos: int = None): else: self.data.append(data) - def removeData(self, data: KeyData): + def remove_data(self, data: Key_C): ''' - Function to remove a keydata attribute from the node + Function to remove a Key_C attribute from the node ''' try: @@ -125,7 +125,7 @@ def removeData(self, data: KeyData): except: raise AttributeError(f"{data.name} does not exist in this node") - def reorderData(self, data: KeyData, pos: int): + def reorder_data(self, data: Key_C, pos: int): ''' Function to reorder the data in the node ''' @@ -136,7 +136,7 @@ def reorderData(self, data: KeyData, pos: int): except: raise AttributeError(f"{data.name} does not exist in this node") - def writeOut(self, file, indent = 0): + def write_out(self, file, indent = 0): ''' Function to write the current node to the file ''' @@ -150,26 +150,26 @@ def writeOut(self, file, indent = 0): file.write("{\n") for d in self.data: file.write("\t") - d.writeOut(file) + d.write_out(file) file.write("}\n") ''' - makeIndent(file, indent) + make_indent(file, indent) file.write(f"{self.name}\n") - makeIndent(file, indent) + make_indent(file, indent) file.write("{\n") for d in self.data: - d.writeOut(file, indent+1) + d.write_out(file, indent+1) - # makeIndent(file, indent) + # make_indent(file, indent) for child in self.children: - child.writeOut(file, indent+1) + child.write_out(file, indent+1) file.write("\n") - makeIndent(file, indent) + make_indent(file, indent) file.write("}\n") diff --git a/pyvnt/DictionaryElement/obj_constructor.py b/pyvnt/Container/obj_constructor.py similarity index 84% rename from pyvnt/DictionaryElement/obj_constructor.py rename to pyvnt/Container/obj_constructor.py index 2a1aecf..37791ab 100755 --- a/pyvnt/DictionaryElement/obj_constructor.py +++ b/pyvnt/Container/obj_constructor.py @@ -1,5 +1,5 @@ -from pyvnt.DictionaryElement.foamDS import Foam -from pyvnt.DictionaryElement.keyData import KeyData +from pyvnt.Container.Node_C import Foam +from pyvnt.Container.Key_C import Key_C # Function no longer needed # It is not available to use outside the package and the code is here just for future reference if needed @@ -21,6 +21,6 @@ def obj_constructor(name: str, parent = None, children: [] = None, *args): elif tmp == [] and children == None: return Foam(name, parent, children) elif children == None: - return KeyData(name, parent, *args) + return Key_C(name, parent, *args) else: raise Exception("Invalid arguments given") \ No newline at end of file diff --git a/pyvnt/Converter/Writer/writer.py b/pyvnt/Converter/Writer/writer.py index 6e89ae7..c8ec16c 100644 --- a/pyvnt/Converter/Writer/writer.py +++ b/pyvnt/Converter/Writer/writer.py @@ -1,4 +1,4 @@ -from pyvnt.DictionaryElement import * +from pyvnt.Container import * def writeTo(root, path): ''' @@ -10,4 +10,4 @@ def writeTo(root, path): ''' with open(path, "w") as file: - root.writeOut(file) \ No newline at end of file + root.write_out(file) \ No newline at end of file diff --git a/pyvnt/Reference/basic.py b/pyvnt/Reference/basic.py index 94644b0..d647d3b 100755 --- a/pyvnt/Reference/basic.py +++ b/pyvnt/Reference/basic.py @@ -2,17 +2,17 @@ from typing import Any import enum from abc import ABC, abstractmethod -from pyvnt.Reference.errorClasses import * +from pyvnt.Reference.error_classes import * # Property Classes -class ValueProperty(ABC): +class Value_P(ABC): ''' Abstract parent class for all the property classes Do not create oobject of this class ''' - __slots__ = ('_ValueProperty__name') + __slots__ = ('_Value_P__name') def __init__(self): self.__name = "" @@ -23,7 +23,7 @@ def instance_restricted(self): -class PropertyInt(ValueProperty): +class Int_P(Value_P): ''' Property class to store integer values @@ -34,17 +34,17 @@ class PropertyInt(ValueProperty): maximum: Maximum value of the range of values that can be stored in the property object (Optional, default = 100) ''' - __slots__ = ('_ValueProperty__name', '_PropertyInt__default', - '_PropertyInt__minimum', '_PropertyInt__maximum') + __slots__ = ('_Value_P__name', '_Int_P__default', + '_Int_P__minimum', '_Int_P__maximum') def __init__(self, name: str, default: int = 1, minimum: int = 0, maximum: int = 100): - super(PropertyInt, self).__init__() - self.setProperties(name, default, minimum, maximum) + super(Int_P, self).__init__() + self.set_properties(name, default, minimum, maximum) def instance_restricted(self): pass - def setProperties(self, name: str, default: int, minimum: int, maximum: int): + def set_properties(self, name: str, default: int, minimum: int, maximum: int): ''' Function to edit the values stored in the object @@ -60,12 +60,12 @@ def setProperties(self, name: str, default: int, minimum: int, maximum: int): elif default not in range(minimum, maximum+1): raise DefaultOutofRangeError(default) else: - self._ValueProperty__name = name + self._Value_P__name = name self.__default = default self.__minimum = minimum self.__maximum = maximum - def giveVal(self): + def give_val(self): ''' Funciton to return the current value of the property ''' @@ -73,39 +73,39 @@ def giveVal(self): return res def __repr__(self): - return f"PropertyInt(name = {self._ValueProperty__name}, default = {self.__default}, minimum = {self.__minimum}, maximum = {self.__maximum})" + return f"Int_P(name = {self._Value_P__name}, default = {self.__default}, minimum = {self.__minimum}, maximum = {self.__maximum})" def __add__(self, other): - return self.__default + other._PropertyFloat__default + return self.__default + other._Flt_P__default def __sub__(self, other): - return self.__default - other._PropertyFloat__default + return self.__default - other._Flt_P__default def __mul__(self, other): - return self.__default * other._PropertyFloat__default + return self.__default * other._Flt_P__default def __truediv__(self, other): - return self.__default / other._PropertyFloat__default + return self.__default / other._Flt_P__default def __gt__(self, other): - return self.__default > other._PropertyFloat__default + return self.__default > other._Flt_P__default def __lt__(self, other): - return self.__default < other._PropertyFloat__default + return self.__default < other._Flt_P__default def __le__(self, other): - return self.__default <= other._PropertyFloat__default + return self.__default <= other._Flt_P__default def __ge__(self, other): - return self.__default >= other._PropertyFloat__default + return self.__default >= other._Flt_P__default def __eq__(self, other): - return self.__default == other._PropertyFloat__default + return self.__default == other._Flt_P__default def __ne__(self, other): - return self.__default != other._PropertyFloat__default + return self.__default != other._Flt_P__default - def writeOut(self, file): + def write_out(self, file): ''' Function to write the object to a file ''' @@ -113,7 +113,7 @@ def writeOut(self, file): -class PropertyFloat(ValueProperty): +class Flt_P(Value_P): ''' Property class to store float values @@ -125,17 +125,17 @@ class PropertyFloat(ValueProperty): ''' - __slots__ = ('_ValueProperty__name', '_PropertyFloat__default', - '_PropertyFloat__minimum', '_PropertyFloat__maximum') + __slots__ = ('_Value_P__name', '_Flt_P__default', + '_Flt_P__minimum', '_Flt_P__maximum') def __init__(self, name=str, default: float = 1.0, minimum: float = 0.0, maximum: float = 100.0): - super(PropertyFloat, self).__init__() - self.setProperties(name, default, minimum, maximum) + super(Flt_P, self).__init__() + self.set_properties(name, default, minimum, maximum) def instance_restricted(self): pass - def setProperties(self, name: str, default: float, minimum: float, maximum: float): + def set_properties(self, name: str, default: float, minimum: float, maximum: float): ''' Function to edit the values stored in the object @@ -151,12 +151,12 @@ def setProperties(self, name: str, default: float, minimum: float, maximum: floa elif default > maximum or default < minimum: raise DefaultOutofRangeError(default) else: - self._ValueProperty__name = name + self._Value_P__name = name self.__default = default self.__minimum = minimum self.__maximum = maximum - def giveVal(self): + def give_val(self): ''' Funciton to return the current value of the property ''' @@ -164,39 +164,39 @@ def giveVal(self): return res def __repr__(self): - return f"PropertyFloat(name = {self._ValueProperty__name}, default = {self.__default}, minimum = {self.__minimum}, maximum = {self.__maximum})" + return f"Flt_P(name = {self._Value_P__name}, default = {self.__default}, minimum = {self.__minimum}, maximum = {self.__maximum})" def __add__(self, other): - return self.__default + other._PropertyFloat__default + return self.__default + other._Flt_P__default def __sub__(self, other): - return self.__default - other._PropertyFloat__default + return self.__default - other._Flt_P__default def __mul__(self, other): - return self.__default * other._PropertyFloat__default + return self.__default * other._Flt_P__default def __truediv__(self, other): - return self.__default / other._PropertyFloat__default + return self.__default / other._Flt_P__default def __gt__(self, other): - return self.__default > other._PropertyFloat__default + return self.__default > other._Flt_P__default def __lt__(self, other): - return self.__default < other._PropertyFloat__default + return self.__default < other._Flt_P__default def __le__(self, other): - return self.__default <= other._PropertyFloat__default + return self.__default <= other._Flt_P__default def __ge__(self, other): - return self.__default >= other._PropertyFloat__default + return self.__default >= other._Flt_P__default def __eq__(self, other): - return self.__default == other._PropertyFloat__default + return self.__default == other._Flt_P__default def __ne__(self, other): - return self.__default != other._PropertyFloat__default + return self.__default != other._Flt_P__default - def writeOut(self, file): + def write_out(self, file): ''' Function to write the object to a file ''' @@ -204,7 +204,7 @@ def writeOut(self, file): -class PropertyString(ValueProperty): # for testing purposes only, to be scrapped +class Str_P(Value_P): # for testing purposes only, to be scrapped ''' Property class to store string values @@ -213,16 +213,16 @@ class PropertyString(ValueProperty): # for testing purposes only, to be scrapped default: Current value of the property (Optional, default = "") ''' - __slots__ = ('_ValueProperty__name', '_PropertyString__default') + __slots__ = ('_Value_P__name', '_Str_P__default') def __init__(self, name: str, default: str = ""): - super(PropertyString, self).__init__() - self.setProperties(name, default) + super(Str_P, self).__init__() + self.set_properties(name, default) def instance_restricted(self): pass - def setProperties(self, name: str, default: str): + def set_properties(self, name: str, default: str): ''' Function to edit the values stored in the object @@ -231,10 +231,10 @@ def setProperties(self, name: str, default: str): default: Current value of the property ''' - self._ValueProperty__name = name + self._Value_P__name = name self.__default = default - def giveVal(self): + def give_val(self): ''' Funciton to return the current value of the property ''' @@ -242,10 +242,10 @@ def giveVal(self): return res def __repr__(self): - return f"PropertyString(name = {self._ValueProperty__name}, default = '{self.__default}')" + return f"Str_P(name = {self._Value_P__name}, default = '{self.__default}')" -class EnumProp(ValueProperty): +class Enm_P(Value_P): ''' Property class to store values that are usually a choice out of many possible choices(string data) @@ -256,11 +256,11 @@ class EnumProp(ValueProperty): ''' - __slots__ = ('_ValueProperty__name', '_EnumProp__items', '_EnumProp__default') + __slots__ = ('_Value_P__name', '_Enm_P__items', '_Enm_P__default') def __init__(self, name: str, items: {str}, default: str): - super(EnumProp, self).__init__() - self.setProperties(name, items, default) + super(Enm_P, self).__init__() + self.set_properties(name, items, default) def instance_restricted(self): pass @@ -307,7 +307,7 @@ def set_default(self, val: str) -> None: else: raise ValueOutofRangeError(val) - def setProperties(self, name: str, items: {str}, default: str): + def set_properties(self, name: str, items: {str}, default: str): ''' Function to edit the values stored in the object @@ -329,21 +329,21 @@ def setProperties(self, name: str, items: {str}, default: str): if default not in items: raise DefaultOutofRangeError(default) - self._ValueProperty__name = name + self._Value_P__name = name self.__items = items self.__default = default def __repr__(self): - return f"EnumProp(name = {self._ValueProperty__name}, items = {self.__items}, default = {self.__default})" + return f"Enm_P(name = {self._Value_P__name}, items = {self.__items}, default = {self.__default})" - def giveVal(self): + def give_val(self): ''' Funciton to return the current value of the property ''' res = self.__default return res - def writeOut(self, file): + def write_out(self, file): ''' Function to write the object to a file ''' diff --git a/pyvnt/Reference/dimSet.py b/pyvnt/Reference/dimension_set.py similarity index 64% rename from pyvnt/Reference/dimSet.py rename to pyvnt/Reference/dimension_set.py index b958050..9171a5e 100644 --- a/pyvnt/Reference/dimSet.py +++ b/pyvnt/Reference/dimension_set.py @@ -1,8 +1,8 @@ from enum import IntEnum, auto -from pyvnt.Reference.errorClasses import IncorrectLengthError +from pyvnt.Reference.error_classes import IncorrectLengthError from pyvnt.Reference.basic import * -class DimmType(IntEnum): +class Dim_Type(IntEnum): MASS = auto() LENGTH = auto() TIME = auto() @@ -11,9 +11,9 @@ class DimmType(IntEnum): CURRENT = auto() LUMINOUS_INTENSITY = auto() -class DimmSet(ValueProperty): +class Dim_Set_P(Value_P): ''' - DimmSet class is a class that represents a set of dimensions. + Dim_Set_P class is a class that represents a set of dimensions. It is used to represent the dimensions of a physical quantity. Contrsucor Parameters: @@ -31,24 +31,24 @@ class DimmSet(ValueProperty): 7. Luminous Intensity ''' - __slots__ = ['_ValueProperty__name', '_DimmSet__dimmtype', '_DimmSet__dimm'] + __slots__ = ['_Value_P__name', '_Dim_Set_P__Dim_Type', '_Dim_Set_P__dimm'] def __init__(self, name, dimms: [] = [0] * 7): - super(DimmSet, self).__init__() + super(Dim_Set_P, self).__init__() - self.__dimmtype = DimmType + self.__Dim_Type = Dim_Type self.__dimm = [0] * 7 - self._ValueProperty__name = name + self._Value_P__name = name if len(dimms) == 7: - self.setProperties(*dimms) + self.set_properties(*dimms) else: raise IncorrectLengthError(len(dimms)) def instance_restricted(self): pass - def setProperties(self, m = 0, l = 0, t = 0, temp = 0, mol = 0, c = 0, li = 0): + def set_properties(self, m = 0, l = 0, t = 0, temp = 0, mol = 0, c = 0, li = 0): ''' Sets the dimensions of the physical quantity. @@ -69,24 +69,24 @@ def setProperties(self, m = 0, l = 0, t = 0, temp = 0, mol = 0, c = 0, li = 0): The dimension of luminous intensity. ''' if m: - self.__dimm[DimmType.MASS - 1] = m + self.__dimm[Dim_Type.MASS - 1] = m if l: - self.__dimm[DimmType.LENGTH - 1] = l + self.__dimm[Dim_Type.LENGTH - 1] = l if t: - self.__dimm[DimmType.TIME - 1] = t + self.__dimm[Dim_Type.TIME - 1] = t if temp: - self.__dimm[DimmType.TEMPERATURE - 1] = temp + self.__dimm[Dim_Type.TEMPERATURE - 1] = temp if mol: - self.__dimm[DimmType.MOLES - 1] = mol + self.__dimm[Dim_Type.MOLES - 1] = mol if c: - self.__dimm[DimmType.CURRENT - 1] = c + self.__dimm[Dim_Type.CURRENT - 1] = c if li: - self.__dimm[DimmType.LUMINOUS_INTENSITY - 1] = li + self.__dimm[Dim_Type.LUMINOUS_INTENSITY - 1] = li def __repr__(self): - return f"DimmSet(name : {self._ValueProperty__name}, dimm : {self.__dimm})" + return f"Dim_Set_P(name : {self._Value_P__name}, dimm : {self.__dimm})" - def giveVal(self): + def give_val(self): ''' Returns the dimensions of the physical quantity. ''' diff --git a/pyvnt/Reference/errorClasses.py b/pyvnt/Reference/error_classes.py similarity index 100% rename from pyvnt/Reference/errorClasses.py rename to pyvnt/Reference/error_classes.py diff --git a/pyvnt/Reference/tensor.py b/pyvnt/Reference/tensor.py index e0990ad..3d5118f 100644 --- a/pyvnt/Reference/tensor.py +++ b/pyvnt/Reference/tensor.py @@ -1,10 +1,10 @@ from pyvnt.Reference.basic import * -from pyvnt.Reference.errorClasses import InvalidTupleError -from pyvnt.Reference.vector import PropertyVector +from pyvnt.Reference.error_classes import InvalidTupleError +from pyvnt.Reference.vector import Vector_P import numpy as np from typing import Self -class PropertyTensor(ValueProperty): +class Tensor_P(Value_P): ''' A property that holds a tensor value. @@ -18,25 +18,25 @@ class PropertyTensor(ValueProperty): value: list ''' - __slots__ = ('_PropertyTensor__name', '_PropertyTensor__values') + __slots__ = ('_Tensor_P__name', '_Tensor_P__values') def instance_restricted(self): pass - def __init__(self, name, value: [PropertyFloat]): - super(PropertyTensor, self).__init__() + def __init__(self, name, value: [Flt_P]): + super(Tensor_P, self).__init__() inputs = [] for i in range(3): for j in range(3): inputs.append((i+1, j+1, value[i*3+j])) - self.setProperties(name, *inputs) + self.set_properties(name, *inputs) # TODO: Implement matrix operations for tensors, refer to the OpenFOAM team for details # TODO: Change the way input is taken in this method, refer Matlab's matrix slicing --done - def setProperties(self, name: str, *args: (int, int, PropertyFloat)) -> None: + def set_properties(self, name: str, *args: (int, int, Flt_P)) -> None: ''' Function to edit the values stored in the object @@ -44,16 +44,16 @@ def setProperties(self, name: str, *args: (int, int, PropertyFloat)) -> None: name: The name of the property. *args: The values of the tensor in the form of tuples. - The tuples should be in the form of (i, j, PropertyFloat) where i and j are the indices of the tensor in 1-based indexing. + The tuples should be in the form of (i, j, Flt_P) where i and j are the indices of the tensor in 1-based indexing. In order to set the value for an entire row or column, set the index to 0 for the row or column respectively. Example: - To set the value of the entire row 1 to 5, the tuple should be (1, 0, PropertyFloat(name, 5)) - To set the value of the entire column 2 to 5, the tuple should be (0, 2, PropertyFloat(name, 5)) - To set the value of the element at row 1 and column 2 to 5, the tuple should be (1, 2, PropertyFloat(name, 5)) + To set the value of the entire row 1 to 5, the tuple should be (1, 0, Flt_P(name, 5)) + To set the value of the entire column 2 to 5, the tuple should be (0, 2, Flt_P(name, 5)) + To set the value of the element at row 1 and column 2 to 5, the tuple should be (1, 2, Flt_P(name, 5)) ''' - self._ValueProperty__name = name + self._Value_P__name = name inputs = list(args) self.__values = [[0, 0, 0], @@ -61,7 +61,7 @@ def setProperties(self, name: str, *args: (int, int, PropertyFloat)) -> None: [0, 0, 0]] for t in inputs: - if len(t) != 3 or type(t[0]) != int or type(t[1]) != int or type(t[2]) != PropertyFloat: + if len(t) != 3 or type(t[0]) != int or type(t[1]) != int or type(t[2]) != Flt_P: raise InvalidTupleError(t) else: if t[0] == 0 and t[1] == 0: @@ -80,89 +80,89 @@ def setProperties(self, name: str, *args: (int, int, PropertyFloat)) -> None: else: raise InvalidTupleError(t) - def xx(self) -> PropertyFloat: + def xx(self) -> Flt_P: ''' Returns the xx value of the tensor ''' - return self.__values[0][0].giveVal() + return self.__values[0][0].give_val() - def xy(self) -> PropertyFloat: + def xy(self) -> Flt_P: ''' Returns the xy value of the tensor ''' - return self.__values[0][1].giveVal() + return self.__values[0][1].give_val() - def xz(self) -> PropertyFloat: + def xz(self) -> Flt_P: ''' Returns the xz value of the tensor ''' - return self.__values[0][2].giveVal() + return self.__values[0][2].give_val() - def yx(self) -> PropertyFloat: + def yx(self) -> Flt_P: ''' Returns the yx value of the tensor ''' - return self.__values[1][0].giveVal() + return self.__values[1][0].give_val() - def yy(self) -> PropertyFloat: + def yy(self) -> Flt_P: ''' Returns the yy value of the tensor ''' - return self.__values[1][1].giveVal() + return self.__values[1][1].give_val() - def yz(self) -> PropertyFloat: + def yz(self) -> Flt_P: ''' Returns the yz value of the tensor ''' - return self.__values[1][2].giveVal() + return self.__values[1][2].give_val() - def zx(self) -> PropertyFloat: + def zx(self) -> Flt_P: ''' Returns the zx value of the tensor ''' - return self.__values[2][0].giveVal() + return self.__values[2][0].give_val() - def zy(self) -> PropertyFloat: + def zy(self) -> Flt_P: ''' Returns the zy value of the tensor ''' - return self.__values[2][1].giveVal() + return self.__values[2][1].give_val() - def zz(self) -> PropertyFloat: + def zz(self) -> Flt_P: ''' Returns the zz value of the tensor ''' - return self.__values[2][2].giveVal() + return self.__values[2][2].give_val() - def row(self, r: int) -> PropertyVector: + def row(self, r: int) -> Vector_P: ''' Returns the row vector of the tensor Parameters: r: The row number of the tensor in 1 based indexing ''' - return PropertyVector(self._ValueProperty__name + "_row", self.__values[r - 1][0], self.__values[r - 1][1], self.__values[r - 1][2]) + return Vector_P(self._Value_P__name + "_row", self.__values[r - 1][0], self.__values[r - 1][1], self.__values[r - 1][2]) - def col(self, c: int) -> PropertyVector: + def col(self, c: int) -> Vector_P: ''' Returns the column vector of the tensor Parameters: c: The column number of the tensor in 1 based indexing ''' - return PropertyVector(self._ValueProperty__name + "_col", self.__values[0][c - 1], self.__values[1][c - 1], self.__values[2][c - 1]) + return Vector_P(self._Value_P__name + "_col", self.__values[0][c - 1], self.__values[1][c - 1], self.__values[2][c - 1]) - def diag(self) -> PropertyVector: + def diag(self) -> Vector_P: ''' Returns the diagonal vector of the tensor ''' - return PropertyVector(self._ValueProperty__name + "_diag", self.__values[0][0], self.__values[1][1], self.__values[2][2]) + return Vector_P(self._Value_P__name + "_diag", self.__values[0][0], self.__values[1][1], self.__values[2][2]) def T(self) -> Self: ''' Return non-Hermitian transpose of the tensor ''' - return PropertyTensor(self._ValueProperty__name + "_T", [self.__values[0][0], self.__values[1][0], self.__values[2][0], + return Tensor_P(self._Value_P__name + "_T", [self.__values[0][0], self.__values[1][0], self.__values[2][0], self.__values[0][1], self.__values[1][1], self.__values[2][1], self.__values[0][2], self.__values[1][2], self.__values[2][2]]) @@ -170,13 +170,13 @@ def inv(self) -> Self: ''' Returns the inverse of the tensor ''' - ar = np.array([[self.xx().giveVal(), self.xy().giveVal(), self.xz().giveVal()], - [self.yx().giveVal(), self.yy().giveVal(), self.yz().giveVal()], - [self.zx().giveVal(), self.zy().giveVal(), self.zz().giveVal()]]) + ar = np.array([[self.xx().give_val(), self.xy().give_val(), self.xz().give_val()], + [self.yx().give_val(), self.yy().give_val(), self.yz().give_val()], + [self.zx().give_val(), self.zy().give_val(), self.zz().give_val()]]) res = np.linalg.inv(ar) - return PropertyTensor(self._ValueProperty__name + "_inv", [res[0][0], res[0][1], res[0][2], + return Tensor_P(self._Value_P__name + "_inv", [res[0][0], res[0][1], res[0][2], res[1][0], res[1][1], res[1][2], res[2][0], res[2][1], res[2][2]]) @@ -184,7 +184,7 @@ def inner(self, t: Self) -> Self: ''' Returns the inner product of the tensor with another tensor ''' - return PropertyTensor(self._ValueProperty__name + "_inner", [self.xx()*t.xx() + self.xy()*t.yx() + self.xz()*t.zx(), + return Tensor_P(self._Value_P__name + "_inner", [self.xx()*t.xx() + self.xy()*t.yx() + self.xz()*t.zx(), self.xx()*t.xy() + self.xy()*t.yy() + self.xz()*t.zy(), self.xx()*t.xz() + self.xy()*t.yz() + self.xz()*t.zz(), @@ -200,11 +200,11 @@ def schur(self, t: Self) -> Self: ''' Returns the Schur product of the tensor with another tensor ''' - return PropertyTensor(self._ValueProperty__name + "_schur", [self.xx()*t.xx(), self.xy()*t.xy(), self.xz()*t.xz(), + return Tensor_P(self._Value_P__name + "_schur", [self.xx()*t.xx(), self.xy()*t.xy(), self.xz()*t.xz(), self.yx()*t.yx(), self.yy()*t.yy(), self.yz()*t.yz(), self.zx()*t.zx(), self.zy()*t.zy(), self.zz()*t.zz()]) - def giveVal(self): + def give_val(self): ''' Returns the tensor value ''' @@ -213,17 +213,17 @@ def giveVal(self): self.zx(), self.zy(), self.zz()) return res - def writeOut(self, file): + def write_out(self, file): ''' Writes the tensor value to a file Parameters: file: The file object to write the value to ''' - file.write(f"{self.giveVal()}") + file.write(f"{self.give_val()}") def __repr__(self): - return f"PropertyTensor(name = {self._ValueProperty__name}, xx = {self.xx()}, xy = {self.xy()}, xz = {self.xz()}, yx = {self.yx()}, yy = {self.yy()}, yz = {self.yz()}, zx = {self.zx()}, zy = {self.zy()}, zz = {self.zz()})" + return f"Tensor_P(name = {self._Value_P__name}, xx = {self.xx()}, xy = {self.xy()}, xz = {self.xz()}, yx = {self.yx()}, yy = {self.yy()}, yz = {self.yz()}, zx = {self.zx()}, zy = {self.zy()}, zz = {self.zz()})" diff --git a/pyvnt/Reference/vector.py b/pyvnt/Reference/vector.py index 8544c32..4ce32ee 100644 --- a/pyvnt/Reference/vector.py +++ b/pyvnt/Reference/vector.py @@ -2,39 +2,39 @@ from typing import Self import math -class PropertyVector(ValueProperty): +class Vector_P(Value_P): ''' Property Class to store vector values Constructor Parameters: name: Name of the property of which vector value is to be stored - x: PropertyFloat object to store x value of the vector - y: PropertyFloat object to store y value of the vector - z: PropertyFloat object to store z value of the vector + x: Flt_P object to store x value of the vector + y: Flt_P object to store y value of the vector + z: Flt_P object to store z value of the vector ''' - __slots__ = ('_ValueProperty__name', '_PropertyVector__x', '_PropertyVector__y', '_PropertyVector__z') + __slots__ = ('_Value_P__name', '_Vector_P__x', '_Vector_P__y', '_Vector_P__z') def instance_restricted(self): pass # TODO: Confirm about the format exoected from a vector - def __init__(self, name: str, x: PropertyFloat, y: PropertyFloat, z: PropertyFloat): - super(PropertyVector, self).__init__() - self.setProperties(name, x, y, z) + def __init__(self, name: str, x: Flt_P, y: Flt_P, z: Flt_P): + super(Vector_P, self).__init__() + self.set_properties(name, x, y, z) - def setProperties(self, name: str = None, x: PropertyFloat = None, y: PropertyFloat = None, z: PropertyFloat = None) -> None: + def set_properties(self, name: str = None, x: Flt_P = None, y: Flt_P = None, z: Flt_P = None) -> None: ''' Function to edit the values stored in the object Parameters: name: Name of the property of which vector value is to be stored - x: PropertyFloat object to store x value of the vector - y: PropertyFloat object to store y value of the vector - z: PropertyFloat object to store z value of the vector + x: Flt_P object to store x value of the vector + y: Flt_P object to store y value of the vector + z: Flt_P object to store z value of the vector ''' if name: - self._ValueProperty__name = name + self._Value_P__name = name if x: self.__x = x @@ -50,27 +50,27 @@ def x(self) -> float: Returns the x value of the vector ''' - return self.__x.giveVal() + return self.__x.give_val() def y(self) -> float: ''' Returns the y value of the vector ''' - return self.__y.giveVal() + return self.__y.give_val() def z(self) -> float: ''' Returns the z value of the vector ''' - return self.__z.giveVal() + return self.__z.give_val() def magnitude(self) -> float: ''' Returns the magnitude of the vector ''' - return math.sqrt(self.__x.giveVal()**2 + self.__y.giveVal()**2 + self.__z.giveVal()**2) + return math.sqrt(self.__x.give_val()**2 + self.__y.give_val()**2 + self.__z.give_val()**2) - def normalise(self, tol: PropertyFloat) -> Self: + def normalise(self, tol: Flt_P) -> Self: ''' Normalises the vector @@ -78,26 +78,26 @@ def normalise(self, tol: PropertyFloat) -> Self: tol: The tolerance value for the normalisation. If the magnitude of the vector is less than the tolerance, the vector is set to 0. ''' s = self.magnitude() - if s < tol.giveVal(): - self.setProperties(self._ValueProperty__name, PropertyFloat(self._ValueProperty__name + "_x", 0), PropertyFloat(self._ValueProperty__name + "_y", 0), PropertyFloat(self._ValueProperty__name + "_z", 0)) + if s < tol.give_val(): + self.set_properties(self._Value_P__name, Flt_P(self._Value_P__name + "_x", 0), Flt_P(self._Value_P__name + "_y", 0), Flt_P(self._Value_P__name + "_z", 0)) else: - self.setProperties(self._ValueProperty__name, PropertyFloat(self._ValueProperty__name + "_x", self.__x.giveVal()/s), PropertyFloat(self._ValueProperty__name + "_y", self.__y.giveVal()/s), PropertyFloat(self._ValueProperty__name + "_z", self.__z.giveVal()/s)) + self.set_properties(self._Value_P__name, Flt_P(self._Value_P__name + "_x", self.__x.give_val()/s), Flt_P(self._Value_P__name + "_y", self.__y.give_val()/s), Flt_P(self._Value_P__name + "_z", self.__z.give_val()/s)) return self - def giveVal(self): + def give_val(self): ''' Returns the vector value ''' - res = (self.__x.giveVal(), self.__y.giveVal(), self.__z.giveVal()) + res = (self.__x.give_val(), self.__y.give_val(), self.__z.give_val()) return res - def writeOut(self, file): + def write_out(self, file): ''' Returns the vector value in a string format ''' - file.write( f"({self.__x.giveVal()} {self.__y.giveVal()} {self.__z.giveVal()})") + file.write( f"({self.__x.give_val()} {self.__y.give_val()} {self.__z.give_val()})") def __repr__(self): - return f"PropertyVector(name = {self._ValueProperty__name}, x = {self.__x.giveVal()}, y = {self.__y.giveVal()}, z = {self.__z.giveVal()})" \ No newline at end of file + return f"Vector_P(name = {self._Value_P__name}, x = {self.__x.give_val()}, y = {self.__y.give_val()}, z = {self.__z.give_val()})" \ No newline at end of file diff --git a/pyvnt/__init__.py b/pyvnt/__init__.py index 7b27ca0..9b0b864 100755 --- a/pyvnt/__init__.py +++ b/pyvnt/__init__.py @@ -1,11 +1,11 @@ from pyvnt.Reference.basic import * from pyvnt.Reference.vector import * from pyvnt.Reference.tensor import * -from pyvnt.Reference.dimSet import DimmSet -from pyvnt.DictionaryElement.foamDS import * -from pyvnt.DictionaryElement.keyData import * -from pyvnt.DictionaryElement.list import * +from pyvnt.Reference.dimension_set import Dim_Set_P +from pyvnt.Container.Node_C import * +from pyvnt.Container.Key_C import * +from pyvnt.Container.list import * from pyvnt.Converter.Writer.writer import * from pyvnt.utils import * -from pyvnt.utils.showTree import * +from pyvnt.utils.show_tree import * diff --git a/pyvnt/utils/makeIndent.py b/pyvnt/utils/make_indent.py similarity index 60% rename from pyvnt/utils/makeIndent.py rename to pyvnt/utils/make_indent.py index 041f5ef..f10b211 100644 --- a/pyvnt/utils/makeIndent.py +++ b/pyvnt/utils/make_indent.py @@ -1,5 +1,5 @@ -def makeIndent(file, indent: int): +def make_indent(file, indent: int): for i in range(indent): file.write("\t") \ No newline at end of file diff --git a/pyvnt/utils/showTree.py b/pyvnt/utils/show_tree.py similarity index 83% rename from pyvnt/utils/showTree.py rename to pyvnt/utils/show_tree.py index 096b1a1..4c2ddf9 100755 --- a/pyvnt/utils/showTree.py +++ b/pyvnt/utils/show_tree.py @@ -1,7 +1,7 @@ from anytree import Node, RenderTree, AsciiStyle, NodeMixin -from pyvnt.DictionaryElement.foamDS import Foam +from pyvnt.Container.Node_C import Foam -def showTree(head: Foam): +def show_tree(head: Foam): ''' Function to output the entire tree in the terminal starting from the current node object @@ -16,7 +16,7 @@ def showTree(head: Foam): attr = "%s{ \n" % (fill) for d in node.data: - tmp_str = u"%s %s" % (fill, d.giveVal()) + tmp_str = u"%s %s" % (fill, d.give_val()) attr = attr + tmp_str + "\n" attr = attr + "%s}"%(fill) diff --git a/tests/test_basic.py b/tests/test_basic.py index acfbea4..624e3b4 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -5,8 +5,8 @@ class TestEnum: def setup_method(self, method): self.items = {'PCG', 'PBiCG', 'PBiCGStab'} - self.eprop2 = basic.EnumProp('val2', items=self.items, default='PBiCG') - self.eprop1 = basic.EnumProp('val1', items=self.items, default='PCG') + self.eprop2 = basic.Enm_P('val2', items=self.items, default='PBiCG') + self.eprop1 = basic.Enm_P('val1', items=self.items, default='PCG') def teardown_method(self, method): del self.eprop1 @@ -14,12 +14,12 @@ def teardown_method(self, method): del self.items def test_enum_print(self): - assert str(self.eprop1) == f"EnumProp(name = val1, items = {self.items}, default = PCG)" - assert str(self.eprop2) == f"EnumProp(name = val2, items = {self.items}, default = PBiCG)" + assert str(self.eprop1) == f"Enm_P(name = val1, items = {self.items}, default = PCG)" + assert str(self.eprop2) == f"Enm_P(name = val2, items = {self.items}, default = PBiCG)" def test_enum_val(self): - assert self.eprop1.giveVal() == 'PCG' - assert self.eprop2.giveVal() == 'PBiCG' + assert self.eprop1.give_val() == 'PCG' + assert self.eprop2.give_val() == 'PBiCG' def test_enum_items(self): assert self.eprop1.get_items() == self.items @@ -27,24 +27,24 @@ def test_enum_items(self): def test_enum_edit(self): dummy_items = {'PCG', 'PBiCG', 'GMRES'} - self.eprop1.setProperties('val1', dummy_items, 'PCG') + self.eprop1.set_properties('val1', dummy_items, 'PCG') assert self.eprop1.get_items() == dummy_items - assert self.eprop1.giveVal() == 'PCG' + assert self.eprop1.give_val() == 'PCG' def test_enum_edit_fail(self): dummy_items = {'PCG', 'PBiCG', 'GMRES'} with pytest.raises(basic.DefaultOutofRangeError): - self.eprop1.setProperties('val1', dummy_items, 'PBiCGStab') + self.eprop1.set_properties('val1', dummy_items, 'PBiCGStab') with pytest.raises(basic.NotSetType): - self.eprop1.setProperties('val1', 'PCG', 'PCG') + self.eprop1.set_properties('val1', 'PCG', 'PCG') with pytest.raises(basic.NotStringType): - self.eprop1.setProperties('val1', {1, 2, 3}, 'PCG') + self.eprop1.set_properties('val1', {1, 2, 3}, 'PCG') def test_enum_change(self): self.eprop1.set_default('PBiCG') - assert self.eprop1.giveVal() == 'PBiCG' + assert self.eprop1.give_val() == 'PBiCG' def test_enum_change_fail(self): with pytest.raises(basic.ValueOutofRangeError): @@ -60,56 +60,56 @@ def test_enum_remove_fail(self): class TestInt: def setup_method(self, method): - self.iprop1 = basic.PropertyInt('val1', 5, 1, 10) - self.iprop2 = basic.PropertyInt('val2', 100, -100, 1000) + self.iprop1 = basic.Int_P('val1', 5, 1, 10) + self.iprop2 = basic.Int_P('val2', 100, -100, 1000) def teardown_method(self, method): del self.iprop1 del self.iprop2 def test_int_print(self): - assert str(self.iprop1) == f"PropertyInt(name = val1, default = 5, minimum = 1, maximum = 10)" - assert str(self.iprop2) == f"PropertyInt(name = val2, default = 100, minimum = -100, maximum = 1000)" + assert str(self.iprop1) == f"Int_P(name = val1, default = 5, minimum = 1, maximum = 10)" + assert str(self.iprop2) == f"Int_P(name = val2, default = 100, minimum = -100, maximum = 1000)" def test_int_edit(self): - self.iprop1.setProperties('val1', 10, 1, 10) - assert self.iprop1.giveVal() == 10 + self.iprop1.set_properties('val1', 10, 1, 10) + assert self.iprop1.give_val() == 10 def test_int_edit_fail(self): with pytest.raises(basic.DefaultOutofRangeError): - self.iprop1.setProperties('val1', 0, 1, 10) + self.iprop1.set_properties('val1', 0, 1, 10) with pytest.raises(basic.InvalidRangeError): - self.iprop1.setProperties('val1', 2, 5, 1) + self.iprop1.set_properties('val1', 2, 5, 1) def test_int_val(self): - assert self.iprop1.giveVal() == 5 - assert self.iprop2.giveVal() == 100 + assert self.iprop1.give_val() == 5 + assert self.iprop2.give_val() == 100 class TestFloat: def setup_method(self, method): - self.fprop1 = basic.PropertyFloat('val1', 5.0, 1.0, 10.0) - self.fprop2 = basic.PropertyFloat('val2', 100.0, -100.0, 1000.0) + self.fprop1 = basic.Flt_P('val1', 5.0, 1.0, 10.0) + self.fprop2 = basic.Flt_P('val2', 100.0, -100.0, 1000.0) def teardown_method(self, method): del self.fprop1 del self.fprop2 def test_float_print(self): - assert str(self.fprop1) == f"PropertyFloat(name = val1, default = 5.0, minimum = 1.0, maximum = 10.0)" - assert str(self.fprop2) == f"PropertyFloat(name = val2, default = 100.0, minimum = -100.0, maximum = 1000.0)" + assert str(self.fprop1) == f"Flt_P(name = val1, default = 5.0, minimum = 1.0, maximum = 10.0)" + assert str(self.fprop2) == f"Flt_P(name = val2, default = 100.0, minimum = -100.0, maximum = 1000.0)" def test_float_edit(self): - self.fprop1.setProperties('val1', 10.0, 1.0, 10.0) - assert self.fprop1.giveVal() == 10.0 + self.fprop1.set_properties('val1', 10.0, 1.0, 10.0) + assert self.fprop1.give_val() == 10.0 def test_float_edit_fail(self): with pytest.raises(basic.DefaultOutofRangeError): - self.fprop1.setProperties('val1', 0.0, 1.0, 10.0) + self.fprop1.set_properties('val1', 0.0, 1.0, 10.0) with pytest.raises(basic.InvalidRangeError): - self.fprop1.setProperties('val1', 2.0, 5.0, 1.0) + self.fprop1.set_properties('val1', 2.0, 5.0, 1.0) def test_float_val(self): - assert self.fprop1.giveVal() == 5.0 - assert self.fprop2.giveVal() == 100.0 \ No newline at end of file + assert self.fprop1.give_val() == 5.0 + assert self.fprop2.give_val() == 100.0 \ No newline at end of file diff --git a/tests/test_dimm.py b/tests/test_dimm.py index c1312c8..586e043 100644 --- a/tests/test_dimm.py +++ b/tests/test_dimm.py @@ -5,25 +5,25 @@ class TestDimm: def setup_method(self, method): self.dimms = [1, 2, 3, 4, 5, 6, 7] - self.dset = DimmSet('test', self.dimms) + self.dset = Dim_Set_P('test', self.dimms) def teardown_method(self, method): del self.dset del self.dimms def test_dimm_print(self): - assert str(self.dset) == f"DimmSet(name : test, dimm : {self.dimms})" + assert str(self.dset) == f"Dim_Set_P(name : test, dimm : {self.dimms})" def test_dimm_val(self): - assert self.dset.giveVal() == self.dimms + assert self.dset.give_val() == self.dimms def test_dimm_edit(self): dummy_dimms = [1, 2, 3, 4, 5, 6, 7] - self.dset.setProperties(*dummy_dimms) - assert self.dset.giveVal() == dummy_dimms + self.dset.set_properties(*dummy_dimms) + assert self.dset.give_val() == dummy_dimms def test_dimm_edit_fail(self): dummy_dimms = [1, 2, 3, 4, 5, 6, 7, 8] with pytest.raises(TypeError): - self.dset.setProperties(*dummy_dimms) + self.dset.set_properties(*dummy_dimms) diff --git a/tests/test_key.py b/tests/test_key.py new file mode 100644 index 0000000..31cdc25 --- /dev/null +++ b/tests/test_key.py @@ -0,0 +1,57 @@ +import pytest + +import pyvnt.Container.Key_C as Key_C +from pyvnt.Reference.basic import * + +class TestKey_C: + def setup_method(self, method): + self.items = {'PCG', 'PBiCG', 'PBiCGStab'} + self.prop2 = Enm_P('val2', items=self.items, default='PBiCG') + self.prop1 = Enm_P('val1', items=self.items, default='PCG') + self.key1 = Key_C.Key_C('solver', self.prop1, self.prop2) + + def teardown_method(self, method): + del self.key1 + del self.prop1 + del self.prop2 + del self.items + + def test_Key_C_print(self): + assert str(self.key1) == f"Key_C(val1 : {str(self.prop1)}, val2 : {str(self.prop2)})" + + def test_Key_C_val(self): + assert self.key1.give_val() == f"solver : {self.prop1.give_val()}, {self.prop2.give_val()}" + + def test_Key_C_edit(self): + tmp_prop1 = Int_P('tmpval1', 2, 1, 10) + tmp_prop2 = Int_P('tmpval2', 3, 1, 10) + + self.key1.replace_val('val1', tmp_prop1) + assert self.key1.give_val() == f"solver : {tmp_prop1.give_val()}, {self.prop2.give_val()}" + + self.key1.replace_val(self.prop2, tmp_prop2) + assert self.key1.give_val() == f"solver : {tmp_prop1.give_val()}, {tmp_prop2.give_val()}" + + tmp_prop3 = Int_P('tmpval2', 4, 1, 10) + + self.key1.replace_val(tmp_prop2, tmp_prop3) + assert self.key1.give_val() == f"solver : {tmp_prop1.give_val()}, {tmp_prop3.give_val()}" + + def test_Key_C_edit_fail(self): + tmp_prop1 = Int_P('tmpval1', 2, 1, 10) + tmp_prop2 = Int_P('tmpval2', 3, 1, 10) + tmp_prop3 = Int_P('tmpval2', 4, 1, 10) + + with pytest.raises(Key_C.KeyRepeatError): + self.key1.replace_val('val1', tmp_prop1) + self.key1.replace_val('val2', tmp_prop1) + + with pytest.raises(Key_C.KeyRepeatError): + self.key1.replace_val('val2', tmp_prop2) + self.key1.replace_val('val2', tmp_prop3) + + def test_Key_C_del(self): + self.key1.delete_val('val1') + assert self.key1.give_val() == f"solver : {self.prop2.give_val()}" + + \ No newline at end of file diff --git a/tests/test_keyData.py b/tests/test_keyData.py deleted file mode 100644 index ac715fd..0000000 --- a/tests/test_keyData.py +++ /dev/null @@ -1,57 +0,0 @@ -import pytest - -import pyvnt.DictionaryElement.keyData as keyData -from pyvnt.Reference.basic import * - -class TestKeyData: - def setup_method(self, method): - self.items = {'PCG', 'PBiCG', 'PBiCGStab'} - self.prop2 = EnumProp('val2', items=self.items, default='PBiCG') - self.prop1 = EnumProp('val1', items=self.items, default='PCG') - self.key1 = keyData.KeyData('solver', self.prop1, self.prop2) - - def teardown_method(self, method): - del self.key1 - del self.prop1 - del self.prop2 - del self.items - - def test_keyData_print(self): - assert str(self.key1) == f"KeyData(val1 : {str(self.prop1)}, val2 : {str(self.prop2)})" - - def test_keyData_val(self): - assert self.key1.giveVal() == f"solver : {self.prop1.giveVal()}, {self.prop2.giveVal()}" - - def test_keyData_edit(self): - tmp_prop1 = PropertyInt('tmpval1', 2, 1, 10) - tmp_prop2 = PropertyInt('tmpval2', 3, 1, 10) - - self.key1.replaceVal('val1', tmp_prop1) - assert self.key1.giveVal() == f"solver : {tmp_prop1.giveVal()}, {self.prop2.giveVal()}" - - self.key1.replaceVal(self.prop2, tmp_prop2) - assert self.key1.giveVal() == f"solver : {tmp_prop1.giveVal()}, {tmp_prop2.giveVal()}" - - tmp_prop3 = PropertyInt('tmpval2', 4, 1, 10) - - self.key1.replaceVal(tmp_prop2, tmp_prop3) - assert self.key1.giveVal() == f"solver : {tmp_prop1.giveVal()}, {tmp_prop3.giveVal()}" - - def test_keyData_edit_fail(self): - tmp_prop1 = PropertyInt('tmpval1', 2, 1, 10) - tmp_prop2 = PropertyInt('tmpval2', 3, 1, 10) - tmp_prop3 = PropertyInt('tmpval2', 4, 1, 10) - - with pytest.raises(keyData.KeyRepeatError): - self.key1.replaceVal('val1', tmp_prop1) - self.key1.replaceVal('val2', tmp_prop1) - - with pytest.raises(keyData.KeyRepeatError): - self.key1.replaceVal('val2', tmp_prop2) - self.key1.replaceVal('val2', tmp_prop3) - - def test_keyData_del(self): - self.key1.delVal('val1') - assert self.key1.giveVal() == f"solver : {self.prop2.giveVal()}" - - \ No newline at end of file diff --git a/tests/test_list.py b/tests/test_list.py index e3060cf..a9465d8 100644 --- a/tests/test_list.py +++ b/tests/test_list.py @@ -4,15 +4,15 @@ class TestList: def setup_method(self, method): - self.hprop1 = PropertyFloat('val1', default=1) - self.hprop2 = PropertyFloat('val2', default=2) - self.hprop3 = PropertyFloat('val3', default=3) - self.hprop4 = PropertyFloat('val4', default=4) - self.hprop5 = PropertyFloat('val5', default=5) - self.hprop6 = PropertyFloat('val6', default=6) + self.hprop1 = Flt_P('val1', default=1) + self.hprop2 = Flt_P('val2', default=2) + self.hprop3 = Flt_P('val3', default=3) + self.hprop4 = Flt_P('val4', default=4) + self.hprop5 = Flt_P('val5', default=5) + self.hprop6 = Flt_P('val6', default=6) - self.lp1 = PropertyList('list1', 3, elems = [[self.hprop1, self.hprop2, self.hprop3]]) - self.lp2 = PropertyList('list2', 3, elems = [[self.hprop4, self.hprop5, self.hprop6]]) + self.lp1 = List_CP('list1', 3, elems = [[self.hprop1, self.hprop2, self.hprop3]]) + self.lp2 = List_CP('list2', 3, elems = [[self.hprop4, self.hprop5, self.hprop6]]) def teardown_method(self, method): del self.hprop1 @@ -30,43 +30,43 @@ def list_print(self): assert self.lp1.size() == 3 - def test_list_giveVal(self): - assert self.lp1.giveVal() == (self.hprop1.giveVal(), self.hprop2.giveVal(), self.hprop3.giveVal()) - assert self.lp2.giveVal() == (self.hprop4.giveVal(), self.hprop5.giveVal(), self.hprop6.giveVal()) + def test_list_give_val(self): + assert self.lp1.give_val() == (self.hprop1.give_val(), self.hprop2.give_val(), self.hprop3.give_val()) + assert self.lp2.give_val() == (self.hprop4.give_val(), self.hprop5.give_val(), self.hprop6.give_val()) - def test_list_getItem(self): - assert self.lp1.getItem(0, 0) == self.hprop1 - assert self.lp1.getItem(0, 1) == self.hprop2 - assert self.lp1.getItem(0, 2) == self.hprop3 + def test_list_get_item(self): + assert self.lp1.get_item(0, 0) == self.hprop1 + assert self.lp1.get_item(0, 1) == self.hprop2 + assert self.lp1.get_item(0, 2) == self.hprop3 - assert self.lp2.getItem(0, 0) == self.hprop4 - assert self.lp2.getItem(0, 1) == self.hprop5 - assert self.lp2.getItem(0, 2) == self.hprop6 + assert self.lp2.get_item(0, 0) == self.hprop4 + assert self.lp2.get_item(0, 1) == self.hprop5 + assert self.lp2.get_item(0, 2) == self.hprop6 def test_list_append_value(self): self.lp1.append_value(0, self.hprop4) - assert self.lp1.getItem(0, 3) == self.hprop4 + assert self.lp1.get_item(0, 3) == self.hprop4 def test_list_append_uniq_value(self): self.lp1.append_uniq_value(0, self.hprop4) - assert self.lp1.getItem(0, 3) == self.hprop4 + assert self.lp1.get_item(0, 3) == self.hprop4 with pytest.raises(KeyRepeatError): self.lp1.append_uniq_value(0, self.hprop4) def test_list_append_elem(self): self.lp1.append_elem([self.hprop4, self.hprop5, self.hprop6]) - self.lp1.getItem(1, 0) - assert self.lp1.getItem(1, 0) == self.hprop4 - assert self.lp1.getItem(1, 1) == self.hprop5 - assert self.lp1.getItem(1, 2) == self.hprop6 + self.lp1.get_item(1, 0) + assert self.lp1.get_item(1, 0) == self.hprop4 + assert self.lp1.get_item(1, 1) == self.hprop5 + assert self.lp1.get_item(1, 2) == self.hprop6 def test_list_append_uniq_elem(self): self.lp1.append_uniq_elem([self.hprop4, self.hprop5, self.hprop6]) - assert self.lp1.getItem(1, 0) == self.hprop4 - assert self.lp1.getItem(1, 1) == self.hprop5 - assert self.lp1.getItem(1, 2) == self.hprop6 + assert self.lp1.get_item(1, 0) == self.hprop4 + assert self.lp1.get_item(1, 1) == self.hprop5 + assert self.lp1.get_item(1, 2) == self.hprop6 with pytest.raises(KeyRepeatError): self.lp1.append_uniq_elem([self.hprop4, self.hprop5, self.hprop6]) diff --git a/tests/test_node.py b/tests/test_node.py index 8c0fa32..6a4c471 100644 --- a/tests/test_node.py +++ b/tests/test_node.py @@ -6,11 +6,11 @@ class TestNode: def setup_method(self, method): self.items = {'PCG', 'PBiCG', 'PBiCGStab'} - self.eprop2 = EnumProp('val2', items=self.items, default='PBiCG') - self.eprop1 = EnumProp('val1', items=self.items, default='PCG') + self.eprop2 = Enm_P('val2', items=self.items, default='PBiCG') + self.eprop1 = Enm_P('val1', items=self.items, default='PCG') - self.key1 = KeyData('solver', self.eprop1, self.eprop2) - self.key2 = KeyData('solver2', self.eprop2, self.eprop1) + self.key1 = Key_C('solver', self.eprop1, self.eprop2) + self.key2 = Key_C('solver2', self.eprop2, self.eprop1) self.head = Foam("test_head", None, None) self.chld1 = Foam("test_child", self.head, None, self.key2) @@ -28,25 +28,25 @@ def test_node_print(self): assert str(self.head) == f"Foam(name : test_head, parent : None, children : ({self.chld1}, {self.chld2}, ), data : ({self.key1}, ), )" def test_node_add_child(self): - self.head.addChild(self.chld2) + self.head.add_child(self.chld2) assert self.head.children == (self.chld1, self.chld2, ) def test_node_set_parent(self): - self.chld2.setParent(self.head) + self.chld2.set_Parent(self.head) assert self.chld2.parent == self.head def test_node_get_child(self): - assert self.head.getChild('test_child') == self.chld1 + assert self.head.get_child('test_child') == self.chld1 def test_node_add_data(self): - self.chld2.addData(self.key2) + self.chld2.add_data(self.key2) assert self.chld2.data == [self.key2] - self.chld2.addData(self.key1, 0) + self.chld2.add_data(self.key1, 0) assert self.chld2.data == [self.key1, self.key2] def test_node_remove_data(self): - self.chld1.removeData(self.key2) + self.chld1.remove_data(self.key2) assert self.chld1.data == [] @pytest.mark.skip(reason = 'Complex to test') diff --git a/tests/test_tensor.py b/tests/test_tensor.py index cc72b59..d6de684 100644 --- a/tests/test_tensor.py +++ b/tests/test_tensor.py @@ -2,18 +2,18 @@ class TestTensor: def setup_method(self, method): - self.hprop1 = PropertyFloat('val1', default=1) - self.hprop2 = PropertyFloat('val2', default=2) - self.hprop3 = PropertyFloat('val3', default=3) - self.hprop4 = PropertyFloat('val4', default=4) - self.hprop5 = PropertyFloat('val5', default=5) - self.hprop6 = PropertyFloat('val6', default=6) - self.hprop7 = PropertyFloat('val7', default=7) - self.hprop8 = PropertyFloat('val8', default=8) - self.hprop9 = PropertyFloat('val9', default=9) + self.hprop1 = Flt_P('val1', default=1) + self.hprop2 = Flt_P('val2', default=2) + self.hprop3 = Flt_P('val3', default=3) + self.hprop4 = Flt_P('val4', default=4) + self.hprop5 = Flt_P('val5', default=5) + self.hprop6 = Flt_P('val6', default=6) + self.hprop7 = Flt_P('val7', default=7) + self.hprop8 = Flt_P('val8', default=8) + self.hprop9 = Flt_P('val9', default=9) - self.tprop1 = PropertyTensor('val1', [self.hprop1, self.hprop2, self.hprop3, self.hprop4, self.hprop5, self.hprop6, self.hprop7, self.hprop8, self.hprop9]) - self.tprop2 = PropertyTensor('val2', [self.hprop4, self.hprop5, self.hprop6, self.hprop7, self.hprop8, self.hprop9, self.hprop1, self.hprop2, self.hprop3]) + self.tprop1 = Tensor_P('val1', [self.hprop1, self.hprop2, self.hprop3, self.hprop4, self.hprop5, self.hprop6, self.hprop7, self.hprop8, self.hprop9]) + self.tprop2 = Tensor_P('val2', [self.hprop4, self.hprop5, self.hprop6, self.hprop7, self.hprop8, self.hprop9, self.hprop1, self.hprop2, self.hprop3]) def teardown_method(self, method): del self.tprop1 @@ -42,19 +42,19 @@ def test_val_returns(self): assert self.tprop1.zz() == 9 def test_tensor_print(self): - assert str(self.tprop1) == f"PropertyTensor(name = val1, xx = 1, xy = 2, xz = 3, yx = 4, yy = 5, yz = 6, zx = 7, zy = 8, zz = 9)" - assert str(self.tprop2) == f"PropertyTensor(name = val2, xx = 4, xy = 5, xz = 6, yx = 7, yy = 8, yz = 9, zx = 1, zy = 2, zz = 3)" + assert str(self.tprop1) == f"Tensor_P(name = val1, xx = 1, xy = 2, xz = 3, yx = 4, yy = 5, yz = 6, zx = 7, zy = 8, zz = 9)" + assert str(self.tprop2) == f"Tensor_P(name = val2, xx = 4, xy = 5, xz = 6, yx = 7, yy = 8, yz = 9, zx = 1, zy = 2, zz = 3)" def test_row(self): - assert str(self.tprop1.row(1)) == f"PropertyVector(name = val1_row, x = 1, y = 2, z = 3)" - assert str(self.tprop1.row(2)) == f"PropertyVector(name = val1_row, x = 4, y = 5, z = 6)" - assert str(self.tprop1.row(3)) == f"PropertyVector(name = val1_row, x = 7, y = 8, z = 9)" + assert str(self.tprop1.row(1)) == f"Vector_P(name = val1_row, x = 1, y = 2, z = 3)" + assert str(self.tprop1.row(2)) == f"Vector_P(name = val1_row, x = 4, y = 5, z = 6)" + assert str(self.tprop1.row(3)) == f"Vector_P(name = val1_row, x = 7, y = 8, z = 9)" def test_col(self): - assert str(self.tprop1.col(1)) == f"PropertyVector(name = val1_col, x = 1, y = 4, z = 7)" - assert str(self.tprop1.col(2)) == f"PropertyVector(name = val1_col, x = 2, y = 5, z = 8)" - assert str(self.tprop1.col(3)) == f"PropertyVector(name = val1_col, x = 3, y = 6, z = 9)" + assert str(self.tprop1.col(1)) == f"Vector_P(name = val1_col, x = 1, y = 4, z = 7)" + assert str(self.tprop1.col(2)) == f"Vector_P(name = val1_col, x = 2, y = 5, z = 8)" + assert str(self.tprop1.col(3)) == f"Vector_P(name = val1_col, x = 3, y = 6, z = 9)" - def test_giveVal(self): - assert self.tprop1.giveVal() == (1, 2, 3, 4, 5, 6, 7, 8, 9) - assert self.tprop2.giveVal() == (4, 5, 6, 7, 8, 9, 1, 2, 3) \ No newline at end of file + def test_give_val(self): + assert self.tprop1.give_val() == (1, 2, 3, 4, 5, 6, 7, 8, 9) + assert self.tprop2.give_val() == (4, 5, 6, 7, 8, 9, 1, 2, 3) \ No newline at end of file diff --git a/tests/test_vector.py b/tests/test_vector.py index fd93507..d21926c 100644 --- a/tests/test_vector.py +++ b/tests/test_vector.py @@ -4,16 +4,16 @@ class TestVector: def setup_method(self, method): - self.hprop1 = PropertyFloat('val1', default=1) - self.hprop2 = PropertyFloat('val2', default=2) - self.hprop3 = PropertyFloat('val3', default=3) - self.hprop4 = PropertyFloat('val4', default=4) - self.hprop5 = PropertyFloat('val5', default=5) - self.hprop6 = PropertyFloat('val6', default=6) + self.hprop1 = Flt_P('val1', default=1) + self.hprop2 = Flt_P('val2', default=2) + self.hprop3 = Flt_P('val3', default=3) + self.hprop4 = Flt_P('val4', default=4) + self.hprop5 = Flt_P('val5', default=5) + self.hprop6 = Flt_P('val6', default=6) - self.vprop1 = PropertyVector('val1', self.hprop1, self.hprop2, self.hprop3) - self.vprop2 = PropertyVector('val2', self.hprop4, self.hprop5, self.hprop6) + self.vprop1 = Vector_P('val1', self.hprop1, self.hprop2, self.hprop3) + self.vprop2 = Vector_P('val2', self.hprop4, self.hprop5, self.hprop6) def teardown_method(self, method): del self.vprop1 @@ -26,8 +26,8 @@ def teardown_method(self, method): del self.hprop6 def test_vector_print(self): - assert str(self.vprop1) == f"PropertyVector(name = val1, x = {self.hprop1.giveVal()}, y = {self.hprop2.giveVal()}, z = {self.hprop3.giveVal()})" - assert str(self.vprop2) == f"PropertyVector(name = val2, x = {self.hprop4.giveVal()}, y = {self.hprop5.giveVal()}, z = {self.hprop6.giveVal()})" + assert str(self.vprop1) == f"Vector_P(name = val1, x = {self.hprop1.give_val()}, y = {self.hprop2.give_val()}, z = {self.hprop3.give_val()})" + assert str(self.vprop2) == f"Vector_P(name = val2, x = {self.hprop4.give_val()}, y = {self.hprop5.give_val()}, z = {self.hprop6.give_val()})" def test_vector_x(self): assert self.vprop1.x() == 1 @@ -46,11 +46,11 @@ def test_vector_magnitude(self): assert self.vprop2.magnitude() == 77**0.5 def test_vector_normalise(self): - self.vprop1.normalise(PropertyFloat('tol', 0.1)) + self.vprop1.normalise(Flt_P('tol', 0.1)) assert self.vprop1.x() == 1/14**0.5 assert self.vprop1.y() == 2/14**0.5 assert self.vprop1.z() == 3/14**0.5 - def test_vector_giveVal(self): - assert self.vprop1.giveVal() == (1, 2, 3) - assert self.vprop2.giveVal() == (4, 5, 6) + def test_vector_give_val(self): + assert self.vprop1.give_val() == (1, 2, 3) + assert self.vprop2.give_val() == (4, 5, 6)