From 493094749d5629d13f283c9804529d21b4554cd3 Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Fri, 22 Oct 2021 21:26:36 +0500 Subject: [PATCH] Mod: working flow process for sample --- anisotropy/openfoam/foamcase.py | 24 ++++++------- anisotropy/openfoam/presets.py | 2 +- anisotropy/openfoam/runner.py | 5 +++ anisotropy/samples/__init__.py | 6 ++-- anisotropy/samples/simple.py | 62 ++++++++++++++++++++++++--------- 5 files changed, 67 insertions(+), 32 deletions(-) create mode 100644 anisotropy/openfoam/runner.py diff --git a/anisotropy/openfoam/foamcase.py b/anisotropy/openfoam/foamcase.py index 5618d5d..0215447 100644 --- a/anisotropy/openfoam/foamcase.py +++ b/anisotropy/openfoam/foamcase.py @@ -5,6 +5,7 @@ from anisotropy.openfoam.foamfile import FoamFile import os, shutil import re +from copy import deepcopy class FoamCase(object): def __init__(self, foamfiles: list = None, path: str = None): @@ -24,27 +25,27 @@ class FoamCase(object): self.__curpath = None def append(self, ff: FoamFile): - #if isinstance(foamfile, FoamFile): - setattr(self, ff.header["object"], ff) + if FoamFile in ff.__class__.mro(): + setattr(self, ff.header["object"], deepcopy(ff)) - #else: - # raise Exception("Trying to append not a FoamFile.") + else: + raise Exception("Trying to put not a FoamFile to FoamCase.") def extend(self, foamfiles: list): for ff in foamfiles: self.append(ff) def write(self): - for v in self.__dict__.values(): - if isinstance(v, FoamFile): - v.write(self.path) + for value in self.__dict__.values(): + if FoamFile in value.__class__.mro(): + value.write(self.path) def read(self): - for v in self.__dict__.values(): - if isinstance(v, FoamFile): - v.read() + for value in self.__dict__.values(): + if FoamFile in value.__class__.mro(): + value.read() - def clean(self): + def clean(self, included: list = ["0", "constant", "system"]): regxs = [ r"^\d+.\d+$", r"^\d+$", @@ -55,7 +56,6 @@ class FoamCase(object): r"^postProcessing$", r"^polyMesh$" ] - included = ["0", "constant", "system"] excluded = [] for root, dirs, files in os.walk(os.path.abspath("")): diff --git a/anisotropy/openfoam/presets.py b/anisotropy/openfoam/presets.py index 067c337..d2cd900 100644 --- a/anisotropy/openfoam/presets.py +++ b/anisotropy/openfoam/presets.py @@ -25,7 +25,7 @@ class ControlDict(FoamFile): "writeCompression": "off", "timeFormat": "general", "timePrecision": 6, - "runTimeModifiable": True + "runTimeModifiable": "true" } class FvSolution(FoamFile): diff --git a/anisotropy/openfoam/runner.py b/anisotropy/openfoam/runner.py new file mode 100644 index 0000000..e888062 --- /dev/null +++ b/anisotropy/openfoam/runner.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# This file is part of anisotropy. +# License: GNU GPL version 3, see the file "LICENSE" for details. + + diff --git a/anisotropy/samples/__init__.py b/anisotropy/samples/__init__.py index 74be2b3..3859687 100644 --- a/anisotropy/samples/__init__.py +++ b/anisotropy/samples/__init__.py @@ -2,6 +2,6 @@ # This file is part of anisotropy. # License: GNU GPL version 3, see the file "LICENSE" for details. -#from anisotropy.samples.simple import Simple -#from anisotropy.samples.bodyCentered import BodyCentered -#from anisotropy.samples.faceCentered import FaceCentered +from anisotropy.samples.simple import Simple +from anisotropy.samples.bodyCentered import BodyCentered +from anisotropy.samples.faceCentered import FaceCentered diff --git a/anisotropy/samples/simple.py b/anisotropy/samples/simple.py index 1b4f874..b9d1c2e 100644 --- a/anisotropy/samples/simple.py +++ b/anisotropy/samples/simple.py @@ -2,12 +2,21 @@ # This file is part of anisotropy. # License: GNU GPL version 3, see the file "LICENSE" for details. -from anisotropy.salomepl.geometry import StructureGeometry -from anisotropy.salomepl.mesh import Mesh from numpy import pi, sqrt, fix import logging -class Simple(StructureGeometry): +from anisotropy.salomepl.geometry import StructureGeometry +from anisotropy.salomepl.mesh import Mesh + +from anisotropy.openfoam.presets import ( + ControlDict, FvSchemes, FvSolution, + TransportProperties, TurbulenceProperties, CreatePatchDict, + P, U +) +from anisotropy.openfoam.foamcase import FoamCase +import anisotropy.openfoam as openfoam + +class _Geometry(StructureGeometry): @property def name(self): """Shape name. @@ -214,7 +223,7 @@ class Simple(StructureGeometry): self.groups.append(self.geo.CutListOfGroups([groupAll], self.groups, theName = "wall")) -class SimpleMesh(Mesh): +class _Mesh(Mesh): def build(self): algo2d = self.mesh.Triangle(algo = self.smeshBuilder.NETGEN_1D2D) hypo2d = algo2d.Parameters() @@ -236,20 +245,15 @@ class SimpleMesh(Mesh): #hypo3dVL = algo3d.ViscousLayers(...) -from anisotropy.openfoam.presets import ( - ControlDict, FvSchemes, FvSolution, - TransportProperties, TurbulenceProperties, CreatePatchDict, - P, U -) -from anisotropy.openfoam.foamcase import FoamCase -class SimpleFlow(object): # FoamCase +class _Flow(object): def __init__(self): controlDict = ControlDict() controlDict.update( startFrom = "latestTime", endTime = 5000, - writeInterval = 100 + writeInterval = 100, + runTimeModifiable = "true" ) fvSchemes = FvSchemes() @@ -329,16 +333,17 @@ class SimpleFlow(object): # FoamCase u = U() u["boundaryField"] = {} + # ISSUE: add proxy from geometry direction to outlet boundaryField. for boundary in boundaries: match boundary: case "inlet": p["boundaryField"][boundary] = dict( type = "fixedValue", - value = "uniform 0.001" + value = "uniform 1e-3" ) u["boundaryField"][boundary] = dict( type = "fixedValue", - value = "uniform (0 0 -6e-5)" + value = "uniform (0 0 -6e-5)" # * direction ) case "outlet": @@ -359,9 +364,34 @@ class SimpleFlow(object): # FoamCase value = "uniform (0 0 0)" ) - - self.approximation = FoamCase([ + self.solution = FoamCase([ controlDict, fvSchemes, fvSolution, createPatchDict, transportProperties, turbulenceProperties, p, u ]) + + def build(self): + self.solution.write() + + openfoam.ideasUnvToFoam("mesh.unv") + openfoam.createPatch() + openfoam.checkMesh() + openfoam.transformPoints((1e-5, 1e-5, 1e-5)) + openfoam.renumberMesh() + openfoam.potentialFoam() + + self.solution.read() + + self.solution.U["boundaryField"]["outlet"] = dict( + type = "pressureInletVelocity", + value = "uniform (0 0 0)" # * direction + ) + self.solution.write() + + openfoam.simpleFoam() + + +class Simple(object): + geometry = _Geometry + mesh = _Mesh + flow = _Flow