From 6fbe3a616ba61c3a44eb1e9ac4cf2c56e111ad07 Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Wed, 13 Nov 2013 15:52:56 -0800 Subject: [PATCH] Added shortcut to making a TensorMesh on a unit cube: mesh = TensorMesh([10, 12, 15]) --- SimPEG/mesh/TensorMesh.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/SimPEG/mesh/TensorMesh.py b/SimPEG/mesh/TensorMesh.py index 90f8fd10..30eebc13 100644 --- a/SimPEG/mesh/TensorMesh.py +++ b/SimPEG/mesh/TensorMesh.py @@ -26,18 +26,25 @@ class TensorMesh(BaseMesh, TensorView, DiffOperators, InnerProducts): .. plot:: examples/mesh/plot_TensorMesh.py + For a quick tensor mesh on a (10x12x15) unit cube:: + + mesh = TensorMesh([10, 12, 15]) + """ _meshType = 'TENSOR' def __init__(self, h, x0=None): - super(TensorMesh, self).__init__(np.array([x.size for x in h]), x0) - - assert len(h) == len(self.x0), "Dimension mismatch. x0 != len(h)" - for i, h_i in enumerate(h): + if type(h_i) in [int, long, float]: + # This gives you something over the unit cube. + h_i = np.ones(int(h_i))/int(h_i) + h[i] = h_i assert type(h_i) == np.ndarray, ("h[%i] is not a numpy array." % i) assert len(h_i.shape) == 1, ("h[%i] must be a 1D numpy array." % i) + BaseMesh.__init__(self, np.array([x.size for x in h]), x0) + assert len(h) == len(self.x0), "Dimension mismatch. x0 != len(h)" + # Ensure h contains 1D vectors self._h = [mkvc(x.astype(float)) for x in h]