Exemple #1
0
def error(config, eta0, k):
    state = Function(config.function_space)
    state.interpolate(
        SinusoidalInitialCondition(config, eta0, k, config.params["depth"]))
    u_exact = "eta0*sqrt(g/depth) * cos(k*x[0]-sqrt(g*depth)*k*t)"
    du_exact = "(- eta0*sqrt(g/depth) * sin(k*x[0]-sqrt(g*depth)*k*t) * k)"
    eta_exact = "eta0*cos(k*x[0]-sqrt(g*depth)*k*t)"
    # The source term
    source = Expression((u_exact + " * " + du_exact,
                               "0.0"), \
                               eta0=eta0, g=config.params["g"], \
                               depth=config.params["depth"], t=config.params["current_time"], k=k)

    adj_reset()
    shallow_water_model.sw_solve(config,
                                 state,
                                 annotate=False,
                                 u_source=source)

    analytic_sol = Expression((u_exact, \
                               "0", \
                               eta_exact), \
                               eta0=eta0, g=config.params["g"], \
                               depth=config.params["depth"], t=config.params["current_time"], k=k)
    exactstate = Function(config.function_space)
    exactstate.interpolate(analytic_sol)
    e = state - exactstate
    return sqrt(assemble(dot(e, e) * dx))
Exemple #2
0
def error(config, eta0, k):
    state = Function(config.function_space)
    state.interpolate(
        SinusoidalInitialCondition(config, eta0, k, config.params["depth"]))
    u_exact = "eta0*sqrt(g/depth) * cos(k*x[0]-sqrt(g*depth)*k*t)"  # The analytical veclocity of the shallow water equations has been multiplied by depth to account for the change of variable (\tilde u = depth u) in this code.
    ddu_exact = "(diffusion_coef * eta0*sqrt(g/depth) * cos(k*x[0]-sqrt(g*depth)*k*t) * k*k)"
    eta_exact = "eta0*cos(k*x[0]-sqrt(g*depth)*k*t)"
    # The source term
    source = Expression((ddu_exact,
                         "0.0"), \
                         eta0 = eta0, g = config.params["g"], \
                         depth = config.params["depth"], t = config.params["current_time"], \
                         k = k, diffusion_coef = config.params["diffusion_coef"])

    adj_reset()
    shallow_water_model.sw_solve(config,
                                 state,
                                 annotate=False,
                                 u_source=source)

    analytic_sol = Expression((u_exact, \
                               "0", \
                               eta_exact), \
                               eta0=eta0, g=config.params["g"], \
                               depth=config.params["depth"], t=config.params["current_time"], k=k)
    exactstate = Function(config.function_space)
    exactstate.interpolate(analytic_sol)
    e = state - exactstate
    return sqrt(assemble(dot(e, e) * dx))
Exemple #3
0
def error(config, eta0, k):
  state = Function(config.function_space)
  state.interpolate(SinusoidalInitialCondition(config, eta0, k, config.params["depth"]))

  adj_reset()
  shallow_water_model.sw_solve(config, state, annotate=False)

  analytic_sol = Expression(("eta0*sqrt(g/depth)*cos(k*x[0]-sqrt(g*depth)*k*t)", \
                             "0", \
                             "eta0*cos(k*x[0]-sqrt(g*depth)*k*t)"), \
                             eta0=config.params["eta0"], g=config.params["g"], \
                             depth=config.params["depth"], t=config.params["current_time"], k=config.params["k"])
  exactstate = Function(config.function_space)
  exactstate.interpolate(analytic_sol)
  e = state - exactstate
  return sqrt(assemble(dot(e,e)*dx))