if not args.nographics:
    fk_plt.plot_mesh(triangular_mesh, plot_labels=False)

################################################################################
#
# Layers:
#--------------------

layer = fk.Layer(NL, triangular_mesh, topography=ZB)

################################################################################
#
# Primitives:
#--------------------

primitives = fk.Primitive(triangular_mesh, layer, height=H0)

################################################################################
#
# Tracer:
#--------------------

if WITH_TRACER:
    T_0 = np.zeros((NC, NL))
    for C in range(NC):
        for L in range(NL):
            x = triangular_mesh.triangulation.x[C]
            y = triangular_mesh.triangulation.y[C]
            if x < BOX_X_MAX and x > BOX_X_MIN and y > BOX_Y_MIN and y < BOX_Y_MAX:
                T_0[C, L] = 0.9
# Primitives:
#--------------------


def h_0(x, y):
    h = H_R
    if x < X_D: h = H_L
    return h


if not args.nographics:
    fk_plt.plot_init_1d(triangular_mesh, h_0, 'x', '$H_0$')

primitives = fk.Primitive(triangular_mesh,
                          layer,
                          height_funct=h_0,
                          Uinit=0.,
                          Vinit=0.)

################################################################################
#
# Boundary conditions:
#---------------------

fluvial_heights = [
    fk.FluvialHeight(ref=1, height=H_L),
    fk.FluvialHeight(ref=2, height=H_R)
]
slides = [fk.Slide(ref=3), fk.Slide(ref=4)]

################################################################################
Example #3
0
#Number of layers is set to one for comparison with analytical solutions.
#
#.. note:: Topography defined in ``fk.Bump`` is shared with ``fk.Layer``
#

NL = 1
layer = fk.Layer(NL, triangular_mesh, topography=bump_analytic.topography)

################################################################################
#
# Primitives:
#--------------------

primitives = fk.Primitive(triangular_mesh,
                          layer,
                          free_surface=FREE_SURFACE_0,
                          QXinit=Q_IN,
                          QYinit=0.)

################################################################################
#
# Boundary conditions:
#---------------------

fluvial_flowrates = [
    fk.FluvialFlowRate(ref=1,
                       flowrate=Q_IN,
                       x_flux_direction=1.0,
                       y_flux_direction=0.0)
]
        x_b = X_B,
        topo = topo_gaussian,
        scheduler=fk.schedules(times=WHEN),
        compute_error=True,
        error_type='L2',
        error_output='txt'))

    bump_analytic_list[I](0.)

    layer_list.append(fk.Layer(
        case.NL, triangular_mesh_list[mesh_id],
        topography=bump_analytic_list[I].topography))

    primitives_list.append(fk.Primitive(
        triangular_mesh_list[mesh_id],
        layer_list[I],
        free_surface=FREE_SURFACE_0,
        QXinit=Q_IN,
        QYinit=0.))

    if PLOT_SOL:
        create_figure = {'plot':fk_plt.plot_freesurface_3d_analytic}
        create_figure_scheduler = fk.schedules(times=[0.99*FINAL_TIME])
    else:
        create_figure = None
        create_figure_scheduler = None

    problem_list.append(fk.Problem(
        simutime_list[I], triangular_mesh_list[mesh_id],
        layer_list[I], primitives_list[I],
        analytic_sol=bump_analytic_list[I],
        numerical_parameters=numerical_params,
Example #5
0
#
simutime = fk.SimuTime(final_time=4.,
                       time_iteration_max=20000,
                       second_order=True)
create_figure_scheduler = fk.schedules(times=[0., 1., 2., 3., 4., 5.])
triangular_mesh = fk.TriangularMesh.from_msh_file(
    '../simulations/inputs/square2.mesh')
layer = fk.Layer(1, triangular_mesh, topography=0.)


def H_0(x, y):
    h = 2.4 * (1.0 + np.exp(-0.25 * ((x - 10.05)**2 + (y - 10.05)**2)))
    return h


primitives = fk.Primitive(triangular_mesh, layer, height_funct=H_0)
tracers = [fk.Tracer(triangular_mesh, layer, primitives, Tinit=1.0)]
slides = [fk.Slide(ref=r) for r in [1, 2, 3, 4]]
vtk_writer = fk.VTKWriter(triangular_mesh,
                          scheduler=fk.schedules(count=10),
                          scale_h=1.)

problem = fk.Problem(simutime,
                     triangular_mesh,
                     layer,
                     primitives,
                     slides=slides,
                     numerical_parameters={'space_second_order': True},
                     tracers=tracers,
                     vtk_writer=vtk_writer,
                     restart_scheduler=restart_scheduler,
Example #6
0
simutime_l = []
layer_l = []
primitives_l = []
wind_effect_l = []
external_effects_l = []
problem_l = []

for C, law in enumerate(cases):

    simutime_l.append(
        fk.SimuTime(final_time=5.,
                    time_iteration_max=10000,
                    second_order=False))
    layer_l.append(fk.Layer(NL, triangular_mesh, topography=0.))
    primitives_l.append(
        fk.Primitive(triangular_mesh, layer_l[C], free_surface=2.0))

    if law == 'Custom':
        wind_effect_l.append(
            fk.WindEffect(velocity=[20, 20, 20, 20],
                          orientation=[270., 270., 270., 270.],
                          times=[0., 3., 4., 5.],
                          friction_law_funct=custom_friction_law))
    else:
        wind_effect_l.append(
            fk.WindEffect(velocity=[20, 20, 20, 20],
                          orientation=[270., 270., 270., 270.],
                          times=[0., 3., 4., 5.],
                          friction_law=law))

    external_effects_l.append({"wind": wind_effect_l[C]})
Example #7
0
    fk_plt.plot_mesh(triangular_mesh, plot_labels=False)

################################################################################
#
# Layers:
#--------------------

NL = 4
layer = fk.Layer(NL, triangular_mesh, topography=0.)

################################################################################
#
# Primitives:
#--------------------

primitives = fk.Primitive(triangular_mesh, layer, free_surface=2.)

################################################################################
#
# Tracer:
#---------------------
#
################################################################################
#
#.. important::
#
#   Let us define two tracers, labeled ``polluant_0`` and ``polluant_1``. Labels are
#   very important to link boundary conditions as well as source terms to the correct
#   tracer in the code.

tracers = [
Example #8
0
#.. note:: Topography defined in thacker2d is shared with layer
#

layer = fk.Layer(NL, triangular_mesh, topography=thacker2d_analytic.topography)

################################################################################
#
# Primitives:
#--------------------
#
#.. note:: H, U and V are initialized with analytic initial solution
#

primitives = fk.Primitive(triangular_mesh,
                          layer,
                          height=thacker2d_analytic.H,
                          Uinit=thacker2d_analytic.U,
                          Vinit=thacker2d_analytic.V)

################################################################################
#
#Topography and initial height computed in thacker2d_analytic are
#the following:


def Topo(x, y):
    r2 = (x - 0.5 * L)**2 + (y - 0.5 * L)**2
    return -H0 * (1 - (r2 / A**2))


def H_0(x, y):
        value = 10.
    else:
        value = 50.
    return value

def Rho_0(x, y):
    if x < GATE_POSITION:
        T = 10
        value = Rho_sea_water(T, 0.)
    else:
        T = 50.
        value = Rho_sea_water(T, 0.)
    return value

if PHY_PARAMS['variable_density_model'] == 'boussinesq':
    primitives = fk.Primitive(triangular_mesh, layer, free_surface=2.0)
    tracers = [fk.Tracer(triangular_mesh, layer, primitives, Tinit_funct=T_0,
                         label='temperature',
                         horizontal_diffusivity=0.0,
                         vertical_diffusivity=0.0)]

elif PHY_PARAMS['variable_density_model'] == 'ns-fourier':
    primitives = fk.Primitive(triangular_mesh, layer, free_surface=2.0, 
                              Rhoinit_funct=Rho_0)
    tracers = []

################################################################################
#
# Custom functions: 
#----------------------
#
Example #10
0
    print(" ")
    print(
        "                           SOLVING CASE {}                   ".format(
            C))
    print(" ")
    print(" ")

    simutime_l.append(
        fk.SimuTime(final_time=FINAL_TIME,
                    time_iteration_max=100000,
                    second_order=False))

    layer_l.append(fk.Layer(NL[law], triangular_mesh, topography=0.))

    primitives_l.append(
        fk.Primitive(triangular_mesh, layer_l[C], height=H0, QXinit=1.))

    PHYSICAL_PARAMS = {
        'friction_law': law,
        'friction_coeff': coef,
        'horizontal_viscosity': .02,
        'vertical_viscosity': .02
    }

    problem_l.append(
        fk.Problem(simutime=simutime_l[C],
                   triangular_mesh=triangular_mesh,
                   layer=layer_l[C],
                   primitives=primitives_l[C],
                   numerical_parameters=NUMERICAL_PARAMS,
                   physical_parameters=PHYSICAL_PARAMS,
Example #11
0
def T_0(x, y):
    if x < -1.5:
        t = 35.0
    else:
        t = 0.0
    return t


#Plot initial free surface in (x,z) slice plane:
if not args.nographics:
    fk_plt.plot_init_1d_slice(triangular_mesh,
                              surf_xy=eta_0,
                              topo_xy=Topography,
                              primitive_xy=T_0)

primitives = fk.Primitive(triangular_mesh, layer, free_surface_funct=eta_0)
tracers = [fk.Tracer(triangular_mesh, layer, primitives, Tinit_funct=T_0)]

################################################################################
#
# Boundary conditions:
#---------------------

slides = [fk.Slide(ref=1), fk.Slide(ref=3)]
torrential_outs = [fk.TorrentialOut(ref=2)]
tube = fk.RectangularTube(xlim=(0.0, 4.0), ylim=(0.0, 6.0), zlim=(0.0, 6.0))
flowrate = fk.TimeDependentFlowRate(times=[0.0, 0.0], flowrates=[0.0, 0.0])
fluvial_flowrates = [
    fk.FluvialFlowRate(ref=4,
                       time_dependent_flowrate=flowrate,
                       rectangular_tube=tube,
#--------------------
#
#There is several ways to initialize these variables:
#
#- For H we can provide water **height** or **free_surface**
#- For velocities (default=0.) we can either provide **QXinit**, **QYinit** or **Uinit**, **Vinit**.
#
#.. note:: For each primitive you can either provide a constant 'Pinit' which will be set within the entire domain or specify a function of **Pinit = f(x,y)** (To call functions you need to add the suffix **_funct** to **Pinit**). If you want to set different initial values on each layer you can also provide a matrix that contains value on every node of the mesh: **Pinit(NC,NL)**.
#
#Since topography is flat in this example defining **height** or **free_surface** is
#the same. First we can set **U** and **V** to simple values:
#

primitives = fk.Primitive(triangular_mesh,
                          layer,
                          free_surface=1.,
                          Uinit=0.3,
                          Vinit=0.2)

################################################################################
#
#If we want to use a function to define **U** we can do:


def U_0(x, y):
    r = np.sqrt((x - 5.0)**2 + (y - 5.0)**2)
    if x < 5.:
        u = np.sinc(r)
    else:
        u = np.sinc(r + np.pi)
    return u
Example #13
0
    elif x > X_2:
        topo = 0.0
    else:
        topo = -(10.0/(X_2-X_1))*(x - X_2)
    return topo

NL = 2
layer = fk.Layer(NL, triangular_mesh, topography_funct=topo)

################################################################################
#  
# Primitives:
#--------------------
#
 
primitives = fk.Primitive(triangular_mesh, layer, free_surface=FREE_SURFACE)

if not args.nographics:
  fk_plt.plot_init_1d_slice(triangular_mesh, surf=FREE_SURFACE, topo_xy=topo)

################################################################################
#  
# Topography source term: 
#------------------------
#
#``ExternalEffects`` objects are called in ``problem.solve()`` at each time step. In
#this example external effects are ``TopographySource``.
#There can be as much external effects as needed as long as they are stored in a
#dictionary type.
#
#Let us consider two cases:
# Layers:
#--------------------

NL = 20
layer = fk.Layer(NL, triangular_mesh, topography=0.)

################################################################################
#
# Primitives:
#--------------------
#
#Initial height is defined thanks to a user defined function.

primitives = fk.Primitive(triangular_mesh,
                          layer,
                          height=2.,
                          Uinit=0.,
                          Vinit=0.)

################################################################################
#
# Particles:
#--------------------
#
#Lagrangian particle tracking is carried out with a Lagrangian class that users
#have to define and pass to the Problem class.
#Initial position of particles can either be defined by the ``generate_homogeneous_positions``
#function provided in freshkiss3d or by a custom user defined function. Lagrangian
#class is initialized with a ``positions`` matrix of dimension [Npart,3] containing
#x, y, z coordonates of each particle.
Example #15
0
                                    tracer=HAS_TRACER,
                                    compute_error=True,
                                    error_type=ERROR_TYPE,
                                    error_output='none'))

    thacker3d_analytic_list[I](0.)

    layer_list.append(
        fk.Layer(case.NL,
                 triangular_mesh_list[mesh_id],
                 topography=thacker3d_analytic_list[I].topography))

    primitives_list.append(
        fk.Primitive(triangular_mesh_list[mesh_id],
                     layer_list[I],
                     height=thacker3d_analytic_list[I].H,
                     Uinit=thacker3d_analytic_list[I].U,
                     Vinit=thacker3d_analytic_list[I].V,
                     HRhoinit=thacker3d_analytic_list[I].HRho))

    problem_list.append(
        fk.Problem(simutime_list[I],
                   triangular_mesh_list[mesh_id],
                   layer_list[I],
                   primitives_list[I],
                   analytic_sol=thacker3d_analytic_list[I],
                   numerical_parameters=NUM_PARAMS,
                   physical_parameters=PHY_PARAMS,
                   fluvial_heights=fluvial_heights))

    problem_list[I].solve()
Example #16
0
#We loop over cases:

for C, NL in enumerate(cases):

    print(" ")
    print(" ")
    print("                         SOLVING CASE {}                 ".format(C))
    print(" ")
    print(" ")

    simutime_l.append(fk.SimuTime(final_time=1., time_iteration_max=100000))

    layer_l.append(fk.Layer(NL, triangular_mesh, topography=0.))

    primitives_l.append(fk.Primitive(triangular_mesh, layer_l[C], 
                                     free_surface=2., 
                                     QXinit=1.))

    problem_l.append(fk.Problem(simutime=simutime_l[C],
                                triangular_mesh=triangular_mesh,
                                layer=layer_l[C],
                                primitives=primitives_l[C], 
                                physical_parameters=PHY_PARAMS,
                                slides=slide,
                                fluvial_flowrates=fluvial_flowrates,
                                fluvial_heights=fluvial_heights))
    problem_l[C].solve()

################################################################################
#  
# Plot velocity profile: