Changeset 2044 for branches/newmole

Show
Ignore:
Timestamp:
05/11/08 14:54:02 (8 months ago)
Author:
rjrw
Message:

Move towards using Householder reflections to apply species
conservation constraints.

Presently optional coding switched off by "if (0)" uses projections to
confirm method detects conservation conservation constraints in error
vector.

Using the Householder vectors to project the away the conservation
nullspace from the matrix given to the linear solver should improve
stability.

Files:
1 modified

Legend:

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

    r2041 r2044  
    1818#include "h2.h" 
    1919#include "newton_step.h" 
     20#include "householder.h" 
    2021/* Nick Abel between July and October of 2003 assisted Dr. Ferland in improving the heavy element  
    2122 * molecular network in Cloudy. Before this routine would predict negative abundances if  
     
    441442        if (lgConserve) 
    442443        { 
     444                // Development code towards using Householder reflections to apply 
     445                // conservation constraints 
    443446                if (0) 
    444447                { 
    445                         double sum1; 
     448                        multi_arr<double,2> u(mole.num_calc,LIMELM); 
     449                        valarray<double> betah(LIMELM); 
     450                        for(i=0;i<mole.num_calc;i++) 
     451                        { 
     452                                for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
     453                                { 
     454                                        u[i][nelem] = mole.list[i]->nElem[nelem]; 
     455                                } 
     456                        } 
    446457                        for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
    447458                        { 
    448                                 sum1 = 0.; 
     459                                double beta; 
     460                                valarray<double> x(mole.num_calc-nelem), 
     461                                        y(mole.num_calc-nelem), 
     462                                        v(mole.num_calc-nelem),  
     463                                        p(mole.num_calc-nelem); 
     464                                for(i=0;i<mole.num_calc-nelem;i++) 
     465                                { 
     466                                        x[i] = u[i+nelem][nelem]; 
     467                                } 
     468                                householder(x,v,beta); 
     469                                betah[nelem] = beta; 
     470                                for(i=0;i<mole.num_calc-nelem;i++) 
     471                                { 
     472                                        u[i+nelem][nelem] = v[i]; 
     473                                } 
     474                                for(long nother=nelem+1;nother<LIMELM;nother++) 
     475                                {                                 
     476                                        for (i=0;i<mole.num_calc-nelem;i++) 
     477                                        { 
     478                                                y[i] = u[i+nelem][nother]; 
     479                                        } 
     480                                        p = project(y,v,beta); 
     481                                        for (i=0;i<mole.num_calc-nelem;i++) 
     482                                        { 
     483                                                u[i+nelem][nother] = p[i]; 
     484                                        }                                        
     485                                } 
     486                        } 
     487                        valarray<double> b2(mole.num_calc); 
     488                        for(i=0;i<mole.num_calc;i++) 
     489                        { 
     490                                b2[i] = b[i]; 
     491                        } 
     492                        for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
     493                        { 
     494                                valarray<double> v(mole.num_calc-nelem), 
     495                                        c(mole.num_calc-nelem), 
     496                                        p(mole.num_calc-nelem); 
     497                                for(i=0;i<mole.num_calc-nelem;i++) 
     498                                { 
     499                                        v[i] = u[i+nelem][nelem]; 
     500                                        c[i] = b2[i+nelem]; 
     501                                } 
     502                                p = project(c,v,betah[nelem]); 
     503                                for (i=0;i<mole.num_calc-nelem;i++) 
     504                                { 
     505                                        b2[i+nelem] = p[i]; 
     506                                } 
     507                        } 
     508                        for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
     509                        { 
     510                                fprintf(ioQQQ,"Elem %ld proj %g %g\n",nelem,b2[nelem],dense.gas_phase[nelem]); 
     511                        } 
     512                        for (;nelem<mole.num_calc;nelem++) 
     513                        { 
     514                                fprintf(ioQQQ,"Remain %ld proj %g\n",nelem,b2[nelem]); 
     515                        } 
     516                } 
     517                if (0) 
     518                { 
     519                        for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
     520                        { 
     521                                double sum1 = 0.; 
    449522                                for(i=0;i<mole.num_calc;i++) 
    450523                                {