cad-to-dagmc 0.6.2__py3-none-any.whl → 0.7.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- _version.py +2 -2
- cad_to_dagmc/core.py +217 -76
- {cad_to_dagmc-0.6.2.dist-info → cad_to_dagmc-0.7.1.dist-info}/METADATA +37 -44
- cad_to_dagmc-0.7.1.dist-info/RECORD +8 -0
- {cad_to_dagmc-0.6.2.dist-info → cad_to_dagmc-0.7.1.dist-info}/WHEEL +1 -1
- cad_to_dagmc-0.6.2.dist-info/RECORD +0 -8
- {cad_to_dagmc-0.6.2.dist-info → cad_to_dagmc-0.7.1.dist-info}/LICENSE +0 -0
- {cad_to_dagmc-0.6.2.dist-info → cad_to_dagmc-0.7.1.dist-info}/top_level.txt +0 -0
_version.py
CHANGED
cad_to_dagmc/core.py
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import typing
|
|
2
|
-
|
|
3
1
|
import cadquery as cq
|
|
4
2
|
import gmsh
|
|
5
3
|
import numpy as np
|
|
6
|
-
from cadquery import importers
|
|
4
|
+
from cadquery import importers, exporters
|
|
7
5
|
from pymoab import core, types
|
|
6
|
+
import tempfile
|
|
8
7
|
|
|
9
8
|
|
|
10
|
-
def _define_moab_core_and_tags() ->
|
|
9
|
+
def _define_moab_core_and_tags() -> tuple[core.Core, dict]:
|
|
11
10
|
"""Creates a MOAB Core instance which can be built up by adding sets of
|
|
12
11
|
triangles to the instance
|
|
13
12
|
|
|
@@ -62,14 +61,11 @@ def _define_moab_core_and_tags() -> typing.Tuple[core.Core, dict]:
|
|
|
62
61
|
|
|
63
62
|
|
|
64
63
|
def _vertices_to_h5m(
|
|
65
|
-
vertices:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
material_tags: typing.Iterable[str],
|
|
71
|
-
h5m_filename="dagmc.h5m",
|
|
72
|
-
implicit_complement_material_tag=None,
|
|
64
|
+
vertices: list[tuple[float, float, float]] | list["cadquery.occ_impl.geom.Vector"],
|
|
65
|
+
triangles_by_solid_by_face: list[list[tuple[int, int, int]]],
|
|
66
|
+
material_tags: list[str],
|
|
67
|
+
h5m_filename: str = "dagmc.h5m",
|
|
68
|
+
implicit_complement_material_tag: str | None = None,
|
|
73
69
|
):
|
|
74
70
|
"""Converts vertices and triangle sets into a tagged h5m file compatible
|
|
75
71
|
with DAGMC enabled neutronics simulations
|
|
@@ -189,11 +185,34 @@ def _vertices_to_h5m(
|
|
|
189
185
|
|
|
190
186
|
moab_core.write_file(h5m_filename)
|
|
191
187
|
|
|
188
|
+
print(f"written DAGMC file {h5m_filename}")
|
|
189
|
+
|
|
192
190
|
return h5m_filename
|
|
193
191
|
|
|
194
192
|
|
|
193
|
+
def get_volumes(gmsh, assembly, method="file"):
|
|
194
|
+
|
|
195
|
+
if method == "in memory":
|
|
196
|
+
volumes = gmsh.model.occ.importShapesNativePointer(assembly.wrapped._address())
|
|
197
|
+
gmsh.model.occ.synchronize()
|
|
198
|
+
elif method == "file":
|
|
199
|
+
with tempfile.NamedTemporaryFile(suffix=".step") as temp_file:
|
|
200
|
+
exporters.export(assembly, temp_file.name)
|
|
201
|
+
volumes = gmsh.model.occ.importShapes(temp_file.name)
|
|
202
|
+
gmsh.model.occ.synchronize()
|
|
203
|
+
|
|
204
|
+
return gmsh, volumes
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def init_gmsh():
|
|
208
|
+
gmsh.initialize()
|
|
209
|
+
gmsh.option.setNumber("General.Terminal", 1)
|
|
210
|
+
gmsh.model.add("made_with_cad_to_dagmc_package")
|
|
211
|
+
return gmsh
|
|
212
|
+
|
|
213
|
+
|
|
195
214
|
def _mesh_brep(
|
|
196
|
-
|
|
215
|
+
gmsh,
|
|
197
216
|
min_mesh_size: float = 1,
|
|
198
217
|
max_mesh_size: float = 10,
|
|
199
218
|
mesh_algorithm: int = 1,
|
|
@@ -203,7 +222,7 @@ def _mesh_brep(
|
|
|
203
222
|
Gmsh.
|
|
204
223
|
|
|
205
224
|
Args:
|
|
206
|
-
|
|
225
|
+
occ_shape: the occ_shape of the Brep file to convert
|
|
207
226
|
min_mesh_size: the minimum mesh element size to use in Gmsh. Passed
|
|
208
227
|
into gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size)
|
|
209
228
|
max_mesh_size: the maximum mesh element size to use in Gmsh. Passed
|
|
@@ -217,30 +236,21 @@ def _mesh_brep(
|
|
|
217
236
|
The resulting gmsh object and volumes
|
|
218
237
|
"""
|
|
219
238
|
|
|
220
|
-
gmsh.initialize()
|
|
221
|
-
gmsh.option.setNumber("General.Terminal", 1)
|
|
222
|
-
gmsh.model.add("made_with_cad_to_dagmc_package")
|
|
223
|
-
volumes = gmsh.model.occ.importShapesNativePointer(brep_object)
|
|
224
|
-
gmsh.model.occ.synchronize()
|
|
225
|
-
|
|
226
239
|
gmsh.option.setNumber("Mesh.Algorithm", mesh_algorithm)
|
|
227
240
|
gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size)
|
|
228
241
|
gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size)
|
|
229
242
|
gmsh.model.mesh.generate(dimensions)
|
|
230
243
|
|
|
231
|
-
return gmsh
|
|
244
|
+
return gmsh
|
|
232
245
|
|
|
233
246
|
|
|
234
|
-
def
|
|
235
|
-
|
|
236
|
-
)
|
|
237
|
-
"""Converts gmsh volumes into
|
|
247
|
+
def mesh_to_vertices_and_triangles(
|
|
248
|
+
dims_and_vol_ids,
|
|
249
|
+
):
|
|
250
|
+
"""Converts gmsh volumes into vertices and triangles for each face.
|
|
238
251
|
|
|
239
252
|
Args:
|
|
240
253
|
volumes: the volumes in the gmsh file, found with gmsh.model.occ.importShapes
|
|
241
|
-
material_tags: A list of material tags to tag the DAGMC volumes with.
|
|
242
|
-
Should be in the same order as the volumes
|
|
243
|
-
h5m_filename: the filename of the DAGMC h5m file to write
|
|
244
254
|
|
|
245
255
|
Returns:
|
|
246
256
|
vertices and triangles (grouped by solid then by face)
|
|
@@ -248,7 +258,7 @@ def _mesh_to_h5m_in_memory_method(
|
|
|
248
258
|
|
|
249
259
|
n = 3 # number of verts in a triangles
|
|
250
260
|
triangles_by_solid_by_face = {}
|
|
251
|
-
for dim_and_vol in
|
|
261
|
+
for dim_and_vol in dims_and_vol_ids:
|
|
252
262
|
# removes all groups so that the following getEntitiesForPhysicalGroup
|
|
253
263
|
# command only finds surfaces for the volume
|
|
254
264
|
gmsh.model.removePhysicalGroups()
|
|
@@ -302,6 +312,22 @@ def _get_ids_from_imprinted_assembly(solid_id_dict):
|
|
|
302
312
|
return ids
|
|
303
313
|
|
|
304
314
|
|
|
315
|
+
def _check_material_tags(material_tags, iterable_solids):
|
|
316
|
+
if material_tags:
|
|
317
|
+
if len(material_tags) != len(iterable_solids):
|
|
318
|
+
msg = (
|
|
319
|
+
"When setting material_tags the number of material_tags \n"
|
|
320
|
+
"should be equal to the number of volumes in the CAD \n"
|
|
321
|
+
f"geometry {len(iterable_solids)} volumes found in model \n"
|
|
322
|
+
f"and {len(material_tags)} material_tags found"
|
|
323
|
+
)
|
|
324
|
+
raise ValueError(msg)
|
|
325
|
+
for material_tag in material_tags:
|
|
326
|
+
if not isinstance(material_tag, str):
|
|
327
|
+
msg = f"material_tags should be an iterable of strings."
|
|
328
|
+
raise ValueError(msg)
|
|
329
|
+
|
|
330
|
+
|
|
305
331
|
def order_material_ids_by_brep_order(original_ids, scrambled_id, material_tags):
|
|
306
332
|
material_tags_in_brep_order = []
|
|
307
333
|
for brep_id in scrambled_id:
|
|
@@ -310,27 +336,94 @@ def order_material_ids_by_brep_order(original_ids, scrambled_id, material_tags):
|
|
|
310
336
|
return material_tags_in_brep_order
|
|
311
337
|
|
|
312
338
|
|
|
339
|
+
class MeshToDagmc:
|
|
340
|
+
"""Convert a GMSH mesh file to a DAGMC h5m file"""
|
|
341
|
+
|
|
342
|
+
def __init__(self, filename: str):
|
|
343
|
+
self.filename = filename
|
|
344
|
+
|
|
345
|
+
# TODO add export_unstructured_mesh_file
|
|
346
|
+
# TODO add add_gmsh_msh_file
|
|
347
|
+
|
|
348
|
+
def export_dagmc_h5m_file(
|
|
349
|
+
self,
|
|
350
|
+
material_tags: list[str],
|
|
351
|
+
implicit_complement_material_tag: str | None = None,
|
|
352
|
+
filename: str = "dagmc.h5m",
|
|
353
|
+
):
|
|
354
|
+
"""Saves a DAGMC h5m file of the geometry
|
|
355
|
+
|
|
356
|
+
Args:
|
|
357
|
+
material_tags (list[str]): the names of the DAGMC
|
|
358
|
+
material tags to assign. These will need to be in the same
|
|
359
|
+
order as the volumes in the GMESH mesh and match the
|
|
360
|
+
material tags used in the neutronics code (e.g. OpenMC).
|
|
361
|
+
implicit_complement_material_tag (str | None, optional):
|
|
362
|
+
the name of the material tag to use for the implicit
|
|
363
|
+
complement (void space). Defaults to None which is a vacuum.
|
|
364
|
+
filename (str, optional): _description_. Defaults to "dagmc.h5m".
|
|
365
|
+
|
|
366
|
+
Raises:
|
|
367
|
+
ValueError: _description_
|
|
368
|
+
|
|
369
|
+
Returns:
|
|
370
|
+
_type_: _description_
|
|
371
|
+
"""
|
|
372
|
+
|
|
373
|
+
gmsh.initialize()
|
|
374
|
+
self.mesh_file = gmsh.open(self.filename)
|
|
375
|
+
dims_and_vol_ids = gmsh.model.getEntities(3)
|
|
376
|
+
|
|
377
|
+
if len(dims_and_vol_ids) != len(material_tags):
|
|
378
|
+
msg = f"Number of volumes {len(dims_and_vol_ids)} is not equal to number of material tags {len(material_tags)}"
|
|
379
|
+
raise ValueError(msg)
|
|
380
|
+
|
|
381
|
+
vertices, triangles_by_solid_by_face = mesh_to_vertices_and_triangles(
|
|
382
|
+
dims_and_vol_ids=dims_and_vol_ids
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
gmsh.finalize()
|
|
386
|
+
|
|
387
|
+
h5m_filename = _vertices_to_h5m(
|
|
388
|
+
vertices=vertices,
|
|
389
|
+
triangles_by_solid_by_face=triangles_by_solid_by_face,
|
|
390
|
+
material_tags=material_tags,
|
|
391
|
+
h5m_filename=filename,
|
|
392
|
+
implicit_complement_material_tag=implicit_complement_material_tag,
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
return h5m_filename
|
|
396
|
+
|
|
397
|
+
|
|
313
398
|
class CadToDagmc:
|
|
399
|
+
"""Converts Step files and CadQuery parts to a DAGMC h5m file"""
|
|
400
|
+
|
|
314
401
|
def __init__(self):
|
|
315
402
|
self.parts = []
|
|
403
|
+
self.material_tags = []
|
|
316
404
|
|
|
317
405
|
def add_stp_file(
|
|
318
406
|
self,
|
|
319
407
|
filename: str,
|
|
320
408
|
scale_factor: float = 1.0,
|
|
321
|
-
|
|
409
|
+
material_tags: list[str] | None = None,
|
|
410
|
+
) -> int:
|
|
322
411
|
"""Loads the parts from stp file into the model.
|
|
323
412
|
|
|
324
413
|
Args:
|
|
325
414
|
filename: the filename used to save the html graph.
|
|
326
|
-
material_tags: the names of the DAGMC
|
|
327
|
-
These will need to be in the
|
|
328
|
-
|
|
329
|
-
|
|
415
|
+
material_tags (list[str]): the names of the DAGMC
|
|
416
|
+
material tags to assign. These will need to be in the
|
|
417
|
+
same order as the volumes in the geometry added (STP
|
|
418
|
+
file and CadQuery objects) and match the material tags
|
|
419
|
+
used in the neutronics code (e.g. OpenMC).
|
|
330
420
|
scale_factor: a scaling factor to apply to the geometry that can be
|
|
331
421
|
used to increase the size or decrease the size of the geometry.
|
|
332
422
|
Useful when converting the geometry to cm for use in neutronics
|
|
333
423
|
simulations.
|
|
424
|
+
|
|
425
|
+
Returns:
|
|
426
|
+
int: number of volumes in the stp file.
|
|
334
427
|
"""
|
|
335
428
|
part = importers.importStep(str(filename)).val()
|
|
336
429
|
|
|
@@ -338,35 +431,52 @@ class CadToDagmc:
|
|
|
338
431
|
scaled_part = part
|
|
339
432
|
else:
|
|
340
433
|
scaled_part = part.scale(scale_factor)
|
|
341
|
-
self.add_cadquery_object(
|
|
434
|
+
return self.add_cadquery_object(cadquery_object=scaled_part, material_tags=material_tags)
|
|
342
435
|
|
|
343
436
|
def add_cadquery_object(
|
|
344
437
|
self,
|
|
345
|
-
|
|
346
|
-
cq.assembly.Assembly
|
|
347
|
-
|
|
348
|
-
|
|
438
|
+
cadquery_object: (
|
|
439
|
+
cq.assembly.Assembly | cq.occ_impl.shapes.Compound | cq.occ_impl.shapes.Solid
|
|
440
|
+
),
|
|
441
|
+
material_tags: list[str] | None,
|
|
442
|
+
) -> int:
|
|
349
443
|
"""Loads the parts from CadQuery object into the model.
|
|
350
444
|
|
|
351
445
|
Args:
|
|
352
|
-
|
|
446
|
+
cadquery_object: the cadquery object to convert, can be a CadQuery assembly
|
|
447
|
+
cadquery workplane or a cadquery solid
|
|
448
|
+
material_tags (Optional list[str]): the names of the
|
|
449
|
+
DAGMC material tags to assign. These will need to be in the
|
|
450
|
+
same order as the volumes in the geometry added (STP file and
|
|
451
|
+
CadQuery objects) and match the material tags used in the
|
|
452
|
+
neutronics code (e.g. OpenMC).
|
|
453
|
+
|
|
454
|
+
Returns:
|
|
455
|
+
int: number of volumes in the stp file.
|
|
353
456
|
"""
|
|
354
457
|
|
|
355
|
-
if isinstance(
|
|
356
|
-
|
|
458
|
+
if isinstance(cadquery_object, cq.assembly.Assembly):
|
|
459
|
+
cadquery_object = cadquery_object.toCompound()
|
|
357
460
|
|
|
358
|
-
if isinstance(
|
|
359
|
-
iterable_solids =
|
|
461
|
+
if isinstance(cadquery_object, (cq.occ_impl.shapes.Compound, cq.occ_impl.shapes.Solid)):
|
|
462
|
+
iterable_solids = cadquery_object.Solids()
|
|
360
463
|
else:
|
|
361
|
-
iterable_solids =
|
|
464
|
+
iterable_solids = cadquery_object.val().Solids()
|
|
465
|
+
|
|
466
|
+
_check_material_tags(material_tags, iterable_solids)
|
|
467
|
+
if material_tags:
|
|
468
|
+
self.material_tags = self.material_tags + material_tags
|
|
362
469
|
self.parts = self.parts + iterable_solids
|
|
363
470
|
|
|
471
|
+
return len(iterable_solids)
|
|
472
|
+
|
|
364
473
|
def export_unstructured_mesh_file(
|
|
365
474
|
self,
|
|
366
475
|
filename: str = "umesh.h5m",
|
|
367
476
|
min_mesh_size: float = 1,
|
|
368
477
|
max_mesh_size: float = 5,
|
|
369
478
|
mesh_algorithm: int = 1,
|
|
479
|
+
method: str = "file",
|
|
370
480
|
):
|
|
371
481
|
|
|
372
482
|
assembly = cq.Assembly()
|
|
@@ -375,8 +485,12 @@ class CadToDagmc:
|
|
|
375
485
|
|
|
376
486
|
imprinted_assembly, _ = cq.occ_impl.assembly.imprint(assembly)
|
|
377
487
|
|
|
378
|
-
gmsh
|
|
379
|
-
|
|
488
|
+
gmsh = init_gmsh()
|
|
489
|
+
|
|
490
|
+
gmsh, _ = get_volumes(gmsh, imprinted_assembly, method=method)
|
|
491
|
+
|
|
492
|
+
gmsh = _mesh_brep(
|
|
493
|
+
gmsh=gmsh,
|
|
380
494
|
min_mesh_size=min_mesh_size,
|
|
381
495
|
max_mesh_size=max_mesh_size,
|
|
382
496
|
mesh_algorithm=mesh_algorithm,
|
|
@@ -392,6 +506,8 @@ class CadToDagmc:
|
|
|
392
506
|
|
|
393
507
|
gmsh.finalize()
|
|
394
508
|
|
|
509
|
+
return gmsh
|
|
510
|
+
|
|
395
511
|
def export_gmsh_mesh_file(
|
|
396
512
|
self,
|
|
397
513
|
filename: str = "mesh.msh",
|
|
@@ -399,6 +515,7 @@ class CadToDagmc:
|
|
|
399
515
|
max_mesh_size: float = 5,
|
|
400
516
|
mesh_algorithm: int = 1,
|
|
401
517
|
dimensions: int = 2,
|
|
518
|
+
method: str = "file",
|
|
402
519
|
):
|
|
403
520
|
"""Saves a GMesh msh file of the geometry in either 2D surface mesh or
|
|
404
521
|
3D volume mesh.
|
|
@@ -410,6 +527,14 @@ class CadToDagmc:
|
|
|
410
527
|
mesh_algorithm: the gmsh mesh algorithm to use.
|
|
411
528
|
dimensions: The number of dimensions, 2 for a surface mesh 3 for a
|
|
412
529
|
volume mesh. Passed to gmsh.model.mesh.generate()
|
|
530
|
+
method: the method to use to import the geometry into gmsh. Options
|
|
531
|
+
are 'file' or 'in memory'. 'file' is the default and will write
|
|
532
|
+
the geometry to a temporary file before importing it into gmsh.
|
|
533
|
+
'in memory' will import the geometry directly into gmsh but
|
|
534
|
+
requires the version of OpenCASCADE used to build gmsh to be
|
|
535
|
+
the same as the version used by CadQuery. This is possible to
|
|
536
|
+
ensure when installing the package with Conda but harder when
|
|
537
|
+
installing from PyPI.
|
|
413
538
|
"""
|
|
414
539
|
|
|
415
540
|
assembly = cq.Assembly()
|
|
@@ -418,8 +543,12 @@ class CadToDagmc:
|
|
|
418
543
|
|
|
419
544
|
imprinted_assembly, _ = cq.occ_impl.assembly.imprint(assembly)
|
|
420
545
|
|
|
421
|
-
gmsh
|
|
422
|
-
|
|
546
|
+
gmsh = init_gmsh()
|
|
547
|
+
|
|
548
|
+
gmsh, _ = get_volumes(gmsh, imprinted_assembly, method=method)
|
|
549
|
+
|
|
550
|
+
gmsh = _mesh_brep(
|
|
551
|
+
gmsh=gmsh,
|
|
423
552
|
min_mesh_size=min_mesh_size,
|
|
424
553
|
max_mesh_size=max_mesh_size,
|
|
425
554
|
mesh_algorithm=mesh_algorithm,
|
|
@@ -428,32 +557,42 @@ class CadToDagmc:
|
|
|
428
557
|
|
|
429
558
|
gmsh.write(filename)
|
|
430
559
|
|
|
560
|
+
print(f"written GMSH mesh file {filename}")
|
|
561
|
+
|
|
431
562
|
gmsh.finalize()
|
|
432
563
|
|
|
433
564
|
def export_dagmc_h5m_file(
|
|
434
565
|
self,
|
|
435
|
-
material_tags: typing.Iterable[str],
|
|
436
566
|
filename: str = "dagmc.h5m",
|
|
437
567
|
min_mesh_size: float = 1,
|
|
438
568
|
max_mesh_size: float = 5,
|
|
439
569
|
mesh_algorithm: int = 1,
|
|
440
|
-
implicit_complement_material_tag:
|
|
441
|
-
|
|
570
|
+
implicit_complement_material_tag: str | None = None,
|
|
571
|
+
method: str = "file",
|
|
572
|
+
) -> str:
|
|
442
573
|
"""Saves a DAGMC h5m file of the geometry
|
|
443
574
|
|
|
444
575
|
Args:
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
576
|
+
|
|
577
|
+
filename (str, optional): the filename to use for the saved DAGMC file. Defaults to "dagmc.h5m".
|
|
578
|
+
min_mesh_size (float, optional): the minimum size of mesh elements to use. Defaults to 1.
|
|
579
|
+
max_mesh_size (float, optional): the maximum size of mesh elements to use. Defaults to 5.
|
|
580
|
+
mesh_algorithm (int, optional): the GMSH mesh algorithm to use.. Defaults to 1.
|
|
581
|
+
implicit_complement_material_tag (str | None, optional):
|
|
582
|
+
the name of the material tag to use for the implicit complement
|
|
583
|
+
(void space). Defaults to None which is a vacuum. Defaults to None.
|
|
584
|
+
method: the method to use to import the geometry into gmsh. Options
|
|
585
|
+
are 'file' or 'in memory'. 'file' is the default and will write
|
|
586
|
+
the geometry to a temporary file before importing it into gmsh.
|
|
587
|
+
'in memory' will import the geometry directly into gmsh but
|
|
588
|
+
requires the version of OpenCASCADE used to build gmsh to be
|
|
589
|
+
the same as the version used by CadQuery. This is possible to
|
|
590
|
+
ensure when installing the package with Conda but harder when
|
|
591
|
+
installing from PyPI.
|
|
592
|
+
Returns:
|
|
593
|
+
str: the DAGMC filename saved
|
|
456
594
|
"""
|
|
595
|
+
|
|
457
596
|
assembly = cq.Assembly()
|
|
458
597
|
for part in self.parts:
|
|
459
598
|
assembly.add(part)
|
|
@@ -466,30 +605,32 @@ class CadToDagmc:
|
|
|
466
605
|
# both id lists should be the same length as each other and the same
|
|
467
606
|
# length as the self.material_tags
|
|
468
607
|
|
|
469
|
-
if len(original_ids) != len(material_tags):
|
|
470
|
-
msg = f"Number of volumes {len(original_ids)} is not equal to number of material tags {len(material_tags)}"
|
|
608
|
+
if len(original_ids) != len(self.material_tags):
|
|
609
|
+
msg = f"Number of volumes {len(original_ids)} is not equal to number of material tags {len(self.material_tags)}"
|
|
471
610
|
raise ValueError(msg)
|
|
472
611
|
|
|
473
612
|
material_tags_in_brep_order = order_material_ids_by_brep_order(
|
|
474
|
-
original_ids, scrambled_ids, material_tags
|
|
613
|
+
original_ids, scrambled_ids, self.material_tags
|
|
475
614
|
)
|
|
476
615
|
|
|
477
|
-
|
|
478
|
-
|
|
616
|
+
_check_material_tags(material_tags_in_brep_order, self.parts)
|
|
617
|
+
|
|
618
|
+
gmsh = init_gmsh()
|
|
619
|
+
|
|
620
|
+
gmsh, volumes = get_volumes(gmsh, imprinted_assembly, method=method)
|
|
621
|
+
|
|
622
|
+
gmsh = _mesh_brep(
|
|
623
|
+
gmsh=gmsh,
|
|
479
624
|
min_mesh_size=min_mesh_size,
|
|
480
625
|
max_mesh_size=max_mesh_size,
|
|
481
626
|
mesh_algorithm=mesh_algorithm,
|
|
482
627
|
)
|
|
483
628
|
|
|
484
|
-
|
|
485
|
-
msg = f"material_tags should be a list of strings, not a single string."
|
|
486
|
-
raise ValueError(msg)
|
|
487
|
-
|
|
488
|
-
if len(volumes) != len(material_tags_in_brep_order):
|
|
489
|
-
msg = f"{len(volumes)} volumes found in Brep file is not equal to the number of material_tags {len(material_tags_in_brep_order)} provided."
|
|
490
|
-
raise ValueError(msg)
|
|
629
|
+
dims_and_vol_ids = volumes
|
|
491
630
|
|
|
492
|
-
vertices, triangles_by_solid_by_face =
|
|
631
|
+
vertices, triangles_by_solid_by_face = mesh_to_vertices_and_triangles(
|
|
632
|
+
dims_and_vol_ids=dims_and_vol_ids
|
|
633
|
+
)
|
|
493
634
|
|
|
494
635
|
gmsh.finalize()
|
|
495
636
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cad_to_dagmc
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.1
|
|
4
4
|
Summary: Converts CAD files to a DAGMC h5m file
|
|
5
5
|
Author-email: Jonathan Shimwell <mail@jshimwell.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/fusion-energy/cad_to_dagmc
|
|
@@ -15,6 +15,8 @@ License-File: LICENSE
|
|
|
15
15
|
Requires-Dist: trimesh
|
|
16
16
|
Requires-Dist: networkx
|
|
17
17
|
Requires-Dist: cadquery >=2.4.0
|
|
18
|
+
Requires-Dist: numpy <=1.23.5
|
|
19
|
+
Requires-Dist: gmsh
|
|
18
20
|
Provides-Extra: tests
|
|
19
21
|
Requires-Dist: pytest ; extra == 'tests'
|
|
20
22
|
Requires-Dist: vtk ; extra == 'tests'
|
|
@@ -51,12 +53,11 @@ Also checkout these other software projects that also create DAGMC geometry [CAD
|
|
|
51
53
|
|
|
52
54
|
# Installation options
|
|
53
55
|
|
|
54
|
-
- Install using Mamba
|
|
55
|
-
- Install using Conda
|
|
56
|
+
- Install using Mamba
|
|
57
|
+
- Install using Conda
|
|
56
58
|
- Install using pip and source compilations
|
|
57
59
|
|
|
58
|
-
|
|
59
|
-
## Install using Mamba and pip
|
|
60
|
+
## Install using Mamba
|
|
60
61
|
|
|
61
62
|
In principle, installing any Conda/Mamba distribution will work. A few Conda/Mamba options are:
|
|
62
63
|
- [Miniforge](https://github.com/conda-forge/miniforge) (recommended as it includes mamba)
|
|
@@ -65,7 +66,7 @@ In principle, installing any Conda/Mamba distribution will work. A few Conda/Mam
|
|
|
65
66
|
|
|
66
67
|
This example assumes you have installed the Miniforge option or separately have installed Mamba with ```conda install -c conda-forge mamba -y```
|
|
67
68
|
|
|
68
|
-
Create a new
|
|
69
|
+
Create a new environment, I've chosen Python 3.10 here but newer versions are
|
|
69
70
|
also supported.
|
|
70
71
|
```bash
|
|
71
72
|
mamba create --name new_env python=3.10 -y
|
|
@@ -76,27 +77,20 @@ Activate the environment
|
|
|
76
77
|
mamba activate new_env
|
|
77
78
|
```
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
Then you can install the cad_to_dagmc package
|
|
80
81
|
```bash
|
|
81
|
-
mamba install -y -c conda-forge
|
|
82
|
+
mamba install -y -c conda-forge cad_to_dagmc
|
|
82
83
|
```
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
pip install cad_to_dagmc
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
## Install using Conda and pip
|
|
85
|
+
## Install using Conda
|
|
91
86
|
|
|
92
87
|
In principle, installing any Conda/Mamba distribution will work. A few Conda/Mamba options are:
|
|
93
88
|
- [Miniforge](https://github.com/conda-forge/miniforge) (recommended as it includes mamba)
|
|
94
89
|
- [Anaconda](https://www.anaconda.com/download)
|
|
95
90
|
- [Miniconda](https://docs.conda.io/en/latest/miniconda.html)
|
|
96
91
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
Create a new conda environment
|
|
92
|
+
Create a new environment, I've chosen Python 3.10 here but newer versions are
|
|
93
|
+
also supported.
|
|
100
94
|
```bash
|
|
101
95
|
conda create --name new_env python=3.10 -y
|
|
102
96
|
```
|
|
@@ -106,23 +100,37 @@ Activate the environment
|
|
|
106
100
|
conda activate new_env
|
|
107
101
|
```
|
|
108
102
|
|
|
109
|
-
|
|
103
|
+
Then you can install the cad_to_dagmc package
|
|
110
104
|
```bash
|
|
111
|
-
conda install -y -c conda-forge
|
|
105
|
+
conda install -y -c conda-forge cad_to_dagmc
|
|
112
106
|
```
|
|
113
107
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
108
|
+
## Install using pip and source compilations
|
|
109
|
+
|
|
110
|
+
It is also possible to avoid the use of conda/mamba and installing using pip.
|
|
111
|
+
|
|
112
|
+
First ensure hdf5 is installed as this is needed by MOAB pip install command
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
sudo apt-get install libhdf5-dev
|
|
117
116
|
```
|
|
118
117
|
|
|
119
|
-
|
|
118
|
+
Then clone the latest version of MOAB and cd into the moab directory.
|
|
120
119
|
|
|
121
|
-
|
|
120
|
+
```
|
|
121
|
+
git clone master https://bitbucket.org/fathomteam/moab/
|
|
122
|
+
cd moab
|
|
123
|
+
```
|
|
122
124
|
|
|
123
|
-
|
|
125
|
+
Ensure pip is up to date as a new version is needed
|
|
126
|
+
```
|
|
127
|
+
python -m pip install --upgrade pip
|
|
128
|
+
```
|
|
124
129
|
|
|
125
|
-
|
|
130
|
+
Run the pip install command with cmake arguments.
|
|
131
|
+
```
|
|
132
|
+
pip install . --config-settings=cmake.args=-DENABLE_HDF5=ON
|
|
133
|
+
```
|
|
126
134
|
|
|
127
135
|
Then you can install the cad_to_dagmc package with ```pip```
|
|
128
136
|
|
|
@@ -130,7 +138,7 @@ Then you can install the cad_to_dagmc package with ```pip```
|
|
|
130
138
|
pip install cad_to_dagmc
|
|
131
139
|
```
|
|
132
140
|
|
|
133
|
-
## Install with
|
|
141
|
+
## Install with OpenMC or other particle transport codes
|
|
134
142
|
|
|
135
143
|
You may also want to install OpenMC with DAGMC to make use of the h5m geometry files produced in simulations. However you could also use other supported particle transport codes such as MCNP, FLUKA and others [link to DAGMC documentation](https://svalinn.github.io/DAGMC/).
|
|
136
144
|
|
|
@@ -144,28 +152,13 @@ It might not be possible to install OpenMC and cad-to-dagmc in the same conda/ma
|
|
|
144
152
|
Another option would be to [install OpenMC from source](https://docs.openmc.org/en/stable/quickinstall.html) which would also need compiling with MOAB and DAGMC options.
|
|
145
153
|
|
|
146
154
|
|
|
147
|
-
|
|
148
155
|
# Known incompatibilities
|
|
149
156
|
|
|
150
157
|
The package requires newer versions of Linux. For example the package does not work on Ubuntu 18.04 or older.
|
|
151
158
|
|
|
152
159
|
The package requires newer versions of pip. It is recommended to ensure that your version of pip is up to date. This can be done with ```python -m pip install --upgrade pip```
|
|
153
160
|
|
|
154
|
-
Installing one of the package dependancies (gmsh) with pip appears to result in
|
|
155
|
-
|
|
156
|
-
# Usage - with OpenMC
|
|
157
|
-
|
|
158
|
-
You may also want to install OpenMC with DAGMC to make use of the h5m geometry files produced in simulations. However you could also use other supported particle transport codes such as MCNP, FLUKA and others supported by [DAGMC](https://svalinn.github.io/DAGMC/).
|
|
159
|
-
|
|
160
|
-
You can run ```mamba install -c conda-forge openmc``` however this may choose to install OpenMC without DAGMC included.
|
|
161
|
-
|
|
162
|
-
You can be more specific with conda/mamba commands to make sure the latest version of OpenMC which contains DAGMC is chosen by conda / mamba
|
|
163
|
-
```bash
|
|
164
|
-
mamba install -c conda-forge -y "openmc=0.14.0=dagmc*nompi*"
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
You could also [install OpenMC from source](https://docs.openmc.org/en/stable/quickinstall.html) which might be prefered as it can be tricky for the conda enviroment to get resolved.
|
|
168
|
-
|
|
161
|
+
Installing one of the package dependancies (gmsh) with pip appears to result in errors when passing cad objects in memory between cadquery / ocp and gmsh. The default method of passing cad objects is via file so this should not impact most users. The conda install gmsh appears to work fine with in memory passing of cad objects as the version of OCP matches between Gmsh and CadQuery.
|
|
169
162
|
|
|
170
163
|
|
|
171
164
|
# Usage - creation of DAGMC h5m files
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
_version.py,sha256=5-skCoU2Vu44uYeNEApDjjGE2Q26ndIh5lKJuVOeL88,411
|
|
2
|
+
cad_to_dagmc/__init__.py,sha256=fskHUTyCunSpnpJUvBfAYjx4uwDKXHTTiMP6GqnFRf0,494
|
|
3
|
+
cad_to_dagmc/core.py,sha256=aGBPoxZMWmoo-qf28AFkoSsdO59EtLtRJ_87QKUaFgU,23297
|
|
4
|
+
cad_to_dagmc-0.7.1.dist-info/LICENSE,sha256=B8kznH_777JVNZ3HOKDc4Tj24F7wJ68ledaNYeL9sCw,1070
|
|
5
|
+
cad_to_dagmc-0.7.1.dist-info/METADATA,sha256=9gUrCwcSrUx0wHrYoug9f9PJiiiCEwnH4BU-_-pyJ-s,7610
|
|
6
|
+
cad_to_dagmc-0.7.1.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
|
7
|
+
cad_to_dagmc-0.7.1.dist-info/top_level.txt,sha256=zTi8C64SEBsE5WOtPovnxhOzt-E6Oc5nC3RW6M_5aEA,22
|
|
8
|
+
cad_to_dagmc-0.7.1.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
_version.py,sha256=PMhMumGW6FY6KtkQm1bSNdEAeyrHlBqpSQ7WpjsTyws,411
|
|
2
|
-
cad_to_dagmc/__init__.py,sha256=fskHUTyCunSpnpJUvBfAYjx4uwDKXHTTiMP6GqnFRf0,494
|
|
3
|
-
cad_to_dagmc/core.py,sha256=eMwKgKOjje3gBZEqjNzy9O6NF8a02WxD-VhXB5AJg58,18108
|
|
4
|
-
cad_to_dagmc-0.6.2.dist-info/LICENSE,sha256=B8kznH_777JVNZ3HOKDc4Tj24F7wJ68ledaNYeL9sCw,1070
|
|
5
|
-
cad_to_dagmc-0.6.2.dist-info/METADATA,sha256=vt8mq3_FjyTBzNfGDDpH5Kd8PVyqICf1AQUphB-qAic,8147
|
|
6
|
-
cad_to_dagmc-0.6.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
7
|
-
cad_to_dagmc-0.6.2.dist-info/top_level.txt,sha256=zTi8C64SEBsE5WOtPovnxhOzt-E6Oc5nC3RW6M_5aEA,22
|
|
8
|
-
cad_to_dagmc-0.6.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|