FLOW: Richards: 1D: Inversion#

The example shows an inversion of Richards equation in 1D with a heterogeneous hydraulic conductivity function.

The haverkamp model is used with the same parameters as Celia1990 the boundary and initial conditions are also the same. The simulation domain is 40cm deep and is run for an hour with an exponentially increasing time step that has a maximum of one minute. The general setup of the experiment is an infiltration front that advances downward through the model over time.

The model chosen is the saturated hydraulic conductivity inside the hydraulic conductivity function (using haverkamp). The initial model is chosen to be the background (1e-3 cm/s). The saturation data has 2% random Gaussian noise added.

The figure shows the recovered saturated hydraulic conductivity next to the true model. The other two figures show the saturation field for the entire simulation for the true and recovered models.

Rowan Cockett - 21/12/2016

True saturation over time, Recovered saturation over time
/usr/share/miniconda/envs/simpeg-test/lib/python3.7/site-packages/discretize/operators/differential_operators.py:1795: UserWarning:

cell_gradient_BC is deprecated and is not longer used. See cell_gradient

SimPEG.InvProblem will set Regularization.reference_model to m0.
SimPEG.InvProblem will set Regularization.reference_model to m0.
SimPEG.InvProblem will set Regularization.reference_model to m0.

                        SimPEG.InvProblem is setting bfgsH0 to the inverse of the eval2Deriv.
                        ***Done using same Solver, and solver_opts as the SimulationNDCellCentered problem***

/usr/share/miniconda/envs/simpeg-test/lib/python3.7/site-packages/pymatsolver/direct.py:26: PardisoTypeConversionWarning:

Converting csc_matrix matrix to CSR format, will slow down.

/usr/share/miniconda/envs/simpeg-test/lib/python3.7/site-packages/pymatsolver/direct.py:73: PardisoTypeConversionWarning:

Converting csc_matrix matrix to CSR format, will slow down.

model has any nan: 0
============================ Inexact Gauss Newton ============================
  #     beta     phi_d     phi_m       f      |proj(x-g)-x|  LS    Comment
-----------------------------------------------------------------------------
x0 has any nan: 0
   0  2.65e+05  9.78e+04  0.00e+00  9.78e+04    1.46e+04      0
   1  2.65e+05  9.29e+04  7.09e-03  9.48e+04    3.64e+03      0
   2  2.65e+05  9.17e+04  1.11e-02  9.46e+04    8.99e+02      0   Skip BFGS
   3  6.63e+04  9.16e+04  1.14e-02  9.23e+04    1.13e+04      2   Skip BFGS
   4  6.63e+04  8.31e+04  6.44e-02  8.74e+04    6.32e+03      0
   5  6.63e+04  7.79e+04  1.14e-01  8.55e+04    4.84e+03      0   Skip BFGS
   6  1.66e+04  7.41e+04  1.57e-01  7.67e+04    1.26e+04      0   Skip BFGS
   7  1.66e+04  6.14e+04  3.58e-01  6.73e+04    1.14e+04      0
   8  1.66e+04  5.01e+04  5.76e-01  5.96e+04    9.77e+03      0   Skip BFGS
   9  4.14e+03  4.08e+04  7.94e-01  4.41e+04    1.50e+04      0   Skip BFGS
NewtonRoot stopped by maxIters (30). norm: 1.9068e-04
NewtonRoot stopped by maxIters (30). norm: 1.9068e-04
NewtonRoot stopped by maxIters (30). norm: 1.9068e-04
NewtonRoot stopped by maxIters (30). norm: 1.9068e-04
  10  4.14e+03  2.89e+04  1.20e+00  3.38e+04    1.55e+04      0
NewtonRoot stopped by maxIters (30). norm: 1.9068e-04
NewtonRoot stopped by maxIters (30). norm: 1.9068e-04
NewtonRoot stopped by maxIters (30). norm: 1.9068e-04
NewtonRoot stopped by maxIters (30). norm: 1.9068e-04
NewtonRoot stopped by maxIters (30). norm: 1.9068e-04
NewtonRoot stopped by maxIters (30). norm: 1.9068e-04
NewtonRoot stopped by maxIters (30). norm: 1.9068e-04
NewtonRoot stopped by maxIters (30). norm: 1.9068e-04
NewtonRoot stopped by maxIters (30). norm: 1.6528e-04
NewtonRoot stopped by maxIters (30). norm: 1.6528e-04
NewtonRoot stopped by maxIters (30). norm: 1.6528e-04
NewtonRoot stopped by maxIters (30). norm: 1.6528e-04
  11  4.14e+03  1.72e+04  1.52e+00  2.35e+04    1.40e+04      0
NewtonRoot stopped by maxIters (30). norm: 1.6528e-04
NewtonRoot stopped by maxIters (30). norm: 1.6528e-04
NewtonRoot stopped by maxIters (30). norm: 1.6528e-04
NewtonRoot stopped by maxIters (30). norm: 1.6528e-04
NewtonRoot stopped by maxIters (30). norm: 1.6528e-04
NewtonRoot stopped by maxIters (30). norm: 1.6528e-04
NewtonRoot stopped by maxIters (30). norm: 1.6528e-04
NewtonRoot stopped by maxIters (30). norm: 1.6528e-04
  12  1.04e+03  7.97e+03  1.85e+00  9.88e+03    1.54e+04      0
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
  13  1.04e+03  2.80e+03  2.37e+00  5.25e+03    1.12e+04      0
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
NewtonRoot stopped by maxIters (30). norm: 1.0172e-04
  14  1.04e+03  1.54e+03  2.52e+00  4.15e+03    7.21e+03      0
  15  2.59e+02  1.04e+03  2.51e+00  1.69e+03    4.23e+03      0
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
  16  2.59e+02  5.91e+02  3.18e+00  1.41e+03    3.38e+03      0
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
NewtonRoot stopped by maxIters (30). norm: 7.5092e-04
  17  2.59e+02  5.66e+02  3.19e+00  1.39e+03    3.23e+03      1
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
  18  6.47e+01  5.01e+02  3.31e+00  7.15e+02    1.84e+03      0
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
NewtonRoot stopped by maxIters (30). norm: 2.4227e-04
  19  6.47e+01  3.84e+02  4.12e+00  6.51e+02    3.87e+03      0
  20  6.47e+01  3.09e+02  4.11e+00  5.75e+02    2.30e+03      0
------------------------- STOP! -------------------------
1 : |fc-fOld| = 7.5990e+01 <= tolF*(1+|f0|) = 9.7762e+03
1 : |xc-x_last| = 5.2381e-01 <= tolX*(1+|x0|) = 4.4688e+00
0 : |proj(x-g)-x|    = 2.3039e+03 <= tolG          = 1.0000e-01
0 : |proj(x-g)-x|    = 2.3039e+03 <= 1e3*eps       = 1.0000e-02
1 : maxIter   =      20    <= iter          =     20
------------------------- DONE! -------------------------

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

import discretize
from SimPEG import maps
from SimPEG import regularization
from SimPEG import data_misfit
from SimPEG import optimization
from SimPEG import inverse_problem
from SimPEG import directives
from SimPEG import inversion

from SimPEG.flow import richards


def run(plotIt=True):

    M = discretize.TensorMesh([np.ones(40)], x0="N")
    M.set_cell_gradient_BC("dirichlet")
    # We will use the haverkamp empirical model with parameters from Celia1990
    k_fun, theta_fun = richards.empirical.haverkamp(
        M,
        A=1.1750e06,
        gamma=4.74,
        alpha=1.6110e06,
        theta_s=0.287,
        theta_r=0.075,
        beta=3.96,
    )

    # Here we are making saturated hydraulic conductivity
    # an exponential mapping to the model (defined below)
    k_fun.KsMap = maps.ExpMap(nP=M.nC)

    # Setup the boundary and initial conditions
    bc = np.array([-61.5, -20.7])
    h = np.zeros(M.nC) + bc[0]
    prob = richards.SimulationNDCellCentered(
        M,
        hydraulic_conductivity=k_fun,
        water_retention=theta_fun,
        boundary_conditions=bc,
        initial_conditions=h,
        do_newton=False,
        method="mixed",
        debug=False,
    )
    prob.time_steps = [(5, 25, 1.1), (60, 40)]

    # Create the survey
    locs = -np.arange(2, 38, 4.0).reshape(-1, 1)
    times = np.arange(30, prob.time_mesh.cell_centers_x[-1], 60)
    rxSat = richards.receivers.Saturation(locs, times)
    survey = richards.Survey([rxSat])
    prob.survey = survey

    # Create a simple model for Ks
    Ks = 1e-3
    mtrue = np.ones(M.nC) * np.log(Ks)
    mtrue[15:20] = np.log(5e-2)
    mtrue[20:35] = np.log(3e-3)
    mtrue[35:40] = np.log(1e-2)
    m0 = np.ones(M.nC) * np.log(Ks)

    # Create some synthetic data and fields
    relative = 0.02  # The standard deviation for the noise
    Hs = prob.fields(mtrue)
    data = prob.make_synthetic_data(
        mtrue, relative_error=relative, f=Hs, add_noise=True
    )

    # Setup a pretty standard inversion
    reg = regularization.WeightedLeastSquares(M, alpha_s=1e-1)
    dmis = data_misfit.L2DataMisfit(simulation=prob, data=data)
    opt = optimization.InexactGaussNewton(maxIter=20, maxIterCG=10)
    invProb = inverse_problem.BaseInvProblem(dmis, reg, opt)
    beta = directives.BetaSchedule(coolingFactor=4)
    betaest = directives.BetaEstimate_ByEig(beta0_ratio=1e2)
    target = directives.TargetMisfit()
    dir_list = [beta, betaest, target]
    inv = inversion.BaseInversion(invProb, directiveList=dir_list)

    mopt = inv.run(m0)

    Hs_opt = prob.fields(mopt)

    if plotIt:
        plt.figure(figsize=(14, 9))

        ax = plt.subplot(121)
        plt.semilogx(np.exp(np.c_[mopt, mtrue]), M.gridCC)
        plt.xlabel("Saturated Hydraulic Conductivity, $K_s$")
        plt.ylabel("Depth, cm")
        plt.semilogx([10 ** -3.9] * len(locs), locs, "ro")
        plt.legend(("$m_{rec}$", "$m_{true}$", "Data locations"), loc=4)

        ax = plt.subplot(222)
        mesh2d = discretize.TensorMesh([prob.time_mesh.h[0] / 60, prob.mesh.h[0]], "0N")
        sats = [theta_fun(_) for _ in Hs]
        clr = mesh2d.plot_image(np.c_[sats][1:, :], ax=ax)
        cmap0 = matplotlib.cm.RdYlBu_r
        clr[0].set_cmap(cmap0)
        c = plt.colorbar(clr[0])
        c.set_label("Saturation $\\theta$")
        plt.xlabel("Time, minutes")
        plt.ylabel("Depth, cm")
        plt.title("True saturation over time")

        ax = plt.subplot(224)
        mesh2d = discretize.TensorMesh([prob.time_mesh.h[0] / 60, prob.mesh.h[0]], "0N")
        sats = [theta_fun(_) for _ in Hs_opt]
        clr = mesh2d.plot_image(np.c_[sats][1:, :], ax=ax)
        cmap0 = matplotlib.cm.RdYlBu_r
        clr[0].set_cmap(cmap0)
        c = plt.colorbar(clr[0])
        c.set_label("Saturation $\\theta$")
        plt.xlabel("Time, minutes")
        plt.ylabel("Depth, cm")
        plt.title("Recovered saturation over time")

        plt.tight_layout()


if __name__ == "__main__":
    run()
    plt.show()

Total running time of the script: ( 9 minutes 20.441 seconds)

Estimated memory usage: 19 MB

Gallery generated by Sphinx-Gallery