tpia_channel.cc

Go to the documentation of this file.
00001 /*
00002 # <<BEGIN-copyright>>
00003 # Copyright (c) 2010, Lawrence Livermore National Security, LLC. 
00004 # Produced at the Lawrence Livermore National Laboratory 
00005 # Written by Bret R. Beck, beck6@llnl.gov. 
00006 # CODE-461393
00007 # All rights reserved. 
00008 #  
00009 # This file is part of GIDI. For details, see nuclear.llnl.gov. 
00010 # Please also read the "Additional BSD Notice" at nuclear.llnl.gov. 
00011 # 
00012 # Redistribution and use in source and binary forms, with or without modification, 
00013 # are permitted provided that the following conditions are met: 
00014 #
00015 #      1) Redistributions of source code must retain the above copyright notice, 
00016 #         this list of conditions and the disclaimer below.
00017 #      2) Redistributions in binary form must reproduce the above copyright notice, 
00018 #         this list of conditions and the disclaimer (as noted below) in the 
00019 #          documentation and/or other materials provided with the distribution.
00020 #      3) Neither the name of the LLNS/LLNL nor the names of its contributors may be 
00021 #         used to endorse or promote products derived from this software without 
00022 #         specific prior written permission. 
00023 #
00024 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
00025 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00026 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT 
00027 # SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR 
00028 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00029 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
00030 # OR SERVICES;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
00031 # AND ON  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00032 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
00033 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00034 # <<END-copyright>>
00035 */
00036 #include <string.h>
00037 
00038 #include <tpia_target.h>
00039 #include <tpia_misc.h>
00040 
00041 #if defined __cplusplus
00042 namespace GIDI {
00043 using namespace GIDI;
00044 #endif
00045 
00046 static int _tpia_channel_getProductData( statusMessageReporting *smr, xData_element *channelElement, tpia_channel *channel );
00047 /*
00048 ************************************************************
00049 */
00050 tpia_channel *tpia_channel_create( statusMessageReporting *smr ) {
00051 
00052     tpia_channel *channel;
00053 
00054     //if( ( channel = xData_malloc2( smr, sizeof( tpia_channel ), 0, "channel" ) ) == NULL ) return( NULL );
00055     if( ( channel = (tpia_channel*) xData_malloc2( smr, sizeof( tpia_channel ), 0, "channel" ) ) == NULL ) return( NULL );
00056     if( tpia_channel_initialize( smr, channel ) ) channel = tpia_channel_free( smr, channel );
00057     return( channel );
00058 }
00059 /*
00060 ************************************************************
00061 */
00062 //int tpia_channel_initialize( statusMessageReporting *smr, tpia_channel *channel ) {
00063 int tpia_channel_initialize( statusMessageReporting *, tpia_channel *channel ) {
00064 
00065     memset( channel, 0, sizeof( tpia_channel ) );
00066     return( 0 );
00067 }
00068 /*
00069 ************************************************************
00070 */
00071 tpia_channel *tpia_channel_createGetFromElement( statusMessageReporting *smr, tpia_target_heated *target, xData_element *channelElement,
00072     int pointwiseRequired ) {
00073 
00074     tpia_channel *channel;
00075 
00076     if( ( channel = tpia_channel_create( smr ) ) == NULL ) return( NULL );
00077     if( tpia_channel_getFromElement( smr, target, channelElement, channel, pointwiseRequired ) != 0 ) channel = tpia_channel_free( smr, channel );
00078     return( channel );
00079 }
00080 /*
00081 ************************************************************
00082 */
00083 tpia_channel *tpia_channel_free( statusMessageReporting *smr, tpia_channel *channel ) {
00084 
00085     tpia_channel_release( smr, channel );
00086     xData_free( smr, channel );
00087     return( NULL );
00088 }
00089 /*
00090 ************************************************************
00091 */
00092 int tpia_channel_release( statusMessageReporting *smr, tpia_channel *channel ) {
00093 
00094     tpia_product *product, *nextProduct;
00095 
00096     xData_releaseAttributionList( smr, &(channel->attributes) );
00097     //channel->crossSectionPointwise.data = xData_free( smr, channel->crossSectionPointwise.data );
00098     channel->crossSectionPointwise.data = (double*) xData_free( smr, channel->crossSectionPointwise.data );
00099     //channel->crossSectionGrouped.data = xData_free( smr, channel->crossSectionGrouped.data );
00100     channel->crossSectionGrouped.data = (double*) xData_free( smr, channel->crossSectionGrouped.data );
00101     //channel->availableEnergyGrouped.data = xData_free( smr, channel->availableEnergyGrouped.data );
00102     channel->availableEnergyGrouped.data = (double*) xData_free( smr, channel->availableEnergyGrouped.data );
00103     for( product = channel->decayChannel.products; product != NULL; product = nextProduct ) {
00104         nextProduct = product->next;
00105         tpia_product_free( smr, product );
00106     }
00107     channel->decayChannel.numberOfProducts = 0;
00108     channel->decayChannel.products = NULL;
00109     return( 0 );
00110 }
00111 /*
00112 ************************************************************
00113 */
00114 int tpia_channel_getFromElement( statusMessageReporting *smr, tpia_target_heated *target, xData_element *channelElement, tpia_channel *channel, 
00115     int pointwiseRequired ) {
00116 
00117     xData_Int ll;
00118     char *p;
00119     xData_element *element, *pElement, *gElement, *eElement;
00120 
00121     xData_addToAccessed( smr, channelElement, 1 );
00122     channel->target = target;
00123     xData_copyAttributionList( smr, &(channel->attributes), &(channelElement->attributes) );
00124     channel->outputChannel = tpia_misc_pointerToAttributeIfAllOk2(smr, channelElement, 1, &(channel->attributes), "outputChannel" );
00125     channel->genre = tpia_misc_pointerToAttributeIfAllOk2( smr, channelElement, 1, &(channel->attributes), "genre" );
00126     channel->QString = tpia_misc_pointerToAttributeIfAllOk2( smr, channelElement, 1, &(channel->attributes), "Q" );
00127     channel->fission = tpia_misc_pointerToAttributeIfAllOk2( smr, channelElement, 0, &(channel->attributes), "fission" );
00128     if( smr_isOk( smr ) ) {
00129         ll = 0;
00130         if( xData_convertAttributeTo_xData_Int( smr, channelElement, "ENDL_C", &ll ) >= 0 ) channel->ENDL_C = (int) ll;
00131     }
00132     if( smr_isOk( smr ) ) {
00133         ll = 0;
00134         if( xData_convertAttributeTo_xData_Int( smr, channelElement, "ENDF_MT2", &ll ) >= 0 ) channel->ENDF_MT = (int) ll;
00135     }
00136     if( smr_isOk( smr ) ) {
00137         channel->QIsFloat = 1;
00138         channel->Q = strtod( channel->QString, &p );      /* Q string may be something like "notApplicable". */
00139         if( *p != 0 ) {                                     /* In that case set QIsFloat to false. */
00140             channel->QIsFloat = 0;
00141             channel->Q = 0.;
00142         }
00143         //if( ( element = xData_getOneElementByTagName( smr, channelElement, "crossSection", 1 ) ) != NULL ) {
00144         if( ( element = xData_getOneElementByTagName( smr, channelElement, (char*) "crossSection", 1 ) ) != NULL ) {
00145             if( ( tpia_frame_setFromElement( smr, element, 2, &channel->crossSectionFrame ) ) == 0 ) {
00146                 xData_addToAccessed( smr, element, 1 );
00147                 //if( ( pElement = xData_getOneElementByTagName( smr, element, "indexed", 1 ) ) != NULL ) {
00148                 if( ( pElement = xData_getOneElementByTagName( smr, element, (char*) "indexed", 1 ) ) != NULL ) {
00149                     channel->crossSectionPointwise.data = tpia_misc_get2dxindex_y_data( smr, pElement,
00150                         &(channel->crossSectionPointwise.start), &(channel->crossSectionPointwise.end), target->energyGrid );
00151                 }
00152                 if( ( gElement = xData_getOneElementByTagName( smr, element, (char*) "grouped", 1 ) ) != NULL ) {
00153                     tpia_misc_get2d_xShared_yHistogram_data_Grouped( smr, gElement, &(channel->crossSectionGrouped) );
00154                 }
00155                 if( ( channel->crossSectionGrouped.data != NULL ) && ( ( channel->crossSectionPointwise.data != NULL ) || !pointwiseRequired ) ) {
00156                     if( target->contents == NULL ) {                /* Only supported "crossSection" currently. */
00157                         if( !tpia_channel_isProduction( smr, channel ) ) {
00158                             //if( ( eElement = xData_getOneElementByTagName( smr, channelElement, "availableEnergy", 1 ) ) != NULL ) {
00159                             if( ( eElement = xData_getOneElementByTagName( smr, channelElement, (char*) "availableEnergy", 1 ) ) != NULL ) {
00160                                 xData_addToAccessed( smr, eElement, 1 );
00161                                 //if( ( gElement = xData_getOneElementByTagName( smr, eElement, "grouped", 1 ) ) != NULL ) {
00162                                 if( ( gElement = xData_getOneElementByTagName( smr, eElement, (char*) "grouped", 1 ) ) != NULL ) {
00163                                     tpia_misc_get2d_xShared_yHistogram_data_Grouped( smr, gElement, &(channel->availableEnergyGrouped) );
00164                                 }
00165                             }
00166                         }
00167                     }
00168                     if( smr_isOk( smr ) ) _tpia_channel_getProductData( smr, channelElement, channel );
00169                 }
00170             }
00171         }
00172     }
00173     return( !smr_isOk( smr ) );
00174 }
00175 /*
00176 ************************************************************
00177 */
00178 static int _tpia_channel_getProductData( statusMessageReporting *smr, xData_element *channelElement, tpia_channel *channel ) {
00179 
00180     return( tpia_product_getDecayChannelFromElement( smr, channelElement, channel, NULL, &(channel->decayChannel.products) ) );
00181 }
00182 /*
00183 ************************************************************
00184 */
00185 tpia_product *tpia_channel_getFirstProduct( tpia_channel *channel ) {
00186 
00187     return( tpia_decayChannel_getFirstProduct( &(channel->decayChannel) ) );
00188 }
00189 /*
00190 ************************************************************
00191 */
00192 //tpia_product *tpia_channel_getProductByIndex( statusMessageReporting *smr, tpia_channel *channel, int index ) {
00193 tpia_product *tpia_channel_getProductByIndex( statusMessageReporting *, tpia_channel *channel, int index ) {
00194 
00195     int i = 0;
00196     tpia_product *p;
00197 
00198     if( index < 0 ) return( NULL );
00199     for( p = tpia_channel_getFirstProduct( channel ); ( p != NULL ) && ( i < index ); p = tpia_decayChannel_getNextProduct( p ), i++ ) ;
00200     return( p );
00201 }
00202 /*
00203 ************************************************************
00204 */
00205 //int tpia_channel_numberOfProducts( statusMessageReporting *smr, tpia_channel *channel ) {
00206 int tpia_channel_numberOfProducts( statusMessageReporting *, tpia_channel *channel ) {
00207 
00208     return( channel->decayChannel.numberOfProducts );
00209 }
00210 /*
00211 ************************************************************
00212 */
00213 //int tpia_channel_isProduction( statusMessageReporting *smr, tpia_channel *channel ) {
00214 int tpia_channel_isProduction( statusMessageReporting *, tpia_channel *channel ) {
00215 
00216     return( strcmp( channel->genre, "production" ) == 0 );
00217 }
00218 /*
00219 ************************************************************
00220 */
00221 //double tpia_channel_getCrossSectionAtE( statusMessageReporting *smr, tpia_channel *channel, xData_Int iEg, double e_in,
00222 double tpia_channel_getCrossSectionAtE( statusMessageReporting *smr, tpia_channel *channel, xData_Int , double e_in,
00223         int crossSectionType ) {
00224 
00225     double xsec = 0.;
00226 
00227     if( crossSectionType == tpia_crossSectionType_grouped ) {
00228         xsec = 0; }
00229     else if( crossSectionType == tpia_crossSectionType_pointwise ) {
00230         xsec = tpia_misc_getPointwiseCrossSectionAtE( smr, &(channel->crossSectionPointwise), channel->target->energyGrid,
00231             tpia_target_heated_getEIndex( channel->target, e_in ), e_in );
00232     }
00233     return( xsec );
00234 }
00235 
00236 }

Generated on Mon May 27 17:50:35 2013 for Geant4 by  doxygen 1.4.7