From 8e1e14217aed0acccd3a41679a0cbc6fe1a44cf2 Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Tue, 8 Jun 2021 17:15:44 +0500 Subject: [PATCH] Mod: minor changes --- anisotropy/anisotropy.py | 40 ++++++++++++++++++---------------------- conf/config.toml | 16 +++++++++------- salomepl/genmesh.py | 4 ++-- salomepl/mesh.py | 26 +++++++++----------------- 4 files changed, 38 insertions(+), 48 deletions(-) diff --git a/anisotropy/anisotropy.py b/anisotropy/anisotropy.py index 72b921c..3fbca89 100644 --- a/anisotropy/anisotropy.py +++ b/anisotropy/anisotropy.py @@ -1,6 +1,6 @@ import os, sys import time -from datetime import timedelta +from datetime import timedelta, datetime import shutil ROOT = "/".join(__file__.split("/")[:-2]) @@ -62,11 +62,14 @@ def main(): queue = createQueue() for n, case in enumerate(queue): + date = datetime.now() logger.info("-" * 80) logger.info(f"""main: task:\t{ n + 1 } / { len(queue) } cpu count:\t{ os.cpu_count() } - case:\t{ case }""") + case:\t{ case } + date:\t{ date.date() } + time:\t{ date.time() }""") ### # Compute mesh @@ -84,7 +87,7 @@ def main(): task = struct(toml.load(taskPath)) if not task.status.mesh: - logger.critical("mesh not computed: Skipping flow computation") + logger.critical("mesh not computed: skip flow computation") continue ### @@ -128,7 +131,7 @@ def createQueue(): case = os.path.join( f"{ BUILD }", f"{ structure }", - f"direction-{ direction[0] }{ direction [1] }{ direction [2] }", + "direction-{}{}{}".format(*direction), f"theta-{ theta }" ) @@ -228,7 +231,7 @@ def computeFlow(case): _, returncode = openfoam.ideasUnvToFoam("mesh.unv") if returncode: - os.chdir(config.ROOT) + os.chdir(ROOT) return returncode @@ -324,6 +327,14 @@ def computeFlow(case): task.status.flow = True task.statistics.flowTime = elapsed + postProcessing = "postProcessing/flowRatePatch(name=outlet)/0/surfaceFieldValue.dat" + + with open(postProcessing, "r") as io: + lastLine = io.readlines()[-1] + flowRate = float(lastLine.replace(" ", "").replace("\n", "").split("\t")[1]) + + task.statistics.flowRate = flowRate + with open(os.path.join(case, "task.toml"), "w") as io: toml.dump(dict(task), io) @@ -351,24 +362,9 @@ def checkEnv(): return missed -def postprocessing(tasks): - - surfaceFieldValue = {} - porosity = {} - - for task in tasks: - direction = "direction-{}{}{}".format(task.direction[0], task.direction[1], task.direction[2]) - path = os.path.join(BUILD, task.structure, "postProcessing", direction) - surfaceFieldValuePath = os.path.join(task.export, "postProcessing", "") - - if not os.path.exists(path): - os.makedirs(path) - - surfaceFieldValues = [ line.strip().split() for line in open(surfaceFieldValuePath, "r").readlines() ] - - with open(os.path.join(path, "porosity.dat")) as io: - io.write("{}\t{}".format(task.coeff, surfaceFieldValues[-1][1])) +def postprocessing(queue): + pass ### # Main entry diff --git a/conf/config.toml b/conf/config.toml index fde9203..ad0e9ae 100644 --- a/conf/config.toml +++ b/conf/config.toml @@ -1,7 +1,9 @@ ### # Default config for anisotropy # -# theta = [min, max, step] +# Special values: +# theta = [min, max, step] +# thickness = [min, max] ## [logger] @@ -10,7 +12,7 @@ format = "%(levelname)s: %(message)s" [base] simple = true -bodyCentered = true +bodyCentered = false faceCentered = true ### @@ -63,7 +65,7 @@ directions = [ fillet = true [bodyCentered.mesh] -fineness = 3 +fineness = 2 minSize = 0.005 maxSize = 0.05 growthRate = 0.5 @@ -98,7 +100,7 @@ directions = [ fillet = true [faceCentered.mesh] -fineness = 3 +fineness = 2 minSize = 0.005 maxSize = 0.05 growthRate = 0.5 @@ -136,9 +138,9 @@ outlet.value = 0 [flow.approx.velocity.boundaryField] inlet.type = "fixedValue" inlet.value = [ - [ 6e-5, 6e-5, 0.0 ], - [ 0.0, 0.0, 6e-5 ], - [ 6e-5, 6e-5, 6e-5 ] + [ 6e-5, 6e-5, 0.0 ], + [ 0.0, 0.0, 6e-5 ], + [ 6e-5, 6e-5, 6e-5 ] ] outlet.type = "zeroGradient" outlet.value = "None" diff --git a/salomepl/genmesh.py b/salomepl/genmesh.py index 4ec2b31..8440ae3 100644 --- a/salomepl/genmesh.py +++ b/salomepl/genmesh.py @@ -80,8 +80,8 @@ def genmesh(): meshParameters.facesToIgnore = facesToIgnore meshParameters.extrusionMethod = smeshBuilder.SURF_OFFSET_SMOOTH - mesh = meshCreate(shape, groups, meshParameters) - returncode = meshCompute(mesh) + mesh = meshCreate(shape, meshParameters) + returncode = meshCompute(mesh, groups) if returncode == 0: config.status.mesh = True diff --git a/salomepl/mesh.py b/salomepl/mesh.py index 6b654a4..cdf1c82 100644 --- a/salomepl/mesh.py +++ b/salomepl/mesh.py @@ -9,7 +9,7 @@ def getSmesh(): return smesh -def meshCreate(shape, groups, parameters): #fineness, parameters, viscousLayers = None): +def meshCreate(shape, parameters): #fineness, parameters, viscousLayers = None): """ Creates a mesh from a geometry. @@ -85,16 +85,9 @@ def meshCreate(shape, groups, parameters): #fineness, parameters, viscousLayers True if param.GetOptimize() else False)) - ### - # Groups - ## - for group in groups: - mesh.GroupOnGeom(group, "{}_".format(group.GetName()), SMESH.FACE) - ### # Viscous layers ## - #if not viscousLayers is None: vlayer = netgen.ViscousLayers( parameters.thickness, parameters.numberOfLayers, @@ -113,17 +106,10 @@ viscous layers: parameters.numberOfLayers, parameters.stretchFactor)) - - - #else: - # logger.info("""meshCreate: - #viscous layers: disabled""") - - return mesh -def meshCompute(mobj): +def meshCompute(mobj, groups): """Compute the mesh.""" status = mobj.Compute() @@ -149,7 +135,13 @@ def meshCompute(mobj): mobj.RemoveGroup(pyramidGroup) mobj.RenumberElements() - + + ### + # Groups + ## + for group in groups: + mobj.GroupOnGeom(group, f"{ group.GetName() }_", SMESH.FACE) + else: logger.warning("meshCompute: not computed")