Mod: improved logger output
Fix: mistakes in samples Mod: Few images for docs Mod: improved cli
This commit is contained in:
parent
d75602f9f3
commit
9feb150a1c
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,6 +16,5 @@ env/
|
|||||||
*.run.xml
|
*.run.xml
|
||||||
*.synctex.gz
|
*.synctex.gz
|
||||||
*.toc
|
*.toc
|
||||||
*.png
|
|
||||||
*.out
|
*.out
|
||||||
*.egg-info
|
*.egg-info
|
||||||
|
@ -26,6 +26,7 @@ env.update(
|
|||||||
)
|
)
|
||||||
env.update(
|
env.update(
|
||||||
logger_name = "anisotropy",
|
logger_name = "anisotropy",
|
||||||
|
db_name = "anisotropy",
|
||||||
db_path = env["BUILD"],
|
db_path = env["BUILD"],
|
||||||
salome_timeout = 15 * 60,
|
salome_timeout = 15 * 60,
|
||||||
openfoam_template = os.path.join(env["ROOT"], "anisotropy/openfoam/template")
|
openfoam_template = os.path.join(env["ROOT"], "anisotropy/openfoam/template")
|
||||||
|
@ -81,6 +81,16 @@ def anisotropy():
|
|||||||
default = 1,
|
default = 1,
|
||||||
help = "Count of parallel processes"
|
help = "Count of parallel processes"
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"-D", "--database", "database",
|
||||||
|
help = "Database path"
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"-f", "--force", "force",
|
||||||
|
type = click.BOOL,
|
||||||
|
default = False,
|
||||||
|
help = "Overwrite existing entries"
|
||||||
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"-p", "--param", "params",
|
"-p", "--param", "params",
|
||||||
metavar = "key=value",
|
metavar = "key=value",
|
||||||
@ -88,8 +98,8 @@ def anisotropy():
|
|||||||
cls = KeyValueOption,
|
cls = KeyValueOption,
|
||||||
help = "Overwrite existing parameter (except control variables)"
|
help = "Overwrite existing parameter (except control variables)"
|
||||||
)
|
)
|
||||||
def compute(stage, nprocs, params):
|
def compute(stage, nprocs, database, force, params):
|
||||||
from anisotropy.core.main import Anisotropy, logger
|
from anisotropy.core.main import Anisotropy, Database, logger
|
||||||
from anisotropy.core.utils import timer, parallel
|
from anisotropy.core.utils import timer, parallel
|
||||||
|
|
||||||
args = dict()
|
args = dict()
|
||||||
@ -99,14 +109,31 @@ def compute(stage, nprocs, params):
|
|||||||
|
|
||||||
###
|
###
|
||||||
model = Anisotropy()
|
model = Anisotropy()
|
||||||
|
|
||||||
|
if database:
|
||||||
|
if database[-3: ] == ".db":
|
||||||
|
splitted = database.split("/")
|
||||||
|
db_path = "/".join(splitted[ :-1])
|
||||||
|
db_name = splitted[-1: ][0][ :-3]
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise Exception("Invalid database extension")
|
||||||
|
|
||||||
|
model.db = Database(db_name, db_path)
|
||||||
|
|
||||||
|
logger.info("Constructing database, tables ...")
|
||||||
model.db.setup()
|
model.db.setup()
|
||||||
|
|
||||||
|
def fill_db():
|
||||||
if model.db.isempty():
|
if model.db.isempty():
|
||||||
paramsAll = model.loadFromScratch()
|
paramsAll = model.loadFromScratch()
|
||||||
|
|
||||||
for entry in paramsAll:
|
for entry in paramsAll:
|
||||||
model.db.update(entry)
|
model.db.update(entry)
|
||||||
|
|
||||||
|
_, fill_elapsed = timer(fill_db)()
|
||||||
|
logger.info(f"Elapsed time = { fill_elapsed }")
|
||||||
|
|
||||||
###
|
###
|
||||||
def computeCase(stage, type, direction, theta):
|
def computeCase(stage, type, direction, theta):
|
||||||
case = Anisotropy()
|
case = Anisotropy()
|
||||||
@ -114,11 +141,15 @@ def compute(stage, nprocs, params):
|
|||||||
case.evalParams()
|
case.evalParams()
|
||||||
case.update()
|
case.update()
|
||||||
|
|
||||||
|
logger.info(f"Case: type = { type }, direction = { direction }, theta = { theta }")
|
||||||
|
logger.info(f"Stage: { stage }")
|
||||||
|
|
||||||
if stage == "all" or stage == "mesh":
|
if stage == "all" or stage == "mesh":
|
||||||
|
if not case.params.get("meshresult", {}).get("status") == "Done" or force:
|
||||||
(out, err, returncode), elapsed = timer(case.computeMesh)()
|
(out, err, returncode), elapsed = timer(case.computeMesh)()
|
||||||
|
|
||||||
click.echo(out)
|
if out: logger.info(out)
|
||||||
click.echo(err)
|
if err: logger.error(err)
|
||||||
|
|
||||||
case.load(type, direction, theta)
|
case.load(type, direction, theta)
|
||||||
|
|
||||||
@ -130,11 +161,15 @@ def compute(stage, nprocs, params):
|
|||||||
logger.error("Mesh computation failed. Skipping flow computation ...")
|
logger.error("Mesh computation failed. Skipping flow computation ...")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.info("Mesh exists. Skipping ...")
|
||||||
|
|
||||||
if stage == "all" or stage == "flow":
|
if stage == "all" or stage == "flow":
|
||||||
|
if not case.params.get("flowresult", {}).get("status") == "Done" or force:
|
||||||
(out, err, returncode), elapsed = timer(case.computeFlow)()
|
(out, err, returncode), elapsed = timer(case.computeFlow)()
|
||||||
|
|
||||||
click.echo(out)
|
if out: logger.info(out)
|
||||||
click.echo(err)
|
if err: logger.error(err)
|
||||||
|
|
||||||
case.load(type, direction, theta)
|
case.load(type, direction, theta)
|
||||||
|
|
||||||
@ -146,6 +181,9 @@ def compute(stage, nprocs, params):
|
|||||||
logger.error("Flow computation failed.")
|
logger.error("Flow computation failed.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.info("Flow exists. Skipping ...")
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
params = model.db.loadGeneral(
|
params = model.db.loadGeneral(
|
||||||
|
@ -27,8 +27,8 @@ from anisotropy.samples import Simple, FaceCentered, BodyCentered
|
|||||||
logger = logging.getLogger(env["logger_name"])
|
logger = logging.getLogger(env["logger_name"])
|
||||||
setupLogger(logger, logging.INFO, env["LOG"])
|
setupLogger(logger, logging.INFO, env["LOG"])
|
||||||
|
|
||||||
peeweeLogger = logging.getLogger("peewee")
|
#peeweeLogger = logging.getLogger("peewee")
|
||||||
peeweeLogger.setLevel(logging.INFO)
|
#peeweeLogger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
class Anisotropy(object):
|
class Anisotropy(object):
|
||||||
@ -38,7 +38,7 @@ class Anisotropy(object):
|
|||||||
"""Constructor method"""
|
"""Constructor method"""
|
||||||
|
|
||||||
self.env = env
|
self.env = env
|
||||||
self.db = Database("anisotropy", env["db_path"])
|
self.db = Database(self.env["db_name"], self.env["db_path"])
|
||||||
self.params = []
|
self.params = []
|
||||||
|
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ class Anisotropy(object):
|
|||||||
*salomeargs,
|
*salomeargs,
|
||||||
timeout = self.env["salome_timeout"],
|
timeout = self.env["salome_timeout"],
|
||||||
root = self.env["ROOT"],
|
root = self.env["ROOT"],
|
||||||
logpath = os.path.join(self.env["LOG"], "salome.log")
|
logpath = self.env["LOG"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -260,20 +260,14 @@ class Anisotropy(object):
|
|||||||
|
|
||||||
p = self.params
|
p = self.params
|
||||||
|
|
||||||
logger.info("\n".join([
|
|
||||||
"genmesh:",
|
|
||||||
f"structure type:\t{ p['structure']['type'] }",
|
|
||||||
f"coefficient:\t{ p['structure']['theta'] }",
|
|
||||||
f"fillet:\t{ p['structure']['fillets'] }",
|
|
||||||
f"flow direction:\t{ p['structure']['direction'] }"
|
|
||||||
]))
|
|
||||||
|
|
||||||
salome.salome_init()
|
salome.salome_init()
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Shape
|
# Shape
|
||||||
##
|
##
|
||||||
|
logger.info("Constructing shape ...")
|
||||||
|
|
||||||
geompy = salomepl.geometry.getGeom()
|
geompy = salomepl.geometry.getGeom()
|
||||||
structure = dict(
|
structure = dict(
|
||||||
simple = Simple,
|
simple = Simple,
|
||||||
@ -284,17 +278,12 @@ class Anisotropy(object):
|
|||||||
|
|
||||||
[length, surfaceArea, volume] = geompy.BasicProperties(shape, theTolerance = 1e-06)
|
[length, surfaceArea, volume] = geompy.BasicProperties(shape, theTolerance = 1e-06)
|
||||||
|
|
||||||
logger.info("\n".join([
|
|
||||||
"shape:",
|
|
||||||
f"edges length:\t{ length }",
|
|
||||||
f"surface area:\t{ surfaceArea }",
|
|
||||||
f"volume:\t{ volume }"
|
|
||||||
]))
|
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Mesh
|
# Mesh
|
||||||
##
|
##
|
||||||
|
logger.info("Prepairing mesh ...")
|
||||||
|
|
||||||
mp = p["mesh"]
|
mp = p["mesh"]
|
||||||
|
|
||||||
lengths = [
|
lengths = [
|
||||||
@ -332,6 +321,7 @@ class Anisotropy(object):
|
|||||||
|
|
||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
|
logger.info("Computing mesh ...")
|
||||||
out, err, returncode = mesh.compute()
|
out, err, returncode = mesh.compute()
|
||||||
|
|
||||||
###
|
###
|
||||||
@ -345,6 +335,7 @@ class Anisotropy(object):
|
|||||||
|
|
||||||
casePath = self.getCasePath()
|
casePath = self.getCasePath()
|
||||||
os.makedirs(casePath, exist_ok = True)
|
os.makedirs(casePath, exist_ok = True)
|
||||||
|
logger.info("Exporting mesh ...")
|
||||||
mesh.exportUNV(os.path.join(casePath, "mesh.unv"))
|
mesh.exportUNV(os.path.join(casePath, "mesh.unv"))
|
||||||
|
|
||||||
meshStats = mesh.stats()
|
meshStats = mesh.stats()
|
||||||
@ -356,10 +347,6 @@ class Anisotropy(object):
|
|||||||
)
|
)
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
logger.info("mesh stats:\n{}".format(
|
|
||||||
"\n".join(map(lambda v: f"{ v[0] }:\t{ v[1] }", meshStats.items()))
|
|
||||||
))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
|
|
||||||
@ -389,6 +376,11 @@ class Anisotropy(object):
|
|||||||
|
|
||||||
# ISSUE: ideasUnvToFoam cannot import mesh with '-case' flag so 'os.chdir' for that
|
# ISSUE: ideasUnvToFoam cannot import mesh with '-case' flag so 'os.chdir' for that
|
||||||
casePath = self.getCasePath()
|
casePath = self.getCasePath()
|
||||||
|
|
||||||
|
if not os.path.exists(casePath):
|
||||||
|
logger.warning(f"Cannot find case path. Skipping computation ...\n\t{ casePath }")
|
||||||
|
return "", "", 1
|
||||||
|
|
||||||
os.chdir(casePath)
|
os.chdir(casePath)
|
||||||
openfoam.foamClean()
|
openfoam.foamClean()
|
||||||
|
|
||||||
@ -404,7 +396,7 @@ class Anisotropy(object):
|
|||||||
if not os.path.exists("mesh.unv"):
|
if not os.path.exists("mesh.unv"):
|
||||||
logger.error(f"missed 'mesh.unv'")
|
logger.error(f"missed 'mesh.unv'")
|
||||||
os.chdir(self.env["ROOT"])
|
os.chdir(self.env["ROOT"])
|
||||||
return 1
|
return "", "", 1
|
||||||
|
|
||||||
out, err, returncode = openfoam.ideasUnvToFoam("mesh.unv")
|
out, err, returncode = openfoam.ideasUnvToFoam("mesh.unv")
|
||||||
|
|
||||||
@ -499,8 +491,6 @@ class Anisotropy(object):
|
|||||||
# )
|
# )
|
||||||
|
|
||||||
out, err, returncode = openfoam.simpleFoam()
|
out, err, returncode = openfoam.simpleFoam()
|
||||||
if out:
|
|
||||||
logger.info(out)
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Results
|
# Results
|
||||||
@ -521,8 +511,7 @@ class Anisotropy(object):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
self.params["flowresult"].update(
|
self.params["flowresult"].update(
|
||||||
status = "Failed",
|
status = "Failed"
|
||||||
flowRate = flowRate
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -530,6 +519,6 @@ class Anisotropy(object):
|
|||||||
|
|
||||||
os.chdir(self.env["ROOT"])
|
os.chdir(self.env["ROOT"])
|
||||||
|
|
||||||
return out, err, returncode
|
return out, str(err, "utf-8"), returncode
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ def setupLogger(logger, level: int, filepath: str = None):
|
|||||||
:param filepath: Path to directory
|
:param filepath: Path to directory
|
||||||
:type filepath: str, optional
|
:type filepath: str, optional
|
||||||
"""
|
"""
|
||||||
|
logger.handlers = []
|
||||||
logger.setLevel(level)
|
logger.setLevel(level)
|
||||||
|
|
||||||
streamhandler = logging.StreamHandler()
|
streamhandler = logging.StreamHandler()
|
||||||
|
@ -42,9 +42,9 @@ def application(name: str, *args: str, case: str = None, stderr: bool = True, us
|
|||||||
out, err = p.communicate()
|
out, err = p.communicate()
|
||||||
logfile.write(err)
|
logfile.write(err)
|
||||||
|
|
||||||
if err and stderr:
|
#if err and stderr:
|
||||||
logger.error("""{}:
|
# logger.error("""{}:
|
||||||
{}""".format(name, str(err, "utf-8")))
|
# {}""".format(name, str(err, "utf-8")))
|
||||||
|
|
||||||
return out, err, p.returncode
|
return out, err, p.returncode
|
||||||
|
|
||||||
|
@ -8,10 +8,12 @@ import re
|
|||||||
|
|
||||||
def potentialFoam(case: str = None, useMPI: bool = False):
|
def potentialFoam(case: str = None, useMPI: bool = False):
|
||||||
if useMPI:
|
if useMPI:
|
||||||
application("potentialFoam", "-parallel", useMPI = True, case = case, stderr = True)
|
out, err, returncode = application("potentialFoam", "-parallel", useMPI = True, case = case, stderr = True)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
application("potentialFoam", case = case, stderr = True)
|
out, err, returncode = application("potentialFoam", case = case, stderr = True)
|
||||||
|
|
||||||
|
return out, err, returncode
|
||||||
|
|
||||||
|
|
||||||
def simpleFoam(case: str = None, useMPI: bool = False):
|
def simpleFoam(case: str = None, useMPI: bool = False):
|
||||||
|
@ -155,13 +155,13 @@ class FaceCentered(object):
|
|||||||
xy = geompy.MakeVectorDXDYDZ(1, 1, 0)
|
xy = geompy.MakeVectorDXDYDZ(1, 1, 0)
|
||||||
xmy = geompy.MakeVectorDXDYDZ(1, -1, 0)
|
xmy = geompy.MakeVectorDXDYDZ(1, -1, 0)
|
||||||
|
|
||||||
grain = geompy.MakeSpherePntR(geompy.MakeVertex(*spos1), radius)
|
grain = geompy.MakeSpherePntR(geompy.MakeVertex(*spos1), self.radius)
|
||||||
lattice1 = geompy.MakeMultiTranslation2D(grain, xy, length, xn, xmy, length, yn)
|
lattice1 = geompy.MakeMultiTranslation2D(grain, xy, length, xn, xmy, length, yn)
|
||||||
lattice1 = geompy.MakeMultiTranslation1D(lattice1, oz, L, zn - 1)
|
lattice1 = geompy.MakeMultiTranslation1D(lattice1, oz, self.L, zn - 1)
|
||||||
|
|
||||||
grain = geompy.MakeSpherePntR(geompy.MakeVertex(*spos2), radius)
|
grain = geompy.MakeSpherePntR(geompy.MakeVertex(*spos2), self.radius)
|
||||||
lattice2 = geompy.MakeMultiTranslation2D(grain, xy, length, xn + 1, xmy, length, yn + 1)
|
lattice2 = geompy.MakeMultiTranslation2D(grain, xy, length, xn + 1, xmy, length, yn + 1)
|
||||||
lattice2 = geompy.MakeMultiTranslation1D(lattice2, oz, L, zn)
|
lattice2 = geompy.MakeMultiTranslation1D(lattice2, oz, self.L, zn)
|
||||||
|
|
||||||
grains = geompy.ExtractShapes(lattice1, geompy.ShapeType["SOLID"], True)
|
grains = geompy.ExtractShapes(lattice1, geompy.ShapeType["SOLID"], True)
|
||||||
grains += geompy.ExtractShapes(lattice2, geompy.ShapeType["SOLID"], True)
|
grains += geompy.ExtractShapes(lattice2, geompy.ShapeType["SOLID"], True)
|
||||||
|
BIN
docs/source/static/er-diagram.png
Normal file
BIN
docs/source/static/er-diagram.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 284 KiB |
BIN
docs/source/static/structure.png
Normal file
BIN
docs/source/static/structure.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 207 KiB |
Loading…
Reference in New Issue
Block a user