Skip to content

Commit

Permalink
Added vector version of Fortran implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeydumont committed Aug 18, 2014
1 parent fbcf227 commit 9bb8f79
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/wignerSymbols/wignerSymbols-fortran.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ extern "C"
extern void drc6j_wrap(double,double,double,double,double,double*,double*,double*,int,int*);
}

/*! Compute a string of Wigner-3j symbols for given l2,l3,m1,m2,m3. */
std::vector<double> wigner3j_f(double l2, double l3, double m1, double m2, double m3);

/*! Computes the Wigner-3j symbol for given l1,l2,l3,m1,m2,m3. We
* explicitly enforce the selection rules. */
double wigner3j_f(double l1, double l2, double l3, double m1, double m2, double m3);
Expand All @@ -60,4 +63,7 @@ inline double clebschGordan_f(double l1, double l2, double l3, double m1, double
double wigner6j_f(double l1, double l2, double l3, double l4, double l5, double l6);
}

/*! Computes a string of Wigner-6j symbols for given l2, l3, l4, l5, l6. */
std::vector<double> wigner6j_f(double l2, double l3, double l4, double l5, double l6);

#endif // WIGNER_SYMBOLS_FORTRAN_H
22 changes: 22 additions & 0 deletions src/wignerSymbols-fortran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@

namespace WignerSymbols {


/*! Computes a string of Wigner-3j symbols for given l2, l3, m1, m2, m3. */
std::vector<double> wigner3j_f(double l2, double l3, double m1, double m2, double m3)
{
// We prepare the size of the resulting array.
int size = (int)std::ceil(l2+l3-std::max(std::fabs(l2-l3),std::fabs(m1)))+1;

// We prepare the output values.
double l1min, l1max;
double thrcof [size];
int ierr;

// External function call.
drc3jj_wrap(l2,l3,m2,m3,&l1min,&l1max,thrcof,size,&ierr);

// We copy the values of the array into a vector.
std::vector<double> thrcof_v(size);
thrcof_v.assign(thrcof, thrcof + size);

return thrcof_v;
}

/*! Computes the Wigner-3j symbol for given l1,l2,l3,m1,m2,m3. We
* explicitly enforce the selection rules. */
double wigner3j_f(double l1, double l2, double l3,
Expand Down
4 changes: 4 additions & 0 deletions tests/gh-issue-2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ int main (int argc, char* argv[])
std::cout << "FOR impl.: " << test34 << ", " << test35 << ", " << test36 << std::endl;

std::vector<double> test4 = WignerSymbols::wigner3j(992, 1243, 196, -901, 705);
std::vector<double> test4_f = WignerSymbols::wigner3j_f(992, 1243, 196, -901, 705);
std::cout << test4[100] << ", " << test4_f[100] << std::endl;
double test41 = WignerSymbols::wigner3j(529, 992, 1243, 196, -901, 705);
double test42 = WignerSymbols::wigner3j_f(529, 992, 1243, 196, -901, 705);
std::cout << "C++ impl.: " << test41 << std::endl;
Expand All @@ -74,6 +76,8 @@ int main (int argc, char* argv[])
std::cout << "FOR impl.: " << test52 << std::endl;
std::cout << std::endl;

std::cout << test4[100] << ", " << test4_f[100] << std::endl;

/*
[ 841 379 1011 -631 313 318] -2.44096504011e-41 -0.0
[ 570 1007 1392 327 -933 606] -1.74376347733e-98 0.0
Expand Down

0 comments on commit 9bb8f79

Please sign in to comment.