Cloudy
Spectral Synthesis Code for Astrophysics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rfield.h
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2023 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #ifndef RFIELD_H_
5 #define RFIELD_H_
6 
7 /* rfield.h */
8 #include "energy.h"
9 #include "module.h"
10 #include "vectorize.h"
11 #include "mesh.h"
12 #include "container_classes.h"
13 
15 const double WL_V_FILT = 5500.;
16 
18 const double WL_B_FILT = 4400.;
19 
22 const int LIMSPC = 100;
23 
25 void rfield_opac_zero( long lo , long ihi );
26 
28 extern bool lgRfieldAllocated;
29 
30 namespace Illuminate {
31  typedef enum { FORWARD , REVERSE , ISOTROPIC } IlluminationType ;
32 }
33 
34 namespace Accumulate {
35  typedef enum { INSTANTANEOUS = 0, CUMULATIVE = 1 } AccumulationType;
36 }
37 
38 
39 class Spectrum
40 {
41 private:
52  vector<realnum> flux[2];
53 
55  double norm;
56 
58  double time_avg_flux;
59 
61  long int nflux;
62 
63 
64 public:
65  // constructor
67  {
68  norm = 1.;
69  time_avg_flux = 0.;
70  }
71 
72  void resize( long int nbins );
73 
74  void accumulate_flux( const double this_cumulfac, double timestep, double total_time )
75  {
76  DEBUG_ENTRY( "accumulate_flux()" );
77 
78  vector<realnum> &flux_inst = flux[0];
79  vector<realnum> &flux_cumul = flux[1];
80 
81  double mean = flux_cumul[ 0 ] * norm + flux_inst[ 0 ] * this_cumulfac;
82 
83  for( long ip = 1; ip < nflux; ip++ )
84  {
85  /* >>refer running mean Welford, 1962, Technometrics, 4-419 */
86  double tmp_fl = flux_cumul[ ip ] * norm +
87  flux_inst[ ip ] * this_cumulfac;
88  mean += (tmp_fl - mean) / double( ip+1 );
89  }
90 
91  if( fp_equal( mean, 0. ) )
92  return;
93 
94  double mean_inv = 1. / mean;
95 
96  for( long ip = 0; ip < nflux; ip++ )
97  {
98  double tmp_flux = flux_cumul[ ip ] * norm +
99  flux_inst[ ip ] * this_cumulfac;
100  flux_cumul[ ip ] = realnum( tmp_flux * mean_inv );
101  }
102 
103  norm = mean;
104 
105  if( fp_equal( time_avg_flux, 0.0 ) )
106  {
108  }
109  else
110  {
111  time_avg_flux += ( mean - time_avg_flux ) *
112  timestep / ( timestep + total_time );
113  }
114 
115  return;
116  }
117 
118  double get_flux( long int accType, long int ip ) const
119  {
120  DEBUG_ENTRY( "get_flux" );
121 
124 
125  ASSERT( ip >= 0 && ip < nflux );
126 
128  {
129  return double( flux[0][ip] );
130  }
131  else
132  {
133  return double( flux[1][ip] ) * norm;
134  }
135  }
136 
137  double get_time_avg_flux() const
138  {
139  return time_avg_flux;
140  }
141 
142  vector<realnum>& operator[]( int accType )
143  {
146  return flux[ accType ];
147  }
148 };
149 
150 struct t_rfield : public module, public t_mesh {
151  const char *chName() const
152  {
153  return "rfield";
154  }
155 
156  void zero();
157  void comment(t_warnings&) {}
163  long int nflux;
164 
167 
170  long int nPositive;
171 
173  double FluxFaint;
174 
176  vector<long> line_count;
177 
179  vector<realnum> OccNumbContEmitOut;
180 
186 
188  vector<realnum> flux_isotropic;
189 
191  vector<realnum> flux_beam_time, flux_beam_const;
192 
194  vector<realnum> flux_accum;
195 
197  vector<realnum> ExtinguishFactor;
205 
210 
211  /* this is set true if H-ionizing radiation is blocked with extinguish
212  * command */
214 
217 
221 
223  bool lgCMB_set;
224 
228 
230  vector<realnum> convoc;
231 
234  vector<realnum> OccNumbIncidCont;
235 
237  vector<realnum> OccNumbDiffCont;
238 
242 
246 
249 
253 
256  multi_arr<realnum,2> ConEmitLocal/* [depth][energy]*/;
257 
260 
263 
269 
271  vector<realnum> ConInterOut;
272 
275 
278  vector<double> SummedCon;
279  vector<realnum> SummedDif;
280  vector<realnum> SummedOcc;
281  vector<realnum> SummedDifSave;
282 
285  vector<realnum> ConOTS_local_photons;
287  vector<realnum> ConOTS_local_OTS_rate;
288 
291  vector<realnum> DiffuseEscape;
292 
294  vector<realnum> TotDiff2Pht;
295 
299  vector<realnum> otslin;
301  vector<realnum> otscon;
303 
306  vector<realnum> outlin_noplot;
307 
309  vector<realnum> DiffuseLineEmission;
310 
313 
317 
320 
324 
326  vector<string> chLineLabel/*[rfield.nflux_with_check][5]*/;
327 
329  vector<string> chContLabel/*[rfield.nflux_with_check][5]*/;
330 
333  char chDffTrns[4];
334 
338  bool lgOutOnly;
339 
344 
346  long int ipMaxBolt;
347 
350 
352  vector<double> comup, comdn;
353 
355  long int ipB_filter , ipV_filter;
356 
360 
364 
367 
369  long int ip1000A;
370 
374 
378 
381 
384  vector<realnum> csigh, csigc;
385 
387  vector<realnum> eeBremsDif;
388 
389  double comtot,
390  cmheat,
391  cmcool,
392  cinrat;
394 
396  bool lgComUndr;
397 
398  double totpow[LIMSPC],
399  slope[LIMSPC],
400  cutoff[LIMSPC][3],
401  spfac[LIMSPC];
402 
405 
406  /* beamed or isotropic continuum? if isotropic then does not vary
407  * with time */
409 
413 
415 
420  long int nShape,
421  ipSpec;
422 
428  vector<Energy> tNu[LIMSPC];
429  vector<realnum> tslop[LIMSPC];
431  vector<realnum> tFluxLog[LIMSPC];
436 
437  long ncont[LIMSPC];
438 
441  double RSFCheck[LIMSPC];
442 
445  double range[LIMSPC][2];
446 
449  char chSpNorm[LIMSPC][5],
450  chRSpec[LIMSPC][5],
451  chSpType[LIMSPC][6],
452  chCumuType[5];
453 
456  qhe,
457  qheii,
458  qbal,
459  qrad,
460  qtot;
461 
464 
467 
469  bool lgUSphON;
472 
475  bool lgHabing;
476 
479  long int fine_opac_nelem;
480 
483 
486 
487 private:
489  vector<realnum> trans_coef_total;
490 
491 public:
493 
496  vector<long> ipnt_coarse_2_fine;
497 
501  long nfine;
503  double fine_resol;
505  vector<realnum> fine_opac_zone;
507  vector<realnum> fine_opt_depth;
509  vector<realnum> fine_anu;
510 
513  unordered_map<long, vector<int> > fine_lstack;
514 
520 
525 
528  bool lgLyaOTS;
529 
532  bool lgHeIIOTS;
533 
536 
539 
542 
546  bool lgPlasNu;
550  plsfrqmax;
551  // the zone where the plasma frequency is evaluated
552  long int nZonePlsFrqEval;
554  long int ipPlasma,
556  ipPlasmax;
557 
560  bool lgMMok,
561  lgHPhtOK,
562  lgXRayOK,
563  lgGamrOK;
564 
567  long int ipEnerGammaRay;
568 
570  bool lgHionRad;
571 
574  occmnu,
575  tbrmax,
576  tbrmnu,
577  tbr4nu,
578  occ1nu;
579 
581  bool lgOcc1Hi;
582 
587 
588  // constructor
590  {
591  nZonePlsFrqEval = -1;
592 
593  // the constant that multiplies the column density to get optical depth at 1 Ryd
595  // the power on the energy for the extinction
597  }
598 
599  const realnum *getCoarseTransCoef();
600 
601  void setCoarseTransCoefPtr(size_t size)
602  {
603  trans_coef_total.resize(size);
604  }
606  {
607  for (long i=0; i<nflux_with_check; ++i)
608  trans_coef_total[i] = 1.0;
609  trans_coef_total_stale = true;
610  }
611  void setTrimming();
612 };
613 extern t_rfield rfield;
614 
626 double flux_correct_isotropic( const bool lgSaveIsotrp, const int nEmType, const int j );
627 
636 double flux_correct_isotropic( const int nEmType, const int j );
637 
638 #endif /* RFIELD_H_ */
Definition: warnings.h:11
Definition: rfield.h:35
double norm
Definition: rfield.h:55
vector_avx< double > ContBoltzHelp1
Definition: rfield.h:244
bool lgBeamed[LIMSPC]
Definition: rfield.h:408
bool lgGamrOK
Definition: rfield.h:560
Spectrum ConEmitOut
Definition: rfield.h:268
bool lgSaveOpacityFine
Definition: rfield.h:524
vector< realnum > ConOTS_local_OTS_rate
Definition: rfield.h:287
long int ipG0_spec_hi
Definition: rfield.h:366
long int fine_opac_nresolv
Definition: rfield.h:482
Definition: rfield.h:31
const char * chName() const
Definition: rfield.h:151
double comtot
Definition: rfield.h:389
double opac_mag_B_extended
Definition: rfield.h:380
realnum qtot
Definition: rfield.h:455
realnum EnerGammaRay
Definition: rfield.h:566
long int ipG0_DB96_hi
Definition: rfield.h:363
bool lgKillOutLine
Definition: rfield.h:535
long int ipEnergyBremsThin
Definition: rfield.h:342
void setTrimming()
Definition: rfield.cpp:103
realnum qbal
Definition: rfield.h:455
double time_avg_flux
Definition: rfield.h:58
const double WL_V_FILT
Definition: rfield.h:15
realnum occ1nu
Definition: rfield.h:573
vector< realnum > outlin_noplot
Definition: rfield.h:306
bool lgSphericalDilution[LIMSPC]
Definition: rfield.h:435
void accumulate_flux(const double this_cumulfac, double timestep, double total_time)
Definition: rfield.h:74
vector< realnum > fine_anu
Definition: rfield.h:509
vector< string > chContLabel
Definition: rfield.h:329
realnum EnergyBremsThin
Definition: rfield.h:343
double opac_mag_V_point
Definition: rfield.h:380
double totpow[LIMSPC]
Definition: rfield.h:398
vector< realnum > eeBremsDif
Definition: rfield.h:387
char chDffTrns[4]
Definition: rfield.h:333
vector< realnum > otslin
Definition: rfield.h:299
char chRSpec[LIMSPC][5]
Definition: rfield.h:449
Spectrum()
Definition: rfield.h:66
vector< realnum > DiffuseEscape
Definition: rfield.h:291
bool lgOcc1Hi
Definition: rfield.h:581
realnum fine_opac_velocity_width
Definition: rfield.h:485
long int ipG0_spec_lo
Definition: rfield.h:366
long int ipMaxBolt
Definition: rfield.h:346
Definition: rfield.h:31
vector< realnum > ConInterOut
Definition: rfield.h:271
bool lgOpacityFine
Definition: rfield.h:522
realnum qhe
Definition: rfield.h:455
vector< realnum > csigh
Definition: rfield.h:384
long int ipG0_TH85_hi
Definition: rfield.h:359
vector< realnum > OccNumbContEmitOut
Definition: rfield.h:179
t_rfield rfield
Definition: rfield.cpp:9
double TableRadius[LIMSPC]
Definition: rfield.h:433
long int nZonePlsFrqEval
Definition: rfield.h:552
void rfield_opac_zero(long lo, long ihi)
Definition: cont_createmesh.cpp:295
bool lgKillOutCont
Definition: rfield.h:538
vector< realnum > OccNumbDiffCont
Definition: rfield.h:237
double RSFCheck[LIMSPC]
Definition: rfield.h:441
bool lgIonizReevaluate
Definition: rfield.h:227
vector< Energy > tNu[LIMSPC]
Definition: rfield.h:428
vector< realnum > flux_beam_const
Definition: rfield.h:191
vector< realnum > tFluxLog[LIMSPC]
Definition: rfield.h:431
bool lgKillOTSLine
Definition: rfield.h:541
void comment(t_warnings &)
Definition: rfield.h:157
long int ipEnerGammaRay
Definition: rfield.h:567
vector< realnum > fine_opt_depth
Definition: rfield.h:507
long ncont[LIMSPC]
Definition: rfield.h:437
long int ipG0_TH85_lo
Definition: rfield.h:359
vector< realnum > flux_beam_const_save
Definition: rfield.h:316
double spfac[LIMSPC]
Definition: rfield.h:398
vector< realnum > tslop[LIMSPC]
Definition: rfield.h:429
vector_avx< double > ContBoltz
Definition: rfield.h:241
realnum time_continuum_scale
Definition: rfield.h:319
double get_time_avg_flux() const
Definition: rfield.h:137
bool lgHeIIOTS
Definition: rfield.h:532
IlluminationType
Definition: rfield.h:31
realnum ExtinguishEnergyPowerLow
Definition: rfield.h:198
double cutoff[LIMSPC][3]
Definition: rfield.h:398
vector< realnum > convoc
Definition: rfield.h:230
vector< realnum > flux_beam_time
Definition: rfield.h:191
bool lgTimeVary[LIMSPC]
Definition: rfield.h:404
vector_avx< double > ContBoltzAvg
Definition: rfield.h:252
void resetCoarseTransCoef()
Definition: rfield.h:605
double range[LIMSPC][2]
Definition: rfield.h:445
bool lgHabing
Definition: rfield.h:475
Definition: rfield.h:35
const int LIMSPC
Definition: rfield.h:22
long int nflux_with_check
Definition: rfield.h:166
realnum ExtinguishConvertColDen2OptDepth
Definition: rfield.h:198
realnum EnergyIncidCont
Definition: rfield.h:585
const realnum * getCoarseTransCoef()
Definition: rfield.cpp:67
long int fine_opac_nelem
Definition: rfield.h:479
bool fp_equal(sys_float x, sys_float y, int n=3)
Definition: cddefines.h:864
double get_flux(long int accType, long int ip) const
Definition: rfield.h:118
typename std::vector< T, allocator_avx< T >> vector_avx
Definition: vectorize.h:331
multi_arr< realnum, 2 > ConEmitLocal
Definition: rfield.h:256
realnum ExtinguishLeakage
Definition: rfield.h:198
Spectrum reflin
Definition: rfield.h:312
multi_arr< realnum, 2 > otssav
Definition: rfield.h:302
long int ipG0_DB96_lo
Definition: rfield.h:363
vector< realnum > flux_isotropic_save
Definition: rfield.h:316
double fine_resol
Definition: rfield.h:503
bool lgOutOnly
Definition: rfield.h:338
double slope[LIMSPC]
Definition: rfield.h:398
vector< realnum > fine_opac_zone
Definition: rfield.h:505
Spectrum ConRefIncid
Definition: rfield.h:274
realnum tbrmax
Definition: rfield.h:573
vector< realnum > SummedOcc
Definition: rfield.h:280
bool lgHPhtOK
Definition: rfield.h:560
vector< realnum > flux_isotropic
Definition: rfield.h:188
vector< realnum > otscon
Definition: rfield.h:301
vector< double > comdn
Definition: rfield.h:352
void resize(long int nbins)
Definition: rfield.cpp:56
long int ipPlasma
Definition: rfield.h:554
bool lgCMB_set
Definition: rfield.h:223
Definition: mesh.h:10
Spectrum outlin
Definition: rfield.h:305
bool trans_coef_total_stale
Definition: rfield.h:492
bool lgLyaOTS
Definition: rfield.h:528
realnum qhtot
Definition: rfield.h:455
double cmcool
Definition: rfield.h:389
t_mean mean
Definition: mean.cpp:17
Spectrum flux
Definition: rfield.h:185
float realnum
Definition: cddefines.h:127
realnum uh
Definition: rfield.h:463
Illuminate::IlluminationType Illumination[LIMSPC]
Definition: rfield.h:414
double opac_mag_B_point
Definition: rfield.h:380
realnum uheii
Definition: rfield.h:466
long int ipFineConVelShift
Definition: rfield.h:519
vector< realnum > flux_time_beam_save
Definition: rfield.h:316
vector< realnum > ConOTS_local_photons
Definition: rfield.h:285
double FluxFaint
Definition: rfield.h:173
double cmheat
Definition: rfield.h:389
bool lgMustBlockHIon
Definition: rfield.h:209
realnum rstrom
Definition: rfield.h:471
vector< realnum > SummedDifSave
Definition: rfield.h:281
vector_avx< double > ContBoltzHelp2
Definition: rfield.h:245
bool lgXRayOK
Definition: rfield.h:560
vector< realnum > SummedDif
Definition: rfield.h:279
vector< string > chLineLabel
Definition: rfield.h:326
char chSpNorm[LIMSPC][5]
Definition: rfield.h:449
vector< realnum > csigc
Definition: rfield.h:384
vector< realnum > & operator[](int accType)
Definition: rfield.h:142
long int nflux
Definition: rfield.h:61
bool lgDoLineTrans
Definition: rfield.h:216
double extin_mag_V_point
Definition: rfield.h:373
realnum fine_ener_lo
Definition: rfield.h:499
long int ipV_filter
Definition: rfield.h:355
Spectrum ConEmitReflec
Definition: rfield.h:262
Spectrum flux_total_incident
Definition: rfield.h:315
vector< realnum > flux[2]
Definition: rfield.h:52
void zero()
Definition: rfield.cpp:11
#define ASSERT(exp)
Definition: cddefines.h:637
vector< long > line_count
Definition: rfield.h:176
realnum fine_ener_hi
Definition: rfield.h:499
bool lgOpacityReevaluate
Definition: rfield.h:220
double extin_mag_B_point
Definition: rfield.h:373
double extin_mag_V_extended
Definition: rfield.h:377
double flux_correct_isotropic(const bool lgSaveIsotrp, const int nEmType, const int j)
Definition: rfield.cpp:123
const double WL_B_FILT
Definition: rfield.h:18
vector< realnum > trans_coef_total
Definition: rfield.h:489
long nfine
Definition: rfield.h:501
double opac_mag_V_extended
Definition: rfield.h:380
vector< double > SummedCon
Definition: rfield.h:278
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:730
Definition: rfield.h:39
realnum ExtinguishColumnDensity
Definition: rfield.h:198
realnum qheii
Definition: rfield.h:455
bool lgRfieldAllocated
Definition: cdinit.cpp:41
bool lgHionRad
Definition: rfield.h:570
vector< realnum > ExtinguishFactor
Definition: rfield.h:197
vector< realnum > OccNumbIncidCont
Definition: rfield.h:234
bool lgMMok
Definition: rfield.h:560
long int ip1000A
Definition: rfield.h:369
realnum EnergyDiffCont
Definition: rfield.h:585
double extin_mag_B_extended
Definition: rfield.h:377
bool lgInducProcess
Definition: rfield.h:349
vector< long > ipnt_coarse_2_fine
Definition: rfield.h:496
realnum OpticalDepthScaleFactor[LIMSPC]
Definition: rfield.h:412
long int ipB_filter
Definition: rfield.h:355
long int ipPlasmax
Definition: rfield.h:554
long int nShape
Definition: rfield.h:420
Definition: rfield.h:150
long int ipSpec
Definition: rfield.h:420
unordered_map< long, vector< int > > fine_lstack
Definition: rfield.h:513
t_rfield()
Definition: rfield.h:589
vector< realnum > TotDiff2Pht
Definition: rfield.h:294
void setCoarseTransCoefPtr(size_t size)
Definition: rfield.h:601
AccumulationType
Definition: rfield.h:35
realnum occmnu
Definition: rfield.h:573
realnum DiffPumpOn
Definition: rfield.h:323
bool lgUSphON
Definition: rfield.h:469
char chCumuType[5]
Definition: rfield.h:449
realnum plsfrqmax
Definition: rfield.h:548
realnum qrad
Definition: rfield.h:455
bool lgComUndr
Definition: rfield.h:396
realnum plsfrq
Definition: rfield.h:548
vector< realnum > DiffuseLineEmission
Definition: rfield.h:309
long int nflux
Definition: rfield.h:163
vector< double > comup
Definition: rfield.h:352
Definition: module.h:26
bool lgPlasNu
Definition: rfield.h:546
bool lgBlockHIon
Definition: rfield.h:213
long int nPositive
Definition: rfield.h:170
multi_arr< realnum, 2 > ConSourceFcnLocal
Definition: rfield.h:259
realnum tbr4nu
Definition: rfield.h:573
char chSpType[LIMSPC][6]
Definition: rfield.h:449
Definition: rfield.h:31
vector_avx< double > vexp_arg
Definition: rfield.h:248
bool lgComptonOn
Definition: rfield.h:393
realnum ExtinguishLowEnergyLimit
Definition: rfield.h:198
vector< realnum > flux_accum
Definition: rfield.h:194
realnum occmax
Definition: rfield.h:573
double cinrat
Definition: rfield.h:389
realnum tbrmnu
Definition: rfield.h:573