Skip to content

Commit

Permalink
Merge pull request #3 from fusion-energy/adding_ci_for_Examples
Browse files Browse the repository at this point in the history
added examples ci
  • Loading branch information
shimwell authored Aug 4, 2022
2 parents 8966079 + b0d9f8b commit af3c5cc
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 33 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ci_with_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# This CI will launch a Docker image that contains all the dependencies required
# within that image the pytest test suite is run


name: CI with examples

on:
pull_request:
branches:
- develop
- main

jobs:
testing:
runs-on: ubuntu-latest
container:
image: continuumio/miniconda3
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: install package
run: |
pip install .
- name: install cadquery as needed by the examples
run: |
apt-get --allow-releaseinfo-change update
apt-get update -y
apt-get upgrade -y
apt-get install -y libgl1-mesa-glx libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libosmesa6 libosmesa6-dev libgles2-mesa-dev
conda install -c conda-forge mamba
mamba install -c conda-forge moab
conda install -c cadquery -c conda-forge cadquery=master
- name: Run examples
run: |
cd examples
python one_volume_cadquery_tesselation.py
python one_volume_mesh.py
python two_volume_mesh.py
39 changes: 18 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

[![CI with install](https://github.com/fusion-energy/vertices_to_h5m/actions/workflows/ci_with_install.yml/badge.svg)](https://github.com/fusion-energy/vertices_to_h5m/actions/workflows/ci_with_install.yml)

[![CI with examples](https://github.com/fusion-energy/vertices_to_h5m/actions/workflows/ci_with_examples.yml/badge.svg)](https://github.com/fusion-energy/vertices_to_h5m/actions/workflows/ci_with_examples.yml)

[![Upload Python Package](https://github.com/fusion-energy/vertices_to_h5m/actions/workflows/python-publish.yml/badge.svg)](https://github.com/fusion-energy/vertices_to_h5m/actions/workflows/python-publish.yml)
[![anaconda-publish](https://github.com/fusion-energy/vertices_to_h5m/actions/workflows/anaconda-publish.yml/badge.svg)](https://github.com/fusion-energy/vertices_to_h5m/actions/workflows/anaconda-publish.yml)

Expand Down Expand Up @@ -52,28 +54,30 @@ material tag mat1.

```python
from vertices_to_h5m import vertices_to_h5m
import numpy as np

# these are the x,y,z coordinates of each vertex. Entries should be floats
vertices = np.array([
[0., 0., 0.],
[1., 0., 0].,
[0., 1., 0.],
[0., 0., 1.]
])
vertices = np.array(
[
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
]
)


# These are the triangle that connect individual vertices together to form a continious surface and also a closed volume. Entries should be ints
triangles = np.array([
[0, 1, 2],
[3, 1, 2],
[0, 2, 3],
[0, 1, 3]
])
triangles = [
np.array([[0, 1, 2], [3, 1, 2], [0, 2, 3], [0, 1, 3]]),
]


# This will produce a h5m file called one_volume.h5m ready for use with DAGMC enabled codes.
vertices_to_h5m(
vertices=vertices,
triangles=triangles,
material_tags=["mat1", "mat2"],
material_tags=["mat1"],
h5m_filename="one_volume.h5m",
)
```
Expand All @@ -90,14 +94,7 @@ import numpy as np

# These are the x,y,z coordinates of each vertex. Numpy array is set to type float to enforce floats
vertices = np.array(
[
[0, 0, 0],
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
[1, 1, 1],
[1, 1, 0]
], dtype="float64"
[[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 1, 1], [1, 1, 0]], dtype="float64"
)

# These are the two sets triangle that connect individual vertices together to form a continious surfaces and also two closed volume.
Expand Down
2 changes: 2 additions & 0 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ test:
- trimesh
- networkx
- dagmc_h5m_file_inspector [not win]
- openmc
- scipy # trimesh makes use of scipy to fix normals in some cases
source_files:
- tests/
commands:
Expand Down
9 changes: 6 additions & 3 deletions examples/one_volume_cadquery_tesselation.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import cadquery as cq
import os
from vertices_to_h5m import vertices_to_h5m

result = cq.Workplane("front").box(2.0, 2.0, 0.5)

# the inbuild cadquery tessellate does not quite do what is needed for multi
# parts geometry but work for single part geometry.
# The cad_to_dagmc package will provide a modified tessellate function in the future
vertices, triangles = result.val().tessellate(tolerance=0.1)

vertices_to_h5m(
vertices=vertices,
triangles=triangles,
triangles=[triangles],
material_tags=["mat1"],
h5m_filename="one_cadquery_volume.h5m",
)

import os

os.system("mbconvert one_cadquery_volume.h5m one_cadquery_volume.vtk")
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ python_requires= >=3.6
install_requires=
trimesh
networkx
scipy # trimesh makes use of scipy to fix normals in some cases
# moab is also not available on pypi but can be installed with conda

[options.extras_require]
tests =
pytest >= 5.4.3
dagmc_h5m_file_inspector # requires moab which can be installed with conda
openmc_data_downloader
# openmc is also needed but not available via pip

[flake8]
per-file-ignores = __init__.py:F401
8 changes: 3 additions & 5 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@


def transport_particles_on_h5m_geometry(
h5m_filename,
material_tags,
h5m_filename, material_tags, cross_sections_xml=None
):
"""A function for testing the geometry file with particle transport in DAGMC OpenMC"""

Expand All @@ -31,9 +30,8 @@ def transport_particles_on_h5m_geometry(

materials.append(mat_dag_material_tag)

materials.cross_sections = (
"/home/jshim/brep_to_h5m/examples/h5m_from_coords/cross_sections.xml"
)
if cross_sections_xml:
materials.cross_sections = cross_sections_xml
# downloads the nuclear data and sets the openmc_cross_sections environmental variable
odd.just_in_time_library_generator(libraries="ENDFB-7.1-NNDC", materials=materials)

Expand Down
33 changes: 29 additions & 4 deletions vertices_to_h5m/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterable, Tuple
from typing import Iterable, Tuple, Union

import numpy as np
import trimesh
Expand Down Expand Up @@ -148,17 +148,42 @@ def add_triangles_to_moab_core(


def vertices_to_h5m(
vertices: Iterable[Tuple[float, float, float]],
vertices: Union[
Iterable[Tuple[float, float, float]], Iterable["cadquery.occ_impl.geom.Vector"]
],
triangles: Iterable[Tuple[int, int, int]],
material_tags: Iterable[str],
h5m_filename="dagmc.h5m",
):
"""Converts vertices and triangle sets into a tagged h5m file compatible
with DAGMC enabled neutronics simulations
Args:
vertices:
triangles:
material_tags:
h5m_filename:
"""

if len(material_tags) != len(triangles):
msg = f"The number of material_tags provided is {len(material_tags)} and the number of sets of triangles is {len(triangles)}. You must provide one material_tag for every triangle set"
raise ValueError(msg)

triangles = fix_normals(vertices=vertices, triangles_in_each_volume=triangles)
# limited attribute checking to see if user passed in a list of CadQuery vectors
if (
hasattr(vertices[0], "x")
and hasattr(vertices[0], "y")
and hasattr(vertices[0], "z")
):
vertices_floats = []
for vert in vertices:
vertices_floats.append((vert.x, vert.y, vert.z))
else:
vertices_floats = vertices

triangles = fix_normals(
vertices=vertices_floats, triangles_in_each_volume=triangles
)

moab_core, tags = _define_moab_core_and_tags()

Expand All @@ -168,7 +193,7 @@ def vertices_to_h5m(
)

moab_core, moab_verts = add_vertices_to_moab_core(
moab_core, vertices, surface_set
moab_core, vertices_floats, surface_set
)

moab_core = add_triangles_to_moab_core(
Expand Down

0 comments on commit af3c5cc

Please sign in to comment.