Skip to content

Commit 0afaae3

Browse files
author
Martin D. Weinberg
committed
More dimensioning consistency fixes
1 parent 4243529 commit 0afaae3

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

expui/BiorthBasis.cc

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,24 @@ namespace BasisClasses
294294
for (auto & v : dpt2) v.resize(lmax+1, nmax);
295295
for (auto & v : dend) v.resize(lmax+1, nmax);
296296

297+
// Wasteful but simple factorial table. Could be done with a
298+
// triangular indexing scheme...
299+
//
297300
for (auto & v : legs ) v.resize(lmax+1, lmax+1);
298301
for (auto & v : dlegs ) v.resize(lmax+1, lmax+1);
299302
for (auto & v : d2legs) v.resize(lmax+1, lmax+1);
300303

301-
expcoef.resize((lmax+1)*(lmax+2)/2, nmax);
304+
// Allocate coefficient storage; stores real and imaginary parts as reals
305+
//
306+
expcoef.resize((lmax+1)*(lmax+1), nmax);
302307
expcoef.setZero();
303308

304309
work.resize(nmax);
305310

306-
factorial.resize(lmax+1, lmax+1); // Wasteful but simple
311+
// Wasteful but simple factorial table. Could be done with a
312+
// triangular indexing scheme...
313+
//
314+
factorial.resize(lmax+1, lmax+1);
307315

308316
for (int l=0; l<=lmax; l++) {
309317
for (int m=0; m<=l; m++) {
@@ -327,6 +335,7 @@ namespace BasisClasses
327335
void Spherical::init_covariance()
328336
{
329337
if (pcavar) {
338+
// Triangular for l,m>=0
330339
int Ltot = (lmax+1)*(lmax+2)/2;
331340

332341
meanV.resize(sampT);
@@ -472,7 +481,7 @@ namespace BasisClasses
472481
cf->time = time;
473482
cf->normed = true;
474483

475-
// Angular storage dimension
484+
// Angular storage dimension; triangular number for complex coefs
476485
int ldim = (lmax+1)*(lmax+2)/2;
477486

478487
// Allocate the coefficient storage
@@ -594,13 +603,13 @@ namespace BasisClasses
594603
}
595604

596605
// L loop
597-
for (int l=0, loffset=0; l<=lmax; loffset+=(2*l+1), l++) {
606+
for (int l=0, loffset=0, L=0; l<=lmax; loffset+=(2*l+1), l++) {
598607

599608
Eigen::VectorXd workE;
600609
int esize = (l+1)*nmax;
601610

602611
// M loop
603-
for (int m=0, moffset=0, moffE=0; m<=l; m++) {
612+
for (int m=0, moffset=0, moffE=0; m<=l; m++, L++) {
604613

605614
if (m==0) {
606615
fac = factorial(l, m) * legs[tid](l, m);
@@ -609,9 +618,9 @@ namespace BasisClasses
609618
expcoef(loffset+moffset, n) += fac4 * norm * mass;
610619

611620
if (pcavar) {
612-
meanV[T][loffset+moffset](n) += fac4 * norm * mass;
621+
meanV[T][L](n) += fac4 * norm * mass;
613622
for (int o=0; o<nmax; o++)
614-
covrV[T][loffset+moffset](n, o) += fac4 * norm *
623+
covrV[T][L](n, o) += fac4 * norm *
615624
fac * potd[tid](l, o) * norm * mass;
616625
}
617626
}
@@ -628,9 +637,9 @@ namespace BasisClasses
628637
expcoef(loffset+moffset+1, n) += fac2 * fac4 * norm * mass;
629638

630639
if (pcavar) {
631-
meanV[T][loffset+moffset](n) += fac * fac4 * norm * mass;
640+
meanV[T][L](n) += fac * fac4 * norm * mass;
632641
for (int o=0; o<nmax; o++)
633-
covrV[T][loffset+moffset](n, o) += fac * fac4 * norm *
642+
covrV[T][L](n, o) += fac * fac4 * norm *
634643
fac * potd[tid](l, o) * norm * mass;
635644
}
636645
}
@@ -647,7 +656,8 @@ namespace BasisClasses
647656
// MPI reduction of coefficients
648657
if (use_mpi) {
649658

650-
int Ltot = (lmax+1)*(lmax+2)/2;
659+
// Square of total number of angular coefficients in real form
660+
int Ltot = (lmax+1)*(lmax+1);
651661

652662
MPI_Allreduce(MPI_IN_PLACE, &used, 1, MPI_INT,
653663
MPI_SUM, MPI_COMM_WORLD);
@@ -661,6 +671,9 @@ namespace BasisClasses
661671

662672
if (pcavar) {
663673

674+
// Triangular number of angular coefficients in complex from
675+
int ltot = (lmax+1)*(lmax+2)/2;
676+
664677
MPI_Allreduce(MPI_IN_PLACE, sampleCounts.data(), sampleCounts.size(),
665678
MPI_INT, MPI_SUM, MPI_COMM_WORLD);
666679

@@ -669,7 +682,7 @@ namespace BasisClasses
669682

670683
for (int T=0; T<sampT; T++) {
671684

672-
for (int l=0; l<Ltot; l++) {
685+
for (int l=0; l<ltot; l++) {
673686

674687
MPI_Allreduce(MPI_IN_PLACE, meanV[T][l].data(), meanV[T][l].size(),
675688
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
@@ -4903,7 +4916,7 @@ namespace BasisClasses
49034916
// Check for version string
49044917
std::string path = "CovarianceFileVersion";
49054918

4906-
// If exists, use extension method
4919+
// Check for valid HDF file
49074920
if (file.exist(path)) {
49084921
extendCoefCovariance(fname, time);
49094922
return;

0 commit comments

Comments
 (0)