Mod: config way for each task
This commit is contained in:
parent
a4d72a779a
commit
2532e20c53
@ -13,10 +13,6 @@ import logging
|
|||||||
CONFIG = os.path.join(ROOT, "conf/config.toml")
|
CONFIG = os.path.join(ROOT, "conf/config.toml")
|
||||||
config = struct(toml.load(CONFIG))
|
config = struct(toml.load(CONFIG))
|
||||||
|
|
||||||
|
|
||||||
#CONFIG = os.path.abspath("../conf/config.toml")
|
|
||||||
#config = struct(toml.load(CONFIG))
|
|
||||||
|
|
||||||
LOG = os.path.join(ROOT, "logs")
|
LOG = os.path.join(ROOT, "logs")
|
||||||
if not os.path.exists(LOG):
|
if not os.path.exists(LOG):
|
||||||
os.makedirs(LOG)
|
os.makedirs(LOG)
|
||||||
@ -35,109 +31,128 @@ logging.basicConfig(
|
|||||||
)
|
)
|
||||||
logger = logging.getLogger(config.logger.name)
|
logger = logging.getLogger(config.logger.name)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if checkEnv():
|
if checkEnv():
|
||||||
return
|
return
|
||||||
|
|
||||||
tasks = createTasks()
|
tasks = createTasks()
|
||||||
|
|
||||||
for task in tasks:
|
for n, case in enumerate(tasks):
|
||||||
logger.info("-" * 80)
|
logger.info("-" * 80)
|
||||||
logger.info(f"""main:
|
logger.info(f"""main:
|
||||||
task:\t{tasks.index(task) + 1} / {len(tasks)}
|
task:\t{ n + 1 } / { len(tasks) }
|
||||||
cpu count:\t{ os.cpu_count() }
|
cpu count:\t{ os.cpu_count() }
|
||||||
structure:\t{task.structure}
|
case:\t{ case }""")
|
||||||
direction:\t{task.direction}
|
|
||||||
theta:\t{task.theta}
|
|
||||||
fillet:\t{task.fillet}
|
|
||||||
export:\t{task.export}""")
|
|
||||||
|
|
||||||
if not os.path.exists(task.export):
|
###
|
||||||
os.makedirs(task.export)
|
# Compute mesh
|
||||||
|
##
|
||||||
|
computeMesh(case)
|
||||||
|
|
||||||
createMesh(task)
|
task = struct(toml.load(os.path.join(case, "task.toml")))
|
||||||
|
|
||||||
if os.path.exists(os.path.join(task.export, "mesh.unv")):
|
if not task.status.mesh:
|
||||||
task.mesh = True
|
logger.critical("mesh not computed: Skipping flow computation")
|
||||||
|
continue
|
||||||
|
|
||||||
returncode = calculate(task)
|
###
|
||||||
|
# Compute flow
|
||||||
if not returncode:
|
##
|
||||||
task.flow = True
|
computeFlow(case)
|
||||||
|
|
||||||
with open(os.path.join(LOG, "tasks.log"), "a") as io:
|
|
||||||
idx = tasks.index(task)
|
|
||||||
io.write(f"""Task {idx}:
|
|
||||||
structure:\t{task.structure}
|
|
||||||
direction:\t{task.direction}
|
|
||||||
theta:\t{task.theta}
|
|
||||||
mesh:\t{task.mesh}
|
|
||||||
flow:\t{task.flow}\n""")
|
|
||||||
|
|
||||||
|
|
||||||
#logger.info(f"Warnings: {logger.warnings}\tErrors: {logger.errors}")
|
|
||||||
|
|
||||||
|
|
||||||
def createTasks():
|
def createTasks():
|
||||||
tasks = []
|
tasks = []
|
||||||
|
|
||||||
|
for structure in config.base.__dict__.keys():
|
||||||
|
###
|
||||||
|
# Special values
|
||||||
|
##
|
||||||
|
_theta = getattr(config, structure).parameters.theta
|
||||||
|
getattr(config, structure).parameters.theta = [ n * _theta[2] for n in range(int(_theta[0] / _theta[2]), int(_theta[1] / _theta[2]) + 1) ]
|
||||||
|
|
||||||
|
_thickness = getattr(config, structure).mesh.thickness
|
||||||
|
_count = len(getattr(config, structure).parameters.theta)
|
||||||
|
getattr(config, structure).mesh.thickness = [ _thickness[0] + n * (_thickness[1] - _thickness[0]) / (_count - 1) for n in range(0, _count) ]
|
||||||
|
|
||||||
|
###
|
||||||
|
# structure type / flow direction / coefficient theta
|
||||||
|
##
|
||||||
for structure in config.base.__dict__.keys():
|
for structure in config.base.__dict__.keys():
|
||||||
if getattr(config.base, structure):
|
if getattr(config.base, structure):
|
||||||
for direction in getattr(config, structure).geometry.directions:
|
for direction in getattr(config, structure).geometry.directions:
|
||||||
for theta in getattr(config, structure).theta:
|
for n, theta in enumerate(getattr(config, structure).parameters.theta):
|
||||||
task = struct(
|
case = os.path.join(
|
||||||
structure = structure,
|
f"{ BUILD }",
|
||||||
theta = theta,
|
f"{ structure }",
|
||||||
fillet = getattr(config, structure).geometry.fillet,
|
f"direction-{ direction[0] }{ direction [1] }{ direction [2] }",
|
||||||
direction = direction,
|
f"theta-{ theta }"
|
||||||
export = os.path.join(ROOT, f"{ BUILD }/{ structure }/direction-{ direction[0] }{ direction [1] }{ direction [2] }/theta-{ theta }"),
|
|
||||||
mesh = False,
|
|
||||||
flow = False
|
|
||||||
)
|
)
|
||||||
|
|
||||||
tasks.append(task)
|
if not os.path.exists(case):
|
||||||
|
os.makedirs(case)
|
||||||
|
|
||||||
|
task = {
|
||||||
|
"logger": config.logger.__dict__,
|
||||||
|
"structure": structure,
|
||||||
|
"status": {
|
||||||
|
"mesh": False,
|
||||||
|
"flow": False
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"theta": theta
|
||||||
|
},
|
||||||
|
"geometry": {
|
||||||
|
"direction": direction,
|
||||||
|
"fillet": getattr(config, structure).geometry.fillet
|
||||||
|
},
|
||||||
|
"mesh": getattr(config, structure).mesh.__dict__
|
||||||
|
}
|
||||||
|
|
||||||
|
#task["mesh"]["thickness"] = task["mesh"]["thickness"][int(n)]
|
||||||
|
|
||||||
|
with open(os.path.join(case, "task.toml"), "w") as io:
|
||||||
|
toml.dump(task, io)
|
||||||
|
|
||||||
|
|
||||||
|
tasks.append(case)
|
||||||
|
|
||||||
return tasks
|
return tasks
|
||||||
|
|
||||||
|
|
||||||
from salomepl.utils import runExecute, salomeVersion
|
from salomepl.utils import runExecute, salomeVersion
|
||||||
|
|
||||||
def createMesh(task):
|
def computeMesh(case):
|
||||||
scriptpath = os.path.join(ROOT, "salomepl/genmesh.py")
|
scriptpath = os.path.join(ROOT, "salomepl/genmesh.py")
|
||||||
port = 2810
|
port = 2810
|
||||||
stime = time.monotonic()
|
stime = time.monotonic()
|
||||||
|
|
||||||
args = (
|
returncode = runExecute(port, scriptpath, ROOT, case)
|
||||||
task.structure,
|
|
||||||
task.theta,
|
|
||||||
int(task.fillet),
|
|
||||||
"".join([str(coord) for coord in task.direction]),
|
|
||||||
os.path.join(task.export, "mesh.unv"),
|
|
||||||
ROOT
|
|
||||||
)
|
|
||||||
returncode = runExecute(port, scriptpath, *args)
|
|
||||||
|
|
||||||
etime = time.monotonic()
|
etime = time.monotonic()
|
||||||
logger.info("createMesh: elapsed time: {}".format(timedelta(seconds = etime - stime)))
|
logger.info("computeMesh: elapsed time: {}".format(timedelta(seconds = etime - stime)))
|
||||||
|
|
||||||
|
|
||||||
import openfoam
|
import openfoam
|
||||||
|
|
||||||
def calculate(task):
|
def computeFlow(case):
|
||||||
foamCase = [ "0", "constant", "system" ]
|
foamCase = [ "0", "constant", "system" ]
|
||||||
|
|
||||||
os.chdir(task.export)
|
os.chdir(case)
|
||||||
|
task = struct(toml.load(os.path.join(case, "task.toml")))
|
||||||
openfoam.foamClean()
|
openfoam.foamClean()
|
||||||
|
|
||||||
for d in foamCase:
|
for d in foamCase:
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
os.path.join(ROOT, "openfoam/template", d),
|
os.path.join(ROOT, "openfoam/template", d),
|
||||||
os.path.join(task.export, d)
|
os.path.join(case, d)
|
||||||
)
|
)
|
||||||
|
|
||||||
stime = time.monotonic()
|
stime = time.monotonic()
|
||||||
|
|
||||||
if not os.path.exists("mesh.unv"):
|
if not os.path.exists("mesh.unv"):
|
||||||
logger.critical(f"calculate: missed 'mesh.unv'")
|
logger.critical(f"computeFlow: missed 'mesh.unv'")
|
||||||
return
|
return
|
||||||
|
|
||||||
_, returncode = openfoam.ideasUnvToFoam("mesh.unv")
|
_, returncode = openfoam.ideasUnvToFoam("mesh.unv")
|
||||||
@ -171,10 +186,23 @@ def calculate(task):
|
|||||||
if out:
|
if out:
|
||||||
logger.info(out)
|
logger.info(out)
|
||||||
|
|
||||||
|
if returncode == 0:
|
||||||
|
task.status.flow = True
|
||||||
|
|
||||||
|
with open(os.path.join(case, "task.toml"), "w") as io:
|
||||||
|
toml.dump({
|
||||||
|
"structure": task.structure,
|
||||||
|
"logger": task.logger.__dict__,
|
||||||
|
"status": task.status.__dict__,
|
||||||
|
"parameters": task.parameters.__dict__,
|
||||||
|
"geometry": task.geometry.__dict__,
|
||||||
|
"mesh": task.mesh.__dict__
|
||||||
|
}, io)
|
||||||
|
|
||||||
os.chdir(ROOT)
|
os.chdir(ROOT)
|
||||||
|
|
||||||
etime = time.monotonic()
|
etime = time.monotonic()
|
||||||
logger.info("calculate: elapsed time: {}".format(timedelta(seconds = etime - stime)))
|
logger.info("computeFlow: elapsed time: {}".format(timedelta(seconds = etime - stime)))
|
||||||
|
|
||||||
return returncode
|
return returncode
|
||||||
|
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
###
|
||||||
|
# Default config for anisotropy
|
||||||
|
#
|
||||||
|
# theta = [min, max, step]
|
||||||
|
##
|
||||||
|
|
||||||
[logger]
|
[logger]
|
||||||
name = "anisotropy"
|
name = "anisotropy"
|
||||||
format = "%(levelname)s: %(message)s"
|
format = "%(levelname)s: %(message)s"
|
||||||
@ -7,8 +13,11 @@ simple = true
|
|||||||
bodyCentered = true
|
bodyCentered = true
|
||||||
faceCentered = true
|
faceCentered = true
|
||||||
|
|
||||||
[simple]
|
###
|
||||||
theta = [0.01, 0.28]
|
# Simple
|
||||||
|
##
|
||||||
|
[simple.parameters]
|
||||||
|
theta = [0.01, 0.28, 0.01]
|
||||||
|
|
||||||
[simple.geometry]
|
[simple.geometry]
|
||||||
directions = [
|
directions = [
|
||||||
@ -34,13 +43,16 @@ useSurfaceCurvature = true
|
|||||||
fuseEdges = true
|
fuseEdges = true
|
||||||
checkChartBoundary = false
|
checkChartBoundary = false
|
||||||
|
|
||||||
thickness = 0.005
|
thickness = [0.005, 0.005]
|
||||||
numberOfLayers = 2
|
numberOfLayers = 2
|
||||||
stretchFactor = 1.2
|
stretchFactor = 1.2
|
||||||
isFacesToIgnore = true
|
isFacesToIgnore = true
|
||||||
|
|
||||||
[bodyCentered]
|
###
|
||||||
theta = [0.01, 0.18]
|
# Body-centered
|
||||||
|
##
|
||||||
|
[bodyCentered.parameters]
|
||||||
|
theta = [0.01, 0.18, 0.01]
|
||||||
|
|
||||||
[bodyCentered.geometry]
|
[bodyCentered.geometry]
|
||||||
directions = [
|
directions = [
|
||||||
@ -66,13 +78,16 @@ useSurfaceCurvature = true
|
|||||||
fuseEdges = true
|
fuseEdges = true
|
||||||
checkChartBoundary = false
|
checkChartBoundary = false
|
||||||
|
|
||||||
thickness = 0.005
|
thickness = [0.005, 0.005]
|
||||||
numberOfLayers = 2
|
numberOfLayers = 2
|
||||||
stretchFactor = 1.2
|
stretchFactor = 1.2
|
||||||
isFacesToIgnore = true
|
isFacesToIgnore = true
|
||||||
|
|
||||||
[faceCentered]
|
###
|
||||||
theta = [0.01, 0.13]
|
# Face-centered
|
||||||
|
##
|
||||||
|
[faceCentered.parameters]
|
||||||
|
theta = [0.01, 0.13, 0.01]
|
||||||
|
|
||||||
[faceCentered.geometry]
|
[faceCentered.geometry]
|
||||||
directions = [
|
directions = [
|
||||||
@ -98,7 +113,7 @@ useSurfaceCurvature = true
|
|||||||
fuseEdges = true
|
fuseEdges = true
|
||||||
checkChartBoundary = false
|
checkChartBoundary = false
|
||||||
|
|
||||||
thickness = 0.001
|
thickness = [0.001, 0.001]
|
||||||
numberOfLayers = 2
|
numberOfLayers = 2
|
||||||
stretchFactor = 1.2
|
stretchFactor = 1.2
|
||||||
isFacesToIgnore = true
|
isFacesToIgnore = true
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
# This file executes inside salome environment
|
# This file executes inside salome environment
|
||||||
#
|
#
|
||||||
# salome starts at user home directory
|
# salome starts at user home directory
|
||||||
|
#
|
||||||
|
# sys.argv = [ .., ROOT, case ]
|
||||||
##
|
##
|
||||||
import os, sys
|
import os, sys
|
||||||
import math
|
import math
|
||||||
@ -9,7 +11,9 @@ import math
|
|||||||
import salome
|
import salome
|
||||||
|
|
||||||
# get project path from args
|
# get project path from args
|
||||||
ROOT = sys.argv[6]
|
ROOT = sys.argv[1]
|
||||||
|
CASE = sys.argv[2]
|
||||||
|
|
||||||
sys.path.append(ROOT)
|
sys.path.append(ROOT)
|
||||||
# site-packages from virtual env
|
# site-packages from virtual env
|
||||||
sys.path.append(os.path.join(ROOT, "env/lib/python3.9/site-packages"))
|
sys.path.append(os.path.join(ROOT, "env/lib/python3.9/site-packages"))
|
||||||
@ -18,7 +22,7 @@ import toml
|
|||||||
import logging
|
import logging
|
||||||
from anisotropy.utils import struct
|
from anisotropy.utils import struct
|
||||||
|
|
||||||
CONFIG = os.path.join(ROOT, "conf/config.toml")
|
CONFIG = os.path.join(CASE, "task.toml")
|
||||||
config = struct(toml.load(CONFIG))
|
config = struct(toml.load(CONFIG))
|
||||||
|
|
||||||
LOG = os.path.join(ROOT, "logs")
|
LOG = os.path.join(ROOT, "logs")
|
||||||
@ -41,25 +45,13 @@ from salomepl.geometry import getGeom
|
|||||||
from salomepl.mesh import smeshBuilder, meshCreate, meshCompute, meshStats, meshExport
|
from salomepl.mesh import smeshBuilder, meshCreate, meshCompute, meshStats, meshExport
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def genmesh():
|
||||||
|
|
||||||
stype = str(sys.argv[1])
|
logger.info(f"""genmesh:
|
||||||
theta = float(sys.argv[2])
|
structure type:\t{ config.structure }
|
||||||
fillet = int(sys.argv[3])
|
coefficient:\t{ config.parameters.theta }
|
||||||
flowdirection = [int(coord) for coord in sys.argv[4]]
|
fillet:\t{ config.geometry.fillet }
|
||||||
export = str(sys.argv[5])
|
flow direction:\t{ config.geometry.direction }""")
|
||||||
|
|
||||||
genmesh(stype, theta, fillet, flowdirection, export)
|
|
||||||
|
|
||||||
|
|
||||||
def genmesh(stype, theta, fillet, direction, export):
|
|
||||||
|
|
||||||
logger.info("""genMesh:
|
|
||||||
structure type:\t{}
|
|
||||||
coefficient:\t{}
|
|
||||||
fillet:\t{}
|
|
||||||
flow direction:\t{}
|
|
||||||
export path:\t{}""".format(stype, theta, fillet, direction, export))
|
|
||||||
|
|
||||||
salome.salome_init()
|
salome.salome_init()
|
||||||
|
|
||||||
@ -67,14 +59,14 @@ def genmesh(stype, theta, fillet, direction, export):
|
|||||||
# Shape
|
# Shape
|
||||||
##
|
##
|
||||||
geompy = getGeom()
|
geompy = getGeom()
|
||||||
structure = globals().get(stype)
|
structure = globals().get(config.structure)
|
||||||
shape, groups = structure(theta, fillet, direction)
|
shape, groups = structure(config.parameters.theta, config.geometry.fillet, config.geometry.direction)
|
||||||
[length, surfaceArea, volume] = geompy.BasicProperties(shape, theTolerance = 1e-06)
|
[length, surfaceArea, volume] = geompy.BasicProperties(shape, theTolerance = 1e-06)
|
||||||
|
|
||||||
logger.info("""shape:
|
logger.info(f"""shape:
|
||||||
edges length:\t{}
|
edges length:\t{ length }
|
||||||
surface area:\t{}
|
surface area:\t{ surfaceArea }
|
||||||
volume:\t{}""".format(length, surfaceArea, volume))
|
volume:\t{ volume }""")
|
||||||
|
|
||||||
###
|
###
|
||||||
# Mesh
|
# Mesh
|
||||||
@ -84,20 +76,33 @@ def genmesh(stype, theta, fillet, direction, export):
|
|||||||
if group.GetName() in ["inlet", "outlet"]:
|
if group.GetName() in ["inlet", "outlet"]:
|
||||||
facesToIgnore.append(group)
|
facesToIgnore.append(group)
|
||||||
|
|
||||||
meshParameters = getattr(config, stype).mesh
|
meshParameters = config.mesh
|
||||||
meshParameters.facesToIgnore = facesToIgnore
|
meshParameters.facesToIgnore = facesToIgnore
|
||||||
meshParameters.extrusionMethod = smeshBuilder.SURF_OFFSET_SMOOTH
|
meshParameters.extrusionMethod = smeshBuilder.SURF_OFFSET_SMOOTH
|
||||||
|
|
||||||
mesh = meshCreate(shape, groups, meshParameters) #fineness, parameters, viscousLayers)
|
mesh = meshCreate(shape, groups, meshParameters)
|
||||||
meshCompute(mesh)
|
returncode = meshCompute(mesh)
|
||||||
|
|
||||||
|
if returncode == 0:
|
||||||
|
config.status.mesh = True
|
||||||
|
|
||||||
|
with open(CONFIG, "w") as io:
|
||||||
|
toml.dump({
|
||||||
|
"structure": config.structure,
|
||||||
|
"logger": config.logger.__dict__,
|
||||||
|
"status": config.status.__dict__,
|
||||||
|
"parameters": config.parameters.__dict__,
|
||||||
|
"geometry": config.geometry.__dict__,
|
||||||
|
"mesh": config.mesh.__dict__
|
||||||
|
}, io)
|
||||||
|
|
||||||
meshStats(mesh)
|
meshStats(mesh)
|
||||||
meshExport(mesh, export)
|
meshExport(mesh, os.path.join(CASE, "mesh.unv"))
|
||||||
|
|
||||||
salome.salome_close()
|
salome.salome_close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
genmesh()
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,6 +153,8 @@ def meshCompute(mobj):
|
|||||||
else:
|
else:
|
||||||
logger.warning("meshCompute: not computed")
|
logger.warning("meshCompute: not computed")
|
||||||
|
|
||||||
|
return not status
|
||||||
|
|
||||||
|
|
||||||
def meshStats(mobj):
|
def meshStats(mobj):
|
||||||
"""
|
"""
|
||||||
|
@ -28,7 +28,7 @@ def runExecute(port: int, scriptpath: str, *args) -> int:
|
|||||||
scriptpath, "args:{}".format(", ".join([str(arg) for arg in args]))]
|
scriptpath, "args:{}".format(", ".join([str(arg) for arg in args]))]
|
||||||
|
|
||||||
logger.info("salome: {}".format(cmd[1 : 6]))
|
logger.info("salome: {}".format(cmd[1 : 6]))
|
||||||
logpath = os.path.join("/".join(args[4].split("/")[:-1]), "salome.log")
|
logpath = os.path.join("/".join(args[0].split("/")[:-1]), "salome.log")
|
||||||
|
|
||||||
#p = subprocess.Popen(["salome", "start", "--shutdown-servers=1", "--port", str(port), "-t", scriptpath, "args:{}".format(", ".join([str(arg) for arg in args]))],
|
#p = subprocess.Popen(["salome", "start", "--shutdown-servers=1", "--port", str(port), "-t", scriptpath, "args:{}".format(", ".join([str(arg) for arg in args]))],
|
||||||
# stderr = subprocess.STDOUT)
|
# stderr = subprocess.STDOUT)
|
||||||
|
Loading…
Reference in New Issue
Block a user