[yt-svn] commit/yt: ngoldbaum: Merged in atmyers/yt (pull request #2402)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Jan 10 08:00:30 PST 2017


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/98bb0abc0b14/
Changeset:   98bb0abc0b14
Branch:      yt
User:        ngoldbaum
Date:        2017-01-10 16:00:03+00:00
Summary:     Merged in atmyers/yt (pull request #2402)

Some work towards 1D unstructured plotting support
Affected #:  7 files

diff -r 175a73a087238b633f6cc92f7f28d94878cd3217 -r 98bb0abc0b1421cba1c16df4ecca2ebd861d36d6 yt/frontends/exodus_ii/data_structures.py
--- a/yt/frontends/exodus_ii/data_structures.py
+++ b/yt/frontends/exodus_ii/data_structures.py
@@ -161,12 +161,6 @@
         self.default_field = [f for f in self.field_list 
                               if f[0] == 'connect1'][-1]
 
-        for mesh in self.index.meshes:
-            num_pseudo = get_num_pseudo_dims(mesh.connectivity_coords)
-            if (num_pseudo > 1 or self.dimensionality < 2):
-                raise RuntimeError("1D unstructured mesh data "
-                                   "are currently not supported.")
-
     def _set_code_unit_attributes(self):
         # This is where quantities are created that represent the various
         # on-disk units.  These are the currently available quantities which
@@ -194,12 +188,6 @@
         self.parameters['elem_names'] = self._get_elem_names()
         self.parameters['nod_names'] = self._get_nod_names()
         self.domain_left_edge, self.domain_right_edge = self._load_domain_edge()
-
-        # set up psuedo-3D for lodim datasets here
-        if self.dimensionality == 2:
-            self.domain_left_edge = np.append(self.domain_left_edge, 0.0)
-            self.domain_right_edge = np.append(self.domain_right_edge, 1.0)
-
         self.periodicity = (False, False, False)
 
         # These attributes don't really make sense for unstructured
@@ -370,6 +358,18 @@
         width = ma - mi
         mi -= 0.1 * width
         ma += 0.1 * width
+
+        # set up pseudo-3D for lodim datasets here
+        for _ in range(self.dimensionality, 3):
+            mi = np.append(mi, 0.0)
+            ma = np.append(ma, 1.0)
+
+        num_pseudo_dims = get_num_pseudo_dims(coords)
+        self.dimensionality -= num_pseudo_dims
+        for i in range(self.dimensionality, 3):
+            mi[i] = 0.0
+            ma[i] = 1.0
+        
         return mi, ma
 
     @classmethod

diff -r 175a73a087238b633f6cc92f7f28d94878cd3217 -r 98bb0abc0b1421cba1c16df4ecca2ebd861d36d6 yt/frontends/stream/data_structures.py
--- a/yt/frontends/stream/data_structures.py
+++ b/yt/frontends/stream/data_structures.py
@@ -1750,11 +1750,6 @@
     """
 
     dimensionality = coordinates.shape[1]
-    num_pseudo = get_num_pseudo_dims(coordinates)
-    if (num_pseudo > 1 or dimensionality < 2):
-        raise RuntimeError("1D unstructured mesh data "
-                           "are currently not supported.")
-
     domain_dimensions = np.ones(3, "int32") * 2
     nprocs = 1
 
@@ -1789,8 +1784,17 @@
                  coordinates[:,i].max() + 0.1 * abs(coordinates[:,i].max())]
                 for i in range(dimensionality)]
 
-    if dimensionality == 2:
+    if dimensionality < 3:
         bbox.append([0.0, 1.0])
+    if dimensionality < 2:
+        bbox.append([0.0, 1.0])
+
+    # handle pseudo-dims here
+    num_pseudo_dims = get_num_pseudo_dims(coordinates)
+    dimensionality -= num_pseudo_dims
+    for i in range(dimensionality, 3):
+        bbox[i][0] = 0.0
+        bbox[i][1] = 1.0
 
     bbox = np.array(bbox, dtype=np.float64)
     domain_left_edge = np.array(bbox[:, 0], 'float64')

diff -r 175a73a087238b633f6cc92f7f28d94878cd3217 -r 98bb0abc0b1421cba1c16df4ecca2ebd861d36d6 yt/utilities/lib/element_mappings.pxd
--- a/yt/utilities/lib/element_mappings.pxd
+++ b/yt/utilities/lib/element_mappings.pxd
@@ -33,6 +33,21 @@
     cdef int check_mesh_lines(self, double* mapped_coord) nogil
 
 
+cdef class P1Sampler1D(ElementSampler):
+
+    cdef void map_real_to_unit(self,
+                               double* mapped_x,
+                               double* vertices,
+                               double* physical_x) nogil
+
+
+    cdef double sample_at_unit_point(self,
+                                     double* coord,
+                                     double* vals) nogil
+
+    cdef int check_inside(self, double* mapped_coord) nogil
+
+
 cdef class P1Sampler2D(ElementSampler):
 
     cdef void map_real_to_unit(self,

diff -r 175a73a087238b633f6cc92f7f28d94878cd3217 -r 98bb0abc0b1421cba1c16df4ecca2ebd861d36d6 yt/utilities/lib/element_mappings.pyx
--- a/yt/utilities/lib/element_mappings.pyx
+++ b/yt/utilities/lib/element_mappings.pyx
@@ -115,6 +115,41 @@
         return val
 
 
+cdef class P1Sampler1D(ElementSampler):
+    '''
+
+    This implements sampling inside a linear, 1D element.
+
+    '''
+
+    def __init__(self):
+        super(P1Sampler1D, self).__init__()
+        self.num_mapped_coords = 1
+
+    @cython.boundscheck(False)
+    @cython.wraparound(False)
+    @cython.cdivision(True)
+    cdef void map_real_to_unit(self, double* mapped_x,
+                               double* vertices, double* physical_x) nogil:
+        mapped_x[0] = -1.0 + 2.0*(physical_x[0] - vertices[0]) / (vertices[1] - vertices[0])
+
+    @cython.boundscheck(False)
+    @cython.wraparound(False)
+    @cython.cdivision(True)
+    cdef double sample_at_unit_point(self,
+                                     double* coord,
+                                     double* vals) nogil:
+        return vals[0] * (1 - coord[0]) / 2.0 + vals[1] * (1.0 + coord[0]) / 2.0
+
+    @cython.boundscheck(False)
+    @cython.wraparound(False)
+    @cython.cdivision(True)
+    cdef int check_inside(self, double* mapped_coord) nogil:
+        if (fabs(mapped_coord[0]) - 1.0 > self.inclusion_tol):
+            return 0
+        return 1
+
+
 cdef class P1Sampler2D(ElementSampler):
     '''
 
@@ -1005,6 +1040,24 @@
 @cython.boundscheck(False)
 @cython.wraparound(False)
 @cython.cdivision(True)
+def test_linear1D_sampler(np.ndarray[np.float64_t, ndim=2] vertices,
+                          np.ndarray[np.float64_t, ndim=1] field_values,
+                          np.ndarray[np.float64_t, ndim=1] physical_x):
+
+    cdef double val
+
+    sampler = P1Sampler1D()
+
+    val = sampler.sample_at_real_point(<double*> vertices.data,
+                                       <double*> field_values.data,
+                                       <double*> physical_x.data)
+
+    return val
+
+
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+ at cython.cdivision(True)
 def test_tri_sampler(np.ndarray[np.float64_t, ndim=2] vertices,
                      np.ndarray[np.float64_t, ndim=1] field_values,
                      np.ndarray[np.float64_t, ndim=1] physical_x):

diff -r 175a73a087238b633f6cc92f7f28d94878cd3217 -r 98bb0abc0b1421cba1c16df4ecca2ebd861d36d6 yt/utilities/lib/pixelization_routines.pyx
--- a/yt/utilities/lib/pixelization_routines.pyx
+++ b/yt/utilities/lib/pixelization_routines.pyx
@@ -25,11 +25,12 @@
 from vec3_ops cimport dot, cross, subtract
 from yt.utilities.lib.element_mappings cimport \
     ElementSampler, \
+    P1Sampler1D, \
+    P1Sampler2D, \
     P1Sampler3D, \
     Q1Sampler3D, \
+    Q1Sampler2D, \
     S2Sampler3D, \
-    P1Sampler2D, \
-    Q1Sampler2D, \
     W1Sampler3D, \
     T2Sampler2D, \
     Tet2Sampler3D
@@ -604,6 +605,8 @@
         sampler = S2Sampler3D()
     elif ndim == 2 and nvertices == 3:
         sampler = P1Sampler2D()
+    elif ndim == 1 and nvertices == 2:
+        sampler = P1Sampler1D()
     elif ndim == 2 and nvertices == 4:
         sampler = Q1Sampler2D()
     elif ndim == 2 and nvertices == 6:
@@ -658,10 +661,13 @@
                 pstart[i] = i64max(<np.int64_t> ((LE[i] - pLE[i])*idds[i]) - 1, 0)
                 pend[i] = i64min(<np.int64_t> ((RE[i] - pLE[i])*idds[i]) + 1, img.shape[i]-1)
 
-            # override for the 2D case
-            if ndim == 2:
+            # override for the low-dimensional case
+            if ndim < 3:
                 pstart[2] = 0
                 pend[2] = 0
+            if ndim < 2:
+                pstart[1] = 0
+                pend[1] = 0
 
             if use == 0:
                 continue

diff -r 175a73a087238b633f6cc92f7f28d94878cd3217 -r 98bb0abc0b1421cba1c16df4ecca2ebd861d36d6 yt/utilities/lib/tests/test_element_mappings.py
--- a/yt/utilities/lib/tests/test_element_mappings.py
+++ b/yt/utilities/lib/tests/test_element_mappings.py
@@ -24,7 +24,8 @@
     test_hex20_sampler, \
     test_wedge_sampler, \
     test_tri2_sampler, \
-    test_tet2_sampler
+    test_tet2_sampler, \
+    test_linear1D_sampler
 
 
 def check_all_vertices(sampler, vertices, field_values):
@@ -37,6 +38,14 @@
         assert_almost_equal(val, field_values[i])
 
 
+def test_P1Sampler1D():
+
+    vertices = np.array([[0.1], [0.3]])
+    field_values = np.array([ 1.,  2.])
+
+    check_all_vertices(test_linear1D_sampler, vertices, field_values)
+
+
 def test_P1Sampler2D():
 
     vertices = np.array([[0.1, 0.2], [0.6, 0.3], [0.2, 0.7]])

diff -r 175a73a087238b633f6cc92f7f28d94878cd3217 -r 98bb0abc0b1421cba1c16df4ecca2ebd861d36d6 yt/visualization/profile_plotter.py
--- a/yt/visualization/profile_plotter.py
+++ b/yt/visualization/profile_plotter.py
@@ -234,7 +234,7 @@
             plot_spec = [plot_spec.copy() for p in profiles]
 
         ProfilePlot._initialize_instance(self, profiles, label, plot_spec, y_log)
-        
+
     @validate_plot
     def save(self, name=None, suffix=None, mpl_kwargs=None):
         r"""

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list