Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def dotest(MYSOLVER, multi=False, A=None, **solverOpts):
if A is None:
h1 = np.ones(10)*100.
h2 = np.ones(10)*100.
h3 = np.ones(10)*100.
h = [h1,h2,h3]
M = TensorMesh(h)
D = M.faceDiv
G = -M.faceDiv.T
Msig = M.getFaceInnerProduct()
A = D*Msig*G
A[-1,-1] *= 1/M.vol[-1] # remove the constant null space from the matrix
else:
M = Mesh.TensorMesh([A.shape[0]])
Ainv = MYSOLVER(A, **solverOpts)
if multi:
e = np.ones(M.nC)
else:
e = np.ones((M.nC, numRHS))
rhs = A * e
x = Ainv * rhs
]
u = np.random.randn(mesh.nC)
for name, opt, nM in opts:
van = Richards.Empirical.Vangenuchten_theta(mesh, **opt)
x0 = np.concatenate([seeds[n] for n in name.split('-')])
def fun(m):
van.model = m
return van(u), van.derivM(u)
print('Vangenuchten_theta test m deriv: ', name)
passed = checkDerivative(
fun,
x0,
plotIt=False
)
self.assertTrue(passed, True)
]
u = np.random.randn(mesh.nC)
for name, opt, nM in opts:
van = Richards.Empirical.Vangenuchten_k(mesh, **opt)
x0 = np.concatenate([seeds[n] for n in name.split('-')])
def fun(m):
van.model = m
return van(u), van.derivM(u)
print('Vangenuchten_k test m deriv: ', name)
passed = checkDerivative(
fun,
x0,
plotIt=False
)
self.assertTrue(passed, True)
'tol': tol,
'maxit': maxit,
'nu_init': nu_init,
'nu_pre': nu_pre,
'nu_coarse': nu_coarse,
'nu_post': nu_post,
'clevel': clevel,
},
'result': efield.field,
'hresult': hfield.field,
}
# # # # # # # # # # 3. TensorMesh check # # # # # # # # # #
# Create an advanced grid with discretize.
grid = TensorMesh(
[[(10, 10, -1.1), (10, 20, 1), (10, 10, 1.1)],
[(33, 20, 1), (33, 10, 1.5)],
[20]],
x0='CN0')
# List of all attributes in emg3d-grid.
all_attr = [
'hx', 'hy', 'hz', 'vectorNx', 'vectorNy', 'vectorNz', 'vectorCCx', 'nE',
'vectorCCy', 'vectorCCz', 'nEx', 'nEy', 'nEz', 'nCx', 'nCy', 'nCz', 'vnC',
'nNx', 'nNy', 'nNz', 'vnN', 'vnEx', 'vnEy', 'vnEz', 'vnE', 'nC', 'nN', 'x0'
]
mesh = {'attr': all_attr}
for attr in all_attr:
mesh[attr] = getattr(grid, attr)
gammaMap=expmap*wires3.three), 3),
]
u = np.random.randn(mesh.nC)
for name, opt, nM in opts:
np.random.seed(2)
hav = Richards.Empirical.Haverkamp_k(mesh, **opt)
def fun(m):
hav.model = m
return hav(u), hav.derivM(u)
print('Haverkamp_k test m deriv: ', name)
passed = checkDerivative(
fun,
np.random.randn(mesh.nC * nM),
plotIt=False
)
self.assertTrue(passed, True)
def test_vangenuchten_theta_u(self):
mesh = Mesh.TensorMesh([50])
van = Richards.Empirical.Vangenuchten_theta(mesh)
passed = checkDerivative(
lambda u: (van(u), van.derivU(u)),
np.random.randn(50),
plotIt=False
)
self.assertTrue(passed, True)
def test_haverkamp_theta_u(self):
mesh = Mesh.TensorMesh([50])
hav = Richards.Empirical.Haverkamp_theta(mesh)
passed = checkDerivative(
lambda u: (hav(u), hav.derivU(u)),
np.random.randn(50),
plotIt=False
)
self.assertTrue(passed, True)
def test_haverkamp_k_u(self):
mesh = Mesh.TensorMesh([5])
hav = Richards.Empirical.Haverkamp_k(mesh)
print('Haverkamp_k test u deriv')
passed = checkDerivative(
lambda u: (hav(u), hav.derivU(u)),
np.random.randn(mesh.nC),
plotIt=False
)
self.assertTrue(passed, True)
def test_simplePass(self):
def simplePass(x):
return np.sin(x), sdiag(np.cos(x))
passed = checkDerivative(simplePass, np.random.randn(5), plotIt=False)
self.assertTrue(passed, True)
def _dotest_sensitivity_full(self):
print('Testing Richards Derivative FULL dim={}'.format(
self.mesh.dim
))
J = self.prob.Jfull(self.mtrue)
passed = checkDerivative(
lambda m: [self.survey.dpred(m), J],
self.mtrue,
num=4,
plotIt=False
)
self.assertTrue(passed, True)