diff --git a/.vscode/settings.json b/.vscode/settings.json index bcea480..816c946 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,12 @@ { "files.associations": { - "dictionaryFile.C": "cpp" + "dictionaryFile.C": "cpp", + "*Dict": "OpenFOAM", + "*Properties": "OpenFOAM", + "fvSchemes": "OpenFOAM", + "fvSolution": "OpenFOAM", + "**/constant/g": "OpenFOAM", + "**/0/*": "OpenFOAM" }, "python.testing.pytestArgs": [ "tests" diff --git a/Demo_case_files/cavity_pyvnt/0_fields/p.py b/Demo_case_files/cavity_pyvnt/0_fields/p.py new file mode 100644 index 0000000..7445ca2 --- /dev/null +++ b/Demo_case_files/cavity_pyvnt/0_fields/p.py @@ -0,0 +1,34 @@ +from pyvnt import * + +p = Node_C("P") + +dim = Dim_Set_P("dimensions", [0, 2, -2, 0, 0, 0, 0]) + +p.add_data(dim) + +internalField = Key_C("internalField", + Enm_P("type", {"uniform", "nonuniform"}, "uniform"), + Flt_P("value", 0) +) + +p.add_data(internalField) + +bf = Node_C("boundaryField", p) + +mWall = Node_C("mWall", bf, [], + Key_C("type", + Enm_P("type", {"fixedValue", "zeroGradient", "noSlip", "empty"}, "zeroGradient") + ) +) + +fWalls = Node_C("fWalls", bf, [], + Key_C("type", + Enm_P("type", {"fixedValue", "zeroGradient", "noSlip", "empty"}, "zeroGradient") + ) +) + +fnb = Node_C("fnb", bf, [], + Key_C("type", + Enm_P("type", {"fixedValue", "zeroGradient", "noSlip", "empty"}, "empty") + ) +) \ No newline at end of file diff --git a/Demo_case_files/cavity_pyvnt/0_fields/u.py b/Demo_case_files/cavity_pyvnt/0_fields/u.py new file mode 100644 index 0000000..342d994 --- /dev/null +++ b/Demo_case_files/cavity_pyvnt/0_fields/u.py @@ -0,0 +1,41 @@ +from pyvnt import * + +u = Node_C("U") + +dim = Key_C("dimensions", + Dim_Set_P("dim_set", [0, 1, -1, 0, 0, 0, 0]) +) + +u.add_data(dim) + +internalField = Key_C("internalField", + Enm_P("type", {"uniform", "nonuniform"}, "uniform"), + Vector_P("value", 0, 0, 0) +) + +u.add_data(internalField) + +bf = Node_C("boundaryField", u) + +mWall = Node_C("mWall", bf, [], + Key_C("type", + Enm_P("type", {"fixedValue", "zeroGradient", "noSlip", "empty"}, "fixedValue") + ), + Key_C("value", + Enm_P("type", {"uniform", "nonuniform"}, "uniform"), + Vector_P("value", 1, 0, 0) + ) +) + +fWalls = Node_C("fWalls", bf, [], + Key_C("type", + Enm_P("type", {"fixedValue", "zeroGradient", "noSlip", "empty"}, "noSlip") + ) +) + +fnb = Node_C("fnb", bf, [], + Key_C("type", + Enm_P("type", {"fixedValue", "zeroGradient", "noSlip", "empty"}, "empty") + ) +) + diff --git a/Demo_case_files/cavity_pyvnt/constant/transportProperties.py b/Demo_case_files/cavity_pyvnt/constant/transportProperties.py new file mode 100644 index 0000000..71a2694 --- /dev/null +++ b/Demo_case_files/cavity_pyvnt/constant/transportProperties.py @@ -0,0 +1,12 @@ +from pyvnt import * + +transportProperties = Node_C("transportProperties") + +nu = Key_C("nu", + Dim_Set_P("nu_dim", [0, 2, -1, 0, 0, 0, 0]), + Flt_P("nu_val", 0.01) +) + +transportProperties.add_data(nu) + +writeTo(transportProperties, "Demo_case_files/") \ No newline at end of file diff --git a/Demo_case_files/cavity_pyvnt/system/blockMeshDict.py b/Demo_case_files/cavity_pyvnt/system/blockMeshDict.py index c8dc46c..1db6b4d 100644 --- a/Demo_case_files/cavity_pyvnt/system/blockMeshDict.py +++ b/Demo_case_files/cavity_pyvnt/system/blockMeshDict.py @@ -1,12 +1,10 @@ from pyvnt import * blockMeshDict = Node_C("blockMeshDict") -cM = Key_C("convertToMeters", "1.0") +cM = Key_C("convertToMeters", Flt_P("convertToMeters", 0.1)) blockMeshDict.add_data(cM) -vertices = List_CP("vertices") - v = [ [0, 0, 0], [1, 0, 0], @@ -18,12 +16,122 @@ [0, 1, 0.1] ] +v_elem = [] + 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])]])) + v_elem.append([List_CP(f"v{i}", elems=[[Flt_P('x', v[i][0]), Flt_P('y', v[i][1]), Flt_P('z', v[i][2])]])]) + +vertices = List_CP("vertices", elems=v_elem) verts = Key_C("vertices", vertices) blockMeshDict.add_data(verts) -blocks = List_CP("blocks") +e1 = [ + Enm_P("type", {"hex"}, "hex"), + List_CP("faces", elems=[[ + Int_P("v0", 0), + Int_P("v1", 1), + Int_P("v2", 2), + Int_P("v3", 3), + Int_P("v4", 4), + Int_P("v5", 5), + Int_P("v6", 6), + Int_P("v7", 7) + ]]), + List_CP("res", elems=[[ + Int_P("nx", 20), + Int_P("ny", 20), + Int_P("nz", 1) + ]]), + Enm_P("grading", {"simpleGrading"}, "simpleGrading"), + List_CP("simpleGrading", elems=[[ + Int_P("x", 1), + Int_P("y", 1), + Int_P("z", 1) + ]]) +] + +blocks = List_CP("blocks", elems=[e1]) + +blks = Key_C("blocks", blocks) + +blockMeshDict.add_data(blks) + +edges = List_CP("edges", elems=[[]]) + +edgs = Key_C("edges", edges) + +blockMeshDict.add_data(edgs) + +typ = Key_C("type", Enm_P("type", {"wall", "empty"}, "wall")) + +faces_1 = List_CP("faces", elems=[ + [List_CP("f0", elems=[[ + Int_P("v0", 3), + Int_P("v1", 7), + Int_P("v2", 6), + Int_P("v3", 2) + ]])] +]) + +fcs1 = Key_C("faces", faces_1) + +mWall = Node_C("movingWall", None, [], typ, fcs1) + +fcs2 = Key_C("faces", List_CP("faces", elems=[ + [List_CP("f0", elems=[ + [ + Int_P("v0", 0), + Int_P("v1", 4), + Int_P("v2", 7), + Int_P("v3", 3) + ]])], [List_CP("f1", elems=[ + [ + Int_P("v0", 2), + Int_P("v1", 6), + Int_P("v2", 5), + Int_P("v3", 1) + ]])], [List_CP("f2", elems=[ + [ + Int_P("v0", 1), + Int_P("v1", 5), + Int_P("v2", 4), + Int_P("v3", 0) + ]])], + +])) + +fwall = Node_C("fixedWalls", None, [], typ, fcs2) + +fcs3 = Key_C("faces", List_CP("faces", elems=[ + [List_CP("f0", elems=[[ + Int_P("v0", 0), + Int_P("v1", 3), + Int_P("v2", 2), + Int_P("v3", 1) + ]])], + [List_CP("f1", elems=[[ + Int_P("v0", 4), + Int_P("v1", 5), + Int_P("v2", 6), + Int_P("v3", 7) + ]])] + +])) + +typ2 = Key_C("type", Enm_P("type", {"wall", "empty"}, "empty")) + +fnb = Node_C("frontAndBack", None, [], typ2 , fcs3) + +bnd = List_CP("boundary", values=[mWall, fwall, fnb], isNode=True) + +blockMeshDict.add_child(bnd) + +mergePatchPairs = List_CP("mergePatchPairs", elems=[[]]) + +mpp = Key_C("mergePatchPairs", mergePatchPairs) + +blockMeshDict.add_data(mpp) +writeTo(blockMeshDict, "Demo_case_files/") diff --git a/Demo_case_files/cavity_pyvnt/system/controlDict.py b/Demo_case_files/cavity_pyvnt/system/controlDict.py new file mode 100644 index 0000000..36e8bd1 --- /dev/null +++ b/Demo_case_files/cavity_pyvnt/system/controlDict.py @@ -0,0 +1,65 @@ +from pyvnt import * + +controlDict = Node_C("controlDict") + +app = Key_C("application", Enm_P("application", {"icoFoam", "simpleFoam", "pimpleFoam"}, "icoFoam")) + +controlDict.add_data(app) + +startFrom = Key_C("startFrom", Enm_P("startFrom", {"startTime", "latestTime"}, "startTime")) + +controlDict.add_data(startFrom) + +startTime = Key_C("startTime", Flt_P("startTime", 0)) + +controlDict.add_data(startTime) + +stopAt = Key_C("stopAt", Enm_P("stopAt", {"endTime", "startTime"}, "endTime")) + +controlDict.add_data(stopAt) + +endTime = Key_C("endTime", Flt_P("endTime", 0.5)) + +controlDict.add_data(endTime) + +deltaT = Key_C("deltaT", Flt_P("deltaT", 0.005)) + +controlDict.add_data(deltaT) + +writeControl = Key_C("writeControl", Enm_P("writeControl", {"timeStep", "runTime", "adjustableRunTime"}, "timeStep")) + +controlDict.add_data(writeControl) + +writeInterval = Key_C("writeInterval", Int_P("writeInterval", 20)) + +controlDict.add_data(writeInterval) + +purgeWrite = Key_C("purgeWrite", Flt_P("purgeWrite", 0)) + +controlDict.add_data(purgeWrite) + +writeFormat = Key_C("writeFormat", Enm_P("writeFormat", {"ascii", "binary"}, "ascii")) + +controlDict.add_data(writeFormat) + +writePrecision = Key_C("writePrecision", Int_P("writePrecision", 6)) + +controlDict.add_data(writePrecision) + +writeCompression = Key_C("writeCompression", Enm_P("writeCompression", {"off", "on"}, "off")) + +controlDict.add_data(writeCompression) + +timeFormat = Key_C("timeFormat", Enm_P("timeFormat", {"general", "scientific"}, "general")) + +controlDict.add_data(timeFormat) + +timePrecision = Key_C("timePrecision", Int_P("timePrecision", 6)) + +controlDict.add_data(timePrecision) + +runTimeModifiable = Key_C("runTimeModifiable", Enm_P("runTimeModifiable", {"true", "false"}, "true")) + +controlDict.add_data(runTimeModifiable) + +writeTo(controlDict, "Demo_case_files/") \ No newline at end of file diff --git a/Demo_case_files/cavity_pyvnt/system/fvSchemes.py b/Demo_case_files/cavity_pyvnt/system/fvSchemes.py new file mode 100644 index 0000000..004a7e7 --- /dev/null +++ b/Demo_case_files/cavity_pyvnt/system/fvSchemes.py @@ -0,0 +1,66 @@ +from pyvnt import * + +fvSchemes = Node_C("fvSchemes") + +ddtSchemes = Node_C( + "ddtSchemes", fvSchemes, [], + Key_C( + "default", + Enm_P("default", {"Euler", "CrankNicolson"}, "Euler") + ) +) + +gradSchemes = Node_C( + "gradSchemes", fvSchemes, [], + Key_C( + "default", + Enm_P("def1", {"Gauss", "CrankNicolson", "none"}, "Gauss"), + Enm_P("def2", {"linear", "limitedlinear", "limitedCubic"}, "linear") + ), + Key_C( + "grad(p)", + Enm_P("gradp1", {"Gauss", "CrankNicolson", "none"}, "Gauss"), + Enm_P("gradp2", {"linear", "limitedlinear", "limitedCubic"}, "linear") + ) +) + +divSchemes = Node_C( + "divSchemes", fvSchemes, [], + Key_C( + "default", + Enm_P("def1", {"Gauss", "CrankNicolson", "none"}, "none"), + ), + Key_C( + "div(phi,U)", + Enm_P("divphi1", {"Gauss", "CrankNicolson", "none"}, "Gauss"), + Enm_P("divphi2", {"linear", "limitedLinear", "limitedCubic"}, "linear") + ) +) + +laplacianSchemes = Node_C( + "laplacianSchemes", fvSchemes, [], + Key_C( + "default", + Enm_P("def1", {"Gauss", "CrankNicolson", "none"}, "Gauss"), + Enm_P("def2", {"linear", "limitedLinear", "limitedCubic"}, "linear"), + Enm_P("def3", {"hexagonal", "orthogonal", "skew", "symmetric"}, "orthogonal") + ) +) + +interpolationSchemes = Node_C( + "interpolationSchemes", fvSchemes, [], + Key_C( + "default", + Enm_P("def1", {"linear", "linearUpwind", "linearLimited", "linearV", "linearVUpwind", "linearVLimited"}, "linear") + ) +) + +snGradSchemes = Node_C( + "snGradSchemes", fvSchemes, [], + Key_C( + "default", + Enm_P("def1", {"hexagonal", "orthogonal", "skew", "symmetric"}, "orthogonal") + ) +) + +writeTo(fvSchemes, "Demo_case_files/") \ No newline at end of file diff --git a/Demo_case_files/cavity_pyvnt/system/fvSolution.py b/Demo_case_files/cavity_pyvnt/system/fvSolution.py new file mode 100644 index 0000000..7457f6b --- /dev/null +++ b/Demo_case_files/cavity_pyvnt/system/fvSolution.py @@ -0,0 +1,71 @@ +from pyvnt import * + +fvSolution = Node_C("fvSolution") + +solvers = Node_C("solvers", fvSolution, []) + +p = Node_C( + "p", solvers, [], + Key_C( + "solver", Enm_P("solver", {"PCG", "smoothSolver", "GAMG"}, "PCG") + ), + Key_C( + "preconditioner", Enm_P("preconditioner", {"DIC", "DILU"}, "DIC") + ), + Key_C( + "tolerance", Flt_P("tolerance", 1e-06) + ), + Key_C( + "relTol", Flt_P("relTol", 0.05) + ) +) + +pFinal = Node_C( + "pFinal", solvers, [], + Key_C( + "solver", Enm_P("solver", {"PCG", "smoothSolver", "GAMG"}, "PCG") + ), + Key_C( + "preconditioner", Enm_P("preconditioner", {"DIC", "DILU"}, "DIC") + ), + Key_C( + "tolerance", Flt_P("tolerance", 1e-06) + ), + Key_C( + "relTol", Flt_P("relTol", 0) + ) +) + +u = Node_C( + "U", solvers, [], + Key_C( + "solver", Enm_P("solver", {"PCG", "smoothSolver", "GAMG"}, "smoothSolver") + ), + Key_C( + "smoother", Enm_P("smoother", {"GaussSeidel", "symGaussSeidel"}, "symGaussSeidel") + ), + Key_C( + "tolerance", Flt_P("tolerance", 1e-05) + ), + Key_C( + "relTol", Flt_P("relTol", 0) + ) +) + +piso = Node_C( + "PISO", fvSolution, [], + Key_C( + "nCorrectors", Int_P("nCorrectors", 2) + ), + Key_C( + "nNonOrthogonalCorrectors", Int_P("nNonOrthogonalCorrectors", 0) + ), + Key_C( + "pRefCell", Int_P("pRefCell", 0) + ), + Key_C( + "pRefValue", Flt_P("pRefValue", 0) + ) +) + +writeTo(fvSolution, "Demo_case_files/") \ No newline at end of file diff --git a/Demo_case_files/pyvnt_outputs/blockMeshDict.txt b/Demo_case_files/pyvnt_outputs/blockMeshDict.txt new file mode 100644 index 0000000..e3f269b --- /dev/null +++ b/Demo_case_files/pyvnt_outputs/blockMeshDict.txt @@ -0,0 +1,69 @@ +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 +( + +); + +mergePatchPairs +( + +); + +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 ) + ); + + } + +) + diff --git a/Demo_case_files/pyvnt_outputs/controlDict.txt b/Demo_case_files/pyvnt_outputs/controlDict.txt new file mode 100644 index 0000000..2833f5e --- /dev/null +++ b/Demo_case_files/pyvnt_outputs/controlDict.txt @@ -0,0 +1,30 @@ +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/pyvnt_outputs/fvSchemes.txt b/Demo_case_files/pyvnt_outputs/fvSchemes.txt new file mode 100644 index 0000000..5984412 --- /dev/null +++ b/Demo_case_files/pyvnt_outputs/fvSchemes.txt @@ -0,0 +1,32 @@ +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/pyvnt_outputs/fvSolution.txt b/Demo_case_files/pyvnt_outputs/fvSolution.txt new file mode 100644 index 0000000..a17eb53 --- /dev/null +++ b/Demo_case_files/pyvnt_outputs/fvSolution.txt @@ -0,0 +1,36 @@ +solvers +{ + p + { + solver PCG; + preconditioner DIC; + tolerance 1e-06; + relTol 0.05; + } + + pFinal + { + solver PCG; + preconditioner DIC; + tolerance 1e-06; + 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/pyvnt_outputs/transportProperties.txt b/Demo_case_files/pyvnt_outputs/transportProperties.txt new file mode 100644 index 0000000..6a3c311 --- /dev/null +++ b/Demo_case_files/pyvnt_outputs/transportProperties.txt @@ -0,0 +1 @@ +nu [0 2 -1 0 0 0 0] 0.01; diff --git a/pyvnt/Container/list.py b/pyvnt/Container/list.py index 01f97c3..5ecbc12 100644 --- a/pyvnt/Container/list.py +++ b/pyvnt/Container/list.py @@ -39,7 +39,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: [Node_C] = [], elems: [[Value_P]] = [], default: Value_P = None, isNode: bool = False, parent: Node_C = 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 @@ -51,9 +51,7 @@ def __init__(self, name: int, size: int = None, values: [Node_C] = [], elems: [[ self.__values = [] self.data = [] - if not parent: - raise NoValueError("No parent given for node") - else: + if parent: self.parent = parent self.children = values @@ -118,7 +116,8 @@ def set_properties(self, name: int, size: int, values: [[Value_P]], default: Val ''' self._Value_P__name = name - self.check_type(elems = values) + if values != [[]]: + self.check_type(elems = values) if size and values != []: ''' @@ -270,7 +269,6 @@ def give_val(self): for val in elem: res = res + (val.give_val(),) - print(res) return res def get_elems(self): diff --git a/pyvnt/Converter/Writer/writer.py b/pyvnt/Converter/Writer/writer.py index 62f1048..b3f632f 100644 --- a/pyvnt/Converter/Writer/writer.py +++ b/pyvnt/Converter/Writer/writer.py @@ -68,12 +68,15 @@ def write_out(obj, file, indent = 0, list_in_key = False): make_indent(file, indent) - if len(obj.get_keys()) == 1 and type(list(obj.get_items())[0]) == List_CP: + if len(list(obj.get_keys())) == 1 and type(list(obj.get_items())[0][1]) == List_CP: file.write(f"{obj.name}\n") for key, val in obj.get_items(): write_out(val, file, indent, True) else: - file.write(f"{obj.name.ljust(col_width)}") + if len(obj.name) >= col_width: + file.write(f"{obj.name} ") + else: + file.write(f"{obj.name.ljust(col_width)}") for key, val in obj.get_items(): write_out(val, file) if key != last_elem: @@ -116,9 +119,12 @@ def write_out(obj, file, indent = 0, list_in_key = False): res += ")" file.write(res) - elif type(obj) == Int_P or type(obj) == Flt_P or type(obj) == Enm_P or type(obj) == Vector_P or type(obj) == Tensor_P or type(obj) == Dim_Set_P : # If object is a property + elif type(obj) == Int_P or type(obj) == Flt_P or type(obj) == Enm_P or type(obj) == Vector_P or type(obj) == Tensor_P : # If object is a property file.write(f"{obj.give_val()}") + elif type(obj) == Dim_Set_P: # special case for dimension set + file.write(" ".join(i for i in str(obj.give_val()).split(","))) + else: raise ValueError(f"Object of type {type(obj)} not supported for writing out to file") \ No newline at end of file