Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_mapping_2d.F90
Go to the documentation of this file.
1 !! eta1, eta2 are the logical coordinates which are transformed
2 !! to the physical coordinates x1, x2
3 !! The Jacobian matrix is the derivate matrix of the transformation function
4 !! the determinant of the Jacobian is needed in an integral if the transformation is used
5 !! the logical paramters are in the interval [0,1]
7  !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 #include "sll_assert.h"
9 #include "sll_memory.h"
10 #include "sll_working_precision.h"
11  implicit none
12 
13  public :: &
15 
16 
17  private
18 
19  abstract interface
20  function sll_i_eval_function( eta1, eta2, params ) result(res)
22  sll_real64, intent(in) :: eta1
23  sll_real64, intent(in) :: eta2
24  sll_real, dimension(:), intent(in) :: params
25  sll_real64 :: res
26  end function sll_i_eval_function
27  end interface
28 
30  procedure(sll_i_eval_function), pointer, nopass :: f
31  end type matrix_element
32 
34 
35  type(matrix_element), dimension(:,:), pointer :: j_matrix
36  procedure(sll_i_eval_function), pointer, nopass :: x1_func
37  procedure(sll_i_eval_function), pointer, nopass :: x2_func
38  sll_real64, dimension(:), pointer :: params
39 
40  contains
41  procedure :: get_x1
42 
43  procedure :: get_x2
44 
45  procedure :: get_x
46 
47  procedure :: jacobian
48 
49  procedure :: jacobian_matrix
50 
52 
54 
55  procedure :: metric
56 
57  procedure :: metric_inverse
58 
59  procedure :: init
60 
61  procedure :: free
62 
63  end type sll_t_mapping_2d
64 
65 contains
66  function get_x1( self, eta1, eta2 ) result(x1)
67  class(sll_t_mapping_2d), intent(in) :: self
68  sll_real64, intent(in) :: eta1
69  sll_real64, intent(in) :: eta2
70  sll_real64 :: x1
71 
72  x1=self%x1_func(eta1,eta2,self%params)
73 
74  end function get_x1
75 
76  function get_x2( self, eta1, eta2 ) result(x2)
77  class(sll_t_mapping_2d), intent(in) :: self
78  sll_real64, intent(in) :: eta1
79  sll_real64, intent(in) :: eta2
80  sll_real64 :: x2
81  x2=self%x2_func(eta1,eta2,self%params)
82 
83  end function get_x2
84 
85  function get_x( self, eta1, eta2 ) result(x)
86  class(sll_t_mapping_2d), intent(in) :: self
87  sll_real64, intent(in) :: eta1
88  sll_real64, intent(in) :: eta2
89  sll_real64 :: x(2)
90  x(1)=self%x1_func(eta1,eta2,self%params)
91  x(2)=self%x2_func(eta1,eta2,self%params)
92  end function get_x
93 
94 
95  function jacobian(self, eta1, eta2)result(x)
96  class(sll_t_mapping_2d), intent(in) :: self
97  sll_real64 :: x
98  sll_real64, intent(in) :: eta1
99  sll_real64, intent(in) :: eta2
100 
101  x=self%j_matrix(1,1)%f(eta1,eta2,self%params)*&
102  self%j_matrix(2,2)%f(eta1,eta2,self%params)-&
103  self%j_matrix(1,2)%f(eta1,eta2,self%params)*&
104  self%j_matrix(2,1)%f(eta1,eta2,self%params)
105  end function jacobian
106 
107 
108 
109  function jacobian_matrix(self, eta1, eta2)result(y)
110  class(sll_t_mapping_2d), intent(in) :: self
111  sll_real64, intent(in) :: eta1
112  sll_real64, intent(in) :: eta2
113  sll_real64 :: y(2,2)
114 
115  y(1,1)=self%j_matrix(1,1)%f(eta1,eta2,self%params)
116  y(1,2)=self%j_matrix(1,2)%f(eta1,eta2,self%params)
117  y(2,1)=self%j_matrix(2,1)%f(eta1,eta2,self%params)
118  y(2,2)=self%j_matrix(2,2)%f(eta1,eta2,self%params)
119  end function jacobian_matrix
120 
121  function jacobian_matrix_inverse(self, eta1, eta2)result(y)
122  class(sll_t_mapping_2d), intent(in) :: self
123  sll_real64, intent(in) :: eta1
124  sll_real64, intent(in) :: eta2
125  sll_real64 :: y(2,2)
126 
127  y(1,1)=self%j_matrix(2,2)%f(eta1,eta2,self%params)
128  y(1,2)=-self%j_matrix(1,2)%f(eta1,eta2,self%params)
129  y(2,1)=-self%j_matrix(2,1)%f(eta1,eta2,self%params)
130  y(2,2)=self%j_matrix(1,1)%f(eta1,eta2,self%params)
131  y=y/self%jacobian(eta1, eta2)
132  end function jacobian_matrix_inverse
133 
134  function jacobian_matrix_inverse_transposed(self, eta1, eta2)result(y)
135  class(sll_t_mapping_2d), intent(in) :: self
136  sll_real64, intent(in) :: eta1
137  sll_real64, intent(in) :: eta2
138  sll_real64 :: y(2,2)
139 
140  y(1,1)=self%j_matrix(2,2)%f(eta1,eta2,self%params)
141  y(1,2)=-self%j_matrix(2,1)%f(eta1,eta2,self%params)
142  y(2,1)=-self%j_matrix(1,2)%f(eta1,eta2,self%params)
143  y(2,2)=self%j_matrix(1,1)%f(eta1,eta2,self%params)
144  y=y/self%jacobian(eta1, eta2)
146 
147  function metric(self, eta1, eta2)result(g)
148  class(sll_t_mapping_2d), intent(in) :: self
149  sll_real64, intent(in) :: eta1
150  sll_real64, intent(in) :: eta2
151  sll_real64 :: y(2,2)
152  sll_real64 :: g(2,2)
153  y=self%jacobian_matrix(eta1, eta2)
154  g(1,1)=y(1,1)**2+y(2,1)**2
155  g(1,2)=y(1,1)*y(1,2)+y(2,1)*y(2,2)
156  g(2,1)=g(1,2)
157  g(2,2)=y(1,2)**2+y(2,2)**2
158  end function metric
159 
160 
161  function metric_inverse(self, eta1, eta2)result(y)
162  class(sll_t_mapping_2d), intent(in) :: self
163  sll_real64, intent(in) :: eta1
164  sll_real64, intent(in) :: eta2
165  sll_real64 :: y(2,2)
166  sll_real64 :: g(2,2)
167  y=self%jacobian_matrix_inverse_transposed(eta1, eta2)
168  g(1,1)=y(1,1)**2+y(2,1)**2
169  g(1,2)=y(1,1)*y(1,2)+y(2,1)*y(2,2)
170  g(2,1)=g(1,2)
171  g(2,2)=y(1,2)**2+y(2,2)**2
172  end function metric_inverse
173 
174 
175  subroutine init(self,j11,j12,j21,j22,x1_func,x2_func,params)
176  class(sll_t_mapping_2d), intent(out) :: self
177  procedure(sll_i_eval_function) :: j11
178  procedure(sll_i_eval_function) :: j12
179  procedure(sll_i_eval_function) :: j21
180  procedure(sll_i_eval_function) :: j22
181  procedure(sll_i_eval_function) :: x1_func
182  procedure(sll_i_eval_function) :: x2_func
183  sll_real64, dimension(:), intent(in) :: params
184  !local variables
185  sll_int32 :: ierr
186 
187  sll_allocate(self%j_matrix(2,2), ierr)
188  sll_allocate(self%params(size(params)),ierr)
189  self%x1_func => x1_func
190  self%x2_func => x2_func
191  self%j_matrix(1,1)%f=>j11
192  self%j_matrix(1,2)%f=>j12
193  self%j_matrix(2,1)%f=>j21
194  self%j_matrix(2,2)%f=>j22
195  self%params=params
196  end subroutine init
197 
198  subroutine free(self)
199  class(sll_t_mapping_2d), intent(inout) :: self
200  DEALLOCATE(self%j_matrix)
201  DEALLOCATE(self%params)
202  end subroutine free
203 
204 
205 end module sll_m_mapping_2d
real(kind=f64) function, dimension(2, 2) jacobian_matrix_inverse(self, eta1, eta2)
real(kind=f64) function jacobian(self, eta1, eta2)
real(kind=f64) function, dimension(2, 2) jacobian_matrix_inverse_transposed(self, eta1, eta2)
real(kind=f64) function, dimension(2, 2) jacobian_matrix(self, eta1, eta2)
real(kind=f64) function get_x1(self, eta1, eta2)
subroutine init(self, j11, j12, j21, j22, x1_func, x2_func, params)
real(kind=f64) function, dimension(2, 2) metric(self, eta1, eta2)
real(kind=f64) function, dimension(2) get_x(self, eta1, eta2)
real(kind=f64) function, dimension(2, 2) metric_inverse(self, eta1, eta2)
real(kind=f64) function get_x2(self, eta1, eta2)
subroutine free(self)
Module to select the kind parameter.
    Report Typos and Errors