ReFRACtor
absorber_vmr_imp_base.h
Go to the documentation of this file.
1 #ifndef ABSORBER_VMR_IMP_BASE_H
2 #define ABSORBER_VMR_IMP_BASE_H
3 #include "absorber_vmr.h"
5 #include <boost/function.hpp>
6 
7 namespace FullPhysics {
8 /****************************************************************/
17 class AbsorberVmrImpBase: public SubStateVectorArray<AbsorberVmr> {
18 public:
19  virtual ~AbsorberVmrImpBase() {}
20  virtual std::string gas_name() const {return gas_name_;}
21  virtual AutoDerivative<double>
23  { fill_cache(); return vmr(P); }
24  virtual boost::shared_ptr<AbsorberVmr> clone() const = 0;
26  clone(const boost::shared_ptr<Pressure>& Press) const = 0;
27  virtual void update_sub_state_hook()
28  { cache_stale = true; }
29 
30 //-----------------------------------------------------------------------
35 //-----------------------------------------------------------------------
36  virtual void print(std::ostream& Os) const { Os << desc(); }
37 
38 //-----------------------------------------------------------------------
41 //-----------------------------------------------------------------------
42  virtual std::string desc() const { return "AbsorberVmrImpBase"; }
43 
44  virtual blitz::Array<bool, 1> state_used() const
45  {
46  blitz::Array<bool, 1> res(sv_full.rows());
47  res = false;
48  if(state_vector_start_index() < res.rows())
49  res(blitz::Range(state_vector_start_index(),
50  state_vector_start_index() + sub_vector_size() - 1)) = true;
51  return res;
52  }
53 protected:
54 //-----------------------------------------------------------------------
57 //-----------------------------------------------------------------------
58  mutable bool cache_stale;
59 
60 //-----------------------------------------------------------------------
63 //-----------------------------------------------------------------------
64  mutable boost::function<AutoDerivative<double>(AutoDerivative<double>)> vmr;
65 
66 //-----------------------------------------------------------------------
69 //-----------------------------------------------------------------------
70  virtual void calc_vmr() const = 0;
71 
72 //-----------------------------------------------------------------------
74 //-----------------------------------------------------------------------
75 
76  void init(const std::string Gas_name,
77  const blitz::Array<double, 1>& Coeff,
78  const blitz::Array<bool, 1>& Used_flag,
79  const boost::shared_ptr<Pressure>& Press,
80  bool Mark_according_to_press = true,
81  int Pdep_start = 0)
82  { SubStateVectorArray<AbsorberVmr>::init(Coeff, Used_flag, Press,
83  Mark_according_to_press,
84  Pdep_start);
85  gas_name_ = Gas_name;
86  }
87 
88 //-----------------------------------------------------------------------
91 //-----------------------------------------------------------------------
92 
93  AbsorberVmrImpBase() : cache_stale(true) { }
94 
95 //-----------------------------------------------------------------------
99 //-----------------------------------------------------------------------
100  AbsorberVmrImpBase(const std::string& Gas_name,
101  const blitz::Array<double, 1>& Coeff,
102  const blitz::Array<bool, 1>& Used_flag,
103  const boost::shared_ptr<Pressure>& Press,
104  bool Mark_according_to_press = true,
105  int Pdep_start = 0)
106  : SubStateVectorArray<AbsorberVmr>(Coeff, Used_flag, Press,
107  Mark_according_to_press, Pdep_start),
108  cache_stale(true), gas_name_(Gas_name) { }
109 private:
110  void fill_cache() const
111  {
112  if(cache_stale)
113  calc_vmr();
114  cache_stale = false;
115  }
116  std::string gas_name_;
117 };
118 }
119 #endif
AbsorberVmrImpBase(const std::string &Gas_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.
virtual void calc_vmr() const =0
Derived classes should provide a function to fill in vmr when this is called.
ArrayAd< double, 1 > sv_full
The last full state vector we have been updated with, saved for reference by derived class...
void init(const std::string Gas_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.
As a design principle, we have each base class with the absolutely minimum interface needed for use f...
int sub_vector_size() const
Length of the sub set of the state vector used by this object.
virtual AutoDerivative< double > volume_mixing_ratio(const AutoDerivative< double > &P) const
This returns the volume mixing ratio at the given pressure level.
virtual blitz::Array< bool, 1 > state_used() const
Indicate what portion of the state vector is used to calculate the VMR.
virtual boost::shared_ptr< AbsorberVmr > clone() const =0
Clone a AbsorberVmr object.
int state_vector_start_index() const
Starting index of state vector used by this object.
This gives the Gas Absorber Volumn mixing ratio for a single gas.
Definition: absorber_vmr.h:17
bool cache_stale
If this is true, the recalculate the vmr the next time we need it.
virtual std::string desc() const
Description of object, to be printed to stream.
AbsorberVmrImpBase()
Default constructor, derived class should call init if they use this constructor. ...
virtual void print(std::ostream &Os) const
Print to stream.
It is common to have a class that is an Observable with a set of coefficients, a subset of which are ...
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)
virtual void update_sub_state_hook()
Hook for anything a derived class needs to do after coefficient is updated and before notify_update...
boost::function< AutoDerivative< double >AutoDerivative< double >)> vmr
The cached volumn mixing ration.
virtual std::string gas_name() const
This indicates the name of this particular Absorber.
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