Пример #1
0
def appRes_psFieldNorm(sigmaHalf):

    # Make the survey
    survey, sigma, sigBG, mesh = nsem.utils.test_utils.setup1DSurvey(
        sigmaHalf, False)
    simulation = nsem.Simulation1DPrimarySecondary(
        mesh,
        survey=survey,
        sigmaPrimary=sigBG,
        sigma=sigma,
    )

    # Get the fields
    fields = simulation.fields()

    # Project the data
    data = simulation.dpred(f=fields)

    # Calculate the app res and phs
    app_r = np.array(nsem.utils.test_utils.getAppResPhs(data,
                                                        survey=survey))[:, 0]

    return np.linalg.norm(
        np.abs(
            np.log(app_r) -
            np.log(np.ones(survey.num_frequencies) / sigmaHalf)) *
        np.log(sigmaHalf))
Пример #2
0
def DerivJvecTest(halfspace_value, freq=False, expMap=True):

    survey, sig, sigBG, mesh = nsem.utils.test_utils.setup1DSurvey(
        halfspace_value, False, structure=True)
    simulation = nsem.Simulation1DPrimarySecondary(
        mesh,
        sigmaPrimary=sigBG,
        sigmaMap=maps.IdentityMap(mesh),
        survey=survey)
    print("Using {0} solver for the simulation".format(simulation.solver))
    print(
        "Derivative test of Jvec for eForm primary/secondary for 1d comp from {0} to {1} Hz\n"
        .format(survey.frequencies[0], survey.frequencies[-1]))
    # simulation.mapping = maps.ExpMap(simulation.mesh)
    # simulation.sigmaPrimary = np.log(sigBG)

    x0 = sigBG
    # cond = sig[0]
    # x0 = np.log(np.ones(simulation.mesh.nC)*halfspace_value)
    # simulation.sigmaPrimary = x0
    np.random.seed(1983)
    # if True:
    #     x0  = x0 + np.random.randn(simulation.mesh.nC)*halfspace_value*1e-1
    survey = simulation.survey

    def fun(x):
        return simulation.dpred(x), lambda x: simulation.Jvec(x0, x)

    return tests.checkDerivative(fun, x0, num=4, plotIt=False, eps=FLR)
Пример #3
0
def JvecAdjointTest(sigmaHalf, formulation="PrimSec"):
    forType = "PrimSec" not in formulation
    survey, sigma, sigBG, m1d = nsem.utils.test_utils.setup1DSurvey(
        sigmaHalf, tD=forType, structure=False)
    print("Adjoint test of e formulation for {:s} comp \n".format(formulation))

    if "PrimSec" in formulation:
        problem = nsem.Simulation1DPrimarySecondary(
            m1d, sigmaPrimary=sigBG, sigmaMap=maps.IdentityMap(m1d))
    else:
        raise NotImplementedError(
            "Only {} formulations are implemented.".format(formulation))
    problem.pair(survey)
    m = sigma
    u = problem.fields(m)

    np.random.seed(1983)
    v = np.random.rand(survey.nD, )
    # print problem.PropMap.PropModel.nP
    w = np.random.rand(problem.mesh.nC, )

    vJw = v.ravel().dot(problem.Jvec(m, w, u))
    wJtv = w.ravel().dot(problem.Jtvec(m, v, u))
    tol = np.max([TOL * (10**int(np.log10(np.abs(vJw)))), FLR])
    print(" vJw   wJtv  vJw - wJtv     tol    abs(vJw - wJtv) < tol")
    print(vJw, wJtv, vJw - wJtv, tol, np.abs(vJw - wJtv) < tol)
    return np.abs(vJw - wJtv) < tol
def dataMis_AnalyticPrimarySecondary(sigmaHalf):

    # Make the survey
    # Primary secondary
    survey, sig, sigBG, mesh = nsem.utils.test_utils.setup1DSurvey(
        sigmaHalf, False, structure=True)
    # Analytic data
    simulation = nsem.Simulation1DPrimarySecondary(mesh,
                                                   sigmaPrimary=sig,
                                                   sigma=sig,
                                                   survey=survey)

    dataAnaObj = calculateAnalyticSolution(survey.source_list, mesh, sig)

    data = simulation.dpred()
    dataAna = mkvc(dataAnaObj)
    return np.all((data - dataAna) / dataAna < 2.0)
def appPhs_psFieldNorm(sigmaHalf):

    # Make the survey
    survey, sigma, sigBG, mesh = nsem.utils.test_utils.setup1DSurvey(
        sigmaHalf, False)
    simulation = nsem.Simulation1DPrimarySecondary(mesh,
                                                   sigmaPrimary=sigBG,
                                                   sigma=sigma)
    simulation.pair(survey)

    # Get the fields
    fields = simulation.fields()

    # Project the data
    data = simulation.dpred(f=fields)

    # Calculate the app  phs
    app_p = np.array(nsem.utils.test_utils.getAppResPhs(data, survey))[:, 1]

    return np.linalg.norm(np.abs(app_p - np.ones(survey.nFreq) * 45) / 45)