Geant4  10.01.p02
tpia_channel.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, beck6@llnl.gov.
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 
38 #include <tpia_target.h>
39 #include <tpia_misc.h>
40 
41 #if defined __cplusplus
42 namespace GIDI {
43 using namespace GIDI;
44 #endif
45 
46 static int _tpia_channel_getProductData( statusMessageReporting *smr, xData_element *channelElement, tpia_channel *channel );
47 /*
48 ************************************************************
49 */
50 tpia_channel *tpia_channel_create( statusMessageReporting *smr ) {
51 
52  tpia_channel *channel;
53 
54  //if( ( channel = xData_malloc2( smr, sizeof( tpia_channel ), 0, "channel" ) ) == NULL ) return( NULL );
55  if( ( channel = (tpia_channel*) xData_malloc2( smr, sizeof( tpia_channel ), 0, "channel" ) ) == NULL ) return( NULL );
56  if( tpia_channel_initialize( smr, channel ) ) channel = tpia_channel_free( smr, channel );
57  return( channel );
58 }
59 /*
60 ************************************************************
61 */
62 //int tpia_channel_initialize( statusMessageReporting *smr, tpia_channel *channel ) {
63 int tpia_channel_initialize( statusMessageReporting *, tpia_channel *channel ) {
64 
65  memset( channel, 0, sizeof( tpia_channel ) );
66  return( 0 );
67 }
68 /*
69 ************************************************************
70 */
71 tpia_channel *tpia_channel_createGetFromElement( statusMessageReporting *smr, tpia_target_heated *target, xData_element *channelElement,
72  int pointwiseRequired ) {
73 
74  tpia_channel *channel;
75 
76  if( ( channel = tpia_channel_create( smr ) ) == NULL ) return( NULL );
77  if( tpia_channel_getFromElement( smr, target, channelElement, channel, pointwiseRequired ) != 0 ) channel = tpia_channel_free( smr, channel );
78  return( channel );
79 }
80 /*
81 ************************************************************
82 */
83 tpia_channel *tpia_channel_free( statusMessageReporting *smr, tpia_channel *channel ) {
84 
85  tpia_channel_release( smr, channel );
86  xData_free( smr, channel );
87  return( NULL );
88 }
89 /*
90 ************************************************************
91 */
92 int tpia_channel_release( statusMessageReporting *smr, tpia_channel *channel ) {
93 
94  tpia_product *product, *nextProduct;
95 
96  xData_releaseAttributionList( smr, &(channel->attributes) );
97  //channel->crossSectionPointwise.data = xData_free( smr, channel->crossSectionPointwise.data );
98  channel->crossSectionPointwise.data = (double*) xData_free( smr, channel->crossSectionPointwise.data );
99  //channel->crossSectionGrouped.data = xData_free( smr, channel->crossSectionGrouped.data );
100  channel->crossSectionGrouped.data = (double*) xData_free( smr, channel->crossSectionGrouped.data );
101  //channel->availableEnergyGrouped.data = xData_free( smr, channel->availableEnergyGrouped.data );
102  channel->availableEnergyGrouped.data = (double*) xData_free( smr, channel->availableEnergyGrouped.data );
103  for( product = channel->decayChannel.products; product != NULL; product = nextProduct ) {
104  nextProduct = product->next;
105  tpia_product_free( smr, product );
106  }
107  channel->decayChannel.numberOfProducts = 0;
108  channel->decayChannel.products = NULL;
109  return( 0 );
110 }
111 /*
112 ************************************************************
113 */
114 int tpia_channel_getFromElement( statusMessageReporting *smr, tpia_target_heated *target, xData_element *channelElement, tpia_channel *channel,
115  int pointwiseRequired ) {
116 
117  xData_Int ll;
118  char *p;
119  xData_element *element, *pElement, *gElement, *eElement;
120 
121  xData_addToAccessed( smr, channelElement, 1 );
122  channel->target = target;
123  xData_copyAttributionList( smr, &(channel->attributes), &(channelElement->attributes) );
124  channel->outputChannel = tpia_misc_pointerToAttributeIfAllOk2(smr, channelElement, 1, &(channel->attributes), "outputChannel" );
125  channel->genre = tpia_misc_pointerToAttributeIfAllOk2( smr, channelElement, 1, &(channel->attributes), "genre" );
126  channel->QString = tpia_misc_pointerToAttributeIfAllOk2( smr, channelElement, 1, &(channel->attributes), "Q" );
127  channel->fission = tpia_misc_pointerToAttributeIfAllOk2( smr, channelElement, 0, &(channel->attributes), "fission" );
128  if( smr_isOk( smr ) ) {
129  ll = 0;
130  if( xData_convertAttributeTo_xData_Int( smr, channelElement, "ENDL_C", &ll ) >= 0 ) channel->ENDL_C = (int) ll;
131  }
132  if( smr_isOk( smr ) ) {
133  ll = 0;
134  if( xData_convertAttributeTo_xData_Int( smr, channelElement, "ENDF_MT2", &ll ) >= 0 ) channel->ENDF_MT = (int) ll;
135  }
136  if( smr_isOk( smr ) ) {
137  channel->QIsFloat = 1;
138  channel->Q = strtod( channel->QString, &p ); /* Q string may be something like "notApplicable". */
139  if( *p != 0 ) { /* In that case set QIsFloat to false. */
140  channel->QIsFloat = 0;
141  channel->Q = 0.;
142  }
143  //if( ( element = xData_getOneElementByTagName( smr, channelElement, "crossSection", 1 ) ) != NULL ) {
144  if( ( element = xData_getOneElementByTagName( smr, channelElement, (char*) "crossSection", 1 ) ) != NULL ) {
145  if( ( tpia_frame_setFromElement( smr, element, 2, &channel->crossSectionFrame ) ) == 0 ) {
146  xData_addToAccessed( smr, element, 1 );
147  //if( ( pElement = xData_getOneElementByTagName( smr, element, "indexed", 1 ) ) != NULL ) {
148  if( ( pElement = xData_getOneElementByTagName( smr, element, (char*) "indexed", 1 ) ) != NULL ) {
149  channel->crossSectionPointwise.data = tpia_misc_get2dxindex_y_data( smr, pElement,
150  &(channel->crossSectionPointwise.start), &(channel->crossSectionPointwise.end), target->energyGrid );
151  }
152  if( ( gElement = xData_getOneElementByTagName( smr, element, (char*) "grouped", 1 ) ) != NULL ) {
153  tpia_misc_get2d_xShared_yHistogram_data_Grouped( smr, gElement, &(channel->crossSectionGrouped) );
154  }
155  if( ( channel->crossSectionGrouped.data != NULL ) && ( ( channel->crossSectionPointwise.data != NULL ) || !pointwiseRequired ) ) {
156  if( target->contents == NULL ) { /* Only supported "crossSection" currently. */
157  if( !tpia_channel_isProduction( smr, channel ) ) {
158  //if( ( eElement = xData_getOneElementByTagName( smr, channelElement, "availableEnergy", 1 ) ) != NULL ) {
159  if( ( eElement = xData_getOneElementByTagName( smr, channelElement, (char*) "availableEnergy", 1 ) ) != NULL ) {
160  xData_addToAccessed( smr, eElement, 1 );
161  //if( ( gElement = xData_getOneElementByTagName( smr, eElement, "grouped", 1 ) ) != NULL ) {
162  if( ( gElement = xData_getOneElementByTagName( smr, eElement, (char*) "grouped", 1 ) ) != NULL ) {
163  tpia_misc_get2d_xShared_yHistogram_data_Grouped( smr, gElement, &(channel->availableEnergyGrouped) );
164  }
165  }
166  }
167  }
168  if( smr_isOk( smr ) ) _tpia_channel_getProductData( smr, channelElement, channel );
169  }
170  }
171  }
172  }
173  return( !smr_isOk( smr ) );
174 }
175 /*
176 ************************************************************
177 */
178 static int _tpia_channel_getProductData( statusMessageReporting *smr, xData_element *channelElement, tpia_channel *channel ) {
179 
180  return( tpia_product_getDecayChannelFromElement( smr, channelElement, channel, NULL, &(channel->decayChannel.products) ) );
181 }
182 /*
183 ************************************************************
184 */
185 tpia_product *tpia_channel_getFirstProduct( tpia_channel *channel ) {
186 
187  return( tpia_decayChannel_getFirstProduct( &(channel->decayChannel) ) );
188 }
189 /*
190 ************************************************************
191 */
192 //tpia_product *tpia_channel_getProductByIndex( statusMessageReporting *smr, tpia_channel *channel, int index ) {
193 tpia_product *tpia_channel_getProductByIndex( statusMessageReporting *, tpia_channel *channel, int index ) {
194 
195  int i = 0;
196  tpia_product *p;
197 
198  if( index < 0 ) return( NULL );
199  for( p = tpia_channel_getFirstProduct( channel ); ( p != NULL ) && ( i < index ); p = tpia_decayChannel_getNextProduct( p ), i++ ) ;
200  return( p );
201 }
202 /*
203 ************************************************************
204 */
205 //int tpia_channel_numberOfProducts( statusMessageReporting *smr, tpia_channel *channel ) {
206 int tpia_channel_numberOfProducts( statusMessageReporting *, tpia_channel *channel ) {
207 
208  return( channel->decayChannel.numberOfProducts );
209 }
210 /*
211 ************************************************************
212 */
213 //int tpia_channel_isProduction( statusMessageReporting *smr, tpia_channel *channel ) {
214 int tpia_channel_isProduction( statusMessageReporting *, tpia_channel *channel ) {
215 
216  return( strcmp( channel->genre, "production" ) == 0 );
217 }
218 /*
219 ************************************************************
220 */
221 //double tpia_channel_getCrossSectionAtE( statusMessageReporting *smr, tpia_channel *channel, xData_Int iEg, double e_in,
222 double tpia_channel_getCrossSectionAtE( statusMessageReporting *smr, tpia_channel *channel, xData_Int , double e_in,
223  int crossSectionType ) {
224 
225  double xsec = 0.;
226 
227  if( crossSectionType == tpia_crossSectionType_grouped ) {
228  xsec = 0; }
229  else if( crossSectionType == tpia_crossSectionType_pointwise ) {
230  xsec = tpia_misc_getPointwiseCrossSectionAtE( smr, &(channel->crossSectionPointwise), channel->target->energyGrid,
231  tpia_target_heated_getEIndex( channel->target, e_in ), e_in );
232  }
233  return( xsec );
234 }
235 
236 }
xData_Int xData_convertAttributeTo_xData_Int(statusMessageReporting *smr, xData_element *element, const char *name, xData_Int *n)
Definition: xData.cc:710
xData_element * xData_getOneElementByTagName(statusMessageReporting *smr, xData_element *element, char *name, int required)
Definition: xData.cc:810
tpia_product * tpia_product_free(statusMessageReporting *smr, tpia_product *product)
int xData_addToAccessed(statusMessageReporting *, xData_element *element, int increment)
Definition: xData.cc:1078
int tpia_misc_get2d_xShared_yHistogram_data_Grouped(statusMessageReporting *smr, xData_element *element, tpia_1dData *group)
Definition: tpia_misc.cc:291
int tpia_product_getDecayChannelFromElement(statusMessageReporting *smr, xData_element *parentElement, tpia_channel *channel, tpia_product *parentProduct, tpia_product **priorProductNext)
tpia_product * tpia_decayChannel_getNextProduct(tpia_product *product)
xData_Int tpia_target_heated_getEIndex(tpia_target_heated *target, double e_in)
int tpia_channel_numberOfProducts(statusMessageReporting *, tpia_channel *channel)
int tpia_channel_getFromElement(statusMessageReporting *smr, tpia_target_heated *target, xData_element *channelElement, tpia_channel *channel, int pointwiseRequired)
tpia_product * tpia_channel_getProductByIndex(statusMessageReporting *, tpia_channel *channel, int index)
int tpia_channel_initialize(statusMessageReporting *, tpia_channel *channel)
Definition: tpia_channel.cc:63
int smr_isOk(statusMessageReporting *smr)
tpia_channel * tpia_channel_createGetFromElement(statusMessageReporting *smr, tpia_target_heated *target, xData_element *channelElement, int pointwiseRequired)
Definition: tpia_channel.cc:71
int tpia_frame_setFromElement(statusMessageReporting *smr, xData_element *element, int dimension, tpia_data_frame *frame)
Definition: tpia_frame.cc:62
int xData_releaseAttributionList(statusMessageReporting *smr, xData_attributionList *attributes)
Definition: xData.cc:611
tpia_channel * tpia_channel_free(statusMessageReporting *smr, tpia_channel *channel)
Definition: tpia_channel.cc:83
int tpia_channel_release(statusMessageReporting *smr, tpia_channel *channel)
Definition: tpia_channel.cc:92
void * xData_free(statusMessageReporting *, void *p)
Definition: xDataMisc.cc:89
double * tpia_misc_get2dxindex_y_data(statusMessageReporting *smr, xData_element *element, xData_Int *start, xData_Int *end, double *xValues)
Definition: tpia_misc.cc:250
int xData_copyAttributionList(statusMessageReporting *smr, xData_attributionList *dest, xData_attributionList *src)
Definition: xData.cc:564
double tpia_channel_getCrossSectionAtE(statusMessageReporting *smr, tpia_channel *channel, xData_Int, double e_in, int crossSectionType)
double tpia_misc_getPointwiseCrossSectionAtE(statusMessageReporting *, tpia_1dData *crossSection, double *energyGrid, xData_Int index, double e_in)
Definition: tpia_misc.cc:300
int tpia_channel_isProduction(statusMessageReporting *, tpia_channel *channel)
tpia_channel * tpia_channel_create(statusMessageReporting *smr)
Definition: tpia_channel.cc:50
tpia_product * tpia_decayChannel_getFirstProduct(tpia_decayChannel *decayChannel)
tpia_product * tpia_channel_getFirstProduct(tpia_channel *channel)
static int _tpia_channel_getProductData(statusMessageReporting *smr, xData_element *channelElement, tpia_channel *channel)