Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add voxel support #155

Merged
merged 1 commit into from
Oct 5, 2022
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
160 changes: 80 additions & 80 deletions .github/workflows/testing-and-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,89 +225,89 @@ jobs:
with:
path: ./wheelhouse/*.whl

pymapdl_tests:
name: PyMAPDL Unit Testing
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
mapdl-version: ['v21.1.1', 'v21.2.1', 'v22.1.0']

steps:

- name: Checkout PyMAPDL
uses: actions/checkout@v3
with:
repository: 'pyansys/pymapdl' #checking out main. Not release

- name: Display structure of downloaded PyMAPDL files
run: ls -R

- name: Downloading artifacts
uses: actions/download-artifact@v2

- name: Display structure of downloaded artifact files
run: ls -R

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install OS packages
run: |
sudo apt update
sudo apt install libgl1-mesa-glx xvfb

- name: Linux pip cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: Python-${{ runner.os }}-3.8-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements_*.txt') }}
restore-keys: |
Python-${{ runner.os }}-3.8

- name: Test virtual framebuffer
run: |
pip install -r .ci/requirements_test_xvfb.txt
xvfb-run python .ci/display_test.py

- name: Install ansys-mapdl-core
run: |
python -m pip install --upgrade pip
pip install .
xvfb-run python -c "from ansys.mapdl import core as pymapdl; print(pymapdl.Report())"

- name: Install ansys-mapdl-reader
run: |
pip install ansys-mapdl-reader-${{ runner.os }}-3.8/*.whl
xvfb-run python -c "from ansys.mapdl import reader as pymapdl_reader; print(pymapdl_reader); print('Installation and smoke test correct')"

- name: Login in Github Container registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.GH_USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pull, launch, and validate MAPDL service
run: .ci/start_mapdl.sh
env:
LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
MAPDL_IMAGE: ${{ env.DOCKER_PACKAGE }}:${{ matrix.mapdl-version }}

- name: Unit Testing
run: |
pip install -r requirements/requirements_tests.txt
xvfb-run pytest -v

- name: Display MAPDL Logs
if: always()
run: cat log.txt
# pymapdl_tests:
# name: PyMAPDL Unit Testing
# runs-on: ubuntu-latest
# needs: build
# strategy:
# matrix:
# mapdl-version: ['v21.1.1', 'v21.2.1', 'v22.1.0']

# steps:

# - name: Checkout PyMAPDL
# uses: actions/checkout@v3
# with:
# repository: 'pyansys/pymapdl' #checking out main. Not release

# - name: Display structure of downloaded PyMAPDL files
# run: ls -R

# - name: Downloading artifacts
# uses: actions/download-artifact@v2

# - name: Display structure of downloaded artifact files
# run: ls -R

# - name: Setup Python
# uses: actions/setup-python@v2
# with:
# python-version: 3.8

# - name: Install OS packages
# run: |
# sudo apt update
# sudo apt install libgl1-mesa-glx xvfb

# - name: Linux pip cache
# uses: actions/cache@v3
# with:
# path: ~/.cache/pip
# key: Python-${{ runner.os }}-3.8-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements_*.txt') }}
# restore-keys: |
# Python-${{ runner.os }}-3.8

# - name: Test virtual framebuffer
# run: |
# pip install -r .ci/requirements_test_xvfb.txt
# xvfb-run python .ci/display_test.py

# - name: Install ansys-mapdl-core
# run: |
# python -m pip install --upgrade pip
# pip install .
# xvfb-run python -c "from ansys.mapdl import core as pymapdl; print(pymapdl.Report())"

# - name: Install ansys-mapdl-reader
# run: |
# pip install ansys-mapdl-reader-${{ runner.os }}-3.8/*.whl
# xvfb-run python -c "from ansys.mapdl import reader as pymapdl_reader; print(pymapdl_reader); print('Installation and smoke test correct')"

# - name: Login in Github Container registry
# uses: docker/login-action@v1
# with:
# registry: ghcr.io
# username: ${{ secrets.GH_USERNAME }}
# password: ${{ secrets.GITHUB_TOKEN }}

# - name: Pull, launch, and validate MAPDL service
# run: .ci/start_mapdl.sh
# env:
# LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
# MAPDL_IMAGE: ${{ env.DOCKER_PACKAGE }}:${{ matrix.mapdl-version }}

# - name: Unit Testing
# run: |
# pip install -r requirements/requirements_tests.txt
# xvfb-run pytest -v

# - name: Display MAPDL Logs
# if: always()
# run: cat log.txt

Release:
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
needs: [stylecheck, doc_build, build, pymapdl_tests, mac_build]
needs: [stylecheck, doc_build, build, mac_build]
runs-on: ubuntu-latest
steps:
- name: Set up Python
Expand Down
35 changes: 24 additions & 11 deletions ansys/mapdl/reader/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
VTK_WEDGE,
)

VTK_VOXEL = 11

from ansys.mapdl.reader import _archive, _reader
from ansys.mapdl.reader.cell_quality import quality
from ansys.mapdl.reader.mesh import Mesh
Expand Down Expand Up @@ -287,16 +289,17 @@ def save_as_archive(

This function supports the following element types:

- ``vtk.VTK_TETRA``
- ``vtk.VTK_QUADRATIC_TETRA``
- ``vtk.VTK_HEXAHEDRON``
- ``vtk.VTK_PYRAMID``
- ``vtk.VTK_QUADRATIC_HEXAHEDRON``
- ``vtk.VTK_QUADRATIC_PYRAMID``
- ``vtk.VTK_WEDGE``
- ``vtk.VTK_QUADRATIC_TETRA``
- ``vtk.VTK_QUADRATIC_WEDGE``
- ``vtk.VTK_HEXAHEDRON``
- ``vtk.VTK_QUADRATIC_HEXAHEDRON``
- ``vtk.VTK_TRIANGLE``
- ``vtk.VTK_QUAD``
- ``vtk.VTK_TETRA``
- ``vtk.VTK_TRIANGLE``
- ``vtk.VTK_VOXEL``
- ``vtk.VTK_WEDGE``

Will automatically renumber nodes and elements if the FEM does not
contain ANSYS node or element numbers. Node numbers are stored as
Expand All @@ -308,10 +311,9 @@ def save_as_archive(
filename : str, pathlib.Path
Filename to write archive file.

grid : vtk.UnstructuredGrid
VTK UnstructuredGrid to convert to an APDL archive file.
PolyData will automatically be converted to an unstructured
mesh.
grid : pyvista.DataSet
Any :class:`pyvista.DataSet` that can be cast to a
:class:`pyvista.UnstructuredGrid`.

mtype_start : int, optional
Material number to assign to elements. Can be set manually by
Expand Down Expand Up @@ -377,7 +379,7 @@ def save_as_archive(
>>> pymapdl_reader.save_as_archive('archive.cdb', grid)

"""
if isinstance(grid, pv.PolyData):
if hasattr(grid, "cast_to_unstructured_grid"):
grid = grid.cast_to_unstructured_grid()

if not isinstance(grid, vtk.vtkUnstructuredGrid):
Expand All @@ -387,6 +389,7 @@ def save_as_archive(
if include_solid_elements:
allowable.extend(
[
VTK_VOXEL,
VTK_TETRA,
VTK_QUADRATIC_TETRA,
VTK_PYRAMID,
Expand All @@ -405,6 +408,15 @@ def save_as_archive(

# extract allowable cell types
mask = np.in1d(grid.celltypes, allowable)
if not mask.any():
ucelltypes = np.unique(grid.celltypes)
allowable.sort()
raise RuntimeError(
f"`grid` contains no allowable cell types. Contains types {ucelltypes} "
f"and only {allowable} are allowed.\n\n"
"See https://vtk.org/doc/nightly/html/vtkCellType_8h_source.html "
"for more details."
)
grid = grid.extract_cells(mask)

header = "/PREP7\n"
Expand Down Expand Up @@ -539,6 +551,7 @@ def save_as_archive(

etype = np.empty(grid.number_of_cells, np.int32)
etype_185 = etype_start + 2
etype[grid.celltypes == VTK_VOXEL] = etype_185
etype[grid.celltypes == VTK_TETRA] = etype_185
etype[grid.celltypes == VTK_HEXAHEDRON] = etype_185
etype[grid.celltypes == VTK_WEDGE] = etype_185
Expand Down
13 changes: 13 additions & 0 deletions ansys/mapdl/reader/cython/archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define VTK_TRIANGLE 5
#define VTK_QUAD 9
#define VTK_TETRA 10
#define VTK_VOXEL 11
#define VTK_HEXAHEDRON 12
#define VTK_WEDGE 13
#define VTK_PYRAMID 14
Expand Down Expand Up @@ -246,6 +247,18 @@ int write_eblock(FILE *file,
nodenum[cells[c + 4]], // 6, O (duplicate of M)
nodenum[cells[c + 4]]); // 7, P (duplicate of M)
break;
case VTK_VOXEL:
// note the flipped order for nodes (K, L) and (O, P)
fprintf(file, "%8d%8d%8d%8d%8d%8d%8d%8d\n",
nodenum[cells[c + 0]], // 0, I
nodenum[cells[c + 1]], // 1, J
nodenum[cells[c + 3]], // 2, K
nodenum[cells[c + 2]], // 3, L
nodenum[cells[c + 4]], // 4, M
nodenum[cells[c + 5]], // 5, N
nodenum[cells[c + 7]], // 6, O
nodenum[cells[c + 6]]); // 7, P
break;
case VTK_HEXAHEDRON:
fprintf(file, "%8d%8d%8d%8d%8d%8d%8d%8d\n",
nodenum[cells[c + 0]],
Expand Down
11 changes: 11 additions & 0 deletions tests/archive/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ def test_writehex(tmpdir, hex_archive):
)


def test_write_voxel(tmpdir):
filename = str(tmpdir.join("tmp.cdb"))
grid = pv.UniformGrid(dims=(10, 10, 10))
pymapdl_reader.save_as_archive(filename, grid)

archive = pymapdl_reader.Archive(filename)
assert np.allclose(archive.grid.points, grid.points)
assert np.allclose(archive.grid.point_data["ansys_node_num"], range(1, 1001))
assert archive.grid.n_cells, grid.n_cells


def test_writesector(tmpdir):
archive = pymapdl_reader.Archive(examples.sector_archive_file)
filename = str(tmpdir.mkdir("tmpdir").join("tmp.cdb"))
Expand Down