Skip to content

Commit 682036d

Browse files
committed
Cache scattering factors per unique atom types.
Lower the number of calls of ScatteringFactorTable.lookup.
1 parent 10b7f5a commit 682036d

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/diffpy/srreal/PDFCalculator.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,13 +647,19 @@ void PDFCalculator::cacheStructureData()
647647
{
648648
int cntsites = this->countSites();
649649
// sfsite
650+
boost::unordered_map<string, double> fcache;
650651
mstructure_cache.sfsite.resize(cntsites);
651652
const ScatteringFactorTablePtr sftable = this->getScatteringFactorTable();
652653
for (int i = 0; i < cntsites; ++i)
653654
{
654655
const string& smbl = mstructure->siteAtomType(i);
655-
mstructure_cache.sfsite[i] = sftable->lookup(smbl) *
656-
mstructure->siteOccupancy(i);
656+
boost::unordered_map<string, double>::iterator ff = fcache.find(smbl);
657+
if (ff == fcache.end())
658+
{
659+
const double value = sftable->lookup(smbl);
660+
ff = fcache.insert(make_pair(smbl, value)).first;
661+
}
662+
mstructure_cache.sfsite[i] = ff->second * mstructure->siteOccupancy(i);
657663
}
658664
// sfaverage
659665
double totocc = mstructure->totalOccupancy();

0 commit comments

Comments
 (0)