Changeset 1179

Show
Ignore:
Timestamp:
06/09/07 13:18:05 (18 months ago)
Author:
gary
Message:

most files change because hard lower and upper limits to range of allowed temperatures changed to macro set in cddefines.h - this defines the following:
const double TEMP_STOP_DEFAULT = 4000.;
/** highest temperature to ever allow */
const double TEMP_LIMIT_HIGH = 1e10;
/** lowest temperature to ever allow */
const double TEMP_LIMIT_LOW = 2.8;

optimize_func.cpp - do not gather optimization quality metric in case where grid is being run. some grid models may abort due to T < 2.8K in which case it is not possible to gather this info anyway.

Location:
trunk/source
Files:
16 modified

Legend:

Unmodified
Added
Removed
  • trunk/source/abundances.cpp

    r1147 r1179  
    223223        /* if stop temp set below default then we are going into cold and possibly molecular 
    224224         * gas - check some parameters in this case */ 
    225         if( called.lgTalk && (StopCalc.tend < TEND ||  
     225        if( called.lgTalk && (StopCalc.tend < TEMP_STOP_DEFAULT ||  
    226226                /* thermal.ConstTemp def is zero, set pos when used */ 
    227                 (thermal.ConstTemp > 0. && thermal.ConstTemp < TEND ) ) ) 
     227                (thermal.ConstTemp > 0. && thermal.ConstTemp < TEMP_STOP_DEFAULT ) ) ) 
    228228        { 
    229229 
  • trunk/source/cddefines.h

    r1148 r1179  
    175175const int NHYDRO_MAX_LEVEL = 401; 
    176176 
    177 /** dimension of vector to do with number of iterations stored 
    178  * so, this is the the most that can possibly be performed */ 
    179 /*const int ITR DIM = 200;*/ 
    180  
    181177/** number of hydrogen species in hmole */ 
    182178const int N_H_MOLEC = 8; 
    183179 
    184 /** stopping temperature */ 
    185 const double TEND = 4000.; 
     180/** The default value of the stopping temperature */ 
     181const double TEMP_STOP_DEFAULT = 4000.; 
     182/** highest temperature to ever allow */ 
     183const double TEMP_LIMIT_HIGH = 1e10; 
     184/** lowest temperature to ever allow */ 
     185const double TEMP_LIMIT_LOW = 2.8; 
    186186 
    187187/** this is used to add to depth to prevent div or log of zero */ 
  • trunk/source/conv_init_solution.cpp

    r1178 r1179  
    44#include "cddefines.h" 
    55#include "trace.h" 
    6 #include "stopcalc.h" 
    76#include "struc.h" 
    87#include "rfield.h" 
     
    328327                                  phycon.te, thermal.htot, thermal.ctot, Cool_min_Heat ); 
    329328                        } 
    330                         /* check range 10-4000K, TeLowest usually 2.8K, set with SET LOWEST command 
     329                        /* check range 10-4000K, TEMP_LIMIT_LOW is lowest possible temperature 
    331330                         * following are series of tests that determine the factor by which 
    332331                         * which can change the temperature.  must be VERY small when  
    333332                         * ice formation on grains is important due to exponential sublimation 
    334333                         * rate.  Also small when molecules are important, to keep chemistry 
    335                          * within limits of linearization solver */ 
     334                         * within limits of linearized solver */ 
    336335                        fac2 = 0.8; 
    337                         while( phycon.te*fac2 > StopCalc.TeLowest && Cool_min_Heat >= 0. && !lgAbort ) 
     336                        while( phycon.te*fac2 > TEMP_LIMIT_LOW && Cool_min_Heat >= 0. && !lgAbort ) 
    338337                        { 
    339338                                double oxy_in_grains; 
     
    474473                                ShowMe(); 
    475474                                 
     475                                /* this is an error return, calculation will immediately stop */ 
    476476                                DEBUG_EXIT( "ConvInitSolution()" ); 
     477                                return(1); 
     478                        } 
     479                        else if( thermal.ctot > thermal.htot ) 
     480                        { 
     481                                /* even at lowest temp, too much cooling; no solution possible */ 
     482                                fprintf( ioQQQ,  
     483                                        "PROBLEM The initial kinetic temperature was below %.1e K," 
     484                                        " the lowest possible temperature I can consider." 
     485                                        "\nSorry, but I cannot go on.\n\n",  
     486                                  TEMP_LIMIT_LOW ); 
     487 
    477488                                /* this is an error return, calculation will immediately stop */ 
    478                                 return(1); 
    479                         } 
    480                         else if( thermal.ctot > thermal.htot ) 
    481                         { 
    482                                 /* even at lowest temp, too much cooling; no solution possible */ 
    483                                 fprintf( ioQQQ, " Equilibrium temperature below T=%8.2e.  If this is OK, then reset with LOWEST command.  This is ConvInitSolution.  TeLowest was%9.2e\n",  
    484                                   phycon.te, StopCalc.TeLowest ); 
    485                                  
    486489                                DEBUG_EXIT( "ConvInitSolution()" ); 
    487                                 /* this is an error return, calculation will immediately stop */ 
    488490                                return(1); 
    489491                        } 
     
    505507 
    506508                /* coming up to here te is either 4,000 (usually) or 10^6 */ 
    507                 t1 = StopCalc.TeLowest/1.001; 
     509                t1 = TEMP_LIMIT_LOW/1.001; 
    508510 
    509511                /* >>chng 96 dec 28, added div by factor to prevent checking on temp > 1e10 */ 
    510                 t2 = StopCalc.TeHighest*1.001/factor; 
     512                t2 = TEMP_LIMIT_HIGH*1.001/factor; 
    511513                if( trace.nTrConvg ) 
    512514                { 
  • trunk/source/conv_temp_eden_ioniz.cpp

    r761 r1179  
    1414#include "colden.h" 
    1515#include "h2.h" 
    16 #include "stopcalc.h" 
    1716#include "pressure.h" 
    1817#include "dense.h" 
     
    943942{ 
    944943        bool lgRet; 
    945         /* >>chng 03 sep 19, add check on StopCalc.TeLowest */ 
     944        /* >>chng 03 sep 19, add check on TEMP_LIMIT_LOW */ 
    946945        if( fabs(thermal.htot - thermal.ctot)/thermal.htot <= conv.HeatCoolRelErrorAllowed || 
    947                 thermal.lgTSetOn || phycon.te <= StopCalc.TeLowest ) 
     946                thermal.lgTSetOn || phycon.te <= TEMP_LIMIT_LOW ) 
    948947        { 
    949948                /* announce that temp is converged if relative heating - cooling mismatch 
  • trunk/source/date.h

    r1175 r1179  
    99#define YEAR    107 
    1010#define MONTH   5 
    11 #define DAY     7 
     11#define DAY     9 
  • trunk/source/init_defaults_preparse.cpp

    r1178 r1179  
    143143        StopCalc.AV_point = 1e30f; 
    144144        /* highest allowed temperature */ 
    145         StopCalc.T2High = 1e12f; 
    146  
    147         /* highest and lowest temperatures to ever allow */ 
    148         StopCalc.TeHighest = 1e10f; 
    149         StopCalc.TeLowest = 2.8f; 
     145        StopCalc.T2High = (float)TEMP_LIMIT_HIGH; 
    150146 
    151147        /* the floor sets a limit to the temperature in the calculation - 
     
    155151 
    156152        /* this is in cddefines.h and is 4000 */ 
    157         StopCalc.tend = (float)TEND; 
     153        StopCalc.tend = (float)TEMP_STOP_DEFAULT; 
    158154        /* ending column densities */ 
    159155        StopCalc.HColStop = COLUMN_INIT; 
  • trunk/source/map.cpp

    r759 r1179  
    66#include "thermal.h" 
    77#include "cooling.h" 
    8 #include "stopcalc.h" 
    98#include "called.h" 
    109#include "dense.h" 
     
    125124        { 
    126125                /* create some sort of map of heating-cooling */ 
    127                 tlowst = MAX2(map.RangeMap[0],StopCalc.TeLowest); 
     126                tlowst = MAX2(map.RangeMap[0],TEMP_LIMIT_LOW); 
    128127                tmin = tlowst*0.998; 
    129                 tmax = MIN2(map.RangeMap[1],StopCalc.TeHighest)*1.002; 
     128                tmax = MIN2(map.RangeMap[1],TEMP_LIMIT_HIGH)*1.002; 
    130129 
    131130                /* we want about nMapStep (=20) steps between high and low temperature */ 
     
    137136                        factor = 1./factor; 
    138137                        /* TeHighest is highest possible temperature, 1E10 */ 
    139                         phycon.te = (MIN2(map.RangeMap[1],StopCalc.TeHighest)/factor); 
     138                        phycon.te = (MIN2(map.RangeMap[1],TEMP_LIMIT_HIGH)/factor); 
    140139                } 
    141140 
  • trunk/source/mole_h2.cpp

    r1178 r1179  
    28312831                        conv.HeatCoolRelErrorAllowed/2. 
    28322832                        /* >>chng 04 may 09, do not check on error in heating if constant temperature */ 
    2833                         /*&& !(thermal.lgTSetOn || phycon.te <= StopCalc.TeLowest  )*/ ) 
     2833                        /*&& !(thermal.lgTSetOn || phycon.te <= TEMP_LIMIT_LOW  )*/ ) 
    28342834                { 
    28352835                        /* default on HeatCoolRelErrorAllowed is 0.02 */ 
  • trunk/source/optimize_func.cpp

    r1178 r1179  
    130130                GridInitialize(); 
    131131        } 
    132  
    133         /* Line fluxes now in commn blocks, so extract and 
    134          * compare with observations */ 
    135         chisq = 0.0; 
    136         for( i=0; i < MAXCAT; i++ ) 
    137         { 
    138                 nobs_cat[i] = 0; 
    139                 chi2_cat[i] = 0.0; 
    140         } 
    141  
    142         if( LineSave.ipNormWavL < 0 ) 
    143         { 
    144                 fprintf( ioQQQ,  
    145                         " Normalization line array index is bad.  What has gone wrong?\n" ); 
    146                 puts( "[Stop in optimize_func]" ); 
    147                 cdEXIT(EXIT_FAILURE); 
    148         } 
    149         snorm = LineSv[LineSave.ipNormWavL].sumlin[LineSave.lgLineEmergent]; 
    150  
    151         if( snorm == 0. ) 
    152         { 
    153                 fprintf( ioQQQ, "\n\n PROBLEM Normalization line has zero intensity.  What has gone wrong?\n" ); 
    154                 fprintf( ioQQQ, " Is spectrum normalized to a species that does not exist?\n" ); 
    155                 puts( "[Stop in optimize_func]" ); 
    156                 cdEXIT(EXIT_FAILURE); 
    157         } 
    158  
    159         /* first print all warnings */ 
    160         cdWarnings(ioQQQ); 
    161  
    162         /* cycle through the observational values */ 
    163         nfound = 0; 
    164          
    165         /* first is to optimize relative emission line spectrum */ 
    166         if( optimize.lgOptLin ) 
    167         { 
    168                 /* set pointers to all optimized lines if first call */ 
    169                 if( !lgLinSet ) 
    170                 { 
    171                         lgHIT = true; 
    172                         lgLinSet = true; 
     132        else 
     133        { 
     134                /* this branch optimizing, not grid  
     135                / * extract line fluxes and compare with observations */ 
     136                chisq = 0.0; 
     137                for( i=0; i < MAXCAT; i++ ) 
     138                { 
     139                        nobs_cat[i] = 0; 
     140                        chi2_cat[i] = 0.0; 
     141                } 
     142 
     143                if( LineSave.ipNormWavL < 0 ) 
     144                { 
     145                        fprintf( ioQQQ,  
     146                                " Normalization line array index is bad.  What has gone wrong?\n" ); 
     147                        puts( "[Stop in optimize_func]" ); 
     148                        cdEXIT(EXIT_FAILURE); 
     149                } 
     150 
     151                if( (snorm = LineSv[LineSave.ipNormWavL].sumlin[LineSave.lgLineEmergent]) == 0. ) 
     152                { 
     153                        fprintf( ioQQQ, "\n\n PROBLEM Normalization line has zero intensity.  What has gone wrong?\n" ); 
     154                        fprintf( ioQQQ, " Is spectrum normalized to a species that does not exist?\n" ); 
     155                        puts( "[Stop in optimize_func]" ); 
     156                        cdEXIT(EXIT_FAILURE); 
     157                } 
     158 
     159                /* first print all warnings */ 
     160                cdWarnings(ioQQQ); 
     161 
     162                /* cycle through the observational values */ 
     163                nfound = 0; 
     164                 
     165                /* first is to optimize relative emission line spectrum */ 
     166                if( optimize.lgOptLin ) 
     167                { 
     168                        /* set pointers to all optimized lines if first call */ 
     169                        if( !lgLinSet ) 
     170                        { 
     171                                lgHIT = true; 
     172                                lgLinSet = true; 
     173                                for( i=0; i < optimize.nlobs; i++ ) 
     174                                { 
     175                                        double temp1, temp2; 
     176                                        cap4(chFind , (char*)optimize.chLineLabel[i]); 
     177                                        /* j = 0; */ 
     178 
     179                                        /* >> chng 06 may 04, use cdLine instead of ad hoc treatment. 
     180                                         * no need to complain, cdLine will do it automatically.  */ 
     181                                        /* this is an intensity, get the line, returns false if could not find it */ 
     182                                        j=cdLine( chFind , optimize.wavelength[i] , &temp1, &temp2 ); 
     183                                        if( j<=0 ) 
     184                                        { 
     185                                                fprintf( ioQQQ, "\n" ); 
     186                                                lgHIT = false; 
     187                                        } 
     188                                        else 
     189                                        { 
     190                                                ipobs[i] = j; 
     191                                        } 
     192                                } 
     193 
     194                                /* we did not find the line */ 
     195                                if( !lgHIT ) 
     196                                { 
     197                                        fprintf( ioQQQ, "\n\n Optimizer could not find one or more lines.\n" ); 
     198                                        fprintf( ioQQQ, " Sorry.\n"); 
     199                                        puts( "[Stop in optimize_func]" ); 
     200                                        cdEXIT(EXIT_FAILURE); 
     201                                } 
     202                        } 
     203 
     204                        for( i=0; i < 10; i++ ) 
     205                        { 
     206                                optimize.SavGenericData[i] = 0.; 
     207                        } 
     208 
    173209                        for( i=0; i < optimize.nlobs; i++ ) 
    174210                        { 
    175                                 double temp1, temp2; 
    176                                 cap4(chFind , (char*)optimize.chLineLabel[i]); 
    177                                 /* j = 0; */ 
    178  
    179                                 /* >> chng 06 may 04, use cdLine instead of ad hoc treatment. 
    180                                  * no need to complain, cdLine will do it automatically.  */ 
    181                                 /* this is an intensity, get the line, returns false if could not find it */ 
    182                                 j=cdLine( chFind , optimize.wavelength[i] , &temp1, &temp2 ); 
    183                                 if( j<=0 ) 
     211                                /* and find corresponding model value by straight search */ 
     212                                nfound += 1; 
     213                                scld = (double)LineSv[ipobs[i]].sumlin[LineSave.lgLineEmergent]/(double)snorm*LineSave.ScaleNormLine; 
     214                                chi1 = chi2_func(scld,(double)optimize.xLineInt_Obs[i],(double)optimize.xLineInt_error[i]); 
     215                                cat = 0; 
     216                                nobs_cat[cat]++; 
     217                                chi2_cat[cat] += chi1; 
     218 
     219                                fprintf( ioQQQ, " %4.4s ",  
     220                                  LineSv[ipobs[i]].chALab); 
     221 
     222                                prt_wl( ioQQQ,LineSv[ipobs[i]].wavelength); 
     223 
     224                                fprintf( ioQQQ, "%12.5f%12.5f%12.5f%12.2e Relative intensity",  
     225                                  scld,  
     226                                  optimize.xLineInt_Obs[i],  
     227                                  optimize.xLineInt_error[i],  
     228                                  chi1 ); 
     229                                 
     230                                fprintf( ioQQQ, "\n" ); 
     231 
     232                                if( i<10 ) 
    184233                                { 
    185                                         fprintf( ioQQQ, "\n" ); 
    186                                         lgHIT = false; 
     234                                        optimize.SavGenericData[i] = chi1; 
    187235                                } 
    188                                 else 
     236                        } 
     237                } 
     238 
     239                /* >>chng 06 may 04, moved this from above so that it only 
     240                 * gets printed if all lines are found */ 
     241                /*if( optimize.lgOptLum || optimize.lgOptCol || optimize.lgOptTemp || optimize.lgOptLin )*/ 
     242                if( optimize.lgOptimize ) 
     243                { 
     244                        fprintf( ioQQQ, "  ID               Model    Observed       error      chi**2     Type\n" ); 
     245                } 
     246                else 
     247                { 
     248                        ASSERT( grid.lgGrid ); 
     249                } 
     250 
     251                /* this is to optimize a mean temperature */ 
     252                if( optimize.lgOptTemp ) 
     253                { 
     254                        for( i=0; i < optimize.nTempObs; i++ ) 
     255                        { 
     256                                if( cdTemp(/*(char*)*/optimize.chTempLab[i],optimize.ionTemp[i], &temp_theory, optimize.chTempWeight[i]) ) 
    189257                                { 
    190                                         ipobs[i] = j; 
     258                                        /* did not find column density */ 
     259                                        fprintf(ioQQQ," optimizer did not find column density %s %li \n", 
     260                                                optimize.chTempLab[i],optimize.ionTemp[i] ); 
     261                                        puts( "[Stop in optimize_func]" ); 
     262                                        cdEXIT(EXIT_FAILURE); 
    191263                                } 
    192                         } 
    193  
    194                         /* we did not find the line */ 
    195                         if( !lgHIT ) 
    196                         { 
    197                                 fprintf( ioQQQ, "\n\n Optimizer could not find one or more lines.\n" ); 
    198                                 fprintf( ioQQQ, " Sorry.\n"); 
    199                                 puts( "[Stop in optimize_func]" ); 
    200                                 cdEXIT(EXIT_FAILURE); 
    201                         } 
    202                 } 
    203  
    204                 for( i=0; i < 10; i++ ) 
    205                 { 
    206                         optimize.SavGenericData[i] = 0.; 
    207                 } 
    208  
    209                 for( i=0; i < optimize.nlobs; i++ ) 
    210                 { 
    211                         /* and find corresponding model value by straight search */ 
     264                                nfound += 1; 
     265                                chi1 = chi2_func(temp_theory,(double)optimize.temp_obs[i],(double)optimize.temp_error[i]); 
     266                                cat = 3; 
     267                                nobs_cat[cat]++; 
     268                                chi2_cat[cat] += chi1; 
     269 
     270                                fprintf( ioQQQ, " %4.4s %2ld        ", 
     271                                  optimize.chTempLab[i],  
     272                                  optimize.ionTemp[i] ); 
     273                                PrintE82( ioQQQ, temp_theory ); 
     274                                fprintf( ioQQQ, "    "); 
     275                                PrintE82( ioQQQ, optimize.temp_obs[i] ); 
     276                                fprintf( ioQQQ, "    %.5f   %.2e",  
     277                                        optimize.temp_error[i],  chi1 ); 
     278                                fprintf( ioQQQ, " Temperature\n"); 
     279                        } 
     280                } 
     281 
     282                /* option to optimize column densities */ 
     283                if( optimize.lgOptCol ) 
     284                { 
     285                        for( i=0; i < optimize.ncobs; i++ ) 
     286                        { 
     287                                if( cdColm((char*)optimize.chColDen_label[i],optimize.ion_ColDen[i], &theocl) ) 
     288                                { 
     289                                        /* did not find column density */ 
     290                                        fprintf(ioQQQ," optimizer did not find column density %s %li \n", 
     291                                                optimize.chColDen_label[i],optimize.ion_ColDen[i] ); 
     292                                        puts( "[Stop in optimize_func]" ); 
     293                                        cdEXIT(EXIT_FAILURE); 
     294                                } 
     295                                nfound += 1; 
     296                                chi1 = chi2_func(theocl,(double)optimize.ColDen_Obs[i],(double)optimize.chColDen_error[i]); 
     297                                cat = 1; 
     298                                nobs_cat[cat]++; 
     299                                chi2_cat[cat] += chi1; 
     300 
     301                                fprintf( ioQQQ, " %4.4s%6ld%12.4e%12.4e%12.5f%12.2e Column density\n",  
     302                                  optimize.chColDen_label[i], optimize.ion_ColDen[i], theocl,  
     303                                  optimize.ColDen_Obs[i], optimize.chColDen_error[i], chi1 ); 
     304                        } 
     305                } 
     306 
     307                /* option to optimize line flux */ 
     308                if( optimize.lgOptLum ) 
     309                { 
    212310                        nfound += 1; 
    213                         scld = (double)LineSv[ipobs[i]].sumlin[LineSave.lgLineEmergent]/(double)snorm*LineSave.ScaleNormLine; 
    214                         chi1 = chi2_func(scld,(double)optimize.xLineInt_Obs[i],(double)optimize.xLineInt_error[i]); 
    215                         cat = 0; 
     311                        if( LineSv[LineSave.ipNormWavL].sumlin[LineSave.lgLineEmergent] > 0.f ) 
     312                        { 
     313                                predin = log10(LineSv[LineSave.ipNormWavL].sumlin[LineSave.lgLineEmergent]) + radius.Conv2PrtInten; 
     314                                help = pow(10.,predin-(double)optimize.optint); 
     315                                chi1 = chi2_func(help,1.,(double)optimize.optier); 
     316                        } 
     317                        else 
     318                        { 
     319                                predin = -999.99999; 
     320                                chi1 = (double)FLT_MAX; 
     321                        } 
     322                        cat = 2; 
    216323                        nobs_cat[cat]++; 
    217324                        chi2_cat[cat] += chi1; 
    218325 
    219                         fprintf( ioQQQ, " %4.4s ",  
    220                           LineSv[ipobs[i]].chALab); 
    221  
    222                         prt_wl( ioQQQ,LineSv[ipobs[i]].wavelength); 
    223  
    224                         fprintf( ioQQQ, "%12.5f%12.5f%12.5f%12.2e Relative intensity",  
    225                           scld,  
    226                           optimize.xLineInt_Obs[i],  
    227                           optimize.xLineInt_error[i],  
     326                        fprintf( ioQQQ, " %4.4s%6f%12.5f%12.5f%12.5f%12.2e Line intensity\n",  
     327                          LineSv[LineSave.ipNormWavL].chALab,  
     328                          LineSv[LineSave.ipNormWavL].wavelength,  
     329                          predin,  
     330                          optimize.optint,  
     331                          optimize.optier,  
    228332                          chi1 ); 
    229                          
    230                         fprintf( ioQQQ, "\n" ); 
    231  
    232                         if( i<10 ) 
    233                         { 
    234                                 optimize.SavGenericData[i] = chi1; 
    235                         } 
    236                 } 
    237         } 
    238  
    239         /* >>chng 06 may 04, moved this from above so that it only 
    240          * gets printed if all lines are found */ 
    241         if( optimize.lgOptLum || optimize.lgOptCol || optimize.lgOptTemp || optimize.lgOptLin ) 
    242         { 
    243                 fprintf( ioQQQ, "  ID               Model    Observed       error      chi**2     Type\n" ); 
    244         } 
    245         else 
    246         { 
    247                 ASSERT( grid.lgGrid ); 
    248         } 
    249  
    250         /* this is to optimize a mean temperature */ 
    251         if( optimize.lgOptTemp ) 
    252         { 
    253                 for( i=0; i < optimize.nTempObs; i++ ) 
    254                 { 
    255                         if( cdTemp(/*(char*)*/optimize.chTempLab[i],optimize.ionTemp[i], &temp_theory, optimize.chTempWeight[i]) ) 
    256                         { 
    257                                 /* did not find column density */ 
    258                                 fprintf(ioQQQ," optimizer did not find column density %s %li \n", 
    259                                         optimize.chTempLab[i],optimize.ionTemp[i] ); 
    260                                 puts( "[Stop in optimize_func]" ); 
    261                                 cdEXIT(EXIT_FAILURE); 
    262                         } 
    263                         nfound += 1; 
    264                         chi1 = chi2_func(temp_theory,(double)optimize.temp_obs[i],(double)optimize.temp_error[i]); 
    265                         cat = 3; 
    266                         nobs_cat[cat]++; 
    267                         chi2_cat[cat] += chi1; 
    268  
    269                         fprintf( ioQQQ, " %4.4s %2ld        ", 
    270                           optimize.chTempLab[i],  
    271