cloudy  trunk
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cool_etc.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 /*CoolSum total cooling from all entries into cooling stack */
4 /*CoolZero set cooling and heating stack to zero */
5 /*CoolAdd add coolants to the cooling stack, called in evaluation of cooling function */
6 #include "cddefines.h"
7 #include "taulines.h"
8 #include "lines_service.h"
9 #include "thermal.h"
10 #include "cooling.h"
11 
12 /*CoolAdd add coolants to the cooling stack, called in evaluation of cooling function */
13 void CoolAdd(
14  const char *chLabel,
15  realnum lambda,
16  double cool)
17 {
18 
19  DEBUG_ENTRY( "CoolAdd()" );
20 
21  /* this flag indicates (true) that we are between when cooling was set to
22  * zero with call to CoolZero, and when final sum was used. Any call
23  * after final summation (false) will be ignored and so is fatal error */
25 
26  /* this can be done with an assert since these results cannot possibly
27  * depend on user input */
29 
30  /* copy coolant label into stack */
32  strcpy( thermal.chClntLab[thermal.ncltot], chLabel);
33 
34  /* now the wavelength */
35  thermal.collam[thermal.ncltot] = lambda;
36 
37  /* normal line cooling */
38  thermal.cooling[thermal.ncltot] = MAX2(0.,cool);
39 
40  /* possible line heating - not supposed to be done this way!
41  * this is intrinsic positive number, to be added to heating */
42  thermal.heatnt[thermal.ncltot] = MAX2(0.,-cool);
43 
44  /* now increment counter, this is the number of coolants entered */
45  thermal.ncltot += 1;
46  return;
47 }
48 
49 /*CoolZero set cooling and heating stack to zero */
50 void CoolZero(void)
51 {
52 
53  DEBUG_ENTRY( "CoolZero()" );
54 
55  thermal.ncltot = 0;
56  thermal.dCooldT = 0.;
57 
58  /* >>chng 03 nov 29, from explicit loop to memset to save time */
59  memset(thermal.cooling , 0 , NCOLNT*sizeof(thermal.cooling[0] ) );
60  memset(thermal.heatnt , 0 , NCOLNT*sizeof(thermal.heatnt[0] ) );
61 
62  /* this flag indicates that it is ok to add coolants to cooling
63  * stack since between first zero, and final sum - CoolAdd checks
64  * that this is true */
65  thermal.lgCoolEvalOK = true;
66  return;
67 }
68 
69 /*CoolSum total cooling from all entries into cooling stack */
70 void CoolSum(double *total)
71 {
72  long int i;
73 
74  DEBUG_ENTRY( "CoolSum()" );
75 
76  /* routine to add together all line heating and cooling */
77 
78  *total = 0.;
79  thermal.coolheat = 0.;
80  /* this is sum of agents that should be coolants
81  * coolheat will be coolants that came out as heat */
82  for( i=0; i < thermal.ncltot; i++ )
83  {
84  *total += thermal.cooling[i];
86  }
88 
89  /* make comment if negative cooling ever significant */
90  if( thermal.htot > 0. )
91  {
92  if( thermal.coolheat/thermal.htot > 0.01 )
93  {
94  /* CoolHeatMax was set to zero at start of calc, we want very biggest */
95  for( i=0; i < thermal.ncltot; i++ )
96  {
98  {
101  strcpy( thermal.chCoolHeatMax, thermal.chClntLab[i] );
102  }
103  }
104  }
105  }
106 
107  /* this sum of lines that were heat sources - this
108  * part was not counted as heating in call to cooling add routine
109  * since atom_level2 and atom_level3 cooling routines separate this out
110  * into ->cool and ->heat - this does
111  * NOT double count line heating */
112 
113  thermal.heatl = 0.;
114  for( i=0; i < nWindLine; i++ )
115  {
116  if( TauLine2[i].Hi->IonStg < TauLine2[i].Hi->nelem+1-NISO )
118  }
119 
120  for( i=1; i <= nLevel1; i++ )
121  {
123  }
124 
125  /* the Chianti and Leiden lines */
126  for( i=0; i < linesAdded2; i++ )
127  {
129  }
130 
131 # if 0
132  /* >>chng 03 feb 25, this should not be counted here since
133  * total cooling (less heating) was added into cooling stack */
134  for( i=0; i < nCORotate; i++ )
135  {
136  thermal.heatl += C12O16Rotate[i].heat;
137  thermal.heatl += C13O16Rotate[i].heat;
138  }
139 # endif
140 
141  /* line heating added in following, only here */
142  thermal.heating[0][22] = thermal.heatl;
143  {
144  enum {DEBUG_LOC=false};
145  if( DEBUG_LOC && thermal.heatl/thermal.ctot > 0.1 )
146  {
147  double thresh = 0.1;
148  fprintf(ioQQQ," all heating lines > %.4f of heatl printed next \n",
149  thresh );
150  for( i=0; i < nWindLine; i++ )
151  {
152  if( TauLine2[i].Hi->IonStg < TauLine2[i].Hi->nelem+1-NISO )
153  {
154  if( TauLine2[i].Coll.heat/thermal.heatl > thresh )
155  DumpLine( &TauLine2[i] );
156  }
157  }
158 
159  for( i=1; i <= nLevel1; i++ )
160  {
161  if( TauLines[i].Coll.heat/thermal.heatl > thresh )
162  DumpLine( &TauLines[i] );
163  }
164 
165  /*Atomic & Molecular Lines Chianti & Leiden lines*/
166  for( i=0; i <linesAdded2; i++)
167  {
168  if( atmolEmis[i].tran->Coll.heat/thermal.heatl > thresh )
169  DumpLine( atmolEmis[i].tran );
170  }
171  }
172  }
173 
174  /*begin sanity check */
175  if( *total <= 0. )
176  {
177  fprintf( ioQQQ, " CoolSum finds cooling <= 0%10.2e\n",
178  *total );
179  }
180  if( thermal.heatl/thermal.ctot < -1e-15 )
181  {
182  fprintf( ioQQQ, " CoolSum finds negative heating %10.2e %10.2e\n",
184  }
185  /*end sanity check */
186 
187  thermal.lgCoolEvalOK = false;
188  return;
189 }

Generated for cloudy by doxygen 1.8.4