Skip to content

Commit 59ffce8

Browse files
initialise potential map from atom type pairs
1 parent ffac161 commit 59ffce8

4 files changed

Lines changed: 59 additions & 17 deletions

File tree

src/classes/potentialMap.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,49 @@ bool PotentialMap::initialise(const std::vector<const AtomType*>& masterAtomType
103103
return true;
104104
}
105105

106+
bool PotentialMap::initialise(const std::vector<const AtomType *> &masterAtomTypes,
107+
const DoubleKeyedMap<PairPotential*> &pairPotentials, double pairPotentialRange)
108+
{
109+
// Clear old data first
110+
clear();
111+
112+
// Create PairPotential matrix
113+
nTypes_ = masterAtomTypes.size();
114+
potentialMatrix_.initialise(nTypes_, nTypes_);
115+
116+
dissolve::for_each_pair(
117+
ParallelPolicies::seq, masterAtomTypes,
118+
[&](int i, const auto &atI, int j, const auto &atJ)
119+
{
120+
if (i == -1)
121+
return Messenger::error("Couldn't find AtomType '{}' in typeIndex.\n", atI->name());
122+
if (j == -1)
123+
return Messenger::error("Couldn't find AtomType '{}' in typeIndex.\n", atJ->name());
124+
125+
auto pp = pairPotentials.get({atI->name(), atJ->name()});
126+
127+
// Store PairPotential pointer
128+
if (i == j)
129+
{
130+
Messenger::print("Linking self-interaction PairPotential for '{}' (index {},{} in matrix).\n", atI->name(), i,
131+
j);
132+
potentialMatrix_[{i, j}] = pp;
133+
}
134+
else
135+
{
136+
Messenger::print("Linking PairPotential between '{}' and '{}' (indices {},{} and {},{} in matrix).\n",
137+
atI->name(), atJ->name(), i, j, j, i);
138+
potentialMatrix_[{i, j}] = pp;
139+
potentialMatrix_[{j, i}] = pp;
140+
}
141+
});
142+
143+
// Store potential range
144+
range_ = pairPotentialRange;
145+
146+
return true;
147+
}
148+
106149
// Return PairPotential range
107150
double PotentialMap::range() const { return range_; }
108151

src/classes/potentialMap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "classes/pairPotential.h"
77
#include "templates/array2D.h"
8+
#include "templates/doubleKeyedMap.h"
89

910
// Forward Declarations
1011
class Atom;
@@ -37,6 +38,8 @@ class PotentialMap
3738
const std::vector<PairPotential::Definition> &pairPotentials, double pairPotentialRange);
3839
bool initialise(const std::vector<const AtomType *> &atomTypes,
3940
const std::vector<PairPotential::Definition> &pairPotentials, double pairPotentialRange);
41+
bool initialise(const std::vector<const AtomType *> &atomTypes,
42+
const DoubleKeyedMap<PairPotential*> &pairPotentials, double pairPotentialRange);
4043
// Return PairPotential range
4144
double range() const;
4245

src/nodes/dissolve.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,15 @@ std::string_view DissolveGraph::summary() const { return "Parent node of all sim
2222
// Return dissolve
2323
Dissolve &DissolveGraph::dissolve() const { return dissolve_; }
2424

25+
// Return pair potential store
26+
const DoubleKeyedMap<PairPotential*> &DissolveGraph::pairPotentialStore() { return pairPotentialStore_; }
27+
2528
/*
2629
* Functions
2730
*/
2831

2932
// Return maximum distance for tabulated PairPotentials
30-
double DissolveGraph::pairPotentialRange() { return pairPotentialRange_; }
31-
32-
// Return first PairPotential in list
33-
const std::vector<PairPotential::Definition> &DissolveGraph::pairPotentials()
34-
{
35-
auto values = std::views::values(pairPotentialStore_.map());
36-
return {values.begin(), values.end()};
37-
}
33+
const double DissolveGraph::pairPotentialRange() const { return pairPotentialRange_; }
3834

3935
// Return energy kernel containing potential map
4036
std::unique_ptr<EnergyKernel> DissolveGraph::prepareEnergyCalculation(Configuration *cfg, std::optional<double> energyCutoff)
@@ -44,9 +40,7 @@ std::unique_ptr<EnergyKernel> DissolveGraph::prepareEnergyCalculation(Configurat
4440

4541
// Generate configuration potential map
4642
PotentialMap potentialMap;
47-
auto atomTypeKeys = std::views::keys(cfg->atomTypeIndexMap());
48-
std::vector<const AtomType *> atomTypes{atomTypeKeys.begin(), atomTypeKeys.end()};
49-
potentialMap.initialise(atomTypes, pairPotentials(), pairPotentialRange());
43+
potentialMap.initialise(cfg->atomTypeVector(), pairPotentialStore(), pairPotentialRange());
5044

5145
// Regenerate cells
5246
cfg->cells().generate(cfg->box(), cfg->requestedCellDivisionLength(), potentialMap.range());
@@ -61,7 +55,9 @@ void DissolveGraph::updatePairPotentials(const AtomType &i, const AtomType &j)
6155
if (pairPotentialStore_.contains(nameI, nameJ))
6256
return;
6357

58+
auto interactionPotential = ShortRangeFunctions::combine(i.interactionPotential(), j.interactionPotential());
6459
pairPotentialStore_.set(
6560
nameI, nameJ,
66-
{std::make_shared<AtomType>(i), std::make_shared<AtomType>(j), std::make_unique<PairPotential>(nameI, nameJ)});
61+
interactionPotential.has_value() ? new PairPotential(nameI, nameJ, *interactionPotential) : new PairPotential(nameI, nameJ)
62+
);
6763
}

src/nodes/dissolve.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ class DissolveGraph : public Graph
3636
// Dissolve reference
3737
Dissolve &dissolve_;
3838
// Pair potential store
39-
DoubleKeyedMap<PairPotential::Definition> pairPotentialStore_{true};
39+
DoubleKeyedMap<PairPotential*> pairPotentialStore_{true};
4040
// Pair potential range
4141
double pairPotentialRange_{0.0};
4242

4343
public:
4444
// Return dissolve
45-
Dissolve &dissolve() const override;
45+
Dissolve &dissolve() const;
46+
// Return pair potential store
47+
const DoubleKeyedMap<PairPotential*> &pairPotentialStore();
4648

4749
/*
4850
* Functions
4951
*/
5052
public:
5153
// Return maximum distance for tabulated PairPotentials
52-
double pairPotentialRange();
53-
// Return first PairPotential in list
54-
const std::vector<PairPotential::Definition> &pairPotentials();
54+
const double pairPotentialRange() const;
5555
// Return energy kernel containing potential map
5656
std::unique_ptr<EnergyKernel> prepareEnergyCalculation(Configuration *cfg, std::optional<double> energyCutoff = {});
5757
// Update pair potential store

0 commit comments

Comments
 (0)