-
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.
* made progress on octree class; working on building the octree class * finished implementing octree class and members/functions; need to fix segmentation fault in testing * update testing and previous implementation; debug octree implementation and makefile configuration * add inclusion of <memory> to octree files * add tests for body implementation; slightly edit body.cpp implementation * Implement config file functionality. * Fix everything * Add yaml-cpp install to workflows * Debug --------- Co-authored-by: jdinovi <[email protected]>
- Loading branch information
1 parent
5ad3d9b
commit bc4b8ad
Showing
15 changed files
with
676 additions
and
65 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
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,37 +1,40 @@ | ||
#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, std::string logFilePrefix = "run"); | ||
GravitationalEnvironment(const std::string configFileName, const bool log, std::string logFilePrefix = "run"); | ||
|
||
// 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; | ||
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; // This should be calculated in the constructor. | ||
std::string logFileName; | ||
|
||
private: | ||
// Instantiation of the physical members | ||
std::string logFilePrefix; | ||
}; | ||
|
||
// Helper functions | ||
int getLargestLabelNumber(const std::vector<std::string>& filenames, const std::string logFilePrefix); | ||
|
||
|
||
typedef GravitationalEnvironment<Particle> ParticleEnvironment; | ||
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,40 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <memory> | ||
|
||
#include "body.h" | ||
|
||
template <typename T> | ||
class Octree { | ||
public: | ||
|
||
// Octree constructor | ||
Octree(std::array<float, 2>& xCoords, std::array<float, 2>& yCoords, std::array<float, 2>& zCoords); | ||
|
||
// Member functions | ||
void clear(); | ||
void insert(std::shared_ptr<T> objPtr); | ||
void build(std::vector<std::shared_ptr<T>>& objPtrs); | ||
|
||
// Members | ||
std::vector<std::shared_ptr<T>> objPtrs; | ||
std::array<float, 3> centerOfMass; | ||
float* totalMass; | ||
|
||
// Dimensions of the current octant | ||
std::array<float, 2> xCoords; | ||
std::array<float, 2> yCoords; | ||
std::array<float, 2> zCoords; | ||
|
||
// Octree children --> 0-7 based on 2D convention in postive z, and then 2D convention in negative z, observing from above | ||
Octree<T>* child0; | ||
Octree<T>* child1; | ||
Octree<T>* child2; | ||
Octree<T>* child3; | ||
Octree<T>* child4; | ||
Octree<T>* child5; | ||
Octree<T>* child6; | ||
Octree<T>* child7; | ||
|
||
}; |
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.