cloudy  trunk
 All Data Structures Namespaces 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-2022 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 "thermal.h"
9 #include "ionbal.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 
73 
74  /* now zero out these arrays */
75  for( long nelem=0; nelem< LIMELM; ++nelem )
76  {
77  for( long ion=0; ion<nelem+1; ++ion )
78  {
79  ionbal.ExcitationGround[nelem][ion] = 0.;
80  }
81  }
82 
83  return;
84 }
85 
86 /*CoolSum total cooling from all entries into cooling stack */
87 void CoolSum(double *total)
88 {
89  long int i;
90 
91  DEBUG_ENTRY( "CoolSum()" );
92 
93  /* routine to add together all line heating and cooling */
94 
95  *total = 0.;
96  thermal.coolheat = 0.;
97  /* this is sum of agents that should be coolants
98  * coolheat will be coolants that came out as heat */
99  for( i=0; i < thermal.ncltot; i++ )
100  {
101  *total += thermal.cooling[i];
103  }
105 
106  /* make comment if negative cooling ever significant */
107  if( thermal.htot > 0. )
108  {
109  if( thermal.coolheat/thermal.htot > 0.01 )
110  {
111  /* CoolHeatMax was set to zero at start of calc, we want very biggest */
112  for( i=0; i < thermal.ncltot; i++ )
113  {
115  {
118  strcpy( thermal.chCoolHeatMax, thermal.chClntLab[i] );
119  }
120  }
121  }
122  }
123 
124  /* this sum of lines that were heat sources - this
125  * part was not counted as heating in call to cooling add routine
126  * since atom_level2 and atom_level3 cooling routines separate this out
127  * into ->cool() and ->heat() - this does
128  * NOT double count line heating */
129 
130  thermal.heatl = 0.;
131  for( i=0; i < nWindLine; i++ )
132  {
133  if( (*TauLine2[i].Hi()).IonStg() < (*TauLine2[i].Hi()).nelem()+1-NISO )
134  thermal.heatl += TauLine2[i].Coll().heat();
135  }
136 
137  /* line heating added in following, only here */
139  {
140  enum {DEBUG_LOC=false};
141  if( DEBUG_LOC && thermal.heatl/thermal.ctot > 0.1 )
142  {
143  double thresh = 0.1;
144  fprintf(ioQQQ," all heating lines > %.4f of heatl printed next \n",
145  thresh );
146  for( i=0; i < nWindLine; i++ )
147  {
148  if( (*TauLine2[i].Hi()).IonStg() < (*TauLine2[i].Hi()).nelem()+1-NISO )
149  {
150  if( TauLine2[i].Coll().heat()/thermal.heatl > thresh )
151  DumpLine( TauLine2[i] );
152  }
153  }
154 
155  /*Atomic & Molecular Lines CHIANTI & Leiden lines*/
156  for (int ipSpecies=0; ipSpecies < nSpecies; ++ipSpecies)
157  {
158  for( EmissionList::iterator em=dBaseTrans[ipSpecies].Emis().begin();
159  em != dBaseTrans[ipSpecies].Emis().end(); ++em)
160  {
161  if( (*em).Tran().Coll().heat()/thermal.heatl > thresh )
162  DumpLine( (*em).Tran() );
163  }
164  }
165  }
166  }
167 
168  /*begin sanity check */
169  if( *total <= 0. )
170  {
171  fprintf( ioQQQ, " CoolSum finds cooling <= 0%10.2e\n",
172  *total );
173  }
174  if( thermal.heatl/thermal.ctot < -1e-15 )
175  {
176  fprintf( ioQQQ, " CoolSum finds negative heating %10.2e %10.2e\n",
178  }
179  /*end sanity check */
180 
181  thermal.lgCoolEvalOK = false;
182  return;
183 }
void CoolAdd(const char *chLabel, realnum lambda, double cool)
Definition: cool_etc.cpp:13
double htot
Definition: thermal.h:169
void DumpLine(const TransitionProxy &t)
Definition: transition.cpp:138
t_thermal thermal
Definition: thermal.cpp:6
char chCoolHeatMax[NCOLNT_LAB_LEN+1]
Definition: thermal.h:127
const int NISO
Definition: cddefines.h:311
bool lgCoolEvalOK
Definition: thermal.h:159
double cooling[NCOLNT]
Definition: thermal.h:104
FILE * ioQQQ
Definition: cddefines.cpp:7
TransitionList TauLine2("TauLine2",&AnonStates)
long int nSpecies
Definition: taulines.cpp:22
double ** ExcitationGround
Definition: ionbal.h:124
void CoolSum(double *total)
Definition: cool_etc.cpp:87
t_ionbal ionbal
Definition: ionbal.cpp:8
void CoolZero(void)
Definition: cool_etc.cpp:50
char chClntLab[NCOLNT][NCOLNT_LAB_LEN+1]
Definition: thermal.h:108
float realnum
Definition: cddefines.h:124
double dima
Definition: thermal.h:118
long nWindLine
Definition: cdinit.cpp:19
void setHeating(long nelem, long ion, double heating)
Definition: thermal.h:190
#define ASSERT(exp)
Definition: cddefines.h:613
#define NCOLNT
Definition: thermal.h:12
long int ncltot
Definition: thermal.h:106
realnum collam[NCOLNT]
Definition: thermal.h:103
const int LIMELM
Definition: cddefines.h:308
double dHeatdT
Definition: thermal.h:169
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
#define NCOLNT_LAB_LEN
Definition: thermal.h:107
double elementcool[LIMELM+1]
Definition: thermal.h:111
#define MAX2(a, b)
Definition: cddefines.h:824
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
double coolheat
Definition: thermal.h:130
realnum wlCoolHeatMax
Definition: thermal.h:126
vector< TransitionList > dBaseTrans
Definition: taulines.cpp:18
double dCooldT
Definition: thermal.h:139
double heatl
Definition: thermal.h:130
realnum CoolHeatMax
Definition: thermal.h:125
double heatnt[NCOLNT]
Definition: thermal.h:104
double ctot
Definition: thermal.h:130