Skip to content

Commit c289970

Browse files
committed
minor cleanup
1 parent 77e3139 commit c289970

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

src/core/config.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ std::expected<void, std::string> Config::init(const std::string &input_file_path
5555

5656
const auto &config = parse_result.unwrap();
5757

58-
if (const auto result = parse_from(config); !result.has_value()) {
58+
if (const auto result = parse_from_toml(config); !result.has_value()) {
5959
const std::string error = fmt::format("failed to parse configuration file: {}", result.error());
6060
SPDLOG_CRITICAL(error);
6161
return std::unexpected(error);
@@ -75,13 +75,22 @@ std::expected<void, std::string> Config::init(const std::string &input_file_path
7575
}
7676

7777
SPDLOG_INFO("configuration summary");
78+
SPDLOG_INFO("end time (s): {:.3e}", end_time);
7879
SPDLOG_INFO("bounding box (m): {:.3e} x {:.3e} x {:.3e}", len.x, len.y, len.z);
80+
SPDLOG_INFO("maximum frequency to resolve (Hz): {:.3e}", max_frequency);
81+
SPDLOG_INFO("number of voxels to resolve minimum wavelength: {}", num_vox_min_wavelength);
82+
SPDLOG_INFO("number of voxels to resolve minimum feature size: {}", num_vox_min_feature);
83+
SPDLOG_INFO("bounding box relative permittivity: {:.3e}", ep_r);
84+
SPDLOG_INFO("bounding box relative permeability: {:.3e}", mu_r);
85+
SPDLOG_INFO("bounding box conductivity (S / m): {:.3e}", sigma);
86+
SPDLOG_INFO("path to store output data: {}", out.string());
87+
SPDLOG_INFO("period between logging steps {:.3e}", log_period);
7988

8089
SPDLOG_TRACE("exit Config::init");
8190
return {};
8291
}
8392

84-
std::expected<void, std::string> Config::parse_from(const toml::basic_value<toml::type_config> &config) noexcept {
93+
std::expected<void, std::string> Config::parse_from_toml(const toml::basic_value<toml::type_config> &config) noexcept {
8594
SPDLOG_TRACE("enter Config::parse_from");
8695

8796
if (auto result = parse_item<fp_t>(config, "time", "end_time"); result.has_value()) {
@@ -297,8 +306,9 @@ std::expected<std::filesystem::path, std::string> Config::setup_out(const std::s
297306
}
298307

299308
} catch (const std::filesystem::filesystem_error &err) {
300-
SPDLOG_CRITICAL("unable to create output directory structure: {}", err.what());
301-
return std::unexpected<std::string>(err.what());
309+
const std::string error = fmt::format("unable to create output directory structure: {}", err.what());
310+
SPDLOG_CRITICAL(error);
311+
return std::unexpected(error);
302312
}
303313

304314
SPDLOG_TRACE("exit Config::setup_dirs with success");

src/core/config.h

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,22 @@ struct Config {
8585
*/
8686
[[nodiscard]] std::expected<void, std::string> init(const std::string &input_file_path) noexcept;
8787

88+
/*!
89+
* parses and sets internal state from a toml configuration
90+
* @param config toml configuration
91+
* @return std::expected<void, std::string> for {success, error} cases respectively
92+
*/
8893
[[nodiscard]] std::expected<void, std::string>
89-
parse_from(const toml::basic_value<toml::type_config> &config) noexcept;
94+
parse_from_toml(const toml::basic_value<toml::type_config> &config) noexcept;
9095

96+
/*!
97+
* parses item of type T from toml configuration at a given table and key
98+
* @tparam T type to be parsed
99+
* @param config toml configuration
100+
* @param table table to parse from
101+
* @param key item key in table
102+
* @return std::expected<T, std::string> for {success, error} cases respectively
103+
*/
91104
template <typename T>
92105
std::expected<T, std::string> parse_item(const toml::basic_value<toml::type_config> &config, const std::string table,
93106
const std::string key) noexcept {
@@ -143,8 +156,21 @@ struct Config {
143156
return name;
144157
}
145158

159+
/*!
160+
* validates internal state against preconfigured value ranges
161+
* @return std::expected<void, std::string> for {success, error} cases respectively
162+
*/
146163
[[nodiscard]] std::expected<void, std::string> validate() noexcept;
147164

165+
/*!
166+
* checks to see if value is within a given range
167+
* @tparam T type of value
168+
* @param value value to check
169+
* @param lower lower end of range
170+
* @param upper upper end of range
171+
* @param bounds inclusivity/exclusivity of lower and upper bounds respectively
172+
* @return {true, false} for {in, out} of range respectively
173+
*/
148174
template <typename T>
149175
static bool in_range(const T value, const T lower, const T upper, const Bounds bounds) noexcept {
150176
SPDLOG_TRACE("enter Config::in_range");
@@ -174,6 +200,12 @@ struct Config {
174200
return status;
175201
}
176202

203+
/*!
204+
* sets up output filesystem at out
205+
* @param id unique identifier
206+
* @return std::expected<std::filesystem::path, std::string> for {success, error} cases respectively
207+
* @note std::filesystem::path is a path to a unique output folder which is used to store data from a given run
208+
*/
177209
std::expected<std::filesystem::path, std::string> setup_out(const std::string &id) const noexcept;
178210
};
179211

0 commit comments

Comments
 (0)