Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4LegendrePolynomial Class Reference

#include <G4LegendrePolynomial.hh>

Public Member Functions

G4double GetCoefficient (size_t i, size_t order)
 
G4double EvalLegendrePoly (G4int order, G4double x)
 
G4double EvalAssocLegendrePoly (G4int l, G4int m, G4double x)
 

Static Public Member Functions

static size_t GetNCoefficients (size_t order)
 

Protected Member Functions

void BuildUpToOrder (size_t order)
 

Protected Attributes

std::vector< std::vector
< G4double > > 
fCoefficients
 

Detailed Description

Definition at line 49 of file G4LegendrePolynomial.hh.

Member Function Documentation

void G4LegendrePolynomial::BuildUpToOrder ( size_t  order)
protected

Definition at line 102 of file G4LegendrePolynomial.cc.

103 {
104  if(orderMax > 30) {
105  G4cout << "G4LegendrePolynomial::GetCoefficient(): "
106  << "I refuse to make a Legendre Polynomial of order "
107  << orderMax << G4endl;
108  return;
109  }
110  while(fCoefficients.size() < orderMax+1) { /* Loop checking, 30-Oct-2015, G.Folger */
111  size_t order = fCoefficients.size();
112  fCoefficients.resize(order+1);
113  if(order <= 1) fCoefficients[order].push_back(1.);
114  else {
115  for(size_t iCoeff = 0; iCoeff < order+1; ++iCoeff) {
116  if((order % 2) == (iCoeff % 2)) {
117  G4double coeff = 0;
118  if(iCoeff <= order-2) coeff -= fCoefficients[order-2][iCoeff/2]*G4double(order-1);
119  if(iCoeff > 0) coeff += fCoefficients[order-1][(iCoeff-1)/2]*G4double(2*order-1);
120  coeff /= G4double(order);
121  fCoefficients[order].push_back(coeff);
122  }
123  }
124  }
125  }
126 }
std::vector< std::vector< G4double > > fCoefficients
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4double G4LegendrePolynomial::EvalAssocLegendrePoly ( G4int  l,
G4int  m,
G4double  x 
)

Definition at line 49 of file G4LegendrePolynomial.cc.

50 {
51  if(l<0 || m<-l || m>l) return 0;
52  G4Pow* g4pow = G4Pow::GetInstance();
53 
54  // Use non-log factorial, which is more efficient until l and m get
55  // above 10 or so.
56  // FIXME: G4Pow doesn't check whether the argument gets too large,
57  // which is unsafe! Max is 512; VI: It is assume that Geant4 does not
58  // need higher order
59  if(m<0) return (m%2 ? -1. : 1.) * g4pow->factorial(l+m)/g4pow->factorial(l-m)
60  * EvalAssocLegendrePoly(l, -m, x);
61 
62  // hard-code the first few orders for speed
63  if(l==0) return 1;
64  if(l==1) {
65  if(m==0) return x;
66  /*m==1*/ return -sqrt(1.-x*x);
67  }
68  if(l<5) {
69  G4double x2 = x*x;
70  if(l==2) {
71  if(m==0) return 0.5*(3.*x2 - 1.);
72  if(m==1) return -3.*x*sqrt(1.-x2);
73  /*m==2*/ return 3.*(1.-x2);
74  }
75  if(l==3) {
76  if(m==0) return 0.5*(5.*x*x2 - 3.*x);
77  if(m==1) return -1.5*(5.*x2-1.)*sqrt(1.-x2);
78  if(m==2) return 15.*x*(1.-x2);
79  /*m==3*/ return -15.*(1.-x2)*sqrt(1.-x2);
80  }
81  if(l==4) {
82  if(m==0) return 0.125*(35.*x2*x2 - 30.*x2 + 3.);
83  if(m==1) return -2.5*(7.*x*x2-3.*x)*sqrt(1.-x2);
84  if(m==2) return 7.5*(7.*x2-1.)*(1.-x2);
85  if(m==3) return -105.*x*(1.-x2)*sqrt(1.-x2);
86  /*m==4*/ return 105.*(1. - 2.*x2 + x2*x2);
87  }
88  }
89 
90  // Easy special cases
91  // FIXME: G4Pow doesn't check whether the argument gets too large, which is unsafe! Max is 512.
92  if(m==l) return (l%2 ? -1. : 1.) *
93  G4Exp(g4pow->logfactorial(2*l) - g4pow->logfactorial(l)) *
94  G4Exp(G4Log((1.-x*x)*0.25)*0.5*G4double(l));
95  if(m==l-1) return x*(2.*G4double(m)+1.)*EvalAssocLegendrePoly(m,m,x);
96 
97  // Otherwise calculate recursively
98  return (x*G4double(2*l-1)*EvalAssocLegendrePoly(l-1,m,x) -
99  (G4double(l+m-1))*EvalAssocLegendrePoly(l-2,m,x))/G4double(l-m);
100 }
static G4Pow * GetInstance()
Definition: G4Pow.cc:55
Definition: G4Pow.hh:56
tuple x
Definition: test.py:50
static constexpr double m
Definition: G4SIunits.hh:129
G4double factorial(G4int Z) const
Definition: G4Pow.hh:264
G4double G4Log(G4double x)
Definition: G4Log.hh:230
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:183
G4double EvalAssocLegendrePoly(G4int l, G4int m, G4double x)
G4double logfactorial(G4int Z) const
Definition: G4Pow.hh:269
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

G4double G4LegendrePolynomial::EvalLegendrePoly ( G4int  order,
G4double  x 
)

Definition at line 43 of file G4LegendrePolynomial.cc.

44 {
45  // Call EvalAssocLegendrePoly with m=0
46  return (EvalAssocLegendrePoly(order,0,x));
47 }
tuple x
Definition: test.py:50
G4double EvalAssocLegendrePoly(G4int l, G4int m, G4double x)
G4double G4LegendrePolynomial::GetCoefficient ( size_t  i,
size_t  order 
)

Definition at line 34 of file G4LegendrePolynomial.cc.

35 {
36  if(order >= fCoefficients.size()) BuildUpToOrder(order);
37  if(order >= fCoefficients.size() ||
38  i/2 >= fCoefficients[order].size() ||
39  (i%2) != order %2) return 0;
40  return fCoefficients[order][i/2];
41 }
std::vector< std::vector< G4double > > fCoefficients
void BuildUpToOrder(size_t order)

Here is the caller graph for this function:

static size_t G4LegendrePolynomial::GetNCoefficients ( size_t  order)
inlinestatic

Definition at line 53 of file G4LegendrePolynomial.hh.

53 { return order+1; }

Here is the caller graph for this function:

Member Data Documentation

std::vector< std::vector<G4double> > G4LegendrePolynomial::fCoefficients
protected

Definition at line 62 of file G4LegendrePolynomial.hh.


The documentation for this class was generated from the following files: