Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_moment_matching.F90
Go to the documentation of this file.
1 !**************************************************************
2 ! Author: Jakob Ameres, jakob.ameres@tum.de
3 !**************************************************************
4 
5 !Transform samples of random distributions such that certain moments are
6 !exactly matched
8 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9 #include "sll_memory.h"
10 #include "sll_working_precision.h"
11 
12  implicit none
13 
14  public :: &
16 
17  private
18 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19 
22  module procedure match_moment_1d_linear_real64
23  end interface
24 
29  end interface
30 
31 contains
32 
33 !Match mean E[X] and E[X^2] = first and second order moment
34  subroutine match_moment_1d_linear_real64(x, mean, mom2)
35  sll_real64, dimension(:), intent(inout) :: x !random samples
36  sll_real64, intent(in) :: mean, mom2 !desired first and second order moment
37  sll_real64 :: meanx, mom2x
38  sll_int32 :: num
39 
40  num = size(x)
41  meanx = sum(x)/real(num, f64)
42  mom2x = sum(x**2)/real(num, f64)
43 
44  x = (x - meanx)*sqrt((mom2 - mean**2)/(mom2x - meanx**2)) + mean
45  end subroutine match_moment_1d_linear_real64
46 
47  subroutine sll_s_match_moment_1d_weight_linear_real64(x, w, mean, mom2, num)
48  sll_real64, dimension(:), intent(inout) :: x !random samples
49  sll_real64, dimension(:), intent(in) :: w !weights
50  sll_int32, intent(in) :: num !number of samples, doestn have to coincide with size of x
51  sll_real64, intent(in) :: mean, mom2 !desired first and second order moment
52  sll_real64 :: meanx, mom2x, sumw
53 
54  meanx = sum(w*x)/real(num, f64)
55  mom2x = sum(w*x**2)/real(num, f64)
56  sumw = sum(w)/real(num, f64)
57 
58  x = (x - meanx/sumw)*sqrt((sumw*mom2 - mean**2)/(sumw*mom2x - meanx**2)) + mean/sumw
60 end module sll_m_moment_matching
!Match mean E[X] and E[X^2] = first and second order moment
!Match mean E[W X] and E[W X^2] = first and second order moment modifies only X, montecarlo estimate ...
subroutine match_moment_1d_linear_real64(x, mean, mom2)
subroutine, public sll_s_match_moment_1d_weight_linear_real64(x, w, mean, mom2, num)
    Report Typos and Errors