tadd function to perform linear interpolation between ocean time steps - Granul… | |
git clone git://src.adamsgaard.dk/Granular.jl | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 2d6071c73d309415a3db2c1233e47e8280a66cf8 | |
parent a065080672ff7a49ae2a4df6798ed69bf7c85963 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Mon, 24 Apr 2017 22:05:50 -0400 | |
add function to perform linear interpolation between ocean time steps | |
Diffstat: | |
M src/ocean.jl | 45 +++++++++++++++++++++++++++++… | |
M src/simulation.jl | 3 +++ | |
2 files changed, 48 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/src/ocean.jl b/src/ocean.jl | |
t@@ -71,3 +71,48 @@ function convertToColocatedOceanGrid(u_in::Array{float, 4}, | |
end | |
return u, v | |
end | |
+ | |
+""" | |
+Ocean data is containted in `Ocean` type at discrete times (`Ocean.time`). Th… | |
+function performs linear interpolation between time steps to get the approxima… | |
+ocean state at any point in time. If the `Ocean` data set only contains a | |
+single time step, values from that time are returned. | |
+""" | |
+function interpolateOceanState(ocean::Ocean, t::float) | |
+ if length(ocean.time) == 1 | |
+ return ocean.u, ocean.v, ocean.h, ocean.e | |
+ elseif t < ocean.time[1] || t > ocean.time[end] | |
+ error("selected time (t = $(t)) is outside the range of time steps in | |
+ the ocean data") | |
+ end | |
+ | |
+ i = 1 | |
+ rel_time = 0. | |
+ while i < length(ocean.time) | |
+ if ocean.time[i+1] < t | |
+ i += 1 | |
+ continue | |
+ end | |
+ | |
+ dt = ocean.time[i+1] - ocean.time[i] | |
+ rel_time = (t - ocean.time[i])/dt | |
+ if rel_time < 0. || rel_time > 1. | |
+ error("time bounds error") | |
+ end | |
+ break | |
+ end | |
+ | |
+ return ocean.u[:,:,:,i]*(1. - rel_time + ocean.u[:,:,:,i+1]*rel_time), | |
+ ocean.v[:,:,:,i]*(1. - rel_time + ocean.v[:,:,:,i+1]*rel_time), | |
+ ocean.h[:,:,:,i]*(1. - rel_time + ocean.h[:,:,:,i+1]*rel_time), | |
+ ocean.e[:,:,:,i]*(1. - rel_time + ocean.e[:,:,:,i+1]*rel_time) | |
+end | |
+ | |
+""" | |
+Add Stokes-type drag from velocity difference between ocean and ice floe. | |
+""" | |
+function addOceanDrag!(simulation::Simulation) | |
+ if !simulation.ocean.id | |
+ error("no ocean data read") | |
+ end | |
+end | |
diff --git a/src/simulation.jl b/src/simulation.jl | |
t@@ -108,6 +108,9 @@ function run!(simulation::Simulation; | |
zeroForcesAndTorques!(simulation) | |
findContacts!(simulation) | |
interact!(simulation) | |
+ if simulation.ocean.input_file | |
+ addOceanDrag!(simulation) | |
+ end | |
updateIceFloeKinematics!(simulation, method=temporal_integration_metho… | |
# Update time variables |