From d6210072cd44f168bc25084dd44b80f6f2c2f278 Mon Sep 17 00:00:00 2001 From: rowanc1 Date: Fri, 2 May 2014 15:05:31 -0700 Subject: [PATCH] Raise exceptions when trying to interpolate fields that don't exist in the CylMesh --- SimPEG/Mesh/TensorMesh.py | 2 ++ SimPEG/Tests/test_interpolation.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/SimPEG/Mesh/TensorMesh.py b/SimPEG/Mesh/TensorMesh.py index 1a5bba66..2dff9b0a 100644 --- a/SimPEG/Mesh/TensorMesh.py +++ b/SimPEG/Mesh/TensorMesh.py @@ -229,6 +229,8 @@ class BaseTensorMesh(BaseRectangularMesh): 'N' -> scalar field defined on nodes 'CC' -> scalar field defined on cell centers """ + if self._meshType == 'CYL' and self.isSymmetric and locType in ['Ex','Ez','Fy']: + raise Exception('Symmetric CylMesh does not support %s interpolation, as this variable does not exist.' % locType) loc = Utils.asArray_N_x_Dim(loc, self.dim) diff --git a/SimPEG/Tests/test_interpolation.py b/SimPEG/Tests/test_interpolation.py index 6eb7ba70..7eb2050e 100644 --- a/SimPEG/Tests/test_interpolation.py +++ b/SimPEG/Tests/test_interpolation.py @@ -144,6 +144,12 @@ class TestInterpolation2dCyl_Simple(unittest.TestCase): fz = np.array([[ 0., 0., 0., 0., 0.5, 0., 0., 0., 0.5, 0., 0., 0.]]) self.assertTrue( np.all(fz == M.getInterpolationMat(locs, 'Fz').todense()) ) + def test_exceptions(self): + M = Mesh.CylMesh([4,1,1]) + locs = np.r_[0,0,0.5] + self.assertRaises(Exception,lambda:M.getInterpolationMat(locs, 'Fy')) + self.assertRaises(Exception,lambda:M.getInterpolationMat(locs, 'Ex')) + self.assertRaises(Exception,lambda:M.getInterpolationMat(locs, 'Ez')) class TestInterpolation2dCyl(OrderTest):