Skip to content

Commit

Permalink
Bring everything upto date
Browse files Browse the repository at this point in the history
  • Loading branch information
ConniBug committed Mar 5, 2024
1 parent 20a343c commit 9025c03
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 665 deletions.
2 changes: 1 addition & 1 deletion .idea/runConfigurations/GalaxySimulation.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 7 additions & 57 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
########### Flags ############################################################
set(SHOULD_USE_EXTERNALS ON)
set(SHOULD_USE_GTEST ON)
set(SHOULD_USE_MATPLOTLIB_CPP ON)
##############################################################################

cmake_minimum_required(VERSION 3.16)
Expand Down Expand Up @@ -32,26 +30,10 @@ else()
endif()
######################################

if(SHOULD_USE_EXTERNALS)
include(FetchContent)

if(SHOULD_USE_GTEST)
FetchContent_Declare(
googletest
# Specify the commit you depend on and update it regularly.
URL https://github.com/google/googletest/archive/5376968f6948923e2411081fd9372e71a59d8e77.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()

# find_package(Matplot++ REQUIRED)
endif()


find_package(Threads REQUIRED)
add_executable(GalaxySimulation
add_executable(
GalaxySimulation

main.cpp
Star.cpp Star.h
includes.h
Expand All @@ -66,46 +48,14 @@ add_executable(GalaxySimulation
star_generator.h
includes/Random.h


includes/ConfigHandler.cpp includes/ConfigHandler.h
includes/ConfigHandler.h

includes/ConfigStruct.h source/star_generator.cpp)


include_directories(${CMAKE_CURRENT_SOURCE_DIR}/includes)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/includes/external)

if(SHOULD_USE_EXTERNALS)
if(SHOULD_USE_GTEST)
enable_testing()
add_executable(Simulation_Tests
Star.cpp
Star.h
GTests/Vector3_Test.cc
GTests/Star_Test.cc
GTests/DataExporter_Test.cc
GTests/Simulation_Test.cc
GTests/Math_Test.cc)
target_link_libraries(
Simulation_Tests
GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(Simulation_Tests)
endif()
#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/includes/external)

if(SHOULD_USE_MATPLOTLIB_CPP)
# find_package(Python3 REQUIRED COMPONENTS Interpreter Development NumPy)
target_link_libraries(GalaxySimulation PUBLIC Threads::Threads)

# target_include_directories(GalaxySimulation PRIVATE ${Python3_INCLUDE_DIRS} includes includes/external/)

if(TARGET Threads::Threads)
target_link_libraries(GalaxySimulation PUBLIC Threads::Threads)
else()
target_link_libraries(GalaxySimulation PUBLIC)
endif()
endif()
else()
target_link_libraries(GalaxySimulation PUBLIC Threads::Threads)
endif()
include(./GTests/CMakeLists.txt)
106 changes: 53 additions & 53 deletions Plotting.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "Star.h"
#include <logging.h>
#include <Vector3.h>
#include <matplot/matplot.h>
//#include <matplot/matplot.h>

//using namespace matplot;

Expand All @@ -32,61 +32,61 @@ class Plotting {

y.push_back(total_kinetic_energy);
}
matplot::plot(x, y);
// matplot::plot(x, y);
}

public:
void test(std::vector<Star*> star_list) {
auto f = figure<matplot::backend::gnuplot>(true);

std::vector<double> x = {};
std::vector<double> y = {};
std::vector<double> z = {};
std::vector<double> vx = {};
std::vector<double> vy = {};
std::vector<double> vz = {};
std::vector<double> time = {};
for (int i = 0; i <= star_list[0]->history.size(); ++i) {

for (auto star: star_list) {
star->velocity = star->velocity * parsecsPerYear_to_metersPerSecond;
++i;
time.push_back(i);
x.push_back(star->history[i].position.x);
y.push_back(star->history[i].position.y);
z.push_back(star->history[i].position.z);
}
}
// plot multiple graphs
// matplot::subplot(1, 2, 2);


matplot::subplot(3, 1, 0);
matplot::title("Y Position");
matplot::plot(time, y);

matplot::subplot(3, 1, 1);
matplot::title("X Position");
matplot::plot(time, x);

matplot::subplot(3, 1, 2);
matplot::title("Z Position");
matplot::plot(time, z);

matplot::show();


// matplot::subplot(1, 2, 1);
// draw_kinetic_energy(&star_list, 10);
matplot::show();



// plt::subplot(2, 2, 2);
// plt::plot(x, y);

// plt::show();
}
// void test(std::vector<Star*> star_list) {
// auto f = figure<matplot::backend::gnuplot>(true);
//
// std::vector<double> x = {};
// std::vector<double> y = {};
// std::vector<double> z = {};
// std::vector<double> vx = {};
// std::vector<double> vy = {};
// std::vector<double> vz = {};
// std::vector<double> time = {};
// for (int i = 0; i <= star_list[0]->history.size(); ++i) {
//
// for (auto star: star_list) {
// star->velocity = star->velocity * parsecsPerYear_to_metersPerSecond;
// ++i;
// time.push_back(i);
// x.push_back(star->history[i].position.x);
// y.push_back(star->history[i].position.y);
// z.push_back(star->history[i].position.z);
// }
// }
//// plot multiple graphs
//// matplot::subplot(1, 2, 2);
//
//
// matplot::subplot(3, 1, 0);
// matplot::title("Y Position");
// matplot::plot(time, y);
//
// matplot::subplot(3, 1, 1);
// matplot::title("X Position");
// matplot::plot(time, x);
//
// matplot::subplot(3, 1, 2);
// matplot::title("Z Position");
// matplot::plot(time, z);
//
// matplot::show();
//
//
//// matplot::subplot(1, 2, 1);
//// draw_kinetic_energy(&star_list, 10);
// matplot::show();
//
//
//
//// plt::subplot(2, 2, 2);
//// plt::plot(x, y);
//
//// plt::show();
// }
};

#endif //GALAXYSIMULATION_PLOTTING_H
26 changes: 13 additions & 13 deletions Simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@

class Simulator {
public:
int thread_count = -1;
int star_per_thread = -1;
int left_over = -1;
std::vector<Star*> *star_list;
unsigned int thread_count = -1;
int star_per_thread = -1;
int left_over = -1;
std::vector<Star*> *star_list;

std::vector<std::vector<Star *>> *work_queue = new std::vector<std::vector<Star *>>();
std::vector<std::vector<Star *>> *work_queue = new std::vector<std::vector<Star *>>();

Simulator(int thread_count, std::vector<Star*> *star_list) {
this->thread_count = thread_count;
this->star_list = star_list;
this->left_over = star_list->size() % thread_count;
this->star_per_thread = (star_list->size() - left_over) / thread_count;
}
Simulator(unsigned int thread_count, std::vector<Star*> *star_list) {
this->thread_count = thread_count;
this->star_list = star_list;
this->left_over = star_list->size() % thread_count;
this->star_per_thread = (star_list->size() - left_over) / thread_count;
}

void output_info();
void output_info();

void generateWorkQueue();
void generateWorkQueue();
};


Expand Down
18 changes: 0 additions & 18 deletions includes/ConfigHandler.cpp

This file was deleted.

54 changes: 50 additions & 4 deletions includes/ConfigHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,58 @@

struct Config {
public:
void loadConfig(const char *config_name = "default");
void loadConfig(int config_index);

void saveConfig(const char *config_name);
static void saveConfig(string path, ConfigStruct config) {
std::ofstream o(path);
ConfigStruct conf;
json jsonNewConfig = config;
o << std::setw(4) << jsonNewConfig << std::endl;
o.close();
logging::info("Config file saved.");
}

void listConfigs();
static ConfigStruct loadConfig(string path) {
// read a JSON file
if(!std::filesystem::exists(path)) {
logging::error("Couldn't find config file.");
// std::ofstream o(path);
// ConfigStruct conf;
// json jsonNewConfig = conf;
// o << std::setw(4) << jsonNewConfig << std::endl;
// o.close();
// logging::info("Config file created.");
logging::info("Error: Config file not found.");
exit(1);
}
logging::info("Config Found.");

ConfigStruct config;
{
json configJson;
std::ifstream conf(path);
conf >> configJson;
conf.close();
config = configJson;

logging::info("Config loaded");

// Print all json components
std::cout << std::setw(4) << config.version.major << std::endl;

for (auto it = configJson.begin(); it != configJson.end(); ++it) {
std::cout << "- " << it.key() << ": ";
if (it.value().is_object() || it.value().is_array()) {
std::cout << std::endl;
for (auto inner_it = it.value().begin(); inner_it != it.value().end(); ++inner_it) {
std::cout << " - " << inner_it.key() << ": " << inner_it.value() << std::endl;
}
} else {
std::cout << it.value() << std::endl;
}
}
}
return config;
}
};

#endif //GALAXYSIMULATION_CONFIGHANDLER_H
Loading

0 comments on commit 9025c03

Please sign in to comment.