anisotropy/salomepl/genmesh.py

143 lines
3.7 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-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
ROOT = sys.argv[6]
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
CONFIG = os.path.join(ROOT, "conf/config.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-05-26 22:02:44 +05:00
from salomepl.simple import simpleCubic, simpleHexagonalPrism
from salomepl.faceCentered import faceCenteredCubic, faceCenteredHexagonalPrism
from salomepl.bodyCentered import bodyCenteredCubic, bodyCenteredHexagonalPrism
from salomepl.geometry import getGeom
from salomepl.mesh import smeshBuilder, meshCreate, meshCompute, meshStats, meshExport
2021-03-24 21:27:12 +05:00
def main():
stype = str(sys.argv[1])
theta = float(sys.argv[2])
fillet = int(sys.argv[3])
flowdirection = [int(coord) for coord in sys.argv[4]]
export = str(sys.argv[5])
2021-05-26 22:02:44 +05:00
genmesh(stype, theta, fillet, flowdirection, export)
2021-05-26 22:02:44 +05:00
def genmesh(stype, theta, fillet, direction, export):
logger.info("""genMesh:
2021-04-12 16:00:26 +05:00
structure type:\t{}
coefficient:\t{}
fillet:\t{}
flow direction:\t{}
export path:\t{}""".format(stype, theta, fillet, direction, export))
2021-03-24 21:27:12 +05:00
2021-04-12 16:00:26 +05:00
params = (theta, fillet, direction)
2021-03-30 22:14:47 +05:00
2021-04-12 16:00:26 +05:00
salome.salome_init()
###
# Structure and mesh configurations
##
if stype == "simple":
if direction in [[1, 0, 0], [0, 0, 1]]:
structure = simpleCubic
2021-03-24 21:27:12 +05:00
2021-04-12 16:00:26 +05:00
elif direction == [1, 1, 1]:
structure = simpleHexagonalPrism
2021-03-24 21:27:12 +05:00
#fineness = config.simple.fineness
#parameters = config.simple.parameters
#viscousLayers = config.simple.viscousLayers
meshParameters = config.simple.mesh
2021-04-12 16:00:26 +05:00
elif stype == "faceCentered":
if direction in [[1, 0, 0], [0, 0, 1]]:
structure = faceCenteredCubic
2021-04-08 00:13:27 +05:00
2021-04-12 16:00:26 +05:00
elif direction == [1, 1, 1]:
structure = faceCenteredHexagonalPrism
2021-03-24 21:27:12 +05:00
#fineness = config.faceCentered.fineness
#parameters = config.faceCentered.parameters
#viscousLayers = config.faceCentered.viscousLayers
meshParameters = config.faceCentered.mesh
2021-04-12 16:00:26 +05:00
elif stype == "bodyCentered":
if direction in [[1, 0, 0], [0, 0, 1]]:
structure = bodyCenteredCubic
2021-03-24 21:27:12 +05:00
2021-04-12 16:00:26 +05:00
elif direction == [1, 1, 1]:
structure = bodyCenteredHexagonalPrism
#fineness = config.bodyCentered.fineness
#parameters = config.bodyCentered.parameters
#viscousLayers = config.bodyCentered.viscousLayers
meshParameters = config.bodyCentered.mesh
2021-04-12 16:00:26 +05:00
###
# Shape
##
2021-05-26 22:02:44 +05:00
geompy = getGeom()
2021-04-12 16:00:26 +05:00
shape, groups = structure(*params)
[length, surfaceArea, volume] = geompy.BasicProperties(shape, theTolerance = 1e-06)
logger.info("""shape:
2021-04-13 22:06:25 +05:00
edges length:\t{}
2021-04-12 16:00:26 +05:00
surface area:\t{}
2021-04-13 22:06:25 +05:00
volume:\t{}""".format(length, surfaceArea, volume))
2021-04-12 16:00:26 +05:00
###
# Mesh
##
facesToIgnore = []
for group in groups:
if group.GetName() in ["inlet", "outlet"]:
facesToIgnore.append(group)
meshParameters.facesToIgnore = facesToIgnore
meshParameters.extrusionMethod = smeshBuilder.SURF_OFFSET_SMOOTH
2021-04-12 16:00:26 +05:00
mesh = meshCreate(shape, groups, meshParameters) #fineness, parameters, viscousLayers)
2021-05-26 22:02:44 +05:00
meshCompute(mesh)
2021-03-24 21:27:12 +05:00
2021-05-26 22:02:44 +05:00
meshStats(mesh)
meshExport(mesh, export)
2021-04-12 16:00:26 +05:00
salome.salome_close()
2021-04-05 22:15:47 +05:00
if __name__ == "__main__":
main()