Skip to content

Commit

Permalink
Fixed naming convention for methods, classes and files
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaHobbyist committed Jul 18, 2024
1 parent 7e1529e commit 11cce23
Show file tree
Hide file tree
Showing 24 changed files with 490 additions and 490 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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),
}
</pre>
</td>
</tr>
</table>

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

Expand Down Expand Up @@ -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)

```

Expand Down
File renamed without changes.
52 changes: 26 additions & 26 deletions pyvnt/DictionaryElement/keyData.py → pyvnt/Container/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


'''
Expand All @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
'''
Expand All @@ -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(" ")

Expand Down
Loading

0 comments on commit 11cce23

Please sign in to comment.