ReFRACtor
auto_derivative_with_unit.h
Go to the documentation of this file.
1 #ifndef AUTO_DERIVATIVE_WITH_UNIT_H
2 #define AUTO_DERIVATIVE_WITH_UNIT_H
3 #include "printable.h"
4 #include "auto_derivative.h"
5 #include "double_with_unit.h"
6 #include "unit.h"
7 
8 namespace FullPhysics {
9 /****************************************************************/
15 template<class T> class AutoDerivativeWithUnit:
16  public Printable<AutoDerivativeWithUnit<T> >,
17  boost::field_operators<AutoDerivativeWithUnit<T> >
18 {
19 public:
22  : value(V), units(U) {}
23  AutoDerivativeWithUnit(const AutoDerivative<T>& V, const std::string& U)
24  : value(V), units(U) {}
26  : value(V), units(units::dimensionless) {}
28  : value(V), units(units::dimensionless) {}
30  : value(V.value), units(V.units) {}
33 
34 //-----------------------------------------------------------------------
36 //-----------------------------------------------------------------------
37 
40  { value *= D.value; units *= D.units; return *this;}
43  { value /= D.value; units /= D.units; return *this;}
46  { value += D.value * FullPhysics::conversion(D.units, units); return *this;}
49  { value -= D.value * FullPhysics::conversion(D.units, units); return *this;}
50 
51 //-----------------------------------------------------------------------
53 //-----------------------------------------------------------------------
54 
55  inline AutoDerivativeWithUnit<T> convert(const Unit& R) const
56  { return AutoDerivativeWithUnit<T>(value * FullPhysics::conversion(units, R), R); }
57 
58  void print(std::ostream& Os) const
59  { Os << value << " " << units.name(); }
60 };
61 }
62 #endif
AutoDerivativeWithUnit< T > & operator/=(const AutoDerivativeWithUnit< T > &D)
This is a AutoDerivative that also has units associated with it.
AutoDerivativeWithUnit< T > convert(const Unit &R) const
Convert to the given units.
AutoDerivativeWithUnit(const AutoDerivative< T > &V)
AutoDerivativeWithUnit< T > & operator*=(const AutoDerivativeWithUnit< T > &D)
Basic math operators for class.
AutoDerivativeWithUnit(const AutoDerivative< T > &V, const std::string &U)
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
This is a Mixin for classes that can be printed.
Definition: printable.h:24
There are a number of tools that can be used to do "Automatic Differentiation" (see for example http:...
AutoDerivativeWithUnit< T > & operator+=(const AutoDerivativeWithUnit< T > &D)
We frequently have a double with units associated with it.
Libraries such as boost::units allow unit handling where we know the units at compile time...
Definition: unit.h:25
AutoDerivativeWithUnit(const AutoDerivative< T > &V, const Unit &U)
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
const std::string & name() const
Name of unit. May be an empty string if a name wasn&#39;t assigned.
Definition: unit.h:77
AutoDerivativeWithUnit< T > & operator-=(const AutoDerivativeWithUnit< T > &D)

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