ReFRACtor
sub_state_vector_array.h
Go to the documentation of this file.
1 #ifndef SUB_STATE_VECTOR_ARRAY_H
2 #define SUB_STATE_VECTOR_ARRAY_H
4 #include "pressure.h"
5 #include <boost/lexical_cast.hpp>
6 
7 namespace FullPhysics {
8 /****************************************************************/
20 template<class Base> class SubStateVectorArray:
21  virtual public Base,
22  public SubStateVectorObserver {
23 public:
24  //-----------------------------------------------------------------------
36  //-----------------------------------------------------------------------
37 
38  SubStateVectorArray(const blitz::Array<double, 1>& Coeff,
39  const blitz::Array<bool, 1>& Used_flag,
41  bool Mark_according_to_press = true,
42  int Pdep_start = 0)
43  : coeff(Coeff.copy()), press(Press), used_flag(Used_flag.copy()),
44  mark_according_to_press(Mark_according_to_press),
45  pdep_start(Pdep_start)
46  {
47  if(coeff.rows() != used_flag.rows()) {
48  throw Exception("Coeff and Used_flag need to be the same size");
49  }
50 
51  state_vector_observer_initialize(count(Used_flag));
52  }
53 
54  //-----------------------------------------------------------------------
56  //-----------------------------------------------------------------------
58 
59  void init(const blitz::Array<double, 1>& Coeff,
60  const blitz::Array<bool, 1>& Used_flag,
62  bool Mark_according_to_press = true,
63  int Pdep_start = 0)
64  {
65  mark_according_to_press = Mark_according_to_press;
66  pdep_start = Pdep_start;
67  coeff.reference(Coeff.copy());
68  press = Press;
69  used_flag.reference(Used_flag.copy());
70 
71  if(coeff.rows() != used_flag.rows()) {
72  throw Exception("Coeff and Used_flag need to be the same size");
73  }
74 
75  state_vector_observer_initialize(count(Used_flag));
76  }
77 
78  //-----------------------------------------------------------------------
80  //-----------------------------------------------------------------------
81 
82  SubStateVectorArray(double Coeff, bool Used_flag)
83  : coeff(1, 0), used_flag(1)
84  {
85  coeff.value()(0) = Coeff;
86  used_flag(0) = Used_flag;
88  }
89 
90  virtual ~SubStateVectorArray() {}
91  void mark_used_sub(blitz::Array<bool, 1>& Used) const
92  {
93  int si = 0;
94 
95  for(int i = 0; i < used_flag.rows(); ++i) {
96  if(used_flag(i)) {
98  i < press->number_level() + pdep_start) {
99  Used(si) = true;
100  }
101 
102  ++si;
103  }
104  }
105  }
106 
107 
108  //-----------------------------------------------------------------------
118  //-----------------------------------------------------------------------
119 
120  virtual std::string sub_state_identifier() const
121  {
122  return "unknown/not_set";
123  }
124 
125  //-----------------------------------------------------------------------
127  //-----------------------------------------------------------------------
128 
129  virtual std::string state_vector_name_i(int i) const
130  {
131  return "Coeff" + boost::lexical_cast<std::string>(i + 1);
132  }
133 
134  virtual void state_vector_name_sub(blitz::Array<std::string, 1>& Sv_name) const
135  {
136  int si = 0;
137 
138  for(int i = 0; i < used_flag.rows(); ++i)
139  if(used_flag(i)) {
140  Sv_name(si) = state_vector_name_i(i);
141  ++si;
142  }
143  }
144 
145  virtual void update_sub_state(const ArrayAd<double, 1>& Sv_sub, const blitz::Array<double, 2>& Cov)
146  {
147  if (Sv_sub.rows() > 0) {
148  cov.reference(Cov.copy());
149  int si = 0;
151 
152  for(int i = 0; i < coeff.rows(); ++i)
153  if(used_flag(i)) {
154  coeff(i) = Sv_sub(si);
155  ++si;
156  }
157  }
158 
161  }
162 
163  //-----------------------------------------------------------------------
166  //-----------------------------------------------------------------------
167  virtual void update_sub_state_hook()
168  {
169  }
170 
172  {
173  return coeff;
174  }
175 
176  const blitz::Array<bool, 1>& used_flag_value() const
177  {
178  return used_flag;
179  }
180 
181  const blitz::Array<double, 2>& statevector_covariance() const
182  {
183  return cov;
184  }
185 
187  {
188  return press;
189  }
190 protected:
191 
192  //-----------------------------------------------------------------------
194  //-----------------------------------------------------------------------
195 
197 
198  //-----------------------------------------------------------------------
201  //-----------------------------------------------------------------------
202 
204 
205  //-----------------------------------------------------------------------
208  //-----------------------------------------------------------------------
209 
210  blitz::Array<bool, 1> used_flag;
211 
212  //-----------------------------------------------------------------------
215  //-----------------------------------------------------------------------
216  blitz::Array<double, 2> cov;
217 
218  //-----------------------------------------------------------------------
223  //-----------------------------------------------------------------------
224 
226 
227  //-----------------------------------------------------------------------
231  //-----------------------------------------------------------------------
232 
234 };
235 }
236 #endif
void resize_number_variable(int nvar)
Definition: array_ad.h:165
void state_vector_observer_initialize(int Plen)
Take the given number of state vector parameters.
virtual void update_sub_state(const ArrayAd< double, 1 > &Sv_sub, const blitz::Array< double, 2 > &Cov)
Called by update_state with the subset of the state vector used by this class.
blitz::Array< double, 2 > cov
Last covariance matrix updated from the StateVector.
bool mark_according_to_press
Flag indicating if we only mark coefficients >= pdep_start + press->number_level() in mark_used_sub...
SubStateVectorArray(double Coeff, bool Used_flag)
Special case when Coeff and Used_flag have exactly one row.
virtual void update_sub_state_hook()
Hook for anything a derived class needs to do after coefficient is updated and before notify_update...
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
const blitz::Array< bool, 1 > & used_flag_value() const
void notify_update_do(const T &Self)
Function to call to notify Observers of a state change.
Definition: observer.h:121
const boost::shared_ptr< Pressure > & pressure() const
const blitz::Array< T, D > & value() const
Definition: array_ad.h:306
const blitz::Array< double, 2 > & statevector_covariance() const
void mark_used_sub(blitz::Array< bool, 1 > &Used) const
Called by mark_used with the subset of the state vector used by this class.
SubStateVectorArray(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)
Constructor.
int pdep_start
Index of first coefficient that depends on the number of pressure levels.
A common StateVectorObserver just "owns" a subset of the StateVector.
int number_variable() const
Definition: array_ad.h:376
virtual void state_vector_name_sub(blitz::Array< std::string, 1 > &Sv_name) const
Called by state_vector_name with the subset of the Sv_name used by this class.
void reference(const ArrayAd< T, D > &V)
Definition: array_ad.h:372
const ArrayAd< double, 1 > & coefficient() const
blitz::Array< bool, 1 > used_flag
Flag indicating which of the coefficients gets updated by the StateVector.
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)
boost::shared_ptr< Pressure > press
Pressure.
ArrayAd< double, 1 > coeff
Coefficients.
virtual std::string state_vector_name_i(int i) const
Return state vector name for ith entry in coeff.
virtual std::string sub_state_identifier() const
Return a string to identify this part of the state, this name should be all lower case and seperate p...
int rows() const
Definition: array_ad.h:368
SubStateVectorArray()
Default constructor, should call init.

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