-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored files into header and cpp files
- Loading branch information
Shaunak Badani
committed
Sep 22, 2023
1 parent
27a0fa9
commit 9443a32
Showing
30 changed files
with
1,843 additions
and
1,509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "complex2d.h" | ||
#include "utilities.h" | ||
|
||
Complex2D::Complex2D() | ||
{ | ||
this->setupSystem(); | ||
this->initializePositions(); | ||
this->initializeVelocities(); | ||
} | ||
|
||
void Complex2D::setupSystem() { | ||
this->numberOfParticles = numParticles; | ||
this->systemDimensionality = 2; | ||
for(int i = 0 ; i < this->numberOfParticles ; i++) | ||
this->masses.push_back(1.0f); | ||
} | ||
|
||
void Complex2D::initializePositions() { | ||
this->positions = initializeRandomVector(this->numberOfParticles, | ||
this->systemDimensionality, | ||
-1.0f, 1.0f); | ||
} | ||
|
||
float Complex2D::potentialEnergy(std::vector<std::vector<float>>& pos) { | ||
float peValue = 0; | ||
for(int i = 0 ; i < this->numberOfParticles ; i++) | ||
peValue += U(pos[i]); | ||
return peValue; | ||
} | ||
|
||
float Complex2D::potentialEnergy() { | ||
return potentialEnergy(this->positions); | ||
} | ||
|
||
|
||
std::vector<std::vector<float>> Complex2D::force(std::vector<std::vector<float>>& pos) { | ||
std::vector<std::vector<float>> returnValue; | ||
for(int i = 0 ; i < this->numberOfParticles ; i++) | ||
returnValue.push_back(F(pos[i])); | ||
return returnValue; | ||
} | ||
|
||
std::vector<std::vector<float>> Complex2D::force() { | ||
return this->force(this->positions); | ||
} | ||
|
||
float Complex2D::U(std::vector<float>& pos) { | ||
float x = pos[0]; | ||
float y = pos[1]; | ||
|
||
return 10 * (pow(x, 10) + pow(y, 10)) + 5 * sin(2 * M_PI * x) * cos(2 * M_PI * y); | ||
} | ||
|
||
std::vector<float> Complex2D::F(std::vector<float>& pos) { | ||
float x = pos[0]; | ||
float y = pos[1]; | ||
|
||
float fX = -1 * (100 * pow(x, 9) + 10 * M_PI * cos(2 * M_PI * x) * cos(2 * M_PI * y)); | ||
float fY = -1 * (100 * pow(y, 9) - 10 * M_PI * sin(2 * M_PI * x) * sin(2 * M_PI * y)); | ||
|
||
return {fX, fY}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#include "config.h" | ||
#include <string> | ||
#include <mpi.h> | ||
#include <iostream> | ||
|
||
float samplingTemperature = 0.3; | ||
std::vector<float> samplingTemperatures = {0.3f, 2.0f}; | ||
int numSteps = 1000; | ||
int numParticles = 1; | ||
int outputPeriod = 100; | ||
std::string runType = "nve"; | ||
std::string runName = "currentRun"; | ||
std::string systemName = "1D_Smit"; | ||
std::string rst; | ||
float tauValue = 0.024f; | ||
bool isRstPresent = false; | ||
bool ada = false; | ||
bool useScalingProtocol = false; | ||
|
||
float temperature() { | ||
int noOfReplicas; | ||
|
||
MPI_Comm_size( MPI_COMM_WORLD, &noOfReplicas ); | ||
|
||
if(noOfReplicas > 1) { | ||
int rank; | ||
MPI_Comm_rank( MPI_COMM_WORLD, &rank ); | ||
return samplingTemperatures[rank]; | ||
} | ||
return samplingTemperature; | ||
} | ||
|
||
void setDefaultConfig() { | ||
samplingTemperature = 0.3; | ||
samplingTemperatures = {0.3f, 2.0f}; | ||
numSteps = 1000; | ||
numParticles = 1; | ||
outputPeriod = 100; | ||
runType = "nve"; | ||
runName = "currentRun"; | ||
systemName = "1D_Smit"; | ||
tauValue = 0.024f; | ||
isRstPresent = false; | ||
ada = false; | ||
useScalingProtocol = false; | ||
} | ||
|
||
void printConfig(int rank) { | ||
std::cout << "Temperature : " << temperature() << std::endl; | ||
|
||
if(rank == 0) { | ||
std::cout << "Number of steps : " << numSteps << std::endl; | ||
std::cout << "Number of particles : " << numParticles << std::endl; | ||
std::cout << "Output Period : " << outputPeriod << std::endl; | ||
std::cout << "Run Type : " << runType << std::endl; | ||
std::cout << "System : " << systemName << std::endl; | ||
std::cout << "Tau Value : " << tauValue << std::endl; | ||
std::cout << "Use Scaling Protocol : " << useScalingProtocol << std::endl; | ||
} | ||
|
||
} | ||
|
||
void getConfigFromFile(std::string fileName) { | ||
|
||
std::ifstream jsonFileObject(fileName); | ||
json data = json::parse(jsonFileObject); | ||
|
||
if(data.contains("temperature")) | ||
samplingTemperature = data["temperature"]; | ||
|
||
if(data.contains("temperatures")) { | ||
for(int i = 0 ; i < data["temperatures"].size() ; i++) | ||
samplingTemperatures[i] = data["temperatures"][i]; | ||
} | ||
|
||
if(data.contains("num_steps")) | ||
numSteps = data["num_steps"]; | ||
|
||
if(data.contains("output_period")) | ||
outputPeriod = data["output_period"]; | ||
|
||
if(data.contains("run_type")) | ||
runType = data["run_type"]; | ||
|
||
if(data.contains("run_name")) | ||
runName = data["run_name"]; | ||
|
||
if(data.contains("system")) | ||
systemName = data["system"]; | ||
|
||
if(data.contains("tau")) | ||
tauValue = data["tau"]; | ||
|
||
if(data.contains("rst")) { | ||
isRstPresent = true; | ||
rst = data["rst"]; | ||
} | ||
|
||
if(data.contains("num_particles")) | ||
numParticles = data["num_particles"]; | ||
|
||
if(data.contains("ada")) | ||
ada = data["ada"]; | ||
|
||
if(data.contains("use_scaling_protocol")) | ||
useScalingProtocol = data["use_scaling_protocol"]; | ||
|
||
|
||
|
||
// if(data.contains("temperatures")) | ||
// samplingTemperatures = data["temperatures"]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.