mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-15 11:26:09 +08:00
Model that allows interpolation from one mesh to another.
This commit is contained in:
@@ -174,6 +174,56 @@ class Vertical1DModel(BaseModel):
|
||||
), shape=(repNum, 1))
|
||||
return sp.kron(sp.identity(self.nP), repVec)
|
||||
|
||||
class Mesh2Mesh(BaseModel):
|
||||
"""
|
||||
Takes a model on one mesh are translates it to another mesh.
|
||||
|
||||
.. plot::
|
||||
|
||||
from SimPEG import *
|
||||
M = Mesh.TensorMesh([100,100])
|
||||
h1 = Utils.meshTensors(((7,6,1.5),(10,6),(7,6,1.5)))
|
||||
h1 = h1/h1.sum()
|
||||
M2 = Mesh.TensorMesh([h1,h1])
|
||||
V = Utils.ModelBuilder.randomModel(M.vnC, seed=79, its=50)
|
||||
v = Utils.mkvc(V)
|
||||
modh = Model.Mesh2Mesh([M,M2])
|
||||
modH = Model.Mesh2Mesh([M2,M])
|
||||
H = modH.transform(v)
|
||||
h = modh.transform(H)
|
||||
ax = plt.subplot(131)
|
||||
M.plotImage(v, ax=ax)
|
||||
ax.set_title('Fine Mesh (Original)')
|
||||
ax = plt.subplot(132)
|
||||
M2.plotImage(H,clim=[0,1],ax=ax)
|
||||
ax.set_title('Course Mesh')
|
||||
ax = plt.subplot(133)
|
||||
M.plotImage(h,clim=[0,1],ax=ax)
|
||||
ax.set_title('Fine Mesh (Interpolated)')
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, meshes, **kwargs):
|
||||
Utils.setKwargs(self, **kwargs)
|
||||
|
||||
assert type(meshes) is list, "meshes must be a list of two meshes"
|
||||
assert len(meshes) == 2, "meshes must be a list of two meshes"
|
||||
assert meshes[0].dim == meshes[1].dim, """The two meshes must be the same dimension"""
|
||||
|
||||
self.mesh = meshes[0]
|
||||
self.mesh2 = meshes[1]
|
||||
|
||||
self.P = self.mesh2.getInterpolationMat(self.mesh.gridCC,'CC',zerosOutside=True)
|
||||
|
||||
@property
|
||||
def nP(self):
|
||||
"""Number of parameters in the model."""
|
||||
return self.mesh2.nC
|
||||
def transform(self, m):
|
||||
return self.P*m
|
||||
def transformDeriv(self, m):
|
||||
return self.P
|
||||
|
||||
class ComboModel(BaseModel):
|
||||
"""Combination of various models."""
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@ class ModelTests(unittest.TestCase):
|
||||
|
||||
a = np.array([1, 1, 1])
|
||||
b = np.array([1, 2])
|
||||
self.mesh2 = Mesh.TensorMesh([a, b], np.array([3, 5]))
|
||||
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):
|
||||
for M in dir(Model):
|
||||
@@ -22,6 +23,10 @@ class ModelTests(unittest.TestCase):
|
||||
continue
|
||||
self.assertTrue(model.test())
|
||||
|
||||
def test_Mesh2MeshModel(self):
|
||||
model = Model.Mesh2Mesh([self.mesh22, self.mesh2])
|
||||
self.assertTrue(model.test())
|
||||
|
||||
def test_comboModels(self):
|
||||
combos = [(Model.LogModel, Model.Vertical1DModel)]
|
||||
for combo in combos:
|
||||
|
||||
Reference in New Issue
Block a user