-
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.
Implement config file functionality.
- Loading branch information
1 parent
aad4eaf
commit 431121f
Showing
9 changed files
with
421 additions
and
51 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
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,29 @@ | ||
global: | ||
nParticles: 1000 | ||
mass: | ||
dist: constant | ||
val: 100000000 | ||
x: | ||
dist: uniform | ||
min: 0 | ||
max: 4 | ||
y: | ||
dist: uniform | ||
min: -2 | ||
max: 4 | ||
z: | ||
dist: uniform | ||
min: 1 | ||
max: 10 | ||
vx: | ||
dist: uniform | ||
min: 0 | ||
max: 4 | ||
vy: | ||
dist: normal | ||
mu: -2 | ||
sigma: 4 | ||
vz: | ||
dist: uniform | ||
min: -10 | ||
max: 10 |
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 |
---|---|---|
@@ -1,34 +1,39 @@ | ||
#pragma once | ||
#include <vector> | ||
#include <array> | ||
#include <memory> | ||
#include <map> | ||
#include <memory> // Include for smart pointers | ||
#include "particle.h" | ||
|
||
#include "./particle.h" | ||
|
||
template <typename T> | ||
class GravitationalEnvironment{ | ||
|
||
public: | ||
// Constructors | ||
// GravitationalEnvironment(const std::vector<std::shared_ptr<T>>& particlePtrs, const bool log); | ||
GravitationalEnvironment(const std::vector<std::shared_ptr<T>>& particlePtrs, const bool log, std::string logFilePrefix="run"); | ||
class GravitationalEnvironment { | ||
public: | ||
// Constructors | ||
GravitationalEnvironment(const std::vector<std::shared_ptr<T>>& particlePtrs, const bool log); | ||
GravitationalEnvironment(const std::vector<std::shared_ptr<T>>& particlePtrs, const bool log, std::string logFilePrefix); | ||
GravitationalEnvironment(const std::string configFileName, const bool log); | ||
GravitationalEnvironment(const std::string configFileName, const bool log, std::string logFilePrefix); | ||
|
||
// Define member functions | ||
std::vector<std::array<double, 3>> getForces(const double timestep); | ||
void updateAll(const std::vector<std::array<double, 3>>& forces, const double timestep); | ||
void step(const double timestep); | ||
void simulate(const double duration, const double timestep); | ||
std::string getStepLog() const; | ||
std::string getLogHeader() const; | ||
void reset(); | ||
// Define member functions | ||
void loadParticlesFromConfig(std::string configFileName); | ||
std::vector<std::array<double, 3>> getForces(const double timestep); | ||
void updateAll(const std::vector<std::array<double, 3>>& forces, const double timestep); | ||
void step(const double timestep); | ||
void simulate(const double duration, const double timestep); | ||
std::string getStepLog() const; | ||
std::string getLogHeader() const; | ||
void reset(); | ||
|
||
// Instantiation of the physical members | ||
std::vector<std::shared_ptr<T>> particlePtrs; // Changed to std::shared_ptr | ||
bool log; | ||
double time; | ||
int nParticles; // This should be calculated in the constructor. | ||
std::string logFileName; | ||
|
||
// Instantiation of the physical members | ||
std::vector<std::shared_ptr<T>> particlePtrs; // Changed to std::shared_ptr | ||
bool log; | ||
double time; | ||
int nParticles; | ||
std::string logFileName; | ||
}; | ||
|
||
// Helper functions | ||
int getLargestLabelNumber(const std::vector<std::string>& filenames, const std::string logFilePrefix); | ||
std::map<std::string, std::map<std::string, std::string>> loadConfig(const std::string& fileName); |
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,18 @@ | ||
#pragma once | ||
#include <vector> | ||
#include <random> | ||
|
||
// Assuming you have the random device and generator declared somewhere | ||
extern std::random_device rd; | ||
extern std::mt19937 GENERATOR; | ||
|
||
// Distribution template used to sample from random distributions | ||
template <typename Distribution> | ||
std::vector<double> sampleFromDistribution(size_t n, Distribution& distribution) { | ||
// Generate samples | ||
std::vector<double> samples(n); | ||
for (size_t i = 0; i < n; ++i) { | ||
samples[i] = distribution(GENERATOR); | ||
} | ||
return samples; | ||
} |
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.