Cloudy
Spectral Synthesis Code for Astrophysics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mesh.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 MESH_H_
5 #define MESH_H_
6 
7 #include "thirdparty.h"
8 #include "energy.h"
9 
10 class t_mesh {
11 
16  double p_emm;
17 
19  double p_egamry;
20 
24 
26  string p_mesh_md5sum;
27 
31  vector<double> p_RangeUpperLimit;
32  vector<double> p_RangeResolution;
33 
35  vector<Energy> p_edges;
36 
38  vector<double> p_anu;
39 
41  vector<double> p_anu_edge;
42 
44  vector<double> p_widflx;
45 
47  vector<double> p_anulog10;
48  vector<double> p_anuln;
49  vector<double> p_anusqrt;
50  vector<double> p_anu2;
51  vector<double> p_anu3;
52 
53  /* this routine reads continuum_mesh.ini */
54  void p_ReadResolution();
55 
56  /* this routine defines the frequency mesh */
57  void p_SetupMesh(bool lgUnitCell);
58 
59  // Set up special edges that need to be merged into the frequency mesh
60  void p_SetupEdges();
61 public:
62  /* set up the frequency mesh */
63  void InitMesh(bool lgUnitCell)
64  {
65  if( lgMeshSetUp() )
66  return;
67 
68  // these are the low and high energy bounds of the continuum
69  Energy Elo( 10., "MHz" );
70  p_emm = Elo.Ryd();
71  Energy Ehi( 100., "MeV" );
72  p_egamry = Ehi.Ryd();
73 
74  p_mesh_md5sum = MD5datafile( "continuum_mesh.ini" );
75 
76  p_SetupEdges();
78  p_SetupMesh(lgUnitCell);
79  }
80  /* perform sanity checks on the frequency mesh */
81  void ValidateEdges() const;
82  void CheckMesh() const;
83 
84  bool lgMeshSetUp() const
85  {
86  return ( p_anu.size() > 0 );
87  }
88  // getters and setters
89  long ncells() const
90  {
91  return long(p_anu.size());
92  }
93  double emm() const
94  {
95  return p_emm;
96  }
97  double egamry() const
98  {
99  return p_egamry;
100  }
102  {
104  }
105  void setResolutionScaleFactor(double fac)
106  {
107  if( !lgMeshSetUp() )
109  else
111  }
112  string mesh_md5sum() const
113  {
114  return p_mesh_md5sum;
115  }
116  const double* anuptr() const
117  {
118  return get_ptr(p_anu);
119  }
120  double anu(size_t i) const
121  {
122  return p_anu[i];
123  }
124  double anu2(size_t i) const
125  {
126  return p_anu2[i];
127  }
128  double anu3(size_t i) const
129  {
130  return p_anu3[i];
131  }
132  double anuln(size_t i) const
133  {
134  return p_anuln[i];
135  }
136  const double* anulog10ptr() const
137  {
138  return get_ptr(p_anulog10);
139  }
140  double anulog10(size_t i) const
141  {
142  return p_anulog10[i];
143  }
144  double anusqrt(size_t i) const
145  {
146  return p_anusqrt[i];
147  }
148  double anumin(size_t i) const
149  {
150  return p_anu_edge[i];
151  }
152  double anumax(size_t i) const
153  {
154  return p_anu_edge[i+1];
155  }
156  double widflx(size_t i) const
157  {
158  return p_widflx[i];
159  }
160  // return index ic such that p_anu_edge[ic] <= anu < p_anu_edge[ic+1]
161  size_t ipointC(double anu) const
162  {
163  ASSERT( lgMeshSetUp() );
164  ASSERT( anu >= p_anu_edge.front() && anu <= p_anu_edge.back() );
165  return hunt_bisect( p_anu_edge, anu );
166  }
167  // same as ipointC, but on fortran scale
168  size_t ipointF(double anu) const
169  {
170  return ipointC(anu) + 1;
171  }
172  // return smallest index ic such that p_anu[ic] >= threshold
173  // this guarantees that rfield.anu(ic) - threshold is always non-negative.
174  size_t ithreshC(double threshold) const
175  {
176  ASSERT( lgMeshSetUp() );
177  ASSERT( threshold >= p_anu.front() && threshold <= p_anu.back() );
178  size_t ic = hunt_bisect( p_anu, threshold );
179  // this if is nearly always taken...
180  if( p_anu[ic] < threshold )
181  ++ic;
182  return ic;
183  }
184  // same as ithreshC, but on fortran scale
185  size_t ithreshF(double threshold) const
186  {
187  return ithreshC(threshold) + 1;
188  }
189  bool isEnergyBound( Energy en ) const
190  {
191  return en.Ryd() > emm() && en.Ryd() < egamry();
192  }
193 
194  // constructor
196  {
197  // these will be initialized in InitMesh()
198  p_emm = 0.;
199  p_egamry = 0.;
200  // this is set with the set continuum resolution command
202  }
203 };
204 
205 #endif /* MESH_H_ */
double emm() const
Definition: mesh.h:93
vector< double > p_RangeUpperLimit
Definition: mesh.h:31
T * get_ptr(T *v)
Definition: cddefines.h:1115
double widflx(size_t i) const
Definition: mesh.h:156
void CheckMesh() const
Definition: mesh.cpp:371
vector< double > p_anulog10
Definition: mesh.h:47
string mesh_md5sum() const
Definition: mesh.h:112
double p_egamry
Definition: mesh.h:19
string MD5datafile(const char *fnam, access_scheme scheme)
Definition: thirdparty.cpp:4350
void InitMesh(bool lgUnitCell)
Definition: mesh.h:63
double anu(size_t i) const
Definition: mesh.h:120
void ValidateEdges() const
Definition: mesh.cpp:274
void setResolutionScaleFactor(double fac)
Definition: mesh.h:105
vector< double > p_RangeResolution
Definition: mesh.h:32
long hunt_bisect(const T x[], long n, T xval)
Definition: thirdparty.h:268
double anuln(size_t i) const
Definition: mesh.h:132
const double * anuptr() const
Definition: mesh.h:116
t_mesh()
Definition: mesh.h:195
bool fp_equal(sys_float x, sys_float y, int n=3)
Definition: cddefines.h:864
vector< double > p_anu3
Definition: mesh.h:51
size_t ipointC(double anu) const
Definition: mesh.h:161
void p_SetupMesh(bool lgUnitCell)
Definition: mesh.cpp:146
vector< double > p_widflx
Definition: mesh.h:44
bool lgMeshSetUp() const
Definition: mesh.h:84
Definition: mesh.h:10
vector< double > p_anu
Definition: mesh.h:38
double p_emm
Definition: mesh.h:16
vector< Energy > p_edges
Definition: mesh.h:35
double anusqrt(size_t i) const
Definition: mesh.h:144
size_t ipointF(double anu) const
Definition: mesh.h:168
vector< double > p_anuln
Definition: mesh.h:48
double anu2(size_t i) const
Definition: mesh.h:124
double anu3(size_t i) const
Definition: mesh.h:128
vector< double > p_anu2
Definition: mesh.h:50
double anumin(size_t i) const
Definition: mesh.h:148
size_t ithreshF(double threshold) const
Definition: mesh.h:185
vector< double > p_anu_edge
Definition: mesh.h:41
#define ASSERT(exp)
Definition: cddefines.h:637
double p_ResolutionScaleFactor
Definition: mesh.h:23
vector< double > p_anusqrt
Definition: mesh.h:49
double Ryd() const
Definition: energy.h:33
Definition: energy.h:9
double egamry() const
Definition: mesh.h:97
size_t ithreshC(double threshold) const
Definition: mesh.h:174
long ncells() const
Definition: mesh.h:89
void p_SetupEdges()
Definition: mesh.cpp:231
double anumax(size_t i) const
Definition: mesh.h:152
string p_mesh_md5sum
Definition: mesh.h:26
double anulog10(size_t i) const
Definition: mesh.h:140
void p_ReadResolution()
Definition: mesh.cpp:12
const double * anulog10ptr() const
Definition: mesh.h:136
double getResolutionScaleFactor() const
Definition: mesh.h:101
bool isEnergyBound(Energy en) const
Definition: mesh.h:189