Python API reference#
- class geouned.CsgToCad[source]#
Bases:
object
Base class for the conversion of CSG to CAD models
- export_cad(input_filename, csg_format, output_filename='cad_from_csg', bounding_box=(-1000, -1000, -1000, 1000, 1000, 1000), universe_start=0, level_max='all', cell_range_type='all', cell_range=(), mat_range_type='all', mat_range=())[source]#
export the CSG geometry in OpenMC or MCNP format to a CAD model.
- 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 ‘openmc_xml’ or ‘mcnp’
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 ‘cad_from_csg’.
bounding_box (Tuple[int, int, int, int, int, int], optional) – The bounding box coordinates of the CSG geometry. This should encompass the entire CSG geometry. Format is (xmin, ymin, zmin, xmax, ymax, zmax) Defaults to (-1000, -1000, -1000, 1000, 1000, 1000).
universe_start (int, optional) – The Universe ID to be converted to CAD. If universe_start is left as 0 then all the universes and any nested universes are converted. If set then the universe and all its nested universes are converted. Defaults to 0.
level_max (str, optional) – Level maximum of nested universe to be translated. If level_max < highest nested universe level, cells inside the container cell whose level is level_max will not be translated. This container cell will be the CAD solid written in the CAD file. Defaults to “all”.
cell_range_type (str, optional) – Define how to consider the range values. setting to ‘all’ results in all the cells with any cell ID being converted (range a no effect). setting to ‘include’ results in only cells defined in ‘range’ being converted. setting to ‘exclude’ results in exclude all cells defined in range. Defaults to “all”.
cell_range (Tuple[int], optional) – list of cells to be included/excluded for the conversion. Defaults to ().
mat_range_type (str, optional) – Define how to consider the range values. setting to ‘all’ results in all the materials with any cell ID being converted (range a no effect). setting to ‘include’ results in only materials defined in ‘range’ being converted. setting to ‘exclude’ results in exclude all materials defined in range. Defaults to “all”.
mat_range (Tuple[int], optional) – list of materials to be included/excluded for the conversion. Defaults to ().
- Raises:
ValueError – If the csg_format is not ‘openmc_xml’ or ‘mcnp’ then a ValueError is raised.
- 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=[])[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.
- 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='12f', 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 “12f”.
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(matFile='', voidGen=True, debug=False, compSolids=True, 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:
matFile (str, optional) – _description_. 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 True.
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.