Skip to content

Commit

Permalink
use const, improve output to console
Browse files Browse the repository at this point in the history
  • Loading branch information
schuhmaj committed Dec 16, 2024
1 parent cb7efe3 commit 161da47
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
int main(int argc, char *argv[]) {
using namespace polyhedralGravity;

SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Version: " + std::string(POLYHEDRAL_GRAVITY_VERSION));
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Commit Hash: " + std::string(POLYHEDRAL_GRAVITY_COMMIT_HASH));
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Parallelization Backend: " + std::string(POLYHEDRAL_GRAVITY_PARALLELIZATION));
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Logging Level: " + std::string(POLYHEDRAL_GRAVITY_LOGGING_LEVEL));
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "####################################################################################");
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Version: {}", POLYHEDRAL_GRAVITY_VERSION);
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Commit Hash: {}", POLYHEDRAL_GRAVITY_COMMIT_HASH);
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Parallelization Backend: {}", POLYHEDRAL_GRAVITY_PARALLELIZATION);
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Logging Level: {}", POLYHEDRAL_GRAVITY_LOGGING_LEVEL);

if (argc != 2) {
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Wrong program call! "
Expand All @@ -22,20 +23,28 @@ int main(int argc, char *argv[]) {
}

try {
std::shared_ptr<ConfigSource> config = std::make_shared<YAMLConfigReader>(argv[1]);
auto polyhedralSource = config->getDataSource()->getPolyhedralSource();
auto density = config->getDensity();
auto computationPoints = config->getPointsOfInterest();
auto outputFileName = config->getOutputFileName();
PolyhedronIntegrity checkPolyhedralInput = config->getMeshInputCheckStatus() ? PolyhedronIntegrity::HEAL : PolyhedronIntegrity::DISABLE;
const std::shared_ptr<ConfigSource> config = std::make_shared<YAMLConfigReader>(argv[1]);
const auto polyhedralSource = config->getDataSource()->getPolyhedralSource();
const auto density = config->getDensity();
const auto computationPoints = config->getPointsOfInterest();
const auto outputFileName = config->getOutputFileName();
const PolyhedronIntegrity checkPolyhedralInput = config->getMeshInputCheckStatus() ? PolyhedronIntegrity::HEAL : PolyhedronIntegrity::DISABLE;

SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "####################################################################################");
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Number of Vertices: {}", std::get<0>(polyhedralSource).size());
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Number of Faces: {}", std::get<1>(polyhedralSource).size());
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Number of Computation Points: {}", computationPoints.size());
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Mesh Check Enabled: {}", config->getMeshInputCheckStatus());
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Output File: {}", outputFileName);
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "####################################################################################");

SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "The calculation started...");
auto start = std::chrono::high_resolution_clock::now();
Polyhedron polyhedron{polyhedralSource, density, NormalOrientation::OUTWARDS, checkPolyhedralInput};
auto result = GravityModel::evaluate(polyhedron, computationPoints, true);
auto end = std::chrono::high_resolution_clock::now();
auto duration = end - start;
auto ms = std::chrono::duration_cast<std::chrono::microseconds>(duration);
const auto start = std::chrono::high_resolution_clock::now();
const Polyhedron polyhedron{polyhedralSource, density, NormalOrientation::OUTWARDS, checkPolyhedralInput};
const auto result = GravityModel::evaluate(polyhedron, computationPoints, true);
const auto end = std::chrono::high_resolution_clock::now();
const auto duration = end - start;
const auto ms = std::chrono::duration_cast<std::chrono::microseconds>(duration);
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(),
"The calculation finished. It took {} microseconds.", ms.count());
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(),
Expand All @@ -46,7 +55,7 @@ int main(int argc, char *argv[]) {
if (!outputFileName.empty()) {
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(),
"Writing results to specified output file {}", outputFileName);
CSVWriter csvWriter{outputFileName};
const CSVWriter csvWriter{outputFileName};
csvWriter.printResult(computationPoints, result);
SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(),
"Writing finished!");
Expand Down

0 comments on commit 161da47

Please sign in to comment.