ReFRACtor
aerosol_extinction_imp_base.h
Go to the documentation of this file.
1 #ifndef AEROSOL_EXTINCTION_IMP_BASE_H
2 #define AEROSOL_EXTINCTION_IMP_BASE_H
3 #include "aerosol_extinction.h"
5 
6 namespace FullPhysics {
7 /****************************************************************/
16 class AerosolExtinctionImpBase: public SubStateVectorArray<AerosolExtinction> {
17 public:
19  virtual std::string aerosol_name() const {return aerosol_name_;}
21  { fill_cache(); return aext; }
23  { fill_cache(); range_check(i, 0, aext.rows() - 1);
24  return (aext(i) + aext(i + 1)) / 2; }
25  virtual boost::shared_ptr<AerosolExtinction> clone() const = 0;
27  clone(const boost::shared_ptr<Pressure>& Press) const = 0;
28  virtual void update_sub_state_hook()
29  { cache_stale = true; }
30 
31 //-----------------------------------------------------------------------
34 //-----------------------------------------------------------------------
35  virtual std::string model_short_name() const = 0;
36 
37 //-----------------------------------------------------------------------
42 //-----------------------------------------------------------------------
43  virtual void print(std::ostream& Os) const { Os << desc(); }
44 
45 //-----------------------------------------------------------------------
48 //-----------------------------------------------------------------------
49  virtual std::string desc() const { return "AerosolExtinctionImpBase"; }
50 
51 //-----------------------------------------------------------------------
54 //-----------------------------------------------------------------------
55 
56  blitz::Array<double, 1> aerosol_parameter() const
57  {
58  return coefficient().value();
59  }
60 
61 //-----------------------------------------------------------------------
63 //-----------------------------------------------------------------------
64 
65  blitz::Array<double, 1> aerosol_parameter_uncertainty() const
66  {
67  blitz::Array<double, 1> uncert(coefficient().rows());
68  for(int i = 0; i < sv_cov_sub.rows(); i++)
69  uncert(i) = (sv_cov_sub(i,i) > 0 ? sqrt(sv_cov_sub(i, i)) : 0.0);
70  return uncert;
71  }
72 
73 protected:
74 //-----------------------------------------------------------------------
77 //-----------------------------------------------------------------------
78  mutable bool cache_stale;
79 
80 //-----------------------------------------------------------------------
83 //-----------------------------------------------------------------------
85 
86 //-----------------------------------------------------------------------
89 //-----------------------------------------------------------------------
90  virtual void calc_aerosol_extinction() const = 0;
91 
92 //-----------------------------------------------------------------------
94 //-----------------------------------------------------------------------
96  {
97  ArrayAd<double, 1> pressure_grid = pressure()->pressure_grid().value;
98  AutoDerivative<double> tot_aod = 0.0;
99  for(int layer_idx = 0; layer_idx < pressure()->number_layer(); layer_idx++) {
100  AutoDerivative<double> delta_press = (pressure_grid(layer_idx + 1) - pressure_grid(layer_idx)) / 2.0;
101  tot_aod += (delta_press * (aext(layer_idx) + aext(layer_idx + 1) ));
102  }
103  return tot_aod;
104  }
105 
106 //-----------------------------------------------------------------------
108 //-----------------------------------------------------------------------
109 
110  void init(const std::string Aerosol_name,
111  const blitz::Array<double, 1>& Coeff,
112  const blitz::Array<bool, 1>& Used_flag,
113  const boost::shared_ptr<Pressure>& Press,
114  bool Mark_according_to_press = true,
115  int Pdep_start = 0)
116  { SubStateVectorArray<AerosolExtinction>::init(Coeff, Used_flag, Press,
117  Mark_according_to_press,
118  Pdep_start);
119  aerosol_name_ = Aerosol_name;
120  }
121 
122 //-----------------------------------------------------------------------
125 //-----------------------------------------------------------------------
126 
127  AerosolExtinctionImpBase() : cache_stale(true) { }
128 
129 //-----------------------------------------------------------------------
133 //-----------------------------------------------------------------------
134  AerosolExtinctionImpBase(const std::string& Aerosol_name,
135  const blitz::Array<double, 1>& Coeff,
136  const blitz::Array<bool, 1>& Used_flag,
137  const boost::shared_ptr<Pressure>& Press,
138  bool Mark_according_to_press = true,
139  int Pdep_start = 0)
140  : SubStateVectorArray<AerosolExtinction>(Coeff, Used_flag, Press,
141  Mark_according_to_press, Pdep_start),
142  cache_stale(true), aerosol_name_(Aerosol_name) { }
143 private:
144  void fill_cache() const
145  {
146  if(cache_stale) {
149  }
150  cache_stale = false;
151  }
152  std::string aerosol_name_;
153 };
154 }
155 #endif
virtual ArrayAd< double, 1 > aerosol_extinction() const
void resize_number_variable(int nvar)
Definition: array_ad.h:165
#define range_check(V, Min, Max)
Range check.
Definition: fp_exception.h:140
AerosolExtinctionImpBase(const std::string &Aerosol_name, const blitz::Array< double, 1 > &Coeff, const blitz::Array< bool, 1 > &Used_flag, const boost::shared_ptr< Pressure > &Press, bool Mark_according_to_press=true, int Pdep_start=0)
Constructor that sets the coefficient() and used_flag() values.
blitz::Array< double, 1 > aerosol_parameter() const
Returns the value of the coefficients used to generate the aerosol extinction.
virtual std::string model_short_name() const =0
A short name representing the type of extinction model being implemented.
virtual boost::shared_ptr< AerosolExtinction > clone() const =0
Clone a AerosolExtinction object.
void init(const std::string Aerosol_name, const blitz::Array< double, 1 > &Coeff, const blitz::Array< bool, 1 > &Used_flag, const boost::shared_ptr< Pressure > &Press, bool Mark_according_to_press=true, int Pdep_start=0)
Initialize object.
virtual void update_sub_state_hook()
Hook for anything a derived class needs to do after coefficient is updated and before notify_update...
blitz::Array< double, 2 > sv_cov_sub
The subset of cov_full that is "owned" by this class, what was passed through update_sub_state.
ArrayAd< double, 1 > aext
The cached aerosol extinction for each level.
virtual void print(std::ostream &Os) const
Print to stream.
virtual std::string desc() const
Description of object, to be printed to stream.
const boost::shared_ptr< Pressure > & pressure() const
bool cache_stale
If this is true, the recalculate the vmr the next time we need it.
const blitz::Array< T, D > & value() const
Definition: array_ad.h:306
int number_variable() const
Definition: array_ad.h:376
AerosolExtinctionImpBase()
Default constructor, derived class should call init if they use this constructor. ...
blitz::Array< double, 1 > aerosol_parameter_uncertainty() const
Returns the uncertainty of the aerosol type coefficients.
virtual AutoDerivative< double > extinction_for_layer(int i) const
Extinction for given layer.
It is common to have a class that is an Observable with a set of coefficients, a subset of which are ...
virtual std::string aerosol_name() const
Name of aerosol.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
void init(const blitz::Array< double, 1 > &Coeff, const blitz::Array< bool, 1 > &Used_flag, const boost::shared_ptr< Pressure > &Press=boost::shared_ptr< Pressure >(), bool Mark_according_to_press=true, int Pdep_start=0)
As a design principle, we have each base class with the absolutely minimum interface needed for use f...
virtual void calc_aerosol_extinction() const =0
Derived classes should provide a function to fill in vmr when this is called.
virtual AutoDerivative< double > total_aod() const
Total aerosol optical depth of the extinction values in aext.
This class maps the state vector to the aerosol extinction on each level.
int rows() const
Definition: array_ad.h:368

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