Changeset 1600

Show
Ignore:
Timestamp:
12/01/07 17:09:37 (12 months ago)
Author:
rjrw
Message:

Remove some commented out stuff,

change a conservation test that should no longer be active to an
ASSERT,

instrument convergence of S ion in conv_base which seems a good
bellweather for pdr_co_fully.

Location:
branches/newmole/source
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/newmole/source/conv_base.cpp

    r1599 r1600  
    378378        { 
    379379 
    380                 fprintf(ioQQQ,"Start of loop %g\n",dense.xIonDense[15][0]); 
    381380                check_conserve(__FILE__,__LINE__); 
    382381         
     
    413412                /*fprintf(ioQQQ,"DEBUG h2\t%.2f\t%.3e\t%.3e", fnzone,hmi.H2_total,findspecies("H2")->hevmol);*/ 
    414413                iso_solve( ipH_LIKE ); 
    415                 fprintf(ioQQQ,"After H_LIKE %g\n",dense.xIonDense[15][0]); 
    416414 
    417415                /* now do level populations for H2 */ 
     
    434432                /* do all he-like species */ 
    435433                iso_solve( ipHE_LIKE ); 
    436                 fprintf(ioQQQ,"After He_like %g\n",dense.xIonDense[15][0]); 
    437434 
    438435                /*>>chng 04 may 09, add option to abort here, inspired by H2 pop failures 
     
    509506                IonOxyge(); 
    510507                IonNitro(); 
    511                 fprintf(ioQQQ,"Before Si %g\n",dense.xIonDense[15][0]); 
    512508                IonSilic(); 
    513                 fprintf(ioQQQ,"Before S %g\n",dense.xIonDense[15][0]); 
     509#define DEBUGRW 1 
     510                if (DEBUGRW) fprintf(ioQQQ," DEBUG Before S %g\n",dense.xIonDense[15][0]); 
    514511                IonSulph(); 
    515                 fprintf(ioQQQ,"After ion %g\n",dense.xIonDense[15][0]); 
     512                if (DEBUGRW) fprintf(ioQQQ," DEBUG After S %g\n",dense.xIonDense[15][0]); 
    516513                IonChlor(); 
    517514                check_conserve(__FILE__,__LINE__); 
     
    519516                /* do carbon monoxide after oxygen */ 
    520517                CO_drive(); 
    521                 fprintf(ioQQQ,"After mole %g\n",dense.xIonDense[15][0]); 
     518                if (DEBUGRW) fprintf(ioQQQ," DEBUG After mole %g\n",dense.xIonDense[15][0]); 
     519#undef DEBUGRW 
    522520 
    523521                check_conserve(__FILE__,__LINE__); 
  • branches/newmole/source/ion_solver.cpp

    r1586 r1600  
    6464        abund_total = SDIV ( dense.gas_phase[nelem] -  dense.xMolecules[nelem] ); 
    6565 
    66         /* >>chng 04 nov 22, 
    67          * if gas nearly all atomic/ionic do not let source - sink terms from  
    68          * molecular network force system of balance equations to become  
    69          * inhomogeneous 
    70          * what constitutes a source or sink IS DIFFERENT for hydrogen and the rest  
    71          * the H solution must couple with hmole - and its defn of source and sink.  For instance, oxygen charge 
    72          * transfer goes into source and sink terms for hydrogen.  So we never hose source and sink for H. 
    73          * for the heavy elements, which couple onto comole, mole.source and sink represent terms that 
    74          * remove atoms and ions from the ionization ladder.  their presence makes the system of 
    75          * equations inhomogeneous.  we don't want to do this when comole has a trivial effect on 
    76          * the ionization balance since the matrix becomes unstable */ 
    77         /* >>chng 04 dec 06, limit from 0.01 to 1e-10 as per NA suggestion */ 
    78 #if 0 
    79         if( nelem>ipHYDROGEN && dense.xMolecules[nelem]/SDIV(dense.gas_phase[nelem]) < 1e-10 ) 
    80         { 
    81                 for( ion=dense.IonLow[nelem]; ion<=dense.IonHigh[nelem]; ++ion ) 
    82                 { 
    83                         mole.source[nelem][ion] = 0.; 
    84                         mole.sink[nelem][ion] = 0.; 
    85                 } 
    86         } 
    87  
    88         /* protect against case where all gas phase abundances are in molecules, use the 
    89          * atomic and first ion density from the molecule solver  
    90          * >>chng 04 aug 15, NA change from 10 0000 to 10 pre-coef on 
    91          * FLT_EPSILON for stability in PDR  
    92          * the factor 10.*FLT_EPSILON also appears in mole_h_step in total H  
    93          * conservation */ 
    94         if( fabs( dense.gas_phase[nelem] -  dense.xMolecules[nelem])/SDIV(dense.gas_phase[nelem] ) < 
    95                 10.*FLT_EPSILON ) 
    96         { 
    97                 double renorm; 
    98                 /* >>chng 04 jul 31, add logic to conserve nuclei in fully molecular limit; 
    99                  * in first calls, when searching for solution, we may be VERY far  
    100                  * off, and sum of first ion and atom density may be far larger  
    101                  * than difference between total gas and molecular densities, 
    102                  * since they reflect the previous evaluation of the solution.  Do  
    103                  * renorm to cover this case */ 
    104                 /* first form sum of all atoms and ions */ 
    105                 realnum sum = 0.; 
    106                 for( ion=dense.IonLow[nelem]; ion<=dense.IonHigh[nelem]; ++ion ) 
    107                         sum += dense.xIonDense[nelem][ion]; 
    108                 /* now renorm to this sum - this should be unity, and is not if we have 
    109                  * now conserved particles, due to molecular fraction changing */ 
    110                 renorm = dense.gas_phase[nelem] / SDIV(sum + dense.xMolecules[nelem] ); 
    111  
    112                 abund_total = renorm * sum; 
    113         } 
    114  
    115         /* negative residual density */ 
    116         if( abund_total < 0. ) 
    117         { 
    118                 /* >>chng 05 dec 16, do not abort when net atomic/ ionic abundance  
    119                  * is negative due to chem net having too much of a species - this  
    120                  * happens naturally when ices become well formed, but the code will  
    121                  * converge away from it.  Rather, we set the ionization 
    122                  * convergence flag to "not converge" and soldier on  
    123                  * if negative populations do not go away, we will eventually  
    124                  * terminate due to convergence failures */ 
    125                 /* print error if not search */ 
    126                 if( !conv.lgSearch ) 
    127                         fprintf(ioQQQ, 
    128                                 "PROBLEM ion_solver - neg net atomic abundance zero for nelem= %li, rel val= %.2e conv.nTotalIoniz=%li, fixed\n", 
    129                                 nelem, 
    130                                 fabs(abund_total) / SDIV(dense.xMolecules[nelem]), 
    131                                 conv.nTotalIoniz ); 
    132                 /* fix up is to use half the positive abundance, assuming chem is  
    133                  * trying to get too much of this species */ 
    134                 abund_total = -abund_total/2.; 
    135  
    136                 /* say that ionization is not converged - do not abort - but if  
    137                  * cannot converge away from negative solution, this will become a  
    138                  * convergence failure abort */ 
    139                 conv.lgConvIoniz = false; 
    140                 strcpy( conv.chConvIoniz, "neg ion" ); 
    141         } 
    142 #endif 
    143  
    14466        if (dense.gas_phase[nelem] <  dense.xMolecules[nelem])  
    14567        { 
    146                 fprintf(stdout,"Bad density %li %g %g\n",nelem,dense.gas_phase[nelem],dense.xMolecules[nelem]); 
     68                fprintf(stdout," DISASTER ion_solver: Bad density %li %g %g\n",nelem,dense.gas_phase[nelem],dense.xMolecules[nelem]); 
     69                puts( "[Stop in ion_solver]" ); 
     70                cdEXIT(EXIT_FAILURE); 
    14771        } 
    14872 
     
    455379 
    456380                        /* these are the external source and sink terms */ 
    457                         /* source first */ 
    458381                        /* need negative sign to get positive pops */ 
    459382                        source[i] -= mole.source[nelem][ion]; 
    460  
    461383                        totsrc += mole.source[nelem][ion]; 
    462                         /* sink next */ 
    463                         /*MAT( xmat, i, i ) += mole.sink[nelem][ion];*/ 
    464384                        MAT( xmat, i, i ) -= mole.sink[nelem][ion]; 
    465385                } 
     
    478398                {                         
    479399                        ion = i+ion_low; 
    480                         /*MAT( xmat, i, i ) += dynamics.Rate;*/ 
    481400                        MAT( xmat, i, i ) -= dynamics.Rate; 
    482                         /*src[i] += dynamics.Source[nelem][ion];*/ 
    483401                        source[i] -= dynamics.Source[nelem][ion]; 
    484402                        /* fprintf(ioQQQ," %li %li %.3e (%.3e %.3e)\n",i,i,MAT(xmat,i,i), 
  • branches/newmole/source/mole_co_solve.cpp

    r1599 r1600  
    7373                                mole.source[nelem][ion] = mole.src[element_list[nelem]->ipMl[ion]]; 
    7474                                mole.sink[nelem][ion] = mole.snk[element_list[nelem]->ipMl[ion]]; 
    75                                 // dense.xIonDense[nelem][ion] = (realnum) COmole[element_list[nelem]->ipMl[ion]]->hevmol; 
     75                                if (dense.IonLow[nelem] > ion) 
     76                                        dense.IonLow[nelem] = ion; 
     77                                if (dense.IonHigh[nelem] < ion) 
     78                                        dense.IonHigh[nelem] = ion;                                      
    7679                        } 
    7780                        else 
     
    8184                        } 
    8285                } 
    83                 if (element_list[nelem]->ipMl[0] != -1) 
    84                 { 
    85                         dense.IonLow[nelem] = 0; 
    86                         dense.IonHigh[nelem] = MAX2( dense.IonHigh[nelem] , 1 ); 
    87                 } 
    8886        } 
    8987 
    9088        /* if populations not conserved then not converged */ 
    91 #       define EPS_MOLE 0.1 
    92         if( dense.lgElmtOn[ipHYDROGEN] && 
    93                 dense.xMolecules[ipHYDROGEN] > dense.gas_phase[ipHYDROGEN]*(1.+EPS_MOLE) ) 
    94         { 
    95                 conv.lgConvIoniz = false; 
    96                 sprintf( conv.chConvIoniz, "COcon%2i",ipHYDROGEN ); 
    97                 conv.BadConvIoniz[0] = dense.xMolecules[ipHYDROGEN]; 
    98                 conv.BadConvIoniz[1] = dense.gas_phase[ipHYDROGEN]; 
    99         } 
    100         else 
    101         { 
    102                 for (nelem=0;nelem<LIMELM; ++nelem) 
    103                 { 
    104                         element = element_list[nelem]; 
    105                         if( dense.lgElmtOn[nelem] && 
    106                                         dense.xMolecules[nelem] > dense.gas_phase[nelem]*(1.+EPS_MOLE) ) 
    107                         { 
    108                                 conv.lgConvIoniz = false; 
    109                                 sprintf( conv.chConvIoniz, "COcon%2li",nelem ); 
    110                                 conv.BadConvIoniz[0] = dense.xMolecules[nelem]; 
    111                                 conv.BadConvIoniz[1] = dense.gas_phase[nelem]; 
    112                                 break; 
    113                         } 
    114                 } 
    115         } 
     89#       define EPS_MOLE 0.01 
     90        for (nelem=0;nelem<LIMELM; ++nelem) 
     91        { 
     92                element = element_list[nelem]; 
     93                if( dense.lgElmtOn[nelem] ) 
     94                        ASSERT(dense.xMolecules[nelem] <= dense.gas_phase[nelem]*(1.+EPS_MOLE) ); 
     95        } 
     96#       undef EPS_MOLE 
    11697 
    11798        DEBUG_EXIT( "CO_solve()" ); 
     
    122103} 
    123104 
    124 #       undef EPS_MOLE 
    125105 
    126106// #define SVD 
  • branches/newmole/source/mole_h_step.cpp

    r1590 r1600  
    613613 
    614614        CO_return_cached_species(); 
     615 
    615616        hmi.H2_total = 0.; 
    616617        /* this is where the transition struc expects to find the H2 abundance */