anisotropy/samples/__init__.py

97 lines
2.5 KiB
Python
Raw Normal View History

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
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
from simpleCubic import simpleCubic
from faceCenteredCubic import faceCenteredCubic
from bodyCenteredCubic import bodyCenteredCubic
from src import geometry_utils
from src import mesh_utils
2021-03-24 21:27:12 +05:00
2021-04-05 22:15:47 +05:00
def genMesh(stype, theta, fillet, flowdirection, saveto):
2021-03-24 21:27:12 +05:00
_G = globals()
structure = _G.get(stype)
if structure:
salome.salome_init()
2021-04-05 22:15:47 +05:00
grains, geometry1, geometry2 = structure(theta, fillet)
2021-03-30 14:49:06 +05:00
geometry = geometry1
2021-03-24 21:27:12 +05:00
if flowdirection == [1, 1, 1]:
2021-03-30 14:49:06 +05:00
geometry = geometry2
2021-04-02 12:22:55 +05:00
norm = [-1, 1, 0]
2021-03-30 14:49:06 +05:00
bcount = 6
2021-03-30 22:14:47 +05:00
# initial angle
angle = math.pi / 6
2021-04-02 12:22:55 +05:00
v1 = Quaternion(axis = norm, angle = math.pi / 2).rotate(flowdirection)
normvec = Quaternion(axis = flowdirection, angle = angle).rotate(v1)
2021-03-31 23:11:29 +05:00
direction = [1, 1, 1]
2021-03-24 21:27:12 +05:00
if flowdirection == [1, 0, 0]:
2021-03-31 23:11:29 +05:00
normvec = [0, 0, 1]
2021-03-30 14:49:06 +05:00
bcount = 4
2021-03-31 23:11:29 +05:00
direction = [1, 1, 0]
2021-03-24 21:27:12 +05:00
if flowdirection == [0, 0, 1]:
2021-03-31 23:11:29 +05:00
normvec = [1, 1, 0]
2021-03-30 14:49:06 +05:00
bcount = 4
2021-03-31 23:11:29 +05:00
direction = [0, 0, 1]
2021-03-24 21:27:12 +05:00
2021-03-31 23:11:29 +05:00
boundary = geometry_utils.createBoundary(geometry, bcount, direction, normvec, grains)
2021-03-24 21:27:12 +05:00
2021-04-02 21:41:48 +05:00
fineness = 1
viscousLayers = {
"thickness": 0.001,
"number": 2,
"stretch": 1
}
mesh = mesh_utils.meshCreate(geometry, boundary, fineness, viscousLayers)
2021-03-24 21:27:12 +05:00
mesh_utils.meshCompute(mesh)
2021-04-05 22:15:47 +05:00
mesh_utils.meshExport(mesh, saveto)
2021-03-24 21:27:12 +05:00
salome.salome_close()
else:
raise Exception("Unknown sample function")
2021-04-05 22:15:47 +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-04-01 15:48:20 +05:00
logging.info("""genMesh:
structure type:\t{}
coefficient:\t{}
2021-04-05 22:15:47 +05:00
fillet:\t{}
flow direction:\t{}
2021-04-05 22:15:47 +05:00
export path:\t{}""".format(stype, theta, fillet, flowdirection, saveto))
2021-04-05 22:15:47 +05:00
genMesh(stype, theta, fillet, flowdirection, saveto)