Loading 1d_diffusion.ipynb +27 −17 Original line number Diff line number Diff line %% Cell type:code id: tags: ``` julia include("src/flux_array.jl") include("src/fhd.jl") ``` %% Output Main.ModFluxArray Main.FHD %% Cell type:code id: tags: ``` julia using .ModFluxArray using .FHD ``` %% Cell type:code id: tags: ``` julia N = 10 D = 1.; h = 1e-3; k = 1.; ``` %% Cell type:code id: tags: ``` julia FluxArray{Float64} ``` %% Output FluxArray{Float64} %% Cell type:code id: tags: ``` julia n = DistributionArray{Float64}(0., 1., N); f = FluxArray{Float64}(N); ``` %% Cell type:code id: tags: ``` julia n.p[Integer(size(n)/2)] = 1; n.p ``` %% Output 10-element Array{Float64,1}: 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 %% Cell type:code id: tags: ``` julia fill_fr!(f); fill_lr!(f, n.p); ``` %% Cell type:code id: tags: ``` julia f.left ``` %% Output 10-element Array{Float64,1}: 0.0 0.0 0.0 0.0 0.1936697622933632 0.8892007282354997 0.0 0.0 0.0 0.0 0.0 %% Cell type:code id: tags: ``` julia f.right ``` %% Output 10-element Array{Float64,1}: 0.0 0.0 0.0 0.0 0.8063302377066368 0.11079927176450033 0.0 0.0 0.0 0.0 0.0 %% Cell type:code id: tags: ``` julia f.left .+ f.right ``` %% Output 10-element Array{Float64,1}: 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 %% Cell type:code id: tags: ``` julia fill_df!(f, D, h); ``` %% Cell type:code id: tags: ``` julia f.diffusive ``` %% Output 11-element Array{Float64,1}: 0.0 0.0 0.0 0.0 193.6697622933632 -806.3302377066368 122.48749433947626 -877.5125056605237 0.0 0.0 0.0 0.0 0.0 %% Cell type:code id: tags: ``` julia fill_sf!(f, D, h, k); ``` %% Cell type:code id: tags: ``` julia f.stochastic ``` %% Output 11-element Array{Float64,1}: 1.662956306086986 0.0 0.769796229343863 -0.0 -0.0 4.240011808025856 2.710972258785979 -0.0 0.0 -4.0441835514004545 -2.5447437949849974 -0.0 -0.0 -0.0 -0.0 -0.3416384648516665 0.36347271419150995 %% Cell type:code id: tags: ``` julia apply_bc!(f); ``` %% Cell type:code id: tags: ``` julia f.stochastic ``` %% Output 11-element Array{Float64,1}: 0.0 0.0 -0.0 -0.0 4.240011808025856 2.710972258785979 -0.0 0.0 -4.0441835514004545 -2.5447437949849974 -0.0 -0.0 -0.0 -0.0 0.0 %% Cell type:code id: tags: ``` julia ``` src/distribution_array.jl 0 → 100644 +32 −0 Original line number Diff line number Diff line #module DistributionArrayModule # export DistributionArray, size """ 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 # end No newline at end of file src/fhd.jl 0 → 100644 +18 −0 Original line number Diff line number Diff line module FHD include("flux_array.jl") #import .FluxArrayModule include("distribution_array.jl") #import .DistributionArrayModule include("sample.jl") #import .SampleModule export FluxArray, DistributionArray export size, reset!, fill_fr!, fill_lr!, fill_df!, fill_sf!, apply_bc! #size(d::FluxArray{T}) where T = FluxArrayModule.size(d) #size(d::DistributionArray{T}) where T = DistributionArrayModule.size(d) end No newline at end of file src/flux_array.jl +5 −39 Original line number Diff line number Diff line module StochFluxArray # module FluxArrayModule export DistributionArray export size export FluxArray, reset!, fill_fr!, fill_lr!, fill_df!, fill_sf!, apply_bc! # export FluxArray, size, reset!, fill_fr!, fill_lr!, fill_df!, fill_sf!, apply_bc! import Base.size import Random.rand! import Distributions.Normal 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 #include("sample.jl") #import .SampleModule """ Loading Loading @@ -181,7 +150,4 @@ function fill_ft!(flx::FluxArray{T}, h::T, k::T) where T end end end No newline at end of file # end No newline at end of file src/sample.jl +3 −3 Original line number Diff line number Diff line module Sample # module SampleModule export Proposal, rejection_sample # export Proposal, rejection_sample import Random.rand Loading Loading @@ -39,4 +39,4 @@ function rejection_sample(x::Array{T}, p::Array{T}, P::T, trials::Integer=1000) return Proposal(T(0), false); end end No newline at end of file # end No newline at end of file Loading
1d_diffusion.ipynb +27 −17 Original line number Diff line number Diff line %% Cell type:code id: tags: ``` julia include("src/flux_array.jl") include("src/fhd.jl") ``` %% Output Main.ModFluxArray Main.FHD %% Cell type:code id: tags: ``` julia using .ModFluxArray using .FHD ``` %% Cell type:code id: tags: ``` julia N = 10 D = 1.; h = 1e-3; k = 1.; ``` %% Cell type:code id: tags: ``` julia FluxArray{Float64} ``` %% Output FluxArray{Float64} %% Cell type:code id: tags: ``` julia n = DistributionArray{Float64}(0., 1., N); f = FluxArray{Float64}(N); ``` %% Cell type:code id: tags: ``` julia n.p[Integer(size(n)/2)] = 1; n.p ``` %% Output 10-element Array{Float64,1}: 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 %% Cell type:code id: tags: ``` julia fill_fr!(f); fill_lr!(f, n.p); ``` %% Cell type:code id: tags: ``` julia f.left ``` %% Output 10-element Array{Float64,1}: 0.0 0.0 0.0 0.0 0.1936697622933632 0.8892007282354997 0.0 0.0 0.0 0.0 0.0 %% Cell type:code id: tags: ``` julia f.right ``` %% Output 10-element Array{Float64,1}: 0.0 0.0 0.0 0.0 0.8063302377066368 0.11079927176450033 0.0 0.0 0.0 0.0 0.0 %% Cell type:code id: tags: ``` julia f.left .+ f.right ``` %% Output 10-element Array{Float64,1}: 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 %% Cell type:code id: tags: ``` julia fill_df!(f, D, h); ``` %% Cell type:code id: tags: ``` julia f.diffusive ``` %% Output 11-element Array{Float64,1}: 0.0 0.0 0.0 0.0 193.6697622933632 -806.3302377066368 122.48749433947626 -877.5125056605237 0.0 0.0 0.0 0.0 0.0 %% Cell type:code id: tags: ``` julia fill_sf!(f, D, h, k); ``` %% Cell type:code id: tags: ``` julia f.stochastic ``` %% Output 11-element Array{Float64,1}: 1.662956306086986 0.0 0.769796229343863 -0.0 -0.0 4.240011808025856 2.710972258785979 -0.0 0.0 -4.0441835514004545 -2.5447437949849974 -0.0 -0.0 -0.0 -0.0 -0.3416384648516665 0.36347271419150995 %% Cell type:code id: tags: ``` julia apply_bc!(f); ``` %% Cell type:code id: tags: ``` julia f.stochastic ``` %% Output 11-element Array{Float64,1}: 0.0 0.0 -0.0 -0.0 4.240011808025856 2.710972258785979 -0.0 0.0 -4.0441835514004545 -2.5447437949849974 -0.0 -0.0 -0.0 -0.0 0.0 %% Cell type:code id: tags: ``` julia ```
src/distribution_array.jl 0 → 100644 +32 −0 Original line number Diff line number Diff line #module DistributionArrayModule # export DistributionArray, size """ 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 # end No newline at end of file
src/fhd.jl 0 → 100644 +18 −0 Original line number Diff line number Diff line module FHD include("flux_array.jl") #import .FluxArrayModule include("distribution_array.jl") #import .DistributionArrayModule include("sample.jl") #import .SampleModule export FluxArray, DistributionArray export size, reset!, fill_fr!, fill_lr!, fill_df!, fill_sf!, apply_bc! #size(d::FluxArray{T}) where T = FluxArrayModule.size(d) #size(d::DistributionArray{T}) where T = DistributionArrayModule.size(d) end No newline at end of file
src/flux_array.jl +5 −39 Original line number Diff line number Diff line module StochFluxArray # module FluxArrayModule export DistributionArray export size export FluxArray, reset!, fill_fr!, fill_lr!, fill_df!, fill_sf!, apply_bc! # export FluxArray, size, reset!, fill_fr!, fill_lr!, fill_df!, fill_sf!, apply_bc! import Base.size import Random.rand! import Distributions.Normal 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 #include("sample.jl") #import .SampleModule """ Loading Loading @@ -181,7 +150,4 @@ function fill_ft!(flx::FluxArray{T}, h::T, k::T) where T end end end No newline at end of file # end No newline at end of file
src/sample.jl +3 −3 Original line number Diff line number Diff line module Sample # module SampleModule export Proposal, rejection_sample # export Proposal, rejection_sample import Random.rand Loading Loading @@ -39,4 +39,4 @@ function rejection_sample(x::Array{T}, p::Array{T}, P::T, trials::Integer=1000) return Proposal(T(0), false); end end No newline at end of file # end No newline at end of file