-
Notifications
You must be signed in to change notification settings - Fork 31
/
system.cpp
78 lines (64 loc) · 2.15 KB
/
system.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <memory>
#include <cassert>
#include "system.h"
#include "sampler.h"
#include "particle.h"
#include "WaveFunctions/wavefunction.h"
#include "Hamiltonians/hamiltonian.h"
#include "InitialStates/initialstate.h"
#include "Solvers/montecarlo.h"
System::System(
std::unique_ptr<class Hamiltonian> hamiltonian,
std::unique_ptr<class WaveFunction> waveFunction,
std::unique_ptr<class MonteCarlo> solver,
std::vector<std::unique_ptr<class Particle>> particles)
{
m_numberOfParticles = particles.size();;
m_numberOfDimensions = particles[0]->getNumberOfDimensions();
m_hamiltonian = std::move(hamiltonian);
m_waveFunction = std::move(waveFunction);
m_solver = std::move(solver);
m_particles = std::move(particles);
}
unsigned int System::runEquilibrationSteps(
double stepLength,
unsigned int numberOfEquilibrationSteps)
{
unsigned int acceptedSteps = 0;
for (unsigned int i = 0; i < numberOfEquilibrationSteps; i++) {
acceptedSteps += m_solver->step(stepLength, *m_waveFunction, m_particles);
}
return acceptedSteps;
}
std::unique_ptr<class Sampler> System::runMetropolisSteps(
double stepLength,
unsigned int numberOfMetropolisSteps)
{
auto sampler = std::make_unique<Sampler>(
m_numberOfParticles,
m_numberOfDimensions,
stepLength,
numberOfMetropolisSteps);
for (unsigned int i = 0; i < numberOfMetropolisSteps; i++) {
/* Call solver method to do a single Monte-Carlo step.
*/
bool acceptedStep = m_solver->step(stepLength, *m_waveFunction, m_particles);
/* Here you should sample the energy (and maybe other things) using the
* sampler instance of the Sampler class.
*/
sampler->sample(acceptedStep, this);
}
sampler->computeAverages();
return sampler;
}
double System::computeLocalEnergy()
{
// Helper function
return m_hamiltonian->computeLocalEnergy(*m_waveFunction, m_particles);
}
const std::vector<double>& System::getWaveFunctionParameters()
{
// Helper function
return m_waveFunction->getParameters();
}