Mod: simple, foamcase for approximation

This commit is contained in:
L-Nafaryus 2021-10-22 14:02:50 +05:00
parent 3071a81d1b
commit b2343aabb4
No known key found for this signature in database
GPG Key ID: C76D8DCD2727DBB7
4 changed files with 147 additions and 33 deletions

View File

@ -23,12 +23,12 @@ class FoamCase(object):
os.chdir(self.__curpath) os.chdir(self.__curpath)
self.__curpath = None self.__curpath = None
def append(self, foamfile: FoamFile): def append(self, ff: FoamFile):
if isinstance(foamfile, FoamFile): #if isinstance(foamfile, FoamFile):
setattr(self, foamfile.header["object"], foamfile) setattr(self, ff.header["object"], ff)
else: #else:
raise Exception("Trying to append not a FoamFile.") # raise Exception("Trying to append not a FoamFile.")
def extend(self, foamfiles: list): def extend(self, foamfiles: list):
for ff in foamfiles: for ff in foamfiles:

View File

@ -38,6 +38,9 @@ class FoamFile(object):
def __delitem__(self, key): def __delitem__(self, key):
del self.content[key] del self.content[key]
def update(self, **kwargs):
self.content.update(**kwargs)
def __len__(self): def __len__(self):
return len(self.content) return len(self.content)
@ -73,7 +76,7 @@ class FoamFile(object):
def write(self, casepath: str = None): def write(self, casepath: str = None):
header = FoamFileGenerator({}, header = self.header) header = FoamFileGenerator({}, header = self.header)
header = header.makeString()[ :-2] header = header.makeString()[ :-2]
header = header.replace("\n ", "\n" + 4 * " ") header = header.replace("\n ", "\n" + 4 * " ")
content = FoamFileGenerator(self.content) content = FoamFileGenerator(self.content)
content = content.makeString()[ :-1] content = content.makeString()[ :-1]

View File

@ -6,11 +6,10 @@ from anisotropy.openfoam.foamfile import FoamFile
class ControlDict(FoamFile): class ControlDict(FoamFile):
def __init__(self): def __init__(self):
ff = FoamFile( FoamFile.__init__(self,
"system/controlDict", "system/controlDict",
_location = "system" _location = "system"
) )
self.header = ff.header
self.content = { self.content = {
"application": "simpleFoam", "application": "simpleFoam",
"startFrom": "startTime", "startFrom": "startTime",
@ -31,11 +30,10 @@ class ControlDict(FoamFile):
class FvSolution(FoamFile): class FvSolution(FoamFile):
def __init__(self): def __init__(self):
ff = FoamFile( FoamFile.__init__(self,
"system/fvSolution", "system/fvSolution",
_location = "system" _location = "system"
) )
self.header = ff.header
self.content = { self.content = {
"solvers": { "solvers": {
"p": { "p": {
@ -71,26 +69,25 @@ class FvSolution(FoamFile):
class FvSchemes(FoamFile): class FvSchemes(FoamFile):
def __init__(self): def __init__(self):
ff = FoamFile( FoamFile.__init__(self,
"system/fvSchemes", "system/fvSchemes",
_location = "system" _location = "system"
) )
self.header = ff.header
self.content = { self.content = {
"ddtSchemes": { "ddtSchemes": {
"default": "steadyState" "default": "steadyState"
}, },
"gradSchemes": { "gradSchemes": {
"default": ["Gauss", "linear"] "default": ("Gauss", "linear")
}, },
"divSchemes": { "divSchemes": {
"default": "none", "default": "none",
"div(phi,U)": ["bounded", "Gauss", "linearUpwind", "grad(U)"], "div(phi,U)": ("bounded", "Gauss", "linearUpwind", "grad(U)"),
"div((nuEff*dev2(T(grad(U)))))": ["Gauss", "linear"], "div((nuEff*dev2(T(grad(U)))))": ("Gauss", "linear"),
"div(nonlinearStress)": ["Gauss", "linear"] "div(nonlinearStress)": ("Gauss", "linear")
}, },
"laplacianSchemes": { "laplacianSchemes": {
"default": ["Gauss", "linear", "corrected"] "default": ("Gauss", "linear", "corrected")
}, },
"interpolationSchemes": { "interpolationSchemes": {
"default": "linear" "default": "linear"
@ -102,11 +99,10 @@ class FvSchemes(FoamFile):
class TransportProperties(FoamFile): class TransportProperties(FoamFile):
def __init__(self): def __init__(self):
ff = FoamFile( FoamFile.__init__(self,
"constant/transportProperties", "constant/transportProperties",
_location = "constant" _location = "constant"
) )
self.header = ff.header
self.content = { self.content = {
"transportModel": "Newtonian", "transportModel": "Newtonian",
"nu": 1e-05 "nu": 1e-05
@ -114,11 +110,10 @@ class TransportProperties(FoamFile):
class TurbulenceProperties(FoamFile): class TurbulenceProperties(FoamFile):
def __init__(self): def __init__(self):
ff = FoamFile( FoamFile.__init__(self,
"constant/turbulenceProperties", "constant/turbulenceProperties",
_location = "constant" _location = "constant"
) )
self.header = ff.header
self.content = { self.content = {
"simulationType": "RAS", "simulationType": "RAS",
"RAS": { "RAS": {
@ -130,12 +125,11 @@ class TurbulenceProperties(FoamFile):
class P(FoamFile): class P(FoamFile):
def __init__(self): def __init__(self):
ff = FoamFile( FoamFile.__init__(self,
"0/p", "0/p",
_location = "0", _location = "0",
_class = "volScalarField" _class = "volScalarField"
) )
self.header = ff.header
self.content = { self.content = {
"dimensions": "[0 2 -2 0 0 0 0]", "dimensions": "[0 2 -2 0 0 0 0]",
"internalField": "uniform 0", "internalField": "uniform 0",
@ -156,12 +150,11 @@ class P(FoamFile):
class U(FoamFile): class U(FoamFile):
def __init__(self): def __init__(self):
ff = FoamFile( FoamFile.__init__(self,
"0/U", "0/U",
_location = "0", _location = "0",
_class = "volVectorField" _class = "volVectorField"
) )
self.header = ff.header
self.content = { self.content = {
"dimensions": "[0 1 -1 0 0 0 0]", "dimensions": "[0 1 -1 0 0 0 0]",
"internalField": "uniform (0 0 0)", "internalField": "uniform (0 0 0)",
@ -182,11 +175,10 @@ class U(FoamFile):
class CreatePatchDict(FoamFile): class CreatePatchDict(FoamFile):
def __init__(self): def __init__(self):
ff = FoamFile( FoamFile.__init__(self,
"system/createPatchDict", "system/createPatchDict",
_location = "system", _location = "system",
) )
self.header = ff.header
self.content = { self.content = {
"pointSync": False, "pointSync": False,
"patches": [ "patches": [
@ -222,11 +214,10 @@ class CreatePatchDict(FoamFile):
class DecomposeParDict(FoamFile): class DecomposeParDict(FoamFile):
def __init__(self): def __init__(self):
ff = FoamFile( FoamFile.__init__(self,
"system/decomposeParDict", "system/decomposeParDict",
_location = "system", _location = "system",
) )
self.header = ff.header
self.content = { self.content = {
"numberOfSubdomains": 4, "numberOfSubdomains": 4,
"method": "simple", "method": "simple",

View File

@ -236,12 +236,132 @@ class SimpleMesh(Mesh):
#hypo3dVL = algo3d.ViscousLayers(...) #hypo3dVL = algo3d.ViscousLayers(...)
from anisotropy.openfoam.presets import ControlDict from anisotropy.openfoam.presets import (
ControlDict, FvSchemes, FvSolution,
TransportProperties, TurbulenceProperties, CreatePatchDict,
P, U
)
from anisotropy.openfoam.foamcase import FoamCase
class SimpleFlow(object): # FoamCase class SimpleFlow(object): # FoamCase
def __init__(self): def __init__(self):
controlDict = ControlDict() controlDict = ControlDict()
controlDict["startFrom"] = "latestTime" controlDict.update(
controlDict["endTime"] = 5000 startFrom = "latestTime",
controlDict["writeInterval"] = 100 endTime = 5000,
writeInterval = 100
)
fvSchemes = FvSchemes()
fvSolution = FvSolution()
fvSolution["solvers"]["U"].update(
nSweeps = 2,
tolerance = 1e-08
)
fvSolution["solvers"]["Phi"] = dict(
solver = "GAMG",
smoother = "DIC",
cacheAgglomeration = "yes",
agglomerator = "faceAreaPair",
nCellsInCoarsestLevel = 10,
mergeLevels = 1,
tolerance = 1e-06,
relTol = 0.01
)
fvSolution["potentialFlow"] = dict(
nNonOrthogonalCorrectors = 20,
PhiRefCell = 0,
PhiRefPoint = 0,
PhiRefValue = 0,
Phi = 0
)
fvSolution["cache"] = { "grad(U)": None }
fvSolution["SIMPLE"].update(
nNonOrthogonalCorrectors = 10,
residualControl = dict(
p = 1e-05,
U = 1e-05
)
)
fvSolution["relaxationFactors"]["equations"]["U"] = 0.5
transportProperties = TransportProperties()
transportProperties.update(
nu = 1e-06
)
turbulenceProperties = TurbulenceProperties()
turbulenceProperties.content = dict(
simulationType = "laminar"
)
createPatchDict = CreatePatchDict()
createPatchDict["patches"] = []
for patch in ["inlet", "outlet", "wall", "strips", *[ f"symetry{ n }" for n in range(6) ]]:
newPatch = dict(
name = patch,
patchInfo = dict(
type = "patch",
inGroups = [patch]
),
constructFrom = "patches",
patches = [ f"smesh_{ patch }" ]
)
match patch:
case "wall" | "strips":
newPatch["patchInfo"].update(
type = "wall",
inGroups = [ "wall" ]
)
case patch if patch.find("symetry") == 0:
newPatch["patchInfo"]["inGroups"] = [ "symetryPlane" ]
createPatchDict["patches"].append(newPatch)
boundaries = [ "inlet", "outlet", "symetryPlane", "wall", "strips" ]
p = P()
p["boundaryField"] = {}
u = U()
u["boundaryField"] = {}
for boundary in boundaries:
match boundary:
case "inlet":
p["boundaryField"][boundary] = dict(
type = "fixedValue",
value = "uniform 0.001"
)
u["boundaryField"][boundary] = dict(
type = "fixedValue",
value = "uniform (0 0 -6e-5)"
)
case "outlet":
p["boundaryField"][boundary] = dict(
type = "fixedValue",
value = "uniform 0"
)
u["boundaryField"][boundary] = dict(
type = "zeroGradient",
)
case _:
p["boundaryField"][boundary] = dict(
type = "zeroGradient"
)
u["boundaryField"][boundary] = dict(
type = "fixedValue",
value = "uniform (0 0 0)"
)
self.approximation = FoamCase([
controlDict, fvSchemes, fvSolution, createPatchDict,
transportProperties, turbulenceProperties,
p, u
])