Skip to content

Commit

Permalink
hacky fix for beam partitioning
Browse files Browse the repository at this point in the history
  • Loading branch information
Krande committed Oct 22, 2024
1 parent 72d53f4 commit dea9776
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
13 changes: 7 additions & 6 deletions examples/scripts/meshing/partitioning_edge_intersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def edges_intersect(use_xact=False):
Config().update_config_globally(
"meshing_open_viewer_breakpoint_names",
[
#"partition_isect_bm_loop",
# "partition_isect_bm_loop",
# "partition_isect_bm_pre",
# "partition_bm_split_cut_1"
],
Expand All @@ -46,19 +46,20 @@ def edges_intersect(use_xact=False):

a = ada.Assembly() / (ada.Part("MyPart") / objects)
p = a.get_part("MyPart")
# a.show()
a.show(
params_override=RenderParams(
gltf_export_to_file="temp/design_model.glb"
)
)

p.fem = p.to_fem_obj(0.1, interactive=False)
a.to_fem("MyIntersectingedge", "usfos", overwrite=True)
a.to_fem("MyIntersectingedge_aba", "abaqus", overwrite=True)
p.fem = p.to_fem_obj(0.3, interactive=False)
p.fem.show(
params_override=RenderParams(
gltf_export_to_file="temp/fea_model.glb",
fea_params=FEARenderParams(solid_beams=True),
)
)

# p.fem.show()
if use_xact:
xact = os.getenv("XACT_EXE")
if xact:
Expand Down
3 changes: 2 additions & 1 deletion src/ada/api/spatial/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ada.comms.fb_model_gen import FileObjectDC, FilePurposeDC, FileTypeDC
from ada.config import logger
from ada.visit.gltf.graph import GraphNode, GraphStore
from ada.visit.renderer_manager import RenderParams

if TYPE_CHECKING:
import trimesh
Expand Down Expand Up @@ -750,7 +751,6 @@ def to_fem_obj(
if interactive is True:
gs.open_gui()


gs.partition_plates()
gs.partition_beams()

Expand Down Expand Up @@ -787,6 +787,7 @@ def to_trimesh_scene(
filter_by_guids=None,
merge_meshes=True,
stream_from_ifc=False,
params: RenderParams = None,
) -> trimesh.Scene:
from ada.occ.tessellating import BatchTessellator
from ada import Assembly
Expand Down
5 changes: 4 additions & 1 deletion src/ada/fem/meshing/partitioning/partition_beams.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ def split_intersecting_beams(gmsh_session: GmshSession, margins=5e-5, out_of_pla
if n == bm.n1 or n == bm.n2:
continue
bm_gmsh_obj = gmsh_session.model_map[bm]
# entities_1 = gmsh_session.model.occ.get_entities(1)
if len(bm_gmsh_obj.entities) != 1:
# This beam has already been split
continue

# entities_1 = gmsh_session.model.occ.get_entities(1)
res, res_map = gmsh_session.model.occ.fragment(bm_gmsh_obj.entities, [(0, split_point)])

bm_gmsh_obj.entities = [x for x in res_map[0] if x[0] == 1]
Expand Down
5 changes: 3 additions & 2 deletions src/ada/occ/tessellating.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ada.visit.gltf.meshes import MeshStore, MeshType
from ada.visit.gltf.optimize import concatenate_stores
from ada.visit.gltf.store import merged_mesh_to_trimesh_scene
from ada.visit.renderer_manager import RenderParams

if TYPE_CHECKING:
import trimesh
Expand Down Expand Up @@ -222,7 +223,7 @@ def meshes_to_trimesh(
merged_mesh_to_trimesh_scene(scene, mesh_store, self.get_mat_by_id(mat_id), mat_id, graph)
return scene

def append_fem_to_trimesh(self, scene: trimesh.Scene, part: Part, graph):
def append_fem_to_trimesh(self, scene: trimesh.Scene, part: Part, graph, params: RenderParams = None):
shell_color = Color.from_str("white")
shell_color_id = self.add_color(shell_color)
line_color = Color.from_str("gray")
Expand All @@ -249,7 +250,7 @@ def append_fem_to_trimesh(self, scene: trimesh.Scene, part: Part, graph):
merged_mesh_to_trimesh_scene(scene, points_store, points_color, points_color_id, graph)

def tessellate_part(
self, part: Part, filter_by_guids=None, render_override=None, merge_meshes=True
self, part: Part, filter_by_guids=None, render_override=None, merge_meshes=True, params: RenderParams = None
) -> trimesh.Scene:

graph = part.get_graph_store()
Expand Down
24 changes: 13 additions & 11 deletions src/ada/visit/renderer_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ada.config import Config
from ada.core.guid import create_guid
from ada.visit.colors import Color
from ada.visit.gltf.graph import GraphNode
from ada.visit.gltf.graph import GraphNode, GraphStore

if TYPE_CHECKING:
from IPython.display import HTML
Expand Down Expand Up @@ -120,7 +120,7 @@ def scene_from_fem_results(self: FEAResult, params: RenderParams):
return scene


def scene_from_fem(fem: FEM, params: RenderParams) -> trimesh.Scene:
def scene_from_fem(fem: FEM, params: RenderParams, graph: GraphStore=None, scene: trimesh.Scene=None) -> trimesh.Scene:
from ada.visit.gltf.store import merged_mesh_to_trimesh_scene

shell_color = Color.from_str("white")
Expand All @@ -132,14 +132,15 @@ def scene_from_fem(fem: FEM, params: RenderParams) -> trimesh.Scene:
solid_bm_color = Color.from_str("light-gray")
solid_bm_color_id = 100003

if fem.parent is not None:
graph = fem.parent.get_graph_store()
parent_node = graph.hash_map.get(fem.parent.guid)
if graph is None:
if fem.parent is not None:
graph = fem.parent.get_graph_store()
parent_node = graph.hash_map.get(fem.parent.guid)
else:
parent_node = GraphNode("root", 0, hash=create_guid())
graph = GraphStore(top_level=parent_node, nodes={0: parent_node})
else:
from ada.visit.gltf.graph import GraphStore

parent_node = GraphNode("root", 0, hash=create_guid())
graph = GraphStore(top_level=parent_node, nodes={0: parent_node})
parent_node = graph.top_level

use_solid_beams = params.fea_params is not None and params.fea_params.solid_beams is True

Expand All @@ -155,7 +156,8 @@ def scene_from_fem(fem: FEM, params: RenderParams) -> trimesh.Scene:
)

base_frame = graph.top_level.name if graph is not None else "root"
scene = trimesh.Scene(base_frame=base_frame)
scene = trimesh.Scene(base_frame=base_frame) if scene is None else scene

if use_solid_beams:
from ada.fem.formats.utils import line_elem_to_beam
from ada.occ.tessellating import BatchTessellator
Expand Down Expand Up @@ -217,7 +219,7 @@ def scene_from_part_or_assembly(part_or_assembly: Part | Assembly, params: Rende
part_or_assembly.ifc_store.sync()

scene = part_or_assembly.to_trimesh_scene(
stream_from_ifc=params.stream_from_ifc_store, merge_meshes=params.merge_meshes
stream_from_ifc=params.stream_from_ifc_store, merge_meshes=params.merge_meshes, params=params
)
return scene

Expand Down
7 changes: 3 additions & 4 deletions tests/core/fem/meshing/test_mesh_intersecting_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ada
from ada.core.utils import Counter
from ada.fem import Elem
from ada.fem.shapes.definitions import LineShapes


Expand All @@ -28,11 +29,9 @@ def test_edges_intersect(tmp_path):
# p.connections.find()

p.fem = p.to_fem_obj(0.1, interactive=False)
p.fem.show()
n = p.fem.nodes.get_by_volume(p=(0.5, 0.5, 0))[0]
assert len(list(filter(lambda x: x.type == LineShapes.LINE, n.refs))) == 4
# a.to_fem("MyIntersectingedge_ufo", "usfos", overwrite=True, scratch_dir=tmp_path)
# a.to_ifc(tmp_path / "IntersectingFEM", include_fem=False)
num_line_elem = len(list(filter(lambda x: isinstance(x, Elem) and x.type == LineShapes.LINE, n.refs)))
assert num_line_elem == 4


def test_crossing_free_beams():
Expand Down

0 comments on commit dea9776

Please sign in to comment.