Commit fecf6229 authored by Johannes Blaschke's avatar Johannes Blaschke

add docstrings

parent 2dc2e0b8
......@@ -90,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.06446778552563037\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.4618638805059607\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 "
]
},
"execution_count": 7,
......@@ -124,7 +124,7 @@
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.9355322144743696\n",
" 0.5381361194940393\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
......@@ -189,17 +189,17 @@
"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 "
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 461.8638805059607\n",
" -538.1361194940392\n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 \n",
" 0.0 "
]
},
"execution_count": 11,
......@@ -229,17 +229,17 @@
"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"
" -0.5929904221281879 \n",
" -0.0 \n",
" -0.0 \n",
" 0.0 \n",
" -4.280339552006784 \n",
" 2.185681116243459 \n",
" 0.0 \n",
" -0.0 \n",
" 0.0 \n",
" -0.0 \n",
" -0.31415706471809324"
]
},
"execution_count": 13,
......@@ -253,7 +253,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
......@@ -262,7 +262,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 15,
"metadata": {},
"outputs": [
{
......@@ -272,9 +272,9 @@
" 0.0 \n",
" -0.0 \n",
" -0.0 \n",
" -0.0 \n",
" -1.735176623280667\n",
" -5.851512422602964\n",
" 0.0 \n",
" -4.280339552006784\n",
" 2.185681116243459\n",
" 0.0 \n",
" -0.0 \n",
" 0.0 \n",
......@@ -282,7 +282,7 @@
" 0.0 "
]
},
"execution_count": 16,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
......@@ -301,15 +301,15 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.1.1",
"display_name": "Julia 1.2.0",
"language": "julia",
"name": "julia-1.1"
"name": "julia-1.2"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.1.1"
"version": "1.2.0"
}
},
"nbformat": 4,
......
......@@ -6,28 +6,35 @@ import Base.size
import Random.rand!
import Distributions.Normal
"""
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`
is the argument of the constructor).
"""
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`
# where `n` is the argument of the constructor).
#
# Fluxes
total::Array{T}
diffusive::Array{T}
stochastic::Array{T}
# Left and Right sampling
fr::Array{T}
left::Array{T}
right::Array{T}
distribution
# Storage for the Dististribution object (used to sample Gaussian random variables)
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
total::Array{T} = zeros(n + 1);
diffusive::Array{T} = zeros(n + 1);
stochastic::Array{T} = zeros(n + 1);
fr::Array{T} = zeros(n);
left::Array{T} = zeros(n);
right::Array{T} = zeros(n);
......@@ -38,15 +45,24 @@ mutable struct FluxArray{T}
end
end
"""
Returns the size of the FluxArray's internal face-centered Array{T} containers
"""
function size(flx::FluxArray{T}) where T
return size(flx.total, 1)
end
"""
Same as `size` but returns the FluxArray's internal cell-centered Array{T}
containers. Identical to `size(flx)-1`
"""
function size_cc(flx::FluxArray{T}) where T
return size(flx) - 1
end
"""
Resets all fluxes to the specified value `zero::T`
"""
function reset!(flx::FluxArray{T}, zero::T) where T
for i = 1:size(flx)
flx.total[i] = zero
......@@ -55,21 +71,37 @@ function reset!(flx::FluxArray{T}, zero::T) where T
end
end
"""
Fills the fr (Fraction Right) array with uniform random numbers
"""
function fill_fr!(flx::FluxArray{T}) where T
rand!(flx.fr);
end
"""
Fills the `left` and `right` fields using the data `n` and the `fr` arrays.
Note that `fill_fr!` needs to be called first for new left and right data.
"""
function fill_lr!(flx::FluxArray{T}, n::Array{T}) where T
flx.left = n .* (1 .- flx.fr);
flx.right = n .* flx.fr;
end
"""
Fills the diffusive fluxes using the `left` and `right` data. `D` is the
diffusion coefficient and `h` is the spatial discretization.
"""
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
"""
Fills the stochstic fluxes using the `left` and `right` data, as well as the
normal random numbers generated by `distribution`. `D` is the diffusion
coefficient, `h` is the spatial discretization, and `k` is unknown (TODO).
"""
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)
......@@ -78,6 +110,10 @@ function fill_sf!(flx::FluxArray{T}, D::T, h::T, k::T) where T
end
end
"""
Fills the stochastic and diffusive flux boundary conditions. Currently only
Dirichlet BCs are implemented.
"""
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;
......
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