Skip to content

Commit

Permalink
Merge pull request #32 from fusion-energy/separate_tests_for_h5m_crea…
Browse files Browse the repository at this point in the history
…tion_and_transport

refactoring to decrease repetition
  • Loading branch information
shimwell authored Mar 16, 2024
2 parents 08290a0 + 86cb873 commit aee24f5
Show file tree
Hide file tree
Showing 35 changed files with 341 additions and 545 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,26 @@ mamba install -y -c conda-forge moab gmsh python-gmsh "openmc=0.14.0=dagmc*nompi
CadQuery should then be installed, here is the mamba command and the pip command.

```bash
mamba install -y -c cadquery cadquery=master
mamba install -y -c cadquery ocp=7.7.4 cadquery=2.4.0
```

If the mamba command fails to solve the environment then try this pip command.

```bash
pip install git+https://github.com/CadQuery/cadquery.git
python -m pip install git+https://github.com/CadQuery/cadquery.git
```

Then you can install the cad_to_dagmc package with ```pip```
Then you can install which ever convertor you want to test. The cad_to_dagmc and the CAD_to_OpenMC packages can both be installed with ```pip```

```bash
pip install cad_to_dagmc
python -m pip install cad_to_dagmc
python -m pip install CAD_to_OpenMC
```

Then you can install the model benchmark zoo with ```pip```

```bash
pip install git+git://github.com/fusion-energy/model_benchmark_zoo.git
python -m pip install git+git://github.com/fusion-energy/model_benchmark_zoo.git
```

# Usage
Expand Down
2 changes: 1 addition & 1 deletion examples/compare_csg_cad_circulartorus.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
my_settings.run_mode = 'fixed source'

# Create a DT point source
my_source = openmc.Source()
my_source = openmc.IndependentSource()
r = openmc.stats.Discrete([major_radius], [1])
phi = openmc.stats.Uniform(0, 2*np.pi)
z = openmc.stats.Discrete([0], [1])
Expand Down
2 changes: 1 addition & 1 deletion examples/compare_csg_cad_cuboid.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
my_settings.run_mode = 'fixed source'

# Create a DT point source
my_source = openmc.Source()
my_source = openmc.IndependentSource()
my_source.space = openmc.stats.Point((0, 0, 0))
my_source.angle = openmc.stats.Isotropic()
my_source.energy = openmc.stats.Discrete([14e6], [1])
Expand Down
2 changes: 1 addition & 1 deletion examples/compare_csg_cad_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
my_settings.run_mode = 'fixed source'

# Create a DT point source
my_source = openmc.Source()
my_source = openmc.IndependentSource()
my_source.space = openmc.stats.Point((0, 0, 0))
my_source.angle = openmc.stats.Isotropic()
my_source.energy = openmc.stats.Discrete([14e6], [1])
Expand Down
2 changes: 1 addition & 1 deletion examples/compare_csg_cad_ellipticaltorus.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
my_settings.run_mode = 'fixed source'

# Create a DT point source
my_source = openmc.Source()
my_source = openmc.IndependentSource()
r = openmc.stats.Discrete([major_radius], [1])
phi = openmc.stats.Uniform(0, 2*np.pi)
z = openmc.stats.Discrete([0], [1])
Expand Down
2 changes: 1 addition & 1 deletion examples/compare_csg_cad_nestedcylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
my_settings.run_mode = 'fixed source'

# Create a DT point source
my_source = openmc.Source()
my_source = openmc.IndependentSource()
my_source.space = openmc.stats.Point((0, 0, 0))
my_source.angle = openmc.stats.Isotropic()
my_source.energy = openmc.stats.Discrete([14e6], [1])
Expand Down
2 changes: 1 addition & 1 deletion examples/compare_csg_cad_nestedsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
my_settings.run_mode = 'fixed source'

# Create a DT point source
my_source = openmc.Source()
my_source = openmc.IndependentSource()
my_source.space = openmc.stats.Point((0, 0, 0))
my_source.angle = openmc.stats.Isotropic()
my_source.energy = openmc.stats.Discrete([14e6], [1])
Expand Down
2 changes: 1 addition & 1 deletion examples/compare_csg_cad_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
my_settings.run_mode = 'fixed source'

# Create a DT point source
my_source = openmc.Source()
my_source = openmc.IndependentSource()
my_source.space = openmc.stats.Point((0, 0, 0))
my_source.angle = openmc.stats.Isotropic()
my_source.energy = openmc.stats.Discrete([14e6], [1])
Expand Down
2 changes: 1 addition & 1 deletion examples/compare_csg_cad_two_touching_cuboids.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
my_settings.run_mode = 'fixed source'

# Create a DT point source
my_source = openmc.Source()
my_source = openmc.IndependentSource()
my_source.space = openmc.stats.Point((0, 0, 0))
my_source.angle = openmc.stats.Isotropic()
my_source.energy = openmc.stats.Discrete([14e6], [1])
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
license = {file = "LICENSE.txt"}
description = "Collection of geometries for testing neutronics simulations in CSG and CAD format"
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.10"
keywords = ["dagmc", "geometry", "test", "benchmark"]
classifiers = [
"Programming Language :: Python :: 3",
Expand Down
71 changes: 15 additions & 56 deletions src/model_benchmark_zoo/circulartorus.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,30 @@

class Circulartorus:
def __init__(self, materials, major_radius=10, minor_radius=1):
self.materials = materials
from .utils import BaseCommonGeometryObject
class Circulartorus(BaseCommonGeometryObject):
def __init__(self, major_radius=10, minor_radius=1):
self.major_radius = major_radius
self.minor_radius = minor_radius

def csg_model(self):
def csg_model(self, materials):
import openmc

surface = openmc.ZTorus(a=self.major_radius, b=self.minor_radius, c=self.minor_radius, boundary_type="vacuum")

surface = openmc.ZTorus(
a=self.major_radius,
b=self.minor_radius,
c=self.minor_radius,
boundary_type="vacuum"
)
region = -surface
cell = openmc.Cell(region=region)
cell.fill = self.materials[0]
cell.fill = materials[0]
geometry = openmc.Geometry([cell])
materials = openmc.Materials([self.materials[0]])
model = openmc.Model(geometry=geometry, materials=materials)
my_materials = openmc.Materials(materials)
model = openmc.Model(geometry=geometry, materials=my_materials)
return model

def cadquery_assembly(self):
import cadquery as cq

assembly = cq.Assembly(name="circulartorus")
circulartorus = cq.Solid.makeTorus(self.major_radius, self.minor_radius)
assembly.add(circulartorus)
return assembly

def export_stp_file(self, filename="circulartorus.step"):
self.cadquery_assembly().save(filename, "STEP")

def dagmc_model(self, filename="circulartorus.h5m", min_mesh_size=0.1, max_mesh_size=100.0):
from cad_to_dagmc import CadToDagmc
import openmc

assembly = self.cadquery_assembly()
ctd = CadToDagmc()
material_tags = [self.materials[0].name]
ctd.add_cadquery_object(assembly, material_tags=material_tags)
ctd.export_dagmc_h5m_file(
filename,
min_mesh_size=min_mesh_size,
max_mesh_size=max_mesh_size
)
universe = openmc.DAGMCUniverse(filename).bounded_universe()
materials = openmc.Materials([self.materials[0]])
geometry = openmc.Geometry(universe)

model = openmc.Model(geometry=geometry, materials=materials)
return model

def dagmc_model_with_cad_to_openmc(self, filename="circulartorus.h5m"):
from CAD_to_OpenMC import assembly
import openmc

self.export_stp_file()

a=assembly.Assembly(["circulartorus.step"])
a.verbose=1
assembly.mesher_config['threads']=1
a.run(
backend='stl2',
merge=True,
h5m_filename=filename,
sequential_tags=[self.materials[0].name],
scale=1.0
)

universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe()
geometry = openmc.Geometry(universe)
model = openmc.Model(geometry=geometry)
return model
return assembly
61 changes: 9 additions & 52 deletions src/model_benchmark_zoo/cuboid.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from .utils import BaseCommonGeometryObject

class Cuboid:
def __init__(self, materials, width=10):
class Cuboid(BaseCommonGeometryObject):
def __init__(self, width=10):
self.width = width
self.materials = materials

def csg_model(self):
def csg_model(self, materials):
import openmc

surface = openmc.model.RectangularParallelepiped(
Expand All @@ -18,59 +18,16 @@ def csg_model(self):
)
region = -surface
cell = openmc.Cell(region=region)
cell.fill = self.materials[0]
cell.fill = materials[0]
geometry = openmc.Geometry([cell])
materials = openmc.Materials([self.materials[0]])
model = openmc.Model(geometry=geometry, materials=materials)
my_materials = openmc.Materials(materials)
model = openmc.Model(geometry=geometry, materials=my_materials)
return model

def cadquery_assembly(self):
import cadquery as cq
assembly = cq.Assembly(name="Cuboid")

assembly = cq.Assembly(name="cuboid")
Cuboid = cq.Workplane().box(self.width, self.width, self.width)
assembly.add(Cuboid)
return assembly

def export_stp_file(self, filename="Cuboid.step"):
self.cadquery_assembly().save(filename, "STEP")

def dagmc_model(self, filename="Cuboid.h5m", min_mesh_size=0.1, max_mesh_size=100.0):
from cad_to_dagmc import CadToDagmc
import openmc

assembly = self.cadquery_assembly()
ctd = CadToDagmc()
material_tags = [self.materials[0].name]
ctd.add_cadquery_object(assembly, material_tags=material_tags)
ctd.export_dagmc_h5m_file(
filename,
min_mesh_size=min_mesh_size,
max_mesh_size=max_mesh_size
)
universe = openmc.DAGMCUniverse(filename).bounded_universe()
geometry = openmc.Geometry(universe)
materials = openmc.Materials([self.materials[0]])
model = openmc.Model(geometry=geometry, materials=materials)
return model

def dagmc_model_with_cad_to_openmc(self, filename="Cuboid.h5m"):
from CAD_to_OpenMC import assembly
import openmc

self.export_stp_file()

a=assembly.Assembly(["Cuboid.step"])
a.verbose=0
assembly.mesher_config['threads']=1
a.run(
backend='stl2',
merge=True,
h5m_filename=filename,
sequential_tags=[self.materials[0].name],
scale=1.0
)

universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe()
geometry = openmc.Geometry(universe)
model = openmc.Model(geometry=geometry)
return model
60 changes: 8 additions & 52 deletions src/model_benchmark_zoo/cylinder.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

class Cylinder:
def __init__(self, materials, radius=1, height=100):
self.materials = materials
from .utils import BaseCommonGeometryObject
class Cylinder(BaseCommonGeometryObject):
def __init__(self, radius=1, height=100):
self.radius = radius
self.height = height

def csg_model(self):
def csg_model(self, materials):
import openmc

surface_1 = openmc.ZCylinder(x0=0.0, y0=0.0, r=self.radius, boundary_type="vacuum")
Expand All @@ -14,59 +13,16 @@ def csg_model(self):

region = -surface_1 & -surface_2 & +surface_3
cell = openmc.Cell(region=region)
cell.fill = self.materials[0]
materials = openmc.Materials([self.materials[0]])
cell.fill = materials[0]
my_materials = openmc.Materials(materials)
geometry = openmc.Geometry([cell])
model = openmc.Model(geometry=geometry, materials=materials)
model = openmc.Model(geometry=geometry, materials=my_materials)
return model

def cadquery_assembly(self):
import cadquery as cq

assembly = cq.Assembly(name="cylinder")
cylinder = cq.Workplane("XY", origin=(0, 0, 0)).circle(self.radius).extrude(self.height, both=True)
assembly.add(cylinder)
return assembly

def export_stp_file(self, filename="cylinder.step"):
self.cadquery_assembly().save(filename, "STEP")

def dagmc_model(self, filename="sphere.h5m", min_mesh_size=0.1, max_mesh_size=100.0):
from cad_to_dagmc import CadToDagmc
import openmc

assembly = self.cadquery_assembly()
ctd = CadToDagmc()
material_tags = [self.materials[0].name]
ctd.add_cadquery_object(assembly, material_tags=material_tags)
ctd.export_dagmc_h5m_file(
filename,
min_mesh_size=min_mesh_size,
max_mesh_size=max_mesh_size
)
universe = openmc.DAGMCUniverse(filename).bounded_universe()
materials = openmc.Materials([self.materials[0]])
geometry = openmc.Geometry(universe)
model = openmc.Model(geometry=geometry, materials=materials)
return model

def dagmc_model_with_cad_to_openmc(self, filename="cylinder.h5m"):
from CAD_to_OpenMC import assembly
import openmc

self.export_stp_file()

a=assembly.Assembly(["cylinder.step"])
a.verbose=0
assembly.mesher_config['threads']=1
a.run(
backend='stl2',
merge=True,
h5m_filename=filename,
sequential_tags=[self.materials[0].name],
scale=1.0
)

universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe()
geometry = openmc.Geometry(universe)
model = openmc.Model(geometry=geometry)
return model
Loading

0 comments on commit aee24f5

Please sign in to comment.