Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_linear_pendulum_operators.F90
Go to the documentation of this file.
1 
8 
10 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 #include "sll_memory.h"
12 #include "sll_working_precision.h"
13 
14  use sll_m_operator_splitting, only: &
18 
19  implicit none
20 
21  public :: &
23 
24  private
25 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26 
33  sll_real64 :: x
34  sll_real64 :: v
35  contains
36  procedure, pass(this) :: operatort => push_x
37  procedure, pass(this) :: operatorv => push_v
39 
40  ! module global variables
41  sll_real64, parameter :: omega = 2.0_f64
42  sll_real64, parameter :: x0 = 1.0_f64
43  sll_real64, parameter :: v0 = 2.0_f64
44  sll_real64, parameter :: t_final = 1.0_f64
45 contains
46 
48  subroutine push_x(this, dt)
49  class(linear_pendulum_operators), intent(inout) :: this
50  sll_real64, intent(in) :: dt
51 
52  this%x = this%x + this%v*dt
53  end subroutine push_x
54 
56  subroutine push_v(this, dt)
57  class(linear_pendulum_operators), intent(inout) :: this
58  sll_real64, intent(in) :: dt
59 
60  this%v = this%v - omega**2*this%x*dt
61  end subroutine push_v
62 
65  subroutine sll_s_check_order(method, steps_fine, expected_order, test_passed)
66  sll_int32, intent(in) :: method
68  sll_real64, intent(in) :: steps_fine
69  sll_int32, intent(in) :: expected_order
70  logical, intent(inout) :: test_passed
71 
72  ! local variables
73  sll_real64 :: dt
74  sll_int32 :: number_time_steps
75  sll_real64 :: x_exact, v_exact
76  sll_real64 :: error0, error1, error2, order1, order2
77  type(linear_pendulum_operators), target :: my_pendulum
78  class(sll_t_operator_splitting), pointer :: split
79  !sll_int32 :: ierr
80 
81  ! initialise my_pendulum
82  split => my_pendulum
83  ! call sll_s_operator_splitting_init(split,sll_p_lie_vt)
84  ! call sll_s_operator_splitting_init(split,sll_p_strang_tvt)
85  ! call sll_s_operator_splitting_init(split,sll_p_triple_jump_tvt)
86  call sll_s_operator_splitting_init(split, method)
87 
88  ! compute exact solution at final time
89  x_exact = x0*cos(omega*t_final) + (v0/omega)*sin(omega*t_final)
90  v_exact = -x0*omega*sin(omega*t_final) + v0*cos(omega*t_final)
91 
92  ! do iterations with smallest time step
93  my_pendulum%x = x0
94  my_pendulum%v = v0
95  dt = t_final/steps_fine
96  number_time_steps = int(steps_fine, i32)
97 
98  call sll_s_do_split_steps(split, dt, number_time_steps)
99 
100  ! compute mean square error
101  error0 = sqrt((my_pendulum%x - x_exact)**2 + (my_pendulum%v - v_exact)**2)
102 
103  ! do iterations with middle time step
104  my_pendulum%x = x0
105  my_pendulum%v = v0
106  dt = 2*dt
107  number_time_steps = number_time_steps/2
108  call sll_s_do_split_steps(split, dt, number_time_steps)
109 
110  ! compute mean square error
111  error1 = sqrt((my_pendulum%x - x_exact)**2 + (my_pendulum%v - v_exact)**2)
112 
113  ! do iterations with largest time step
114  my_pendulum%x = x0
115  my_pendulum%v = v0
116  dt = 2*dt
117  number_time_steps = number_time_steps/2
118  call sll_s_do_split_steps(split, dt, number_time_steps)
119 
120  ! compute mean square error
121  error2 = sqrt((my_pendulum%x - x_exact)**2 + (my_pendulum%v - v_exact)**2)
122 
123  ! compute order
124  !print*, 'error', error0, error1, error2
125  order1 = log(error1/error0)/log(2.0_f64)
126  order2 = log(error2/error1)/log(2.0_f64)
127  if ((abs(order1 - expected_order) > 5.e-2) .or. (abs(order2 - expected_order) > 5.e-2)) then
128  test_passed = .false.
129  print *, 'error coarse =', error2
130  print *, 'error middle =', error1
131  print *, ' order (coarse/middle) =', order2
132  print *, 'error fine =', error0
133  print *, ' order (middle/fine) =', order1
134  end if
135  end subroutine sll_s_check_order
136 
Implements split operators for linear pendulum.
real(kind=f64), parameter omega
frequency
subroutine, public sll_s_check_order(method, steps_fine, expected_order, test_passed)
checks the order of a splitting method on the linear pendulum. used for unit testing.
real(kind=f64), parameter t_final
final time for order checking
subroutine push_v(this, dt)
Implements the second operator of splitting for linear pendulum.
real(kind=f64), parameter v0
initial v for order checking
subroutine push_x(this, dt)
Implements the first operator of splitting for linear pendulum.
real(kind=f64), parameter x0
initial x for order checking
Base class of operator splitting library. It is only used with particle-in-cell method.
subroutine, public sll_s_do_split_steps(split, dt, number_time_steps)
Apply the composition method for given number of times steps.
subroutine, public sll_s_operator_splitting_init(split, split_case, split_step, nb_split_step, split_begin_T, dt)
Initialises data for operator splitting.
Simple operator splitting type for linear pendulum Extends operator splitting.
    Report Typos and Errors