From be0be1e9864b29f25a5ac263a46e1c465c550d36 Mon Sep 17 00:00:00 2001 From: rowanc1 Date: Sun, 18 May 2014 16:09:47 -0700 Subject: [PATCH] curModel in problem and combo maps no longer takes a mesh. --- SimPEG/Maps.py | 6 +++--- SimPEG/Models.py | 2 ++ SimPEG/Problem.py | 19 ++++++++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/SimPEG/Maps.py b/SimPEG/Maps.py index 4333a617..dd7a9591 100644 --- a/SimPEG/Maps.py +++ b/SimPEG/Maps.py @@ -99,7 +99,7 @@ class IdentityMap(object): if isinstance(val, IdentityMap): if not self.shape[1] == val.shape[0]: raise ValueError('Dimension mismatch in %s and %s.' % (str(self), str(val))) - return ComboMap(self.mesh, [self, val]) + return ComboMap([self, val]) elif isinstance(val, np.ndarray): if not self.shape[1] == val.shape[0]: raise ValueError('Dimension mismatch in %s and np.ndarray%s.' % (str(self), str(val.shape))) @@ -112,8 +112,8 @@ class IdentityMap(object): class ComboMap(IdentityMap): """Combination of various maps.""" - def __init__(self, mesh, maps, **kwargs): - IdentityMap.__init__(self, mesh, **kwargs) + def __init__(self, maps, **kwargs): + IdentityMap.__init__(self, None, **kwargs) self.maps = [] for ii, m in enumerate(maps): diff --git a/SimPEG/Models.py b/SimPEG/Models.py index fdefc31d..583653be 100644 --- a/SimPEG/Models.py +++ b/SimPEG/Models.py @@ -6,6 +6,8 @@ class Model(np.ndarray): def __new__(cls, input_array, mapping=None): assert isinstance(mapping, IdentityMap), 'mapping must be a SimPEG.Mapping' + assert isinstance(input_array, np.ndarray), 'input_array must be a numpy array' + assert len(input_array.shape) == 1, 'input_array must be a 1D vector' obj = np.asarray(input_array).view(cls) obj._mapping = mapping if not obj.size == mapping.nP: diff --git a/SimPEG/Problem.py b/SimPEG/Problem.py index 7e69fcba..63fc9c1c 100644 --- a/SimPEG/Problem.py +++ b/SimPEG/Problem.py @@ -1,4 +1,4 @@ -import Utils, Survey, numpy as np, scipy.sparse as sp +import Utils, Survey, Models, numpy as np, scipy.sparse as sp import Maps, Mesh class BaseProblem(object): @@ -44,6 +44,23 @@ class BaseProblem(object): self.survey._prob = None self._survey = None + deleteTheseOnModelUpdate = [] # List of strings, e.g. ['_MeSigma', '_MeSigmaI'] + + @property + def curModel(self): + """ + Sets the current model, and removes dependent mass matrices. + """ + return getattr(self, '_curModel', None) + @curModel.setter + def curModel(self, value): + if value is self.curModel: + return # it is the same! + self._curModel = Models.Model(value, self.mapping) + for prop in self.deleteTheseOnModelUpdate: + if hasattr(self, prop): + delattr(self, prop) + @property def ispaired(self): """True if the problem is paired to a survey."""