Commit 2dc2e0b8 authored by Johannes Blaschke's avatar Johannes Blaschke

implemented diffusive and stochastic fluxes

parent 35cb4161
......@@ -33,20 +33,12 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"N = 10"
"N = 10\n",
"D = 1.;\n",
"h = 1e-3;\n",
"k = 1.;"
]
},
{
......@@ -98,16 +90,16 @@
"data": {
"text/plain": [
"10-element Array{Float64,1}:\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.4837357890990863\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 "
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.06446778552563037\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 "
]
},
"execution_count": 7,
......@@ -132,7 +124,7 @@
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.5162642109009137\n",
" 0.9355322144743696\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
......@@ -179,6 +171,126 @@
"f.left .+ f.right"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"fill_df!(f, D, h);"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11-element Array{Float64,1}:\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 64.46778552563038\n",
" -935.5322144743697 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f.diffusive"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"fill_sf!(f, D, h, k);"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11-element Array{Float64,1}:\n",
" 1.4002402012922117\n",
" -0.0 \n",
" -0.0 \n",
" -0.0 \n",
" -1.735176623280667 \n",
" -5.851512422602964 \n",
" 0.0 \n",
" -0.0 \n",
" 0.0 \n",
" -0.0 \n",
" -0.5199940022311099"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f.stochastic"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"apply_bc!(f);"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11-element Array{Float64,1}:\n",
" 0.0 \n",
" -0.0 \n",
" -0.0 \n",
" -0.0 \n",
" -1.735176623280667\n",
" -5.851512422602964\n",
" 0.0 \n",
" -0.0 \n",
" 0.0 \n",
" -0.0 \n",
" 0.0 "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f.stochastic"
]
},
{
"cell_type": "code",
"execution_count": null,
......
module FP
export FluxArray, size, reset!, fill_fr!, fill_lr!
export FluxArray, size, reset!, fill_fr!, fill_lr!, fill_df!, fill_sf!, apply_bc!
import Base.size
import Random.rand!
......@@ -60,12 +60,32 @@ function fill_fr!(flx::FluxArray{T}) where T
end
function fill_lr!(flx::FluxArray{T}, n::Array{T}) where T
#rand!(flx.distribution, flx.left) .* (1 .- flx.fr);
#rand!(flx.distribution, flx.right) .* flx.fr;
flx.left = n .* (1 .- flx.fr);
flx.right = n .* flx.fr;
end
function fill_df!(flx::FluxArray{T}, D::T, h::T) where T
for i = 2:size_cc(flx)
flx.diffusive[i] = D/h * (flx.left[i] - flx.right[i-1]);
end
end
function fill_sf!(flx::FluxArray{T}, D::T, h::T, k::T) where T
rand!(flx.distribution, flx.stochastic);
for i = 2:size_cc(flx)
flx.stochastic[i] *= sqrt(D*(flx.left[i] .+ flx.right[i-1])/(k*sqrt(h)));
# TODO: Ask Anthony about k, and if this is a nested sqrt ^^^^^^^^^^^
end
end
function apply_bc!(flx::FluxArray{T},
vd_lo::T=T(0), vd_hi::T=T(0), vs_lo::T=T(0), vs_hi::T=T(0)) where T
flx.diffusive[1] = vd_lo;
flx.diffusive[end] = vd_hi;
flx.stochastic[1] = vs_lo;
flx.stochastic[end] = vs_hi;
end
#function getFlux(n, h, N, k, D, FP, time)
# #get the diffusive flux for FV solver
......
Markdown is supported
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