cloudy trunk
Loading...
Searching...
No Matches
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 */
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 */
24 ASSERT( thermal.lgCoolEvalOK );
25
26 /* this can be done with an assert since these results cannot possibly
27 * depend on user input */
28 ASSERT( thermal.ncltot < NCOLNT );
29
30 /* copy coolant label into stack */
31 ASSERT( strlen( thermal.chClntLab[thermal.ncltot]) < NCOLNT_LAB_LEN );
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 */
50void 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 */
76void 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];
91 thermal.coolheat += thermal.heatnt[i];
92 }
93 thermal.heating[0][12] = thermal.coolheat;
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 {
103 if( thermal.heatnt[i]/thermal.htot > thermal.CoolHeatMax )
104 {
105 thermal.CoolHeatMax = (realnum)(thermal.heatnt[i]/thermal.htot);
106 thermal.wlCoolHeatMax = thermal.collam[i];
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",
194 thermal.heatl, thermal.ctot );
195 }
196 /*end sanity check */
197
198 thermal.lgCoolEvalOK = false;
199 return;
200}
FILE * ioQQQ
Definition cddefines.cpp:7
#define ASSERT(exp)
Definition cddefines.h:578
const int LIMELM
Definition cddefines.h:258
const int NISO
Definition cddefines.h:261
float realnum
Definition cddefines.h:103
#define MAX2
Definition cddefines.h:782
#define DEBUG_ENTRY(funcname)
Definition cddefines.h:684
long nWindLine
Definition cdinit.cpp:19
EmissionProxy::iterator iterator
Definition emission.h:317
TransitionProxy::iterator iterator
Definition transition.h:280
void CoolSum(double *total)
Definition cool_etc.cpp:76
void CoolAdd(const char *chLabel, realnum lambda, double cool)
Definition cool_etc.cpp:13
void CoolZero(void)
Definition cool_etc.cpp:50
long int nSpecies
Definition taulines.cpp:21
TransitionList TauLine2("TauLine2", &AnonStates)
vector< TransitionList > dBaseTrans
Definition taulines.cpp:17
long int nLevel1
Definition taulines.cpp:28
TransitionList TauLines("TauLines", &AnonStates)
species * dBaseSpecies
Definition taulines.cpp:14
t_thermal thermal
Definition thermal.cpp:5
#define NCOLNT_LAB_LEN
Definition thermal.h:91
#define NCOLNT
Definition thermal.h:9
void DumpLine(const TransitionProxy &t)