Commit c25a94e0 authored by Johannes Blaschke's avatar Johannes Blaschke
Browse files

add left and right fluxes

parent 87a70a9b
Loading
Loading
Loading
Loading
+82 −32
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` julia
include("src/fp.jl")
```

%% Output

    Main.FP

%% Cell type:code id: tags:

``` julia
using .FP
```

%% Cell type:code id: tags:

``` julia
f = FluxArray{Float64}(10)
```

%% Output

    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])
    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))

%% Cell type:code id: tags:

``` julia
f.total[1] = 2
```

%% Output

    2

%% Cell type:code id: tags:

``` julia
f
```

%% Output

    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])

%% Cell type:code id: tags:

``` julia
f
```

%% Output

    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])
    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))

%% Cell type:code id: tags:

``` julia
size(f)
```

%% Output

    11

%% Cell type:code id: tags:

``` julia
f.total
```

%% Output

    11-element Array{Float64,1}:
     2.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0

%% Cell type:code id: tags:

``` julia
reset!(f, 0.)
```

%% Cell type:code id: tags:

``` julia
f.total
```

%% Output

    11-element Array{Float64,1}:
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0

%% Cell type:code id: tags:

``` julia
fill_fr!(f)
```

%% Output

    10-element Array{Float64,1}:
     0.2360682842072197
     0.5793307175394222
     0.529037753922956
     0.2692179337072087
     0.25318067370057373
     0.1556375949079274
     0.961760331302904
     0.6771712762431588
     0.12442636982784938
     0.3921258104088836
     0.3719488756174305
     0.7078439875853346
     0.14686744039919186
     0.7371645339687076
     0.28061514908409957
     0.06665763097169641
     0.3619721310699473
     0.5156590411935236
     0.9600217110629821
     0.0028426574179554187

%% Cell type:code id: tags:

``` julia
f.fr
```

%% Output

    10-element Array{Float64,1}:
     0.2360682842072197
     0.5793307175394222
     0.529037753922956
     0.2692179337072087
     0.25318067370057373
     0.1556375949079274
     0.961760331302904
     0.6771712762431588
     0.12442636982784938
     0.3921258104088836
     0.3719488756174305
     0.7078439875853346
     0.14686744039919186
     0.7371645339687076
     0.28061514908409957
     0.06665763097169641
     0.3619721310699473
     0.5156590411935236
     0.9600217110629821
     0.0028426574179554187

%% Cell type:code id: tags:

``` julia
fill_lr!(f)
```

%% Output

    10-element Array{Float64,1}:
      0.15640224893447258
     -0.8567724114538633
     -0.03319116142866772
     -0.015849254780078256
      0.8756940245445292
      0.05592573265792126
     -0.43241475945139746
     -0.3858741762658584
      0.31423851240411305
     -0.0027535889452761316

%% Cell type:code id: tags:

``` julia
f.left
```

%% Output

    10-element Array{Float64,1}:
     -0.225580551433496
     -0.4954587637915302
      0.43257977013920135
      0.6598113417294635
     -0.8498029315267405
      0.7326503841221602
     -0.415898912958631
      1.8333641220723385
      0.034033453904415645
     -1.9254946253093828

%% Cell type:code id: tags:

``` julia
f.right
```

%% Output

    10-element Array{Float64,1}:
      0.42049394200976353
     -1.2103972435742056
     -0.22599400751080537
     -0.021500294777815575
      3.1206227725149867
      0.8389997040499078
     -1.1946078781624154
     -0.7483126357539075
      0.32732438108735384
     -0.9686671801826372

%% Cell type:code id: tags:

``` julia
```
+13 −9
Original line number Diff line number Diff line
module FP

export FluxArray, size, reset!, fill_fr!
export FluxArray, size, reset!, fill_fr!, fill_lr!

import Base.size
import Random.rand!
@@ -21,6 +21,8 @@ struct FluxArray{T}
    left::Array{T}
    right::Array{T}

    distribution

    function FluxArray{T}(n) where T
        total::Array{T}      = zeros(n + 1);
        diffusive::Array{T}  = zeros(n + 1);
@@ -30,7 +32,9 @@ struct FluxArray{T}
        left::Array{T}  = zeros(n);
        right::Array{T} = zeros(n);

        new{T}(total, diffusive, stochastic, fr, left, right)
        d = Normal(0, 1);

        new{T}(total, diffusive, stochastic, fr, left, right, d)
    end
end

@@ -49,18 +53,18 @@ function reset!(flx::FluxArray{T}, zero::T) where T
        flx.diffusive[i]  = zero
        flx.stochastic[i] = zero
    end
    
    # for i = 1:size(flx) - 1
    #     flx.fr[i]    = zero;
    #     flx.left[i]  = zero;
    #     flx.right[i] = zero;
    # end
end

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
end


#function getFlux(n, h, N, k, D, FP, time)
#    #get the diffusive flux for FV solver
#