gjquad_cli.py
Go to the documentation of this file.
1 # BEGIN_HEADER
2 # -----------------------------------------------------------------------------
3 # Gauss-Jacobi Quadrature Implementation
4 # Authors: Rohit Goswami <rgoswami[at]ieee.org>
5 # Source: GaussJacobiQuad Library
6 # License: MIT
7 # GitHub Repository: https://github.com/HaoZeke/GaussJacobiQuad
8 # Date: 2023-08-28
9 # Commit: c442f77
10 # -----------------------------------------------------------------------------
11 # This code is part of the GaussJacobiQuad library, providing an efficient
12 # implementation for Gauss-Jacobi quadrature nodes and weights computation.
13 # -----------------------------------------------------------------------------
14 # To cite this software:
15 # Rohit Goswami (2023). HaoZeke/GaussJacobiQuad: v0.1.0.
16 # Zenodo: https://doi.org/10.5281/ZENODO.8285112
17 # ---------------------------------------------------------------------
18 # END_HEADER
19 """!
20 @brief This script computes Gauss-Jacobi quadrature roots and weights using
21 GaussJacobiQuadPy.
22 
23 @details
24 The script takes polynomial degree, alpha, beta, and method parameters to
25 compute Gauss-Jacobi quadrature roots and weights. It calls the GaussJacobiQuad
26 library for the calculations.
27 
28 @author Rohit Goswami
29 @date 26-08-2023
30 """
31 import argparse
32 
33 import gjquadpy
34 
35 
36 def main(n, alpha, beta, meth):
37  if meth == "rec":
38  roots, weights = gjquadpy.gaussjacobiquadccompat.gauss_jacobi_rec_c(
39  n, alpha, beta
40  )
41  elif meth == "gw":
42  roots, weights = gjquadpy.gaussjacobiquadccompat.gauss_jacobi_gw_c(
43  n, alpha, beta
44  )
45  elif meth == "algo665":
46  roots, weights = gjquadpy.gaussjacobiquadccompat.gauss_jacobi_algo665_c(
47  n, alpha, beta
48  )
49  # print(f"method: {meth}, npts: {n}, alpha: {alpha}, beta: {beta}, range: [-1, 1]")
50  for idx, root in enumerate(roots):
51  sign = " " if root >= 0 else ""
52  root_str = f"{root:23.17E}"
53  weight_str = f"{weights[idx]:23.17E}"
54  print(f"Root:{sign} {root_str} Weight: {weight_str}")
55 
56 
57 if __name__ == "__main__":
58  parser = argparse.ArgumentParser(
59  description="Compute Gauss-Jacobi quadrature via GaussJacobiQuad."
60  )
61  parser.add_argument("--npts", type=int, default=5, help="Degree of the polynomial.")
62  parser.add_argument("--alpha", type=float, default=0, help="Alpha parameter.")
63  parser.add_argument("--beta", type=float, default=12, help="Beta parameter.")
64  parser.add_argument(
65  "--meth",
66  type=str,
67  default="gw",
68  help="Method.",
69  choices=["gw", "rec", "algo665"],
70  )
71 
72  args = parser.parse_args()
73 
74  main(args.npts, args.alpha, args.beta, args.meth)
def main(n, alpha, beta, meth)
Definition: gjquad_cli.py:36