Phase.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2004-2009 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/MEAL/MEAL/Phase.h
10 
11 #ifndef __MEAL_Phase_H
12 #define __MEAL_Phase_H
13 
14 #include "MEAL/OneParameter.h"
15 #include <complex>
16 
17 namespace MEAL
18 {
20  template<typename Parent>
21  class Phase : public Parent
22  {
23 
24  public:
25 
27  Phase (double _scale = 1.0) : parameter (this)
28  { parameter.set_name ("phase"); scale = _scale; }
29 
30  // ///////////////////////////////////////////////////////////////////
31  //
32  // Function implementation
33  //
34  // ///////////////////////////////////////////////////////////////////
35 
37  std::string get_name () const
38  { return "Phase<" + std::string(Parent::Name) + ">"; }
39 
40  protected:
41 
42  typedef typename Parent::Result Return;
43 
45  void calculate (Return& result, std::vector<Return>* gradient);
46 
47  OneParameter parameter;
48  double scale;
49  };
50 
51 }
52 
54 template<typename Parent>
55 void MEAL::Phase<Parent>::calculate (Return& result, std::vector<Return>* grad)
56 {
57  double phase = this->get_param(0);
58 
59  double cos_phase = cos(scale * phase);
60  double sin_phase = sin(scale * phase);
61 
63  std::cerr << get_name () << "::calculate scale=" << scale
64  << " phase=" << phase*180/M_PI << " deg"
65  << " cos=" << cos_phase << " sin=" << sin_phase << std::endl;
66 
67  result = std::complex<double>(cos_phase, sin_phase);
68 
69  if (grad)
70  {
71  (*grad)[0] = scale * std::complex<double>(-sin_phase, cos_phase);
72 
74  std::cerr << "MEAL::Phase<Parent>::calculate gradient" << std::endl
75  << " " << (*grad)[0] << std::endl;
76  }
77 }
78 
79 #endif
Abstract base class implements parameter storage and access.
Definition: OneParameter.h:26
void set_name(const std::string &_name)
Set the name of the parameter.
Definition: OneParameter.h:54
const ScalarMath sin(const ScalarMath &x)
Return a ScalarMath instance representing sin(x)
Definition: ScalarMath.C:160
void calculate(Return &result, std::vector< Return > *gradient)
Calculate the result and its gradient.
Definition: Phase.h:55
Namespace in which all modeling and calibration related code is declared.
Definition: ExampleComplex2.h:16
static bool verbose
Verbosity flag.
Definition: Function.h:54
const ScalarMath cos(const ScalarMath &x)
Return a ScalarMath instance representing cos(x)
Definition: ScalarMath.C:168
Phase(double _scale=1.0)
Default constructor.
Definition: Phase.h:37
std::string get_name() const
Return the name of the class.
Definition: Phase.h:47

Generated using doxygen 1.8.17