def adjointTest(fdemType, comp): prb = getFDEMProblem(fdemType, comp, SrcList, freq) # prb.solverOpts = dict(check_accuracy=True) print('Adjoint {0!s} formulation - {1!s}'.format(fdemType, comp)) m = np.log(np.ones(prb.sigmaMap.nP)*CONDUCTIVITY) mu = np.ones(prb.mesh.nC)*MU if addrandoms is True: m = m + np.random.randn(prb.sigmaMap.nP)*np.log(CONDUCTIVITY)*1e-1 mu = mu + np.random.randn(prb.mesh.nC)*MU*1e-1 survey = prb.survey # prb.PropMap.PropModel.mu = mu # prb.PropMap.PropModel.mui = 1./mu u = prb.fields(m) v = np.random.rand(survey.nD) w = np.random.rand(prb.mesh.nC) vJw = v.dot(prb.Jvec(m, w, u)) wJtv = w.dot(prb.Jtvec(m, v, u)) tol = np.max([TOL*(10**int(np.log10(np.abs(vJw)))),FLR]) print(vJw, wJtv, vJw - wJtv, tol, np.abs(vJw - wJtv) < tol) return np.abs(vJw - wJtv) < tol
def crossCheckTest(fdemType, comp): l2norm = lambda r: np.sqrt(r.dot(r)) prb1 = getFDEMProblem(fdemType, comp, SrcList, freq, verbose) mesh = prb1.mesh print "Cross Checking Forward: %s formulation - %s" % (fdemType, comp) m = np.log(np.ones(mesh.nC) * CONDUCTIVITY) mu = np.log(np.ones(mesh.nC) * MU) if addrandoms is True: m = m + np.random.randn(mesh.nC) * np.log(CONDUCTIVITY) * 1e-1 mu = mu + np.random.randn(mesh.nC) * MU * 1e-1 # prb1.PropMap.PropModel.mu = mu # prb1.PropMap.PropModel.mui = 1./mu survey1 = prb1.survey d1 = survey1.dpred(m) if verbose: print " Problem 1 solved" if fdemType == "e": prb2 = getFDEMProblem("b", comp, SrcList, freq, verbose) elif fdemType == "b": prb2 = getFDEMProblem("e", comp, SrcList, freq, verbose) elif fdemType == "j": prb2 = getFDEMProblem("h", comp, SrcList, freq, verbose) elif fdemType == "h": prb2 = getFDEMProblem("j", comp, SrcList, freq, verbose) else: raise NotImplementedError() # prb2.mu = mu survey2 = prb2.survey d2 = survey2.dpred(m) if verbose: print " Problem 2 solved" r = d2 - d1 l2r = l2norm(r) tol = np.max([TOL * (10 ** int(np.log10(l2norm(d1)))), FLR]) print l2norm(d1), l2norm(d2), l2r, tol, l2r < tol return l2r < tol
def derivTest(fdemType, comp): prb = getFDEMProblem(fdemType, comp, SrcType, freq) print '%s formulation - %s' % (fdemType, comp) x0 = np.log(np.ones(prb.mapping.nP)*CONDUCTIVITY) mu = np.log(np.ones(prb.mesh.nC)*MU) if addrandoms is True: x0 = x0 + np.random.randn(prb.mapping.nP)*np.log(CONDUCTIVITY)*1e-1 mu = mu + np.random.randn(prb.mapping.nP)*MU*1e-1 survey = prb.survey def fun(x): return survey.dpred(x), lambda x: prb.Jvec(x0, x) return Tests.checkDerivative(fun, x0, num=2, plotIt=False, eps=FLR)
def derivTest(fdemType, comp): prb = getFDEMProblem(fdemType, comp, SrcType, freq) print '{0!s} formulation - {1!s}'.format(fdemType, comp) x0 = np.log(np.ones(prb.mapping.nP) * CONDUCTIVITY) mu = np.log(np.ones(prb.mesh.nC) * MU) if addrandoms is True: x0 = x0 + np.random.randn(prb.mapping.nP) * np.log(CONDUCTIVITY) * 1e-1 mu = mu + np.random.randn(prb.mapping.nP) * MU * 1e-1 survey = prb.survey def fun(x): return survey.dpred(x), lambda x: prb.Jvec(x0, x) return Tests.checkDerivative(fun, x0, num=2, plotIt=False, eps=FLR)
def derivTest(fdemType, comp): prb = getFDEMProblem(fdemType, comp, SrcType, freq) # prb.solverOpts = dict(check_accuracy=True) print('{0!s} formulation - {1!s}'.format(fdemType, comp)) x0 = np.log(np.ones(prb.sigmaMap.nP)*CONDUCTIVITY) # mu = np.log(np.ones(prb.mesh.nC)*MU) if addrandoms is True: x0 = x0 + np.random.randn(prb.sigmaMap.nP)*np.log(CONDUCTIVITY)*1e-1 # mu = mu + np.random.randn(prb.sigmaMap.nP)*MU*1e-1 survey = prb.survey def fun(x): return survey.dpred(x), lambda x: prb.Jvec(x0, x) return Tests.checkDerivative(fun, x0, num=2, plotIt=False, eps=FLR)
def adjointTest(fdemType, comp): prb = getFDEMProblem(fdemType, comp, SrcList, freq) print 'Adjoint %s formulation - %s' % (fdemType, comp) m = np.log(np.ones(prb.mapping.nP) * CONDUCTIVITY) mu = np.ones(prb.mesh.nC) * MU if addrandoms is True: m = m + np.random.randn(prb.mapping.nP) * np.log(CONDUCTIVITY) * 1e-1 mu = mu + np.random.randn(prb.mesh.nC) * MU * 1e-1 survey = prb.survey u = prb.fields(m) v = np.random.rand(survey.nD) w = np.random.rand(prb.mesh.nC) vJw = v.dot(prb.Jvec(m, w, u)) wJtv = w.dot(prb.Jtvec(m, v, u)) tol = np.max([TOL * (10**int(np.log10(np.abs(vJw)))), FLR]) print vJw, wJtv, vJw - wJtv, tol, np.abs(vJw - wJtv) < tol return np.abs(vJw - wJtv) < tol
def adjointTest(fdemType, comp): prb = getFDEMProblem(fdemType, comp, SrcList, freq) print 'Adjoint %s formulation - %s' % (fdemType, comp) m = np.log(np.ones(prb.mapping.nP)*CONDUCTIVITY) mu = np.ones(prb.mesh.nC)*MU if addrandoms is True: m = m + np.random.randn(prb.mapping.nP)*np.log(CONDUCTIVITY)*1e-1 mu = mu + np.random.randn(prb.mesh.nC)*MU*1e-1 survey = prb.survey # prb.PropMap.PropModel.mu = mu # prb.PropMap.PropModel.mui = 1./mu u = prb.fields(m) v = np.random.rand(survey.nD) w = np.random.rand(prb.mesh.nC) vJw = v.dot(prb.Jvec(m, w, u)) wJtv = w.dot(prb.Jtvec(m, v, u)) tol = np.max([TOL*(10**int(np.log10(np.abs(vJw)))),FLR]) print vJw, wJtv, vJw - wJtv, tol, np.abs(vJw - wJtv) < tol return np.abs(vJw - wJtv) < tol