Commit abdfc5f2 authored by Johannes Blaschke's avatar Johannes Blaschke

added simplified histogram

parent d8407280
......@@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"n = zeros(N);\n",
"n = DistributionArray{Float64}(0., 1., N);\n",
"f = FluxArray{Float64}(N);"
]
},
......@@ -59,7 +59,17 @@
{
"data": {
"text/plain": [
"1"
"10-element Array{Float64,1}:\n",
" 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": 5,
......@@ -68,7 +78,8 @@
}
],
"source": [
"n[Integer(length(n)/2)] = 1"
"n.p[Integer(size(n)/2)] = 1;\n",
"n.p"
]
},
{
......@@ -78,7 +89,7 @@
"outputs": [],
"source": [
"fill_fr!(f);\n",
"fill_lr!(f, n);"
"fill_lr!(f, n.p);"
]
},
{
......@@ -90,16 +101,16 @@
"data": {
"text/plain": [
"10-element Array{Float64,1}:\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.13816584763737239\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.0022742765607139948\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 "
]
},
"execution_count": 7,
......@@ -120,16 +131,16 @@
"data": {
"text/plain": [
"10-element Array{Float64,1}:\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.8618341523626276\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.997725723439286\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 "
]
},
"execution_count": 8,
......@@ -189,17 +200,17 @@
"data": {
"text/plain": [
"11-element Array{Float64,1}:\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 138.1658476373724\n",
" -861.8341523626276\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",
" 2.2742765607139948\n",
" -997.725723439286 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 "
]
},
"execution_count": 11,
......@@ -229,17 +240,17 @@
"data": {
"text/plain": [
"11-element Array{Float64,1}:\n",
" -0.42054232430683963\n",
" -0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.9582299402193841 \n",
" 9.427963410111976 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" -0.0 \n",
" 0.6927609681908308 "
" -0.8640646960498399\n",
" 0.0 \n",
" 0.0 \n",
" -0.0 \n",
" 0.3672085709169771\n",
" -2.924360797089483 \n",
" 0.0 \n",
" 0.0 \n",
" -0.0 \n",
" 0.0 \n",
" 0.3838915655069409"
]
},
"execution_count": 13,
......@@ -270,15 +281,15 @@
"text/plain": [
"11-element Array{Float64,1}:\n",
" 0.0 \n",
" -0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.9582299402193841\n",
" 9.427963410111976 \n",
" 0.0 \n",
" -0.0 \n",
" 0.3672085709169771\n",
" -2.924360797089483 \n",
" 0.0 \n",
" 0.0 \n",
" -0.0 \n",
" 0.0 \n",
" 0.0 "
]
},
......
module FP
export FluxArray, size, reset!, fill_fr!, fill_lr!, fill_df!, fill_sf!, apply_bc!
export DistributionArray
export size
export FluxArray, reset!, fill_fr!, fill_lr!, fill_df!, fill_sf!, apply_bc!
import Base.size
import Random.rand!
......@@ -10,6 +12,35 @@ include("sample.jl")
import .Sample
"""
DistributionArrays store the distribution (probablity) `p` data, together with
the cell-center `xc` and face-center `xf` coodrdinates. This is essentially a
cheap histogram.
"""
mutable struct DistributionArray{T}
xc::Array{T};
xf::Array{T};
p::Array{T};
function DistributionArray{T}(xlo::T, xhi::T, n::Integer) where T
p::Array{T} = zeros(n);
xf::Array{T} = collect(range(xlo, stop = xhi, length = n+1));
dx::T = (xhi-xlo)/n;
xc::Array{T} = xf[1:n] .+ dx/2;
new{T}(xc, xf, p)
end
end
function size(d::DistributionArray{T}) where T
return size(d.p, 1)
end
"""
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` where `n`
......@@ -18,23 +49,23 @@ is the argument of the constructor).
mutable struct FluxArray{T}
# Fluxes
total::Array{T}
diffusive::Array{T}
stochastic::Array{T}
total::Array{T};
diffusive::Array{T};
stochastic::Array{T};
# Left and Right sampling
fr::Array{T}
left::Array{T}
right::Array{T}
fr::Array{T};
left::Array{T};
right::Array{T};
# Storage for the Dististribution object (used to sample Gaussian random variables)
distribution
distribution;
"""
Constructor: allocates memory for all fluxes, and intializes the distribution
object. Note that `n` is the length of the corresponding 1D data array.
"""
function FluxArray{T}(n) where T
function FluxArray{T}(n::Integer) where T
total::Array{T} = zeros(n + 1);
diffusive::Array{T} = zeros(n + 1);
stochastic::Array{T} = zeros(n + 1);
......
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