ReFRACtor
atmosphere_oco.h
Go to the documentation of this file.
1 #ifndef ATMOSPHERE_OCO_H
2 #define ATMOSPHERE_OCO_H
3 #include "rt_atmosphere.h"
4 #include "absorber.h"
5 #include "pressure.h"
6 #include "temperature.h"
7 #include "aerosol.h"
8 #include "ground.h"
9 #include "surface_temperature.h"
10 #include "relative_humidity.h"
11 #include "rayleigh.h"
12 #include "rayleigh_greek_moment.h"
13 #include "array_ad_cache.h"
14 
15 namespace FullPhysics {
16 /****************************************************************/
36 class AtmosphereOco : public RtAtmosphere,
37  public Observer<Aerosol>,
38  public Observer<Pressure> {
39 public:
40  // Supply all atmospheric consituent classes
42  const boost::shared_ptr<Pressure>& pressurev,
43  const boost::shared_ptr<Temperature>& temperaturev,
44  const boost::shared_ptr<Aerosol>& aerosolv,
46  const boost::shared_ptr<Ground>& groundv,
47  const boost::shared_ptr<SurfaceTemperature>& surface_tempv,
48  const std::vector<boost::shared_ptr<Altitude> >& altv,
50 
51  // No surface temperature
53  const boost::shared_ptr<Pressure>& pressurev,
54  const boost::shared_ptr<Temperature>& temperaturev,
55  const boost::shared_ptr<Aerosol>& aerosolv,
57  const boost::shared_ptr<Ground>& groundv,
58  const std::vector<boost::shared_ptr<Altitude> >& altv,
60 
61  // No ground, no surface temperature
63  const boost::shared_ptr<Pressure>& pressurev,
64  const boost::shared_ptr<Temperature>& temperaturev,
65  const boost::shared_ptr<Aerosol>& aerosolv,
67  const std::vector<boost::shared_ptr<Altitude> >& altv,
69 
70  // No aerosol
72  const boost::shared_ptr<Pressure>& pressurev,
73  const boost::shared_ptr<Temperature>& temperaturev,
75  const boost::shared_ptr<Ground>& groundv,
76  const boost::shared_ptr<SurfaceTemperature>& surface_tempv,
77  const std::vector<boost::shared_ptr<Altitude> >& altv,
79 
80  // No aerosol, no surface temperature
82  const boost::shared_ptr<Pressure>& pressurev,
83  const boost::shared_ptr<Temperature>& temperaturev,
85  const boost::shared_ptr<Ground>& groundv,
86  const std::vector<boost::shared_ptr<Altitude> >& altv,
88 
89  // No ground, aerosol or surface temperature
91  const boost::shared_ptr<Pressure>& pressurev,
92  const boost::shared_ptr<Temperature>& temperaturev,
94  const std::vector<boost::shared_ptr<Altitude> >& altv,
96 
97  virtual ~AtmosphereOco() {}
98  virtual ArrayAdWithUnit<double, 1> altitude(int spec_index) const;
99  virtual int number_spectrometer() const {return alt.size();}
100  virtual int number_layer() const
101  {
102  if(nlay < 0)
103  nlay = pressure->number_layer();
104  return nlay;
105  }
106  virtual AutoDerivative<double>
107  column_optical_depth(double wn, int spec_index, const std::string& Gas_name) const
108  {
109  if (totaltaug_cache) {
110  if (not totaltaug_cache->is_valid(wn))
111  fill_cache(wn, spec_index);
112 
113  return (*totaltaug_cache)[wn](absorber->gas_index(Gas_name));
114  } else {
115  fill_cache(wn, spec_index);
116  return totaltaug(absorber->gas_index(Gas_name));
117  }
118  }
120  {
121  return totaltaug_cache;
122  };
123  virtual ArrayAd<double, 1>
124  optical_depth_wrt_iv(double wn, int spec_index) const
125  {
126  fill_cache(wn, spec_index);
127  return tau;
128  }
129  virtual ArrayAd<double, 1>
130  single_scattering_albedo_wrt_iv(double wn, int spec_index) const
131  {
132  fill_cache(wn, spec_index);
133  return omega;
134  }
135  virtual ArrayAd<double, 3>
136  scattering_moment_wrt_iv(double wn, int spec_index, int nummom = -1, int numscat = -1) const
137  {
138  fill_cache(wn, spec_index);
139  return scattering_moment_common(wn, nummom, numscat);
140  }
141  virtual ArrayAd<double, 1>
142  optical_depth_wrt_iv(double wn, int spec_index,
143  const ArrayAd<double, 2>& iv) const
144  {
146  calc_rt_parameters(wn, iv);
147  return tau;
148  }
149  virtual ArrayAd<double, 1>
150  single_scattering_albedo_wrt_iv(double wn, int spec_index,
151  const ArrayAd<double, 2>& iv) const
152  {
154  calc_rt_parameters(wn, iv);
155  return omega;
156  }
157  virtual ArrayAd<double, 3>
158  scattering_moment_wrt_iv(double wn, int spec_index,
159  const ArrayAd<double, 2>& iv,
160  int nummom = -1,
161  int numscat = -1) const
162  {
164  calc_rt_parameters(wn, iv);
165  return scattering_moment_common(wn, nummom, numscat);
166  }
167 
168 
169  virtual ArrayAd<double, 1>
170  atmosphere_blackbody(double wn, int spec_index) const;
171 
172  virtual AutoDerivative<double>
173  surface_blackbody(double wn, int spec_index) const;
174 
175  virtual ArrayAd<double, 2>
176  intermediate_variable(double wn, int spec_index) const
177  {
178  fill_cache(wn, spec_index);
179  return intermediate_v;
180  }
181 
182  virtual const boost::shared_ptr<Ground> ground() const {return ground_ptr;}
183 
184  // Use the state vector observer routines to update the length of the
185  // state vector size used internally to allocated intermediate variables
186  virtual void notify_add(StateVector& Sv)
187  { sv_size = (int) Sv.state().size(); }
188  virtual void notify_remove(StateVector& Sv)
189  { sv_size = (int) Sv.state().size(); }
190  virtual void notify_update(const StateVector& Sv)
191  { notify_update_do(*this); sv_size = (int) Sv.state().size(); }
192 
193  virtual void print(std::ostream& Os) const;
194  virtual void notify_update(const Aerosol& A);
195  virtual void notify_update(const Pressure& P)
196  { nlay = -1; }
197 
198  virtual void reset_timer();
199  virtual std::string timer_info() const;
200 
201  const boost::shared_ptr<Pressure>& pressure_ptr() const {return pressure;}
202  const boost::shared_ptr<Absorber>& absorber_ptr() const {return absorber;}
204  {return temperature;}
205  const boost::shared_ptr<Aerosol>& aerosol_ptr() const {return aerosol;}
206  void set_aerosol(boost::shared_ptr<Aerosol>& new_aerosol, StateVector& Sv);
208  { return rh; }
209  const boost::shared_ptr<Constant>& constant_ptr() const {return constant;}
210  const boost::shared_ptr<Rayleigh>& rayleigh_ptr() const {return rayleigh;}
211  const std::vector<boost::shared_ptr<Altitude> >& altitude_ptr() const
212  { return alt;}
213  const boost::shared_ptr<Altitude>& altitude_ptr(int Spec_index) const
214  { range_check(Spec_index, 0, number_spectrometer()); return alt[Spec_index];}
216 
217 //-----------------------------------------------------------------------
220 //-----------------------------------------------------------------------
221 
223  return !aerosol || aerosol->number_particle() == 0;
224  }
225 
226  void set_surface_pressure_for_testing(double x);
227 
228  void attach_children_to_sv(StateVector& statev);
229 private:
230 
233  boost::shared_ptr<Temperature> temperature;
236  boost::shared_ptr<Ground> ground_ptr;
240 
241  // The Altitude and Gravity constants depend on the specific
242  // spectrometer we are using, because they see different ground
243  // locations and this location enters into the hydrostatic equations
244  // that determine the gravity and altitude constants.
245  std::vector<boost::shared_ptr<Altitude> > alt;
246  int sv_size;
247 
248  // We cache the last calculation of these values
249  // Keeping these around to reuse helps since
250  // its almost certain each subsequent calculation
251  // will have the same size, meaning the .resize operation
252  // has no work to do and no new memory has to be allocated
253  mutable double wn_tau_cache;
254  mutable int spec_index_tau_cache;
255  mutable ArrayAd<double, 1> omega, taur, frac_ray, tau;
256  mutable ArrayAd<double, 1> totaltaug;
257  mutable ArrayAd<double, 2> frac_aer;
258  mutable ArrayAd<double, 2> intermediate_v;
259  mutable int nlay;
260 
261  // Items that might need to be cached for access
262  // outside of say the radiative transfer loop, without
263  // causing everything else to be recalculated
265 
266  void initialize();
267  void calc_rt_parameters(double wn, const ArrayAd<double, 2>& iv) const;
268  void calc_intermediate_variable(double wn, int spec_index) const;
269  bool fill_cache(double wn, int spec_index) const;
270  ArrayAd<double, 3> scattering_moment_common(double wn,
271  int nummom, int numscat) const;
272 };
273 }
274 #endif
virtual ArrayAd< double, 1 > optical_depth_wrt_iv(double wn, int spec_index, const ArrayAd< double, 2 > &iv) const
This is a variation of optical_depth that takes the supplied value for the intermediate variables rat...
#define range_check(V, Min, Max)
Range check.
Definition: fp_exception.h:140
virtual ArrayAd< double, 1 > single_scattering_albedo_wrt_iv(double wn, int spec_index, const ArrayAd< double, 2 > &iv) const
This is a variation of single_scattering_albedo that takes the supplied value for the intermediate va...
virtual std::string timer_info() const
Return timer information.
This class is responsible for setting up the atmosphere and ground information needed to run the Radi...
Definition: rt_atmosphere.h:51
bool rayleigh_only_atmosphere() const
Indicate we have rayleigh only atmosphere, i.e., we don&#39;t have any aerosol content.
void set_aerosol(boost::shared_ptr< Aerosol > &new_aerosol, StateVector &Sv)
Changes the aerosol class used.
const blitz::Array< double, 1 > & state() const
Current state vector.
Definition: state_vector.h:34
const boost::shared_ptr< Pressure > & pressure_ptr() const
virtual ArrayAd< double, 1 > optical_depth_wrt_iv(double wn, int spec_index) const
The optical depth for each layer, for the given wave number.
virtual void notify_add(StateVector &Sv)
Called when an object is added to an Observable.
boost::shared_ptr< AtmosphereOco > clone() const
This clones a Atmosphere object.
static AccumulatedTimer timer
Timer for RtAtmosphere.
Definition: rt_atmosphere.h:55
virtual void notify_remove(StateVector &Sv)
Called when an object is removed from an Observable.
virtual AutoDerivative< double > column_optical_depth(double wn, int spec_index, const std::string &Gas_name) const
Total column optical depth for the given gas.
const boost::shared_ptr< RelativeHumidity > & relative_humidity_ptr() const
const boost::shared_ptr< Constant > & constant_ptr() const
virtual ArrayAd< double, 3 > scattering_moment_wrt_iv(double wn, int spec_index, int nummom=-1, int numscat=-1) const
The scattering moments for for each layer, for the given wave number.
virtual ArrayAd< double, 2 > intermediate_variable(double wn, int spec_index) const
This gives the values of the intermediate variables and the Jacobian with respect to the state vector...
virtual int number_layer() const
Number of layers we currently have.
const boost::shared_ptr< Temperature > & temperature_ptr() const
virtual void reset_timer()
Reset timer.
void notify_update_do(const RtAtmosphere &Self)
Function to call to notify Observers of a state change.
Definition: observer.h:121
const Unit A("A", 1.0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0)
virtual const boost::shared_ptr< Ground > ground() const
Object that represents the ground surface.
const boost::shared_ptr< Altitude > & altitude_ptr(int Spec_index) const
This class maintains the aerosol portion of the state.
Definition: aerosol.h:24
FunctionTimer function_timer(bool Auto_log=false) const
Function timer.
virtual int number_spectrometer() const
Number of spectrometers we have.
virtual AutoDerivative< double > surface_blackbody(double wn, int spec_index) const
The surface thermal blackbody.
virtual ArrayAd< double, 3 > scattering_moment_wrt_iv(double wn, int spec_index, const ArrayAd< double, 2 > &iv, int nummom=-1, int numscat=-1) const
This is a variation of scattering_moment that takes the supplied value for the intermediate variables...
This handles informing a set of interested objects when the state vector has updated.
Definition: state_vector.h:16
const boost::shared_ptr< Rayleigh > & rayleigh_ptr() const
virtual void print(std::ostream &Os) const
This class maintains the pressure portion of the state.
Definition: pressure.h:32
const boost::shared_ptr< Aerosol > & aerosol_ptr() const
virtual void notify_update(const Pressure &P)
Called when the Observed object is updated.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
virtual boost::shared_ptr< ArrayAdCache< double, double, 1 > > & column_optical_depth_cache()
const std::vector< boost::shared_ptr< Altitude > > & altitude_ptr() const
This class maintains the atmosphere portion of the state, and uses this to set up the atmosphere and ...
Helper class for AccumulatedTimer.
void set_surface_pressure_for_testing(double x)
For unit test purposes, it is useful to be able to directly change the surface pressure.
virtual ArrayAd< double, 1 > single_scattering_albedo_wrt_iv(double wn, int spec_index) const
The single scattering albedo for each layer, for the given wave number.
void attach_children_to_sv(StateVector &statev)
For unit test purposes, it is useful to be able to clone or create a new atmosphere class then attach...
virtual void notify_update(const StateVector &Sv)
Called when the Observed object is updated.
virtual ArrayAd< double, 1 > atmosphere_blackbody(double wn, int spec_index) const
The atmospheric thermal blackbody values per level.
const boost::shared_ptr< Absorber > & absorber_ptr() const
virtual ArrayAdWithUnit< double, 1 > altitude(int spec_index) const
Altitude grid for current pressure grid.
Simple Mixin to be and Observer of another object of class T.
Definition: observer.h:29
AtmosphereOco(const boost::shared_ptr< Absorber > &absorberv, const boost::shared_ptr< Pressure > &pressurev, const boost::shared_ptr< Temperature > &temperaturev, const boost::shared_ptr< Aerosol > &aerosolv, const boost::shared_ptr< RelativeHumidity > &rhv, const boost::shared_ptr< Ground > &groundv, const boost::shared_ptr< SurfaceTemperature > &surface_tempv, const std::vector< boost::shared_ptr< Altitude > > &altv, const boost::shared_ptr< Constant > &C)
Create an an Atmosphere with all available components:

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:08