ReFRACtor
array_ad_with_unit.h
Go to the documentation of this file.
1 #ifndef ARRAY_AD_WITH_UNIT_H
2 #define ARRAY_AD_WITH_UNIT_H
3 #include "array_ad.h"
5 #include "unit.h"
6 
7 namespace FullPhysics {
8 /****************************************************************/
14 template<class T, int D> class ArrayAdWithUnit
15 {
16 public:
18  ArrayAdWithUnit(const ArrayAd<T, D>& V, const Unit& U)
19  : value(V), units(U) {}
20  ArrayAdWithUnit(const ArrayAd<T, D>& V, const std::string& U)
21  : value(V), units(U) {}
23  : value(V), units(units::dimensionless) {}
26 
27 //-----------------------------------------------------------------------
29 //-----------------------------------------------------------------------
30 
31  inline ArrayAdWithUnit<T, D> convert(const Unit& R) const
32  { ArrayAd<T, D> res(value.copy());
33  double c = FullPhysics::conversion(units, R);
34  res.value() *= c;
35  res.jacobian() *= c;
36  return ArrayAdWithUnit<T, D>(res, R);
37  }
39  { return AutoDerivativeWithUnit<T>(value(i1), units); }
40  AutoDerivativeWithUnit<T> operator()(int i1, int i2) const
41  { return AutoDerivativeWithUnit<T>(value(i1, i2), units); }
42  AutoDerivativeWithUnit<T> operator()(int i1, int i2, int i3) const
43  { return AutoDerivativeWithUnit<T>(value(i1, i2, i3), units); }
44  AutoDerivativeWithUnit<T> operator()(int i1, int i2, int i3, int i4) const
45  { return AutoDerivativeWithUnit<T>(value(i1, i2, i3, i4), units); }
46  AutoDerivativeWithUnit<T> operator()(int i1, int i2, int i3, int i4,
47  int i5) const
48  { return AutoDerivativeWithUnit<T>(value(i1, i2, i3, i4, i5), units); }
49  int rows() const {return value.rows();}
50  int cols() const {return value.cols();}
51  int depth() const {return value.depth();}
52  bool is_constant() const {return value.is_constant();}
53  int number_variable() const {return value.number_variable(); }
55  {
56  value.reference(V.value);
57  units = V.units;
58  }
59 };
60 }
61 #endif
ArrayAdWithUnit< T, D > convert(const Unit &R) const
Convert to the given units.
AutoDerivativeWithUnit< T > operator()(int i1, int i2, int i3) const
int cols() const
Definition: array_ad.h:369
ArrayAdWithUnit(const ArrayAd< T, D > &V)
bool is_constant() const
Definition: array_ad.h:371
int depth() const
Definition: array_ad.h:370
This is a AutoDerivative that also has units associated with it.
AutoDerivativeWithUnit< T > operator()(int i1, int i2) const
AutoDerivativeWithUnit< T > operator()(int i1) const
AutoDerivativeWithUnit< T > operator()(int i1, int i2, int i3, int i4) const
const Unit dimensionless("dimensionless", 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
double conversion(const Unit &Dunit_from, const Unit &Dunit_to)
Return conversion factor to go from one unit to another.
Definition: unit.cc:180
void reference(const ArrayAdWithUnit< T, D > &V)
const blitz::Array< T, D+1 > jacobian() const
Definition: array_ad.h:307
This is a ArrayAd that also has units associated with it.
ArrayAdWithUnit(const ArrayAd< T, D > &V, const Unit &U)
The AutoDerivative<T> works well, and it works with blitz if you create a blitz::Array<AutoDerivative...
Definition: array_ad.h:40
ArrayAd< T, D > copy() const
Definition: array_ad.h:374
AutoDerivativeWithUnit< T > operator()(int i1, int i2, int i3, int i4, int i5) const
ArrayAdWithUnit(const ArrayAd< T, D > &V, const std::string &U)
int number_variable() const
Definition: array_ad.h:376
void reference(const ArrayAd< T, D > &V)
Definition: array_ad.h:372
Libraries such as boost::units allow unit handling where we know the units at compile time...
Definition: unit.h:25
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
int rows() const
Definition: array_ad.h:368

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