cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
eden_sum.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 #include "cddefines.h"
4 #include "conv.h"
5 #include "trace.h"
6 #include "grainvar.h"
7 #include "rfield.h"
8 #include "mole.h"
9 #include "dense.h"
10 #include "iso.h"
11 #include "deuterium.h"
12 
13 // eden_sum: sum all contributions to the electron density, sets variable dense.EdenTrue
14 // called by ConvBase - ConvEdenIoniz actually updates the electron density dense.eden
15 // here we allow dense.EdenTrue to become negative, ConvEdenIoniz will deal with this
16 // and will also assure that dense.eden is always positive. this routine always returns 0
17 int eden_sum(void)
18 {
19  DEBUG_ENTRY( "eden_sum()" );
20 
21  if( dense.EdenSet > 0.f )
22  {
23  /* electron density set with set eden command */
26 
27  if( trace.lgTrace || trace.lgESOURCE )
28  fprintf( ioQQQ, " eden_sum zn: %.2f eden set to: %.4e\n", fnzone, dense.EdenSet );
29  }
30  else if( dense.EdenFraction > 0.f )
31  {
32  /* electron fraction set with set eden fraction command */
35 
36  if( trace.lgTrace || trace.lgESOURCE )
37  {
38  fprintf( ioQQQ, " eden_sum zn: %.2f eden ratio set to: %.4e, eden is: %.4e\n",
40  }
41  }
42  else
43  {
44  /* EdenExtra is normally zero, set with EDEN command, to add extra e- */
46 
47  /* sum over all ions */
48  double eden_ions[LIMELM];
49  double sum_all_ions = 0.;
50  double sum_metals = 0.;
51  for( long nelem=ipHYDROGEN; nelem < LIMELM; nelem++ )
52  {
53  eden_ions[nelem] = 0.;
54  for( long ion=1; ion <= nelem+1; ion++ )
55  eden_ions[nelem] += ion*dense.xIonDense[nelem][ion];
56 
57  sum_all_ions += eden_ions[nelem];
58  if( nelem >= ipLITHIUM )
59  sum_metals += eden_ions[nelem];
60  }
61  sum_all_ions += deut.xIonDense[1];
62  dense.EdenTrue += sum_all_ions;
63 
64  /* electrons contributed by heavy molecules */
65  // include electrons lost to negative atomic ions, e.g. H-, but
66  // not +ve which are treated by the ionization ladders
67  mole.elec = 0.;
68  for( long i=0; i < mole_global.num_calc; i++ )
69  {
70  if( mole_global.list[i]->isIsotopicTotalSpecies() && (!mole_global.list[i]->isMonatomic() || mole_global.list[i]->charge < 0) )
71  mole.elec += mole.species[i].den*mole_global.list[i]->charge;
72  }
73 
75 
76  /* gv.lgGrainElectrons - should grain electron source/sink be included in overall electron sum?
77  * default is true, set false with no grain electrons command */
79 
80  /* fraction of electrons from ions heavier than helium */
81  dense.eden_from_metals = safe_div( sum_metals, dense.EdenTrue, 1. );
82 
83  if( trace.lgTrace || trace.lgESOURCE )
84  {
85  fprintf( ioQQQ,
86  " eden_sum zn: %.2f current: %.4e new true: %.4e ions: %.4e mole: %.4e"
87  " grain: %.4e extra: %.4e LaOTS: %.4e\n",
88  fnzone ,
89  dense.eden ,
90  dense.EdenTrue ,
91  sum_all_ions ,
92  mole.elec ,
96 
97  if( trace.lgNeBug )
98  {
99  for( long nelem=ipHYDROGEN; nelem < LIMELM; nelem++ )
100  {
101  if( nelem == 0 )
102  fprintf( ioQQQ, " eden_sum H -Ne:" );
103  else if( nelem == 10 )
104  fprintf( ioQQQ, " eden_sum Na-Ca:" );
105  else if( nelem == 20 )
106  fprintf( ioQQQ, " eden_sum Sc-Zn:" );
107  fprintf( ioQQQ, " %.4e", eden_ions[nelem] );
108  if( nelem%10 == 9 )
109  fprintf( ioQQQ, "\n" );
110  }
111  }
112  }
113  }
114 
115  /* case where electron density is set with set eden command, make sure we use it */
117 
118  return 0;
119 }
realnum EdenFraction
Definition: dense.h:220
t_mole_global mole_global
Definition: mole.cpp:7
bool lgGrainElectrons
Definition: grainvar.h:498
int num_calc
Definition: mole.h:362
int eden_sum(void)
Definition: eden_sum.cpp:17
FILE * ioQQQ
Definition: cddefines.cpp:7
t_dense dense
Definition: global.cpp:15
bool lgNeBug
Definition: trace.h:112
t_iso_sp iso_sp[NISO][LIMELM]
Definition: iso.cpp:11
double xIonDense[LIMELM][LIMELM+1]
Definition: dense.h:135
realnum * otslin
Definition: rfield.h:183
t_trace trace
Definition: trace.cpp:5
bool fp_equal(sys_float x, sys_float y, int n=3)
Definition: cddefines.h:854
double TotalEden
Definition: grainvar.h:529
bool lgESOURCE
Definition: trace.h:24
const int ipH1s
Definition: iso.h:29
bool lgTrace
Definition: trace.h:12
t_mole_local mole
Definition: mole.cpp:8
double EdenTrue
Definition: dense.h:232
t_rfield rfield
Definition: rfield.cpp:9
long & ipCont() const
Definition: transition.h:489
float realnum
Definition: cddefines.h:124
valarray< class molezone > species
Definition: mole.h:468
sys_float safe_div(sys_float x, sys_float y, sys_float res_0by0)
Definition: cddefines.h:1011
double xIonDense[2]
Definition: deuterium.h:23
TransitionProxy trans(const long ipHi, const long ipLo)
Definition: iso.h:473
realnum gas_phase[LIMELM]
Definition: dense.h:76
const int ipH2p
Definition: iso.h:31
#define ASSERT(exp)
Definition: cddefines.h:613
const int ipH_LIKE
Definition: iso.h:64
const int LIMELM
Definition: cddefines.h:308
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
t_deuterium deut
Definition: deuterium.cpp:7
double eden
Definition: dense.h:201
double elec
Definition: mole.h:460
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
MoleculeList list
Definition: mole.h:365
realnum EdenSet
Definition: dense.h:214
GrainVar gv
Definition: grainvar.cpp:5
double eden_from_metals
Definition: dense.h:235
double fnzone
Definition: cddefines.cpp:15
const int ipHYDROGEN
Definition: cddefines.h:349
const int ipLITHIUM
Definition: cddefines.h:351
realnum EdenExtra
Definition: dense.h:217