-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimrun.cpp
More file actions
123 lines (105 loc) · 3.33 KB
/
simrun.cpp
File metadata and controls
123 lines (105 loc) · 3.33 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright (c) 2013, Robert Rueger <rueger@itp.uni-frankfurt.de>
*
* This file is part of YASS.
*
* YASS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* YASS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with YASS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "simrun.hpp"
#include "model.hpp"
#include <iostream>
using namespace std;
void simrun_const( const Options& opts )
{
bool verbose = opts.count( "verbose" );
cout << "-> Creating the model" << endl;
SandpileModel m( opts["size"].as<unsigned int>(), true,
opts["toppling"].as<topplemode_t>(),
opts["seed"].as<unsigned int>() );
if ( verbose ) {
cout << m << endl;
}
cout << "-> Filling to const density" << endl;
while ( m.get_density() < opts["density"].as<double>() ) {
m.add_grain();
}
if ( verbose ) {
cout << m << endl;
}
cout << "-> Topple a little bit" << endl;
for ( unsigned int i = 0; i < opts["mcs-equil"].as<unsigned int>(); ++i ) {
if ( m.topple() == false ) {
break;
}
}
if ( verbose ) {
cout << m << endl;
}
cout << "-> Measure the density of active sites while toppling" << endl;
double asd_sum = 0.f;
for ( unsigned int i = 0; i < opts["mcs-measure"].as<unsigned int>(); ++i ) {
asd_sum += m.get_active_site_density();
if ( m.topple() == false ) {
asd_sum = 0;
break;
}
}
if ( verbose ) {
cout << m << endl;
}
double asd =
asd_sum / static_cast<double>( opts["mcs-measure"].as<unsigned int>() );
cout << "-> Result:" << endl;
cout << opts["density"].as<double>() << " " << asd << endl;
}
void simrun_drop( const Options& opts )
{
bool verbose = opts.count( "verbose" );
cout << "-> Creating the model" << endl;
SandpileModel m( opts["size"].as<unsigned int>(), false,
opts["toppling"].as<topplemode_t>(),
opts["seed"].as<unsigned int>() );
if ( verbose ) {
cout << m << endl;
}
cout << "-> Add grain + topple to equilibrate" << endl;
for ( unsigned int s = 0; s < opts["mcs-equil"].as<unsigned int>(); ++s ) {
for ( unsigned int i = 0; i < m.get_num_sites(); ++i ) {
m.add_grain();
while ( m.topple() == true ) { };
}
}
cout << "Density after equilibration: " << m.get_density() << endl;
if ( verbose ) {
cout << m << endl;
}
cout << "-> Add grain + topple to measure the density" << endl;
double dens_sum = 0.f;
for ( unsigned int s = 0; s < opts["mcs-measure"].as<unsigned int>(); ++s ) {
for ( unsigned int i = 0; i < m.get_num_sites(); ++i ) {
m.add_grain();
while ( m.topple() == true ) { };
dens_sum += m.get_density();
}
}
if ( verbose ) {
cout << m << endl;
}
double dens
= dens_sum / static_cast<double>(
opts["mcs-measure"].as<unsigned int>() * m.get_num_sites()
);
cout << "-> Result:" << endl;
cout << dens << endl;
}