Commit 0943a87a authored by Berutti, Michael (Contractor) Charles's avatar Berutti, Michael (Contractor) Charles
Browse files

Added run simulation to unsteady example

parent a2f19bb9
%% Cell type:code id: tags:
``` python
import os
from fluegg.ras import RASProject
project_file_path = r'..\test\data\ras\unsteadyflume\HEC-RASFlumeCase.prj'
with RASProject(project_file_path) as rp:
data_frame = rp.hydraulic_model_data('Unsteady')
data_frame.head(9)
```
%% Output
Depth_m Q_cms Vmag_mps CumlDistance_km \\n2017-01-01 00:00:00 1 0.055352 0.001416 0.119885 7.62 \n 2 0.055076 0.001416 0.120487 22.86 \n 3 0.055350 0.001416 0.119890 30.48 \n2017-01-01 01:00:00 1 0.055322 0.001416 0.119951 7.62 \n 2 0.055108 0.001416 0.120416 22.86 \n 3 0.055320 0.001416 0.119956 30.48 \n2017-01-01 02:00:00 1 0.055322 0.001416 0.119951 7.62 \n 2 0.055108 0.001416 0.120416 22.86 \n 3 0.055320 0.001416 0.119956 30.48 \n\n Ustar_mps Vvert_mps Vlat_mps Temp_C \n2017-01-01 00:00:00 1 0.006386 0.0 0.0 22.0 \n 2 0.006421 0.0 0.0 22.0 \n 3 0.006386 0.0 0.0 22.0 \n2017-01-01 01:00:00 1 0.006390 0.0 0.0 22.0 \n 2 0.006417 0.0 0.0 22.0 \n 3 0.006390 0.0 0.0 22.0 \n2017-01-01 02:00:00 1 0.006390 0.0 0.0 22.0 \n 2 0.006417 0.0 0.0 22.0 \n 3 0.006390 0.0 0.0 22.0
%% Cell type:code id: tags:
``` python
grouped_by_time = data_frame.groupby(axis=0, level=0)
hydraulic_data = grouped_by_time.get_group(data_frame.index[0][0])
hydraulic_data.index = hydraulic_data.index.droplevel(0)
hydraulic_data
```
%% Output
Depth_m Q_cms Vmag_mps CumlDistance_km Ustar_mps Vvert_mps \\n1 0.055352 0.001416 0.119885 7.62 0.006386 0.0 \n2 0.055076 0.001416 0.120487 22.86 0.006421 0.0 \n3 0.055350 0.001416 0.119890 30.48 0.006386 0.0 \n\n Vlat_mps Temp_C \n1 0.0 22.0 \n2 0.0 22.0 \n3 0.0 22.0
%% Cell type:code id: tags:
``` python
total_simulation_time = (data_frame.index.get_level_values(0)[-1] - data_frame.index.get_level_values(0)[0]).total_seconds()
total_simulation_time
```
%% Output
212400.0
%% Cell type:code id: tags:
``` python
from fluegg.asiancarpeggs import BigheadCarpEggs
from fluegg.simclock import SimulationClock
time_step_size = 1 # seconds
simulation_clock = SimulationClock(time_step_size, total_simulation_time)
```
%% Cell type:code id: tags:
``` python
import numpy as np
first_cell_x_midpoint = 1000*hydraulic_data.loc[1, 'CumlDistance_km']/2
depth = hydraulic_data.loc[1, 'Depth_m']
first_cell_z_midpoint = -depth/2
area = hydraulic_data.loc[1, 'Q_cms']/hydraulic_data.loc[1, 'Vmag_mps']
width = area/depth
first_cell_y_midpoint = 0
initial_position = np.array([10, first_cell_y_midpoint, first_cell_z_midpoint])
number_of_eggs = 10
initial_position = np.tile(initial_position, (number_of_eggs, 1))
carp_eggs = BigheadCarpEggs(initial_position, simulation_clock)
```
%% Cell type:code id: tags:
``` python
from fluegg.transporter import init_transporter
transport_model = init_transporter(simulation_clock, carp_eggs, 'parabolic')
```
%% Cell type:code id: tags:
``` python
from fluegg.simulation import Simulation
fluegg_simulation = Simulation(carp_eggs, transport_model, simulation_clock)
```
%% Cell type:code id: tags:
``` python
from fluegg.hydraulics import RoughBottomSeriesOfHydraulicCells
start_time = data_frame.index.get_level_values(0)[0]
# initialize a hydraulic model as a series of hydraulic cells from the CSV
hydraulic_model = RoughBottomSeriesOfHydraulicCells.from_data_frame(data_frame,
start_time=start_time,
simulation_clock=simulation_clock,
simulation=fluegg_simulation)
fluegg_simulation.set_hydraulic_model(hydraulic_model)
transport_model.set_hydraulic_model(hydraulic_model)
```
%% Cell type:code id: tags:
``` python
edges = hydraulic_model.cell_edges()
edges
fluegg_simulation.run()
```
%% Output
%% Cell type:code id: tags:
array([ 0., 7620., 22860., 30480.])
``` python
edges = hydraulic_model.cell_edges()
edges
```
%% Cell type:code id: tags:
``` python
x_position = np.zeros((len(edges) + 1))
x_position[1:-1] = edges[:-1] + np.diff(edges)/2
x_position[0] = -100
x_position[-1] = edges[-1] + 100
x_position
```
%% Output
array([ -100., 3810., 15240., 26670., 30580.])
%% Cell type:code id: tags:
``` python
position = np.stack((x_position, np.zeros_like(x_position), np.zeros_like(x_position)), axis=1)
position
```
%% Output
array([[ -100., 0., 0.],\n [ 3810., 0., 0.],\n [15240., 0., 0.],\n [26670., 0., 0.],\n [30580., 0., 0.]])
%% Cell type:code id: tags:
``` python
hydraulic_data
```
%% Output
Depth_m Q_cms Vmag_mps CumlDistance_km Ustar_mps Vvert_mps \\n1 0.055352 0.001416 0.119885 7.62 0.006386 0.0 \n2 0.055076 0.001416 0.120487 22.86 0.006421 0.0 \n3 0.055350 0.001416 0.119890 30.48 0.006386 0.0 \n\n Vlat_mps Temp_C \n1 0.0 22.0 \n2 0.0 22.0 \n3 0.0 22.0
%% Cell type:code id: tags:
``` python
hydraulic_results = hydraulic_model.hydraulic_results(position)
hydraulic_results.streamwise_velocity()
```
%% Output
array([0.23171144, 0.23171144, 0.23289156, 0.2317213 , 0.2317213 ])
%% Cell type:code id: tags:
``` python
hydraulic_results.depth()
```
%% Output
array([0.05535244, 0.05535244, 0.0550757 , 0.05535011, 0.05535011])
%% Cell type:code id: tags:
``` python
hydraulic_results.shear_velocity()
```
%% Output
array([0.00638586, 0.00638586, 0.00642147, 0.00638615, 0.00638615])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment