Python API reference#
- class geouned.CadToCsg(options=<geouned.GEOUNED.utils.data_classes.Options object>, tolerances=<geouned.GEOUNED.utils.data_classes.Tolerances object>, numeric_format=<geouned.GEOUNED.utils.data_classes.NumericFormat object>, settings=<geouned.GEOUNED.utils.data_classes.Settings object>)[source]#
Bases:
object
Base class for the conversion of CAD to CSG models
- Parameters:
options (geouned.Options, optional) – An instance of a geouned.Options class with the attributes set for the desired conversion. Defaults to a geouned.Options with default attributes values.
tolerances (geouned.Tolerances, optional) – An instance of a geouned.Tolerances class with the attributes set for the desired conversion. Defaults to a geouned.Tolerances with default attributes values.
numeric_format (geouned.NumericFormat, optional) – An instance of a geouned.NumericFormat class with the attributes set for the desired conversion. Defaults to a geouned.NumericFormat with default attributes values.
settings (geouned.Settings, optional) – An instance of a geouned.Settings class with the attributes set for the desired conversion. Defaults to a geouned.Settings with default attributes values.
- export_csg(title='Converted with GEOUNED', geometryName='csg', outFormat=('openmc_xml', 'openmc_py', 'serpent', 'phits', 'mcnp'), volSDEF=False, volCARD=True, UCARD=None, dummyMat=False, cellCommentFile=False, cellSummaryFile=True)[source]#
Writes out a CSG file in the requested Monte Carlo code format.
- Parameters:
title (str, optional) – Title of the model written at the top of the output file. Defaults to “Geouned conversion”.
geometryName (str, optional) – the file stem of the output file(s). Defaults to “converted_with_geouned”.
outFormat (Tuple[str], optional) – Format for the output geometry. Available format are: “mcnp”, “openmc_xml”, “openmc_py”, “phits” and “serpent”. Several output format can be written in the same method call. Defaults to output all codes.
volSDEF (bool, optional) – Write SDEF definition and tally of solid cell for stochastic volume checking. Defaults to False.
volCARD (bool, optional) – Write the CAD calculated volume in the cell definition using the VOL card. Defaults to True.
UCARD (int, optional) – Write universe card in the cell definition with the specified universe number (if value = 0 Universe card is not written). Defaults to None.
dummyMat (bool, optional) – Write dummy material definition card in the MCNP output file for all material labels present in the model. Dummy material definition is “MX 1001 1”. Defaults to False.
cellCommentFile (bool, optional) – Write an additional file with comment associated to each CAD cell in the MCNP output file. Defaults to False.
cellSummaryFile (bool, optional) – Write an additional file with information on the CAD cell translated. Defaults to True.
- classmethod from_json(filename)[source]#
Creates a CadToCsg instance, runs CadToCsg.load_Step_file(), runs CadToCsg.start() and returns the instance. Populating the arguments for the methods that are run by looking for keys with the same name as the method in the JSON file. For example CadToCsg.start() accepts arguments for Options, Tolerance, Settings and NumericFormat and can be populated from matching key names in the JSON. If export_to_csg key is present then this method also runs CadToCsg.export_to_csg() on the instance.
- Parameters:
str (filename) – The filename of the config file.
- Raises:
FileNotFoundError – If the config file is not found
ValueError – If the config JSON file is found to contain an invalid key
- Returns:
returns a geouned CadToCsg class instance.
- Return type:
- load_step_file(filename, skip_solids=[], spline_surfaces='stop')[source]#
Load STEP file(s) and extract solid volumes and enclosure volumes.
- Parameters:
filename (str) – The path to the STEP file or a list of paths to multiple STEP files.
skip_solids (Sequence[int], optional) – A sequence (list or tuple) of indexes of solids to not load for conversion.
spline_surfaces (str) – Behavior of the code if solids with spline surface are considered: ‘stop’ execution, ‘remove’ solid, ‘ignore’ solid is included for translation (may lead to translation errors)
- Returns:
A tuple containing the solid volumes list and enclosure volumes list extracted from the STEP files.
- Return type:
tuple
- class geouned.NumericFormat(P_abc='14.7e', P_d='14.7e', P_xyz='14.7e', S_r='14.7e', S_xyz='14.7e', C_r='12f', C_xyz='12f', K_xyz='13.6e', K_tan2='13.6e', T_r='14.7e', T_xyz='14.7e', GQ_1to6='18.15f', GQ_7to9='18.15f', GQ_10='18.15f')[source]#
Bases:
object
Numerical format options for each of the surface types.
- Parameters:
P_abc (str, optional) – Plane general a,b,c params. Defaults to “14.7e”.
P_d (str, optional) – Plane general d params. Defaults to “14.7e”.
P_xyz (str, optional) – PX/PY/PZ params. Defaults to “14.7e”.
S_r (str, optional) – SO/SX/SY/SZ/S radius. Defaults to “14.7e”.
S_xyz (str, optional) – SO/SX/SY/SZ/S center. Defaults to “14.7e”.
C_r (str, optional) – Cylinder radius. Defaults to “12f”.
C_xyz (str, optional) – Cylinder center. Defaults to “12f”.
K_xyz (str, optional) – Cone apex. Defaults to “13.6e”.
K_tan2 (str, optional) – Cone tan^2 value. Defaults to “13.6e”.
T_r (str, optional) – Torus radii. Defaults to “14.7e”.
T_xyz (str, optional) – Torus center. Defaults to “14.7e”.
GQ_1to6 (str, optional) – GQ 1 to 6 coefficients (order 2 x2,y2,z2,xy,…). Defaults to “18.15f”.
GQ_7to9 (str, optional) – GQ 7 to 9 coefficients (order 1 x,y,z). Defaults to “18.15f”.
GQ_10 (str, optional) – GQ 10 coefficient. Defaults to “18.15f”.
- class geouned.Options(forceCylinder=False, newSplitPlane=True, delLastNumber=False, enlargeBox=2.0, nPlaneReverse=0, splitTolerance=0.0, scaleUp=True, quadricPY=False, Facets=False, prnt3PPlane=False, forceNoOverlap=False)[source]#
Bases:
object
A class for containing conversion options
- Parameters:
forceCylinder (bool, optional) – Use cylinder (instead of cones) as ancillary surface where unclosed torus surfaces are involved in the solid definition. Defaults to False.
newSplitPlane (bool, optional) – New method to consider plane as cutting surface during the decomposition process. Former method split first planes perpendicular to X,Y,Z axis and then the other planes involved in the solid definition. New method group all parallel planes independently whether their normal are along X,Y,Z axes, and start the decomposition process cutting first with the group having the highest number of parallel planes. Defaults to True.
delLastNumber (bool, optional) – Deleting the last word in the comment if it is a number. Defaults to False.
enlargeBox (Real, optional) – Enlarge box boundary when evaluating the constraint table during the simplification of the void cell definition. (unit is millimeter). Defaults to 2.
nPlaneReverse (int, optional) – Threshold value to determine whether cut with parallel planes should be carried out first. Defaults to 0.
splitTolerance (Real, optional) – Fuzzy tolerance value used in the FreeCAD function “BOPTools.SplitAPI.slice”. This function is used during the solid decomposition process. Defaults to 0.
scaleUp (bool, optional) – Scale up Fuzzy tolerance once get below 1e-12. Defaults to True.
quadricPY (bool, optional) – In openMC python script format, the cones or cylinders no aligned with the X,Y, or Z axis can be defined using the openmc.Cone or open.Cylinder methods but can also be defined with their quadric parameter. If “quadricPY” is 11 True then all cones and cylinders will be defined in the openMC python script format under their quadric form. Defaults to False.
Facets (bool, optional) – use alternative conversion module when geometry is defined by cells compound by only triangular plane faces. Defaults to False.
prnt3PPlane (bool, optional) – print 3 point plane definition in output as 3 points coordinates. Defaults to False.
forceNoOverlap (bool, optional) – force no overlaping cell definition. Adjacent cell definition are rested from current cell definition. Defaults to False.
- class geouned.Settings(outPath='.', matFile='', voidGen=True, debug=False, compSolids=False, simplify='no', exportSolids=None, minVoidSize=200.0, maxSurf=50, maxBracket=30, voidMat=[], voidExclude=[], startCell=1, startSurf=1, sort_enclosure=False)[source]#
Bases:
object
Settings for changing the way the CAD to CSG conversion is done
- Parameters:
outPath (str, optional) – Path to folder where output file will be written. If folder doesn’t exist it will be created. Defaults to “.”.
matFile (str, optional) – Name of the file in which the material information is provided. Defaults to “”.
voidGen (bool, optional) – Generate voids of the geometry. Defaults to True.
debug (bool, optional) – Write step files of original and decomposed solids, for each solid in the STEP file. Defaults to False.
compSolids (bool, optional) – Join subsolids of STEP file as a single compound solid. Step files generated with SpaceClaim have not exactly the same level of solids as FreeCAD. It may a happened that solids defined has separated solids are read by FreeCAD as a single compound solid (and will produce only one MCNP cell). In this case compSolids should be set to False. Defaults to False.
simplify (str, optional) – Simplify the cell definition considering relative surfaces position and using Boolean logics. Available options are: “no” no optimization, “void” only void cells are simplified. Algorithm is faster but the simplification is not optimal. “voidfull” : only void cells are simplified with the most optimal algorithm. The time of the conversion can be multiplied by 5 or more. “full” : all the cells (solids and voids) are simplified. Defaults to “No”.
exportSolids (str, optional) – Export CAD solid after reading. The execution is stopped after export, the translation is not carried out. Defaults to “”.
minVoidSize (float, optional) – Minimum size of the edges of the void cell. Units are in mm. Defaults to 200.0.
maxSurf (int, optional) – #TODO
maxBracket (int, optional) – Maximum number of brackets (solid complementary) allowed in void cell definition. Defaults to 30.
voidMat (list, optional) – Assign a material defined by the user instead of void for cells without material definition and the cells generated in the automatic void generation. The format is a 3 valued tuple (mat_label, mat_density, mat_description). Example (100,1e-3,’Air assigned to Void’). Defaults to [].
voidExclude (list, optional) – #TODO see issue 87. Defaults to [].
startCell (int, optional) – Starting cell numbering label. Defaults to 1.
startSurf (int, optional) – Starting surface numbering label. Defaults to 1.
sort_enclosure (bool, optional) – If enclosures are defined in the CAD models, the voids cells of the enclosure will be located in the output file in the same location where the enclosure solid is located in the CAD solid tree.. Defaults to False.
- class geouned.Tolerances(relativeTol=False, relativePrecision=1e-06, value=1e-06, distance=0.0001, angle=0.0001, pln_distance=0.0001, pln_angle=0.0001, cyl_distance=0.0001, cyl_angle=0.0001, sph_distance=0.0001, kne_distance=0.0001, kne_angle=0.0001, tor_distance=0.0001, tor_angle=0.0001, min_area=0.01)[source]#
Bases:
object
A class for containing tolerances values
- Parameters:
relativeTol (bool, optional) – _description_. Defaults to False.
relativePrecision (float, optional) – relative precision. Defaults to 1.0e-6.
value (float, optional) – Tolerance in single value comparison. Defaults to 1.0e-6.
distance (float, optional) – General Distance Tolerance. Defaults to 1.0e-4.
angle (float, optional) – General Angle Tolerance. Defaults to 1.0e-4.
pln_distance (float, optional) – distance between planes equal planes if distance between parallel planes < 1e-4 cm. Defaults to 1.0e-4.
pln_angle (float, optional) – angle between axis. 1e-4 : planes separate each other 0.1mm each 1m. Defaults to 1.0e-4.
cyl_distance (float, optional) – distance between radius/center. Defaults to 1.0e-4.
cyl_angle (float, optional) – angle between axis. Defaults to 1.0e-4.
sph_distance (float, optional) – distance between radius/center. Defaults to 1.0e-4.
kne_distance (float, optional) – distance between apex. Defaults to 1.0e-4.
kne_angle (float, optional) – angle between semiangles/axis. Defaults to 1.0e-4.
tor_distance (float, optional) – distance between Major/Minor radii/center. Defaults to 1.0e-4.
tor_angle (float, optional) – angle between axis. Defaults to 1.0e-4.
min_area (float, optional) – minimum face area to consider in cell definition. Defaults to 1.0e-2.
- class geouned.CsgToCad(settings=<geouned.GEOReverse.Modules.Utils.boundBox.BoxSettings object>)[source]#
Bases:
object
Base class for the conversion of CSG to CAD models
- Parameters:
BoxSettings (geouned.BoxSettings, optional) – Adjust the default parameters for the solid boundbox creation. Defaults to a geouned.BoxSettings with default attributes values.
- build_container(cell_label, depth=-1)[source]#
Build the universe contained in the cell “cell_label”. The level of nested universes to consider is controlled by the parameter “depth”. The universe is located inside the container cell according to the transformation.
- Parameters:
cell_label (int) – Label of the cell containing the universe to convert.
depth (int, optional) – Depth level of the nested to considered. Default to -1 (all nested universes).
- build_universe(U=None, depth=-1)[source]#
Build the universe U. The level of nested universes is to consider is controlled by the parameter “depth”. The universe is build in its own coordinate system.
- Parameters:
U (int, optional) – Value of the universe to convert. Default to None (root universe).
depth (int, optional) – Depth level of the nested to considered. Default to -1 (all nested universes).
- cell_filter(type='all', cells=None)[source]#
Selects the cells to build from the CSG geometry in MCNP or OpenMC format and export to the CAD model.
- Parameters:
type (str, optional) – Filtering type. Allowed values “all”, “include”, “exclude”. Default to all.
cells (None, list, tuple, optional) – List of cells to include or exclude. If type is “all” has no effect. Default to None
- export_cad(output_filename='')[source]#
export the CSG geometry in OpenMC or MCNP format to a CAD model.
- Parameters:
output_filename (str, optional) – The filename stem and path of the output file created. Two files will be created with the ‘.step’ suffix and one with the ‘FCStd’ suffix. Defaults to name of the csg file + stp.
- material_filter(type='all', materials=None)[source]#
Selects the materials of the cells to build from the CSG geometry in MCNP or OpenMC format and export to the CAD model.
- Parameters:
type (str, optional) – Filtering type. Allowed values “all”, “include”, “exclude”. Default to all.
materials (None, list, tuple, optional) – List of cells to include or exclude. If type is “all” has no effect. Default to None
- read_csg_file(input_filename, csg_format)[source]#
Reads the geometry definition from MCNP or OpenMC XML input.
- Parameters:
input_filename (str) – The filename and path of the input CSG text file.
csg_format (str) – The format of the CSG input file, options are ‘mcnp’ or ‘openmc_xml’
- Raises:
ValueError – If the csg_format is not ‘openmc_xml’ or ‘mcnp’ then a ValueError is raised.
- class geouned.BoxSettings(universe_radius=1000000.0, insolid_tolerance=1, box_dimensions=None)[source]#
Bases:
object
Parameters used in the solids boundbox generation. Optimized dimensions can reduce the translation time.
- Parameters:
universe_radius (float, optional) – Maximum radius of the CAD universe. Solids with coordinates x^2+y^2+z*2 > universe_radius^2 will be cut or not represented. Units mm. Defaults to 1.0e6.
insolid_tolerance (float, optional) – Maximum distance from the nearest surface of the solid, for which a point outside the solid is assumed inside the solid. Used only for boundbox generation. Units mm. Defaults to 1.
box_dimensions (None,tuple,list, optional) – dimensions of the universe box in which solids will be converted to CAD. Dimensions are (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax) of the box. If no box dimensions is provided, the universe dimension is given by the universe_radius parameter. Defaul to None.