-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSimulation.cpp
More file actions
66 lines (55 loc) · 1.78 KB
/
CSimulation.cpp
File metadata and controls
66 lines (55 loc) · 1.78 KB
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
/*
* File: CSimulation.cpp
* Author: Mark Wittekind and Drew Murray
*
* Created on March 6, 2015, 11:33 AM
*/
#include "CSimulation.h"
#include "CObject.h"
#include "SimulationParametersStruct.cpp"
CSimulation::CSimulation(SimulationParameters *SimPar) {
m_simPar = SimPar;
}
void CSimulation::addObject(CObject* obj){
m_objects.push_back(obj);
}
CSimulation::~CSimulation() {
}
float CSimulation::calcMag(){
float magTot = 0.0;
for (vector<CObject*>::iterator it2 = m_objects.begin(); it2 != m_objects.end(); it2++){
magTot += (*it2)->calcMag();
}
return magTot;
}
float CSimulation::calcEnergy(){
float enTot = 0.0;
for (vector<CObject*>::iterator it2 = m_objects.begin(); it2 != m_objects.end(); it2++){
enTot += (*it2)->calcEnergy();
}
return enTot;
}
void CSimulation::run(ostream& pos_stream, ostream& mag_stream, SimulationParameters *SimPar){
//mystery line to allow virtual functions to work as they should (this variable is never used)
//CLattice uselessvariable(m_simPar->WIDTH,m_simPar->HEIGHT);
for (vector<CObject*>::iterator it2 = m_objects.begin(); it2 != m_objects.end(); it2++){
mag_stream << m_simPar->temperature << "\n";
(*it2)->print_all(pos_stream, mag_stream, m_simPar);
}
for(unsigned int t = 0; t<m_simPar->MAXTIMESTEPS;t++)
{
for (vector<CObject*>::iterator it = m_objects.begin(); it != m_objects.end(); it++){
(*it)->update(m_simPar);
}
if((t%SimPar->PRINT_FREQ==m_simPar->PRINT_FREQ-1) || ((t+1)>=(m_simPar->MAXTIMESTEPS)))
{
cout << "printing timestep " << t << " of " << SimPar->MAXTIMESTEPS << "\n";
for (vector<CObject*>::iterator it2 = m_objects.begin(); it2 != m_objects.end(); it2++){
(*it2)->print_all(pos_stream,mag_stream, m_simPar);
}
}
}
mag_stream<<"\n";
pos_stream<<"TEMP CHANGED\n";
return;
}