Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCGIDI_pop.cc
Go to the documentation of this file.
1 /*
2 # <<BEGIN-copyright>>
3 # <<END-copyright>>
4 */
5 
6 #include <string.h>
7 #include <PoPs.h>
8 
9 #include "MCGIDI.h"
10 
11 #if defined __cplusplus
12 namespace GIDI {
13 using namespace GIDI;
14 #endif
15 
16 /*
17 ************************************************************
18 */
20 
21  MCGIDI_POPs *pops;
22 
23  if( ( pops = (MCGIDI_POPs *) smr_malloc2( smr, sizeof( MCGIDI_POPs ), 0, "pops->sorted" ) ) == NULL ) return( NULL );
24  if( MCGIDI_POPs_initial( smr, pops, size ) ) smr_freeMemory( (void **) &pops );
25  return( pops );
26 }
27 /*
28 ************************************************************
29 */
30 int MCGIDI_POPs_initial( statusMessageReporting * /*smr*/, MCGIDI_POPs *pops, int size ) {
31 
32  memset( pops, 0, sizeof( MCGIDI_POPs ) );
33  if( size < 10 ) size = 10;
34  pops->increment = size;
35 
36  return( 0 );
37 }
38 /*
39 ************************************************************
40 */
41 void *MCGIDI_POPs_free( MCGIDI_POPs *pops ) {
42 
43  if( pops == NULL ) return( NULL );
44  MCGIDI_POPs_release( pops );
45  smr_freeMemory( (void **) &pops );
46  return( NULL );
47 }
48 /*
49 ************************************************************
50 */
52 
53  MCGIDI_POP *pop, *next;
54 
55  if( pops == NULL ) return( 0 );
56  for( pop = pops->first; pop != NULL; pop = next ) {
57  next = pop->next;
58  MCGIDI_POP_free( pop );
59  }
60  smr_freeMemory( (void **) &(pops->sorted) );
61  MCGIDI_POPs_initial( NULL, pops, 0 );
62  return( 0 );
63 }
64 /*
65 ************************************************************
66 */
68  double level_MeV, MCGIDI_POP *parent, int globalParticle ) {
69 
70  int i, index;
71  MCGIDI_POP *pop;
72 
73  if( ( index = MCGIDI_POPs_findParticleIndex( pops, name ) ) >= 0 ) return( pops->sorted[index] );
74  if( pops->size == pops->numberOfPOPs ) {
75  int size = pops->size + pops->increment;
76  MCGIDI_POP **sorted = (MCGIDI_POP **) smr_malloc2( smr, size * sizeof( MCGIDI_POP * ), 0, "sorted" );
77 
78  if( sorted == NULL ) return( NULL );
79  for( i = 0; i < pops->numberOfPOPs; i++ ) sorted[i] = pops->sorted[i];
80  smr_freeMemory( (void **) &(pops->sorted) );
81  pops->sorted = sorted;
82  pops->size = size;
83  }
84  index = -index - 1;
85  if( ( pop = MCGIDI_POP_new( smr, name, mass_MeV, level_MeV, parent ) ) == NULL ) return( NULL );
86  for( i = pops->numberOfPOPs; i > index; i-- ) pops->sorted[i] = pops->sorted[i-1];
87  pops->sorted[index] = pop;
88  if( pops->first == NULL ) {
89  pops->first = pop; }
90  else {
91  pops->last->next = pop;
92  }
93  pops->last = pop;
94  pops->numberOfPOPs++;
95  pop->globalPoPsIndex = -1;
96  if( globalParticle ) {
97  if( ( pop->globalPoPsIndex = lPoPs_addParticleIfNeeded( smr, name, "LLNL" ) ) < 0 ) return( NULL );
98  }
99  return( pop );
100 }
101 /*
102 ************************************************************
103 */
104 int MCGIDI_POPs_findParticleIndex( MCGIDI_POPs *pops, char const *name ) {
105 
106  int iCmp = 0, min = 0, mid = 0, max = pops->numberOfPOPs;
107 
108  if( max == 0 ) return( -1 );
109  while( ( max - min ) > 1 ) {
110  mid = ( min + max ) / 2;
111  iCmp = strcmp( name, pops->sorted[mid]->name );
112  if( iCmp == 0 ) return( mid );
113  if( iCmp < 0 ) {
114  max = mid; }
115  else {
116  min = mid;
117  }
118  } // Loop checking, 11.05.2015, T. Koi
119  if( max == 1 ) { /* First point is not checked as loop exits when ( max = 1 ) - ( min = 0 ) !> 1 ). */
120  if( strcmp( name, pops->sorted[0]->name ) == 0 ) return( 0 );
121  }
122  if( max < pops->numberOfPOPs ) {
123  if( strcmp( name, pops->sorted[max]->name ) == 0 ) return( max );
124  }
125  if( max == 1 ) {
126  if( strcmp( name, pops->sorted[0]->name ) < 0 ) return( -1 );
127  }
128  return( -max - 1 );
129 }
130 /*
131 ************************************************************
132 */
134 
135  int index = MCGIDI_POPs_findParticleIndex( pops, name );
136 
137  if( index < 0 ) return( NULL );
138  return( pops->sorted[index] );
139 }
140 /*
141 ************************************************************
142 */
143 void MCGIDI_POPs_writeSortedList( MCGIDI_POPs *pops, FILE *f ) {
144 
145  int i;
146 
147  fprintf( f, "POPs Information: n = %d\n", pops->numberOfPOPs );
148  for( i = 0; i < pops->numberOfPOPs; i++ ) fprintf( f, " %-20s %e\n", pops->sorted[i]->name, pops->sorted[i]->mass_MeV );
149 }
150 /*
151 ************************************************************
152 */
154 
155  MCGIDI_POPs_writeSortedList( pops, stdout );
156 }
157 
158 
159 /*
160 ********* MCGIDI_POP routines *********
161 */
162 /*
163 ************************************************************
164 */
165 MCGIDI_POP *MCGIDI_POP_new( statusMessageReporting *smr, char const *name, double mass_MeV, double level_MeV, MCGIDI_POP *parent ) {
166 
167  int Z, A, m, level;
168  MCGIDI_POP *pop = (MCGIDI_POP *) smr_malloc2( smr, sizeof( MCGIDI_POP ), 0, "pop" );
169 
170  if( pop == NULL ) return( NULL );
171  pop->next = NULL;
172  pop->parent = parent;
173  if( ( pop->name = smr_allocateCopyString2( smr, name, "pop->name" ) ) == NULL ) {
174  smr_freeMemory( (void **) &pop );
175  return( NULL );
176  }
177  MCGIDI_miscNameToZAm( smr, name, &Z, &A, &m, &level );
178  pop->Z = Z;
179  pop->A = A;
180  pop->level = level;
181  pop->m = m;
182  pop->mass_MeV = mass_MeV;
183  pop->level_MeV = level_MeV;
184  pop->numberOfGammaBranchs = 0;
185  pop->gammas = NULL;
186  return( pop );
187 }
188 /*
189 ************************************************************
190 */
192 
193  if( pop == NULL ) return( NULL );
194  MCGIDI_POP_release( pop );
195  smr_freeMemory( (void **) &pop );
196  return( NULL );
197 }
198 /*
199 ************************************************************
200 */
202 
203  if( pop == NULL ) return( NULL );
204  smr_freeMemory( (void **) &(pop->name) );
205  pop->numberOfGammaBranchs = 0;
206  if( pop->gammas != NULL ) smr_freeMemory( (void **) &(pop->gammas) );
207  return( NULL );
208 }
209 /*
210 ************************************************************
211 */
213 
214  return( pop->mass_MeV );
215 }
216 
217 #if defined __cplusplus
218 }
219 #endif
220 
const XML_Char * name
Definition: expat.h:151
int MCGIDI_POPs_findParticleIndex(MCGIDI_POPs *pops, char const *name)
Definition: MCGIDI_pop.cc:104
#define smr_allocateCopyString2(smr, s, forItem)
void * MCGIDI_POPs_free(MCGIDI_POPs *pops)
Definition: MCGIDI_pop.cc:41
void MCGIDI_POPs_writeSortedList(MCGIDI_POPs *pops, FILE *f)
Definition: MCGIDI_pop.cc:143
MCGIDI_POP ** sorted
Definition: MCGIDI.h:243
MCGIDI_POP * MCGIDI_POPs_findParticle(MCGIDI_POPs *pops, char const *name)
Definition: MCGIDI_pop.cc:133
MCGIDI_POP * first
Definition: MCGIDI.h:243
MCGIDI_POP * MCGIDI_POPs_addParticleIfNeeded(statusMessageReporting *smr, MCGIDI_POPs *pops, char const *name, double mass_MeV, double level_MeV, MCGIDI_POP *parent, int globalParticle)
Definition: MCGIDI_pop.cc:67
int numberOfPOPs
Definition: MCGIDI.h:242
int lPoPs_addParticleIfNeeded(statusMessageReporting *smr, char const *name, char const *special)
Definition: lPoPs.cc:36
MCGIDI_POP * MCGIDI_POP_release(MCGIDI_POP *pop)
Definition: MCGIDI_pop.cc:201
void MCGIDI_POPs_printSortedList(MCGIDI_POPs *pops)
Definition: MCGIDI_pop.cc:153
double MCGIDI_POP_getMass_MeV(MCGIDI_POP *pop)
Definition: MCGIDI_pop.cc:212
char * name
Definition: MCGIDI.h:232
int globalPoPsIndex
Definition: MCGIDI.h:233
double A(double temperature)
static constexpr double m
Definition: G4SIunits.hh:129
MCGIDI_GammaBranching * gammas
Definition: MCGIDI.h:238
int increment
Definition: MCGIDI.h:242
MCGIDI_POP * MCGIDI_POP_free(MCGIDI_POP *pop)
Definition: MCGIDI_pop.cc:191
#define smr_malloc2(smr, size, zero, forItem)
MCGIDI_POP * last
Definition: MCGIDI.h:243
int MCGIDI_miscNameToZAm(statusMessageReporting *smr, const char *name, int *Z, int *A, int *m, int *level)
Definition: MCGIDI_misc.cc:81
double mass_MeV
Definition: MCGIDI.h:235
int MCGIDI_POPs_release(MCGIDI_POPs *pops)
Definition: MCGIDI_pop.cc:51
void * smr_freeMemory(void **p)
MCGIDI_POPs * MCGIDI_POPs_new(statusMessageReporting *smr, int size)
Definition: MCGIDI_pop.cc:19
T max(const T t1, const T t2)
brief Return the largest of the two arguments
double level_MeV
Definition: MCGIDI.h:236
int level
Definition: MCGIDI.h:234
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
MCGIDI_POP * parent
Definition: MCGIDI.h:231
int numberOfGammaBranchs
Definition: MCGIDI.h:237
MCGIDI_POP * MCGIDI_POP_new(statusMessageReporting *smr, char const *name, double mass_MeV, double level_MeV, MCGIDI_POP *parent)
Definition: MCGIDI_pop.cc:165
int MCGIDI_POPs_initial(statusMessageReporting *smr, MCGIDI_POPs *pops, int size)
Definition: MCGIDI_pop.cc:30
MCGIDI_POP * next
Definition: MCGIDI.h:230