simper model-->mapping and docs updates.

This commit is contained in:
rowanc1
2014-04-15 15:43:16 -07:00
parent 4b569924f4
commit 8f108d488d
6 changed files with 44 additions and 47 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ Tests:
[https://travis-ci.org/simpeg/simpegflow](https://travis-ci.org/simpeg/simpegflow)
Build Status:
[![Build Status](https://travis-ci.org/simpeg/simpegflow.png)](https://travis-ci.org/simpeg/simpegflow)
[![Build Status](https://travis-ci.org/simpeg/simpegflow.svg?branch=master)](https://travis-ci.org/simpeg/simpegflow)
Bugs & Issues:
[https://github.com/simpeg/simpegflow/issues](https://github.com/simpeg/simpegflow/issues)
@@ -9,14 +9,14 @@ import matplotlib.pyplot as plt
M = Mesh.TensorMesh([np.ones(40)])
M.setCellGradBC('dirichlet')
params = Richards.Empirical.HaverkampParams().celia1990
model = Richards.Empirical.Haverkamp(M, **params)
E = Richards.Empirical.Haverkamp(M, **params)
bc = np.array([-61.5,-20.7])
h = np.zeros(M.nC) + bc[0]
def getFields(timeStep,method):
prob = Richards.RichardsProblem(model, timeStep=timeStep, timeEnd=360,
prob = Richards.RichardsProblem(M, mapping=E, timeStep=timeStep, timeEnd=360,
boundaryConditions=bc, initialConditions=h,
doNewton=False, method=method)
return prob.fields(params['Ks'])
+1 -7
View File
@@ -24,17 +24,11 @@ Testing SimPEG
==============
* Master Branch
.. image:: https://travis-ci.org/simpeg/simpegflow.png?branch=master
.. image:: https://travis-ci.org/simpeg/simpegflow.svg?branch=master
:target: https://travis-ci.org/simpeg/simpegflow
:alt: Master Branch
:align: center
* Develop Branch
.. image:: https://travis-ci.org/simpeg/simpegflow.png?branch=develop
:target: https://travis-ci.org/simpeg/simpegflow
:alt: Develop Branch
:align: center
Project Index & Search
======================
+21 -18
View File
@@ -1,8 +1,8 @@
from SimPEG import Mesh, Model, Utils, np
from SimPEG import Mesh, Maps, Utils, np
class RichardsModel(object):
"""docstring for RichardsModel"""
class RichardsMap(object):
"""docstring for RichardsMap"""
mesh = None #: SimPEG mesh
@@ -18,8 +18,8 @@ class RichardsModel(object):
def __init__(self, mesh, thetaModel, kModel):
self.mesh = mesh
assert isinstance(thetaModel, Model.BaseNonLinearModel)
assert isinstance(kModel, Model.BaseNonLinearModel)
assert isinstance(thetaModel, Maps.NonLinearMap)
assert isinstance(kModel, Maps.NonLinearMap)
self._thetaModel = thetaModel
self._kModel = kModel
@@ -52,6 +52,9 @@ class RichardsModel(object):
ax = plt.subplot(122)
ax.semilogx(self.k(h, m), h)
def _assertMatchesPair(self, pair):
assert isinstance(self, pair), "Mapping object must be an instance of a %s class."%(pair.__name__)
def _ModelProperty(name, models, doc=None, default=None):
@@ -91,7 +94,7 @@ class HaverkampParams(object):
'gamma':4.74}
class _haverkamp_theta(Model.BaseNonLinearModel):
class _haverkamp_theta(Maps.NonLinearMap):
theta_s = 0.430
theta_r = 0.078
@@ -99,7 +102,7 @@ class _haverkamp_theta(Model.BaseNonLinearModel):
beta = 3.960
def __init__(self, mesh, **kwargs):
Model.BaseNonLinearModel.__init__(self, mesh)
Maps.NonLinearMap.__init__(self, mesh)
Utils.setKwargs(self, **kwargs)
def setModel(self, m):
@@ -128,14 +131,14 @@ class _haverkamp_theta(Model.BaseNonLinearModel):
return g
class _haverkamp_k(Model.BaseNonLinearModel):
class _haverkamp_k(Maps.NonLinearMap):
A = 1.175e+06
gamma = 4.74
Ks = np.log(24.96)
def __init__(self, mesh, **kwargs):
Model.BaseNonLinearModel.__init__(self, mesh)
Maps.NonLinearMap.__init__(self, mesh)
Utils.setKwargs(self, **kwargs)
def setModel(self, m):
@@ -169,7 +172,7 @@ class _haverkamp_k(Model.BaseNonLinearModel):
g = Utils.sdiag(g)
return g
class Haverkamp(RichardsModel):
class Haverkamp(RichardsMap):
"""Haverkamp Model"""
alpha = _ModelProperty('alpha', ['thetaModel'], default=1.6110e+06)
@@ -182,7 +185,7 @@ class Haverkamp(RichardsModel):
gamma = _ModelProperty('gamma', ['kModel'], default=4.74)
def __init__(self, mesh, **kwargs):
RichardsModel.__init__(self, mesh,
RichardsMap.__init__(self, mesh,
_haverkamp_theta(mesh),
_haverkamp_k(mesh))
Utils.setKwargs(self, **kwargs)
@@ -190,7 +193,7 @@ class Haverkamp(RichardsModel):
class _vangenuchten_theta(Model.BaseNonLinearModel):
class _vangenuchten_theta(Maps.NonLinearMap):
theta_s = 0.430
theta_r = 0.078
@@ -198,7 +201,7 @@ class _vangenuchten_theta(Model.BaseNonLinearModel):
n = 1.560
def __init__(self, mesh, **kwargs):
Model.BaseNonLinearModel.__init__(self, mesh)
Maps.NonLinearMap.__init__(self, mesh)
Utils.setKwargs(self, **kwargs)
def setModel(self, m):
@@ -226,7 +229,7 @@ class _vangenuchten_theta(Model.BaseNonLinearModel):
return g
class _vangenuchten_k(Model.BaseNonLinearModel):
class _vangenuchten_k(Maps.NonLinearMap):
I = 0.500
alpha = 0.036
@@ -234,7 +237,7 @@ class _vangenuchten_k(Model.BaseNonLinearModel):
Ks = np.log(24.96)
def __init__(self, mesh, **kwargs):
Model.BaseNonLinearModel.__init__(self, mesh)
Maps.NonLinearMap.__init__(self, mesh)
Utils.setKwargs(self, **kwargs)
def setModel(self, m):
@@ -282,7 +285,7 @@ class _vangenuchten_k(Model.BaseNonLinearModel):
g = Utils.sdiag(g)
return g
class VanGenuchten(RichardsModel):
class VanGenuchten(RichardsMap):
"""vanGenuchten Model"""
theta_r = _ModelProperty('theta_r', ['thetaModel'], default=0.075)
@@ -295,7 +298,7 @@ class VanGenuchten(RichardsModel):
I = _ModelProperty('I', ['kModel'], default=0.500)
def __init__(self, mesh, **kwargs):
RichardsModel.__init__(self, mesh,
RichardsMap.__init__(self, mesh,
_haverkamp_theta(mesh),
_haverkamp_k(mesh))
Utils.setKwargs(self, **kwargs)
@@ -497,7 +500,7 @@ class VanGenuchtenParams(object):
if __name__ == '__main__':
import matplotlib.pyplot as plt
M = Mesh.TensorMesh([10])
VGparams = vanGenuchtenParams()
VGparams = VanGenuchtenParams()
leg = []
for p in dir(VGparams):
if p[0] == '_': continue
+15 -15
View File
@@ -1,5 +1,5 @@
from SimPEG import *
from Empirical import RichardsModel
from Empirical import RichardsMap
class RichardsSurvey(Survey.BaseSurvey):
"""docstring for RichardsSurvey"""
@@ -55,7 +55,7 @@ class RichardsSurvey(Survey.BaseSurvey):
#TODO: if m is a parameter in the theta
# distribution, we may need to do
# some more chain rule here.
dT = self.model.thetaDerivU(u, m)
dT = self.mapping.thetaDerivU(u, m)
return self.P*dT
@@ -67,13 +67,13 @@ class RichardsProblem(Problem.BaseProblem):
initialConditions = None
surveyPair = RichardsSurvey
modelPair = RichardsModel
mapPair = RichardsMap
Solver = Solver
solverOpts = {}
def __init__(self, model, **kwargs):
Problem.BaseProblem.__init__(self, model, **kwargs)
def __init__(self, mesh, mapping=None, **kwargs):
Problem.BaseProblem.__init__(self, mesh, mapping=mapping, **kwargs)
@property
def timeStep(self):
@@ -134,11 +134,11 @@ class RichardsProblem(Problem.BaseProblem):
bc = self.boundaryConditions
dt = self.timeStep
dT = self.model.thetaDerivU(hn, m)
dT1 = self.model.thetaDerivU(hn1, m)
K1 = self.model.k(hn1, m)
dK1 = self.model.kDerivU(hn1, m)
dKm1 = self.model.kDerivM(hn1, m)
dT = self.mapping.thetaDerivU(hn, m)
dT1 = self.mapping.thetaDerivU(hn1, m)
K1 = self.mapping.k(hn1, m)
dK1 = self.mapping.kDerivU(hn1, m)
dKm1 = self.mapping.kDerivM(hn1, m)
# Compute part of the derivative of:
#
@@ -188,11 +188,11 @@ class RichardsProblem(Problem.BaseProblem):
bc = self.boundaryConditions
dt = self.timeStep
T = self.model.theta(h, m)
dT = self.model.thetaDerivU(h, m)
Tn = self.model.theta(hn, m)
K = self.model.k(h, m)
dK = self.model.kDerivU(h, m)
T = self.mapping.theta(h, m)
dT = self.mapping.thetaDerivU(h, m)
Tn = self.mapping.theta(hn, m)
K = self.mapping.k(h, m)
dK = self.mapping.kDerivU(h, m)
aveK = 1./(AV*(1./K))
+4 -4
View File
@@ -133,12 +133,12 @@ class RichardsTests1D(unittest.TestCase):
M.setCellGradBC('dirichlet')
params = Richards.Empirical.HaverkampParams().celia1990
model = Richards.Empirical.Haverkamp(M, **params)
E = Richards.Empirical.Haverkamp(M, **params)
bc = np.array([-61.5,-20.7])
h = np.zeros(M.nC) + bc[0]
prob = Richards.RichardsProblem(model, timeStep=60, timeEnd=180,
prob = Richards.RichardsProblem(M, mapping=E, timeStep=60, timeEnd=180,
boundaryConditions=bc, initialConditions=h,
doNewton=False, method='mixed')
@@ -199,7 +199,7 @@ class RichardsTests1D(unittest.TestCase):
stdev = 0.01 # The standard deviation for the noise
survey = self.prob.createSyntheticSurvey(mTrue, std=stdev, P=self.survey.P)
opt = Optimization.InexactGaussNewton(maxIterLS=20, maxIter=10, tolF=1e-6, tolX=1e-6, tolG=1e-6, maxIterCG=6)
reg = Regularization.Tikhonov(Model.BaseModel(self.M))
reg = Regularization.Tikhonov(self.M)
obj = ObjFunction.BaseObjFunction(survey, reg)
derChk = lambda m: [obj.dataObj(m), obj.dataObjDeriv(m)]
print 'Testing Richards Derivative - Pressure Head'
@@ -213,7 +213,7 @@ class RichardsTests1D(unittest.TestCase):
stdev = 0.01 # The standard deviation for the noise
survey = self.prob.createSyntheticSurvey(mTrue, std=stdev, P=self.survey.P)
opt = Optimization.InexactGaussNewton(maxIterLS=20, maxIter=10, tolF=1e-6, tolX=1e-6, tolG=1e-6, maxIterCG=6)
reg = Regularization.Tikhonov(Model.BaseModel(self.M))
reg = Regularization.Tikhonov(self.M)
obj = ObjFunction.BaseObjFunction(survey, reg)
derChk = lambda m: [obj.dataObj(m), obj.dataObjDeriv(m)]
print 'Testing Richards Derivative - Saturation'