ReFRACtor
pressure_sigma.cc
Go to the documentation of this file.
1 #include "pressure_sigma.h"
2 #include "fp_exception.h"
3 #include "ostream_pad.h"
4 using namespace FullPhysics;
5 using namespace blitz;
6 
7 #ifdef HAVE_LUA
8 #include "register_lua.h"
10 .def(luabind::constructor<const blitz::Array<double, 1>&,
11  const blitz::Array<double, 1>&,
12  double, bool>())
13 .def(luabind::constructor<const blitz::Array<double, 1>&,
14  double, bool>())
16 #endif
17 
18 //-----------------------------------------------------------------------
20 //-----------------------------------------------------------------------
21 
22 PressureSigma::PressureSigma(const blitz::Array<double, 1>& A,
23  const blitz::Array<double, 1>& B,
24  double Surface_pressure, bool Pressure_flag)
25 : a_(A.copy()), b_(B.copy())
26 {
27  if(A.rows() != B.rows())
28  throw Exception("A and B need to be the same size in PressureSigma constructor");
29 
30  blitz::Array<double, 1> val(1);
31  blitz::Array<bool, 1> flag(1);
32  val(0) = Surface_pressure;
33  flag(0) = Pressure_flag;
34  init(val, flag);
35  cov.resize(1, 1);
36  cov(0,0) = 1;
37 }
38 
39 //-----------------------------------------------------------------------
44 //-----------------------------------------------------------------------
45 
46 PressureSigma::PressureSigma(const blitz::Array<double, 1>& Pressure_grid,
47  double Surface_pressure, bool Pressure_flag)
48 {
49  set_levels_from_grid(Pressure_grid);
50 
51  blitz::Array<double, 1> val(1);
52  blitz::Array<bool, 1> flag(1);
53  val(0) = Surface_pressure;
54  flag(0) = Pressure_flag;
55  init(val, flag);
56  cov.resize(1, 1);
57  cov(0,0) = 1;
58 }
59 
60 //-----------------------------------------------------------------------
64 //-----------------------------------------------------------------------
65 
66 void PressureSigma::set_levels_from_grid(const blitz::Array<double, 1>& Pressure_grid)
67 {
68  a_.resize(Pressure_grid.rows());
69  a_ = 0.0;
70 
71  b_.resize(Pressure_grid.rows());
72  b_ = Pressure_grid;
73  b_ = b_ / Pressure_grid(Pressure_grid.rows()-1);
74 
75  cache_stale = true;
77 }
78 
79 //-----------------------------------------------------------------------
82 //-----------------------------------------------------------------------
83 
85 {
87  pgrid.value.resize(b_.rows(), coeff.number_variable());
88  for(int i = 0; i < b_.rows(); ++i) {
89  pgrid.value(i) = b_(i) * coeff(0) + a_(i);
90 
91  // Ensure that the pressure grid calculated in increasing
92  // Since so many linear interpolations rely on this, this error
93  // message will make more sense than what would be throw otherwise:
94  // X needs to be sorted
95  if(i > 0 and pgrid.value(i-1).value() > pgrid.value(i).value()) {
96  stringstream err_msg;
97  err_msg << "At level " << i << " pressure is smaller: "
98  << "("
99  << b_(i-1) << " * " << coeff(0).value() << " + " << a_(i-1)
100  << ") = "
101  << pgrid.value(i).value()
102  << " than the value at the previous level: "
103  << "("
104  << b_(i) << " * " << coeff(0).value() << " + " << a_(i)
105  << ") = "
106  << pgrid.value(i-1).value();
107  throw Exception(err_msg.str());
108  }
109  }
110 }
111 
112 //-----------------------------------------------------------------------
116 //-----------------------------------------------------------------------
117 
119 {
121  (new PressureSigma(a_, b_, coefficient()(0).value(),
122  used_flag_value()(0)));
123  return res;
124 }
125 
126 void PressureSigma::print(std::ostream& Os) const
127 {
128  OstreamPad opad(Os, " ");
129  Os << "PressureSigma:\n"
130  << " Surface pressure: " << surface_pressure().value.value() << "\n"
131  << " Retrieval Flag: " << (used_flag_value()(0) ? "True\n":
132  "False\n")
133  << " a: \n";
134  opad << a() << "\n";
135  opad.strict_sync();
136  Os << " b: \n";
137  opad << b() << "\n";
138  opad.strict_sync();
139 }
140 
virtual boost::shared_ptr< Pressure > clone() const
Clone a PressureFixedLevel object.
blitz::Array< double, 2 > cov
Last covariance matrix updated from the StateVector.
PressureSigma(const blitz::Array< double, 1 > &A, const blitz::Array< double, 1 > &B, double Surface_pressure, bool Pressure_flag)
Constructor.
ArrayAdWithUnit< double, 1 > pgrid
The cached pressure grid.
This is a filtering stream that adds a pad to the front of every line written out.
Definition: ostream_pad.h:32
void set_levels_from_grid(const blitz::Array< double, 1 > &Pressure_grid)
Creates A and B parameters from the pressure grid passed in.
const Unit Pa("Pa", N/(m *m))
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
virtual void calc_pressure_grid() const
Calculate the new pressure grid.
const blitz::Array< bool, 1 > & used_flag_value() const
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
This class maintains the pressure portion of the state.
void notify_update_do(const T &Self)
Function to call to notify Observers of a state change.
Definition: observer.h:121
Apply value function to a blitz array.
const Unit A("A", 1.0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0)
const blitz::Array< T, D > & value() const
Definition: array_ad.h:306
void resize(const blitz::TinyVector< int, D > &Shape, int nvar)
Definition: array_ad.h:177
virtual void print(std::ostream &Os) const
Print to stream.
AutoDerivativeWithUnit< double > surface_pressure() const
Return surface pressure, which is just the pressure at the bottom level of pressure_grid.
Definition: pressure.cc:19
bool cache_stale
If this is true, the recalculate the pressure_grid the next time we need it.
const blitz::Array< double, 1 > & a() const
int number_variable() const
Definition: array_ad.h:376
const blitz::Array< double, 1 > & b() const
This class maintains the pressure portion of the state.
Definition: pressure.h:32
const ArrayAd< double, 1 > & coefficient() const
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)
#define REGISTER_LUA_END()
Definition: register_lua.h:134
double value(const FullPhysics::AutoDerivative< double > &Ad)

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