ReFRACtor
scattering_moment_interpolator.h
Go to the documentation of this file.
1 #ifndef SCATTER_MOMENT_INTERPOLATOR_H
2 #define SCATTER_MOMENT_INTERPOLATOR_H
3 #include <blitz/array.h>
4 #include <boost/shared_ptr.hpp>
5 #include "auto_derivative.h"
6 
7 namespace FullPhysics {
8 /****************************************************************/
19 public:
20 //-----------------------------------------------------------------------
23 //-----------------------------------------------------------------------
25  const blitz::Array<double, 2>& Pf_mom1,
26  double Wn2,
27  const blitz::Array<double, 2>& Pf_mom2)
28  : wn0(Wn1), pf0(Pf_mom1), delta_pf0((Pf_mom2 - Pf_mom1)/(Wn2 - Wn1))
29  {
30  range_max_check(Wn1, Wn2);
31  }
32 //-----------------------------------------------------------------------
39 //-----------------------------------------------------------------------
40 
41  blitz::Array<double, 2>
42  operator()(double wn, int nummom = -1, int numscat = -1) const
43  {
44  using namespace blitz;
45  Range r1, r2;
46  Range ra(Range::all());
47  int s2;
48  if(nummom == -1 || nummom - 1> pf0.rows())
49  r1 = Range(0, pf0.rows() - 1);
50  else
51  r1 = Range(0, nummom);
52  if(numscat == -1 || numscat > pf0.cols()) {
53  r2 = ra;
54  s2 = pf0.cols();
55  } else {
56  r2 = Range(0, numscat - 1);
57  s2 = numscat;
58  }
59  int s1 = (nummom == -1 ? pf0.rows() : nummom + 1);
60  Array<double, 2> res(s1, s2);
61  if(nummom - 1 > pf0.rows())
62  res = 0;
63  res(r1, ra) = pf0(r1, r2) + delta_pf0(r1, r2) * (wn - wn0);
64  return res;
65  }
66 private:
67  double wn0;
68  blitz::Array<double, 2> pf0;
69  blitz::Array<double, 2> delta_pf0;
70 };
71 
73 public:
74  template<class I1, class I2> ScatteringMomentInterpolate(I1 xstart, I1 xend,
75  I2 ystart)
76  {
77  while(xstart != xend) {
78  double x0 = *xstart++;
79  const blitz::Array<double, 2>& y0 = *ystart++;
80  if(xstart == xend)
81  return;
82  double x1 = *xstart;
83  const blitz::Array<double, 2>& y1 = *ystart;
84  if(x1 <= x0)
85  throw Exception("X needs to be sorted");
87  (new ScatteringMomentInterpolate2Point(x0, y0, x1, y1));
88  }
89  }
90  blitz::Array<double, 2>
91  operator()(double x, int nummom = -1, int nscatt = -1) const
92  {
93  typedef
94  std::map<double, boost::shared_ptr<ScatteringMomentInterpolate2Point> >::const_iterator Itype;
95  Itype i = inter.lower_bound(x);
96  if(i == inter.end()) // If we are past the upper end,
97  // then extrapolate
98  return (*inter.rbegin()->second)(x, nummom, nscatt);
99  else
100  return (*i->second)(x, nummom, nscatt);
101  }
102 private:
103  std::map<double, boost::shared_ptr<ScatteringMomentInterpolate2Point> > inter;
104 };
105 
106 }
107 #endif
#define range_max_check(V, Max)
Range check.
Definition: fp_exception.h:194
blitz::Array< double, 2 > operator()(double wn, int nummom=-1, int numscat=-1) const
Interpolate the data to give the phase function scattering moments for the given wave number...
ScatteringMomentInterpolate2Point(double Wn1, const blitz::Array< double, 2 > &Pf_mom1, double Wn2, const blitz::Array< double, 2 > &Pf_mom2)
Constructor, this takes the two wave numbers and scattering matrices to interpolate.
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
Apply value function to a blitz array.
The calculation of the phase function scattering matrix moments is fairly expensive.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
blitz::Array< double, 2 > operator()(double x, int nummom=-1, int nscatt=-1) const
ScatteringMomentInterpolate(I1 xstart, I1 xend, I2 ystart)

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