cad-to-dagmc 0.7.0__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 CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.7.0'
16
- __version_tuple__ = version_tuple = (0, 7, 0)
15
+ __version__ = version = '0.7.1'
16
+ __version_tuple__ = version_tuple = (0, 7, 1)
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() -> typing.Tuple[core.Core, dict]:
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: typing.Union[
66
- typing.Iterable[typing.Tuple[float, float, float]],
67
- typing.Iterable["cadquery.occ_impl.geom.Vector"],
68
- ],
69
- triangles_by_solid_by_face: typing.Iterable[typing.Iterable[typing.Tuple[int, int, int]]],
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
@@ -194,8 +190,29 @@ def _vertices_to_h5m(
194
190
  return h5m_filename
195
191
 
196
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
+
197
214
  def _mesh_brep(
198
- occ_shape: str,
215
+ gmsh,
199
216
  min_mesh_size: float = 1,
200
217
  max_mesh_size: float = 10,
201
218
  mesh_algorithm: int = 1,
@@ -219,18 +236,12 @@ def _mesh_brep(
219
236
  The resulting gmsh object and volumes
220
237
  """
221
238
 
222
- gmsh.initialize()
223
- gmsh.option.setNumber("General.Terminal", 1)
224
- gmsh.model.add("made_with_cad_to_dagmc_package")
225
- volumes = gmsh.model.occ.importShapesNativePointer(occ_shape)
226
- gmsh.model.occ.synchronize()
227
-
228
239
  gmsh.option.setNumber("Mesh.Algorithm", mesh_algorithm)
229
240
  gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size)
230
241
  gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size)
231
242
  gmsh.model.mesh.generate(dimensions)
232
243
 
233
- return gmsh, volumes
244
+ return gmsh
234
245
 
235
246
 
236
247
  def mesh_to_vertices_and_triangles(
@@ -336,18 +347,18 @@ class MeshToDagmc:
336
347
 
337
348
  def export_dagmc_h5m_file(
338
349
  self,
339
- material_tags: typing.Iterable[str],
340
- implicit_complement_material_tag: typing.Optional[str] = None,
350
+ material_tags: list[str],
351
+ implicit_complement_material_tag: str | None = None,
341
352
  filename: str = "dagmc.h5m",
342
353
  ):
343
354
  """Saves a DAGMC h5m file of the geometry
344
355
 
345
356
  Args:
346
- material_tags (typing.Iterable[str]): the names of the DAGMC
357
+ material_tags (list[str]): the names of the DAGMC
347
358
  material tags to assign. These will need to be in the same
348
359
  order as the volumes in the GMESH mesh and match the
349
360
  material tags used in the neutronics code (e.g. OpenMC).
350
- implicit_complement_material_tag (typing.Optional[str], optional):
361
+ implicit_complement_material_tag (str | None, optional):
351
362
  the name of the material tag to use for the implicit
352
363
  complement (void space). Defaults to None which is a vacuum.
353
364
  filename (str, optional): _description_. Defaults to "dagmc.h5m".
@@ -395,13 +406,13 @@ class CadToDagmc:
395
406
  self,
396
407
  filename: str,
397
408
  scale_factor: float = 1.0,
398
- material_tags: typing.Optional[typing.Iterable[str]] = None,
399
- ):
409
+ material_tags: list[str] | None = None,
410
+ ) -> int:
400
411
  """Loads the parts from stp file into the model.
401
412
 
402
413
  Args:
403
414
  filename: the filename used to save the html graph.
404
- material_tags (typing.Iterable[str]): the names of the DAGMC
415
+ material_tags (list[str]): the names of the DAGMC
405
416
  material tags to assign. These will need to be in the
406
417
  same order as the volumes in the geometry added (STP
407
418
  file and CadQuery objects) and match the material tags
@@ -410,6 +421,9 @@ class CadToDagmc:
410
421
  used to increase the size or decrease the size of the geometry.
411
422
  Useful when converting the geometry to cm for use in neutronics
412
423
  simulations.
424
+
425
+ Returns:
426
+ int: number of volumes in the stp file.
413
427
  """
414
428
  part = importers.importStep(str(filename)).val()
415
429
 
@@ -417,25 +431,28 @@ class CadToDagmc:
417
431
  scaled_part = part
418
432
  else:
419
433
  scaled_part = part.scale(scale_factor)
420
- self.add_cadquery_object(cadquery_object=scaled_part, material_tags=material_tags)
434
+ return self.add_cadquery_object(cadquery_object=scaled_part, material_tags=material_tags)
421
435
 
422
436
  def add_cadquery_object(
423
437
  self,
424
- cadquery_object: typing.Union[
425
- cq.assembly.Assembly, cq.occ_impl.shapes.Compound, cq.occ_impl.shapes.Solid
426
- ],
427
- material_tags: typing.Optional[typing.Iterable[str]] = None,
428
- ):
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:
429
443
  """Loads the parts from CadQuery object into the model.
430
444
 
431
445
  Args:
432
446
  cadquery_object: the cadquery object to convert, can be a CadQuery assembly
433
447
  cadquery workplane or a cadquery solid
434
- material_tags (Optional typing.Iterable[str]): the names of the
448
+ material_tags (Optional list[str]): the names of the
435
449
  DAGMC material tags to assign. These will need to be in the
436
450
  same order as the volumes in the geometry added (STP file and
437
451
  CadQuery objects) and match the material tags used in the
438
452
  neutronics code (e.g. OpenMC).
453
+
454
+ Returns:
455
+ int: number of volumes in the stp file.
439
456
  """
440
457
 
441
458
  if isinstance(cadquery_object, cq.assembly.Assembly):
@@ -451,12 +468,15 @@ class CadToDagmc:
451
468
  self.material_tags = self.material_tags + material_tags
452
469
  self.parts = self.parts + iterable_solids
453
470
 
471
+ return len(iterable_solids)
472
+
454
473
  def export_unstructured_mesh_file(
455
474
  self,
456
475
  filename: str = "umesh.h5m",
457
476
  min_mesh_size: float = 1,
458
477
  max_mesh_size: float = 5,
459
478
  mesh_algorithm: int = 1,
479
+ method: str = "file",
460
480
  ):
461
481
 
462
482
  assembly = cq.Assembly()
@@ -465,8 +485,12 @@ class CadToDagmc:
465
485
 
466
486
  imprinted_assembly, _ = cq.occ_impl.assembly.imprint(assembly)
467
487
 
468
- gmsh, _ = _mesh_brep(
469
- occ_shape=imprinted_assembly.wrapped._address(),
488
+ gmsh = init_gmsh()
489
+
490
+ gmsh, _ = get_volumes(gmsh, imprinted_assembly, method=method)
491
+
492
+ gmsh = _mesh_brep(
493
+ gmsh=gmsh,
470
494
  min_mesh_size=min_mesh_size,
471
495
  max_mesh_size=max_mesh_size,
472
496
  mesh_algorithm=mesh_algorithm,
@@ -491,6 +515,7 @@ class CadToDagmc:
491
515
  max_mesh_size: float = 5,
492
516
  mesh_algorithm: int = 1,
493
517
  dimensions: int = 2,
518
+ method: str = "file",
494
519
  ):
495
520
  """Saves a GMesh msh file of the geometry in either 2D surface mesh or
496
521
  3D volume mesh.
@@ -502,6 +527,14 @@ class CadToDagmc:
502
527
  mesh_algorithm: the gmsh mesh algorithm to use.
503
528
  dimensions: The number of dimensions, 2 for a surface mesh 3 for a
504
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.
505
538
  """
506
539
 
507
540
  assembly = cq.Assembly()
@@ -510,8 +543,12 @@ class CadToDagmc:
510
543
 
511
544
  imprinted_assembly, _ = cq.occ_impl.assembly.imprint(assembly)
512
545
 
513
- gmsh, _ = _mesh_brep(
514
- occ_shape=imprinted_assembly.wrapped._address(),
546
+ gmsh = init_gmsh()
547
+
548
+ gmsh, _ = get_volumes(gmsh, imprinted_assembly, method=method)
549
+
550
+ gmsh = _mesh_brep(
551
+ gmsh=gmsh,
515
552
  min_mesh_size=min_mesh_size,
516
553
  max_mesh_size=max_mesh_size,
517
554
  mesh_algorithm=mesh_algorithm,
@@ -530,7 +567,8 @@ class CadToDagmc:
530
567
  min_mesh_size: float = 1,
531
568
  max_mesh_size: float = 5,
532
569
  mesh_algorithm: int = 1,
533
- implicit_complement_material_tag: typing.Optional[str] = None,
570
+ implicit_complement_material_tag: str | None = None,
571
+ method: str = "file",
534
572
  ) -> str:
535
573
  """Saves a DAGMC h5m file of the geometry
536
574
 
@@ -540,10 +578,17 @@ class CadToDagmc:
540
578
  min_mesh_size (float, optional): the minimum size of mesh elements to use. Defaults to 1.
541
579
  max_mesh_size (float, optional): the maximum size of mesh elements to use. Defaults to 5.
542
580
  mesh_algorithm (int, optional): the GMSH mesh algorithm to use.. Defaults to 1.
543
- implicit_complement_material_tag (typing.Optional[str], optional):
581
+ implicit_complement_material_tag (str | None, optional):
544
582
  the name of the material tag to use for the implicit complement
545
583
  (void space). Defaults to None which is a vacuum. Defaults to None.
546
-
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.
547
592
  Returns:
548
593
  str: the DAGMC filename saved
549
594
  """
@@ -570,8 +615,12 @@ class CadToDagmc:
570
615
 
571
616
  _check_material_tags(material_tags_in_brep_order, self.parts)
572
617
 
573
- gmsh, volumes = _mesh_brep(
574
- occ_shape=imprinted_assembly.wrapped._address(), # in memory address
618
+ gmsh = init_gmsh()
619
+
620
+ gmsh, volumes = get_volumes(gmsh, imprinted_assembly, method=method)
621
+
622
+ gmsh = _mesh_brep(
623
+ gmsh=gmsh,
575
624
  min_mesh_size=min_mesh_size,
576
625
  max_mesh_size=max_mesh_size,
577
626
  mesh_algorithm=mesh_algorithm,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cad_to_dagmc
3
- Version: 0.7.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'
@@ -53,8 +55,6 @@ Also checkout these other software projects that also create DAGMC geometry [CAD
53
55
 
54
56
  - Install using Mamba
55
57
  - Install using Conda
56
- - Install using Mamba and pip
57
- - Install using Conda and pip
58
58
  - Install using pip and source compilations
59
59
 
60
60
  ## Install using Mamba
@@ -105,73 +105,32 @@ Then you can install the cad_to_dagmc package
105
105
  conda install -y -c conda-forge cad_to_dagmc
106
106
  ```
107
107
 
108
- ## Install using Mamba and pip
108
+ ## Install using pip and source compilations
109
109
 
110
- In principle, installing any Conda/Mamba distribution will work. A few Conda/Mamba options are:
111
- - [Miniforge](https://github.com/conda-forge/miniforge) (recommended as it includes mamba)
112
- - [Anaconda](https://www.anaconda.com/download)
113
- - [Miniconda](https://docs.conda.io/en/latest/miniconda.html)
110
+ It is also possible to avoid the use of conda/mamba and installing using pip.
114
111
 
115
- This example assumes you have installed the Miniforge option or separately have installed Mamba with ```conda install -c conda-forge mamba -y```
112
+ First ensure hdf5 is installed as this is needed by MOAB pip install command
116
113
 
117
- Create a new environment, I've chosen Python 3.10 here but newer versions are
118
- also supported.
119
- ```bash
120
- mamba create --name new_env python=3.10 -y
121
114
  ```
122
-
123
- Activate the environment
124
- ```bash
125
- mamba activate new_env
115
+ sudo apt-get install libhdf5-dev
126
116
  ```
127
117
 
128
- Install the dependencies
129
- ```bash
130
- mamba install -y -c conda-forge "moab>=5.3.0" gmsh python-gmsh
131
- ```
118
+ Then clone the latest version of MOAB and cd into the moab directory.
132
119
 
133
- Then you can install the cad_to_dagmc package
134
- ```bash
135
- pip install cad_to_dagmc
136
120
  ```
137
-
138
-
139
- ## Install using Conda and pip
140
-
141
- In principle, installing any Conda/Mamba distribution will work. A few Conda/Mamba options are:
142
- - [Miniforge](https://github.com/conda-forge/miniforge) (recommended as it includes mamba)
143
- - [Anaconda](https://www.anaconda.com/download)
144
- - [Miniconda](https://docs.conda.io/en/latest/miniconda.html)
145
-
146
- This example uses Conda to install some dependencies that are not available via PyPi.
147
-
148
- Create a new environment
149
- ```bash
150
- conda create --name new_env python=3.10 -y
121
+ git clone master https://bitbucket.org/fathomteam/moab/
122
+ cd moab
151
123
  ```
152
124
 
153
- Activate the environment
154
- ```bash
155
- conda activate new_env
125
+ Ensure pip is up to date as a new version is needed
156
126
  ```
157
-
158
- Install the dependencies
159
- ```bash
160
- conda install -y -c conda-forge "moab>=5.3.0" gmsh python-gmsh
127
+ python -m pip install --upgrade pip
161
128
  ```
162
129
 
163
- Then you can install the cad_to_dagmc package
164
- ```bash
165
- pip install cad_to_dagmc
130
+ Run the pip install command with cmake arguments.
131
+ ```
132
+ pip install . --config-settings=cmake.args=-DENABLE_HDF5=ON
166
133
  ```
167
-
168
- ## Install using pip and source compilations
169
-
170
- It should possible to avoid the use of conda and installing using pip and compiling from source.
171
-
172
- First compile MOAB (and install Pymoab) from source
173
-
174
- Then install gmsh from source (installing from pip appears to cause conflicts with the open cascade used in ocp and cadquery)
175
134
 
176
135
  Then you can install the cad_to_dagmc package with ```pip```
177
136
 
@@ -199,7 +158,7 @@ The package requires newer versions of Linux. For example the package does not w
199
158
 
200
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```
201
160
 
202
- Installing one of the package dependancies (gmsh) with pip appears to result in occational errors when passing cad objects between cadquery / ocp and gmsh. The conda install gmsh appears to work fine.
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.
203
162
 
204
163
 
205
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,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (75.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,8 +0,0 @@
1
- _version.py,sha256=akvr8ObxvMF-aaLBzW41juT4_KL3BjQUrjbwkIuQXMk,411
2
- cad_to_dagmc/__init__.py,sha256=fskHUTyCunSpnpJUvBfAYjx4uwDKXHTTiMP6GqnFRf0,494
3
- cad_to_dagmc/core.py,sha256=WJXKGK9yOtary66qPRB7cmdLlSdhSTkv1b4TxHtIvxw,21495
4
- cad_to_dagmc-0.7.0.dist-info/LICENSE,sha256=B8kznH_777JVNZ3HOKDc4Tj24F7wJ68ledaNYeL9sCw,1070
5
- cad_to_dagmc-0.7.0.dist-info/METADATA,sha256=40zC0CAVvVveGQ7wRpLvTE0gEhCtt5a-3ZvJQYCZc80,8770
6
- cad_to_dagmc-0.7.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
7
- cad_to_dagmc-0.7.0.dist-info/top_level.txt,sha256=zTi8C64SEBsE5WOtPovnxhOzt-E6Oc5nC3RW6M_5aEA,22
8
- cad_to_dagmc-0.7.0.dist-info/RECORD,,