New: config file and project configuration
This commit is contained in:
parent
86f5a5264f
commit
ab0bf8f146
@ -1,4 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
if [ "$1" = "clean" ]; then
|
||||||
|
git clean -fdx
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
python ${DIR}/anisotropy/anisotropy.py
|
python ${DIR}/anisotropy/anisotropy.py
|
||||||
|
@ -5,27 +5,43 @@ import shutil
|
|||||||
|
|
||||||
sys.path.append(os.path.abspath("../"))
|
sys.path.append(os.path.abspath("../"))
|
||||||
|
|
||||||
import config
|
|
||||||
#from config import logger
|
|
||||||
#logger = config.logger
|
|
||||||
from utils import struct, checkEnv
|
from utils import struct, checkEnv
|
||||||
|
import toml
|
||||||
|
import logging
|
||||||
|
|
||||||
|
CONFIG = os.path.abspath("../conf/config.toml")
|
||||||
|
config = struct(toml.load(CONFIG))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if not os.path.exists(config.LOG):
|
|
||||||
os.makedirs(config.LOG)
|
|
||||||
|
|
||||||
if not os.path.exists(config.BUILD):
|
#CONFIG = os.path.abspath("../conf/config.toml")
|
||||||
os.makedirs(config.BUILD)
|
#config = struct(toml.load(CONFIG))
|
||||||
|
|
||||||
check = checkEnv()
|
LOG = os.path.abspath("../logs")
|
||||||
|
if not os.path.exists(LOG):
|
||||||
|
os.makedirs(LOG)
|
||||||
|
|
||||||
if check:
|
BUILD = os.path.abspath("../build")
|
||||||
|
if not os.path.exists(BUILD):
|
||||||
|
os.makedirs(BUILD)
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
level = logging.INFO,
|
||||||
|
format = config.logger.format,
|
||||||
|
handlers = [
|
||||||
|
logging.StreamHandler(),
|
||||||
|
logging.FileHandler(f"{ LOG }/{ config.logger.name }.log")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
logger = logging.getLogger(config.logger.name)
|
||||||
|
|
||||||
|
if checkEnv():
|
||||||
return
|
return
|
||||||
|
|
||||||
tasks = createTasks()
|
tasks = createTasks()
|
||||||
|
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
logger.fancyline()
|
logger.info("-" * 80)
|
||||||
logger.info(f"""main:
|
logger.info(f"""main:
|
||||||
task:\t{tasks.index(task) + 1} / {len(tasks)}
|
task:\t{tasks.index(task) + 1} / {len(tasks)}
|
||||||
cpu count:\t{os.cpu_count()}
|
cpu count:\t{os.cpu_count()}
|
||||||
@ -63,25 +79,17 @@ def main():
|
|||||||
|
|
||||||
def createTasks():
|
def createTasks():
|
||||||
tasks = []
|
tasks = []
|
||||||
structures = [ getattr(config, s)() for s in config.structures ]
|
|
||||||
|
|
||||||
for structure in structures:
|
|
||||||
for direction in structure.directions:
|
|
||||||
for theta in structure.theta:
|
|
||||||
name = type(structure).__name__
|
|
||||||
export = os.path.join(
|
|
||||||
config.BUILD,
|
|
||||||
name,
|
|
||||||
"direction-{}{}{}".format(*direction),
|
|
||||||
"theta-{}".format(theta)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
for structure in config.base.__dict__.keys():
|
||||||
|
if getattr(config.base, structure):
|
||||||
|
for direction in getattr(config, structure).geometry.directions:
|
||||||
|
for theta in getattr(config, structure).theta:
|
||||||
task = struct(
|
task = struct(
|
||||||
structure = name,
|
structure = structure,
|
||||||
theta = theta,
|
theta = theta,
|
||||||
fillet = structure.fillet,
|
fillet = getattr(config, structure).geometry.fillet,
|
||||||
direction = direction,
|
direction = direction,
|
||||||
export = export,
|
export = os.path.abspath(f"../build/{ structure }/direction-{ direction[0] }{ direction [1] }{ direction [2] }/theta-{ theta }"),
|
||||||
mesh = False,
|
mesh = False,
|
||||||
flow = False
|
flow = False
|
||||||
)
|
)
|
||||||
@ -93,7 +101,7 @@ def createTasks():
|
|||||||
from salomepl.utils import runExecute
|
from salomepl.utils import runExecute
|
||||||
|
|
||||||
def createMesh(task):
|
def createMesh(task):
|
||||||
scriptpath = os.path.join(config.ROOT, "salome/genmesh.py")
|
scriptpath = os.path.abspath("../salomepl/genmesh.py")
|
||||||
port = 2810
|
port = 2810
|
||||||
stime = time.monotonic()
|
stime = time.monotonic()
|
||||||
|
|
||||||
@ -103,7 +111,7 @@ def createMesh(task):
|
|||||||
int(task.fillet),
|
int(task.fillet),
|
||||||
"".join([str(coord) for coord in task.direction]),
|
"".join([str(coord) for coord in task.direction]),
|
||||||
os.path.join(task.export, "mesh.unv"),
|
os.path.join(task.export, "mesh.unv"),
|
||||||
config.ROOT
|
os.path.abspath("../")
|
||||||
)
|
)
|
||||||
returncode = runExecute(port, scriptpath, *args)
|
returncode = runExecute(port, scriptpath, *args)
|
||||||
|
|
||||||
@ -121,7 +129,7 @@ def calculate(task):
|
|||||||
|
|
||||||
for d in foamCase:
|
for d in foamCase:
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
os.path.join(config.ROOT, "openfoam/template", d),
|
os.path.abspath("../openfoam/template", d),
|
||||||
os.path.join(task.export, d)
|
os.path.join(task.export, d)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -5,7 +5,15 @@ import socket
|
|||||||
|
|
||||||
|
|
||||||
class struct:
|
class struct:
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
if len(args) > 0:
|
||||||
|
if type(args[0]) == dict:
|
||||||
|
for (k, v) in args[0].items():
|
||||||
|
if type(v) == dict:
|
||||||
|
setattr(self, k, struct(v))
|
||||||
|
else:
|
||||||
|
setattr(self, k, v)
|
||||||
|
else:
|
||||||
for (k, v) in kwargs.items():
|
for (k, v) in kwargs.items():
|
||||||
setattr(self, k, v)
|
setattr(self, k, v)
|
||||||
|
|
||||||
|
105
conf/config.toml
Normal file
105
conf/config.toml
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
[logger]
|
||||||
|
name = "anisotropy"
|
||||||
|
format = "%(levelname)s: %(message)s"
|
||||||
|
|
||||||
|
[base]
|
||||||
|
simple = true
|
||||||
|
bodyCentered = true
|
||||||
|
faceCentered = true
|
||||||
|
|
||||||
|
[simple]
|
||||||
|
theta = [0.01, 0.28]
|
||||||
|
|
||||||
|
[simple.geometry]
|
||||||
|
directions = [
|
||||||
|
[1, 0, 0],
|
||||||
|
[0, 0, 1],
|
||||||
|
[1, 1, 1]
|
||||||
|
]
|
||||||
|
fillet = true
|
||||||
|
|
||||||
|
[simple.mesh]
|
||||||
|
fineness = 3
|
||||||
|
minSize = 0.01
|
||||||
|
maxSize = 0.1
|
||||||
|
growthRate = 0.5
|
||||||
|
nbSegPerEdge = 0.5
|
||||||
|
nbSegPerRadius = 0.5
|
||||||
|
chordalErrorEnabled = false
|
||||||
|
chordalError = -1
|
||||||
|
secondOrder = false
|
||||||
|
optimize = true
|
||||||
|
quadAllowed = false
|
||||||
|
useSurfaceCurvature = true
|
||||||
|
fuseEdges = true
|
||||||
|
checkChartBoundary = false
|
||||||
|
|
||||||
|
thickness = 0.005
|
||||||
|
numberOfLayers = 2
|
||||||
|
stretchFactor = 1.2
|
||||||
|
isFacesToIgnore = true
|
||||||
|
|
||||||
|
[bodyCentered]
|
||||||
|
theta = [0.01, 0.18]
|
||||||
|
|
||||||
|
[bodyCentered.geometry]
|
||||||
|
directions = [
|
||||||
|
[1, 0, 0],
|
||||||
|
[0, 0, 1],
|
||||||
|
[1, 1, 1]
|
||||||
|
]
|
||||||
|
fillet = true
|
||||||
|
|
||||||
|
[bodyCentered.mesh]
|
||||||
|
fineness = 3
|
||||||
|
minSize = 0.005
|
||||||
|
maxSize = 0.05
|
||||||
|
growthRate = 0.5
|
||||||
|
nbSegPerEdge = 0.5
|
||||||
|
nbSegPerRadius = 0.5
|
||||||
|
chordalErrorEnabled = false
|
||||||
|
chordalError = -1
|
||||||
|
secondOrder = false
|
||||||
|
optimize = true
|
||||||
|
quadAllowed = false
|
||||||
|
useSurfaceCurvature = true
|
||||||
|
fuseEdges = true
|
||||||
|
checkChartBoundary = false
|
||||||
|
|
||||||
|
thickness = 0.005
|
||||||
|
numberOfLayers = 2
|
||||||
|
stretchFactor = 1.2
|
||||||
|
isFacesToIgnore = true
|
||||||
|
|
||||||
|
[faceCentered]
|
||||||
|
theta = [0.01, 0.13]
|
||||||
|
|
||||||
|
[faceCentered.geometry]
|
||||||
|
directions = [
|
||||||
|
[1, 0, 0],
|
||||||
|
[0, 0, 1],
|
||||||
|
[1, 1, 1]
|
||||||
|
]
|
||||||
|
fillet = true
|
||||||
|
|
||||||
|
[faceCentered.mesh]
|
||||||
|
fineness = 3
|
||||||
|
minSize = 0.005
|
||||||
|
maxSize = 0.05
|
||||||
|
growthRate = 0.5
|
||||||
|
nbSegPerEdge = 0.5
|
||||||
|
nbSegPerRadius = 0.5
|
||||||
|
chordalErrorEnabled = false
|
||||||
|
chordalError = -1
|
||||||
|
secondOrder = false
|
||||||
|
optimize = true
|
||||||
|
quadAllowed = false
|
||||||
|
useSurfaceCurvature = true
|
||||||
|
fuseEdges = true
|
||||||
|
checkChartBoundary = false
|
||||||
|
|
||||||
|
thickness = 0.001
|
||||||
|
numberOfLayers = 2
|
||||||
|
stretchFactor = 1.2
|
||||||
|
isFacesToIgnore = true
|
||||||
|
|
129
config.py
129
config.py
@ -1,129 +0,0 @@
|
|||||||
import os, sys
|
|
||||||
from anisotropy.utils import Logger, struct
|
|
||||||
|
|
||||||
PROJECT = "anisotropy"
|
|
||||||
###
|
|
||||||
# Paths
|
|
||||||
##
|
|
||||||
ROOT = os.getcwd()
|
|
||||||
sys.path.append(ROOT)
|
|
||||||
|
|
||||||
LOG = os.path.join(ROOT, "logs")
|
|
||||||
BUILD = os.path.join(ROOT, "build")
|
|
||||||
|
|
||||||
###
|
|
||||||
# Logger
|
|
||||||
##
|
|
||||||
global logger
|
|
||||||
logger = Logger(PROJECT, os.path.join(LOG, f"{ PROJECT }.log"))
|
|
||||||
|
|
||||||
###
|
|
||||||
# Project variables
|
|
||||||
##
|
|
||||||
structures = [
|
|
||||||
"simple",
|
|
||||||
#"bodyCentered",
|
|
||||||
#"faceCentered"
|
|
||||||
]
|
|
||||||
|
|
||||||
simple = struct(
|
|
||||||
theta = [0.01, 0.02], #[c * 0.01 for c in range(1, 28 + 1)],
|
|
||||||
directions = [
|
|
||||||
[1, 0, 0],
|
|
||||||
[0, 0, 1],
|
|
||||||
[1, 1, 1]
|
|
||||||
],
|
|
||||||
fillet = True,
|
|
||||||
fineness = 3,
|
|
||||||
parameters = struct(
|
|
||||||
minSize = 0.01,
|
|
||||||
maxSize = 0.1,
|
|
||||||
growthRate = 0.5,
|
|
||||||
nbSegPerEdge = 0.5,
|
|
||||||
nbSegPerRadius = 0.5,
|
|
||||||
chordalErrorEnabled = False,
|
|
||||||
chordalError = -1,
|
|
||||||
secondOrder = False,
|
|
||||||
optimize = True,
|
|
||||||
quadAllowed = False,
|
|
||||||
useSurfaceCurvature = True,
|
|
||||||
fuseEdges = True,
|
|
||||||
checkChartBoundary = False
|
|
||||||
),
|
|
||||||
viscousLayers = struct(
|
|
||||||
thickness = 0.005, # 0.01, 0.005 for 0.28, 0.01 for prism
|
|
||||||
numberOfLayers = 2,
|
|
||||||
stretchFactor = 1.2,
|
|
||||||
isFacesToIgnore = True,
|
|
||||||
facesToIgnore = None,
|
|
||||||
extrusionMethod = None
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
bodyCentered = struct(
|
|
||||||
theta = [c * 0.01 for c in range(1, 18 + 1)],
|
|
||||||
directions = [
|
|
||||||
[1, 0, 0],
|
|
||||||
[0, 0, 1],
|
|
||||||
[1, 1, 1]
|
|
||||||
],
|
|
||||||
fillet = True,
|
|
||||||
fineness = 3,
|
|
||||||
parameters = struct(
|
|
||||||
minSize = 0.005,
|
|
||||||
maxSize = 0.05,
|
|
||||||
growthRate = 0.5,
|
|
||||||
nbSegPerEdge = 0.5,
|
|
||||||
nbSegPerRadius = 0.5,
|
|
||||||
chordalErrorEnabled = False,
|
|
||||||
chordalError = -1,
|
|
||||||
secondOrder = False,
|
|
||||||
optimize = True,
|
|
||||||
quadAllowed = False,
|
|
||||||
useSurfaceCurvature = True,
|
|
||||||
fuseEdges = True,
|
|
||||||
checkChartBoundary = False
|
|
||||||
),
|
|
||||||
viscousLayers = struct(
|
|
||||||
thickness = 0.005,
|
|
||||||
numberOfLayers = 2,
|
|
||||||
stretchFactor = 1.2,
|
|
||||||
isFacesToIgnore = True,
|
|
||||||
facesToIgnore = None,
|
|
||||||
extrusionMethod = None
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
faceCentered = struct(
|
|
||||||
theta = [0.06, 0.13], #[c * 0.01 for c in range(1, 13 + 1)]
|
|
||||||
directions = [
|
|
||||||
#[1, 0, 0],
|
|
||||||
#[0, 0, 1],
|
|
||||||
[1, 1, 1]
|
|
||||||
],
|
|
||||||
fillet = True,
|
|
||||||
fineness = 3,
|
|
||||||
parameters = struct(
|
|
||||||
minSize = 0.005,
|
|
||||||
maxSize = 0.05,
|
|
||||||
growthRate = 0.5,
|
|
||||||
nbSegPerEdge = 0.5,
|
|
||||||
nbSegPerRadius = 0.5,
|
|
||||||
chordalErrorEnabled = False,
|
|
||||||
chordalError = -1,
|
|
||||||
secondOrder = False,
|
|
||||||
optimize = True,
|
|
||||||
quadAllowed = False,
|
|
||||||
useSurfaceCurvature = True,
|
|
||||||
fuseEdges = True,
|
|
||||||
checkChartBoundary = False
|
|
||||||
),
|
|
||||||
viscousLayers = struct(
|
|
||||||
thickness = 0.001, # Failing on 0.13-111
|
|
||||||
numberOfLayers = 2,
|
|
||||||
stretchFactor = 1.2,
|
|
||||||
isFacesToIgnore = True,
|
|
||||||
facesToIgnore = None,
|
|
||||||
extrusionMethod = None
|
|
||||||
)
|
|
||||||
)
|
|
@ -3,7 +3,8 @@ import subprocess
|
|||||||
|
|
||||||
sys.path.append(os.path.abspath("../"))
|
sys.path.append(os.path.abspath("../"))
|
||||||
|
|
||||||
from config import logger
|
import logging
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
from openfoam.miscellaneous import *
|
from openfoam.miscellaneous import *
|
||||||
from openfoam.meshConversion import *
|
from openfoam.meshConversion import *
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
numpy
|
numpy
|
||||||
pyquaternion
|
pyquaternion
|
||||||
|
toml
|
||||||
|
@ -11,8 +11,14 @@ import salome
|
|||||||
# get project path from args
|
# get project path from args
|
||||||
sys.path.append(sys.argv[6])
|
sys.path.append(sys.argv[6])
|
||||||
|
|
||||||
import config
|
import toml
|
||||||
from config import logger
|
import logging
|
||||||
|
from anisotropy.utils import struct
|
||||||
|
|
||||||
|
CONFIG = os.path.abspath("../conf/config.toml")
|
||||||
|
config = struct(toml.load(CONFIG))
|
||||||
|
|
||||||
|
logger = logging.getLogger(config.logger.name)
|
||||||
|
|
||||||
from salomepl.simple import simpleCubic, simpleHexagonalPrism
|
from salomepl.simple import simpleCubic, simpleHexagonalPrism
|
||||||
from salomepl.faceCentered import faceCenteredCubic, faceCenteredHexagonalPrism
|
from salomepl.faceCentered import faceCenteredCubic, faceCenteredHexagonalPrism
|
||||||
|
@ -2,7 +2,8 @@ import SMESH
|
|||||||
from salome.smesh import smeshBuilder
|
from salome.smesh import smeshBuilder
|
||||||
smesh = smeshBuilder.New()
|
smesh = smeshBuilder.New()
|
||||||
|
|
||||||
from config import logger
|
import logging
|
||||||
|
logger = logging.getLogger(config.logger.name)
|
||||||
|
|
||||||
def getSmesh():
|
def getSmesh():
|
||||||
return smesh
|
return smesh
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
import sys, os
|
import sys, os
|
||||||
import config
|
|
||||||
from config import logger
|
logger = logging.getLogger()
|
||||||
|
|
||||||
def hasDesktop() -> bool:
|
def hasDesktop() -> bool:
|
||||||
return salome.sg.hasDesktop()
|
return salome.sg.hasDesktop()
|
||||||
|
Loading…
Reference in New Issue
Block a user