Choral
ode_Lin_0d.f90
Go to the documentation of this file.
1 
25 
26 program ode_lin_0d
27 
29  use choral
30 
31  implicit none
32 
33  !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34  !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
35  !!
36  !! VARAIBLE DEFINITION : BEGIN
37  !!
38  !!
39 
40  !! verbosity level
41  integer, parameter :: verb = 2
42 
43  !! TIME DISCRETISATION
44  !!
45  !! pb = definition of the ode problem
46  !! slv = definition of the ode solver
47  !! sol = data structure for the ode solution
48  !!
49  type(ode_solution) :: sol
50  type(ode_problem) :: pb
51  type(ode_solver) :: slv
52  !! t0 = initial time
53  !! T = final time
54  !! dt = time step
55  !! L_meth = method for the non-ilinear system
56  !!
57  real(RP), parameter :: t0 = 0.0_rp
58  real(RP), parameter :: T = 1.5_rp
59  integer , parameter :: L_meth = ode_cn
60  real(RP), parameter :: dt = 0.1_rp
61  !!
62  !! OUTPUT DEF.
63  !! ode_out = definition of the output
64  type(ode_output) :: ode_out
65 
66 
67  !!
68  !! VARAIBLE DEFINITION : END
69  !!
70  !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
71  !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
72 
73 
74  call choral_init(verb=verb)
75  write(*,*) "ode_Lin_0d : start"
76 
77 
78  !!
79  !! output settings
80  !!
81  write(*,*) ""
82  write(*,*) "================================== OUTPUT SETTINGS"
83  ode_out = ode_output(t0, t, n=1)
84  call set(ode_out, verb=5)
85  call set(ode_out, vxn_period = 0.1_rp, vxn_plot=.true.)
86  if (verb>0) call print(ode_out)
87 
88 
89  !! !!!!!!!!!!!!!!!!!!!!! ODE PROBLEM DEF.
90  !!
91  write(*,*) ""
92  write(*,*) "================================== TIME DISCRETISATION"
93  !!
94  pb = ode_problem(ode_pb_lin, dim=0, m=id, s=id_m)
95  if (verb>0) call print(pb)
96 
97  !! !!!!!!!!!!!!!!!!!!!!! ODE SOLVER DEF.
98  !!
99  slv = ode_solver(pb, ode_slv_1s, l_meth=l_meth, verb=verb)
100  if (verb>0) call print(slv)
101 
102 
103  !! !!!!!!!!!!!!!!!!!!!!! ODE SOLUTION DEF.
104  !!
105  sol = ode_solution(slv, pb)
106  if (verb>0) call print(sol)
107 
108  !!!!!!!!!!!!!!!!!!!!!!! SOLVE
109  !!
110  write(*,*) ""
111  write(*,*) "================================== NUMERICAL RESOLUTION"
112  write(*,*) "================================== 1- USER-DEFINED OUTPUT"
113  !!
114  !! initial condition
115  call initialcond(sol, pb, slv, t0, (/1.0_rp/))
116  !!
117  !! set the output to the routine "user_defined_output" below
118  call set_ode_solver_output(slv, user_defined_output)
119  !!
120  !! numerical resolution
121  call solve(sol, slv, pb, t0, t, dt)!, output=ode_out)
122 
123  write(*,*) ""
124  write(*,*) "================================== NUMERICAL RESOLUTION"
125  write(*,*) "================================== 2- PRE-DEFINED OUTPUT&
126  & USING 'ode-output' type"
127  !!
128  !! initial condition
129  call initialcond(sol, pb, slv, t0, (/1.0_rp/))
130  !!
131  !! finalise the output definition
132  call assemble(ode_out, dt)
133  !!
134  !! numerical resolution
135  call solve(sol, slv, pb, t0, t, dt, output=ode_out)
136  !!
137  !! Numerical error at time T
138  write(*,*) " Error = |y_h(T) - y(T)| / |y(T)| = ", &
139  & abs(sol%V(1,1) - exp(t)) / exp(t)
140 
141  write(*,*) "ode_Lin_0d : end"
142 
143 contains
144 
145  subroutine id(yy,xx)
146  real(RP), dimension(:), intent(out) :: yy
147  real(RP), dimension(:), intent(in) :: xx
148 
149  yy = xx
150 
151  end subroutine id
152 
153  subroutine id_m(yy,xx)
154  real(RP), dimension(:), intent(out) :: yy
155  real(RP), dimension(:), intent(in) :: xx
156 
157  yy = -xx
158 
159  end subroutine id_m
160 
161  subroutine user_defined_output(tn, s, stop)
162  real(RP) , intent(in) :: tn
163  type(ode_solution), intent(in) :: s
164  logical , intent(inout) :: stop
165 
166  if (tn<=real_tol) then
167  print*, 'Solving with a user_defined_output:'
168  print*, 'Resolution method = ', name_ode_method(l_meth)
169  print*, ' Time t | y_h(t) | errro |y_h(t) - y(t)|/y(t)'
170  end if
171  print*, real(tn, SP), real(s%v, SP), real(abs(s%v-exp(tn))/exp(tn), sp)
172 
173  stop = .false.
174  end subroutine user_defined_output
175 
176 end program ode_lin_0d
subroutine, public choral_init(verb)
Initialisation for the CHORAL library
Definition: choral.F90:166
TOP-LEVEL MODULE FOR THE LIBRARY CHORAL
Definition: choral.F90:27
subroutine id_m(yy, xx)
Definition: ode_Lin_0d.f90:154
integer, parameter ode_cn
Crank Nicholson.
program ode_lin_0d
EXAMPLE FOR THE RESOLUTION OF:
Definition: ode_Lin_0d.f90:26
integer, parameter ode_pb_lin
Linear ODE : .
CHORAL CONSTANTS
subroutine user_defined_output(tn, s, stop)
Definition: ode_Lin_0d.f90:162
subroutine id(yy, xx)
Definition: ode_Lin_0d.f90:146
integer, parameter ode_slv_1s
onestep