ukaea / paramak

Create parametric 3D fusion reactor CAD models
https://paramak.readthedocs.io/en/main/
37 stars 12 forks source link

Add the ability to convert existing stp files into Shapes #672

Open shimwell opened 3 years ago

shimwell commented 3 years ago

I have found a few cases where stp files provided are difficult to reproduce with the paramak and are already clean enough to be used in the neutronics simulations.

When this is the case it could be useful to import the stp file and combine it with a paramak generated geometry.

I've done this with cadquery code for now but perhaps we could wrap this and add it to the paramak as another method of generating Shapes


def convert_stp_file_to_paramak_part(filename, material_tag, filename_stub, scale_factor=0.1):

    part = importers.importStep(str(filename))

    part = part.val().scale(scale_factor)

    new_part = paramak.Shape()

    new_part.material_tag = material_tag
    new_part.stl_filename = filename_stub+'.stl'
    new_part.stp_filename = filename_stub+'.stp'

    # assumes there is just one solid in the geometry
    new_part.solid = part.Solids()[0]

    # parts can be mirrored and rotated to make the complete geometry
    # part2 = part.mirror(mirrorPlane="ZX", basePointVector=(0, 0, 0))
    # part4 = part2.rotate((0,0,1),(0,0,-1), 20)

    return new_part
shimwell commented 3 years ago

This is now built into the utils which makes things a little simpler

import paramak

solid, wires = paramak.utils.load_stp_file('original_stp_files/FirstWall.stp', scale_factor=0.1)

But I think a nicer option would be a ShapeFromFile class

RemDelaporteMathurin commented 3 years ago

@Shimwell if we'd want to cut a shape with this imported solid would something like this work ? ping @jhdark

import paramak

# import the cad file
solid, wires = paramak.utils.load_stp_file('my_file.stp', scale_factor=0.1)
my_imported_shape = paramak.Shape()
my_imported_shape.solid = solid

# create a blanket and cut it with the imported shape
blanket = paramak.BlanketFP(......)
blanket.cut = my_imported_shape

if so then a ShapeFromFile class could simply inherit from Shape

shimwell commented 3 years ago

I think that will work and if it doesn't then we can add some code to the cut logic. Sometimes we need code to handel solids a little differently (cad query sometimes needs .val or not .val for different types of solids)