Mod: working flow process for sample

This commit is contained in:
L-Nafaryus 2021-10-22 21:26:36 +05:00
parent b2343aabb4
commit 493094749d
No known key found for this signature in database
GPG Key ID: C76D8DCD2727DBB7
5 changed files with 67 additions and 32 deletions

View File

@ -5,6 +5,7 @@
from anisotropy.openfoam.foamfile import FoamFile from anisotropy.openfoam.foamfile import FoamFile
import os, shutil import os, shutil
import re import re
from copy import deepcopy
class FoamCase(object): class FoamCase(object):
def __init__(self, foamfiles: list = None, path: str = None): def __init__(self, foamfiles: list = None, path: str = None):
@ -24,27 +25,27 @@ class FoamCase(object):
self.__curpath = None self.__curpath = None
def append(self, ff: FoamFile): def append(self, ff: FoamFile):
#if isinstance(foamfile, FoamFile): if FoamFile in ff.__class__.mro():
setattr(self, ff.header["object"], ff) setattr(self, ff.header["object"], deepcopy(ff))
#else: else:
# raise Exception("Trying to append not a FoamFile.") raise Exception("Trying to put not a FoamFile to FoamCase.")
def extend(self, foamfiles: list): def extend(self, foamfiles: list):
for ff in foamfiles: for ff in foamfiles:
self.append(ff) self.append(ff)
def write(self): def write(self):
for v in self.__dict__.values(): for value in self.__dict__.values():
if isinstance(v, FoamFile): if FoamFile in value.__class__.mro():
v.write(self.path) value.write(self.path)
def read(self): def read(self):
for v in self.__dict__.values(): for value in self.__dict__.values():
if isinstance(v, FoamFile): if FoamFile in value.__class__.mro():
v.read() value.read()
def clean(self): def clean(self, included: list = ["0", "constant", "system"]):
regxs = [ regxs = [
r"^\d+.\d+$", r"^\d+.\d+$",
r"^\d+$", r"^\d+$",
@ -55,7 +56,6 @@ class FoamCase(object):
r"^postProcessing$", r"^postProcessing$",
r"^polyMesh$" r"^polyMesh$"
] ]
included = ["0", "constant", "system"]
excluded = [] excluded = []
for root, dirs, files in os.walk(os.path.abspath("")): for root, dirs, files in os.walk(os.path.abspath("")):

View File

@ -25,7 +25,7 @@ class ControlDict(FoamFile):
"writeCompression": "off", "writeCompression": "off",
"timeFormat": "general", "timeFormat": "general",
"timePrecision": 6, "timePrecision": 6,
"runTimeModifiable": True "runTimeModifiable": "true"
} }
class FvSolution(FoamFile): class FvSolution(FoamFile):

View File

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# This file is part of anisotropy.
# License: GNU GPL version 3, see the file "LICENSE" for details.

View File

@ -2,6 +2,6 @@
# This file is part of anisotropy. # This file is part of anisotropy.
# License: GNU GPL version 3, see the file "LICENSE" for details. # License: GNU GPL version 3, see the file "LICENSE" for details.
#from anisotropy.samples.simple import Simple from anisotropy.samples.simple import Simple
#from anisotropy.samples.bodyCentered import BodyCentered from anisotropy.samples.bodyCentered import BodyCentered
#from anisotropy.samples.faceCentered import FaceCentered from anisotropy.samples.faceCentered import FaceCentered

View File

@ -2,12 +2,21 @@
# This file is part of anisotropy. # This file is part of anisotropy.
# License: GNU GPL version 3, see the file "LICENSE" for details. # 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 from numpy import pi, sqrt, fix
import logging 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 @property
def name(self): def name(self):
"""Shape name. """Shape name.
@ -214,7 +223,7 @@ class Simple(StructureGeometry):
self.groups.append(self.geo.CutListOfGroups([groupAll], self.groups, theName = "wall")) self.groups.append(self.geo.CutListOfGroups([groupAll], self.groups, theName = "wall"))
class SimpleMesh(Mesh): class _Mesh(Mesh):
def build(self): def build(self):
algo2d = self.mesh.Triangle(algo = self.smeshBuilder.NETGEN_1D2D) algo2d = self.mesh.Triangle(algo = self.smeshBuilder.NETGEN_1D2D)
hypo2d = algo2d.Parameters() hypo2d = algo2d.Parameters()
@ -236,20 +245,15 @@ class SimpleMesh(Mesh):
#hypo3dVL = algo3d.ViscousLayers(...) #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): def __init__(self):
controlDict = ControlDict() controlDict = ControlDict()
controlDict.update( controlDict.update(
startFrom = "latestTime", startFrom = "latestTime",
endTime = 5000, endTime = 5000,
writeInterval = 100 writeInterval = 100,
runTimeModifiable = "true"
) )
fvSchemes = FvSchemes() fvSchemes = FvSchemes()
@ -329,16 +333,17 @@ class SimpleFlow(object): # FoamCase
u = U() u = U()
u["boundaryField"] = {} u["boundaryField"] = {}
# ISSUE: add proxy from geometry direction to outlet boundaryField.
for boundary in boundaries: for boundary in boundaries:
match boundary: match boundary:
case "inlet": case "inlet":
p["boundaryField"][boundary] = dict( p["boundaryField"][boundary] = dict(
type = "fixedValue", type = "fixedValue",
value = "uniform 0.001" value = "uniform 1e-3"
) )
u["boundaryField"][boundary] = dict( u["boundaryField"][boundary] = dict(
type = "fixedValue", type = "fixedValue",
value = "uniform (0 0 -6e-5)" value = "uniform (0 0 -6e-5)" # * direction
) )
case "outlet": case "outlet":
@ -359,9 +364,34 @@ class SimpleFlow(object): # FoamCase
value = "uniform (0 0 0)" value = "uniform (0 0 0)"
) )
self.solution = FoamCase([
self.approximation = FoamCase([
controlDict, fvSchemes, fvSolution, createPatchDict, controlDict, fvSchemes, fvSolution, createPatchDict,
transportProperties, turbulenceProperties, transportProperties, turbulenceProperties,
p, u 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