def backModel(self, value): if value is self.backModel: return # it is the same! self._backModel = Models.Model(value, self.mapping) for prop in self.deleteTheseOnModelUpdate: if hasattr(self, prop): delattr(self, prop)
def test_mapMultiplication(self): M = Mesh.TensorMesh([2, 3]) expMap = Maps.ExpMap(M) vertMap = Maps.SurjectVertical1D(M) combo = expMap * vertMap m = np.arange(3.0) t_true = np.exp(np.r_[0, 0, 1, 1, 2, 2.]) self.assertLess(np.linalg.norm((combo * m) - t_true, np.inf), TOL) self.assertLess( np.linalg.norm((expMap * vertMap * m) - t_true, np.inf), TOL) self.assertLess( np.linalg.norm(expMap * (vertMap * m) - t_true, np.inf), TOL) self.assertLess( np.linalg.norm((expMap * vertMap) * m - t_true, np.inf), TOL) # Try making a model mod = Models.Model(m, mapping=combo) # print mod.transform # import matplotlib.pyplot as plt # plt.colorbar(M.plotImage(mod.transform)[0]) # plt.show() self.assertLess(np.linalg.norm(mod.transform - t_true, np.inf), TOL) self.assertRaises(Exception, Models.Model, np.r_[1.0], mapping=combo) self.assertRaises(ValueError, lambda: combo * (vertMap * expMap)) self.assertRaises(ValueError, lambda: (combo * vertMap) * expMap) self.assertRaises(ValueError, lambda: vertMap * expMap) self.assertRaises(ValueError, lambda: expMap * np.ones(100)) self.assertRaises(ValueError, lambda: expMap * np.ones((100, 1))) self.assertRaises(ValueError, lambda: expMap * np.ones((100, 5))) self.assertRaises(ValueError, lambda: combo * np.ones(100)) self.assertRaises(ValueError, lambda: combo * np.ones((100, 1))) self.assertRaises(ValueError, lambda: combo * np.ones((100, 5)))
def test_activeCells(self): M = Mesh.TensorMesh([2, 4], '0C') for actMap in [Maps.InjectActiveCells(M, M.vectorCCy <= 0, 10, nC=M.nCy), Maps.ActiveCells(M, M.vectorCCy <= 0, 10, nC=M.nCy)]: vertMap = Maps.SurjectVertical1D(M) combo = vertMap * actMap m = np.r_[1., 2.] mod = Models.Model(m, combo) self.assertLess(np.linalg.norm(mod.transform - np.r_[1, 1, 2, 2, 10, 10, 10, 10.]), TOL) self.assertLess((mod.transformDeriv - combo.deriv(m)).toarray().sum(), TOL)
def test_activeCells(self): M = Mesh.TensorMesh([2, 4], '0C') expMap = Maps.ExpMap(M) for actMap in [ Maps.InjectActiveCells(M, M.vectorCCy <= 0, 10, nC=M.nCy), Maps.ActiveCells(M, M.vectorCCy <= 0, 10, nC=M.nCy) ]: # actMap = Maps.InjectActiveCells(M, M.vectorCCy <=0, 10, nC=M.nCy) vertMap = Maps.SurjectVertical1D(M) combo = vertMap * actMap m = np.r_[1, 2.] mod = Models.Model(m, combo) # import matplotlib.pyplot as plt # plt.colorbar(M.plotImage(mod.transform)[0]) # plt.show() self.assertLess( np.linalg.norm(mod.transform - np.r_[1, 1, 2, 2, 10, 10, 10, 10.]), TOL) self.assertLess( (mod.transformDeriv - combo.deriv(m)).toarray().sum(), TOL)