tpia_Legendre.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 <math.h>
00038 #ifdef WIN32
00039    #include <float.h>
00040 #endif
00041 
00042 #include <tpia_target.h>
00043 #include <tpia_misc.h>
00044 
00045 #if defined __cplusplus
00046 namespace GIDI {
00047 using namespace GIDI;
00048 #endif
00049 
00050 static int _tpia_Legendre_getOrder( statusMessageReporting *smr, xData_element *LegendreOrder, tpia_Legendre *Legendre, tpia_EqualProbableBinSpectra *l );
00051 /*
00052 ************************************************************
00053 */
00054 int tpia_Legendre_initialize( statusMessageReporting *smr, tpia_Legendre *Legendre ) {
00055 
00056     memset( Legendre, 0, sizeof( tpia_Legendre ) );
00057     if( tpia_frame_setFromString( smr, "", "", 0, &(Legendre->frame) ) ) return( 1 );
00058     Legendre->binned.numberOfLs = 0;
00059     Legendre->binned.ls = NULL;
00060     return( 0 );
00061 }
00062 /*
00063 ************************************************************
00064 */
00065 int tpia_Legendre_release( statusMessageReporting *smr, tpia_Legendre *Legendre ) {
00066 
00067     int i;
00068 
00069     for( i = 0; i < Legendre->binned.numberOfLs; i++ ) xData_free( smr, Legendre->binned.ls[i].energies );
00070     //Legendre->binned.ls = xData_free( smr, Legendre->binned.ls );
00071     Legendre->binned.ls = (tpia_EqualProbableBinSpectra*) xData_free( smr, Legendre->binned.ls );
00072     tpia_Legendre_initialize( smr, Legendre );
00073     return( 0 );
00074 }
00075 /*
00076 ************************************************************
00077 */
00078 int tpia_Legendre_getFromElement( statusMessageReporting *smr, xData_element *LegendreElement, tpia_Legendre *Legendre ) {
00079 
00080     int i, status = 0;
00081     xData_elementList *list;
00082 
00083     xData_addToAccessed( smr, LegendreElement, 1 );
00084     if( ( tpia_frame_setFromElement( smr, LegendreElement, 4, &(Legendre->frame) ) ) != 0 ) return( 1 );
00085     list = xData_getElementsByTagNameAndSort( smr, LegendreElement, "l", NULL, NULL );
00086     if( list->n == 0 ) {
00087         status = 1;
00088         tpia_misc_setMessageError_Element( smr, NULL, LegendreElement, __FILE__, __LINE__, 1, "Legendre element does not contain any l elements" ); }
00089     else {
00090         //if( ( Legendre->binned.ls = xData_malloc2( smr, list->n * sizeof( tpia_EqualProbableBinSpectra ), 1, "ls" ) ) != NULL ) {
00091         if( ( Legendre->binned.ls = (tpia_EqualProbableBinSpectra*) xData_malloc2( smr, list->n * sizeof( tpia_EqualProbableBinSpectra ), 1, "ls" ) ) != NULL ) {
00092             Legendre->binned.numberOfLs = 0;
00093             for( i = 0; i < list->n; i++ ) {
00094                 if( ( status = _tpia_Legendre_getOrder( smr, list->items[i].element, Legendre, &(Legendre->binned.ls[i]) ) ) != 0 ) break;
00095                 Legendre->binned.numberOfLs++;
00096             }
00097         }
00098     }
00099     xData_freeElementList( smr, list );
00100     return( status );
00101 }
00102 /*
00103 ************************************************************
00104 */
00105 //static int _tpia_Legendre_getOrder( statusMessageReporting *smr, xData_element *LegendreOrder, tpia_Legendre *Legendre, tpia_EqualProbableBinSpectra *l ) {
00106 static int _tpia_Legendre_getOrder( statusMessageReporting *smr, xData_element *LegendreOrder, tpia_Legendre *, tpia_EqualProbableBinSpectra *l ) {
00107 
00108     int status = 1;
00109     xData_Int n, nBins, lOrder;
00110 
00111     if( xData_convertAttributeTo_xData_Int( smr, LegendreOrder, "value", &lOrder ) != 0 ) {
00112         tpia_misc_setMessageError_Element( smr, NULL, LegendreOrder, __FILE__, __LINE__, 1, "missing or invalid nBins attribute for angular bins" ); }
00113     else {
00114         l->iValue = lOrder;
00115         l->dValue = 0.;
00116         if( ( l->energies = tpia_misc_getEqualProbableBin( smr, LegendreOrder, &n, &nBins ) ) != NULL ) {
00117             status = 0;
00118             l->nBins = (int) nBins;
00119             l->numberOfEs = (int) n;
00120         }
00121     }
00122     return( status );
00123 }
00124 /*
00125 ************************************************************
00126 */
00127 int tpia_Legendre_SampleEp( statusMessageReporting *smr, tpia_Legendre *Legendre, int sampleMu, tpia_decaySamplingInfo *decaySamplingInfo ) {
00128 
00129     tpia_EqualProbableBinSpectra *binned_l0 = Legendre->binned.ls;
00130     double Ep;
00131 
00132 /*
00133 Currently, only l = 0, equal probable binning is supported.
00134 Need to return frame info for Ep, mu, also.
00135 */
00136     if( Legendre->binned.numberOfLs > 0 ) {
00137         if( sampleMu ) decaySamplingInfo->mu = 2. * tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState ) - 1.;
00138 #ifndef WIN32
00139         if( decaySamplingInfo->mu <= -1 ) decaySamplingInfo->mu = nextafter( -1., 0. );
00140 #endif
00141 #ifdef WIN32
00142         if( decaySamplingInfo->mu <= -1 ) decaySamplingInfo->mu = _nextafter( -1., 0. );
00143 #endif
00144 
00145         tpia_misc_sampleEqualProbableBin( smr, decaySamplingInfo, decaySamplingInfo->e_in, binned_l0->nBins, binned_l0, &Ep );
00146         /* ??? Need to check that e_in > E_Threshold */
00147         decaySamplingInfo->Ep = Ep; }
00148     else {
00149         return( 1 );
00150     }
00151 
00152     return( 0 );
00153 }
00154 
00155 #if defined __cplusplus
00156 }
00157 #endif

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