tstCRAMInterface.f90

./Manager/wrap/tests/tstCRAMInterface.f90

1 !
2 ! Unit test for using the CRAM solver in Origen.
3 ! Author: Aarno Isotalo
4 !
5 program tstcraminterface
6 
7 #include "ScaleSTL/FortranTestMacros.h"
8 
11  !2. Add dynamic path info for ARP library.
12  use origen_testpaths_m
14  !
15  use nemesis_comm, only: build_types, initialize, finalize, node
16 
17  implicit none
18 
19  ! timing
20  integer :: count1, count2, count_rate
21 
22  !instance of origen calc class
23  !instance of origen library class
24  type(origen_casewrapper) :: casew1, casew2
25  type(origen_librarywrapper) :: libw
26 
27  !some local variables
28  integer :: itot,nsteps
29  real(C_DOUBLE), allocatable :: times(:)
30  real(C_DOUBLE), allocatable :: fluxes(:) !will depend on number of steps
31  integer,parameter :: nnucl0=2
32  real(C_DOUBLE) :: conc0(nnucl0)
33  integer :: nucl0(nnucl0), typ0(nnucl0)
34 
35  !important ones
36  real(C_DOUBLE),allocatable :: conc_fw(:,:), conc_ad(:,:)
37 
38  integer :: i,j
39  real(C_DOUBLE) :: dt
40 
41 
42  !solver options
43  integer :: solver, nterm, nshrt, cram_order, internal_steps
44  real(C_DOUBLE) :: abstol, reltol
45 
46  real(C_DOUBLE) :: dot1, dot2
47 
48  call initialize
49  call build_types
50  if(node() /= 0 ) call finalize
51 
52  nsteps=1
53  allocate(times(0:nsteps),fluxes(1:nsteps))
54  times(0)=0.d0
55  times(1)=100.0
56  times=times*86400.d0 !units from days to seconds
57  fluxes=1.e14;
58 
59  nucl0=[922350,922380]
60  conc0=[0.05d0,0.95d0]
61  !Origen_SUBLIB_1LT,Origen_SUBLIB_3FP also available
62  typ0=[origen_sublib_2ac,origen_sublib_2ac]
63 
64  call libw%initialize(pwrlib_filepath)
65  call libw%set_pos(1)
66 
67  call casew1%initialize(libw)
68  call casew1%set_times(times)
69  call casew1%set_fluxes(fluxes)
70  call casew1%set_initial_concentrations(nnucl0,nucl0,conc0,typ0,origen_concentrationunit_gatoms)
71 
72  itot = casew1 % libw % get_itot()
73 
74  ! Set the solver options (order 14 cram, normally use order 16 (default))
75  ! Also set the use of internal substeps (4)
76  call casew1%b_case%set_solver_options(2, -1, -2, -3.0d0, -4.0d0, 14, 4)
77 
78  ! Check that the options were correctly set
79  call casew1%b_case%get_solver_options(solver, nterm, nshrt, abstol, reltol, cram_order, internal_steps)
80 
81  expect_eq(2, solver)
82  expect_eq(-1, nterm)
83  expect_eq(-2, nshrt)
84  expect_eq(-3.0d0, abstol)
85  expect_eq(-4.0d0, reltol)
86  expect_eq(14, cram_order)
87  expect_eq(4, internal_steps)
88 
89  ! run and time origen
90  call system_clock(count1, count_rate)
91 
92  call casew1%run()
93  call casew1%get_concentrations(conc_fw)
94 
95  call system_clock(count2, count_rate)
96 
97  Write(*,*) "ORIGEN RUN TOOK (ms):", dble(count2-count1)/dble(count_rate)*1000.0
98 
99  ! check the results for a few nuclides to see that the calculation actually
100  ! used CRAM
101 
102  expect_near(1.1397904580875401d-5, conc_fw(1,libw%find_nuclide(origen_sublib_2ac, 942400)), 1d-10)
103  expect_near(3.1582984913113634d-7, conc_fw(1,libw%find_nuclide(origen_sublib_3fp, 541350)), 1d-10)
104 
105  ! write(*,*) conc_fw(1,libw%find_nuclide(Origen_SUBLIB_2AC, 942400))
106  ! write(*,*) conc_fw(1,libw%find_nuclide(Origen_SUBLIB_3FP, 541350))
107 
108  ! Test adjoint calculation
109 
110  nucl0=[942390,942400]
111  conc0=[2.00d0,1.5d0]
112  typ0=[origen_sublib_2ac,origen_sublib_2ac]
113 
114  call casew2%initialize(libw,.true.) !use adjoint!
115  call casew2%set_times(times)
116  call casew2%set_fluxes(fluxes)
117  call casew2%set_initial_concentrations(nnucl0,nucl0,conc0,typ0,origen_concentrationunit_gatoms)
118  call casew2%b_case%set_solver_options(2, -1, -2, -3.0d0, -4.0d0, 14, 2)
119  call casew2%run()
120  call casew2%get_concentrations(conc_ad)
121 
122  dot1 = 0.0d0
123  dot2 = 0.0d0
124  do i=1,itot
125  dot1 = dot1 + conc_fw(0,i)*conc_ad(1,i);
126  dot2 = dot2 + conc_fw(1,i)*conc_ad(0,i);
127  end do
128 
129  expect_near(1d0, dot1/dot2, 1d-10)
130 
131  !destroy
132  call casew1%destroy()
133  call libw%destroy()
134 
135  deallocate(times,fluxes)
136 
137  call finalize
138 
139 end program tstcraminterface