Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
- name: Run tests
run: |
python3 -m pytest test/ --cov openmc2dolfinx --cov-report xml --cov-report term

- name: Install curl for codecov
run: |
apt-get update && apt-get install -y curl

- name: Upload to codecov
uses: codecov/codecov-action@v5
Expand Down
21 changes: 12 additions & 9 deletions src/openmc2dolfinx/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class OpenMC2dolfinx(pyvista.VTKDataSetReader):
path: the path to the OpenMC .vtk file

Attributes:
data: the mesh and results from the OpenMC .vtk file
_data: the mesh and results from the OpenMC .vtk file
connectivity: The OpenMC mesh cell connectivity
dolfinx_mesh: the dolfinx mesh
"""

data: pyvista.core.pointset.UnstructuredGrid | pyvista.core.pointset.StructuredGrid
_data: pyvista.core.pointset.UnstructuredGrid | pyvista.core.pointset.StructuredGrid
connectivity: np.ndarray
dolfinx_mesh: dolfinx.mesh.Mesh = None

Expand All @@ -41,7 +41,7 @@ def create_dolfinx_mesh(self):
if not hasattr(self, "cell_type"):
raise AttributeError("cell_type must be defined in the child class")

self.data = self.read()
self._data = self.read()
if not hasattr(self, "cell_connectivity"):
raise AttributeError("cell_connectivity must be defined in the child class")

Expand All @@ -55,7 +55,10 @@ def create_dolfinx_mesh(self):
# Create dolfinx Mesh
mesh_ufl = ufl.Mesh(mesh_element)
self.dolfinx_mesh = create_mesh(
MPI.COMM_WORLD, self.cell_connectivity, self.data.points, mesh_ufl
comm=MPI.COMM_WORLD,
cells=self.cell_connectivity,
x=self._data.points,
e=mesh_ufl,
)

def create_dolfinx_function(self, data: str = "mean") -> dolfinx.fem.Function:
Expand All @@ -74,7 +77,7 @@ def create_dolfinx_function(self, data: str = "mean") -> dolfinx.fem.Function:
function_space = dolfinx.fem.functionspace(self.dolfinx_mesh, ("DG", 0))
u = dolfinx.fem.Function(function_space)

u.x.array[:] = self.data.cell_data[f"{data}"][
u.x.array[:] = self._data.cell_data[f"{data}"][
self.dolfinx_mesh.topology.original_cell_index
]

Expand All @@ -101,7 +104,7 @@ class UnstructuredMeshReader(OpenMC2dolfinx):

@property
def cell_connectivity(self):
return self.data.cells_dict[10]
return self._data.cells_dict[10]


class StructuredGridReader(OpenMC2dolfinx):
Expand All @@ -124,8 +127,8 @@ class StructuredGridReader(OpenMC2dolfinx):
_cell_connectivity = None

def get_connectivity(self):
num_cells = self.data.GetNumberOfCells()
assert self.data.GetCellType(0) == 12, "Only hexahedron cells are supported"
num_cells = self._data.GetNumberOfCells()
assert self._data.GetCellType(0) == 12, "Only hexahedron cells are supported"

# Extract connectivity information
ordering = [0, 1, 3, 2, 4, 5, 7, 6]
Expand All @@ -135,7 +138,7 @@ def get_connectivity(self):
# TODO numpify this
# Extract all cell connectivity data at once
for i in range(num_cells):
cell = self.data.GetCell(i) # Get the i-th cell
cell = self._data.GetCell(i) # Get the i-th cell
point_ids = [cell.GetPointId(j) for j in ordering] # Extract connectivity
self._cell_connectivity.append(point_ids)

Expand Down
Loading