CAD_to_OpenMC package
Submodules
CAD_to_OpenMC.assembly module
- class CAD_to_OpenMC.assembly.Assembly(stp_files=[], stl_files=[], verbose: int = 1, default_tag='vacuum', implicit_complement=None)
Bases:
objectMain class representing a geometry model to process
This class encapsulates a geometry defined by a set of step-files that are to be converted into a single surface-meshed geometry. N.b. if geometries are not overlapping it may be simple to use a single Assembly-object per step-file and merge them later using the merge_h5m-methiod.
- Parameters:
stp_files – List of filenames of the step-files to be processed. Most often this is a lits with single member
verbose (int) – verbosity level of output. 0: most quiet, 1: some output, 2+: a lot of diagnostic output
default_tag (str) – Material tag to apply to objects where none is found or where no tag-conversion is applicable
implicit_complement (str or None) – Material tag to be applied to the volume _not_ claimed by any object. If set to None, it is ignored.
- stp_files
List of filenames of the step-files to be processed.
- Type:
List
- verbose
verbosity level of output. 0: most quiet, 1: some output, 2+: a lot of diagnostic output
- Type:
- default_tag
Material tag to apply to objects where none is found or where no tag-conversion is applicable
- Type:
string
- delete_intermediate
Should intermediate data-files be deleted after finishing a run? Superceded by “cleanup”
- Type:
- datadir
Data directory where intermediate data is stored. If == “.” (default) a unique directory will be created
- Type:
string
- tags
Dictionary of material tag-conversions to be applied after extracting tags from the step-file(s). Keys are expected to be regexp-patterns to be matched agains the extracted tags (see also set_tag_delim), and values are the atcual tags to be set. E.g. tags = {“steel.*” : “niobium”} will replace all tags starting with “steel” with the tag “niobium”.
- Type:
dictionary
- sequential_tags
List of tages to be applied sequentially to a model. If set, this applies the tags in the list in the sequence they are encountered in the step-file, until either one is exhausted. If the seq. tag list is exhausted, remaining objects will retain the tag extracted from the step-file or get the default depending on whether noextract_tags is set.
- Type:
- implicit_complement
Material tag to be applied to the volume _not_ claimed by any object.
- Type:
string
- tag_delim_pattern
Regex-pattern which determines what the constitutes the first section of a part name. The first bit is the extracted material tag. E.g. with default setting, the names “steel pipe” and “steel_pipe” both become the tag “steel”.
- Type:
string
- add_stl_to_moab_core(mbcore: Core, surface_id: int, volume_id: int, material_name: str, mbtags: dict, stl_filename: str, last: bool = False) Core
Appends a set of surfaces (comprising a volume) from an stl-file to a moab.Core object and returns the updated object
- Parameters:
mbcore – A moab core object
surface_id – the id number to apply to the surface
volume_id – the id numbers to apply to the volumes
material_name – the material tag name to add. the value provided will be prepended with “mat:” unless it is “reflective” which is a special case and therefore will remain as is.
mbtags – A dictionary of the MOAB tags
stl_filename – the filename of the stl file to load into the moab core
- Returns:
An updated pymoab.core.Core() instance
- apply_transforms(part, filename, scale_factor, translate, rotate)
- dummy_h5m()
- get_all_tags()
- get_unique_tags()
- heal_stls(stls)
- import_stp_files(tags: dict | None = None, sequential_tags: iter | None = None, match_anywhere: bool = False, default_tag: str = 'vacuum', scale: float = 0.1, translate: iter = [], rotate: iter = [], vol_skip: iter = [], **kwargs: dict)
Import a list of step-files and extract material tags.
- Parameters:
tags (dictionary) – Contains pairs of reg.exp. patterns and material tags. If not None, entities with names matching the patterns will be assigned to corresponding tag. If no patterns match the default_tag will be applied
match_anywhere (bool) – Match patterns anywhere in the entitiy name
default_tag (string) – The material tag that will be applied if no patterns are matched.
scale (float) – Overall scaling factor applied to all parts
translate (List) – 3D translation vector to apply to all parts in the step-file.
rotate (list) – Rotation angles to apply to the parts in the step-file.
vol_skip (list) – Numbers of volumes to skip meshing for.
- imprint_all()
- imprint_solid_on_self(s0)
- imprint_solid_on_solid(solid0, solid1)
- imprint_solids(solids)
- init_moab()
Creates a MOAB Core instance which can be built up by adding sets of triangles to the instance Returns: (pymoab Core): A pymoab.core.Core() instance (pymoab tag_handle): A pymoab.core.tag_get_handle() instance
- load_stp_file(filename: str, scale_factor: float = 0.1, translate: list = [], rotate: list = [])
Loads a stp file and makes the 3D solid and wires available for use.
- Parameters:
filename – the filename of the file containing the step-definition.
scale_factor – a scaling factor to apply to the geometry that can be used to increase the size or decrease the size of the geometry. Useful when converting the geometry to cm for use in neutronics simulations. The default (0.1) corresponds to the standard setting of OpenCASCADE which assumes mm to the the standard of OpenMC which is cm.
translate – optional, iterable of 3 float iterable. Translation vector to apply to parts in the model before meshing occurs. If list of list then each translation in the list is applied to 1 part in sequence.
- Returns:
[CadQuery.solid]
- merge_all()
- overlap_bounding_boxes(solid1, solid2)
- print_summary()
- run(backend: str = 'stl', h5m_filename: str = 'dagmc.h5m', merge: bool = True, imprint: bool = False, **kwargs: dict)
Convenience function to easily run the processing sequence
This method merges the calls to import_stp_files, imprint, merge, and solids_to_h5m into a single call
- Parameters:
backend (string) – Mesh creatinon backend to use. Allowed values are ‘stl’, ‘stl2’, ‘gmsh, and ‘db’. The currently recommended choices ae “stl2” and “db”.
h5m_filename (string) – Filename of the created output data-file which will contains the meshed geometry
merge (bool) – Perform a merge step during geometry processing
imprint (bool) – Perform imprinting step during geometry processing
- solids_to_h5m(brep_filename: str | None = None, h5m_filename: str = 'dagmc.h5m', samples: int = 100, backend: str = 'gmsh', heal: bool = True, **kwargs: dict)
Convert the imported list of solids into surface-meshed bounded objects
Main processing function that processes the list of already imported entities. It creates a mesher backend object as appropriate and calls that to create a surface mesh.
- Parameters:
h5m_filename (string) – Name of the output file
backend (string) – Name of the meshing backend to call. Allowed values are in [“gmsh”, “stl”, “stl2”, “db”]
heal (bool) – Use trimesh (if available) to perform a healing step on the surface normals”
- class CAD_to_OpenMC.assembly.Entity(solid=None, idx=0, tag='vacuum')
Bases:
objectContainer class for Parts / Volumes
This class is a container to allow iterating through the geometry model, storing links to data as we go along. Each Entity is a glue-object that connects a step part with a h5m-volume, including positioning, material tags, and links to surface mesh.
- Parameters:
solid (cadquery:Solid) – The cadquery Solid object corresponding to the step-part
idx (int) – The index number of the part/solid.
tag (string) – Material tag of the part/solid
- export_stp()
Not yet implemented
- similar(center: tuple = (0, 0, 0), bb: tuple = (0, 0, 0), volume: float = 1, tolerance=0.01) bool
Quantifies similarity between an Entity and a set of parameters
Method compares an entity and the 3 parameters cms, bb, and volume - presumable cvoming from another Entity, and reports whether it is similar.
- Parameters:
center – The center coordinate to compare with
bb – Bounding box to compare with
volume – Volume to compare with
tolerance – Threshold for when an object is considered similar.
- Returns:
Is this Entity similar to the another with the given parameters?
- Return type:
- similarity(center: tuple = (0, 0, 0), bb: tuple = (0, 0, 0), volume: float = 1, tolerance=0.01) float
Quantifies similarity between an Entity and a set of parameters
Method returns a value for the similarity between the entity and the 3 parameters cms, bb, and volume - presumable cvoming from another Entity
- Parameters:
center – The center coordinate to compare with
bb – Bounding box to compare with
volume – Volume to compare with
tolerance – Unused - will be removed
- Returns:
How similar to the another with the given parameters?
- Return type:
- CAD_to_OpenMC.assembly.hdf5_in_moab(cls)
function to perform a check on whether the written h5m-name file is actually hdf5
- Usage:
a=CAD_to_OpenMC.assembly.hdf5_in_moab()
- CAD_to_OpenMC.assembly.idx_similar(entity_list, center, bounding_box, volume)
Which objects (if any) are similar to the object specified by the set of parameters
- Parameters:
entity_list (List) – List of entities to check agains the given parameters
center – The center coordinate to compare with
bb – Bounding box to compare with
volume – Volume to compare with
- Returns:
The index in the entity_list for which a solid is similar in terms of bounding box, cms, and volume If no similar object is found return -1.
- Return type:
- CAD_to_OpenMC.assembly.merge2h5m(assemblies=[], h5m_file: str = 'dagmc.h5m', vtk: bool = True, verbose: int = 1)
Function that (re)performs the assembly of an h5m_file from a set of already triangularized assemblies.
- Usage:
a=Assembly([‘stepfileA.step’]) a.run( … ) b=Assembly([‘stepfileB.step’]) b.run( … ) merge2h5m([a,b],h5m_file=’c.h5m’)
paramters
- assemblies: list
Iterable of Assemblies.
- h5m_file: string
Filename of merged file.
- vtk: bool
If True, also write a vtk-file of the structure.
- verbose: int
If == 0 do not write status messages to console.
- CAD_to_OpenMC.assembly.similar_solids(solid1_vol, solid1_bb, solid1_c, solid2_vol, solid2_bb, solid2_c)
This function compares two solids and reports their similarity constant. defined as the sum of: 1. cubic root difference in volume 2. difference of bounding box diagonal 3. difference in location vector.
CAD_to_OpenMC.assemblymesher module
- class CAD_to_OpenMC.assemblymesher.MesherFactory
Bases:
ObjectFactory- get(mesher_id, **kwargs)
CAD_to_OpenMC.assemblymesher_base module
CAD_to_OpenMC.assemblymesher_cq module
- class CAD_to_OpenMC.assemblymesher_cq.MesherCQSTL(tolerance, angular_tolerance, min_mesh_size, max_mesh_size, default, refine, threads, entities)
Bases:
assemblymesher- cq_mesher_ang_tolereance = None
- cq_mesher_entities = None
- cq_mesher_faceHash = {}
- cq_mesher_max_mesh_size = None
- cq_mesher_min_mesh_size = None
- cq_mesher_tolerance = None
- generate_stls()
- property refine
CAD_to_OpenMC.assemblymesher_cq2 module
- class CAD_to_OpenMC.assemblymesher_cq2.MesherCQSTL2(tolerance, angular_tolerance, min_mesh_size, max_mesh_size, default, refine, threads, entities)
Bases:
assemblymesher- cq_mesher_ang_tolereance = None
- cq_mesher_entities = None
- cq_mesher_faceHash = {}
- cq_mesher_max_mesh_size = None
- cq_mesher_min_mesh_size = None
- cq_mesher_tolerance = None
- generate_stls()
- property refine
- classmethod surface_hash(surface)
- wr = <OCP.StlAPI.StlAPI_Writer object>
CAD_to_OpenMC.assemblymesher_db module
- class CAD_to_OpenMC.assemblymesher_db.MesherDB(tolerance, angular_tolerance, min_mesh_size, max_mesh_size, default, refine, threads, entities)
Bases:
assemblymesher- db_mesher_faceHash = {}
- db_mesher_params = None
- generate_stls()
- property refine
- classmethod surface_hash(surface)
- wr = <OCP.StlAPI.StlAPI_Writer object>
CAD_to_OpenMC.assemblymesher_gmsh module
- class CAD_to_OpenMC.assemblymesher_gmsh.MesherGMSH(min_mesh_size, max_mesh_size, curve_samples, default, mesh_algorithm, vetoed, threads, radial_threshold, refine, entities)
Bases:
assemblymesher- generate_stls()
export all the optionally merged volumes as stl-files and returns the list of files. This list may subsequently be iterated upon to merge into a h5m-file. Expects that the geometry has been surface-mesh by gmsh so we have a list of volumes to operate on. We do this be greating gmsh physical groups and export 1 group at a time.
- gmsh_mesher_entities = None
- property refine
CAD_to_OpenMC.check_step module
- CAD_to_OpenMC.check_step.assemble_cmd(line, file)
- CAD_to_OpenMC.check_step.has_degenerate_toroids(infile='geometry.step', only_known_fail=False)
- CAD_to_OpenMC.check_step.parse_command(command)
CAD_to_OpenMC.cq_serialize module
MIT License
Copyright (c) 2022 Simon Dibbern
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- CAD_to_OpenMC.cq_serialize.register()
Registers pickle support functions for common CadQuery and OCCT objects.
CAD_to_OpenMC.datadirectory module
- CAD_to_OpenMC.datadirectory.mesher_datadir(path, delete_intermediate=True, movein=False)
Changes working directory and returns to previous on exit.
CAD_to_OpenMC.meshutils module
Set of utility functions that handle IO with the .mesh format
- CAD_to_OpenMC.meshutils.find_edges(triangles)
algorithm to find the edge lines in a set of triangles. I.e. the lines which are only present in a single triangle
- CAD_to_OpenMC.meshutils.write_dotmesh(dest, vertices, triangles, vertex_labels=None, triangle_labels=None, edges=None, required_edges='all')
vertices and triangles can be lists of lists or 2d arrays
CAD_to_OpenMC.object_factory module
CAD_to_OpenMC.stl_utils module
a set of utility functions that deal with stl-files
- CAD_to_OpenMC.stl_utils.buffer2triangles(buffer, vertices=None)
- CAD_to_OpenMC.stl_utils.buffer2vertices(buffer)
take a raw buffer as returned by the functions above and extract only the vertices from it
- CAD_to_OpenMC.stl_utils.find_vertex(v, vertices)
- CAD_to_OpenMC.stl_utils.merge_stl(dest, src, of='binary')
function that takes either a string or a list of strings as input and outputs a single binary stl that contains all the facets from the input files and assembles them in the output file “dest”
- CAD_to_OpenMC.stl_utils.read_stl(src)
- CAD_to_OpenMC.stl_utils.read_stl_ascii(infp)
- CAD_to_OpenMC.stl_utils.read_stl_bin(infp)
- CAD_to_OpenMC.stl_utils.write_stl(fname, buffer, of='bin', header=b'', name='')
- CAD_to_OpenMC.stl_utils.write_stl_ascii(fname, faces, objectname='')
- CAD_to_OpenMC.stl_utils.write_stl_bin(fname, faces, header=b'', color=None)