tstXSChange.f90

./Manager/wrap/tests/tstXSChange.f90

1 program tstxschange
2 
5 
6 use origen_testpaths_m
7 use dbcf_m
8 !
9 use nemesis_comm, only: build_types, initialize, finalize, node
10 
11 
12 #include "ScaleSTL/FortranTestMacros.h"
13 
14 implicit none
15 
16 type(origen_casewrapper) :: casew
17 type(origen_librarywrapper) :: libw
18 
19 
20 integer :: itot,nsteps
21 real(C_DOUBLE), allocatable :: times(:)
22 real(C_DOUBLE),allocatable :: conc_buffer1(:),conc_buffer2(:,:)
23 real(C_DOUBLE), allocatable :: fluxes(:) !will depend on number of steps
24 integer,parameter :: nnucl0=2
25 real(C_DOUBLE) :: conc0(nnucl0)
26 integer :: nucl0(nnucl0), typ0(nnucl0)
27 integer,allocatable :: myids(:)
28 real(C_DOUBLE),allocatable :: myxs(:)
29 integer :: kfound
30 logical :: mt_set(200)
31 
32 integer,allocatable :: all_nucl(:), all_typ(:),all_mt(:),all_loc(:)
33 real(C_DOUBLE),allocatable :: conc(:,:),all_tocap(:),all_fiss(:)
34 
35 integer :: i,j,ilite,iact,ifp
36 real(C_DOUBLE) :: dt,myfis
37 ! CHARACTER(len=255) :: cwd
38 ! CALL getcwd(cwd)
39 ! write(ERROR_UNIT,*)TRIM(cwd)
40 
41 call initialize
42 call build_types
43 if( node() /= 0 ) call finalize
44 !initialize input
45 nsteps=3
46 allocate(times(0:nsteps),fluxes(1:nsteps))
47 dt=100
48 times(0)=0.d0
49 do i=1,nsteps
50  times(i)=times(i-1)+dt
51 end do
52 times=times*86400.d0 !units from days to seconds
53 fluxes=1.e14;
54 
55 nucl0=[922350,922380]
56 conc0=[0.05d0,0.95d0]
57 typ0=[origen_sublib_2ac,origen_sublib_2ac] !Origen_SUBLIB_1LT,Origen_SUBLIB_3FP also available
58 
59 
60 
61 !get data
62 call libw % initialize(pwrlib_filepath) !library must be initialized and loaded OUTSIDE the loop
63 itot=libw % get_itot()
64 allocate( conc(0:nsteps,1:itot) )
65 allocate(conc_buffer1(itot))
66 allocate(myids(2),myxs(2))
67 myids(1) = libw % find_nuclide_guess(922350)
68 myids(2) = libw % find_nuclide_guess(922380)
69 myxs(1) = libw % get_xs(myids(1),18)
70 
71 call test_times_array(libw)
72 
73 if( .false. )then
74 ! write(ERROR_UNIT,*)'my U-235 guess=',myids(1)
75 ! write(ERROR_UNIT,*)'my U-238 guess=',myids(2)
76 ! write(ERROR_UNIT,*)'my U-235 fission xs=',myxs(1),' kfound='
77 
78 ! write(ERROR_UNIT,*)'print_transitions'
79  call libw % print_transitions_for(922350,18);
80 ! write(ERROR_UNIT,*)'print info'
81  call libw % print_info();
82 ! write(ERROR_UNIT,*)'print library'
83  call libw % library_printout(.true.,.true.,.true.);
84 end if
85 
86 call libw % get_nucl(all_nucl)
87 call libw % get_typ_nuc(all_typ)
88 call libw % get_fiss(all_fiss)
89 call libw % get_tocap(all_tocap)
90 !write(ERROR_UNIT,*)'size(all_nucl)=',size(all_nucl)
91 !write(ERROR_UNIT,*)'size(all_typ)=',size(all_typ)
92 
93 !write(ERROR_UNIT,*)'for all isotopes:'
94 !write(ERROR_UNIT,'(a5,4(x,a12))')'n','nucl','type','fiss','tocap'
95 !1:ilite Origen_SUBLIB_1LT
96 !ilite+1:ilite+iact Origen_SUBLIB_2AC
97 !ilite+iact+1:ilite+iact+ifp Origen_SUBLIB_3FP
98 ilite=libw % get_ilite()
99 iact=libw % get_iact()
100 ifp=libw % get_ifp()
101 do i=1,itot
102  if( i>=(1+ilite) .AND. i<=(ilite+iact) )then
103  expect_eq(origen_sublib_2ac, all_typ(i)) ! Should be actinide
104  myfis=all_fiss(i-ilite)
105  else
106  myfis=0
107  end if
108 ! write(ERROR_UNIT,'(i5,2(x,i12),2(x,es12.5))')i,all_nucl(i),all_typ(i),myfis,all_tocap(i)
109 end do
110 
111 call libw % get_mt(all_mt)
112 call libw % get_loc(all_loc)
113 !write(ERROR_UNIT,*)'size(all_mt)=',size(all_mt)
114 !write(ERROR_UNIT,*)'size(all_loc)=',size(all_loc)
115 
116 if( .true. )then
117 ! write(ERROR_UNIT,*)'for all nonzeros in the matrix:'
118 ! write(ERROR_UNIT,'(a5,3(x,a12))')'n','mt','loc','parent'
119  do i=1,libw % get_non()
120 ! write(ERROR_UNIT,'(i5,3(x,i12))')i,all_mt(i),all_loc(i),all_nucl(all_loc(i))
121  mt_set(abs(all_mt(i)))=.true.
122  end do
123  mt_set=.false.
124  do i=1,200
125  if(mt_set(i))write(error_unit,*)mt_set(i)
126  end do
127 end if
128 
129 !stop
130 
131 do i=1,nsteps
132  call casew % initialize(libw)
133  expect_eq(itot,casew % total_nuclides())
134  call casew % set_times(times(i-1:i)) !only 1 step
135  call casew % set_fluxes(fluxes(i:i))
136 
137  !we need a special condition for the first step we will pass in the initial concentrations
138  !which are a much shorter list and we need to get the full nuclide ids and types lists
139  !for future steps
140  if( i==1 )then
141  call casew % set_initial_concentrations(nnucl0,nucl0,conc0,typ0,origen_concentrationunit_gatoms)
142 
143  !now we are in the general looping regime
144  else
145  conc_buffer1=conc(i-1,1:itot) !pass in beginning of time step concentrations
146  call casew % set_initial_concentrations_by_vector(conc_buffer1,origen_concentrationunit_gatoms)
147  endif
148 
149  !the big run
150  call casew % run()
151 
152  !extract beginning and end-of step
153  call casew % get_concentrations(conc_buffer2)
154  conc(i-1:i,1:itot)=conc_buffer2
155 
156 end do
157 
158 !destroy
159 call casew % destroy()
160 call libw % destroy()
161 
162 call finalize
163 
164 contains
165 
166 subroutine test_times_array(libwt)
167 type(origen_librarywrapper) :: libwt
168 
169 type(origen_casewrapper) :: casewt
170 real(C_DOUBLE),allocatable :: times(:)
171 real(C_DOUBLE) :: times1a(0:1)
172 real(C_DOUBLE) :: times2a(1:2)
173 real(C_DOUBLE) :: times1b(0:2)
174 real(C_DOUBLE) :: times2b(1:3)
175 
176 
177 call casewt%initialize(libwt)
178 
179 !1a
180 times1a = [0d0,1d0]
181 call casewt%set_times(times1a)
182 expect_eq(1,casewt%nsteps())
183 call casewt%get_times(times)
184 expect_eq(0.0,times(0))
185 expect_eq(1.0,times(1))
186 expect_eq(2,size(times,1))
187 
188 !2a (same result from shifted times)
189 times2a = [0d0,1d0]
190 call casewt%set_times(times2a)
191 expect_eq(1,casewt%nsteps())
192 call casewt%get_times(times)
193 expect_eq(0.0,times(0))
194 expect_eq(1.0,times(1))
195 expect_eq(2,size(times,1))
196 
197 !1b
198 times1b = [0d0,1d0,2d0]
199 call casewt%set_times(times1b)
200 expect_eq(2,casewt%nsteps())
201 call casewt%get_times(times)
202 expect_eq(0.0,times(0))
203 expect_eq(1.0,times(1))
204 expect_eq(2.0,times(2))
205 expect_eq(3,size(times,1))
206 
207 !2b (same result from shifted times)
208 times2b = [0d0,1d0,2d0]
209 call casewt%set_times(times2b)
210 expect_eq(2,casewt%nsteps())
211 call casewt%get_times(times)
212 expect_eq(0.0,times(0))
213 expect_eq(1.0,times(1))
214 expect_eq(2.0,times(2))
215 expect_eq(3,size(times,1))
216 
217 call casewt%destroy()
218 end subroutine
219 
220 end program