ReFRACtor
aerosol_shape_gaussian.cc
Go to the documentation of this file.
2 #include "ostream_pad.h"
3 
4 using namespace FullPhysics;
5 using namespace blitz;
6 
7 #ifdef HAVE_LUA
8 #include "register_lua.h"
10 .def(luabind::constructor<const boost::shared_ptr<Pressure>&,
11  const blitz::Array<bool, 1>&,
12  const blitz::Array<double, 1>&,
13  const std::string&,
14  const bool&>())
16 #endif
17 
18 const double AerosolShapeGaussian::min_aod = 1e-9;
19 // See base class for description
21 (const boost::shared_ptr<Pressure>& Pres) const
22 {
24  (new AerosolShapeGaussian(Pres, used_flag, coeff.value(),
25  aerosol_name(), linear_aod));
26 }
27 
29 {
30  // Input parameters
31  AutoDerivative<double> desired_aod;
32 
33  if (linear_aod) {
34  desired_aod = coefficient()(0);
35 
36  // Don't let aod go lower than a minimum value. Not clear if this
37  // is actually what we want to do, see ticket #2252 for this
38  // suggestion. We might instead want to use a constrained solver.
39  if(desired_aod < min_aod) {
40  desired_aod = min_aod;
41  }
42  } else {
43  desired_aod = exp(coefficient()(0));
44  }
45 
46  int ngaussians = int((coefficient().rows() - 1) / 2);
47 
48  ArrayAd<double, 1> pressure_grid = pressure()->pressure_grid().value;
49  AutoDerivative<double> surface_press = pressure()->surface_pressure().value;
50 
51  aext.resize(pressure()->number_level(),
52  coeff.number_variable());
53 
54  for(int g_idx = 0; g_idx < ngaussians; g_idx++) {
55  AutoDerivative<double> p0 = coefficient()(g_idx * 2 + 1);
56  AutoDerivative<double> sigma = coefficient()(g_idx * 2 + 2);
57 
58  for(int lev = 0; lev < aext.rows(); lev++) {
59  AutoDerivative<double> p = pressure_grid(lev) / surface_press;
60  AutoDerivative<double> g_eval = exp( -1 * (p - p0) * (p - p0) / (2 * sigma * sigma) );
61 
62  // Because its not that easy to init ArrayAd from python to 0.0
63  if (g_idx == 0) {
64  aext(lev) = g_eval;
65  } else {
66  aext(lev) = aext(lev) + g_eval;
67  }
68  }
69  }
70 
71  AutoDerivative<double> scaling_N;
72 
73  // Protect against a divide by zero
74  if (total_aod().value() != 0.0) {
75  scaling_N = desired_aod / total_aod();
76  } else {
77  scaling_N = 0.0;
78  }
79 
80  for(int lev = 0; lev < aext.rows(); lev++) {
81  aext(lev) = aext(lev) * scaling_N;
82  }
83 }
84 
85 void AerosolShapeGaussian::print(std::ostream& Os) const
86 {
87  OstreamPad opad(Os, " ");
88  Os << "AerosolShapeGaussian: ("
89  << (linear_aod ? "Linear" : "Logarithmic")
90  << ")\n"
91  << " Coefficient:\n";
92  opad << coeff.value() << "\n";
93  opad.strict_sync();
94  Os << " Retrieval flag:\n";
95  opad << used_flag << "\n";
96  opad.strict_sync();
97 }
virtual void calc_aerosol_extinction() const
Derived classes should provide a function to fill in vmr when this is called.
This is a filtering stream that adds a pad to the front of every line written out.
Definition: ostream_pad.h:32
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
Apply value function to a blitz array.
const blitz::Array< T, D > & value() const
Definition: array_ad.h:306
This class maps the state vector to aerosol extinction defined by a Gaussian parameterization.
virtual void print(std::ostream &Os) const
Print to stream.
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
double value(const FullPhysics::AutoDerivative< double > &Ad)
This class maps the state vector to the aerosol extinction on each level.
virtual boost::shared_ptr< AerosolExtinction > clone() const
Clone a AerosolExtinction object.

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