Skip to content

Commit e781cba

Browse files
committed
added linear cell quality check
1 parent 18ca9e0 commit e781cba

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

pyansys/cellquality.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
Cell quality module
33
"""
44
import ctypes
5-
from pyansys import _cellqual
5+
import numpy as np
6+
7+
from pyansys import _cellqual, _cellqualfloat
68

79

810
def CellQuality(grid):
@@ -20,6 +22,14 @@ def CellQuality(grid):
2022
"""
2123
# Get cells and points from grid
2224
cells = grid.GetNumpyCells(ctypes.c_long)
23-
points = grid.GetNumpyPoints(ctypes.c_double)
25+
points = grid.points
26+
if not points.flags.c_contiguous:
27+
points = np.ascontiguousarray(points)
2428

25-
return _cellqual.CompScJac_quad(cells, points)
29+
if points.dtype == ctypes.c_float:
30+
return _cellqualfloat.CompScJac_quad(cells, points)
31+
elif points.dtype == ctypes.c_double:
32+
return _cellqual.CompScJac_quad(cells, points)
33+
else:
34+
raise Exception('Invalid point precision %s. ' % points.dtype +
35+
'Must be either float or double')

pyansys/cython/_cellqual.pyx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
# cython imports
88
import numpy as np
99
cimport numpy as np
10-
from libc.math cimport sqrt, fabs
11-
from numpy.math cimport INFINITY
10+
from libc.math cimport sqrt
1211
import ctypes
1312

1413

@@ -2398,4 +2397,3 @@ def CompScJac_quad(long [::1] cellarr, double [:, ::1] pts):
23982397
cnum += 1
23992398

24002399
return np.asarray(jacs)[:cnum]
2401-

setup.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from io import open as io_open
77

88
from setuptools import setup, Extension
9-
#from setuptools.command.build_ext import build_ext
10-
119
from setuptools.command.build_ext import build_ext as _build_ext
12-
# Create a build class that includes numpy directory
10+
11+
1312
class build_ext(_build_ext):
13+
""" build class that includes numpy directory """
1414
def finalize_options(self):
1515
_build_ext.finalize_options(self)
1616
# Prevent numpy from thinking it is still in its setup process:
@@ -123,6 +123,12 @@ def compilerName():
123123
extra_compile_args=cmp_arg,
124124
language='c'),
125125

126+
# cell quality module
127+
Extension("pyansys._cellqualfloat",
128+
["pyansys/cython/_cellqualfloat.pyx"],
129+
extra_compile_args=cmp_arg,
130+
language='c'),
131+
126132
Extension("pyansys._rstHelper",
127133
["pyansys/cython/_rstHelper.pyx"],
128134
extra_compile_args=cmp_arg,

0 commit comments

Comments
 (0)