CHROMA
remez_rat_approx.cc
Go to the documentation of this file.
1 /*! @file
2  * @brief Remez-type rational approximation
3  */
4 
6 
9 
11 
12 namespace Chroma
13 {
14 
15  //! Remez param
16  void read(XMLReader& xml, const std::string& path, RemezRatApproxEnv::Params& param)
17  {
18  RemezRatApproxEnv::Params tmp(xml, path);
19  param = tmp;
20  }
21 
22  //! Write Parameters
23  void write(XMLWriter& xml, const std::string& path, const RemezRatApproxEnv::Params& param)
24  {
25  param.writeXML(xml, path);
26  }
27 
28  //! Hooks to register the class
29  namespace RemezRatApproxEnv
30  {
31  //! Callback function
32  RationalApprox* createApprox(XMLReader& xml_in,
33  const std::string& path)
34  {
35  return new RatApprox(Params(xml_in, path));
36  }
37 
38  //! Name to be used
39  const std::string name = "REMEZ";
40 
41  //! Local registration flag
42  static bool registered = false;
43 
44  //! Register all the factories
45  bool registerAll()
46  {
47  bool success = true;
48  if (! registered)
49  {
50  success &= Chroma::TheRationalApproxFactory::Instance().registerObject(name, createApprox);
51  registered = true;
52  }
53  return success;
54  }
55 
56 
57  //! Parameters for running code
58  Params::Params(XMLReader& xml, const std::string& path)
59  {
60  XMLReader paramtop(xml, path);
61 
62  read(paramtop, "numPower", numPower);
63  read(paramtop, "denPower", denPower);
64  read(paramtop, "lowerMin", lowerMin);
65  read(paramtop, "upperMax", upperMax);
66  read(paramtop, "degree", degree);
67 
68  if (paramtop.count("digitPrecision") != 0)
69  read(paramtop, "digitPrecision", digitPrecision);
70  else
71  digitPrecision = 50;
72  }
73 
74 
75  //! Parameters for running code
76  void Params::writeXML(XMLWriter& xml, const std::string& path) const
77  {
78  push(xml, path);
79 
80  write(xml, "ratApproxType", RemezRatApproxEnv::name);
81  write(xml, "numPower", numPower);
82  write(xml, "denPower", denPower);
83  write(xml, "lowerMin", lowerMin);
84  write(xml, "upperMax", upperMax);
85  write(xml, "degree", degree);
86  write(xml, "digitPrecision", digitPrecision);
87 
88  pop(xml);
89  }
90 
91 
92  // Produce the partial-fraction-expansion (PFE) and its inverse (IPFE)
94  {
95  START_CODE();
96 
97  unsigned long prec = abs(params.digitPrecision);
98  unsigned long power_num = abs(params.numPower);
99  unsigned long power_den = abs(params.denPower);
100 
101  QDPIO::cout << "GenApprox: Numerator : " << params.numPower << " Denominator: " << params.denPower << std::endl;
102  QDPIO::cout << " Action Degree " << params.degree << std::endl;
103 
104  if (params.denPower <= 0)
105  {
106  QDPIO::cerr << name << ": invalid params" << std::endl;
107  QDP_abort(1);
108  }
109 
110  // Find approx to x^abs(params.numPower/params.denPower)
111  QDPIO::cout << "Compute partial fraction expansion" << std::endl;
112  QDPIO::cout << "Numerator Power=" << power_num << " Denominator Power=" << power_den << std::endl;
113  Remez remez(params.lowerMin, params.upperMax, prec);
114  remez.generateApprox(params.degree, power_num, power_den);
115 
116  if (params.numPower > 0)
117  {
118  // Find approx to x^(params.numPower/params.denPower)
119  QDPIO::cout << "Sign = +1" << std::endl;
120 
121  pfe = remez.getPFE();
122  ipfe = remez.getIPFE();
123  }
124  else
125  {
126  // Find approx to x^(-params.numPower/params.denPower)
127  QDPIO::cout << "Sign = -1" << std::endl;
128 
129  pfe = remez.getIPFE();
130  ipfe = remez.getPFE();
131  }
132 
133  END_CODE();
134  }
135 
136 
137  } // end namespace
138 
139 
140 } //end namespace Chroma
141 
142 
Base class for rational approximations.
Definition: rat_approx.h:19
Remez type of rational approximations.
void operator()(RemezCoeff_t &pfe, RemezCoeff_t &ipfe) const
Produce the partial-fraction-expansion (PFE) and its inverse (IPFE)
Dummy class for case when gmp is not present.
Definition: remez_stub.h:20
RemezCoeff_t getPFE()
Return the partial fraction expansion of the approximation x^(pnum/pden)
Definition: remez_stub.h:35
RemezCoeff_t getIPFE()
Return the partial fraction expansion of the approximation x^(-pnum/pden)
Definition: remez_stub.h:42
const Real generateApprox(int num_degree, int den_degree, unsigned long power_num, unsigned long power_den)
Definition: remez_stub.h:29
static T & Instance()
Definition: singleton.h:432
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
RationalApprox * createApprox(XMLReader &xml_in, const std::string &path)
Callback function.
const std::string name
Name to be used.
bool registerAll()
Register all the factories.
static bool registered
Local registration flag.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
pop(xml_out)
START_CODE()
::std::string string
Definition: gtest.h:1979
Rational approximation aggregator.
Rational approximation factories.
Redirector for Remez algorithm for finding nth roots.
Remez-type rational approximation.
Convenient structure to package Remez coeffs.
Definition: remez_coeff.h:19
Params for Remez type rational approximation.
void writeXML(XMLWriter &in, const std::string &path) const
Parameters for running code.