tpia_target_heated.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 #include <tpia_target.h>
00038 #include <tpia_misc.h>
00039 
00040 #if defined __cplusplus
00041 namespace GIDI {
00042 using namespace GIDI;
00043 #endif
00044 
00045 static void _tpia_target_heated_getEnergyGridAndAllocateTotalCrossSections( statusMessageReporting *smr, tpia_target_heated *target, xData_element *element );
00046 static int _tpia_target_heated_releaseAndReturnOne( statusMessageReporting *smr, xData_document *doc, tpia_target_heated *target );
00047 static int _tpia_target_heated_checkElememtsForAccess( statusMessageReporting *smr, xData_document *doc );
00048 static int _tpia_target_heated_checkElememtsForAccess2( statusMessageReporting *smr, xData_element *element );
00049 /*
00050 ************************************************************
00051 */
00052 tpia_target_heated *tpia_target_heated_create( statusMessageReporting *smr ) {
00053 
00054     tpia_target_heated *target;
00055 
00056     //if( ( target = xData_malloc2( smr, sizeof( tpia_target_heated ), 0, "target" ) ) == NULL ) return( NULL );
00057     if( ( target = (tpia_target_heated*) xData_malloc2( smr, sizeof( tpia_target_heated ), 0, "target" ) ) == NULL ) return( NULL );
00058     //if( tpia_target_heated_initialize( smr, target ) ) target = xData_free( smr, target );
00059     if( tpia_target_heated_initialize( smr, target ) ) target = (tpia_target_heated*) xData_free( smr, target );
00060     return( target );
00061 }
00062 /*
00063 ************************************************************
00064 */
00065 //int tpia_target_heated_initialize( statusMessageReporting *smr, tpia_target_heated *target ) {
00066 int tpia_target_heated_initialize( statusMessageReporting *, tpia_target_heated *target ) {
00067 
00068     memset( target, 0, sizeof( tpia_target_heated ) );
00069     return( 0 );
00070 }
00071 /*
00072 ************************************************************
00073 */
00074 tpia_target_heated *tpia_target_heated_createRead( statusMessageReporting *smr, const char *fileName, int checkElememtsForAccess ) {
00075 
00076     tpia_target_heated *target;
00077 
00078     if( ( target = tpia_target_heated_create( smr ) ) == NULL ) return( NULL );
00079     //if( tpia_target_heated_read( smr, target, fileName, checkElememtsForAccess ) != 0 ) target = xData_free( smr, target );
00080     if( tpia_target_heated_read( smr, target, fileName, checkElememtsForAccess ) != 0 ) target = (tpia_target_heated*) xData_free( smr, target );
00081     return( target );
00082 }
00083 /*
00084 ************************************************************
00085 */
00086 tpia_target_heated *tpia_target_heated_free( statusMessageReporting *smr, tpia_target_heated *target ) {
00087 
00088     tpia_target_heated_release( smr, target );
00089     xData_free( smr, target );
00090     return( NULL );
00091 }
00092 /*
00093 ************************************************************
00094 */
00095 int tpia_target_heated_release( statusMessageReporting *smr, tpia_target_heated *target ) {
00096 
00097     int i;
00098 
00099     //target->path = xData_free( smr, target->path );
00100     target->path = (char*) xData_free( smr, target->path );
00101     //target->absPath = xData_free( smr, target->absPath );
00102     target->absPath = (char*) xData_free( smr, target->absPath );
00103     target->energyGridLength = 0;
00104     //target->energyGrid = xData_free( smr, target->energyGrid );
00105     target->energyGrid = (double*) xData_free( smr, target->energyGrid );
00106     //target->kerma = xData_free( smr, target->kerma );
00107     target->kerma = (double*) xData_free( smr, target->kerma );
00108     //target->totalCrossSectionPointwise.data = xData_free( smr, target->totalCrossSectionPointwise.data );
00109     target->totalCrossSectionPointwise.data = (double*) xData_free( smr, target->totalCrossSectionPointwise.data );
00110     //target->totalCrossSectionGrouped.data = xData_free( smr, target->totalCrossSectionGrouped.data );
00111     target->totalCrossSectionGrouped.data = (double*) xData_free( smr, target->totalCrossSectionGrouped.data );
00112     xData_releaseAttributionList( smr, &(target->attributes) );
00113     for( i = 0; i < target->nChannels; i++ ) tpia_channel_free( smr, target->channels[i] );
00114     target->nChannels = 0;
00115     //target->channels = xData_free( smr, target->channels );
00116     target->channels = (tpia_channel**) xData_free( smr, target->channels );
00117     for( i = 0; i < target->nProductionChannels; i++ ) tpia_channel_free( smr, target->productionChannels[i] );
00118     target->nProductionChannels = 0;
00119     //target->productionChannels = xData_free( smr, target->productionChannels );
00120     target->productionChannels = (tpia_channel**) xData_free( smr, target->productionChannels );
00121     return( 0 );
00122 }
00123 /*
00124 ************************************************************
00125 */
00126 int tpia_target_heated_read( statusMessageReporting *smr, tpia_target_heated *target, const char *fileName, int checkElememtsForAccess ) {
00127 /*
00128 *   If a target has already been read into this target, user must have called tpia_target_heated_release before calling this routine.
00129 *   Otherwise, there will be memory leaks.
00130 */
00131     xData_document *doc = NULL;
00132     xData_element *element, *channelElement, *channels;
00133     int nChannels;
00134     tpia_channel *channel;
00135     char *name;
00136     xData_Int i, j;
00137 
00138     tpia_target_heated_initialize( smr, target );
00139     if( ( target->path = xDataMisc_allocateCopyString2( smr, fileName, "path" ) ) == NULL ) return( 1 );
00140     if( ( target->absPath = xDataMisc_getAbsPath( smr, fileName ) ) == NULL ) return( _tpia_target_heated_releaseAndReturnOne( smr, doc, target ) );
00141     if( ( doc = xData_parseReadFile( smr, fileName, NULL, NULL ) ) == NULL ) return( _tpia_target_heated_releaseAndReturnOne( smr, doc, target ) );
00142     element = xData_getDocumentsElement( doc );
00143     xData_addToAccessed( smr, element, 1 );
00144     if( xData_convertAttributeTo_xData_Int( smr, element, "nGroups", &i ) != 0 ) return( _tpia_target_heated_releaseAndReturnOne( smr, doc, target ) );
00145     target->nGroups = (int) i;
00146     if( strcmp( element->name, "xTargetHeated" ) != 0 ) {
00147         tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "input file's top element must be xTargetHeated and not %s", 
00148             element->name ); }
00149     else {
00150         xData_copyAttributionList( smr, &(target->attributes), &(element->attributes) );
00151         if( smr_isOk( smr ) ) target->contents = xData_getAttributesValue( &(target->attributes), "contents" );
00152         if( ( name = tpia_misc_pointerToAttributeIfAllOk3( smr, target->absPath, 1, &(target->attributes), "projectile" ) ) != NULL )
00153             target->projectileID = tpia_particle_getInternalID( smr, name );
00154         if( ( name = tpia_misc_pointerToAttributeIfAllOk3( smr, target->absPath, 1, &(target->attributes), "target" ) ) != NULL )
00155             target->targetID = tpia_particle_getInternalID( smr, name );
00156         if( smr_isOk( smr ) ) _tpia_target_heated_getEnergyGridAndAllocateTotalCrossSections( smr, target, element );
00157         if( smr_isOk( smr ) ) {            /* Get channels. */
00158             //if( ( channels = xData_getOneElementByTagName( smr, element, "channels", 1 ) ) == NULL ) 
00159             if( ( channels = xData_getOneElementByTagName( smr, element, (char*)"channels", 1 ) ) == NULL ) 
00160                 return( _tpia_target_heated_releaseAndReturnOne( smr, doc, target ) );
00161             xData_addToAccessed( smr, channels, 1 );
00162             if( ( nChannels = xData_numberOfElementsByTagName( smr, channels, "channel" ) ) > 0 ) {
00163                 //if( ( target->channels = xData_malloc2( smr, nChannels * sizeof( tpia_channel * ), 1, "channels" ) ) == NULL ) 
00164                 if( ( target->channels = (tpia_channel**) xData_malloc2( smr, nChannels * sizeof( tpia_channel * ), 1, "channels" ) ) == NULL ) 
00165                     return( _tpia_target_heated_releaseAndReturnOne( smr, doc, target ) );
00166                 for( channelElement = xData_getFirstElement( channels ); channelElement != NULL; channelElement = xData_getNextElement( channelElement ) ) {
00167                     if( !strcmp( channelElement->name, "channel" ) ) {
00168                         if( ( channel = tpia_channel_createGetFromElement( smr, target, channelElement, 1 ) ) == NULL ) break;
00169                         target->channels[target->nChannels] = channel;
00170                         target->nChannels++;
00171                         for( i = channel->crossSectionPointwise.start, j = 0; i < channel->crossSectionPointwise.end; i++, j++ ) 
00172                             target->totalCrossSectionPointwise.data[i] += channel->crossSectionPointwise.data[j];
00173                         for( i = channel->crossSectionGrouped.start, j = 0; i < channel->crossSectionGrouped.end; i++, j++ ) 
00174                             target->totalCrossSectionGrouped.data[i] += channel->crossSectionGrouped.data[j];
00175                     }
00176                 }
00177             }
00178         }
00179         if( smr_isOk( smr ) ) {            /* Get production channels. */
00180             //if( ( channels = xData_getOneElementByTagName( smr, element, "productionChannels", 0 ) ) == NULL ) {
00181             if( ( channels = xData_getOneElementByTagName( smr, element, (char*) "productionChannels", 0 ) ) == NULL ) {
00182                 if( !smr_isOk( smr ) ) return( _tpia_target_heated_releaseAndReturnOne( smr, doc, target ) ); }
00183             else {
00184                 xData_addToAccessed( smr, channels, 1 );
00185                 if( ( nChannels = xData_numberOfElementsByTagName( smr, channels, "channel" ) ) > 0 ) {
00186                     //if( ( target->productionChannels = xData_malloc2( smr, nChannels * sizeof( tpia_channel * ), 1, "channels" ) ) != NULL ) {
00187                     if( ( target->productionChannels = (tpia_channel**) xData_malloc2( smr, nChannels * sizeof( tpia_channel * ), 1, "channels" ) ) != NULL ) {
00188                         for( channelElement = xData_getFirstElement(channels); channelElement != NULL; channelElement = xData_getNextElement(channelElement) ) {
00189                             if( !strcmp( channelElement->name, "channel" ) ) {
00190                                 channel = tpia_channel_createGetFromElement( smr, target, channelElement, 1 );
00191                                 if( channel == NULL ) break;
00192                                 target->productionChannels[target->nProductionChannels] = channel;
00193                                 target->nProductionChannels++;
00194                             }
00195                         }
00196                     }
00197                 }
00198             }
00199         }
00200     }
00201     if( smr_isOk( smr ) && checkElememtsForAccess ) _tpia_target_heated_checkElememtsForAccess( smr, doc );
00202     xData_parseFree( smr, doc );
00203     if( !smr_isOk( smr ) ) tpia_target_heated_release( smr, target );
00204     return( !smr_isOk( smr ) );
00205 }
00206 /*
00207 ************************************************************
00208 */
00209 static void _tpia_target_heated_getEnergyGridAndAllocateTotalCrossSections( statusMessageReporting *smr, tpia_target_heated *target, xData_element *element ) {
00210 
00211     xData_Int i, energyGridIndex, energyGridStart, energyGridEnd, energyGridLength;
00212     xData_element *energyGrid, *kerma;
00213 
00214     if( !smr_isOk( smr ) ) return;
00215     //if( ( energyGrid = xData_getOneElementByTagName( smr, element, "energyGrid", 1 ) ) == NULL ) return;
00216     if( ( energyGrid = xData_getOneElementByTagName( smr, element, (char*) "energyGrid", 1 ) ) == NULL ) return;
00217     xData_addToAccessed( smr, energyGrid, 1 );
00218     if( ( energyGrid = xData_getElements_xDataElement( smr, energyGrid ) ) == NULL ) return;
00219     xData_addToAccessed( smr, energyGrid, 1 );
00220     xData_getCommonData( smr, energyGrid, &energyGridIndex, &energyGridStart, &energyGridEnd, &energyGridLength );
00221     if( ( target->energyGrid = xData_1d_x_allocateCopyData( smr, energyGrid ) ) == NULL ) return;
00222     target->energyGridLength = energyGridLength;
00223     target->totalCrossSectionPointwise.start = 0;
00224     target->totalCrossSectionPointwise.end = energyGridLength;
00225     target->totalCrossSectionPointwise.length = energyGridLength;
00226     //if( ( target->totalCrossSectionPointwise.data = xData_malloc2( smr, energyGridLength * sizeof( double ), 0, "totalCrossSectionPointwise" ) ) == NULL ) 
00227     if( ( target->totalCrossSectionPointwise.data = (double*) xData_malloc2( smr, energyGridLength * sizeof( double ), 0, "totalCrossSectionPointwise" ) ) == NULL ) 
00228         return;
00229     for( i = 0; i < energyGridLength; i++ ) target->totalCrossSectionPointwise.data[i] = 0.;
00230     target->totalCrossSectionGrouped.start = 0;
00231     target->totalCrossSectionGrouped.end = energyGridLength;
00232     target->totalCrossSectionGrouped.length = energyGridLength;
00233     //if( ( target->totalCrossSectionGrouped.data = xData_malloc2( smr, target->nGroups * sizeof( double ), 0, "totalCrossSectionGrouped" ) ) == NULL ) return;
00234     if( ( target->totalCrossSectionGrouped.data = (double*) xData_malloc2( smr, target->nGroups * sizeof( double ), 0, "totalCrossSectionGrouped" ) ) == NULL ) return;
00235     for( i = 0; i < target->nGroups; i++ ) target->totalCrossSectionGrouped.data[i] = 0.;
00236     //if( ( kerma = xData_getOneElementByTagName( smr, element, "kerma", 1 ) ) != NULL ) { 
00237     if( ( kerma = xData_getOneElementByTagName( smr, element, (char*) "kerma", 1 ) ) != NULL ) { 
00238         xData_addToAccessed( smr, kerma, 1 );
00239         if( ( kerma = xData_getElements_xDataElement( smr, kerma ) ) == NULL ) return;
00240         xData_addToAccessed( smr, kerma, 1 );
00241         if( ( target->kerma = xData_1d_x_allocateCopyData( smr, kerma ) ) == NULL ) return;
00242     }
00243 }
00244 /*
00245 ************************************************************
00246 */
00247 //int tpia_target_heated_numberOfChannels( statusMessageReporting *smr, tpia_target_heated *target ) {
00248 int tpia_target_heated_numberOfChannels( statusMessageReporting *, tpia_target_heated *target ) {
00249 
00250     return( target->nChannels );
00251 }
00252 /*
00253 ************************************************************
00254 */
00255 //int tpia_target_heated_numberOfProductionChannels( statusMessageReporting *smr, tpia_target_heated *target ) {
00256 int tpia_target_heated_numberOfProductionChannels( statusMessageReporting *, tpia_target_heated *target ) {
00257 
00258     return( target->nProductionChannels );
00259 }
00260 /*
00261 ************************************************************
00262 */
00263 tpia_channel *tpia_target_heated_getChannelAtIndex( tpia_target_heated *target, int index ) {
00264 
00265     tpia_channel *channel = NULL;
00266 
00267     if( ( index >= 0 ) && ( index < target->nChannels ) ) channel = target->channels[index];
00268     return( channel );
00269 }
00270 /*
00271 ************************************************************
00272 */
00273 tpia_channel *tpia_target_heated_getChannelAtIndex_smr( statusMessageReporting *smr, tpia_target_heated *target, int index ) {
00274 
00275     tpia_channel *channel = tpia_target_heated_getChannelAtIndex( target, index );
00276 
00277     if( channel == NULL ) {
00278         smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "bad channel index = %d for %s + %s", index, 
00279             target->projectileID->name, target->targetID->name ); 
00280     }
00281     return( channel );
00282 }
00283 /*
00284 ************************************************************
00285 */
00286 tpia_channel *tpia_target_heated_getProductionChannelAtIndex( tpia_target_heated *target, int index ) {
00287 
00288     tpia_channel *channel = NULL;
00289 
00290     if( ( index >= 0 ) && ( index < target->nProductionChannels ) ) channel = target->productionChannels[index];
00291     return( channel );
00292 }
00293 /*
00294 ************************************************************
00295 */
00296 //xData_Int tpia_target_heated_getEnergyGrid( statusMessageReporting *smr, tpia_target_heated *target, double **energyGrid ) {
00297 xData_Int tpia_target_heated_getEnergyGrid( statusMessageReporting *, tpia_target_heated *target, double **energyGrid ) {
00298 
00299     if( energyGrid != NULL ) *energyGrid = target->energyGrid;
00300     return( target->energyGridLength );
00301 }
00302 /*
00303 ************************************************************
00304 */
00305 xData_Int tpia_target_heated_getEIndex( tpia_target_heated *target, double e_in ) {
00306 
00307     return( tpia_misc_binarySearch( target->energyGridLength, target->energyGrid, e_in ) );
00308 }
00309 /*
00310 ************************************************************
00311 */
00312 //double tpia_target_heated_getTotalCrossSectionAtE( statusMessageReporting *smr, tpia_target_heated *target, xData_Int iEg, double e_in, 
00313 double tpia_target_heated_getTotalCrossSectionAtE( statusMessageReporting *smr, tpia_target_heated *target, xData_Int , double e_in, 
00314         int crossSectionType ) {
00315 
00316     double xsec = 0.;
00317 
00318     if( crossSectionType == tpia_crossSectionType_grouped ) {
00319         xsec = 0; }
00320     else if( crossSectionType == tpia_crossSectionType_pointwise ) {
00321         xsec = tpia_misc_getPointwiseCrossSectionAtE( smr, &(target->totalCrossSectionPointwise), target->energyGrid, 
00322             tpia_target_heated_getEIndex( target, e_in ), e_in );
00323     }
00324     return( xsec );
00325 }
00326 /*
00327 ************************************************************
00328 */
00329 double tpia_target_heated_getIndexChannelCrossSectionAtE( statusMessageReporting *smr, tpia_target_heated *target, int index, xData_Int iEg, double e_in, 
00330         int crossSectionType ) {
00331 
00332     double xsec = 0.;
00333     tpia_channel *channel = tpia_target_heated_getChannelAtIndex_smr( smr, target, index );
00334 
00335     if( channel != NULL ) xsec = tpia_channel_getCrossSectionAtE( smr, channel, iEg, e_in, crossSectionType );
00336     return( xsec );
00337 }
00338 /*
00339 ************************************************************
00340 */
00341 int tpia_target_heated_sampleIndexChannelProductsAtE( statusMessageReporting *smr, tpia_target_heated *target, int index, 
00342         tpia_decaySamplingInfo *decaySamplingInfo, int nProductData, tpia_productOutgoingData *productDatas ) {
00343 
00344     tpia_channel *channel = tpia_target_heated_getChannelAtIndex_smr( smr, target, index );
00345 
00346     if( channel == NULL ) return( -1 );
00347     return( tpia_decayChannel_sampleProductsAtE( smr, &(channel->decayChannel), decaySamplingInfo, nProductData, productDatas ) );
00348 }
00349 /*
00350 ************************************************************
00351 */
00352 static int _tpia_target_heated_releaseAndReturnOne( statusMessageReporting *smr, xData_document *doc, tpia_target_heated *target ) {
00353 
00354     tpia_target_heated_release( smr, target );
00355     if( doc != NULL ) xData_parseFree( smr, doc );
00356     return( 1 );
00357 }
00358 /*
00359 ************************************************************
00360 */
00361 static int _tpia_target_heated_checkElememtsForAccess( statusMessageReporting *smr, xData_document *doc ) {
00362 
00363     xData_element *element = xData_getDocumentsElement( doc );
00364 
00365     _tpia_target_heated_checkElememtsForAccess2( smr, element );
00366     return( 0 );
00367 }
00368 /*
00369 ************************************************************
00370 */
00371 static int _tpia_target_heated_checkElememtsForAccess2( statusMessageReporting *smr, xData_element *element ) {
00372 
00373     xData_element *child;
00374 
00375     if( xData_getAccessed( smr, element ) != 1 ) printf( "%3d %s\n", xData_getAccessed( smr, element ), element->fullName );
00376     for( child = xData_getFirstElement( element ); child != NULL; child = xData_getNextElement( child ) ) 
00377         _tpia_target_heated_checkElememtsForAccess2( smr, child );
00378     return( 0 );
00379 }
00380 
00381 #if defined __cplusplus
00382 }
00383 #endif

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