Commit 35cb4161 authored by Johannes Blaschke's avatar Johannes Blaschke

correct implementation of the `left` and `right` fluxes

parent c25a94e0
......@@ -37,7 +37,7 @@
{
"data": {
"text/plain": [
"FluxArray{Float64}([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], Distributions.Normal{Float64}(μ=0.0, σ=1.0))"
"10"
]
},
"execution_count": 3,
......@@ -46,27 +46,17 @@
}
],
"source": [
"f = FluxArray{Float64}(10)"
"N = 10"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"f.total[1] = 2"
"n = zeros(N);\n",
"f = FluxArray{Float64}(N);"
]
},
{
......@@ -77,7 +67,7 @@
{
"data": {
"text/plain": [
"FluxArray{Float64}([2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], Distributions.Normal{Float64}(μ=0.0, σ=1.0))"
"1"
]
},
"execution_count": 5,
......@@ -86,27 +76,17 @@
}
],
"source": [
"f"
"n[Integer(length(n)/2)] = 1"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"size(f)"
"fill_fr!(f);\n",
"fill_lr!(f, n);"
]
},
{
......@@ -117,18 +97,17 @@
{
"data": {
"text/plain": [
"11-element Array{Float64,1}:\n",
" 2.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0"
"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 "
]
},
"execution_count": 7,
......@@ -137,197 +116,67 @@
}
],
"source": [
"f.total"
"f.left"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"reset!(f, 0.)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11-element Array{Float64,1}:\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f.total"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10-element Array{Float64,1}:\n",
" 0.3719488756174305 \n",
" 0.7078439875853346 \n",
" 0.14686744039919186 \n",
" 0.7371645339687076 \n",
" 0.28061514908409957 \n",
" 0.06665763097169641 \n",
" 0.3619721310699473 \n",
" 0.5156590411935236 \n",
" 0.9600217110629821 \n",
" 0.0028426574179554187"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fill_fr!(f)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10-element Array{Float64,1}:\n",
" 0.3719488756174305 \n",
" 0.7078439875853346 \n",
" 0.14686744039919186 \n",
" 0.7371645339687076 \n",
" 0.28061514908409957 \n",
" 0.06665763097169641 \n",
" 0.3619721310699473 \n",
" 0.5156590411935236 \n",
" 0.9600217110629821 \n",
" 0.0028426574179554187"
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.5162642109009137\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 "
]
},
"execution_count": 11,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f.fr"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10-element Array{Float64,1}:\n",
" 0.15640224893447258 \n",
" -0.8567724114538633 \n",
" -0.03319116142866772 \n",
" -0.015849254780078256 \n",
" 0.8756940245445292 \n",
" 0.05592573265792126 \n",
" -0.43241475945139746 \n",
" -0.3858741762658584 \n",
" 0.31423851240411305 \n",
" -0.0027535889452761316"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fill_lr!(f)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10-element Array{Float64,1}:\n",
" -0.225580551433496 \n",
" -0.4954587637915302 \n",
" 0.43257977013920135 \n",
" 0.6598113417294635 \n",
" -0.8498029315267405 \n",
" 0.7326503841221602 \n",
" -0.415898912958631 \n",
" 1.8333641220723385 \n",
" 0.034033453904415645\n",
" -1.9254946253093828 "
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f.left"
"f.right"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10-element Array{Float64,1}:\n",
" 0.42049394200976353 \n",
" -1.2103972435742056 \n",
" -0.22599400751080537 \n",
" -0.021500294777815575\n",
" 3.1206227725149867 \n",
" 0.8389997040499078 \n",
" -1.1946078781624154 \n",
" -0.7483126357539075 \n",
" 0.32732438108735384 \n",
" -0.9686671801826372 "
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 1.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0\n",
" 0.0"
]
},
"execution_count": 15,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f.right"
"f.left .+ f.right"
]
},
{
......
......@@ -6,7 +6,7 @@ import Base.size
import Random.rand!
import Distributions.Normal
struct FluxArray{T}
mutable struct FluxArray{T}
#
# FluxArrays store flux data as Struct-of-Arrays. These arrays are allocated
# and initialized (to zero) by the constructor (each array has length `n+1`
......@@ -59,9 +59,11 @@ function fill_fr!(flx::FluxArray{T}) where T
rand!(flx.fr);
end
function fill_lr!(flx::FluxArray{T}) where T
rand!(flx.distribution, flx.left) .* (1 .- flx.fr)
rand!(flx.distribution, flx.right) .* flx.fr
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
......
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