anisotropy/salomepl/genmesh.py

102 lines
2.4 KiB
Python
Raw Normal View History

2021-05-26 17:18:39 +05:00
###
# This file executes inside salome environment
2021-05-26 22:02:44 +05:00
#
# salome starts at user home directory
2021-06-02 16:12:34 +05:00
#
# sys.argv = [ .., ROOT, case ]
2021-05-26 17:18:39 +05:00
##
import os, sys
2021-04-01 15:48:20 +05:00
import math
2021-03-24 21:27:12 +05:00
import salome
2021-05-26 22:02:44 +05:00
# get project path from args
2021-06-02 16:12:34 +05:00
ROOT = sys.argv[1]
CASE = sys.argv[2]
sys.path.append(ROOT)
# site-packages from virtual env
sys.path.append(os.path.join(ROOT, "env/lib/python3.9/site-packages"))
import toml
import logging
from anisotropy.utils import struct
2021-06-02 16:12:34 +05:00
CONFIG = os.path.join(CASE, "task.toml")
config = struct(toml.load(CONFIG))
LOG = os.path.join(ROOT, "logs")
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)
2021-06-02 12:41:12 +05:00
from salomepl.simple import simple
from salomepl.faceCentered import faceCentered
from salomepl.bodyCentered import bodyCentered
2021-05-26 22:02:44 +05:00
from salomepl.geometry import getGeom
from salomepl.mesh import smeshBuilder, meshCreate, meshCompute, meshStats, meshExport
2021-03-24 21:27:12 +05:00
2021-06-02 16:12:34 +05:00
def genmesh():
2021-06-02 16:12:34 +05:00
logger.info(f"""genmesh:
structure type:\t{ config.structure }
coefficient:\t{ config.parameters.theta }
fillet:\t{ config.geometry.fillet }
flow direction:\t{ config.geometry.direction }""")
2021-03-24 21:27:12 +05:00
2021-04-12 16:00:26 +05:00
salome.salome_init()
###
# Shape
##
2021-05-26 22:02:44 +05:00
geompy = getGeom()
2021-06-02 16:12:34 +05:00
structure = globals().get(config.structure)
shape, groups = structure(config.parameters.theta, config.geometry.fillet, config.geometry.direction)
2021-04-12 16:00:26 +05:00
[length, surfaceArea, volume] = geompy.BasicProperties(shape, theTolerance = 1e-06)
2021-06-02 16:12:34 +05:00
logger.info(f"""shape:
edges length:\t{ length }
surface area:\t{ surfaceArea }
volume:\t{ volume }""")
2021-04-12 16:00:26 +05:00
###
# Mesh
##
facesToIgnore = []
for group in groups:
if group.GetName() in ["inlet", "outlet"]:
facesToIgnore.append(group)
2021-06-02 16:12:34 +05:00
meshParameters = config.mesh
meshParameters.facesToIgnore = facesToIgnore
meshParameters.extrusionMethod = smeshBuilder.SURF_OFFSET_SMOOTH
2021-04-12 16:00:26 +05:00
2021-06-08 17:15:44 +05:00
mesh = meshCreate(shape, meshParameters)
returncode = meshCompute(mesh, groups)
2021-06-02 16:12:34 +05:00
if returncode == 0:
config.status.mesh = True
with open(CONFIG, "w") as io:
toml.dump(dict(config), io)
2021-03-24 21:27:12 +05:00
2021-05-26 22:02:44 +05:00
meshStats(mesh)
2021-06-02 16:12:34 +05:00
meshExport(mesh, os.path.join(CASE, "mesh.unv"))
2021-04-12 16:00:26 +05:00
salome.salome_close()
2021-04-05 22:15:47 +05:00
if __name__ == "__main__":
2021-06-02 16:12:34 +05:00
genmesh()