oILAB
Loading...
Searching...
No Matches
CanonicalTPImplementation.h
Go to the documentation of this file.
1//
2// Created by Nikhil Chandra Admal on 8/14/24.
3//
4#ifndef OILAB_CANONICALTPIMPLEMENTATION_H
5#define OILAB_CANONICALTPIMPLEMENTATION_H
6
7#include <algorithm>
8#include "../Lattices/OrderedTuplet.h"
9
10namespace oILAB {
11
12template <typename StateType, typename SystemType>
14 const std::string &lmpLocation, const std::string &potentialName,
15 const double &temperature, const std::string &filename)
16 : lmpLocation(lmpLocation), potentialName(potentialName),
17 temperature(temperature), countTP(0) {
18 if (!filename.empty())
19 output.open(filename);
20 }
21
22 template<typename StateType, typename SystemType>
23 double CanonicalTP<StateType,SystemType>::probability(const std::pair<StateType,SystemType>& proposedStateSystem,
24 const std::pair<StateType,SystemType>& currentStateSystem)
25 {
26 // calculate energies here
27 const auto& currentState= currentStateSystem.first;
28 const auto& currentSystem= currentStateSystem.second;
29 const auto& proposedState= proposedStateSystem.first;
30 const auto& proposedSystem= proposedStateSystem.second;
31
32 if(countTP==0) {
33 const auto &temp = currentSystem.densityEnergy(lmpLocation, potentialName, false);
34 currentDensity = std::get<0>(temp);
35 currentEnergy = std::get<1>(temp);
36 stateEnergyMap[currentState] = currentEnergy;
37 //std::cout << "density = " << currentDensity << ", energy = " << currentEnergy << std::endl;
38 }
39 else {
40 assert(stateEnergyMap.find(currentState) != stateEnergyMap.end());
41 currentEnergy= stateEnergyMap[currentState];
42 }
43
44 double proposedEnergy, proposedDensity;
45
46 //StateType proposedState(proposedStateSystemPair.first);
47 //SystemType proposedSystem(proposedStateSystemPair.second);
48 if (stateEnergyMap.find(proposedState) != stateEnergyMap.end()) {
49 proposedEnergy = stateEnergyMap.at(proposedState);
50 }
51 else {
52 const auto& temp= proposedSystem.densityEnergy(lmpLocation, potentialName, false);
53 proposedDensity= std::get<0>(temp);
54 proposedEnergy= std::get<1>(temp);
55 //proposedEnergy = proposedSystem.energy();
56 //std::cout << "density = " << proposedDensity << ", energy = " << proposedEnergy << std::endl;
57 stateEnergyMap[proposedState] = proposedEnergy;
58 }
59
60 countTP++;
61 double delta = proposedEnergy - currentEnergy;
62
63 if(output.is_open())
64 output << currentState << " " << currentState.density() << " " << currentEnergy << std::endl;
65 return std::min(1.0, exp(-delta / temperature));
66 }
67
68 } // namespace oILAB
69#endif
CanonicalTP(const std::string &lmpLocation, const std::string &potentialName, const double &temperature, const std::string &filename="")
double probability(const std::pair< StateType, SystemType > &proposedState, const std::pair< StateType, SystemType > &currentState)
std::ofstream output
Definition CanonicalTP.h:21