def swe_mms_p2p1():
    from firedrake_fluids.shallow_water import ShallowWater

    configs = ["MMS_A", "MMS_B", "MMS_C"]
    ux_norms = []
    uy_norms = []
    h_norms = []

    for c in configs:
        sw = ShallowWater(path=os.path.join(cwd, c + ".swml"))
        solution = sw.run()
        ux_old = solution.split()[0][0]
        uy_old = solution.split()[0][1]
        h_old = solution.split()[1]

        fs_exact = FunctionSpace(sw.mesh, "CG", 3)

        ux_exact = project(Expression("cos(x[0])*sin(x[1])"), fs_exact)
        uy_exact = project(Expression("sin(x[0]*x[0]) + cos(x[1])"), fs_exact)
        h_exact = project(Expression("sin(x[0])*sin(x[1])"), fs_exact)

        h_norms.append(
            sqrt(assemble(dot(h_old - h_exact, h_old - h_exact) * dx)))
        ux_norms.append(
            sqrt(assemble(dot(ux_old - ux_exact, ux_old - ux_exact) * dx)))
        uy_norms.append(
            sqrt(assemble(dot(uy_old - uy_exact, uy_old - uy_exact) * dx)))

    return (h_norms, ux_norms, uy_norms)
Esempio n. 2
0
def swe_tidal_flow_regular_bed():
    from firedrake_fluids.shallow_water import ShallowWater
    from firedrake_adjoint import project

    sw = ShallowWater(
        path=os.path.join(cwd, "swe_tidal_flow_regular_bed.swml"))
    solution = sw.run()

    mesh = sw.mesh

    # Get the coordinates of each node
    coordinates = mesh.coordinates

    # For projecting to the same space as the coordinate field
    vfs = VectorFunctionSpace(mesh, "CG", 1)
    fs = FunctionSpace(mesh, "CG", 1)

    u = solution.split()[0]
    h = solution.split()[1]

    u = project(u, vfs, annotate=False)
    h = project(h, fs, annotate=False)

    print coordinates.vector().array()
    print u.vector().array()
    print h.vector().array()

    # Use [0::2] to select the even-numbered components of the vector's array (i.e. the x-component only).
    return coordinates.vector().array()[0::2], u.vector().array(
    )[0::2], h.vector().array()
def swe_mms_p2p1_quadratic_drag_divergence_free():
   from firedrake_fluids.shallow_water import ShallowWater
   
   configs = ["MMS_A", "MMS_B", "MMS_C"]
   ux_norms = []
   uy_norms = []
   h_norms = []
   
   for c in configs:
      sw = ShallowWater(path=os.path.join(cwd, c + ".swml"))
      solution = sw.run()
      ux_old = solution.split()[0][0]
      uy_old = solution.split()[0][1]
      h_old = solution.split()[1]
      
      fs_exact = FunctionSpace(sw.mesh, "CG", 3)
      
      ux_exact = project(Expression("cos(x[1])*sin(x[0])"), fs_exact)
      uy_exact = project(Expression("-cos(x[0])*sin(x[1])"), fs_exact)
      h_exact = project(Expression("sin(x[0])*sin(x[1])"), fs_exact)
      
      h_norms.append(sqrt(assemble(dot(h_old - h_exact, h_old - h_exact) * dx)))
      ux_norms.append(sqrt(assemble(dot(ux_old - ux_exact, ux_old - ux_exact) * dx)))
      uy_norms.append(sqrt(assemble(dot(uy_old - uy_exact, uy_old - uy_exact) * dx)))

   return (h_norms, ux_norms, uy_norms)
def swe_mms_p0p1():
   from firedrake_fluids.shallow_water import ShallowWater
   
   configs = ["MMS_A", "MMS_B", "MMS_C"]
   ux_norms = []
   uy_norms = []
   h_norms = []
   
   for c in configs:
      sw = ShallowWater(path=os.path.join(cwd, c + ".swml"))
      solution = sw.run()
      ux_old = solution.split()[0][0]
      uy_old = solution.split()[0][1]
      h_old = solution.split()[1]
      
      fs_exact_dg = FunctionSpace(sw.mesh, "DG", 3)
      fs_exact_cg = FunctionSpace(sw.mesh, "CG", 3)
      
      ux_exact = project(Expression("cos(x[0])*sin(x[1])"), fs_exact_dg, solver_parameters={'ksp_type': 'gmres', 'ksp_rtol': 1e-8, 'pc_type': 'sor'})
      uy_exact = project(Expression("sin(x[0]*x[0]) + cos(x[1])"), fs_exact_dg, solver_parameters={'ksp_type': 'gmres', 'ksp_rtol': 1e-8, 'pc_type': 'sor'})
      h_exact = project(Expression("sin(x[0])*sin(x[1])"), fs_exact_cg, solver_parameters={'ksp_type': 'gmres', 'ksp_rtol': 1e-8, 'pc_type': 'sor'})
      
      h_norms.append(sqrt(assemble(dot(h_old - h_exact, h_old - h_exact) * dx)))
      ux_norms.append(sqrt(assemble(dot(ux_old - ux_exact, ux_old - ux_exact) * dx)))
      uy_norms.append(sqrt(assemble(dot(uy_old - uy_exact, uy_old - uy_exact) * dx)))

   return (h_norms, ux_norms, uy_norms)
def swe_tidal_flow_regular_bed():
   from firedrake_fluids.shallow_water import ShallowWater
   from firedrake_adjoint import project
   
   sw = ShallowWater(path=os.path.join(cwd, "swe_tidal_flow_regular_bed.swml"))
   solution = sw.run()
   
   mesh = sw.mesh
   
   # Get the coordinates of each node
   coordinates = mesh.coordinates
   
   # For projecting to the same space as the coordinate field
   vfs = VectorFunctionSpace(mesh, "CG", 1)
   fs = FunctionSpace(mesh, "CG", 1)
   
   u = solution.split()[0]
   h = solution.split()[1]
  
   u = project(u, vfs, annotate=False)
   h = project(h, fs, annotate=False)

   print coordinates.vector().array()
   print u.vector().array()
   print h.vector().array()
   
   # Use [0::2] to select the even-numbered components of the vector's array (i.e. the x-component only).
   return coordinates.vector().array()[0::2], u.vector().array()[0::2], h.vector().array()
def swe_standing_wave():
    from firedrake_fluids.shallow_water import ShallowWater

    sw = ShallowWater(path=os.path.join(cwd, "swe_standing_wave.swml"))
    solution = sw.run()
    h = solution.split()[-1]

    return h.vector().array()
def swe_standing_wave():
    from firedrake_fluids.shallow_water import ShallowWater

    sw = ShallowWater(path=os.path.join(cwd, "swe_standing_wave.swml"))
    solution = sw.run()
    h = solution.split()[-1]

    return h.vector().array()
Esempio n. 8
0
def swe_steady_state():
   from firedrake_fluids.shallow_water import ShallowWater
   sw = ShallowWater(path=os.path.join(cwd, "swe_steady_state.swml"))
   solution = sw.run()
   u_old = solution.split()[0]
   h_old = solution.split()[1]
   
   return u_old.vector().array(), h_old.vector().array()
def swe_dam_break_1d():
    from firedrake_fluids.shallow_water import ShallowWater
    sw = ShallowWater(path=os.path.join(cwd, "swe_dam_break_1d.swml"))
    solution = sw.run()
    h = solution.split()[1]
    u = solution.split()[0]

    return h.vector().array(), u.vector().array()
def swe_steady_flow_dirichlet():
   from firedrake_fluids.shallow_water import ShallowWater
   sw = ShallowWater(path=os.path.join(cwd, "swe_steady_flow_dirichlet.swml"))
   solution = sw.run()
   u_old = solution.split()[0]
   h_old = solution.split()[1]
   
   return u_old.vector().array(), h_old.vector().array()
def swe_dam_break_2d():
   from firedrake_fluids.shallow_water import ShallowWater
   sw = ShallowWater(path=os.path.join(cwd, "swe_dam_break_2d.swml"))
   solution = sw.run()
   
   h = solution.split()[1]
   u = solution.split()[0]
   
   return h.vector().array(), u.vector().array()
def turbine_drag_function():
   from firedrake_fluids.shallow_water import ShallowWater
   
   sw = ShallowWater(path=os.path.join(cwd, "bump.swml"))
   array = sw.get_turbine_array()
   bump = assemble(array.turbine_drag*dx)

   sw = ShallowWater(path=os.path.join(cwd, "tophat.swml"))
   array = sw.get_turbine_array()
   tophat = assemble(array.turbine_drag*dx)
   
   return bump, tophat
def checkpoint():
   from firedrake_fluids.shallow_water import ShallowWater
   # Initialise the simulation from scratch.
   sw = ShallowWater(path=os.path.join(cwd, "checkpoint.swml"))
   solution = sw.run(checkpoint=None)
   ux_initial = solution.split()[0]
   h_initial = solution.split()[1]

   # Initialise the simulation using the data in checkpoint.npy for the initial conditions.
   sw = ShallowWater(path=os.path.join(cwd, "checkpoint.swml"))
   solution = sw.run(checkpoint=os.path.join(cwd, "checkpoint.npy"))
   ux_initial_from_checkpoint = solution.split()[0]
   h_initial_from_checkpoint = solution.split()[1]
   
   return ux_initial.vector().array(), h_initial.vector().array(), ux_initial_from_checkpoint.vector().array(), h_initial_from_checkpoint.vector().array()
Esempio n. 14
0
def turbine_drag_function():
    from firedrake_fluids.shallow_water import ShallowWater

    sw = ShallowWater(path=os.path.join(cwd, "bump.swml"))
    array = sw.get_turbine_array()
    bump = assemble(array.turbine_drag() * dx)

    sw = ShallowWater(path=os.path.join(cwd, "tophat.swml"))
    array = sw.get_turbine_array()
    tophat = assemble(array.turbine_drag() * dx)

    return bump, tophat
Esempio n. 15
0
def checkpoint():
    from firedrake_fluids.shallow_water import ShallowWater
    # Initialise the simulation from scratch.
    sw = ShallowWater(path=os.path.join(cwd, "checkpoint.swml"))
    solution = sw.run(checkpoint=None)
    ux_initial = solution.split()[0]
    h_initial = solution.split()[1]

    # Initialise the simulation using the data in checkpoint.npy for the initial conditions.
    sw = ShallowWater(path=os.path.join(cwd, "checkpoint.swml"))
    solution = sw.run(checkpoint=os.path.join(cwd, "checkpoint.npy"))
    ux_initial_from_checkpoint = solution.split()[0]
    h_initial_from_checkpoint = solution.split()[1]

    return ux_initial.vector().array(), h_initial.vector().array(
    ), ux_initial_from_checkpoint.vector().array(
    ), h_initial_from_checkpoint.vector().array()
def swe_wave_speed_1d():
    from firedrake_fluids.shallow_water import ShallowWater
    sw = ShallowWater(path=os.path.join(cwd, "swe_wave_speed_1d.swml"))
    solution = sw.run()
    h_old = solution.split()[-1]
    return h_old.vector().array()
def swe_wave_speed_1d():
   from firedrake_fluids.shallow_water import ShallowWater
   sw = ShallowWater(path=os.path.join(cwd, "swe_wave_speed_1d.swml"))
   solution = sw.run()
   h_old = solution.split()[-1]
   return h_old.vector().array()