Commit 2dc2e0b8 authored by Johannes Blaschke's avatar Johannes Blaschke
Browse files

implemented diffusive and stochastic fluxes

parent 35cb4161
Loading
Loading
Loading
Loading
+86 −6
Original line number Original line Diff line number Diff line
%% Cell type:code id: tags:
%% Cell type:code id: tags:


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


%% Output
%% Output


    Main.FP
    Main.FP


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` julia
``` julia
using .FP
using .FP
```
```


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` julia
``` julia
N = 10
N = 10
D = 1.;
h = 1e-3;
k = 1.;
```
```


%% Output

    10

%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` julia
``` julia
n = zeros(N);
n = zeros(N);
f = FluxArray{Float64}(N);
f = FluxArray{Float64}(N);
```
```


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` julia
``` julia
n[Integer(length(n)/2)] = 1
n[Integer(length(n)/2)] = 1
```
```


%% Output
%% Output


    1
    1


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` julia
``` julia
fill_fr!(f);
fill_fr!(f);
fill_lr!(f, n);
fill_lr!(f, n);
```
```


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` julia
``` julia
f.left
f.left
```
```


%% Output
%% Output


    10-element Array{Float64,1}:
    10-element Array{Float64,1}:
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.4837357890990863
     0.06446778552563037
     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:
%% Cell type:code id: tags:


``` julia
``` julia
f.right
f.right
```
```


%% Output
%% Output


    10-element Array{Float64,1}:
    10-element Array{Float64,1}:
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.5162642109009137
     0.9355322144743696
     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:
%% Cell type:code id: tags:


``` julia
``` julia
f.left .+ f.right
f.left .+ f.right
```
```


%% Output
%% Output


    10-element Array{Float64,1}:
    10-element Array{Float64,1}:
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     0.0
     1.0
     1.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:
%% Cell type:code id: tags:


``` julia
``` 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
       64.46778552563038
     -935.5322144743697
        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.4002402012922117
     -0.0
     -0.0
     -0.0
     -1.735176623280667
     -5.851512422602964
      0.0
     -0.0
      0.0
     -0.0
     -0.5199940022311099

%% 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
     -1.735176623280667
     -5.851512422602964
      0.0
     -0.0
      0.0
     -0.0
      0.0

%% Cell type:code id: tags:

``` julia
```
```
+23 −3
Original line number Original line Diff line number Diff line
module FP
module FP


export FluxArray, size, reset!, fill_fr!, fill_lr!
export FluxArray, size, reset!, fill_fr!, fill_lr!, fill_df!, fill_sf!, apply_bc!


import Base.size
import Base.size
import Random.rand!
import Random.rand!
@@ -60,12 +60,32 @@ function fill_fr!(flx::FluxArray{T}) where T
end
end


function fill_lr!(flx::FluxArray{T}, n::Array{T}) where T
function fill_lr!(flx::FluxArray{T}, n::Array{T}) where T
    #rand!(flx.distribution, flx.left)  .* (1 .- flx.fr);
    #rand!(flx.distribution, flx.right) .* flx.fr;
    flx.left  = n .* (1 .- flx.fr);
    flx.left  = n .* (1 .- flx.fr);
    flx.right = n .* flx.fr;
    flx.right = n .* flx.fr;
end
end


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

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)
        flx.stochastic[i] *= sqrt(D*(flx.left[i] .+ flx.right[i-1])/(k*sqrt(h)));
        #    TODO: Ask Anthony about k, and if this is a nested sqrt ^^^^^^^^^^^
    end
end

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;
    flx.diffusive[end]  = vd_hi;
    flx.stochastic[1]   = vs_lo;
    flx.stochastic[end] = vs_hi;
end



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