Skip to content

Commit

Permalink
cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Moritz Maurer committed Oct 5, 2024
1 parent 6f505fa commit 8c2aaea
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ build/*
.vscode/

# Test artifacts
Testing/
Testing/
dev/Testing/
2 changes: 2 additions & 0 deletions dev/app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ int main(int argc, char* argv[]) {
auto commandLineArguments = loadCommandLineArguments(argc, argv);
auto configParameters = setupConfigParameters(commandLineArguments);



return 0;
}
9 changes: 4 additions & 5 deletions dev/libs/data_processing/include/data_processing/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
#define FLASH_CONFIG_H

#include <array>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
#include <cmath>

#include <yaml-cpp/yaml.h>

#include <types/types.h>
#include <yaml-cpp/yaml.h>

namespace flash {
namespace data_processing{
namespace config{
namespace data_processing {
namespace config {

/**
* @brief Throw when an invalid key is detected.
Expand Down
8 changes: 4 additions & 4 deletions dev/libs/data_processing/include/data_processing/read_hdf5.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
#include <vector>

#include <H5Cpp.h>

#include <types/types.h>

namespace flash {
namespace data_processing{
namespace data_processing {
namespace read_hdf5 {


/**
* @brief Read a \p flash::types::real_dp vector from an HDF5 file
*
*
* @param[in] filename Name of the HDF5 file
* @param[in] datasetName Absolute name of the dataset
* @return A \p flash::types::DVector initialized with the data from the file
Expand All @@ -26,4 +26,4 @@ flash::types::DVector readDoubleVectorHDF5(const std::string &filename, const st
} // namespace data_processing
} // namespace flash

#endif // FLASH_READ_H
#endif // FLASH_READ_H
53 changes: 24 additions & 29 deletions dev/libs/data_processing/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,14 @@ auto nodeToArray(const YAML::Node &node, bool (*rule)(T value), std::string msg)

Config::Config(const YAML::Node &configYamlNode, const std::vector<std::string> &allowedKeys,
const std::vector<std::string> &mandatoryKeys, const DefaultConfig &defaults) {
// extract keys from yaml node

std::cout<<configYamlNode["n_k_points"]<<std::endl;

// extract keys from yaml node
std::vector<std::string> keysInNode;
for (auto kv : configYamlNode) {
auto key = kv.first.as<std::string>();
keysInNode.push_back(key);
}

std::cout<<configYamlNode["n_k_points"]<<std::endl;
// verify that all keys from keysInNode that are in allowedKeys
for (auto key : keysInNode) {
if (std::find(allowedKeys.begin(), allowedKeys.end(), key) == allowedKeys.end()) {
Expand All @@ -74,7 +71,6 @@ Config::Config(const YAML::Node &configYamlNode, const std::vector<std::string>
}
}

std::cout<<configYamlNode["n_k_points"]<<std::endl;
// verify that keys from mandatoryKeys are in keysInNode
for (auto key : mandatoryKeys) {
if (std::find(keysInNode.begin(), keysInNode.end(), key) == keysInNode.end()) {
Expand All @@ -83,37 +79,36 @@ Config::Config(const YAML::Node &configYamlNode, const std::vector<std::string>
}

try {

n_k_points = nodeToValue<tp::size>(configYamlNode["n_k_points"], "n_k_points is wrongly initialized.");
n_occupied_total =
nodeToValue<tp::size>(configYamlNode["n_occupied_total"], "n_occupied_total is wrongly initialized.");
n_unoccupied_total =
nodeToValue<tp::size>(configYamlNode["n_unoccupied_total"], "n_unoccupied_total is wrongly initialized.");
n_isdf_vexc = nodeToValue<tp::size>(configYamlNode["n_isdf_vexc"], "n_isdf_vexc is wrongly initialized.");
n_isdf_wscr_occupied =
nodeToValue<tp::size>(configYamlNode["n_isdf_wscr_occupied"], "n_isdf_wscr_occupied is wrongly initialized.");
n_isdf_wscr_occupied = nodeToValue<tp::size>(configYamlNode["n_isdf_wscr_occupied"],
"n_isdf_wscr_occupied is wrongly initialized.");
n_isdf_wscr_unoccupied = nodeToValue<tp::size>(configYamlNode["n_isdf_wscr_unoccupied"],
"n_isdf_wscr_unoccupied is wrongly initialized.");
"n_isdf_wscr_unoccupied is wrongly initialized.");
max_lanczos_iterations = nodeToValue<tp::size>(configYamlNode["max_lanczos_iterations"],
"max_lanczos_iterations is wrongly initialized.");
omega_range =
nodeToValue<std::array<tp::real_dp, 2>>(configYamlNode["omega_range"], "omega_range is wrongly initialized.");
"max_lanczos_iterations is wrongly initialized.");
omega_range = nodeToValue<std::array<tp::real_dp, 2>>(configYamlNode["omega_range"],
"omega_range is wrongly initialized.");
n_omega = nodeToValue<tp::size>(configYamlNode["n_omega"], "n_omega is wrongly initialized.");
max_cvt_iterations =
nodeToValueWithDefault<tp::size>(configYamlNode, "max_cvt_iterations", defaults.max_cvt_Itereations,
"max_cvt_iterations is wrongly initialized.");
cvt_convergence_criterium = nodeToValueWithDefault<tp::real_dp>(configYamlNode, "cvt_convergence_criterium",
defaults.cvt_convergence_criterium,
"cvt_convergence_criterium is wrongly initialized.");
"max_cvt_iterations is wrongly initialized.");
cvt_convergence_criterium = nodeToValueWithDefault<tp::real_dp>(
configYamlNode, "cvt_convergence_criterium", defaults.cvt_convergence_criterium,
"cvt_convergence_criterium is wrongly initialized.");
seed_source = nodeToSeed(configYamlNode, "seed_source", defaults.seed_source);

} catch (const InvalidConfigurationException) {
throw;
}
}


void Config::validate() {

// Rule for n_k_points
if (n_k_points == 0) {
throw InvalidConfigurationException("n_k_points must be > 0.");
Expand All @@ -131,45 +126,45 @@ void Config::validate() {
throw InvalidConfigurationException("n_occupied_total + n_unoccupied_total must be divisable by n_k_points.");
}
// Rules for n_isdf_vexc
if (!n_isdf_vexc > 0) {
if (n_isdf_vexc == 0) {
throw InvalidConfigurationException("n_isdf_vexc must be > 0.");
}
if (!n_isdf_vexc <= n_occupied_total * n_unoccupied_total / n_k_points) {
if (n_isdf_vexc > n_occupied_total * n_unoccupied_total / n_k_points) {
throw InvalidConfigurationException(
"n_isdf_vexc must be <= n_occupied_total * n_unoccupied_total / n_k_points.");
}
// Rules for n_isdf_wscr_occupied
if (!n_isdf_wscr_occupied > 0) {
if (n_isdf_wscr_occupied == 0) {
throw InvalidConfigurationException("n_isdf_wscr_occupied must be > 0.");
}
if (!n_isdf_wscr_occupied <= std::pow(n_occupied_total, 2)) {
if (n_isdf_wscr_occupied > std::pow(n_occupied_total, 2)) {
throw InvalidConfigurationException("n_isdf_wscr_occupied must be <= n_occupied_total^2.");
}
// Rules for n_isdf_wscr_unoccupied
if (!n_isdf_wscr_unoccupied > 0) {
if (n_isdf_wscr_unoccupied == 0) {
throw InvalidConfigurationException("n_isdf_wscr_unoccupied must be > 0.");
}
if (!n_isdf_wscr_unoccupied <= std::pow(n_occupied_total, 2)) {
if (n_isdf_wscr_unoccupied > std::pow(n_occupied_total, 2)) {
throw InvalidConfigurationException("n_isdf_wscr_unoccupied must be <= n_occupied_total^2.");
}
// Rule for max_lanczos_iterations
if (!max_lanczos_iterations > 0) {
if (max_lanczos_iterations == 0) {
throw InvalidConfigurationException("max_lanczos_iterations must be > 0.");
}
// Rule for omega_range
if (!sizeof(omega_range) == 2) {
if (sizeof(omega_range) != 2) {
throw InvalidConfigurationException("omega_range must contain exactly 2 values.");
}
if (!omega_range[0] < omega_range[1]) {
if (omega_range[0] >= omega_range[1]) {
throw InvalidConfigurationException(
"Lower limit of omega_range (left value) must be smaller then the upper limit (right value).");
}
// Rule for n_omega
if (!n_omega > 0) {
if (n_omega == 0) {
throw InvalidConfigurationException("n_omega must be > 0.");
}
// Rule for max_cvt_iterations
if (!cvt_convergence_criterium > 0) {
if (cvt_convergence_criterium == 0) {
throw InvalidConfigurationException("cvt_convergence_criterium must be > 0.");
}
}
13 changes: 4 additions & 9 deletions dev/libs/data_processing/src/read_hdf5.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include <data_processing/read_hdf5.h>


namespace tp = flash::types;
using namespace flash::data_processing::read_hdf5;


tp::DVector readDoubleVectorHDF5(const std::string &filename, const std::string &datasetName) {
try {
try {
// Open the HDF5 file
H5::H5File file(filename, H5F_ACC_RDONLY);

Expand All @@ -26,14 +24,11 @@ tp::DVector readDoubleVectorHDF5(const std::string &filename, const std::string
tp::DVector eigenVector = Eigen::Map<tp::DVector>(buffer.data(), buffer.size());

return eigenVector;
}
catch (H5::FileIException &error) {
} catch (H5::FileIException &error) {
error.printErrorStack();
}
catch (H5::DataSetIException &error) {
} catch (H5::DataSetIException &error) {
error.printErrorStack();
}
catch (H5::DataSpaceIException &error) {
} catch (H5::DataSpaceIException &error) {
error.printErrorStack();
}

Expand Down
1 change: 0 additions & 1 deletion dev/libs/types/include/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ typedef Eigen::Vector<complex_dp, Eigen::Dynamic> CVector;
typedef Eigen::Matrix<real_dp, Eigen::Dynamic, Eigen::Dynamic> DMatrix;
typedef Eigen::Matrix<complex_dp, Eigen::Dynamic, Eigen::Dynamic> CMatrix;


} // namespace types
} // namespace flash

Expand Down
1 change: 1 addition & 0 deletions dev/linter/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Checks: >
- bugprone-*
- misc-*
- filter-.*
- header-filter=.*
- -* # Disable other checks
WarningsAsErrors: ''
Expand Down
4 changes: 2 additions & 2 deletions dev/tests/data_processing/src/config_test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#define CATCH_CONFIG_MAIN

#include <catch2/catch.hpp>

#include <data_processing/config.h>

#include <catch2/catch.hpp>

namespace ftp = flash::types;
using namespace flash::data_processing::config;

Expand Down

0 comments on commit 8c2aaea

Please sign in to comment.