CHROMA
t_remez.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Test the Remez code
3  */
4 
5 #include "chroma.h"
6 
7 using namespace Chroma;
8 
9 int main(int argc, char *argv[])
10 {
11  // Put the machine into a known state
12  Chroma::initialize(&argc, &argv);
13 
14  // Setup the layout
15  const int foo[] = {2,2,2,2};
16  multi1d<int> nrow(Nd);
17  nrow = foo; // Use only Nd elements
18  Layout::setLattSize(nrow);
19  Layout::create();
20 
21  Real lower;
22  Real upper;
23  long prec;
24  int degree;
25  long power_num;
26  long power_den;
27  Real maxerr;
28 
29  XMLReader xml_in(Chroma::getXMLInputFileName());
30  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
31 
32  try {
33  XMLReader paramtop(xml_in, "/Remez");
34  read(paramtop, "lowerMin", lower);
35  read(paramtop, "upperMax", upper);
36  read(paramtop, "numPower", power_num);
37  read(paramtop, "denPower", power_den);
38  read(paramtop, "degree", degree);
39 
40  if( paramtop.count("prec") == 1 ) {
41  read(paramtop, "prec", prec);
42  }
43  else {
44  prec=80;
45  }
46 
47  push(xml_out, "RationalApprox");
48  write(xml_out, "ratApproxType", "READ_COEFFS");
49 
50  proginfo(xml_out); // basic program info
51  push(xml_out, "Param");
52  xml_out << paramtop;
53  pop(xml_out);
54 
55  }
56  catch(const std::string& s) {
57  QDPIO::cout << "Caught Exception reading parameters: " << s << std::endl;
58  QDP_abort(1);
59  }
60  catch(...) {
61  QDPIO::cout << "Caught unknown exception while processing input " << std::endl;
62  QDP_abort(1);
63  }
64 
65  bool invertP;
66 
67  long multmp = power_num*power_den;
68  if( multmp > 0 ) {
69  invertP = false;
70  QDPIO::cout << "Either both num and den powers are + or both are -" << std::endl;
71  }
72  else {
73  invertP = true;
74  QDPIO::cout << "One of num or den powers is -" << std::endl;
75  }
76 
77  unsigned long pn = power_num > 0 ? power_num : -power_num ;
78  unsigned long pd = power_den > 0 ? power_den : -power_den ;
79 
80 
81  Remez remez(lower, upper, prec);
82  Real error;
83  error=remez.generateApprox(degree, pn, pd);
84 
85  QDPIO::cout << "Start getPFE" << std::endl;
86  RemezCoeff_t pfe;
87 
88  if( ! invertP ) {
89  pfe = remez.getPFE();
90  }
91  else {
92  pfe = remez.getIPFE();
93  }
94 
95  QDPIO::cout << "Finished getPFE" << std::endl;
96 
97  push(xml_out, "ApproxInfo");
98  write(xml_out, "lowerMin", lower);
99  write(xml_out, "upperMax", upper);
100  write(xml_out, "degree", degree);
101  write(xml_out, "error", error);
102  pop(xml_out);
103 
104  push(xml_out, "PFECoeffs");
105  write(xml_out, "norm", pfe.norm);
106  write(xml_out, "res", pfe.res);
107  write(xml_out, "pole", pfe.pole);
108  pop(xml_out);
109 
110  QDPIO::cout << "Start getIPFE" << std::endl;
111  RemezCoeff_t ipfe;
112 
113  if( !invertP ) {
114  ipfe = remez.getIPFE();
115  }
116  else {
117  ipfe = remez.getPFE();
118  }
119  QDPIO::cout << "Finished getIPFE" << std::endl;
120 
121  push(xml_out, "IPFECoeffs");
122  write(xml_out, "norm", ipfe.norm);
123  write(xml_out, "res", ipfe.res);
124  write(xml_out, "pole", ipfe.pole);
125  pop(xml_out);
126 
127  pop(xml_out);
128 
129  QDPIO::cout << "Approximation with degree " << degree << " has maximum error=" << error << std::endl;
130 
131 
132  // Time to bolt
134 
135  exit(0);
136 }
Primary include file for CHROMA in application codes.
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
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.
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
Definition: chroma_init.cc:114
void finalize(void)
Chroma finalization routine.
Definition: chroma_init.cc:308
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
pop(xml_out)
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
multi1d< LatticeFermion > s(Ncb)
::std::string string
Definition: gtest.h:1979
Convenient structure to package Remez coeffs.
Definition: remez_coeff.h:19
multi1d< Real > pole
Definition: remez_coeff.h:21
multi1d< Real > res
Definition: remez_coeff.h:20
int main(int argc, char *argv[])
Definition: t_remez.cc:9