Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Facets From Point Cloud, and Volumes From Facets With Cubit #177

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions parastell/invessel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,82 @@ def export_cad_to_dagmc(self, dagmc_filename="dagmc", export_dir=""):

model.export_dagmc_h5m_file(filename=str(export_path))

def build_volumes_cubit(self):
cubit_io.init_cubit()
for surface_name, surface in self.Surfaces.items():
print(surface_name)
vertex_ids = []
for loop in surface.get_loci():
loop_vert_ids = []
for point in loop:
cubit.cmd(
f"create vertex {point[0]} {point[1]} {point[2]}"
)
vertex_id = cubit.get_last_id("vertex")
loop_vert_ids.append(vertex_id)
vertex_ids.append(loop_vert_ids)
surface_ids = []
vertex_ids = np.array(vertex_ids)
for loop_index, loop in enumerate(vertex_ids[0:-1, :]):
for point_index, point in enumerate(loop[0:-1]):
ul = vertex_ids[loop_index, point_index]
ll = vertex_ids[loop_index + 1, point_index]
ur = vertex_ids[loop_index, point_index + 1]
lr = vertex_ids[loop_index + 1, point_index + 1]
cubit.cmd(f"create surface vertex {ul} {ll} {ur}")
surface_ids.append(cubit.get_last_id("surface"))
cubit.cmd(f"create surface vertex {lr} {ll} {ur}")
surface_ids.append(cubit.get_last_id("surface"))
start_cap_ids = " ".join(
[str(vertex) for vertex in vertex_ids[0][0:-1]]
)
print(start_cap_ids)
end_cap_ids = " ".join(
[str(vertex) for vertex in vertex_ids[-1][0:-1]]
)
surface_id_str = " ".join(
[str(surf_id) for surf_id in surface_ids]
)
surface_ids = []
# for whatever reason, uniting this surface first makes the volume
# creation go much faster (~10x)
cubit.cmd(f"unite surface {surface_id_str}")
surface_ids.append(cubit.get_last_id("surface"))
cubit.cmd(f"create surface vertex {start_cap_ids}")
surface_ids.append(cubit.get_last_id("surface"))
cubit.cmd(f"create surface vertex {end_cap_ids}")
surface_ids.append(cubit.get_last_id("surface"))
surface_id_str = " ".join(
[str(surf_id) for surf_id in surface_ids]
)
cubit.cmd(f"create volume surface {surface_id_str}")
cubit.cmd("compress")
volume_id = cubit.get_last_id("volume")
self.radial_build.radial_build[surface_name]["vol_id"] = volume_id
cubit.cmd('save cub5 "all_surfaces_faceted.cub5" overwrite')
# remove overlap
print("removing overlap")
layers = list(self.radial_build.radial_build.values())
for layer, next_layer in zip(
reversed(layers[0:-1]), reversed(layers[1:])
):
cubit.cmd(
"remove overlap volume "
f"{layer['vol_id']} {next_layer['vol_id']} modify larger"
)
cubit.cmd('save cub5 "overlap_removed.cub5" overwrite')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What overlap is occurring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each volume is made without the through hole, similar to how they are made in CADquery now. This subtracts the inner component from the outer component, working outside in.

# merge layers
for layer, next_layer in zip(
reversed(layers[0:-1]), reversed(layers[1:])
):
print(layer)
cubit.cmd(
f"imprint volume {layer['vol_id']} {next_layer['vol_id']}"
)
cubit.cmd(f"merge volume {layer['vol_id']} {next_layer['vol_id']}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably make this the way we imprint and merge by default in Stellarator.export_dagmc


cubit.cmd('save cub5 "merged.cub5" overwrite')


class Surface(object):
"""An object representing a surface formed by lofting across a set of
Expand Down
Loading