Changeset 2108

Show
Ignore:
Timestamp:
06/13/08 11:23:57 (5 months ago)
Author:
peter
Message:

source/grains_mie.cpp:
source/grains.cpp:
source/grainvar.h:

Speed up the code for initializing the grain electron yields. No change in functionality.

Location:
trunk/source
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/source/grains.cpp

    r2025 r2108  
    3333inline double ASINH(double x) 
    3434{ 
    35         if( abs(x) <= 2.3e-4 ) 
    36                 return x - pow3(x)/6.; 
    37         else if( abs(x) <= 8.e-3 ) 
     35        if( abs(x) <= 8.e-3 ) 
    3836                return ((0.075*pow2(x) - 1./6.)*pow2(x) + 1.)*x; 
    3937        else if( abs(x) <= 1./sqrt(DBL_EPSILON) ) 
     
    4745        { 
    4846                if( x < 0. ) 
    49                         return -log(-2.*x); 
     47                        return -(log(-x)+LN_TWO); 
    5048                else 
    51                         return log(2.*x); 
     49                        return log(x)+LN_TWO; 
    5250        } 
    5351} 
     
    145143                return 1.e-7; 
    146144        else 
    147                 return 3.e-6*pow((double)gv.bin[nd]->dustp[0],-0.85)*pow(e*EVRYD*1.e-3,1.5); 
     145                return 3.e-6*gv.bin[nd]->eec*sqrt(pow3(e*EVRYD*1.e-3)); 
    148146} 
    149147         
     
    192190STATIC void UpdatePot2(long,long); 
    193191/* Helper function to calculate primary and secondary yields and the average electron energy at infinity */ 
    194 STATIC void Yfunc(long,long,double,double,double,double,double,/*@out@*/double*,/*@out@*/double*, 
     192inline void Yfunc(long,long,double,double,double,double,double,/*@out@*/double*,/*@out@*/double*, 
    195193                  /*@out@*/double*,/*@out@*/double*); 
    196194/* This calculates the y0 function for band electrons (Sect. 4.1.3/4.1.4 of WDB06) */ 
     
    203201STATIC double y1psa(long,long,double); 
    204202/* This calculates the y2 function for primary and Auger electrons (Eq. 8 of WDB06) */ 
    205 STATIC double y2pa(double,double,long,double*); 
     203inline double y2pa(double,double,long,double*); 
    206204/* This calculates the y2 function for secondary electrons (Eq. 20-21 of WDB06) */ 
    207 STATIC double y2s(double,double,long,double*); 
     205inline double y2s(double,double,long,double*); 
    208206/* find highest ionization stage with non-zero population */ 
    209207STATIC long HighestIonStage(void); 
     
    32163214        } 
    32173215 
     3216        double GrainPot = chrg2pot(Zg,nd); 
     3217 
    32183218        if( nfill > ipLo ) 
    32193219        { 
     
    32413241                        /* calculate yield for band structure */ 
    32423242                        Ehi = Ehi_band = anu[i] - ThresInfVal - Emin; 
    3243                         Wcorr = ThresInfVal + Emin - chrg2pot(Zg,nd); 
     3243                        Wcorr = ThresInfVal + Emin - GrainPot; 
    32443244                        Eel = anu[i] - DustWorkFcn; 
    32453245                        yzero = y0b( nd, nz, i ); 
     
    32523252 
    32533253                        /* add in yields for inner shell ionization */ 
    3254                         for( ns=1; ns < gv.bin[nd]->nShells; ns++ ) 
     3254                        unsigned long nsmax = gv.bin[nd]->nShells; 
     3255                        for( ns=1; ns < nsmax; ns++ ) 
    32553256                        { 
    32563257                                sptr = gv.bin[nd]->sd[ns]; 
     
    32683269 
    32693270                                /* add in Auger yields */ 
    3270                                 for( n=0; n < sptr->nData; n++ ) 
     3271                                long nmax = sptr->nData; 
     3272                                for( n=0; n < nmax; n++ ) 
    32713273                                { 
    32723274                                        double max = sptr->AvNr[n]*sptr->p[i]; 
    3273                                         Ehi = sptr->Ener[n] - chrg2pot(Zg,nd); 
     3275                                        Ehi = sptr->Ener[n] - GrainPot; 
    32743276                                        Eel = sptr->Ener[n]; 
    32753277                                        Yfunc(nd,nz,sptr->y01A[n][i],max,Elo,Ehi,Eel,&Yp1,&Ys1,&Ehp,&Ehs); 
     
    34323434 
    34333435/* Helper function to calculate primary and secondary yields and the average electron energy at infinity */ 
    3434 STATIC void Yfunc(long nd, 
     3436inline void Yfunc(long nd, 
    34353437                  long nz, 
    34363438                  double y01, 
     
    34723474                /* this is Eq. 18 of WDB06 */ 
    34733475                /* Eel may be negative near threshold -> set yield to zero */ 
    3474                 f3 = max(Eel,0.)/(eps*elec_esc_length(Eel,nd)*(1./gv.bin[nd]->AvRadius + 1.e7)); 
     3476                f3 = max(Eel,0.)/(eps*elec_esc_length(Eel,nd)*gv.bin[nd]->eyc); 
    34753477                *Ys = y2sec*f3*min(y01,maxval); 
    34763478        } 
     
    36143616 
    36153617/* This calculates the y2 function for primary and Auger electrons (Eq. 8 of WDB06) */ 
    3616 STATIC double y2pa(double Elo, 
     3618inline double y2pa(double Elo, 
    36173619                   double Ehi, 
    36183620                   long Zg, 
     
    36583660 
    36593661/* This calculates the y2 function for secondary electrons (Eqs. 20-21 of WDB06) */ 
    3660 STATIC double y2s(double Elo, 
     3662inline double y2s(double Elo, 
    36613663                  double Ehi, 
    36623664                  long Zg, 
     
    37133715                                { 
    37143716                                        N0 = alpha*(1./sqR0 - 1./sqRh); 
    3715                                         E0 = alpha*ETILDE*(ASINH(x) + ASINH(yl) - yh/sqRh); 
     3717                                        E0 = alpha*ETILDE*(ASINH(x*sqR0 + yl*sqRh) - yh/sqRh); 
    37163718                                } 
    37173719                        } 
  • trunk/source/grains_mie.cpp

    r1891 r2108  
    10881088        mie_next_data(chFile,io2,chLine,&dl); 
    10891089        mie_read_realnum(chFile,chLine,&gv.bin[nd]->dustp[0],true,dl); 
     1090        /* constant needed in the evaluation of the electron escape length */ 
     1091        gv.bin[nd]->eec = pow((double)gv.bin[nd]->dustp[0],-0.85); 
    10901092 
    10911093        /* molecular weight of grain molecule (amu) */ 
     
    11081110        mie_next_data(chFile,io2,chLine,&dl); 
    11091111        mie_read_realnum(chFile,chLine,&gv.bin[nd]->AvRadius,true,dl); 
     1112        gv.bin[nd]->eyc = 1./gv.bin[nd]->AvRadius + 1.e7; 
    11101113 
    11111114        /* average grain area <4pi*a^2> for entire size distr (cm^2) */ 
     
    12791282                                        gv.bin[nd2]->dustp[j] = gv.bin[nd]->dustp[j]; 
    12801283                                } 
     1284                                gv.bin[nd2]->eec = gv.bin[nd]->eec; 
     1285                                gv.bin[nd2]->eyc = gv.bin[nd]->eyc; 
    12811286                                gv.bin[nd2]->DustWorkFcn = gv.bin[nd]->DustWorkFcn; 
    12821287                                gv.bin[nd2]->BandGap = gv.bin[nd]->BandGap; 
  • trunk/source/grainvar.h

    r1813 r2108  
    240240        /** general information on the grains */ 
    241241        char chDstLab[13];      /**< label for the species */ 
     242        double eec;             /**< pow(dustp[0],-0.85), needed for electron esacpe length */ 
     243        double eyc;            /**< 1./AvRadius + 1.e7, needed for electron yield */ 
    242244        realnum dustp[5],       /**< 0 = specific weight (g/cm^3), 1 = mol. weight (amu), 2 = default abundance, 
    243245                                 *   3 = default depletion, 4 = fraction of the mass in this grain bin */