Changeset 1834 for branches/newmole/source
- Timestamp:
- 03/09/08 07:08:13 (9 months ago)
- Files:
-
- 1 modified
-
branches/newmole/source/iso_level.cpp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/newmole/source/iso_level.cpp
r1830 r1834 50 50 bool lgNegPop=false; 51 51 static double SaveHe23S_photorate=0.; 52 static int32 *ipiv; /* malloc out to [numlevels_local] */52 valarray<int32> ipiv(numlevels_local); 53 53 /* this block of variables will be obtained and freed here */ 54 static double 55 *creation, 56 *error/*[numlevels_local]*/, 57 *work/*[numlevels_local]*/, 58 *Save_creation; 59 static bool lgSpaceMalloc=false; 60 double *PopPerN; 54 valarray<double> 55 creation(numlevels_local), 56 error(numlevels_local), 57 work(numlevels_local), 58 Save_creation(numlevels_local); 59 double source=0., 60 sink=0.; 61 valarray<double> PopPerN(iso.n_HighestResolved_local[ipISO][nelem]+1); 61 62 62 63 multi_arr<double,2,C_TYPE> z, SaveZ; 63 64 /* this flag true means to malloc and free all space each time */65 # define PARALLEL false66 64 67 65 DEBUG_ENTRY( "iso_level()" ); … … 70 68 ASSERT( nelem >= ipISO ); 71 69 ASSERT( nelem < LIMELM ); 72 73 /* malloc some scratch space */74 if( PARALLEL )75 {76 ipiv = (int32 *)MALLOC(sizeof(int32)*(unsigned)(numlevels_local) );77 creation = (double *)MALLOC(sizeof(double)*(unsigned)(numlevels_local) );78 error = (double *)MALLOC(sizeof(double)*(unsigned)(numlevels_local) );79 work = (double *)MALLOC(sizeof(double)*(unsigned)(numlevels_local) );80 Save_creation = (double *)MALLOC(sizeof(double)*(unsigned)(numlevels_local) );81 }82 else if( !lgSpaceMalloc )83 {84 /* space has not been malloced yet, but will only do it one time */85 lgSpaceMalloc = true;86 87 ipiv = (int32 *)MALLOC(sizeof(int32)*(unsigned)(max_num_levels) );88 creation = (double *)MALLOC(sizeof(double)*(unsigned)(max_num_levels) );89 error = (double *)MALLOC(sizeof(double)*(unsigned)(max_num_levels) );90 work = (double *)MALLOC(sizeof(double)*(unsigned)(max_num_levels) );91 Save_creation = (double *)MALLOC(sizeof(double)*(unsigned)(max_num_levels) );92 }93 70 94 71 /* now do the 2D array */ … … 370 347 { 371 348 /* recombination must be multiplied by a ratio of densities to get proper rate. */ 372 creation[0]+= gv.GrainChTrRate[nelem][ion][nelem-ipISO] *373 dense.xIonDense[nelem][ion] / SDIV(dense.xIonDense[nelem][nelem+1-ipISO]);349 source += gv.GrainChTrRate[nelem][ion][nelem-ipISO] * 350 dense.xIonDense[nelem][ion] ; 374 351 /* take ionization out of every level. */ 375 for( level=0; level < numlevels_local; level++ ) 376 { 377 z[level][level] += gv.GrainChTrRate[nelem][nelem-ipISO][ion]; 378 } 352 sink += gv.GrainChTrRate[nelem][nelem-ipISO][ion]; 379 353 } 380 354 } … … 382 356 /* >>chng 02 Sep 06 rjrw -- all elements have these terms */ 383 357 /*>>>chng 02 oct 01, only include if lgAdvection is set */ 384 if( dynamics.lgAdvection )358 if( dynamics.lgAdvection && dynamics.lgISO[ipISO]) 385 359 { 386 360 /* add in advection - these terms normally zero */ 387 361 /* assume for present that all advection is into ground state */ 388 creation[0] += 389 dynamics.Source[nelem][nelem-ipISO]/ 390 SDIV(dense.xIonDense[nelem][nelem+1-ipISO])* 391 dynamics.lgISO[ipISO]; 362 source += dynamics.Source[nelem][nelem-ipISO]; 392 363 /* >>chng 02 Sep 06 rjrw -- advective term not recombination */ 393 364 /* can sink from all components (must do, for conservation) */ 394 for( ipLo=0; ipLo<numlevels_local; ++ipLo ) 395 { 396 z[ipLo][ipLo] += dynamics.Rate*dynamics.lgISO[ipISO]; 397 } 365 sink += dynamics.Rate; 398 366 } 399 367 … … 401 369 if( conv.nTotalIoniz && nelem-ipISO < N_MOLE_ION) 402 370 { 403 creation[0] += mole.source[nelem][nelem-ipISO]/SDIV(dense.xIonDense[nelem][nelem+1-ipISO]); 404 for( ipLo=0; ipLo<numlevels_local; ++ipLo ) 405 { 406 z[ipLo][ipLo] += mole.sink[nelem][nelem-ipISO]; 407 } 371 source += mole.source[nelem][nelem-ipISO]; 372 sink += mole.sink[nelem][nelem-ipISO]; 408 373 409 374 for( long ion=0; ion<N_MOLE_ION; ++ion ) … … 412 377 { 413 378 /* recombination must be multiplied by a ratio of densities to get proper rate. */ 414 creation[0] += mole.xMoleChTrRate[nelem][ion][nelem-ipISO] * 415 dense.xIonDense[nelem][ion] / SDIV(dense.xIonDense[nelem][nelem+1-ipISO]); 416 for( ipLo=0; ipLo<numlevels_local; ++ipLo ) 417 { 418 z[ipLo][ipLo] += mole.xMoleChTrRate[nelem][nelem-ipISO][ion]; 419 } 379 source += mole.xMoleChTrRate[nelem][ion][nelem-ipISO] * 380 dense.xIonDense[nelem][ion] ; 381 sink += mole.xMoleChTrRate[nelem][nelem-ipISO][ion]; 420 382 } 421 383 } 384 } 385 386 creation[0] += source/SDIV(dense.xIonDense[nelem][nelem+1-ipISO]); 387 for( level=0; level < numlevels_local; level++ ) 388 { 389 z[level][level] += sink; 422 390 } 423 391 … … 494 462 495 463 getrf_wrapper(numlevels_local,numlevels_local, 496 z.data(),numlevels_local, ipiv,&nerror);497 498 getrs_wrapper('N',numlevels_local,1,z.data(),numlevels_local, ipiv,499 creation,numlevels_local,&nerror);464 z.data(),numlevels_local,&ipiv[0],&nerror); 465 466 getrs_wrapper('N',numlevels_local,1,z.data(),numlevels_local,&ipiv[0], 467 &creation[0],numlevels_local,&nerror); 500 468 501 469 if( nerror != 0 ) … … 744 712 * of highest to next highest stage of ionization */ 745 713 { 746 PopPerN = (double *)MALLOC(sizeof(double)*(unsigned)(iso.n_HighestResolved_local[ipISO][nelem]+1) );747 714 748 715 for( long n=0; n <= iso.n_HighestResolved_local[ipISO][nelem]; n++ ) … … 809 776 } 810 777 } 811 812 free( PopPerN );813 778 814 779 /************************************************/ … … 896 861 } 897 862 #endif 898 899 /* only release this if option for parallel processing */900 if( PARALLEL )901 {902 free( Save_creation );903 free( work );904 free( error );905 free( creation );906 free( ipiv );907 }908 863 909 864 return;
