Show
Ignore:
Timestamp:
12/16/07 06:22:43 (11 months ago)
Author:
rjrw
Message:

Fixes to get dynamics running with conservation constraints applied.

ion_solver now renormalizes for /all/ cases, the dynamic sources to
the ladder are applied in the molecular network.

Small recodings to fold trimmed advective species into the highest
state available and reorder a logical test so the most likely failure
comes first (small short-circuit optimization).

Location:
branches/newmole/source
Files:
3 modified

Legend:

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

    r1653 r1681  
    774774                        { 
    775775                                dynamics.Source[nelem][ion] = 0.; 
     776                                dynamics.Source[nelem][dense.IonHigh[nelem]] +=  
     777                                        UpstreamIon[nelem][ion] * scalingDensity() / timestep; 
    776778                        } 
    777779                } 
     
    948950                                 Old_molecules[ipUpstream][mol]/Old_density[ipUpstream])* 
    949951                                frac_next; 
    950                         /* Atoms and positive ions are already counted in upstreamElem */ 
     952                        /* Atoms and positive ions are already counted in UpstreamElem */ 
    951953                        if(COmole[mol]->n_nuclei != 1 || COmole[mol]->nElec < 0)  
    952954                        { 
     
    15061508                                        Oldi_ion = Old_xIonDense[ilast][nelem][ion]; 
    15071509                                } 
    1508                                 dynamics.convergence_error += POW2(Oldi_ion/Oldi_density-struc.xIonDense[nelem][ion][i]/scalingZoneDensity(i)) /* *struc.dr[i] */;   
     1510                                dynamics.convergence_error += POW2((double)Oldi_ion/Oldi_density-struc.xIonDense[nelem][ion][i]/scalingZoneDensity(i)) /* *struc.dr[i] */;   
    15091511 
    15101512                                /* >>chng 02 nov 11, add first error scale estimate from Robin */ 
    1511                                 dynamics.error_scale1 += POW2(struc.xIonDense[nelem][ion][i]/scalingZoneDensity(i));                     
     1513                                //fprintf(ioQQQ,"%g %g %g\n",dynamics.error_scale1, 
     1514                                //                              struc.xIonDense[nelem][ion][i],scalingZoneDensity(i)); 
     1515                                dynamics.error_scale1 += POW2((double)struc.xIonDense[nelem][ion][i]/scalingZoneDensity(i));                     
    15121516                        } 
    15131517                } 
     
    15241528                                Oldi_mol = Old_molecules[ilast][mol]; 
    15251529                        } 
    1526                         dynamics.convergence_error += POW2(Oldi_mol/Oldi_density-struc.molecules[mol][i]/scalingZoneDensity(i)) /* *struc.dr[i] */;   
     1530                        dynamics.convergence_error += POW2((double)Oldi_mol/Oldi_density-struc.molecules[mol][i]/scalingZoneDensity(i)) /* *struc.dr[i] */;   
    15271531 
    15281532                        /* >>chng 02 nov 11, add first error scale estimate from Robin 
    15291533                         * used to normalize the above convergence_error */ 
    1530                         dynamics.error_scale1 += POW2(struc.molecules[mol][i]/scalingZoneDensity(i));                    
     1534                        dynamics.error_scale1 += POW2((double)struc.molecules[mol][i]/scalingZoneDensity(i));                    
    15311535                } 
    15321536        } 
  • branches/newmole/source/ion_solver.cpp

    r1654 r1681  
    386386        /* chng 03 jan 13 rjrw, add in dynamics if required here, 
    387387         * last test - only do advection if we have not overrun the radius scale */ 
    388         if( iteration > dynamics.n_initial_relax+1 && dynamics.lgAdvection  
     388        if( dynamics.lgAdvection && iteration > dynamics.n_initial_relax+1  
    389389                /*&& radius.depth < dynamics.oldFullDepth*/ ) 
    390390        { 
     
    758758 
    759759        renormnew = 1.; 
    760         /* >>chng 06 mar 17, comment out test on old full depth - keep old solution if overrun scale */ 
    761         if(iteration > dynamics.n_initial_relax+1 && dynamics.lgAdvection /*&& radius.depth < dynamics.oldFullDepth */) 
    762         { 
    763                 /* The normalization out of the matrix solution is correct and 
    764                  * should be retained if: dynamics is on and the total 
    765                  * abundance of HI & H+ isn't being controlled by the 
    766                  * molecular network */ 
    767                 renormnew = 1.; 
    768         } 
    769         else 
    770760        { 
    771761                double dennew = 0., 
  • branches/newmole/source/mole_newton_step.cpp

    r1680 r1681  
    77/*lint -e725 expect positive indentation */ 
    88#include "cddefines.h" 
     9#include "dense.h" 
    910#include "dynamics.h" 
    1011#include "mole.h" 
     
    3334 
    3435static void updateMolecules(double *b2, double fion[LIMELM][N_MOLE_ION], realnum numelem[]); 
    35 static void mole_eval_dynamic_balance(long int num_total, double *b, double **c); 
     36STATIC void mole_eval_dynamic_balance(long int num_total, double *b, double **c); 
    3637STATIC int32 solve_system(double *a, double *b, long int n); 
    3738 
     
    702703        return; 
    703704} 
    704  
    705 void mole_eval_dynamic_balance(long int num_total, double *b, double **c) 
     705STATIC void mole_eval_dynamic_balance(long int num_total, double *b, double **c) 
    706706{ 
    707         long int i; 
     707        long int i, 
     708                ion, 
     709                nelem; 
     710        double 
     711                source; 
    708712         
    709713        DEBUG_ENTRY("mole_eval_dynamic_balance()"); 
     714 
    710715        mole_eval_balance(num_total, b, c); 
    711716 
     
    714719        { 
    715720                /* Don't use conservation form in matrix solution -- dynamics rate terms make c[][] non-singular */              
     721 
    716722                for(i=0;i<mole.num_calc;i++)  
    717723                { 
    718724                        if (c) 
    719725                                c[COmole[i]->index][COmole[i]->index] -= dynamics.Rate; 
    720                         b[COmole[i]->index] -= (COmole[i]->hevmol-dynamics.molecules[i])*dynamics.Rate; 
     726 
     727                        b[COmole[i]->index] -= COmole[i]->hevmol*dynamics.Rate; 
     728 
     729                        if (COmole[i]->n_nuclei != 1 || COmole[i]->nElec < 0) 
     730                        { 
     731                                b[COmole[i]->index] += dynamics.molecules[i]*dynamics.Rate; 
     732                        } 
     733                        else if (COmole[i]->nElec == 0) 
     734                        { 
     735                                for ( nelem=ipHYDROGEN; nelem < LIMELM; nelem++) 
     736                                        if (COmole[i]->nElem[nelem] == 1) 
     737                                                break; 
     738                                source = 0.0; 
     739                                for ( ion=dense.IonLow[nelem]; ion<=dense.IonHigh[nelem]; ++ion )  
     740                                { 
     741                                        source += dynamics.Source[nelem][ion]; 
     742                                        if (ion >= N_MOLE_ION || element_list[nelem]->ipMl[ion] == -1) 
     743                                                source -= dense.xIonDense[nelem][ion]*dynamics.Rate; 
     744                                } 
     745                                b[COmole[i]->index] += source; 
     746                        } 
    721747                } 
    722748        }