Commit 87a70a9b authored by Johannes Blaschke's avatar Johannes Blaschke
Browse files

start computing random fluxes

parent eeae95d6
Loading
Loading
Loading
Loading
+43 −3
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])
    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])

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

%% 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

%% Cell type:code id: tags:

``` julia
```
+27 −2
Original line number Diff line number Diff line
module FP

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

import Base.size
import Random.rand!
import Distributions.Normal

struct FluxArray{T}
    #
@@ -14,12 +17,20 @@ struct FluxArray{T}
    diffusive::Array{T}
    stochastic::Array{T}

    fr::Array{T}
    left::Array{T}
    right::Array{T}
    
    function FluxArray{T}(n) where T
        total::Array{T}      = zeros(n + 1);
        diffusive::Array{T}  = zeros(n + 1);
        stochastic::Array{T} = zeros(n + 1);
        
        new{T}(total, diffusive, stochastic)
        fr::Array{T}    = zeros(n);
        left::Array{T}  = zeros(n);
        right::Array{T} = zeros(n);

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

@@ -27,14 +38,28 @@ function size(flx::FluxArray{T}) where T
    return size(flx.total, 1)
end

function size_cc(flx::FluxArray{T}) where T
    return size(flx) - 1
end


function reset!(flx::FluxArray{T}, zero::T) where T
    for i = 1:size(flx)
        flx.total[i]      = zero
        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 getFlux(n, h, N, k, D, FP, time)
#    #get the diffusive flux for FV solver