2021-03-02 16:29:43 +05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import salome, GEOM, SMESH, SALOMEDS
|
|
|
|
from salome.geom import geomBuilder
|
|
|
|
from salome.smesh import smeshBuilder
|
|
|
|
import math
|
|
|
|
import os, sys
|
2021-03-03 16:24:47 +05:00
|
|
|
import logging
|
|
|
|
import time
|
|
|
|
from datetime import timedelta
|
2021-03-16 14:53:34 +05:00
|
|
|
from .gutils import *
|
|
|
|
from .mutils import *
|
2021-03-02 16:29:43 +05:00
|
|
|
|
|
|
|
class simpleCubic:
|
2021-03-15 16:16:48 +05:00
|
|
|
def __init__(self, alpha, fillet, name = None):
|
2021-03-02 16:29:43 +05:00
|
|
|
self.name = name if type(name) != None else "simpleCubic"
|
2021-03-15 16:16:48 +05:00
|
|
|
|
|
|
|
self.scale = None
|
|
|
|
self.angle = None
|
|
|
|
self.pos = None
|
|
|
|
|
2021-03-02 16:29:43 +05:00
|
|
|
self.geometry = None
|
2021-03-05 00:02:47 +05:00
|
|
|
self.geometrybbox = None
|
2021-03-02 16:29:43 +05:00
|
|
|
self.mesh = None
|
|
|
|
self.boundary = None
|
2021-03-05 00:02:47 +05:00
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
self.geometry2 = None
|
|
|
|
self.geometry2bbox = None
|
2021-03-05 00:02:47 +05:00
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
self.grains = None
|
2021-03-06 19:19:43 +05:00
|
|
|
|
2021-03-02 22:22:54 +05:00
|
|
|
salome.salome_init()
|
2021-03-02 16:29:43 +05:00
|
|
|
|
2021-03-03 13:00:28 +05:00
|
|
|
"""
|
|
|
|
Create the simple cubic geometry.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
alpha (float): Sphere intersection parameter which used for cutting spheres from box.
|
|
|
|
|
2021-03-06 19:19:43 +05:00
|
|
|
Radius = R0 / (1 - alpha)
|
|
|
|
Should be from 0.01 to 0.28
|
2021-03-03 13:00:28 +05:00
|
|
|
|
2021-03-09 13:13:31 +05:00
|
|
|
fillet (list): Fillet coefficient.
|
|
|
|
|
|
|
|
[fillet1, fillet2]
|
|
|
|
0 <= fillet <= 1
|
|
|
|
if fillet = [0, 0] then R_fillet = 0
|
|
|
|
|
2021-03-03 13:00:28 +05:00
|
|
|
Returns:
|
|
|
|
Configured geometry.
|
|
|
|
"""
|
|
|
|
|
2021-03-02 16:29:43 +05:00
|
|
|
geompy = geomBuilder.New()
|
|
|
|
|
2021-03-06 19:19:43 +05:00
|
|
|
# Parameters
|
|
|
|
R0 = 1
|
|
|
|
R = R0 / (1 - alpha)
|
|
|
|
|
2021-03-09 13:13:31 +05:00
|
|
|
C1 = fillet[0]
|
|
|
|
C2 = fillet[1]
|
2021-03-06 19:19:43 +05:00
|
|
|
alpha1 = 0.01
|
|
|
|
alpha2 = 0.28
|
|
|
|
|
|
|
|
Cf = C1 + (C2 - C1) / (alpha2 - alpha1) * (alpha - alpha1)
|
|
|
|
R_fillet = Cf * (R0 * math.sqrt(2) - R)
|
|
|
|
|
|
|
|
logging.info("geometryCreate: alpha = {}".format(alpha))
|
|
|
|
logging.info("geometryCreate: R_fillet = {}".format(R_fillet))
|
2021-03-02 16:29:43 +05:00
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
self.scale = [2 * math.sqrt(2), 2 * math.sqrt(2), 2]
|
|
|
|
self.angle = [0, 0, 0.25 * math.pi]
|
|
|
|
self.pos = [2, 0, 0]
|
2021-03-02 16:29:43 +05:00
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
# Box
|
|
|
|
box = geompy.MakeBoxDXDYDZ(scale[0], scale[1], scale[2])
|
|
|
|
box = rotate(box, angle)
|
2021-03-07 16:29:04 +05:00
|
|
|
box = geompy.MakeTranslation(box, pos[0], pos[1], pos[2])
|
2021-03-02 16:29:43 +05:00
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
self.geometrybbox = box
|
|
|
|
|
|
|
|
# Grains
|
2021-03-16 14:53:34 +05:00
|
|
|
stackang = [
|
|
|
|
0.5 * math.pi - stackAng[0],
|
|
|
|
0.5 * math.pi - stackAng[1],
|
|
|
|
0.5 * math.pi - stackAng[2]
|
|
|
|
]
|
2021-03-02 16:29:43 +05:00
|
|
|
|
2021-03-16 14:53:34 +05:00
|
|
|
xvec = geompy.MakeVector(
|
|
|
|
geompy.MakeVertex(0, 0, 0),
|
|
|
|
geompy.MakeVertex(1, 0, 0))
|
|
|
|
yvec = rotate(xvec, [0.5 * math.pi, 0, 0])
|
|
|
|
zvec = rotate(xvec, [0, 0.5 * math.pi, 0])
|
2021-03-02 16:29:43 +05:00
|
|
|
|
2021-03-16 14:53:34 +05:00
|
|
|
hvec = rotate(xvec, [stackang[0], 0, 0])
|
|
|
|
vvec = rotate(zvec, [0, stackang[1], stackang[2]])
|
|
|
|
|
|
|
|
grain = geompy.MakeSpherePntR(geompy.MakeVertex(pos[0], pos[1], pos[2]), R)
|
|
|
|
hstack = geompy.MakeMultiTranslation1D(grain, hvec, 2 * R0, 3)
|
|
|
|
vstack = geompy.MakeMultiTranslation1D(hstack, vvec, 2 * Ro, 3)
|
|
|
|
stack = geompy.MakeTranslation(vstack, -2 * R0, 0, 0)
|
|
|
|
|
|
|
|
self.grains = geompy.ExtractShapes(stack, geompy.ShapeType["SOLID"], True)
|
2021-03-05 00:02:47 +05:00
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
self.grains = geompy.MakeFuseList(self.grains, False, False)
|
2021-03-06 19:19:43 +05:00
|
|
|
|
2021-03-05 23:02:28 +05:00
|
|
|
if not R_fillet == 0:
|
2021-03-15 16:16:48 +05:00
|
|
|
self.grains = geompy.MakeFilletAll(self.grains, R_fillet)
|
2021-03-02 16:29:43 +05:00
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
# Geometry 1
|
|
|
|
self.geometry = geompy.MakeCutList(box, [self.grains], True)
|
2021-03-06 19:19:43 +05:00
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
# Rhombohedron
|
2021-03-05 00:02:47 +05:00
|
|
|
h = 2
|
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
sk = geompy.Sketcher3D()
|
|
|
|
sk.addPointsAbsolute(0, 0, h * 2)
|
|
|
|
sk.addPointsAbsolute(h, 0, h)
|
|
|
|
sk.addPointsAbsolute(h, h, 0)
|
|
|
|
sk.addPointsAbsolute(0, h, h)
|
|
|
|
sk.addPointsAbsolute(0, 0, h * 2)
|
2021-03-02 22:22:54 +05:00
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
rhombus = sk.wire()
|
|
|
|
rhombus = geompy.MakeFaceWires([rombus], 1)
|
|
|
|
vec = geompy.MakeVectorDXDYDZ(1, 1, 0)
|
|
|
|
rhombohedron = geompy.MakePrismVecH(rombus, vec, self.scale[0])
|
2021-03-02 16:29:43 +05:00
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
self.geometry2bbox = rhombohedron
|
2021-03-02 16:29:43 +05:00
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
# Geometry 2
|
|
|
|
self.geometry2 = geompy.MakeCutList(rhombohedron, [self.grains], True)
|
2021-03-02 16:29:43 +05:00
|
|
|
|
2021-03-15 16:16:48 +05:00
|
|
|
# Debug study
|
|
|
|
geompy.addToStudy(self.grains, "grains")
|
|
|
|
geompy.addToStudy(self.geometry, self.name)
|
|
|
|
geompy.addToStudy(self.geometrybbox, "bbox 1")
|
|
|
|
geompy.addToStudy(self.geometry2, "geometry 2")
|
|
|
|
geompy.addToStudy(self.geometry2bbox, "bbox 2")
|
2021-03-02 16:29:43 +05:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-03-03 16:24:47 +05:00
|
|
|
# Arguments
|
2021-03-02 16:29:43 +05:00
|
|
|
buildpath = str(sys.argv[1])
|
|
|
|
alpha = float(sys.argv[2])
|
|
|
|
direction = str(sys.argv[3])
|
2021-03-03 16:24:47 +05:00
|
|
|
|
|
|
|
name = "simpleCubic-{}-{}".format(direction, alpha)
|
|
|
|
|
|
|
|
# Logger
|
2021-03-03 22:16:36 +05:00
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.INFO,
|
|
|
|
format="%(levelname)s: %(message)s",
|
|
|
|
handlers = [
|
|
|
|
logging.StreamHandler(),
|
2021-03-05 00:02:47 +05:00
|
|
|
logging.FileHandler(os.path.join(buildpath, "{}.log".format(name)))
|
2021-03-03 22:16:36 +05:00
|
|
|
])
|
2021-03-03 16:24:47 +05:00
|
|
|
start_time = time.monotonic()
|
|
|
|
|
|
|
|
# Simple cubic
|
|
|
|
logging.info("Creating the geometry ...")
|
2021-03-15 16:16:48 +05:00
|
|
|
sc = simpleCubic(alpha, [0, 0], name)
|
2021-03-03 16:24:47 +05:00
|
|
|
|
|
|
|
logging.info("Extracting boundaries ...")
|
2021-03-15 16:16:48 +05:00
|
|
|
boundary = sc.boundaryCreate(sc.geometry, direction, sc.grains)
|
2021-03-03 16:24:47 +05:00
|
|
|
|
|
|
|
logging.info("Creating the mesh ...")
|
2021-03-15 16:16:48 +05:00
|
|
|
mesh = sc.meshCreate(sc.geometry, boundary, 2) #, {
|
2021-03-06 19:19:43 +05:00
|
|
|
# "thickness": 0.001,
|
|
|
|
# "number": 1,
|
|
|
|
# "stretch": 1.1
|
|
|
|
#})
|
2021-03-15 16:16:48 +05:00
|
|
|
meshCompute(mesh)
|
2021-03-03 16:24:47 +05:00
|
|
|
|
|
|
|
logging.info("Exporting the mesh ...")
|
2021-03-15 16:16:48 +05:00
|
|
|
meshExport(mesh, buildpath)
|
2021-03-03 16:24:47 +05:00
|
|
|
|
|
|
|
end_time = time.monotonic()
|
|
|
|
logging.info("Elapsed time: {}".format(timedelta(seconds=end_time - start_time)))
|
|
|
|
logging.info("Done.")
|
|
|
|
|
2021-03-02 16:29:43 +05:00
|
|
|
if salome.sg.hasDesktop():
|
|
|
|
salome.sg.updateObjBrowser()
|