Skip to content

Commit

Permalink
Change all grid types to double from int
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewcarbone committed Dec 17, 2023
1 parent c262c7c commit 09072aa
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 66 deletions.
4 changes: 2 additions & 2 deletions inc/emax.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
struct EMaxt2Data
{
double max_energy = -1e16;
long long tmin;
long long tmax;
double tmin;
double tmax;
};

class EMaxt2
Expand Down
6 changes: 3 additions & 3 deletions inc/obs1.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ class OnePointObservables

// Base objects we need
const utils::SimulationParameters params;
std::vector<long long> grid;
int grid_length;
std::vector<double> grid;
size_t grid_length;
const SpinSystem* spin_system_ptr;

// The pointer to the last-updated point on the grid
// Note that this is not actually a pointer =]
unsigned int pointer = 0;
size_t pointer = 0;

// Define the ridge energy objects
RidgeEnergyObject ridge_E_object;
Expand Down
24 changes: 12 additions & 12 deletions inc/obs2.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class PsiConfig

// The (roughly) maximum timestep on the counter. It's padded at the end,
// and is taken care of during post processing.
long long _max_counter;
size_t _max_counter;
std::vector<long long> _counter;

// Keep track internally of the waiting time for both the standard
// trajectory and the inherent structure
double _waiting_time = 0.0;

int _out_of_counter = 0;
size_t _out_of_counter = 0;

public:

Expand Down Expand Up @@ -54,7 +54,7 @@ class PsiBasin
const utils::FileNames fnames;
const utils::SimulationParameters params;
const SpinSystem* spin_system_ptr;
long long _max_counter;
size_t _max_counter;
PsiBasinData data_E, data_S;

void _init_E_data();
Expand All @@ -79,9 +79,9 @@ class Aging
const utils::SimulationParameters params;

// The pi 1 and 2 grids
std::vector<long long> grid_pi1;
std::vector<long long> grid_pi2;
int length;
std::vector<double> grid_pi1;
std::vector<double> grid_pi2;
size_t length;

public:
Aging(const utils::SimulationParameters params, const SpinSystem& spin_system);
Expand All @@ -97,8 +97,8 @@ class AgingConfig : public Aging
std::vector<std::string> results2;

// Define the pointers
int pointer1 = 0;
int pointer2 = 0;
size_t pointer1 = 0;
size_t pointer2 = 0;

// Helpers
void _help_step_1(const double simulation_clock);
Expand All @@ -114,13 +114,13 @@ class AgingConfig : public Aging
struct AgingBasinData
{
// Define the pointers
int pointer1 = 0;
int pointer2 = 0;
size_t pointer1 = 0;
size_t pointer2 = 0;

std::vector<long long> vec_basin_index_1;
std::vector<long long> vec_basin_index_2;
std::vector<int> vec_prev_state_in_basin_1;
std::vector<int> vec_prev_state_in_basin_2;
std::vector<size_t> vec_prev_state_in_basin_1;
std::vector<size_t> vec_prev_state_in_basin_2;

double threshold;
bool threshold_valid = true;
Expand Down
6 changes: 3 additions & 3 deletions inc/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void cleanup_directories();
* @param log10_timesteps [description]
* @param n_gridpoints [description]
*/
void make_energy_grid_logspace(const int log10_timesteps, const int n_gridpoints);
void make_energy_grid_logspace(const size_t log10_timesteps, const size_t n_gridpoints);

/**
* @brief [brief description]
Expand All @@ -235,7 +235,7 @@ void make_energy_grid_logspace(const int log10_timesteps, const int n_gridpoints
* @param dw [description]
* @param n_gridpoints [description]
*/
void make_pi_grids(const int log10_timesteps, const double dw, const int n_gridpoints);
void make_pi_grids(const size_t log10_timesteps, const double dw, const size_t n_gridpoints);

/**
* @brief [brief description]
Expand All @@ -245,7 +245,7 @@ void make_pi_grids(const int log10_timesteps, const double dw, const int n_gridp
* @param loc [description]
* @param grid_size [description]
*/
void load_long_long_grid_(std::vector<long long> &grid, const std::string loc);
void load_grid_(std::vector<double> &grid, const std::string path);

/**
* @brief [brief description]
Expand Down
6 changes: 3 additions & 3 deletions src/emax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ EMaxt2::EMaxt2(const utils::SimulationParameters params, const SpinSystem& spin_

// We need the pi2 grid since this goes from 0 to the length of the
// simulation
std::vector<long long> grid2;
utils::load_long_long_grid_(grid2, PI2_GRID_PATH);
std::vector<double> grid2;
utils::load_grid_(grid2, PI2_GRID_PATH);
length = grid2.size();

// Grid 1 is grid2 // 2
for (size_t ii=0; ii<length; ii++)
{
EMaxt2Data d;
d.tmax = grid2[ii];
d.tmin = d.tmax / 2;
d.tmin = d.tmax / 2.0;
trackers[ii] = d;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "CLI11/CLI11.hpp"


// All utilities in this main module come from main_utils
// All utilities in this main module come from main_utils or processing_utils
using namespace main_utils;


Expand Down
2 changes: 1 addition & 1 deletion src/obs1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ OnePointObservables::OnePointObservables(const utils::SimulationParameters param

spin_system_ptr = &spin_system;

utils::load_long_long_grid_(grid, ENERGY_GRID_PATH);
utils::load_grid_(grid, ENERGY_GRID_PATH);
grid_length = grid.size();

// Cache capacity observable
Expand Down
9 changes: 5 additions & 4 deletions src/obs2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ size_t _get_max_counter(const utils::SimulationParameters params)
// let N be the log base 10 total timesteps
// log2(10^N) = N log2(10)
// Give the max counter a lot of space
return params.log10_N_timesteps * log(10.0) + 10;
return params.log10_N_timesteps * log(10.0) + 10;
}


/**
* @brief Fills a long long vector with zeros up to _max_counter
*/

void _fill_counter(const size_t _max_counter, std::vector<long long> &counter)
{
for (size_t ii=0; ii<_max_counter; ii++){counter.push_back(0);}
}


int _get_key(const double local_waiting_time)
size_t _get_key(const double local_waiting_time)
{
// If the waiting time is <= 1, round it to 1.
if (local_waiting_time <= 1.0){return 0;} // 2^0
Expand Down Expand Up @@ -239,8 +240,8 @@ json PsiBasin::as_json() const
Aging::Aging(const utils::SimulationParameters params, const SpinSystem& spin_system) : params(params)
{
spin_system_ptr = &spin_system;
utils::load_long_long_grid_(grid_pi1, PI1_GRID_PATH);
utils::load_long_long_grid_(grid_pi2, PI2_GRID_PATH);
utils::load_grid_(grid_pi1, PI1_GRID_PATH);
utils::load_grid_(grid_pi2, PI2_GRID_PATH);
length = grid_pi1.size();
assert(length == grid_pi2.size());
}
Expand Down
12 changes: 6 additions & 6 deletions src/processing_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,16 @@ json load_grids()
{
json j;

std::vector<long long> grid_energy;
utils::load_long_long_grid_(grid_energy, ENERGY_GRID_PATH);
std::vector<double> grid_energy;
utils::load_grid_(grid_energy, ENERGY_GRID_PATH);
j["energy"] = grid_energy;

std::vector<long long> grid_pi1;
utils::load_long_long_grid_(grid_pi1, PI1_GRID_PATH);
std::vector<double> grid_pi1;
utils::load_grid_(grid_pi1, PI1_GRID_PATH);
j["pi1"] = grid_pi1;

std::vector<long long> grid_pi2;
utils::load_long_long_grid_(grid_pi2, PI2_GRID_PATH);
std::vector<double> grid_pi2;
utils::load_grid_(grid_pi2, PI2_GRID_PATH);
j["pi2"] = grid_pi2;

return j;
Expand Down
55 changes: 24 additions & 31 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,73 +227,66 @@ void cleanup_directories()
system(command.c_str());
}


void make_energy_grid_logspace(const int log10_timesteps, const int n_gridpoints)
void make_energy_grid_logspace(const size_t log10_timesteps, const size_t n_gridpoints)
{
std::vector <long long> v;
v.push_back(0.0);
std::vector <double> v;
const double delta = ((double) log10_timesteps) / ((double) n_gridpoints);
for (int ii=0; ii<n_gridpoints + 1; ii++)
for (size_t ii=0; ii<n_gridpoints + 1; ii++)
{
int val = int(pow(10, ((double) ii * delta)));
const double val = pow(10.0, ((double) ii * delta));
v.push_back(val);
}

v.erase(unique(v.begin(), v.end()), v.end());

FILE* outfile = fopen(ENERGY_GRID_PATH, "w");
for (int ii=0; ii<v.size(); ii++)
for (size_t ii=0; ii<v.size(); ii++)
{
fprintf(outfile, "%lli\n", v[ii]);
fprintf(outfile, "%e\n", v[ii]);
}
fclose(outfile);
}

void make_pi_grids(const int log10_timesteps, const double dw, const int n_gridpoints)
void make_pi_grids(const size_t log10_timesteps, const double dw, const size_t n_gridpoints)
{
std::vector <long long> v1;
std::vector <long long> v2;
const int nMC = int(pow(10, log10_timesteps));
const int tw_max = int(nMC / (dw + 1.0));
const double delta = ((double) log10(tw_max)) / ((double) n_gridpoints);

int _v1;
for (int ii=0; ii<n_gridpoints + 1; ii++)
std::vector <float> v1;
std::vector <float> v2;
const double nMC = pow(10, log10_timesteps);
const double tw_max = nMC / (dw + 1.0);
const double delta = log10(tw_max) / ((double) n_gridpoints);

for (size_t ii=0; ii<n_gridpoints + 1; ii++)
{
_v1 = int(pow(10, ((double) ii * delta)));
const double _v1 = pow(10, ((double) ii * delta));
v1.push_back(_v1);
}
v1.erase(unique(v1.begin(), v1.end()), v1.end());

int _v2;
for (int ii=0; ii<v1.size(); ii++)
const double dw_plus_1 = dw + 1.0;
for (size_t ii=0; ii<v1.size(); ii++)
{
_v2 = int(v1[ii] * (dw + 1.0));
const double _v2 = v1[ii] * dw_plus_1;
v2.push_back(_v2);
}

FILE* outfile1 = fopen(PI1_GRID_PATH, "w");
FILE* outfile2 = fopen(PI2_GRID_PATH, "w");

for (int ii=0; ii<v1.size(); ii++)
for (size_t ii=0; ii<v1.size(); ii++)
{
fprintf(outfile1, "%lli\n", v1[ii]);
fprintf(outfile2, "%lli\n", v2[ii]);
fprintf(outfile1, "%e\n", v1[ii]);
fprintf(outfile2, "%e\n", v2[ii]);
}

fclose(outfile1);
fclose(outfile2);
}

void load_long_long_grid_(std::vector<long long> &grid, const std::string loc)
void load_grid_(std::vector<double> &grid, const std::string path)
{
std::ifstream myfile (loc);
std::ifstream myfile (path);
std::string line;
if (myfile.is_open())
{
while (getline(myfile, line))
{
grid.push_back(stoll(line));
grid.push_back(stof(line));
}
myfile.close();
}
Expand Down

0 comments on commit 09072aa

Please sign in to comment.