2021-03-25 23:22:21 +05:00
|
|
|
from collections import namedtuple
|
|
|
|
import os, sys
|
|
|
|
import logging
|
2021-03-30 22:14:47 +05:00
|
|
|
from pyquaternion import Quaternion
|
2021-04-01 15:48:20 +05:00
|
|
|
import math
|
2021-03-24 21:27:12 +05:00
|
|
|
|
2021-03-25 23:22:21 +05:00
|
|
|
ROOT = "/home/nafaryus/projects/anisotrope-cube"
|
|
|
|
sys.path.append(ROOT)
|
|
|
|
|
|
|
|
LOG = os.path.join(ROOT, "logs")
|
2021-03-24 21:27:12 +05:00
|
|
|
|
|
|
|
import salome
|
2021-03-25 23:22:21 +05:00
|
|
|
|
2021-04-12 16:00:26 +05:00
|
|
|
from simple import simpleCubic, simpleHexagonalPrism
|
|
|
|
from faceCentered import faceCenteredCubic, faceCenteredHexagonalPrism
|
|
|
|
from bodyCentered import bodyCenteredCubic, bodyCenteredHexagonalPrism
|
2021-03-25 23:22:21 +05:00
|
|
|
|
|
|
|
from src import geometry_utils
|
|
|
|
from src import mesh_utils
|
2021-03-24 21:27:12 +05:00
|
|
|
|
2021-04-12 16:00:26 +05:00
|
|
|
def genMesh(stype, theta, fillet, direction, saveto):
|
2021-03-24 21:27:12 +05:00
|
|
|
|
2021-04-12 16:00:26 +05:00
|
|
|
logging.info("""genMesh:
|
|
|
|
structure type:\t{}
|
|
|
|
coefficient:\t{}
|
|
|
|
fillet:\t{}
|
|
|
|
flow direction:\t{}
|
|
|
|
export path:\t{}""".format(stype, theta, fillet, direction, saveto))
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
###
|
|
|
|
# Shape
|
|
|
|
##
|
|
|
|
geompy = geometry_utils.getGeom()
|
|
|
|
shape, groups = structure(*params)
|
|
|
|
[length, surfaceArea, volume] = geompy.BasicProperties(shape, theTolerance = 1e-06)
|
|
|
|
|
|
|
|
logging.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
|
|
|
|
##
|
2021-04-13 22:06:25 +05:00
|
|
|
fineness = 0
|
2021-04-12 16:00:26 +05:00
|
|
|
parameters = mesh_utils.Parameters(
|
|
|
|
minSize = 0.001,
|
|
|
|
maxSize = 0.1,
|
2021-04-14 15:13:41 +05:00
|
|
|
growthRate = 0.5,
|
|
|
|
nbSegPerEdge = 0.5,
|
|
|
|
nbSegPerRadius = 0.5,
|
2021-04-12 16:00:26 +05:00
|
|
|
chordalErrorEnabled = False,
|
|
|
|
chordalError = -1,
|
|
|
|
secondOrder = False,
|
|
|
|
optimize = True,
|
|
|
|
quadAllowed = False,
|
|
|
|
useSurfaceCurvature = True,
|
|
|
|
fuseEdges = True,
|
|
|
|
checkChartBoundary = False
|
|
|
|
)
|
|
|
|
|
|
|
|
facesToIgnore = []
|
|
|
|
for group in groups:
|
|
|
|
if group.GetName() in ["inlet", "outlet"]:
|
|
|
|
facesToIgnore.append(group)
|
|
|
|
|
|
|
|
viscousLayers = mesh_utils.ViscousLayers(
|
|
|
|
thickness = 0.001,
|
|
|
|
numberOfLayers = 3,
|
|
|
|
stretchFactor = 1.2,
|
|
|
|
isFacesToIgnore = True,
|
|
|
|
facesToIgnore = facesToIgnore,
|
|
|
|
extrusionMethod = mesh_utils.smeshBuilder.NODE_OFFSET
|
|
|
|
)
|
|
|
|
|
|
|
|
mesh = mesh_utils.meshCreate(shape, groups, fineness, parameters, viscousLayers)
|
|
|
|
mesh_utils.meshCompute(mesh)
|
2021-03-24 21:27:12 +05:00
|
|
|
|
2021-04-12 16:00:26 +05:00
|
|
|
mesh_utils.meshExport(mesh, saveto)
|
2021-03-24 21:27:12 +05:00
|
|
|
|
2021-04-12 16:00:26 +05:00
|
|
|
salome.salome_close()
|
2021-03-25 23:22:21 +05:00
|
|
|
|
2021-04-05 22:15:47 +05:00
|
|
|
|
2021-03-25 23:22:21 +05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.INFO,
|
|
|
|
format="%(levelname)s: %(message)s",
|
|
|
|
handlers = [
|
|
|
|
logging.StreamHandler(),
|
|
|
|
logging.FileHandler("{}/cubic.log".format(LOG))
|
|
|
|
])
|
|
|
|
|
|
|
|
stype = str(sys.argv[1])
|
|
|
|
theta = float(sys.argv[2])
|
2021-04-05 22:15:47 +05:00
|
|
|
fillet = True if int(sys.argv[3]) == 1 else False
|
|
|
|
flowdirection = [int(coord) for coord in sys.argv[4]]
|
|
|
|
saveto = str(sys.argv[5])
|
2021-03-25 23:22:21 +05:00
|
|
|
|
2021-04-05 22:15:47 +05:00
|
|
|
genMesh(stype, theta, fillet, flowdirection, saveto)
|
2021-03-25 23:22:21 +05:00
|
|
|
|