diff --git a/Demo_case_files/cavity/0/U b/Demo_case_files/cavity/0/U new file mode 100644 index 0000000..d580641 --- /dev/null +++ b/Demo_case_files/cavity/0/U @@ -0,0 +1,39 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 9 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class volVectorField; + object U; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 1 -1 0 0 0 0]; + +internalField uniform (0 0 0); + +boundaryField +{ + movingWall + { + type fixedValue; + value uniform (1 0 0); + } + + fixedWalls + { + type noSlip; + } + + frontAndBack + { + type empty; + } +} + +// ************************************************************************* // diff --git a/Demo_case_files/cavity/0/p b/Demo_case_files/cavity/0/p new file mode 100644 index 0000000..426f760 --- /dev/null +++ b/Demo_case_files/cavity/0/p @@ -0,0 +1,38 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 9 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class volScalarField; + object p; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 2 -2 0 0 0 0]; + +internalField uniform 0; + +boundaryField +{ + movingWall + { + type zeroGradient; + } + + fixedWalls + { + type zeroGradient; + } + + frontAndBack + { + type empty; + } +} + +// ************************************************************************* // diff --git a/Demo_case_files/cavity/constant/transportProperties b/Demo_case_files/cavity/constant/transportProperties new file mode 100644 index 0000000..fa08ba5 --- /dev/null +++ b/Demo_case_files/cavity/constant/transportProperties @@ -0,0 +1,20 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 9 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + location "constant"; + object transportProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +nu [0 2 -1 0 0 0 0] 0.01; + + +// ************************************************************************* // diff --git a/Demo_case_files/cavity/system/blockMeshDict b/Demo_case_files/cavity/system/blockMeshDict new file mode 100644 index 0000000..31ba15f --- /dev/null +++ b/Demo_case_files/cavity/system/blockMeshDict @@ -0,0 +1,74 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 9 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object blockMeshDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +convertToMeters 0.1; + +vertices +( + (0 0 0) + (1 0 0) + (1 1 0) + (0 1 0) + (0 0 0.1) + (1 0 0.1) + (1 1 0.1) + (0 1 0.1) +); + +blocks +( + hex (0 1 2 3 4 5 6 7) (20 20 1) simpleGrading (1 1 1) +); + +edges +( +); + +boundary +( + movingWall + { + type wall; + faces + ( + (3 7 6 2) + ); + } + fixedWalls + { + type wall; + faces + ( + (0 4 7 3) + (2 6 5 1) + (1 5 4 0) + ); + } + frontAndBack + { + type empty; + faces + ( + (0 3 2 1) + (4 5 6 7) + ); + } +); + +mergePatchPairs +( +); + +// ************************************************************************* // diff --git a/Demo_case_files/cavity/system/controlDict b/Demo_case_files/cavity/system/controlDict new file mode 100644 index 0000000..0155e73 --- /dev/null +++ b/Demo_case_files/cavity/system/controlDict @@ -0,0 +1,48 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 9 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + location "system"; + object controlDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +application icoFoam; + +startFrom startTime; + +startTime 0; + +stopAt endTime; + +endTime 0.5; + +deltaT 0.005; + +writeControl timeStep; + +writeInterval 20; + +purgeWrite 0; + +writeFormat ascii; + +writePrecision 6; + +writeCompression off; + +timeFormat general; + +timePrecision 6; + +runTimeModifiable true; + + +// ************************************************************************* // diff --git a/Demo_case_files/cavity/system/fvSchemes b/Demo_case_files/cavity/system/fvSchemes new file mode 100644 index 0000000..56249c2 --- /dev/null +++ b/Demo_case_files/cavity/system/fvSchemes @@ -0,0 +1,50 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 9 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + location "system"; + object fvSchemes; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +ddtSchemes +{ + default Euler; +} + +gradSchemes +{ + default Gauss linear; + grad(p) Gauss linear; +} + +divSchemes +{ + default none; + div(phi,U) Gauss linear; +} + +laplacianSchemes +{ + default Gauss linear orthogonal; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default orthogonal; +} + + +// ************************************************************************* // diff --git a/Demo_case_files/cavity/system/fvSolution b/Demo_case_files/cavity/system/fvSolution new file mode 100644 index 0000000..ca3249b --- /dev/null +++ b/Demo_case_files/cavity/system/fvSolution @@ -0,0 +1,51 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 9 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + location "system"; + object fvSolution; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solvers +{ + p + { + solver PCG; + preconditioner DIC; + tolerance 1e-06; + relTol 0.05; + } + + pFinal + { + $p; + relTol 0; + } + + U + { + solver smoothSolver; + smoother symGaussSeidel; + tolerance 1e-05; + relTol 0; + } +} + +PISO +{ + nCorrectors 2; + nNonOrthogonalCorrectors 0; + pRefCell 0; + pRefValue 0; +} + + +// ************************************************************************* // diff --git a/Demo_case_files/cavity_pyvnt/system/blockMeshDict.py b/Demo_case_files/cavity_pyvnt/system/blockMeshDict.py new file mode 100644 index 0000000..c8dc46c --- /dev/null +++ b/Demo_case_files/cavity_pyvnt/system/blockMeshDict.py @@ -0,0 +1,29 @@ +from pyvnt import * + +blockMeshDict = Node_C("blockMeshDict") +cM = Key_C("convertToMeters", "1.0") + +blockMeshDict.add_data(cM) + +vertices = List_CP("vertices") + +v = [ + [0, 0, 0], + [1, 0, 0], + [1, 1, 0], + [0, 1, 0], + [0, 0, 0.1], + [1, 0, 0.1], + [1, 1, 0.1], + [0, 1, 0.1] +] + +for i in range(len(v)): + vertices.append_elem(List_CP(name=f'v_{i+1}', elems=[[Flt_P('x', i[0]), Flt_P('y', i[1]), Flt_P('z', i[2])]])) + +verts = Key_C("vertices", vertices) + +blockMeshDict.add_data(verts) + +blocks = List_CP("blocks") + diff --git a/README.md b/README.md index 1d2f488..de8998f 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ There are different classes in the package for different kinds of data in OpenFO - `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. +- `Node_C` class is used to represent the OpenFOAM dictionary data type. Here is a detailed comparisions of a OpenFOAM dictionary and a pyvnt Node tree: @@ -74,8 +74,8 @@ solvers
-solvers(Foam) -└── p(Foam) +solvers(Node_C) +└── p(Node_C) { solver(Key_C) : PCG(Enm_P), BNR(Enm_P) preconditioner(Key_C) : DIC(Enm_P), @@ -87,7 +87,7 @@ solvers(Foam) -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. +As shown above, the `Node_C` 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 @@ -146,27 +146,27 @@ Here is how a sample code would look like that would build this file inside pyvn from pyvnt import * -head = Foam('fvSolutions') +head = Node_C('fvSolutions') -sl = Foam('solvers', parent = head) +sl = Node_C('solvers', parent = head) 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) +p = Node_C('p', sl, None, pc, s, tol, rt) relTol2 = Key_C('relTol', Flt_P('val1', minimum=0, maximum=100, default=0)) -pf = Foam('pFinal', sl, None, relTol2) +pf = Node_C('pFinal', sl, None, relTol2) 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, +u = Node_C('U', sl, None, sol2, sm, tol2, relTol3) ncorr = Key_C('nCorrectors', Int_P('int_prop_1', minimum=0, maximum=100, default=2)) @@ -175,7 +175,7 @@ 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, +piso = Node_C('PISO', head, None, ncorr, nnoc, prc, prv) show_tree(head) diff --git a/pyvnt/Container/list.py b/pyvnt/Container/list.py index 2c44965..cad3501 100644 --- a/pyvnt/Container/list.py +++ b/pyvnt/Container/list.py @@ -1,5 +1,5 @@ from pyvnt.Reference.basic import * -from pyvnt.Container.node import Foam +from pyvnt.Container.node import Node_C from anytree import Node, RenderTree, AsciiStyle, NodeMixin from pyvnt.Reference.error_classes import SizeError, NoPlaceholdersError, NoValueError, KeyRepeatError from pyvnt.utils.make_indent import make_indent @@ -39,14 +39,14 @@ class List_CP(Value_P, NodeMixin): __slots__ = ['_Value_P__name', '_List_CP__values', '_List_CP__isNode'] - def __init__(self, name: int, size: int = None, values: [Foam] = [], elems: [[Value_P]] = [], default: Value_P = None, isNode: bool = False, parent: Foam = None): + def __init__(self, name: int, size: int = None, values: [Node_C] = [], elems: [[Value_P]] = [], default: Value_P = None, isNode: bool = False, parent: Node_C = None): super(List_CP, self).__init__() self.__isNode = isNode if not self.__isNode: 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.check_type(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 Node_C as the values are all the children nodes self.name = name self.__values = [] self.data = [] @@ -73,8 +73,8 @@ def check_type(self, elems: [[Value_P]] = None, values: [Value_P] = None, value: ''' if value: if self.__isNode: - if not isinstance(value, Foam): - raise TypeError("Value should be of type Foam") + if not isinstance(value, Node_C): + raise TypeError("Value should be of type Node_C") else: pass else: @@ -85,8 +85,8 @@ def check_type(self, elems: [[Value_P]] = None, values: [Value_P] = None, value: elif elems: if self.__isNode: for v in elems: - if not all(isinstance(i, Foam) for i in v): - raise TypeError("All values should be of type Foam") + if not all(isinstance(i, Node_C) for i in v): + raise TypeError("All values should be of type Node_C") else: pass else: @@ -97,8 +97,8 @@ def check_type(self, elems: [[Value_P]] = None, values: [Value_P] = None, value: pass elif values: if self.__isNode: - if not all(isinstance(i, Foam) for i in values): - raise TypeError("All values should be of type Foam") + if not all(isinstance(i, Node_C) for i in values): + raise TypeError("All values should be of type Node_C") else: pass else: diff --git a/pyvnt/Container/list_backup.py b/pyvnt/Container/list_backup.py index 7ed2b14..a105cfd 100644 --- a/pyvnt/Container/list_backup.py +++ b/pyvnt/Container/list_backup.py @@ -1,5 +1,5 @@ from pyvnt.Reference.basic import * -from pyvnt.Container.node import Foam +from pyvnt.Container.node import Node_C from anytree import Node, RenderTree, AsciiStyle, NodeMixin from pyvnt.Reference.error_classes import SizeError, NoPlaceholdersError, NoValueError, KeyRepeatError import warnings @@ -38,7 +38,7 @@ class List_CP(Value_P, NodeMixin): __slots__ = ['_Value_P__name', '_List_CP__values', '_List_CP__isNode'] - 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): + def __init__(self, name: int, size: int = None, values: [Value_P] = [], elems: [[Value_P]] or [Node_C] = [], default: Value_P = None, isNode: bool = False, parent: Node_C = None): super(List_CP, self).__init__() self.__isNode = isNode @@ -66,8 +66,8 @@ def check_type(self, values: [Value_P] = None, value: Value_P = None): ''' if value: if self.__isNode: - if not isinstance(value, Foam): - raise TypeError("Value should be of type Foam") + if not isinstance(value, Node_C): + raise TypeError("Value should be of type Node_C") else: pass else: @@ -77,8 +77,8 @@ def check_type(self, values: [Value_P] = None, value: Value_P = None): pass elif values: if self.__isNode: - if not all(isinstance(i, Foam) for i in values): - raise TypeError("All values should be of type Foam") + if not all(isinstance(i, Node_C) for i in values): + raise TypeError("All values should be of type Node_C") else: pass else: diff --git a/pyvnt/Container/node.py b/pyvnt/Container/node.py index f1560fe..6579c98 100755 --- a/pyvnt/Container/node.py +++ b/pyvnt/Container/node.py @@ -12,7 +12,7 @@ 3. the attributed should not be accesible through . operator -- done by name mangling(__var) ''' -class Foam(NodeMixin): +class Node_C(NodeMixin): """ Class to define nodes of the tree @@ -26,7 +26,7 @@ class Foam(NodeMixin): def __init__(self, name: str, parent = None, children: [] = None, *args: Key_C): - super(Foam, self).__init__() + super(Node_C, self).__init__() # self._privateDict = kwargs self.name = name @@ -90,7 +90,7 @@ def set_Parent(self, node): self.parent = node def __repr__(self): - res_str = f"Foam(" + res_str = f"Node_C(" for key, val in self.__dict__.items(): res_str = res_str + f"{key} : {val}, " res_str = res_str + ")" diff --git a/pyvnt/Container/obj_constructor.py b/pyvnt/Container/obj_constructor.py index 7d045f8..c62fb8b 100755 --- a/pyvnt/Container/obj_constructor.py +++ b/pyvnt/Container/obj_constructor.py @@ -1,4 +1,4 @@ -from pyvnt.Container.node import Foam +from pyvnt.Container.node import Node_C from pyvnt.Container.key import Key_C # Function no longer needed @@ -19,7 +19,7 @@ def obj_constructor(name: str, parent = None, children: [] = None, *args): if children != None and tmp != []: raise Exception("Both children and args cannot be given at the same time") elif tmp == [] and children == None: - return Foam(name, parent, children) + return Node_C(name, parent, children) elif children == None: return Key_C(name, parent, *args) else: diff --git a/pyvnt/Converter/Writer/writer.py b/pyvnt/Converter/Writer/writer.py index c8ec16c..16564f1 100644 --- a/pyvnt/Converter/Writer/writer.py +++ b/pyvnt/Converter/Writer/writer.py @@ -5,7 +5,7 @@ def writeTo(root, path): Function to write the dictionary object to the file Parameters: - Foam: Dictionary object to be written + Node_C: Dictionary object to be written path: Path to the file where the dictionary object is to be written ''' diff --git a/pyvnt/utils/show_tree.py b/pyvnt/utils/show_tree.py index 8150d4c..0526381 100755 --- a/pyvnt/utils/show_tree.py +++ b/pyvnt/utils/show_tree.py @@ -1,12 +1,12 @@ from anytree import Node, RenderTree, AsciiStyle, NodeMixin -from pyvnt.Container.node import Foam +from pyvnt.Container.node import Node_C -def show_tree(head: Foam): +def show_tree(head: Node_C): ''' Function to output the entire tree in the terminal starting from the current node object Parameters: - head: Head Node of the tree to be printed. Must be of typpe `Foam` + head: Head Node of the tree to be printed. Must be of typpe `Node_C` Returns: None diff --git a/tests/test_node.py b/tests/test_node.py index 6a4c471..ade4c58 100644 --- a/tests/test_node.py +++ b/tests/test_node.py @@ -12,9 +12,9 @@ def setup_method(self, method): 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) - self.chld2 = Foam("test_child2", None, None) + self.head = Node_C("test_head", None, None) + self.chld1 = Node_C("test_child", self.head, None, self.key2) + self.chld2 = Node_C("test_child2", None, None) def teardown_method(self, method): del self.head @@ -25,7 +25,7 @@ def teardown_method(self, method): @pytest.mark.skip(reason = 'Complex to test') def test_node_print(self): - assert str(self.head) == f"Foam(name : test_head, parent : None, children : ({self.chld1}, {self.chld2}, ), data : ({self.key1}, ), )" + assert str(self.head) == f"Node_C(name : test_head, parent : None, children : ({self.chld1}, {self.chld2}, ), data : ({self.key1}, ), )" def test_node_add_child(self): self.head.add_child(self.chld2)