Exemplo n.º 1
0
    comp_new = project(comp, P1)
    comp_new2 = interpolate(
        conditional(comp_new > Constant(0.0), comp_new, Constant(0.0)), P1)
    mon_init = project(Constant(1.0) + comp_new2, P1)

    H = Function(P1)
    tau = TestFunction(P1)

    a = (inner(tau, H) * dx) + (K * inner(tau.dx(1), H.dx(1)) *
                                dx) - inner(tau, mon_init) * dx
    solve(a == 0, H)

    return H


swp.set_monitor_functions(gradient_interface_monitor)

t1 = time.time()
swp.solve_forward()
t2 = time.time()

print(t2 - t1)

print(fac_x)
print(alpha)
print(beta)
print(gamma)

new_mesh = RectangleMesh(880, 20, 220, 10)

bath = Function(FunctionSpace(new_mesh, "CG",
Exemplo n.º 2
0
    else:
        return 1.0 + alpha * local_norm(u, norm_type=norm_type)


def mixed_monitor(mesh, **kwargs):
    return 0.5 * (velocity_norm_monitor(mesh, norm_type='HDiv') +
                  elevation_norm_monitor(mesh, norm_type='H1'))


# Set monitor function to use during simulation
if monitor_type == 'elev':
    monitor = elevation_norm_monitor
elif monitor_type == 'uv':
    monitor = velocity_norm_monitor
else:
    monitor = mixed_monitor
swp.set_monitor_functions(monitor)

# --- Solve forward problem and print diagnostics

swp.solve_forward()
if bool(args.calculate_metrics or False):
    print_output("\nCalculating error metrics...")
    metrics = op.get_peaks(swp.fwd_solutions[-1].split()[1],
                           reference_mesh_resolution=n_fine)
    print_output("h+       : {:.8e}".format(metrics[0]))
    print_output("h-       : {:.8e}".format(metrics[1]))
    print_output("C+       : {:.8e}".format(metrics[2]))
    print_output("C-       : {:.8e}".format(metrics[3]))
    print_output("RMS error: {:.8e}".format(metrics[4]))
Exemplo n.º 3
0
def frobenius_monitor(mesh, x=None):  # NOQA: Version above not smooth enough
    """
    Frobenius norm taken element-wise.
    """
    P1 = FunctionSpace(mesh, "CG", 1)
    b = swp.fwd_solutions_bathymetry[0]
    P0 = FunctionSpace(b.function_space().mesh(), "DG", 0)
    H = recovery.recover_hessian(b, op=op)
    frob = interpolate(local_frobenius_norm(H), P0)
    return 1 + alpha_const*project(frob, P1)/frob.vector().gather().max()


# --- Simulation and analysis

# Solve forward problem
swp.set_monitor_functions(frobenius_monitor)
t1 = time.time()
swp.solve_forward()
t2 = time.time()

# Save solution data
new_mesh = RectangleMesh(16*5*5, 5*1, 16, 1.1)
bath = Function(FunctionSpace(new_mesh, "CG", 1)).project(swp.fwd_solutions_bathymetry[0])
bathymetrythetis1 = []
diff_thetis = []
datathetis = np.linspace(0, 15.9, 160)
bathymetrythetis1 = [-bath.at([i, 0.55]) for i in datathetis]
df = pd.concat([pd.DataFrame(datathetis, columns=['x']), pd.DataFrame(bathymetrythetis1, columns=['bath'])], axis=1)
df.to_csv('adapt_output/bed_trench_output_uni_s_{:.4f}_{:.1f}_{:.1e}_{:d}.csv'.format(res, alpha, rtol, freq))

# Compute l2 error against experimental data
Exemplo n.º 4
0

def velocity_monitor(mesh, alpha=alpha, beta=beta, gamma=gamma, K=kappa):
    P1 = FunctionSpace(mesh, "CG", 1)
    b = swp.fwd_solutions_bathymetry[0]

    if b is not None:
        abs_hor_vel_norm = Function(b.function_space()).project(conditional(b > 0.0, Constant(1.0), Constant(0.0)))
    else:
        abs_hor_vel_norm = Function(swp.bathymetry[0].function_space()).project(conditional(swp.bathymetry[0] > 0.0, Constant(1.0), Constant(0.0)))
    comp_new = project(abs_hor_vel_norm, P1)
    mon_init = project(1.0 + alpha * comp_new, P1)
    return mon_init


swp.set_monitor_functions(velocity_monitor)

t1 = time.time()
swp.solve_forward()
t2 = time.time()

print(t2-t1)

fpath = "hydrodynamics_beach_bath_new_{:d}_basic".format(int(nx*220))
export_bathymetry(swp.fwd_solutions_bathymetry[0], fpath, op=op)

xaxisthetis1 = []
baththetis1 = []

for i in np.linspace(0, 219, 220):
    xaxisthetis1.append(i)
Exemplo n.º 5
0
alpha = 1.0  # size of the dense region surrounding the coast
beta = 10.0  # level of refinement at coast


def wet_dry_interface_monitor(mesh, **kwargs):
    """
    Monitor function focused around the wet-dry interface.

    NOTES:
      * The monitor function is defined on the *computational* mesh.
      * For the first mesh movement iteration, the mesh coordinates coincide.
    """
    eta_old = swp.fwd_solutions[0].split()[1]
    b_old = swp.bathymetry[0]
    eta = Function(FunctionSpace(mesh, eta_old.ufl_element()))
    b = Function(FunctionSpace(mesh, b_old.ufl_element()))
    same_mesh = np.allclose(mesh.coordinates.dat.data,
                            swp.meshes[0].coordinates.dat.data)
    if same_mesh:
        eta.dat.data[:] = eta_old.dat.data
        b.dat.data[:] = b_old.dat.data
    else:
        eta.project(eta_old)
        b.project(b_old)
    return 1.0 + alpha * pow(cosh(beta * (eta + b)), -2)


swp.set_monitor_functions(wet_dry_interface_monitor)
swp.solve_forward()