Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
tpia_particle.cc
Go to the documentation of this file.
1/*
2# <<BEGIN-copyright>>
3# Copyright (c) 2010, Lawrence Livermore National Security, LLC.
4# Produced at the Lawrence Livermore National Laboratory
5# Written by Bret R. Beck, [email protected].
6# CODE-461393
7# All rights reserved.
8#
9# This file is part of GIDI. For details, see nuclear.llnl.gov.
10# Please also read the "Additional BSD Notice" at nuclear.llnl.gov.
11#
12# Redistribution and use in source and binary forms, with or without modification,
13# are permitted provided that the following conditions are met:
14#
15# 1) Redistributions of source code must retain the above copyright notice,
16# this list of conditions and the disclaimer below.
17# 2) Redistributions in binary form must reproduce the above copyright notice,
18# this list of conditions and the disclaimer (as noted below) in the
19# documentation and/or other materials provided with the distribution.
20# 3) Neither the name of the LLNS/LLNL nor the names of its contributors may be
21# used to endorse or promote products derived from this software without
22# specific prior written permission.
23#
24# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
25# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27# SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR
28# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34# <<END-copyright>>
35*/
36#include <string.h>
37#include <tpia_target.h>
38
39#if defined __cplusplus
40namespace GIDI {
41using namespace GIDI;
42#endif
43
44static int initialSizeOfList = 100, incrementalSizeOfList = 100;
45static int numberOfParticles = 0, sizeOfParticleSortedList = 0;
46static tpia_particle **particleSortedList = NULL;
47static tpia_particle *particleList = NULL, *particleListEnd = NULL;
48/*
49************************************************************
50*/
52
53 //tpia_particle *particle = xData_malloc2( smr, sizeof( tpia_particle ), 0, "particle" );
54 tpia_particle *particle = (tpia_particle*) xData_malloc2( smr, sizeof( tpia_particle ), 0, "particle" );
55
56 if( particle == NULL ) return( NULL );
57 tpia_particle_initialize( smr, particle );
58 return( particle );
59}
60/*
61************************************************************
62*/
63//int tpia_particle_initialize( statusMessageReporting *smr, tpia_particle *particle ) {
65
66 memset( particle, 0, sizeof( tpia_particle ) );
67 return( 0 );
68}
69/*
70************************************************************
71*/
73
74 int i, j;
75 tpia_particle **p;
76
77 for( i = 0, p = particleSortedList; i < numberOfParticles; i++, p++ ) {
78 if( *p == particle ) {
79 numberOfParticles--;
80 for( j = i; j < numberOfParticles; j++, p++ ) *p = p[1];
81 break;
82 }
83 }
84 if( particle == particleListEnd ) particleListEnd = particle->prior;
85 if( particle == particleList ) particleList = particle->next;
86 if( particle->prior != NULL ) particle->prior->next = particle->next;
87 if( particle->next != NULL ) particle->next->prior = particle->prior;
88 tpia_particle_release( smr, particle );
89 xData_free( smr, particle );
90 return( NULL );
91}
92/*
93************************************************************
94*/
96
97 if( particle->spectralID != NULL ) tpi_spectralID_free( smr, particle->spectralID );
98 return( 0 );
99}
100/*
101************************************************************
102*/
104
105 while( particleList != NULL ) tpia_particle_free( smr, particleList );
106 //particleSortedList = xData_free( smr, particleSortedList );
107 particleSortedList = (tpia_particle**) xData_free( smr, particleSortedList );
108 return( 0 );
109}
110/*
111************************************************************
112*/
114
115 int i, iCmp, min, mid, max, Z, A, m;
116 tpia_particle *particle;
117 char *EOP;
118
119 iCmp = 0;
120 min = mid = 0;
121 max = numberOfParticles;
122 while( min != max ) {
123 mid = ( min + max ) / 2;
124 iCmp = strcmp( name, particleSortedList[mid]->name );
125 if( iCmp == 0 ) return( particleSortedList[mid] );
126 if( iCmp < 0 ) {
127 max = mid - 1;
128 if( mid == 0 ) max = 0; }
129 else {
130 min = mid + 1;
131 if( min > max ) min = max;
132 }
133 }
134 mid = min;
135 if( numberOfParticles > 0 ) {
136 iCmp = strcmp( name, particleSortedList[mid]->name );
137 if( iCmp == 0 ) return( particleSortedList[mid] );
138 if( ( iCmp < 0 ) && ( mid != 0 ) ) {
139 mid--;
140 iCmp = strcmp( name, particleSortedList[mid]->name );
141 }
142 }
143
144 if( ( particle = tpia_particle_create( smr ) ) == NULL ) return( NULL );
145 if( ( particle->spectralID = tpi_spectralID_parse( smr, name, &(EOP) ) ) == NULL ) return( tpia_particle_free( smr, particle ) );
146 particle->name = particle->spectralID->name;
147 if( tpia_miscNameToZAm( smr, particle->name, &Z, &A, &m ) != 0 ) return( tpia_particle_free( smr, particle ) );
148 particle->prior = NULL;
149 particle->next = NULL;
150 particle->Z = Z;
151 particle->A = A;
152 particle->m = m;
153 particle->mass = tpia_particleMass_AMU( smr, particle->name );
154 if( !smr_isOk( smr ) ) return( tpia_particle_free( smr, particle ) );
155 particle->fullMass_MeV = tpia_AMU2MeV * particle->mass + particle->spectralID->level;
156
157 if( sizeOfParticleSortedList < ( numberOfParticles + 1 ) ) {
158 if( sizeOfParticleSortedList == 0 ) {
159 sizeOfParticleSortedList = initialSizeOfList; }
160 else {
161 sizeOfParticleSortedList += incrementalSizeOfList;
162 }
163 //if( ( particleSortedList = xData_realloc2( smr, particleSortedList, sizeOfParticleSortedList * sizeof( tpia_particle * ),
164 if( ( particleSortedList = (tpia_particle** ) xData_realloc2( smr, particleSortedList, sizeOfParticleSortedList * sizeof( tpia_particle * ),
165 "particleSortedList" ) ) == NULL ) return( tpia_particle_free( smr, particle ) );
166 }
167
168 if( particleList == NULL ) {
169 particle->ordinal = 0;
170 particleListEnd = particleList = particle; }
171 else {
172 particle->ordinal = particleListEnd->ordinal + 1;
173 particle->prior = particleListEnd;
174 particleListEnd->next = particle;
175 particleListEnd = particle;
176 }
177
178 if( ( mid != 0 ) || ( iCmp > 0 ) ) mid++;
179 for( i = numberOfParticles; i > mid; i-- ) particleSortedList[i] = particleSortedList[i-1];
180 particleSortedList[mid] = particle;
181 numberOfParticles++;
182
183 return( particle );
184}
185/*
186************************************************************
187*/
188//int tpia_particle_printInternalSortedList( statusMessageReporting *smr ) {
190
191 int i;
192
193 for( i = 0; i < numberOfParticles; i++ ) printf( "%s\n", particleSortedList[i]->name );
194 return( 0 );
195}
196
197#if defined __cplusplus
198}
199#endif
int smr_isOk(statusMessageReporting *smr)
double level
Definition: tpi_IDs.h:68
char * name
Definition: tpi_IDs.h:63
tpi_spectralID * spectralID
Definition: tpia_target.h:132
double fullMass_MeV
Definition: tpia_target.h:130
tpia_particle * prior
Definition: tpia_target.h:125
tpia_particle * next
Definition: tpia_target.h:126
void * tpi_spectralID_free(statusMessageReporting *smr, tpi_spectralID *spectralID)
Definition: tpi_IDs.cc:191
tpi_spectralID * tpi_spectralID_parse(statusMessageReporting *smr, char const *str, char **EOP)
Definition: tpi_IDs.cc:218
double tpia_particleMass_AMU(statusMessageReporting *smr, const char *name)
Definition: tpia_mass.cc:887
int tpia_particle_release(statusMessageReporting *smr, tpia_particle *particle)
tpia_particle * tpia_particle_getInternalID(statusMessageReporting *smr, const char *const name)
tpia_particle * tpia_particle_free(statusMessageReporting *smr, tpia_particle *particle)
int tpia_particle_initialize(statusMessageReporting *smr, tpia_particle *particle)
int tpia_particle_printInternalSortedList(statusMessageReporting *smr)
#define tpia_AMU2MeV
Definition: tpia_target.h:101
int tpia_miscNameToZAm(statusMessageReporting *smr, const char *name, int *Z, int *A, int *m)
Definition: tpia_misc.cc:105
int tpia_particle_freeInternalList(statusMessageReporting *smr)
tpia_particle * tpia_particle_create(statusMessageReporting *smr)
void * xData_free(statusMessageReporting *smr, void *p)
Definition: xDataMisc.cc:89
#define xData_malloc2(smr, size, zero, forItem)
Definition: xData.h:313
#define xData_realloc2(smr, old, size, forItem)
Definition: xData.h:314