anisotropy/src/geometry_utils.py

144 lines
4.1 KiB
Python
Raw Normal View History

2021-03-18 17:29:30 +05:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import GEOM
2021-03-15 16:16:48 +05:00
from salome.geom import geomBuilder
2021-03-18 17:29:30 +05:00
geompy = geomBuilder.New()
2021-03-15 16:16:48 +05:00
import math
import logging
2021-03-18 17:29:30 +05:00
def getGeom():
return geompy
2021-03-15 16:16:48 +05:00
def rotate(gobj, ang):
2021-03-24 21:27:12 +05:00
x = geompy.MakeVectorDXDYDZ(1, 0, 0)
y = geompy.MakeVectorDXDYDZ(0, 1, 0)
2021-03-15 16:16:48 +05:00
z = geompy.MakeVectorDXDYDZ(0, 0, 1)
# yaw
rotated = geompy.MakeRotation(gobj, z, ang[2])
# pitch
rotated = geompy.MakeRotation(rotated, y, ang[1])
# roll
rotated = geompy.MakeRotation(rotated, x, ang[0])
return rotated
def createGroup(gobj, planelist, grains, name):
gr = geompy.CreateGroup(gobj, geompy.ShapeType["FACE"], name)
grcomp = geompy.MakeCompound(planelist)
2021-03-24 21:27:12 +05:00
#grcut = geompy.MakeCutList(grcomp, [grains], False)
2021-03-15 16:16:48 +05:00
2021-03-24 21:27:12 +05:00
gip = geompy.GetInPlace(gobj, grcomp, True)
2021-03-15 16:16:48 +05:00
faces = geompy.SubShapeAll(gip, geompy.ShapeType["FACE"])
geompy.UnionList(gr, faces)
return gr
def boundaryCreate(gobj, dvec, grains):
xvec = geompy.MakeVector(
geompy.MakeVertex(0, 0, 0),
2021-03-24 21:27:12 +05:00
geompy.MakeVertex(dvec.x[0], dvec.x[1], dvec.x[2]))
#xvec = rotate(xvec, [0, 0, 0.25 * math.pi])
2021-03-15 16:16:48 +05:00
2021-03-24 21:27:12 +05:00
#yvec = rotate(xvec, [0.5 * math.pi, 0, 0])
#zvec = rotate(xvec, [0, 0.5 * math.pi, 0])
yvec = geompy.MakeVector(
geompy.MakeVertex(0, 0, 0),
geompy.MakeVertex(dvec.y[0], dvec.y[1], dvec.y[2]))
zvec = geompy.MakeVector(
geompy.MakeVertex(0, 0, 0),
geompy.MakeVertex(dvec.z[0], dvec.z[1], dvec.z[2]))
geompy.addToStudy(xvec, "xvec")
geompy.addToStudy(yvec, "yvec")
geompy.addToStudy(zvec, "zvec")
2021-03-15 16:16:48 +05:00
logging.info("""boundaryCreate:
direction vectors: x = {}
y = {}
z = {}""".format(dvec.x, dvec.y, dvec.z))
2021-03-15 16:16:48 +05:00
2021-03-24 21:27:12 +05:00
planes = geompy.ExtractShapes(gobj, geompy.ShapeType["FACE"], False)
planes = geompy.MakeCompound(planes)
planes = geompy.MakeCutList(planes, [grains], False)
planes = geompy.ExtractShapes(planes, geompy.ShapeType["FACE"], False)
2021-03-15 16:16:48 +05:00
inletplanes = []
outletplanes = []
2021-03-24 21:27:12 +05:00
#uplanes = []
2021-03-15 16:16:48 +05:00
fwplanes = []
bwplanes = []
lplanes = []
rplanes = []
for plane in planes:
nvec = geompy.GetNormal(plane)
2021-03-24 21:27:12 +05:00
xang = round(geompy.GetAngle(nvec, xvec), 0)
yang = round(geompy.GetAngle(nvec, yvec), 0)
zang = round(geompy.GetAngle(nvec, zvec), 0)
#print(xang, yang, zang, sep="\t")
2021-03-15 16:16:48 +05:00
if xang == 0:
inletplanes.append(plane)
elif xang == 180:
outletplanes.append(plane)
elif yang == 0:
fwplanes.append(plane)
elif yang == 180:
bwplanes.append(plane)
elif zang == 0:
lplanes.append(plane)
elif zang == 180:
rplanes.append(plane)
logging.info("""boundaryCreate:
planes count:\t{}
inlet planes:\t{}
outlet planes:\t{}
forward planes:\t{}
backward planes:\t{}
left planes:\t{}
right planes:\t{}""".format(len(planes), len(inletplanes), len(outletplanes),
len(fwplanes), len(bwplanes), len(lplanes), len(rplanes)))
2021-03-15 16:16:48 +05:00
# Main groups
2021-03-24 21:27:12 +05:00
inlet = createGroup(gobj, inletplanes, grains, "inlet")
outlet = createGroup(gobj, outletplanes, grains, "outlet")
2021-03-15 16:16:48 +05:00
symetryPlaneFW = createGroup(gobj, fwplanes, grains, "symetryPlaneFW")
symetryPlaneBW = createGroup(gobj, bwplanes, grains, "symetryPlaneBW")
symetryPlaneL = createGroup(gobj, lplanes, grains, "symetryPlaneL")
symetryPlaneR = createGroup(gobj, rplanes, grains, "symetryPlaneR")
# wall
allgroup = geompy.CreateGroup(gobj, geompy.ShapeType["FACE"])
faces = geompy.SubShapeAllIDs(gobj, geompy.ShapeType["FACE"])
geompy.UnionIDs(allgroup, faces)
wall = geompy.CutListOfGroups([allgroup],
[inlet, outlet, symetryPlaneFW, symetryPlaneBW, symetryPlaneL, symetryPlaneR], "wall")
boundary = {
"inlet": inlet,
"outlet": outlet,
"symetryPlaneFW": symetryPlaneFW,
"symetryPlaneBW": symetryPlaneBW,
"symetryPlaneL": symetryPlaneL,
"symetryPlaneR": symetryPlaneR,
"wall": wall
}
return boundary