|
|
|
|
|
# Run Hydro
|
|
|
|
|
|
Useful import
|
|
|
|
|
|
```python
|
|
|
import slim
|
|
|
```
|
|
|
|
|
|
Give the name of the directories where data are (same as in the preprocessing script)
|
|
|
|
|
|
```python
|
|
|
data_dir_base = 'data_'+slim.partition_nb()+'/'
|
|
|
data_dir = data_dir_base+slim.partition_id()+'/'
|
|
|
```
|
|
|
|
|
|
Create a ```Domain``` object, the computational domain defined by the mesh and the bathymetry (and gravity, density, order of the element, ...)
|
|
|
|
|
|
```python
|
|
|
domain = slim.Domain(data_dir+'mesh.msh', data_dir_base+'bathymetry_smooth/bathymetry_smooth.idx')
|
|
|
```
|
|
|
|
|
|
Create a ```ShallowWater2d``` object, the hydrodynamics equation with the following arguments :
|
|
|
|
|
|
- ```Domain``` object
|
|
|
- Temporal scheme (here ```implicit```)
|
|
|
- Initial and final time
|
|
|
- ...
|
|
|
|
|
|
```python
|
|
|
eq = slim.ShallowWater2d(domain, 'implicit', initial_time="2016-01-01 00:00:00", final_time="2016-01-08 00:00:00")
|
|
|
```
|
|
|
|
|
|
Specify different parameters/terms of the equations (bottom friction, viscosity, ...)
|
|
|
|
|
|
```python
|
|
|
eq.set_dissipation('manning')
|
|
|
eq.set_viscosity('smagorinsky')
|
|
|
eq.set_coriolis((data_dir+'coriolis.nc', 'coriolis'))
|
|
|
```
|
|
|
|
|
|
Specify the boundary conditions. For open boundaries, you can provide sea surface elevation (```sse```), eastward (```ux```) and northward (```uy```) velocity or transport, ...
|
|
|
|
|
|
```python
|
|
|
eq.set_boundary_coast('coast')
|
|
|
eq.set_boundary_coast('island')
|
|
|
openBnd = data_dir+'open_bnd.nc'
|
|
|
eq.set_boundary_open('atlantic', sse=(openBnd,'h'),ux=(openBnd,'u'),uy=(openBnd,'v'),transport_flux=True)
|
|
|
eq.set_boundary_open('mexico', sse=(openBnd,'h'),ux=(openBnd,'u'),uy=(openBnd,'v'),transport_flux=True)
|
|
|
```
|
|
|
|
|
|
Create ```Loop``` object, which will compute the numerical solution. Arguments give the time step, the time period between exports, the directory where solutions are stored, ...
|
|
|
|
|
|
```python
|
|
|
loop = slim.Loop(maximum_time_step = 900., export_time = 3600., path = 'output')
|
|
|
```
|
|
|
|
|
|
Add every equation object you want to solve
|
|
|
|
|
|
```python
|
|
|
loop.add_equation(eq)
|
|
|
```
|
|
|
|
|
|
Run the model
|
|
|
|
|
|
```python
|
|
|
loop.run()
|
|
|
```
|
|
|
|
|
|
# Run Tracer
|
|
|
|
|
|
SLIM model can simulate any passive tracer. The simulation can be performed online, by running both hydrodynamics and tracer models at the same time, or offline, by loading previously stored outputs of the hydrodynamical SLIM model.
|
|
|
|
|
|
## Online
|
|
|
|
|
|
Running the tracer online request running the hydrodynamic at the same time
|
|
|
|
|
|
In the same python file as Run Hydro:
|
|
|
|
|
|
Create the Tracer equation
|
|
|
|
|
|
```python
|
|
|
eqTracer = slim.ShallowWaterTracer2d(domain, "implicit",eq, name="tracer", offline = False, initial_time=initial_time, final_time=final_time)
|
|
|
```
|
|
|
- ```domain``` is the same domain as the one used for the hydrodynamic running
|
|
|
- ```"implicit"``` is the temporal scheme used to solve the equation (same as for the hydrodynamic run)
|
|
|
- ```eq``` is the equation of the hydrodynamic run
|
|
|
- ```offline``` is set to False for Online mode
|
|
|
- ```initial_time``` initial time for the temporal solver
|
|
|
- ```final_time``` final time for the final solver
|
|
|
|
|
|
Import the tracer initial condition from the file created in preprocessing
|
|
|
|
|
|
```python
|
|
|
eqTracer.set_initial_condition((data_dir+'init_tracer.nc', 'tracer'))
|
|
|
```
|
|
|
|
|
|
Set the diffusivity model used
|
|
|
|
|
|
```python
|
|
|
eqTracer.set_diffusivity("okubo", okubo_coefficient=0.04)
|
|
|
```
|
|
|
- ```"okubo"``` diffusivity model used: either a constant diffusivity or the Okubo scheme
|
|
|
- ```okubo_coefficient``` coefficient for Okubo scheme [in m^0.85/s] (default: 0.03 m^0.85/s)
|
|
|
|
|
|
Add the boundary condition
|
|
|
|
|
|
```python
|
|
|
eqTracer.set_boundary_coast("coast")
|
|
|
eqTracer.set_boundary_coast("island")
|
|
|
eqTracer.set_boundary_open("mexico", (data_dir + "concentration_atlantic.nc",'tracer'))
|
|
|
eqTracer.set_boundary_open("atlantic", (data_dir + "concentration_atlantic.nc",'tracer'))
|
|
|
```
|
|
|
- ```boundary_coast``` condition for coast (no flux condition)
|
|
|
- ```boundary_open``` impose the external condition
|
|
|
- ```concentration``` netcdf of msh file containing the concentration which will be applied at the boundary [in c]
|
|
|
|
|
|
Compute the total mass of tracer in the domain
|
|
|
|
|
|
```python
|
|
|
eqTracer.compute_mass("tracer.dat")
|
|
|
```
|
|
|
|
|
|
## Offline
|
|
|
|
|
|
Running the tracer offline is much quicker than online. It request the output file from a hydrodynamic run with the option ```export_every_sub_time_step```
|
|
|
|
|
|
|
|
|
Useful import
|
|
|
|
|
|
```python
|
|
|
import slim
|
|
|
```
|
|
|
|
|
|
Give the name of the directories where data are (same as in the preprocessing script)
|
|
|
|
|
|
```python
|
|
|
data_dir_base = 'data_'+slim.partition_nb()+'/'
|
|
|
data_dir = data_dir_base+slim.partition_id()+'/'
|
|
|
```
|
|
|
|
|
|
Create a ```Domain``` object, the computational domain defined by the mesh and the bathymetry (and gravity, density, order of the element, ...) . It has to be the same as the one used for the hydro equation
|
|
|
|
|
|
```python
|
|
|
domain = slim.Domain(data_dir+'mesh.msh', data_dir_base+'bathymetry_smooth/bathymetry_smooth.idx')
|
|
|
```
|
|
|
- ```(data_dir+"gravity.nc","gravity")``` is a preprocessing file with the gravity over the domain
|
|
|
- ```rho``` is the water density
|
|
|
- ```solve_on_sphere``` ```True``` if you solve the equation on a sphere, ```False``` if it is in a projected domain
|
|
|
|
|
|
Create the Tracer equation
|
|
|
|
|
|
```python
|
|
|
eqTracer = slim.ShallowWaterTracer2d(domain, "implicit","output_offline/", name="tracer", offline = True, initial_time=param.initial_time, final_time=param.final_time)
|
|
|
```
|
|
|
- ```domain``` is the same domain defined above
|
|
|
- ```"implicit"``` is the temporal scheme used to solve the equation (same as for the hydrodynamic run)
|
|
|
- ```"output_offline/"``` is the path to the output from an hydrodynamic run with ```export_every_sub_time_step``` set to ```True```
|
|
|
- ```offline``` is set to True for Offline mode
|
|
|
- ```initial_time``` initial time for the temporal solver
|
|
|
- ```final_time``` final time for the final solver
|
|
|
|
|
|
|
|
|
Import the tracer initial condition from the file created in preprocessing
|
|
|
|
|
|
```python
|
|
|
eqTracer.set_initial_condition((data_dir+'init_tracer.nc', 'tracer'))
|
|
|
'''
|
|
|
|
|
|
Set the diffusivity model used
|
|
|
'''python
|
|
|
eqTracer.set_diffusivity("okubo", okubo_coefficient=0.04)
|
|
|
```
|
|
|
- ```"okubo"``` diffusivity model used: either a constant diffusivity or the okubo scheme
|
|
|
- ```okubo_coefficient``` coefficient for Okubo scheme [in m^0.85/s] (default: 0.03 m^0.85/s)
|
|
|
|
|
|
Add the boundary condition
|
|
|
|
|
|
```python
|
|
|
eqTracer.set_boundary_coast("coast")
|
|
|
eqTracer.set_boundary_coast("island")
|
|
|
eqTracer.set_boundary_open("mexico", (data_dir + "concentration_atlantic.nc",'tracer'))
|
|
|
eqTracer.set_boundary_open("atlantic", (data_dir + "concentration_atlantic.nc",'tracer'))
|
|
|
```
|
|
|
- ```boundary_coast``` condition for coast (no flux condition)
|
|
|
- ```boundary_open``` impose the external condition
|
|
|
- ```concentration``` netcdf of msh file containing the concentration which will be applied at the boundary [in c]
|
|
|
|
|
|
Compute the total mass of tracer in the domain
|
|
|
|
|
|
```python
|
|
|
eqTracer.compute_mass("tracer.dat")
|
|
|
```
|
|
|
|
|
|
Create the temporal solver
|
|
|
|
|
|
```python
|
|
|
loop=slim.Loop(maximum_time_step = dt, export_time = 4*dt,path="output")
|
|
|
```
|
|
|
|
|
|
Add the equation(s) you want to solve (you can solve several passive tracer at the same time
|
|
|
|
|
|
```python
|
|
|
loop.add_equation(eqTracer)
|
|
|
```
|
|
|
|
|
|
Set the time_step offline (i.e., the time step of the hydrodynamic run)
|
|
|
|
|
|
```python
|
|
|
loop.set_time_step_offline(dt, periodic = False)
|
|
|
```
|
|
|
|
|
|
Launch
|
|
|
|
|
|
```python
|
|
|
loop.run()
|
|
|
``` |