New: fillet control

This commit is contained in:
L-Nafaryus 2021-04-05 22:15:47 +05:00
parent 517145446b
commit 2df2cd0b8f
No known key found for this signature in database
GPG Key ID: C76D8DCD2727DBB7
6 changed files with 119 additions and 144 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ logs/
*.synctex.gz
*.toc
*.png
*.out

35
run.py
View File

@ -23,23 +23,24 @@ def createTasks():
"faceCenteredCubic"
]
directions = [
#[1, 0, 0],
#[0, 0, 1],
[1, 0, 0],
[0, 0, 1],
[1, 1, 1]
]
fillet = 0
Task = namedtuple("Task", ["structure", "coeff", "direction", "saveto"])
Task = namedtuple("Task", ["structure", "coeff", "fillet", "direction", "saveto"])
tasks = []
for structure in structures:
if structure == "simpleCubic":
theta = [] #[0.01, 0.28] #[c * 0.01 for c in range(1, 29 + 1)]
theta = [c * 0.01 for c in range(1, 28 + 1)]
elif structure == "faceCenteredCubic":
theta = [0.01, 0.13] #[c * 0.01 for c in range(1, 13 + 1)]
theta = [c * 0.01 for c in range(1, 13 + 1)]
elif structure == "bodyCenteredCubic":
theta = [0.01, 0.13, 0.14, 0.18] #[c * 0.01 for c in range(1, 18 + 1)]
theta = [c * 0.01 for c in range(1, 18 + 1)]
for coeff in theta:
for direction in directions:
@ -49,7 +50,7 @@ def createTasks():
if not os.path.exists(saveto):
os.makedirs(saveto)
t = Task(structure, coeff, direction, saveto)
t = Task(structure, coeff, fillet, direction, saveto)
tasks.append(t)
return tasks
@ -58,19 +59,26 @@ def createTasks():
def createMesh(tasks):
scriptpath = os.path.join(ROOT, "samples/__init__.py")
port = 2810
errors = 0
for task in tasks:
logging.info("-" * 80)
logging.info("""createMesh:
task:\t{} / {}""".format(tasks.index(task) + 1, len(tasks)))
start_time = time.monotonic()
returncode = salome_utils.runExecute(port, scriptpath, task.structure, task.coeff, "".join([str(coord) for coord in task.direction]), os.path.join(task.saveto, "mesh.unv"))
returncode = salome_utils.runExecute(port, scriptpath, task.structure, task.coeff, task.fillet, "".join([str(coord) for coord in task.direction]), os.path.join(task.saveto, "mesh.unv"))
logging.info("Return code:\t{}".format(returncode))
#logging.info("-" * 80)
end_time = time.monotonic()
logging.info("createMesh: elapsed time: {}".format(timedelta(seconds=end_time - start_time)))
logging.info("salome: return code:\t{}".format(returncode))
if returncode == 1:
break
#break
errors += 1
pass
return errors
def calculate(tasks):
@ -181,11 +189,12 @@ if __name__ == "__main__":
start_time = time.monotonic()
#logging.info("Started at {}".format(timedelta(seconds=start_time)))
createMesh(tasks)
errors = createMesh(tasks)
end_time = time.monotonic()
logging.info("-" * 80)
logging.info("Elapsed time: {}".format(timedelta(seconds=end_time - start_time)))
logging.info("Elapsed time:\t{}".format(timedelta(seconds=end_time - start_time)))
logging.info("Errors:\t{}".format(errors))
if args.calc:
start_time = time.monotonic()

View File

@ -18,7 +18,7 @@ from bodyCenteredCubic import bodyCenteredCubic
from src import geometry_utils
from src import mesh_utils
def genMesh(stype, theta, flowdirection, saveto):
def genMesh(stype, theta, fillet, flowdirection, saveto):
_G = globals()
structure = _G.get(stype)
@ -26,9 +26,7 @@ def genMesh(stype, theta, flowdirection, saveto):
if structure:
salome.salome_init()
#grains, cubic, rhombohedron = structure(theta)
#fd = namedtuple("fd", ["x", "y", "z"])
grains, geometry1, geometry2 = structure(theta)
grains, geometry1, geometry2 = structure(theta, fillet)
geometry = geometry1
if flowdirection == [1, 1, 1]:
@ -38,35 +36,20 @@ def genMesh(stype, theta, flowdirection, saveto):
# initial angle
angle = math.pi / 6
#vec = Quaternion(0, norm[0], norm[1], norm[2])
#ax = Quaternion(
# math.cos(angle * 0.5),
# math.sin(angle * 0.5) * flowdirection[0],
# math.sin(angle * 0.5) * flowdirection[1],
# math.sin(angle * 0.5) * flowdirection[2])
#qvec = (ax * vec * ax.inverse).vector
#normvec = [qvec[0], qvec[1], qvec[2]]
v1 = Quaternion(axis = norm, angle = math.pi / 2).rotate(flowdirection)
normvec = Quaternion(axis = flowdirection, angle = angle).rotate(v1)
direction = [1, 1, 1]
#direction = fd([1, 1, 1], [1, -1, 1], [1, -1, -1])
#else:
# geometry = cubic
if flowdirection == [1, 0, 0]:
normvec = [0, 0, 1]
bcount = 4
direction = [1, 1, 0]
#direction = fd([1, 1, 0], [1, -1, 0], [0, 0, 1])
if flowdirection == [0, 0, 1]:
normvec = [1, 1, 0]
bcount = 4
direction = [0, 0, 1]
#direction = fd([0, 0, 1], [1, -1, 0], [1, 1, 0])
#boundary = geometry_utils.boundaryCreate(geometry, direction, grains)
boundary = geometry_utils.createBoundary(geometry, bcount, direction, normvec, grains)
fineness = 1
@ -78,22 +61,14 @@ def genMesh(stype, theta, flowdirection, saveto):
mesh = mesh_utils.meshCreate(geometry, boundary, fineness, viscousLayers)
mesh_utils.meshCompute(mesh)
#path = os.path.join(saveto,
# stype,
# "theta-%s" % theta,
# "direction-{}{}{}".format(flowdirection[0], flowdirection[1], flowdirection[2]))
#if not os.path.exists(path):
# logging.info("Creating directory: {}".format(path))
# os.makedirs(path)
mesh_utils.meshExport(mesh, saveto) # os.path.join(path, "mesh.unv"))
mesh_utils.meshExport(mesh, saveto)
salome.salome_close()
else:
raise Exception("Unknown sample function")
if __name__ == "__main__":
logging.basicConfig(
@ -104,29 +79,18 @@ if __name__ == "__main__":
logging.FileHandler("{}/cubic.log".format(LOG))
])
#fancyline = "--------------------------------------------------------------------------------"
#logging.info(fancyline)
stype = str(sys.argv[1])
theta = float(sys.argv[2])
#ignore = "[], "
flowdirection = [int(coord) for coord in sys.argv[3]]
#for sym in str(sys.argv[3]):
# if sym not in list(ignore):
# flowdirection.append(int(sym))
saveto = str(sys.argv[4])
fillet = True if int(sys.argv[3]) == 1 else False
flowdirection = [int(coord) for coord in sys.argv[4]]
saveto = str(sys.argv[5])
logging.info("""genMesh:
structure type:\t{}
coefficient:\t{}
fillet:\t{}
flow direction:\t{}
export path:\t{}""".format(stype, theta, flowdirection, saveto))
export path:\t{}""".format(stype, theta, fillet, flowdirection, saveto))
#print(flowdirection)
genMesh(stype, theta, fillet, flowdirection, saveto)
genMesh(stype, theta, flowdirection, saveto)
#logging.info(fancyline)

View File

@ -10,7 +10,7 @@ import SALOMEDS
geompy = geomBuilder.New()
def bodyCenteredCubic(alpha):
def bodyCenteredCubic(alpha, fillet = False):
O = geompy.MakeVertex(0, 0, 0)
OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
@ -149,39 +149,38 @@ def bodyCenteredCubic(alpha):
grains = geompy.ExtractShapes(Up_Down, geompy.ShapeType["SOLID"], True)
grains += geompy.ExtractShapes(Middle, geompy.ShapeType["SOLID"], True)
grains = geompy.MakeFuseList(grains, False, False)
geometry1 = Pore_1a
geometry2 = Pore_3c
R = r0 / (1 - alpha)
C1 = 0.8
C2 = 0.01
alpha1 = 0.01
alpha2 = 0.18
if fillet:
R = r0 / (1 - alpha)
C1 = 0.8
C2 = 0.01
alpha1 = 0.01
alpha2 = 0.18
Cf = C1 + (C2 - C1) / (alpha2 - alpha1) * (alpha - alpha1)
R_fillet = Cf * (R - r0)
Cf = C1 + (C2 - C1) / (alpha2 - alpha1) * (alpha - alpha1)
R_fillet = Cf * (R - r0)
#grains = geompy.MakeFilletAll(grains, R_fillet)
#geometry1 = geompy.MakeCutList(Pore_1a, [grains], True)
#geometry2 = geompy.MakeCutList(Pore_3c, [grains], True)
# Scaling up
scale = 100
grains = geompy.MakeScaleTransform(grains, O, scale)
geometry1 = geompy.MakeScaleTransform(geometry1, O, scale)
geometry2 = geompy.MakeScaleTransform(geometry2, O, scale)
# Scaling up
scale = 100
grains = geompy.MakeScaleTransform(grains, O, scale)
geometry1 = geompy.MakeScaleTransform(Pore_1a, O, scale)
geometry2 = geompy.MakeScaleTransform(Pore_3c, O, scale)
#
grains = geompy.MakeFilletAll(grains, R_fillet * scale)
geometry1 = geompy.MakeCutList(geometry1, [grains], True)
geometry2 = geompy.MakeCutList(geometry2, [grains], True)
#
grains = geompy.MakeFilletAll(grains, R_fillet * scale)
geometry1 = geompy.MakeCutList(geometry1, [grains], True)
geometry2 = geompy.MakeCutList(geometry2, [grains], True)
# Scaling down
grains = geompy.MakeScaleTransform(grains, O, 1 / scale)
geometry1 = geompy.MakeScaleTransform(geometry1, O, 1 / scale)
geometry2 = geompy.MakeScaleTransform(geometry2, O, 1 / scale)
# Scaling down
grains = geompy.MakeScaleTransform(grains, O, 1 / scale)
geometry1 = geompy.MakeScaleTransform(geometry1, O, 1 / scale)
geometry2 = geompy.MakeScaleTransform(geometry2, O, 1 / scale)
#
geompy.addToStudy(grains, "grains")
geompy.addToStudy(geometry1, "geometry1")
geompy.addToStudy(geometry2, "geometry2")
return grains, Pore_1a, Pore_3c
return grains, geometry1, geometry2

View File

@ -10,7 +10,7 @@ import SALOMEDS
geompy = geomBuilder.New()
def faceCenteredCubic(alpha):
def faceCenteredCubic(alpha, fillet = False):
O = geompy.MakeVertex(0, 0, 0)
OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
@ -144,35 +144,34 @@ def faceCenteredCubic(alpha):
grains = geompy.ExtractShapes(Up_Down, geompy.ShapeType["SOLID"], True)
grains += geompy.ExtractShapes(Middle_Up, geompy.ShapeType["SOLID"], True)
grains = geompy.MakeFuseList(grains, False, False)
geometry1 = Common
geometry2 = Cut_8
R = r0 / (1 - alpha)
C1 = 0.8
C2 = 0.01
alpha1 = 0.01
alpha2 = 0.13
if fillet:
R = r0 / (1 - alpha)
C1 = 0.8
C2 = 0.01
alpha1 = 0.01
alpha2 = 0.13
Cf = C1 + (C2 - C1) / (alpha2 - alpha1) * (alpha - alpha1)
R_fillet = Cf * (R - r0)
print(R_fillet)
#grains = geompy.MakeFilletAll(grains, R_fillet)
#geometry1 = geompy.MakeCutList(Common, [grains], True)
#geometry2 = geompy.MakeCutList(Cut_8, [grains], True)
Cf = C1 + (C2 - C1) / (alpha2 - alpha1) * (alpha - alpha1)
R_fillet = Cf * (R - r0)
# Scaling up
scale = 100
grains = geompy.MakeScaleTransform(grains, O, scale)
geometry1 = geompy.MakeScaleTransform(Common, O, scale)
geometry2 = geompy.MakeScaleTransform(Cut_8, O, scale)
# Scaling up
scale = 100
grains = geompy.MakeScaleTransform(grains, O, scale)
geometry1 = geompy.MakeScaleTransform(geometry1, O, scale)
geometry2 = geompy.MakeScaleTransform(geometry2, O, scale)
#
grains = geompy.MakeFilletAll(grains, R_fillet * scale)
geometry1 = geompy.MakeCutList(geometry1, [grains], True)
geometry2 = geompy.MakeCutList(geometry2, [grains], True)
#
grains = geompy.MakeFilletAll(grains, R_fillet * scale)
geometry1 = geompy.MakeCutList(geometry1, [grains], True)
geometry2 = geompy.MakeCutList(geometry2, [grains], True)
# Scaling down
grains = geompy.MakeScaleTransform(grains, O, 1 / scale)
geometry1 = geompy.MakeScaleTransform(geometry1, O, 1 / scale)
geometry2 = geompy.MakeScaleTransform(geometry2, O, 1 / scale)
# Scaling down
grains = geompy.MakeScaleTransform(grains, O, 1 / scale)
geometry1 = geompy.MakeScaleTransform(geometry1, O, 1 / scale)
geometry2 = geompy.MakeScaleTransform(geometry2, O, 1 / scale)
#
geompy.addToStudy(grains, "grains")

View File

@ -10,7 +10,7 @@ import SALOMEDS
geompy = geomBuilder.New()
def simpleCubic(alpha):
def simpleCubic(alpha, fillet = False):
O = geompy.MakeVertex(0, 0, 0)
OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
@ -113,31 +113,34 @@ def simpleCubic(alpha):
# Preparation
grains = geompy.ExtractShapes(Multi_Translation_3, geompy.ShapeType["SOLID"], True)
grains = geompy.MakeFuseList(grains, False, False)
geometry1 = Cut_1
geometry2 = Cut_4
R = r0 / (1 - alpha)
C1 = 0.8
C2 = 0.4
alpha1 = 0.01
alpha2 = 0.28
if fillet:
R = r0 / (1 - alpha)
C1 = 0.8
C2 = 0.01
alpha1 = 0.01
alpha2 = 0.28
Cf = C1 + (C2 - C1) / (alpha2 - alpha1) * (alpha - alpha1)
R_fillet = Cf * (R - r0)
Cf = C1 + (C2 - C1) / (alpha2 - alpha1) * (alpha - alpha1)
R_fillet = Cf * (R - r0)
# Scaling up
scale = 100
grains = geompy.MakeScaleTransform(grains, O, scale)
geometry1 = geompy.MakeScaleTransform(Cut_1, O, scale)
geometry2 = geompy.MakeScaleTransform(Cut_4, O, scale)
# Scaling up
scale = 100
grains = geompy.MakeScaleTransform(grains, O, scale)
geometry1 = geompy.MakeScaleTransform(geometry1, O, scale)
geometry2 = geompy.MakeScaleTransform(geometry2, O, scale)
#
grains = geompy.MakeFilletAll(grains, R_fillet * scale)
geometry1 = geompy.MakeCutList(geometry1, [grains], True)
geometry2 = geompy.MakeCutList(geometry2, [grains], True)
#
grains = geompy.MakeFilletAll(grains, R_fillet * scale)
geometry1 = geompy.MakeCutList(geometry1, [grains], True)
geometry2 = geompy.MakeCutList(geometry2, [grains], True)
# Scaling down
grains = geompy.MakeScaleTransform(grains, O, 1 / scale)
geometry1 = geompy.MakeScaleTransform(geometry1, O, 1 / scale)
geometry2 = geompy.MakeScaleTransform(geometry2, O, 1 / scale)
# Scaling down
grains = geompy.MakeScaleTransform(grains, O, 1 / scale)
geometry1 = geompy.MakeScaleTransform(geometry1, O, 1 / scale)
geometry2 = geompy.MakeScaleTransform(geometry2, O, 1 / scale)
#
geompy.addToStudy(grains, "grains")