Run black on utils

This commit is contained in:
Dion Moult
2024-07-26 12:13:29 +10:00
parent a6286293d8
commit e7b791f4a2
78 changed files with 2235 additions and 2098 deletions
-1
View File
@@ -1,4 +1,3 @@
# Ifc2CA - IFC Code_Aster utility
# Copyright (C) 2020, 2021 Ioannis P. Christovasilis <ipc@aethereng.com>
#
+17 -47
View File
@@ -55,9 +55,7 @@ class COMMANDFILE:
conn["relatedElements"] = []
for el in elements:
for rel in el["connections"]:
conn = [
c for c in connections if c["referenceName"] == rel["relatedConnection"]
][0]
conn = [c for c in connections if c["referenceName"] == rel["relatedConnection"]][0]
conn["relatedElements"].append(rel)
# End <--
@@ -65,27 +63,17 @@ class COMMANDFILE:
profiles = data["db"]["profiles"]
edgeGroupNames = tuple(
[
self.getGroupName(el["referenceName"])
for el in elements
if el["geometryType"] == "line"
]
[self.getGroupName(el["referenceName"]) for el in elements if el["geometryType"] == "line"]
)
faceGroupNames = tuple(
[
self.getGroupName(el["referenceName"])
for el in elements
if el["geometryType"] == "surface"
]
[self.getGroupName(el["referenceName"]) for el in elements if el["geometryType"] == "surface"]
)
rigidLinkGroupNames = []
for conn in connections:
rigidLinkGroupNames.extend(
[
self.getGroupName(rel["relatingElement"])
+ "_1DR_"
+ self.getGroupName(conn["referenceName"])
self.getGroupName(rel["relatingElement"]) + "_1DR_" + self.getGroupName(conn["referenceName"])
for rel in conn["relatedElements"]
if rel["eccentricity"]
]
@@ -192,20 +180,16 @@ model = AFFE_MODELE(
else:
if "shearModulus" in material["mechProps"]:
poissonRatio = (
material["mechProps"]["youngModulus"]
/ 2.0
/ material["mechProps"]["shearModulus"]
material["mechProps"]["youngModulus"] / 2.0 / material["mechProps"]["shearModulus"]
) - 1
else:
poissonRatio = 0.0
context = {
"matNameID": "mat" + "_%s" % i,
"youngModulus": float(material["mechProps"]["youngModulus"])
* ScaleFactor ** 2,
"youngModulus": float(material["mechProps"]["youngModulus"]) * ScaleFactor**2,
"poissonRatio": float(poissonRatio),
"massDensity": float(material["commonProps"]["massDensity"])
* ScaleFactor ** 3,
"massDensity": float(material["commonProps"]["massDensity"]) * ScaleFactor**3,
}
f.write(template.format(**context))
@@ -225,9 +209,7 @@ material = AFFE_MATERIAU(
),"""
context = {
"groupNames": tuple(
[self.getGroupName(rel) for rel in material["relatedElements"]]
),
"groupNames": tuple([self.getGroupName(rel) for rel in material["relatedElements"]]),
"matNameID": "mat" + "_%s" % i,
}
@@ -260,10 +242,7 @@ element = AFFE_CARA_ELEM(
)
for profile in profiles:
if (
profile["profileShape"] == "rectangular"
and profile["profileType"] == "AREA"
):
if profile["profileShape"] == "rectangular" and profile["profileType"] == "AREA":
template = """
_F(
GROUP_MA = {groupNames},
@@ -273,9 +252,7 @@ element = AFFE_CARA_ELEM(
),"""
context = {
"groupNames": tuple(
[self.getGroupName(rel) for rel in profile["relatedElements"]]
),
"groupNames": tuple([self.getGroupName(rel) for rel in profile["relatedElements"]]),
"profileDimensions": (
profile["xDim"] / ScaleFactor,
profile["yDim"] / ScaleFactor,
@@ -284,10 +261,7 @@ element = AFFE_CARA_ELEM(
f.write(template.format(**context))
elif (
profile["profileShape"] == "iSymmetrical"
and profile["profileType"] == "AREA"
):
elif profile["profileShape"] == "iSymmetrical" and profile["profileType"] == "AREA":
template = """
_F(
GROUP_MA = {groupNames},
@@ -297,14 +271,12 @@ element = AFFE_CARA_ELEM(
),"""
context = {
"groupNames": tuple(
[self.getGroupName(rel) for rel in profile["relatedElements"]]
),
"groupNames": tuple([self.getGroupName(rel) for rel in profile["relatedElements"]]),
"profileProperties": (
profile["mechProps"]["crossSectionArea"] / ScaleFactor ** 2,
profile["mechProps"]["momentOfInertiaY"] / ScaleFactor ** 4,
profile["mechProps"]["momentOfInertiaZ"] / ScaleFactor ** 4,
profile["mechProps"]["torsionalConstantX"] / ScaleFactor ** 4,
profile["mechProps"]["crossSectionArea"] / ScaleFactor**2,
profile["mechProps"]["momentOfInertiaY"] / ScaleFactor**4,
profile["mechProps"]["momentOfInertiaZ"] / ScaleFactor**4,
profile["mechProps"]["torsionalConstantX"] / ScaleFactor**4,
),
}
@@ -572,9 +544,7 @@ if __name__ == "__main__":
files = fileNames
for fileName in files:
BASE_PATH = Path(
"/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/"
)
BASE_PATH = Path("/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/")
DATAFILENAME = BASE_PATH / fileName / f"{fileName}.json"
ASTERFILENAME = BASE_PATH / fileName / f"{fileName}.comm"
COMMANDFILE(DATAFILENAME, ASTERFILENAME)
+17 -48
View File
@@ -30,6 +30,7 @@ from pathlib import Path
flatten = itertools.chain.from_iterable
class MODEL:
def __init__(self, dataFilename, medFilename, meshSize, zGround):
self.dataFilename = dataFilename
@@ -97,9 +98,7 @@ class MODEL:
shapeType = "EDGE"
if geometryType == "surface":
shapeType = "FACE"
return self.geompy.MakePartition(
objects, [], [], [], self.geompy.ShapeType[shapeType], 0, [], 1
)
return self.geompy.MakePartition(objects, [], [], [], self.geompy.ShapeType[shapeType], 0, [], 1)
def getLinkGeometry(self, ecc, orientation, finalPoint):
vector = np.array(orientation).transpose().dot(ecc["vector"])
@@ -195,29 +194,21 @@ class MODEL:
el["linkObjs"] = [None for _ in el["connections"]]
for j, rel in enumerate(el["connections"]):
conn = [
c for c in connections if c["referenceName"] == rel["relatedConnection"]
][0]
conn = [c for c in connections if c["referenceName"] == rel["relatedConnection"]][0]
if rel["eccentricity"]:
rel["index"] = len(conn["relatedElements"]) + 1
geometry = self.getLinkGeometry(
rel["eccentricity"], el["orientation"], conn["geometry"]
)
geometry = self.getLinkGeometry(rel["eccentricity"], el["orientation"], conn["geometry"])
el["linkObjs"][j] = self.makeObject(geometry, "line")
conn["relatedElements"].append(rel)
# Make assemble of Building Object
bldObjs = []
bldObjs.extend([el["elemObj"] for el in elements])
bldObjs.extend(
flatten([[link for link in el["linkObjs"] if link] for el in elements])
)
bldObjs.extend(flatten([[link for link in el["linkObjs"] if link] for el in elements]))
# bldComp = geompy.MakeCompound(bldObjs)
bldComp = geompy.MakePartition(
bldObjs, [], [], [], self.geompy.ShapeType[buildingShapeType], 0, [], 1
)
bldComp = geompy.MakePartition(bldObjs, [], [], [], self.geompy.ShapeType[buildingShapeType], 0, [], 1)
geompy.addToStudy(bldComp, "bldComp")
elapsed_time = time.time() - init_time
@@ -227,25 +218,19 @@ class MODEL:
# Define and add groups for all curve, surface and rigid members
if len([e for e in elements if e["geometryType"] == "line"]) > 0:
# Make compound of requested group
compoundTemp = geompy.MakeCompound(
[e["elemObj"] for e in elements if e["geometryType"] == "line"]
)
compoundTemp = geompy.MakeCompound([e["elemObj"] for e in elements if e["geometryType"] == "line"])
# Define group object and add to study
curveCompound = geompy.GetInPlace(bldComp, compoundTemp, True)
geompy.addToStudyInFather(bldComp, curveCompound, "CurveMembers")
if len([e for e in elements if e["geometryType"] == "surface"]) > 0:
# Make compound of requested group
compoundTemp = geompy.MakeCompound(
[e["elemObj"] for e in elements if e["geometryType"] == "surface"]
)
compoundTemp = geompy.MakeCompound([e["elemObj"] for e in elements if e["geometryType"] == "surface"])
# Define group object and add to study
surfaceCompound = geompy.GetInPlace(bldComp, compoundTemp, True)
geompy.addToStudyInFather(bldComp, surfaceCompound, "SurfaceMembers")
linkObjs = list(
flatten([[obj for obj in el["linkObjs"] if obj] for el in elements])
)
linkObjs = list(flatten([[obj for obj in el["linkObjs"] if obj] for el in elements]))
if len(linkObjs) > 0:
# Make compound of requested group
compoundTemp = geompy.MakeCompound(linkObjs)
@@ -256,21 +241,15 @@ class MODEL:
for el in elements:
# el['partObj'] = geompy.RestoreGivenSubShapes(bldComp, [el['partObj']], GEOM.FSM_GetInPlace, False, False)[0]
el["elemObj"] = geompy.GetInPlace(bldComp, el["elemObj"], True)
geompy.addToStudyInFather(
bldComp, el["elemObj"], self.getGroupName(el["referenceName"])
)
geompy.addToStudyInFather(bldComp, el["elemObj"], self.getGroupName(el["referenceName"]))
for j, rel in enumerate(el["connections"]):
if rel["eccentricity"]: # point geometry
el["linkObjs"][j] = geompy.GetInPlace(
bldComp, el["linkObjs"][j], True
)
el["linkObjs"][j] = geompy.GetInPlace(bldComp, el["linkObjs"][j], True)
geompy.addToStudyInFather(
bldComp,
el["linkObjs"][j],
self.getGroupName(el["referenceName"])
+ "_1DR_"
+ self.getGroupName(rel["relatedConnection"]),
self.getGroupName(el["referenceName"]) + "_1DR_" + self.getGroupName(rel["relatedConnection"]),
)
elapsed_time = time.time() - init_time
@@ -307,9 +286,7 @@ class MODEL:
NETGEN2D_Pars.SetFuseEdges(254)
isDone = bldMesh.Compute()
coincident_nodes_on_part = bldMesh.FindCoincidentNodesOnPart(
[bldMesh], tolLoc, [], 0
)
coincident_nodes_on_part = bldMesh.FindCoincidentNodesOnPart([bldMesh], tolLoc, [], 0)
if coincident_nodes_on_part:
# bldMesh.MergeNodes(coincident_nodes_on_part, [], 0)
# print(f'{len(coincident_nodes_on_part)} Sets of Coincident Nodes Found and Merged')
@@ -349,25 +326,19 @@ class MODEL:
shapeType = SMESH.EDGE
if el["geometryType"] == "surface":
shapeType = SMESH.FACE
tempgroup = bldMesh.GroupOnGeom(
el["elemObj"], self.getGroupName(el["referenceName"]), shapeType
)
tempgroup = bldMesh.GroupOnGeom(el["elemObj"], self.getGroupName(el["referenceName"]), shapeType)
smesh.SetName(tempgroup, self.getGroupName(el["referenceName"]))
for j, rel in enumerate(el["connections"]):
if rel["eccentricity"]:
tempgroup = bldMesh.GroupOnGeom(
el["linkObjs"][j],
self.getGroupName(el["referenceName"])
+ "_1DR_"
+ self.getGroupName(rel["relatedConnection"]),
self.getGroupName(el["referenceName"]) + "_1DR_" + self.getGroupName(rel["relatedConnection"]),
SMESH.EDGE,
)
smesh.SetName(
tempgroup,
self.getGroupName(el["referenceName"])
+ "_1DR_"
+ self.getGroupName(rel["relatedConnection"]),
self.getGroupName(el["referenceName"]) + "_1DR_" + self.getGroupName(rel["relatedConnection"]),
)
self.mesh = bldMesh
@@ -420,9 +391,7 @@ if __name__ == "__main__":
zGround = 0
for fileName in files:
BASE_PATH = Path(
"/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/"
)
BASE_PATH = Path("/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/")
DATAFILENAME = BASE_PATH / fileName / f"{fileName}.json"
MEDFILENAME = BASE_PATH / fileName / f"{fileName}.med"
model = MODEL(DATAFILENAME, str(MEDFILENAME), meshSize, zGround)
-1
View File
@@ -1,4 +1,3 @@
# Ifc2CA - IFC Code_Aster utility
# Copyright (C) 2020, 2021, 2023, 2024 Ioannis P. Christovasilis <ipc@aethereng.com>
#
+2
View File
@@ -24,10 +24,12 @@ from pathlib import Path
from typing import Dict, List
import ifcopenshell as ios
# import ifcopenshell.geom
import ifcopenshell.util.element
import ifcopenshell.util.placement
import ifcopenshell.util.representation
# import ifcopenshell.util.shape
import numpy as np
from jinja2 import Environment, FileSystemLoader