diff --git a/dev/app/CMakeLists.txt b/dev/app/CMakeLists.txt index eca8f85..bded2ee 100644 --- a/dev/app/CMakeLists.txt +++ b/dev/app/CMakeLists.txt @@ -2,9 +2,4 @@ project(lightning-app) add_executable(app src/main.cpp) target_link_libraries(app - PRIVATE - data_processing - constants - yaml-cpp - ${Boost_LIBRARIES} ) diff --git a/dev/app/src/main.cpp b/dev/app/src/main.cpp index 6c25028..83ef69d 100644 --- a/dev/app/src/main.cpp +++ b/dev/app/src/main.cpp @@ -1,60 +1,3 @@ -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace po = boost::program_options; -namespace dpc = flash::data_processing::config; -namespace tp = flash::types; - -po::variables_map loadCommandLineArguments(int argc, char* argv[]) { - - po::options_description desc("Allowed options"); - desc.add_options()("help,h", "produce help message")( - "config-file,i", po::value()->default_value("config.yaml"), "set path to a config.yaml"); - - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - - if (vm.count("help")) { - std::cout << desc << std::endl; - std::exception(); - } - - return vm; -} - -dpc::Config setupConfigParameters(po::variables_map commandLineArguments) { - - auto configFile = commandLineArguments["config-file"].as(); - std::cout << "Load configuration from " << configFile << std::endl; - try { - auto configNode = YAML::LoadFile(configFile); - auto params = dpc::Config(configNode); - params.validate(); - return params; - - } catch (YAML::BadFile BF) { - std::cerr << "Flash is terminating: " - << "Could not open " << configFile << std::endl; - } catch (dpc::InvalidKeyException IKE) { - std::cerr << "Flash is terminating: " << IKE.what() << std::endl; - } catch (dpc::MissingKeyException MKE) { - std::cerr << "Flash is terminating: " << MKE.what() << std::endl; - } catch (dpc::InvalidConfigurationException ICE) { - std::cerr << "Flash is terminating: " << ICE.what() << std::endl; - } -} - int main(int argc, char* argv[]) { - auto commandLineArguments = loadCommandLineArguments(argc, argv); - auto configParameters = setupConfigParameters(commandLineArguments); - - return 0; } diff --git a/dev/libs/CMakeLists.txt b/dev/libs/CMakeLists.txt deleted file mode 100644 index f0fcacf..0000000 --- a/dev/libs/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ - - - - -add_subdirectory(types) -add_subdirectory(constants) -add_subdirectory(data_processing) -add_subdirectory(electrons) \ No newline at end of file diff --git a/dev/libs/constants/CMakeLists.txt b/dev/libs/constants/CMakeLists.txt deleted file mode 100644 index f8d48cf..0000000 --- a/dev/libs/constants/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -#project(lighning-constants) - -add_library(constants INTERFACE) - -target_include_directories(constants - INTERFACE - include -) \ No newline at end of file diff --git a/dev/libs/constants/include/constants/constants.h b/dev/libs/constants/include/constants/constants.h deleted file mode 100644 index 35d9068..0000000 --- a/dev/libs/constants/include/constants/constants.h +++ /dev/null @@ -1,10 +0,0 @@ -// -// Created by benedikt on 26.05.24. -// - -#ifndef CONSTANTS_H -#define CONSTANTS_H - -#include "precision.h" - -#endif // CONSTANTS_H \ No newline at end of file diff --git a/dev/libs/constants/include/constants/precision.h b/dev/libs/constants/include/constants/precision.h deleted file mode 100644 index 5f3698b..0000000 --- a/dev/libs/constants/include/constants/precision.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// Created by benedikt on 26.05.24. -// - -#ifndef PRECISION_H -#define PRECISION_H - -#include - -namespace precison { -inline constexpr int testConst = 3; -} - -#endif // PRECISION_H \ No newline at end of file diff --git a/dev/libs/data_processing/CMakeLists.txt b/dev/libs/data_processing/CMakeLists.txt deleted file mode 100644 index 9793b59..0000000 --- a/dev/libs/data_processing/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -#project(lightning-config) - -add_library(data_processing - src/config.cpp - src/read_hdf5.cpp -) - -target_link_libraries(data_processing - types - yaml-cpp -) - -target_include_directories(data_processing - PUBLIC - include - PRIVATE - src -) \ No newline at end of file diff --git a/dev/libs/data_processing/include/data_processing/config.h b/dev/libs/data_processing/include/data_processing/config.h deleted file mode 100644 index 43c03e4..0000000 --- a/dev/libs/data_processing/include/data_processing/config.h +++ /dev/null @@ -1,201 +0,0 @@ -#ifndef FLASH_CONFIG_H -#define FLASH_CONFIG_H - -#include -#include -#include -#include -#include -#include - -#include - -#include - -namespace flash { -namespace data_processing { -namespace config { - -/** - * @brief Throw when an invalid key is detected. - */ -class InvalidKeyException : public std::exception { - private: - std::string message; - - public: - InvalidKeyException(std::string msg) : message(msg) {} - std::string what() { return message; } -}; - -/** - * @brief Throw when a missing key is detected. - */ -class MissingKeyException : public std::exception { - private: - std::string message; - - public: - MissingKeyException(std::string msg) : message(msg) {} - std::string what() { return message; } -}; - -/** - * @brief Throw when an invalid configuration is detected. - */ -class InvalidConfigurationException : public std::exception { - private: - std::string message; - - public: - InvalidConfigurationException(std::string msg) : message(msg) {} - std::string what() { return message; } -}; - -/// @brief Options for random seed. -enum class Seed { fixed, clock, invalid }; - -/// @brief Allowed Keys in config.yaml -static const std::vector getAllowedKeys() { - static const std::vector allowedKeys = {"n_k_points", - "n_occupied_total", - "n_unoccupied_total", - "n_isdf_vexc", - "n_isdf_wscr_occupied", - "n_isdf_wscr_unoccupied", - "max_lanczos_iterations", - "omega_range", - "n_omega", - "max_cvt_iterations", - "cvt_convergence_criterium", - "seed_source"}; - return allowedKeys; -} - -/// @brief Mandatory keys in config.yaml. These do not have a default value. -static const std::vector getMandatoryKeys() { - static const std::vector allowedKeys = {"n_k_points", - "n_occupied_total", - "n_unoccupied_total", - "n_isdf_vexc", - "n_isdf_wscr_occupied", - "n_isdf_wscr_unoccupied", - "max_lanczos_iterations", - "omega_range", - "n_omega"}; - return allowedKeys; -} - -/// @brief Default configuration values for non mandatory keys. -struct DefaultConfig { - types::size max_cvt_Itereations = 1000; - types::real_dp cvt_convergence_criterium = 1.e-5; - Seed seed_source = Seed::clock; - - DefaultConfig() = default; -}; - -/// @brief Class for handling the configuration of the program -class Config { - public: - /** - * @brief Number of **k**-points. - */ - types::size n_k_points; - - /** - * @brief Number of occupied bands cumulative over the **k**-points. - * @details \p n_occupied_total + \p n_occupied_total must be divisable by \p n_k_points - */ - types::size n_occupied_total; - - /** - * @brief Number of unoccupied bands cumulative over the **k**-points. - */ - types::size n_unoccupied_total; - - /** - * @brief Number of interpolation points for occupied unoccupied pairing. - * @details Must be <= \p n_occupied_total * \p n_unoccupied_total / \p n_k_points. - */ - types::size n_isdf_vexc; - - /** - * @brief Number of interpolation points for occupied unoccupied pairing. - * @details Must be <= \p n_occupied_total ** 2. - */ - types::size n_isdf_wscr_occupied; - - /** - * @brief Number of interpolation points for occupied unoccupied pairing. - * @details Must be <= \p n_unoccupied_total ** 2. - */ - types::size n_isdf_wscr_unoccupied; - - /** - * @brief Number of Lanczos iterations. - * @details Must be <= \p n_occupied_total * \p n_unoccupied_total / \p n_k_points. - */ - types::size max_lanczos_iterations; - - /** - * @brief Energy range for calculating the spectrum. - * @details The lower limit (left value) must be smaller than the upper limit (right value). - */ - std::array omega_range; - - /** - * @brief Number of energy sampling points. - */ - types::size n_omega; - - /** - * @brief Max. iterations for CVT. - */ - types::size max_cvt_iterations; - - /** - * @brief CVT convergence criterium - */ - types::real_dp cvt_convergence_criterium; - - /** - * @brief Seed source for random number generation. - * @details Must be one of - * - `"fixed"` for using a fixed seed - * - `"clock"` for using the system clock as seed. - */ - Seed seed_source; - - /** - * @brief Initialize the configuration from a yaml node \p configYaml. - * - * @details Initialize the configuration from a yaml node \p configYaml and - * check that the node only contains allowed keys \p allowedKeys and defines all - * mandatory keys \p mandatoryKeys . - * value is initialized from \p DefaultConfig. - * - * @param[in] configYaml Yaml node that contains the configuration. - * @param[in] allowedKeys List of allowed keys. - * @return instance initialized with values from config.yaml - * @throws InvalidKeyException - * @throws MissingKeyException - * @throws InvalidConfigurationException - */ - Config(const YAML::Node &configYamlNode, const std::vector &allowedKeys = getAllowedKeys(), - const std::vector &mandatoryKeys = getMandatoryKeys(), - const DefaultConfig &defaults = DefaultConfig()); - - /** - * @brief Validate configurataions. - * @details A valid configuration follows the rules described in the documentation of each attribute. - * @throws InvalidConfigurationException - */ - void validate(); -}; - -} // namespace config -} // namespace data_processing -} // namespace flash - -#endif // FLASH_CONFIG_H` diff --git a/dev/libs/data_processing/include/data_processing/read_hdf5.h b/dev/libs/data_processing/include/data_processing/read_hdf5.h deleted file mode 100644 index 9c26abf..0000000 --- a/dev/libs/data_processing/include/data_processing/read_hdf5.h +++ /dev/null @@ -1,29 +0,0 @@ - -#ifndef FLASH_READ_H -#define FLASH_READ_H - -#include -#include - -#include - -#include - -namespace flash { -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 - */ -flash::types::DVector readDoubleVectorHDF5(const std::string &filename, const std::string &datasetName); - -} // namespace read_hdf5 -} // namespace data_processing -} // namespace flash - -#endif // FLASH_READ_H \ No newline at end of file diff --git a/dev/libs/data_processing/src/config.cpp b/dev/libs/data_processing/src/config.cpp deleted file mode 100644 index 5d638e0..0000000 --- a/dev/libs/data_processing/src/config.cpp +++ /dev/null @@ -1,178 +0,0 @@ -#include - -namespace tp = flash::types; -using namespace flash::data_processing::config; - -inline std::map seedToStringDefault{{Seed::fixed, "fixed"}, {Seed::clock, "clock"}}; - -inline std::map stringToSeedDefault{{"fixed", Seed::fixed}, {"clock", Seed::clock}}; - -Seed nodeToSeed(const YAML::Node &node, const std::string &key, const Seed &defaultValue, - const std::map &stringToSeed = stringToSeedDefault) { - try { - return stringToSeed.at(node[key].as()); - } catch (YAML::InvalidNode) { - return defaultValue; - } catch (std::out_of_range) { - throw InvalidConfigurationException("Invalid option for seed."); - } - return Seed::invalid; -} - -template -T nodeToValue(const YAML::Node &node, std::string msg) { - try { - return node.as(); - } catch (...) { - throw InvalidConfigurationException(msg); - } - return T(); -} - -template -T nodeToValueWithDefault(const YAML::Node &node, const std::string &key, const T &defaultValue, std::string msg) { - try { - return node[key].as(); - ; - } catch (YAML::InvalidNode) { - return defaultValue; - } catch (...) { - throw InvalidConfigurationException(msg); - } - return T(); -} - -template -auto nodeToArray(const YAML::Node &node, bool (*rule)(T value), std::string msg) { - try { - std::array values; - tp::size idx = 0; - for (auto element : node) { - values[idx] = node.as(); - } - return values; - } catch (...) { - throw InvalidConfigurationException(msg); - } - return std::array(); -} - -Config::Config(const YAML::Node &configYamlNode, const std::vector &allowedKeys, - const std::vector &mandatoryKeys, const DefaultConfig &defaults) { - - // extract keys from yaml node - std::vector keysInNode; - for (auto kv : configYamlNode) { - auto key = kv.first.as(); - keysInNode.push_back(key); - } - - // verify that all keys from keysInNode that are in allowedKeys - for (auto key : keysInNode) { - if (std::find(allowedKeys.begin(), allowedKeys.end(), key) == allowedKeys.end()) { - throw InvalidKeyException("Configuration has a forbidden parameter: " + key + " = " + - configYamlNode[key].as()); - } - } - - // verify that keys from mandatoryKeys are in keysInNode - for (auto key : mandatoryKeys) { - if (std::find(keysInNode.begin(), keysInNode.end(), key) == keysInNode.end()) { - throw MissingKeyException("Configuration is missing a mandatory parameter: " + key); - } - } - - try { - n_k_points = nodeToValue(configYamlNode["n_k_points"], "n_k_points is wrongly initialized."); - n_occupied_total = - nodeToValue(configYamlNode["n_occupied_total"], "n_occupied_total is wrongly initialized."); - n_unoccupied_total = - nodeToValue(configYamlNode["n_unoccupied_total"], "n_unoccupied_total is wrongly initialized."); - n_isdf_vexc = nodeToValue(configYamlNode["n_isdf_vexc"], "n_isdf_vexc is wrongly initialized."); - n_isdf_wscr_occupied = nodeToValue(configYamlNode["n_isdf_wscr_occupied"], - "n_isdf_wscr_occupied is wrongly initialized."); - n_isdf_wscr_unoccupied = nodeToValue(configYamlNode["n_isdf_wscr_unoccupied"], - "n_isdf_wscr_unoccupied is wrongly initialized."); - max_lanczos_iterations = nodeToValue(configYamlNode["max_lanczos_iterations"], - "max_lanczos_iterations is wrongly initialized."); - omega_range = nodeToValue>(configYamlNode["omega_range"], - "omega_range is wrongly initialized."); - n_omega = nodeToValue(configYamlNode["n_omega"], "n_omega is wrongly initialized."); - max_cvt_iterations = - nodeToValueWithDefault(configYamlNode, "max_cvt_iterations", defaults.max_cvt_Itereations, - "max_cvt_iterations is wrongly initialized."); - cvt_convergence_criterium = nodeToValueWithDefault( - 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."); - } - // Rule for n_occupied_total - if (n_occupied_total == 0) { - throw InvalidConfigurationException("n_occupied_total must be > 0."); - } - // Rule for n_unoccupied_total - if (n_unoccupied_total == 0) { - throw InvalidConfigurationException("n_unoccupied_total must be > 0."); - } - // Rule for n_occupied_total + n_unoccupied_total - if ((n_unoccupied_total + n_occupied_total) % n_k_points != 0) { - 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) { - throw InvalidConfigurationException("n_isdf_vexc must be > 0."); - } - 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) { - throw InvalidConfigurationException("n_isdf_wscr_occupied must be > 0."); - } - 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) { - throw InvalidConfigurationException("n_isdf_wscr_unoccupied must be > 0."); - } - 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) { - throw InvalidConfigurationException("max_lanczos_iterations must be > 0."); - } - // Rule for omega_range - if (sizeof(omega_range) != 2) { - throw InvalidConfigurationException("omega_range must contain exactly 2 values."); - } - 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) { - throw InvalidConfigurationException("n_omega must be > 0."); - } - // Rule for max_cvt_iterations - if (cvt_convergence_criterium == 0) { - throw InvalidConfigurationException("cvt_convergence_criterium must be > 0."); - } - // Rule for seed_source - if (seed_source == Seed::invalid) { - throw InvalidConfigurationException("seed_source is invalid."); - } -} diff --git a/dev/libs/data_processing/src/read_hdf5.cpp b/dev/libs/data_processing/src/read_hdf5.cpp deleted file mode 100644 index f242acc..0000000 --- a/dev/libs/data_processing/src/read_hdf5.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include - -namespace tp = flash::types; -using namespace flash::data_processing::read_hdf5; - -tp::DVector readDoubleVectorHDF5(const std::string &filename, const std::string &datasetName) { - try { - // Open the HDF5 file - H5::H5File file(filename, H5F_ACC_RDONLY); - - // Open the dataset - H5::DataSet dataset = file.openDataSet(datasetName); - - // Get the dataspace and the size of the dataset - H5::DataSpace dataspace = dataset.getSpace(); - hsize_t dims[1]; - int ndims = dataspace.getSimpleExtentDims(dims, nullptr); - - // Read data into a std::vector - std::vector buffer(dims[0]); - dataset.read(buffer.data(), H5::PredType::NATIVE_DOUBLE); - - // Convert std::vector to tp::DVector - tp::DVector eigenVector = Eigen::Map(buffer.data(), buffer.size()); - - return eigenVector; - } catch (H5::FileIException &error) { - error.printErrorStack(); - } catch (H5::DataSetIException &error) { - error.printErrorStack(); - } catch (H5::DataSpaceIException &error) { - error.printErrorStack(); - } - - // Return an empty vector in case of an error - return tp::DVector(); -} \ No newline at end of file diff --git a/dev/libs/electrons/CMakeLists.txt b/dev/libs/electrons/CMakeLists.txt deleted file mode 100644 index bfc48ef..0000000 --- a/dev/libs/electrons/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -#project(lightning-config) - -add_library(electrons src/electrons.cpp) - -target_link_libraries(electrons - PRIVATE - Eigen3::Eigen - types) - -target_include_directories(electrons - PUBLIC - include - PRIVATE - src -) \ No newline at end of file diff --git a/dev/libs/electrons/include/electrons/electrons.h b/dev/libs/electrons/include/electrons/electrons.h deleted file mode 100644 index 9164981..0000000 --- a/dev/libs/electrons/include/electrons/electrons.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// Created by benedikt on 29.03.24. -// - -#ifndef FLASH_ELECTRONS_H -#define FLASH_ELECTRONS_H - -#include - -#include - -namespace electron { - -class ElectronSystem { - private: - public: - // ElectronSystem(const DMatrix $energies, const DMatrix $occupation, const std::size_t &nKPoints); -}; - -} // namespace electron - -#endif // FLASH_ELECTRONS_H diff --git a/dev/libs/electrons/src/electrons.cpp b/dev/libs/electrons/src/electrons.cpp deleted file mode 100644 index d5d1ef3..0000000 --- a/dev/libs/electrons/src/electrons.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// -// Created by benedikt on 29.03.24. -// - -#include "electrons/electrons.h" - -using namespace electron; - -// ElectronSystem::ElectronSystem(const DMatrix $energies, const DMatrix $occupation, const std::size_t &nKPoints) { - -// } diff --git a/dev/libs/types/CMakeLists.txt b/dev/libs/types/CMakeLists.txt deleted file mode 100644 index afd9f49..0000000 --- a/dev/libs/types/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -#project(lightning-types) - -add_library(types src/types.cpp) - -target_link_libraries(types Eigen3::Eigen) - -target_include_directories(types - PUBLIC - include - PRIVATE - src -) \ No newline at end of file diff --git a/dev/libs/types/include/types/types.h b/dev/libs/types/include/types/types.h deleted file mode 100644 index d8b1e51..0000000 --- a/dev/libs/types/include/types/types.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef FLASH_TYPES_H -#define FLASH_TYPES_H - -#include - -#include -#include -#include -#include -#include - -namespace flash { -namespace types { - -typedef std::size_t size; -typedef std::double_t real_dp; -typedef std::complex complex_dp; - -typedef Eigen::Vector DVector; -typedef Eigen::Vector CVector; -typedef Eigen::Matrix DMatrix; -typedef Eigen::Matrix CMatrix; - -} // namespace types -} // namespace flash - -#endif // FLASH_TYPES_H \ No newline at end of file diff --git a/dev/libs/types/src/types.cpp b/dev/libs/types/src/types.cpp deleted file mode 100644 index cb68c10..0000000 --- a/dev/libs/types/src/types.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// -// Created by benedikt on 15.07.24. -// - -#include - -using namespace flash; diff --git a/dev/tests/CMakeLists.txt b/dev/tests/CMakeLists.txt index 9a2bd2d..e69de29 100644 --- a/dev/tests/CMakeLists.txt +++ b/dev/tests/CMakeLists.txt @@ -1 +0,0 @@ -add_subdirectory(data_processing) \ No newline at end of file diff --git a/dev/tests/data_processing/CMakeLists.txt b/dev/tests/data_processing/CMakeLists.txt deleted file mode 100644 index 70d3c79..0000000 --- a/dev/tests/data_processing/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# Add the test executable -add_executable(data_processing_tests) - -# Collect all .cpp files in the 'src' directory -file(GLOB_RECURSE SOURCE_FILES "src/*.cpp") - -# Add the collected source files to the target -target_sources(data_processing_tests PRIVATE ${SOURCE_FILES}) - -# Link the library and Catch2 to the test executable -target_link_libraries(data_processing_tests - PRIVATE - Catch2::Catch2WithMain - data_processing - yaml-cpp -) - -target_include_directories(data_processing_tests - PRIVATE - src - ${catch2_SOURCE_DIR}/include -) - - -# Add the tests to CTest -add_test(NAME data_processing_test COMMAND data_processing_tests) \ No newline at end of file diff --git a/dev/tests/data_processing/src/config_test.cpp b/dev/tests/data_processing/src/config_test.cpp deleted file mode 100644 index 6624517..0000000 --- a/dev/tests/data_processing/src/config_test.cpp +++ /dev/null @@ -1,228 +0,0 @@ -#define CATCH_CONFIG_MAIN - -#include -#include - -#include -#include - -namespace tp = flash::types; -using namespace flash::data_processing::config; - -/** - * @brief string of a valid config.yaml that defines all parameters. - */ -std::string config_yaml = R"( - n_k_points: 50 - n_occupied_total: 13 - n_unoccupied_total: 37 - n_isdf_vexc: 3 - n_isdf_wscr_occupied: 4 - n_isdf_wscr_unoccupied: 5 - max_lanczos_iterations: 200 - omega_range: [1.0, 2.0] - n_omega: 1500 - max_cvt_iterations: 333 - cvt_convergence_criterium: 1.e-6 - seed_source: fixed -)"; - -/** - * @brief string of a valid config.yaml that defines only mandatory parameters. - */ -std::string default_config_yaml = R"( - n_k_points: 50 - n_occupied_total: 13 - n_unoccupied_total: 37 - n_isdf_vexc: 3 - n_isdf_wscr_occupied: 4 - n_isdf_wscr_unoccupied: 5 - max_lanczos_iterations: 200 - omega_range: [1.0, 2.0] - n_omega: 1500 -)"; - -TEST_CASE("Test Config construction from a valid YAML::node that defines all parameters.", "[valid-config]") { - Config params(YAML::Load(config_yaml)); - REQUIRE(params.n_k_points == 50); - REQUIRE(params.n_occupied_total == 13); - REQUIRE(params.n_unoccupied_total == 37); - REQUIRE(params.n_isdf_vexc == 3); - REQUIRE(params.n_isdf_wscr_occupied == 4); - REQUIRE(params.n_isdf_wscr_unoccupied == 5); - REQUIRE(params.max_lanczos_iterations == 200); - REQUIRE(params.omega_range == std::array{1.0, 2.0}); - REQUIRE(params.n_omega == 1500); - REQUIRE(params.max_cvt_iterations == 333); - REQUIRE(params.cvt_convergence_criterium == 1e-6); - REQUIRE(params.seed_source == Seed::fixed); -} - -TEST_CASE("Test Config construction from a valid YAML::node that defines not all parameters.", - "[valid-config-default]") { - Config params(YAML::Load(default_config_yaml)); - REQUIRE(params.n_k_points == 50); - REQUIRE(params.n_occupied_total == 13); - REQUIRE(params.n_unoccupied_total == 37); - REQUIRE(params.n_isdf_vexc == 3); - REQUIRE(params.n_isdf_wscr_occupied == 4); - REQUIRE(params.n_isdf_wscr_unoccupied == 5); - REQUIRE(params.max_lanczos_iterations == 200); - REQUIRE(params.omega_range == std::array{1.0, 2.0}); - REQUIRE(params.n_omega == 1500); - REQUIRE(params.max_cvt_iterations == 1000); - REQUIRE(params.cvt_convergence_criterium == 1e-5); - REQUIRE(params.seed_source == Seed::clock); -} - -TEST_CASE("Test Config construction from an invalid YAML::node that uses a forbidden key.", - "[invalid-config-missing-param]") { - auto configNode = YAML::Load(config_yaml); - configNode["naughty"] = "no"; // assign value to forbidden key "naugty" - REQUIRE_THROWS_AS(Config(configNode), InvalidKeyException); -} - -TEST_CASE("Test Config construction from an invalid YAML::node that does not define all mandatory parameters.", - "[invalid-config-missing-param]") { - auto configNode = YAML::Load(config_yaml); - configNode.remove("n_k_points"); - REQUIRE_THROWS_AS(Config(configNode), MissingKeyException); - - configNode = YAML::Load(config_yaml); - configNode.remove("n_occupied_total"); - REQUIRE_THROWS_AS(Config(configNode), MissingKeyException); - - configNode = YAML::Load(config_yaml); - configNode.remove("n_unoccupied_total"); - REQUIRE_THROWS_AS(Config(configNode), MissingKeyException); - - configNode = YAML::Load(config_yaml); - configNode.remove("n_isdf_vexc"); - REQUIRE_THROWS_AS(Config(configNode), MissingKeyException); - - configNode = YAML::Load(config_yaml); - configNode.remove("n_unoccupied_total"); - REQUIRE_THROWS_AS(Config(configNode), MissingKeyException); - - configNode = YAML::Load(config_yaml); - configNode.remove("n_isdf_vexc"); - REQUIRE_THROWS_AS(Config(configNode), MissingKeyException); - - configNode = YAML::Load(config_yaml); - configNode.remove("n_isdf_wscr_occupied"); - REQUIRE_THROWS_AS(Config(configNode), MissingKeyException); - - configNode = YAML::Load(config_yaml); - configNode.remove("n_unoccupied_total"); - REQUIRE_THROWS_AS(Config(configNode), MissingKeyException); - - configNode = YAML::Load(config_yaml); - configNode.remove("max_lanczos_iterations"); - REQUIRE_THROWS_AS(Config(configNode), MissingKeyException); - - configNode = YAML::Load(config_yaml); - configNode.remove("omega_range"); - REQUIRE_THROWS_AS(Config(configNode), MissingKeyException); - - configNode = YAML::Load(config_yaml); - configNode.remove("n_omega"); - REQUIRE_THROWS_AS(Config(configNode), MissingKeyException); -} - -TEST_CASE("Test Config construction from an invalid YAML::node that defines a parameter illegally.", - "[invalid-config]") { - auto configNode = YAML::Load(config_yaml); - configNode["n_isdf_vexc"] = "nope"; - REQUIRE_THROWS_AS(Config(configNode), InvalidConfigurationException); - - configNode = YAML::Load(config_yaml); - configNode["cvt_convergence_criterium"] = "nope"; - REQUIRE_THROWS_AS(Config(configNode), InvalidConfigurationException); - - configNode = YAML::Load(config_yaml); - configNode["seed_source"] = "nope"; - REQUIRE_THROWS_AS(Config(configNode), InvalidConfigurationException); - - configNode = YAML::Load(config_yaml); - configNode["omega_range"] = 1.0; - REQUIRE_THROWS_AS(Config(configNode), InvalidConfigurationException); -} - -TEST_CASE("Test Config construction from an invalid YAML::node that defines a parameter wrongly.", "[invalid-config]") { - // Check n_k_points rule - auto configNode = YAML::Load(config_yaml); - configNode["n_k_points"] = 0; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - - // Check n_occupied_total rule - configNode = YAML::Load(config_yaml); - configNode["n_occupied_total"] = 0; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - - // Check n_unoccupied_total rule - configNode = YAML::Load(config_yaml); - configNode["n_unoccupied_total"] = 0; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - - // Check n_occupied_total + n_unoccupied_total rule - configNode = YAML::Load(config_yaml); - configNode["n_occupied_total"] = 13; - configNode["n_unoccupied_total"] = 38; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - - // Checkn_isdf_vexc rules - configNode = YAML::Load(config_yaml); - configNode["n_isdf_vexc"] = 0; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - configNode["n_isdf_vexc"] = 10; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - - // n_isdf_wscr_occupied rules - configNode = YAML::Load(config_yaml); - configNode["n_isdf_wscr_occupied"] = 0; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - configNode["n_isdf_wscr_occupied"] = 170; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - - // n_isdf_wscr_unoccupied rules - configNode = YAML::Load(config_yaml); - configNode["n_isdf_wscr_unoccupied"] = 0; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - configNode["n_isdf_wscr_unoccupied"] = 1407; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - - // max_lanczos_iterations rule - configNode = YAML::Load(config_yaml); - configNode["max_lanczos_iterations"] = 0; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - - // omega_range rules - configNode = YAML::Load(config_yaml); - configNode.remove("omega_range"); - configNode["omega_range"].push_back(2.0); - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - configNode.remove("omega_range"); - configNode["omega_range"].push_back(2.0); - configNode["omega_range"].push_back(1.0); - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - configNode.remove("omega_range"); - configNode["omega_range"].push_back(1.0); - configNode["omega_range"].push_back(2.0); - configNode["omega_range"].push_back(3.0); - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - - // n_omega rule - configNode = YAML::Load(config_yaml); - configNode["n_omega"] = 0; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - - // max_cvt_iterations rule - configNode = YAML::Load(config_yaml); - configNode["max_cvt_iterations"] = 0; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); - - // cvt_convergence_criterium rule - configNode = YAML::Load(config_yaml); - configNode["cvt_convergence_criterium"] = 0; - REQUIRE_THROWS_AS(Config(configNode).validate(), InvalidConfigurationException); -}