cloudy  trunk
cool_etc.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2013 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  thermal.dHeatdT = 0.;
58 
59  /* >>chng 03 nov 29, from explicit loop to memset to save time */
60  memset(thermal.cooling , 0 , NCOLNT*sizeof(thermal.cooling[0] ) );
61  memset(thermal.heatnt , 0 , NCOLNT*sizeof(thermal.heatnt[0] ) );
62 
63  /* initialize coolants' cooling data */
64  for( int i = 0; i <= LIMELM ; i++ )
65  thermal.elementcool[i] = 0.;
66  thermal.dima = 0.;
67 
68  /* this flag indicates that it is ok to add coolants to cooling
69  * stack since between first zero, and final sum - CoolAdd checks
70  * that this is true */
71  thermal.lgCoolEvalOK = true;
72  return;
73 }
74 
75 /*CoolSum total cooling from all entries into cooling stack */
76 void CoolSum(double *total)
77 {
78  long int i;
79 
80  DEBUG_ENTRY( "CoolSum()" );
81 
82  /* routine to add together all line heating and cooling */
83 
84  *total = 0.;
85  thermal.coolheat = 0.;
86  /* this is sum of agents that should be coolants
87  * coolheat will be coolants that came out as heat */
88  for( i=0; i < thermal.ncltot; i++ )
89  {
90  *total += thermal.cooling[i];
92  }
94 
95  /* make comment if negative cooling ever significant */
96  if( thermal.htot > 0. )
97  {
98  if( thermal.coolheat/thermal.htot > 0.01 )
99  {
100  /* CoolHeatMax was set to zero at start of calc, we want very biggest */
101  for( i=0; i < thermal.ncltot; i++ )
102  {
104  {
107  strcpy( thermal.chCoolHeatMax, thermal.chClntLab[i] );
108  }
109  }
110  }
111  }
112 
113  /* this sum of lines that were heat sources - this
114  * part was not counted as heating in call to cooling add routine
115  * since atom_level2 and atom_level3 cooling routines separate this out
116  * into ->cool() and ->heat() - this does
117  * NOT double count line heating */
118 
119  thermal.heatl = 0.;
120  for( i=0; i < nWindLine; i++ )
121  {
122  if( (*TauLine2[i].Hi()).IonStg() < (*TauLine2[i].Hi()).nelem()+1-NISO )
123  thermal.heatl += TauLine2[i].Coll().heat();
124  }
125 
126  for( i=1; i <= nLevel1; i++ )
127  {
128  thermal.heatl += TauLines[i].Coll().heat();
129  }
130 
131  /* the CHIANTI and Leiden lines */
132  for( long ipSpecies=0; ipSpecies<nSpecies; ipSpecies++ )
133  {
134  if( dBaseSpecies[ipSpecies].lgActive )
135  {
136  for (TransitionList::iterator tr=dBaseTrans[ipSpecies].begin();
137  tr != dBaseTrans[ipSpecies].end(); ++tr)
138  {
139  int ipHi = (*tr).ipHi();
140  if (ipHi >= dBaseSpecies[ipSpecies].numLevels_local || (*tr).ipCont() <= 0)
141  continue;
142  thermal.heatl += (*tr).Coll().heat();
143  }
144  }
145  }
146 
147 
148  /* line heating added in following, only here */
149  thermal.heating[0][22] = thermal.heatl;
150  {
151  enum {DEBUG_LOC=false};
152  if( DEBUG_LOC && thermal.heatl/thermal.ctot > 0.1 )
153  {
154  double thresh = 0.1;
155  fprintf(ioQQQ," all heating lines > %.4f of heatl printed next \n",
156  thresh );
157  for( i=0; i < nWindLine; i++ )
158  {
159  if( (*TauLine2[i].Hi()).IonStg() < (*TauLine2[i].Hi()).nelem()+1-NISO )
160  {
161  if( TauLine2[i].Coll().heat()/thermal.heatl > thresh )
162  DumpLine( TauLine2[i] );
163  }
164  }
165 
166  for( i=1; i <= nLevel1; i++ )
167  {
168  if( TauLines[i].Coll().heat()/thermal.heatl > thresh )
169  DumpLine( TauLines[i] );
170  }
171 
172  /*Atomic & Molecular Lines CHIANTI & Leiden lines*/
173  for (int ipSpecies=0; ipSpecies < nSpecies; ++ipSpecies)
174  {
175  for( EmissionList::iterator em=dBaseTrans[ipSpecies].Emis().begin();
176  em != dBaseTrans[ipSpecies].Emis().end(); ++em)
177  {
178  if( (*em).Tran().Coll().heat()/thermal.heatl > thresh )
179  DumpLine( (*em).Tran() );
180  }
181  }
182  }
183  }
184 
185  /*begin sanity check */
186  if( *total <= 0. )
187  {
188  fprintf( ioQQQ, " CoolSum finds cooling <= 0%10.2e\n",
189  *total );
190  }
191  if( thermal.heatl/thermal.ctot < -1e-15 )
192  {
193  fprintf( ioQQQ, " CoolSum finds negative heating %10.2e %10.2e\n",
195  }
196  /*end sanity check */
197 
198  thermal.lgCoolEvalOK = false;
199  return;
200 }
thermal.h
t_thermal::CoolHeatMax
realnum CoolHeatMax
Definition: thermal.h:105
DumpLine
void DumpLine(const TransitionProxy &t)
Definition: transition.cpp:100
t_thermal::chClntLab
char chClntLab[NCOLNT][NCOLNT_LAB_LEN+1]
Definition: thermal.h:92
ioQQQ
FILE * ioQQQ
Definition: cddefines.cpp:7
nLevel1
long int nLevel1
Definition: taulines.cpp:28
dBaseTrans
vector< TransitionList > dBaseTrans
Definition: taulines.cpp:17
t_thermal::wlCoolHeatMax
realnum wlCoolHeatMax
Definition: thermal.h:106
realnum
float realnum
Definition: cddefines.h:103
nWindLine
long nWindLine
Definition: cdinit.cpp:19
t_thermal::coolheat
double coolheat
Definition: thermal.h:116
CoolZero
void CoolZero(void)
Definition: cool_etc.cpp:50
ProxyIterator
Definition: proxy_iterator.h:58
lines_service.h
CoolAdd
void CoolAdd(const char *chLabel, realnum lambda, double cool)
Definition: cool_etc.cpp:13
t_thermal::cooling
double cooling[NCOLNT]
Definition: thermal.h:88
t_thermal::dima
double dima
Definition: thermal.h:98
ASSERT
#define ASSERT(exp)
Definition: cddefines.h:578
t_thermal::ctot
double ctot
Definition: thermal.h:112
t_thermal::heatnt
double heatnt[NCOLNT]
Definition: thermal.h:89
t_thermal::lgCoolEvalOK
bool lgCoolEvalOK
Definition: thermal.h:139
t_thermal::dHeatdT
double dHeatdT
Definition: thermal.h:155
CoolSum
void CoolSum(double *total)
Definition: cool_etc.cpp:76
t_thermal::ncltot
long int ncltot
Definition: thermal.h:90
t_thermal::heatl
double heatl
Definition: thermal.h:114
cooling.h
t_thermal::collam
realnum collam[NCOLNT]
Definition: thermal.h:87
cddefines.h
thermal
t_thermal thermal
Definition: thermal.cpp:5
TauLine2
TransitionList TauLine2("TauLine2", &AnonStates)
t_thermal::heating
double heating[LIMELM][LIMELM]
Definition: thermal.h:158
NCOLNT
#define NCOLNT
Definition: thermal.h:9
MAX2
#define MAX2
Definition: cddefines.h:782
LIMELM
const int LIMELM
Definition: cddefines.h:258
TauLines
TransitionList TauLines("TauLines", &AnonStates)
t_thermal::htot
double htot
Definition: thermal.h:149
t_thermal::chCoolHeatMax
char chCoolHeatMax[NCOLNT_LAB_LEN+1]
Definition: thermal.h:107
t_thermal::elementcool
double elementcool[LIMELM+1]
Definition: thermal.h:95
dBaseSpecies
species * dBaseSpecies
Definition: taulines.cpp:14
t_thermal::dCooldT
double dCooldT
Definition: thermal.h:119
taulines.h
NCOLNT_LAB_LEN
#define NCOLNT_LAB_LEN
Definition: thermal.h:91
nSpecies
long int nSpecies
Definition: taulines.cpp:21
NISO
const int NISO
Definition: cddefines.h:261
DEBUG_ENTRY
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:684