ReFRACtor
pressure_fixed_level.cc
Go to the documentation of this file.
1 #include "pressure_fixed_level.h"
2 #include "fp_exception.h"
3 #include "ostream_pad.h"
4 using namespace FullPhysics;
5 using namespace blitz;
6 #ifdef HAVE_LUA
7 #include "register_lua.h"
9 .def(luabind::constructor<bool, const boost::shared_ptr<PressureLevelInput>&,
10  double>())
12 #endif
13 
14 //-----------------------------------------------------------------------
19 //-----------------------------------------------------------------------
20 
22 
23 //-----------------------------------------------------------------------
26 //-----------------------------------------------------------------------
27 
29 {
30  const AutoDerivative<double>& surf_p = coefficient()(0);
31  const blitz::Array<double, 1>& plevel = press_level->pressure_level();
32 
33  blitz::Array<double, 1>::const_iterator lb_iter = std::lower_bound(plevel.begin(), plevel.end(), surf_p);
34  int nelem = -1;
35  if (lb_iter != plevel.end())
36  nelem = lb_iter.position()(0) + 1;
37 
38  if(nelem < 2 || nelem > plevel.rows())
39  throw Exception("Surface pressure is outside the range of the pressure levels");
40 
41  // Group surface pressure as bottom of previous layer if new layer
42  // with the lower bound of the surface pressure would be too small
43  // But only if doing so would not result in 0 levels
44  if (nelem > 2) {
45  double psurf_diff = surf_p.value() - plevel(nelem-2);
46  double level_frac = (plevel(nelem-1) - plevel(nelem-2)) *
47  new_level_fractional_size;
48  if (psurf_diff < level_frac) nelem--;
49  }
50 
51  pgrid.value.resize(nelem, surf_p.number_variable());
52  Range r(0, nelem - 2);
53  pgrid.value(r) = plevel(r);
54  pgrid.value(nelem - 1) = surf_p;
55  pgrid.units = units::Pa;
56 }
57 
58 //-----------------------------------------------------------------------
62 //-----------------------------------------------------------------------
63 
65 {
67  (new PressureFixedLevel(used_flag_value()(0), press_level,
68  coefficient()(0).value()));
69  return res;
70 }
71 
72 void PressureFixedLevel::print(std::ostream& Os) const
73 {
74  OstreamPad opad(Os, " ");
75  Os << "PressureFixedLevel:\n"
76  << " Surface pressure: " << surface_pressure().value.value() << "\n"
77  << " Retrieval Flag: " << (used_flag_value()(0) ? "True\n":
78  "False\n")
79  << " Number active level: " << number_active_level() << "\n";
80  opad << *press_level;
81  opad.strict_sync();
82 }
83 
This is a filtering stream that adds a pad to the front of every line written out.
Definition: ostream_pad.h:32
static const double new_level_fractional_size
Size a new level must be in porportion to the layer above it when resizing pressure grid due to moved...
virtual boost::shared_ptr< Pressure > clone() const
Clone a PressureFixedLevel object.
const Unit Pa("Pa", N/(m *m))
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
Apply value function to a blitz array.
virtual void print(std::ostream &Os) const
Print to stream.
int number_variable() const
Number of variables in gradient.
virtual void calc_pressure_grid() const
Calculate the new pressure grid.
This class maintains the pressure portion of the state.
Definition: pressure.h:32
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
const T & value() const
Convert to type T.
#define REGISTER_LUA_END()
Definition: register_lua.h:134
This class maintains the pressure portion of the state.
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:08