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
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("")):

View File

@ -25,7 +25,7 @@ class ControlDict(FoamFile):
"writeCompression": "off",
"timeFormat": "general",
"timePrecision": 6,
"runTimeModifiable": True
"runTimeModifiable": "true"
}
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.
# 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

View File

@ -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