mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-08 07:15:03 +08:00
updates to problem
This commit is contained in:
+14
-14
@@ -68,8 +68,8 @@ class IdentityMap(object):
|
||||
|
||||
def _assertMatchesPair(self, pair):
|
||||
assert (isinstance(self, pair) or
|
||||
isinstance(self, ComboMap) and isinstance(self.models[0], pair)
|
||||
), "Model object must be an instance of a %s class."%(pair.__name__)
|
||||
isinstance(self, ComboMap) and isinstance(self.maps[0], pair)
|
||||
), "Mapping object must be an instance of a %s class."%(pair.__name__)
|
||||
|
||||
class NonLinearMap(object):
|
||||
"""
|
||||
@@ -335,17 +335,17 @@ class ActiveCells(IdentityMap):
|
||||
return self.P
|
||||
|
||||
class ComboMap(IdentityMap):
|
||||
"""Combination of various models."""
|
||||
"""Combination of various maps."""
|
||||
|
||||
def __init__(self, mesh, models, **kwargs):
|
||||
def __init__(self, mesh, maps, **kwargs):
|
||||
IdentityMap.__init__(self, mesh, **kwargs)
|
||||
|
||||
self.models = []
|
||||
for m in models:
|
||||
self.maps = []
|
||||
for m in maps:
|
||||
if not isinstance(m, IdentityMap):
|
||||
self.models += [m(mesh, **kwargs)]
|
||||
self.maps += [m(mesh, **kwargs)]
|
||||
else:
|
||||
self.models += [m]
|
||||
self.maps += [m]
|
||||
|
||||
@property
|
||||
def nP(self):
|
||||
@@ -353,19 +353,19 @@ class ComboMap(IdentityMap):
|
||||
|
||||
The number of cells in the
|
||||
last dimension of the mesh."""
|
||||
return self.models[-1].nP
|
||||
return self.maps[-1].nP
|
||||
|
||||
def transform(self, m):
|
||||
for model in reversed(self.models):
|
||||
m = model.transform(m)
|
||||
for map_i in reversed(self.maps):
|
||||
m = map_i.transform(m)
|
||||
return m
|
||||
|
||||
def transformDeriv(self, m):
|
||||
deriv = 1
|
||||
mi = m
|
||||
for model in reversed(self.models):
|
||||
deriv = model.transformDeriv(mi) * deriv
|
||||
mi = model.transform(mi)
|
||||
for map_i in reversed(self.maps):
|
||||
deriv = map_i.transformDeriv(mi) * deriv
|
||||
mi = map_i.transform(mi)
|
||||
return deriv
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
+2
-1
@@ -1,5 +1,5 @@
|
||||
import Utils, Survey, numpy as np, scipy.sparse as sp
|
||||
import Maps
|
||||
import Maps, Mesh
|
||||
|
||||
class BaseProblem(object):
|
||||
"""
|
||||
@@ -18,6 +18,7 @@ class BaseProblem(object):
|
||||
|
||||
def __init__(self, mesh, mapping=None, **kwargs):
|
||||
Utils.setKwargs(self, **kwargs)
|
||||
assert isinstance(mesh, Mesh.BaseMesh), "mesh must be a SimPEG.Mesh object."
|
||||
self.mesh = mesh
|
||||
self.mapping = mapping or Maps.IdentityMap(mesh)
|
||||
self.mapping._assertMatchesPair(self.mapPair)
|
||||
|
||||
@@ -14,24 +14,24 @@ class MapTests(unittest.TestCase):
|
||||
self.mesh2 = Mesh.TensorMesh([a, b], x0=np.array([3, 5]))
|
||||
self.mesh22 = Mesh.TensorMesh([b, a], x0=np.array([3, 5]))
|
||||
|
||||
def test_modelTransforms(self):
|
||||
def test_transforms(self):
|
||||
for M in dir(Maps):
|
||||
try:
|
||||
model = getattr(Maps, M)(self.mesh2)
|
||||
assert isinstance(model, Maps.BaseModel)
|
||||
maps = getattr(Maps, M)(self.mesh2)
|
||||
assert isinstance(maps, Maps.BaseModel)
|
||||
except Exception, e:
|
||||
continue
|
||||
self.assertTrue(model.test())
|
||||
self.assertTrue(maps.test())
|
||||
|
||||
def test_Mesh2MeshMap(self):
|
||||
model = Maps.Mesh2Mesh([self.mesh22, self.mesh2])
|
||||
self.assertTrue(model.test())
|
||||
maps = Maps.Mesh2Mesh([self.mesh22, self.mesh2])
|
||||
self.assertTrue(maps.test())
|
||||
|
||||
def test_comboMaps(self):
|
||||
combos = [(Maps.ExpMap, Maps.Vertical1DMap)]
|
||||
for combo in combos:
|
||||
model = Maps.ComboMap(self.mesh2, combo)
|
||||
self.assertTrue(model.test())
|
||||
maps = Maps.ComboMap(self.mesh2, combo)
|
||||
self.assertTrue(maps.test())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user