tstNuclideSet.f90

./Core/dc/f/tests/tstNuclideSet.f90

1 program tstnuclideset
2 
3 #include "ScaleSTL/FortranTestMacros.h"
4 
6 use scalestl_vec_int_m
8 
9 implicit none
10 
11 type(origen_nuclideset) :: nucset,nucset2
12 type(scalestl_vec_int) :: vec_ids,inds
13 type(scalestl_vec_str) :: vec_str
14 integer,allocatable :: native_ids(:)
15 integer,parameter :: l=c_size_t
16 integer(L) :: n
17 type(scalestl_vec_int) :: remember
18 logical(C_BOOL) :: found
19 
20 !initialize a nuclide set and make sure it is empty
21 call nucset % initialize()
22 expect_true(nucset % has_ids() ) !internal ids are non-null
23 expect_eq(0,nucset % ids_size() )
24 
25 !create a Vec_Int and manage it in the nuclide set
26 !(once you use manageptr, it is owned by the NuclideSet--do not destroy)
27 call vec_ids % initialize()
28 call vec_ids % push_back(10008016)
29 call vec_ids % push_back(10008017)
30 call vec_ids % push_back(10054135)
31 call vec_ids % push_back(20092235)
32 call vec_ids % push_back(20092238)
33 call vec_ids % push_back(30054135)
34 expect_eq(6,vec_ids%size())
35 
36 !dangerous!
37 !only do this when you know exactly what's going on, e.g. in a unit test
38 remember % instance_ptr = vec_ids % instance_ptr
39 call nucset % manageptr_ids(vec_ids)
40 !has been automatically nullified to you can't kill it
41 assert_not_c_assoc(vec_ids)
42 
43 !get the pointer and make sure memory is same
44 call nucset % getptr_ids_vec(vec_ids)
45 assert_c_assoc2(remember,vec_ids)
46 
47 !get a copy of the ids in a native fortran vector
48 call nucset % get_ids(native_ids)
49 
50 expect_eq(6,size(native_ids,1))
51 expect_eq(10008016,native_ids(1))
52 expect_eq(10008017,native_ids(2))
53 expect_eq(10054135,native_ids(3))
54 expect_eq(20092235,native_ids(4))
55 expect_eq(20092238,native_ids(5))
56 expect_eq(30054135,native_ids(6))
57 
58 !check the lookup_index
59 expect_eq(1_l,nucset%lookup_index(10008016))
60 expect_eq(2_l,nucset%lookup_index(10008017))
61 expect_eq(3_l,nucset%lookup_index(10054135))
62 expect_eq(4_l,nucset%lookup_index(20092235))
63 expect_eq(5_l,nucset%lookup_index(20092238))
64 expect_eq(6_l,nucset%lookup_index(30054135))
65 
66 !not found as index (must be exact match)
67 expect_eq(nucset%NOT_FOUND(),nucset%lookup_index(54135))
68 
69 !found fission product version with last_izzzaaa lookup
70 expect_eq(6_l,nucset%lookup_index_guess(54135))
71 
72 !now get both 30054135 and 10054135
73 call inds%initialize()
74 found = nucset%lookup_index_all(inds,54135)
75 expect_true(found)
76 expect_eq(2_l,inds%size())
77 expect_eq(3_l,inds%at(1_l))
78 expect_eq(6_l,inds%at(2_l))
79 
80 !save the original with a smart/shallow copy
81 call nucset2 % initialize_copy(nucset)
82 
83 !change one value and set the new ids
84 !the data will be reallocated completely
85 native_ids(4) = 21092235
86 call nucset % set_ids(native_ids)
87 
88 !test the pointer on the new data
89 call nucset % getptr_ids_vec(vec_ids)
90 expect_eq(21092235,vec_ids%at(4_l))
91 
92 !test the pointer on the old data
93 call nucset2 % getptr_ids_vec(vec_ids)
94 expect_eq(20092235,vec_ids%at(4_l))
95 
96 !destroy and free all the smart pointers
97 call nucset % destroy()
98 call nucset2 % destroy()
99 
100 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
101 ! Test symbol_to_izzzaaa
102 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
103 call vec_ids % initialize()
104 call vec_str % initialize()
105 call vec_str % push_back("u235")
106 call vec_str % push_back("u235m")
107 call vec_str % push_back("pu239")
108 call vec_str % push_back("h1")
109 call vec_str % push_back("zr")
110 call nucset % convert_symbol_to_izzzaaa(vec_str,vec_ids)
111 expect_eq(92235,vec_ids%at(1_l))
112 expect_eq(1092235,vec_ids%at(2_l))
113 expect_eq(94239,vec_ids%at(3_l))
114 expect_eq(1001,vec_ids%at(4_l))
115 expect_eq(40000,vec_ids%at(5_l))
116 
117 call nucset % convert_sizzzaaa_to_zzzaaai(vec_ids)
118 expect_eq(922350,vec_ids%at(1_l))
119 expect_eq(922351,vec_ids%at(2_l))
120 expect_eq(942390,vec_ids%at(3_l))
121 expect_eq( 10010,vec_ids%at(4_l))
122 expect_eq(400000,vec_ids%at(5_l))
123 
124 call vec_ids % destroy()
125 call vec_str % destroy()
126 
127 end program