build(libconstants): changed over to use external libconstants
this is the same module as before just broken out into its own subproject
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -68,6 +68,7 @@ subprojects/pybind11*/
|
||||
subprojects/packagecache/
|
||||
subprojects/hypre/
|
||||
subprojects/qhull/
|
||||
subprojects/libconstants/
|
||||
|
||||
qhull.wrap
|
||||
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
subdir('const')
|
||||
subdir('atomic')
|
||||
subdir('atomic')
|
||||
|
||||
2
build-config/fourdst/libconstants/meson.build
Normal file
2
build-config/fourdst/libconstants/meson.build
Normal file
@@ -0,0 +1,2 @@
|
||||
const_p = subproject('libconstants')
|
||||
const_dep = const_p.get_variable('const_dep')
|
||||
1
build-config/fourdst/meson.build
Normal file
1
build-config/fourdst/meson.build
Normal file
@@ -0,0 +1 @@
|
||||
subdir('libconstants')
|
||||
@@ -1,5 +1,7 @@
|
||||
cmake = import('cmake')
|
||||
|
||||
subdir('fourdst')
|
||||
|
||||
subdir('mfem')
|
||||
subdir('yaml-cpp')
|
||||
subdir('quill')
|
||||
@@ -20,4 +22,4 @@ elif configErr == 'harsh'
|
||||
commonCppArgs += ['-DCONFIG_HARSH']
|
||||
endif
|
||||
|
||||
add_project_arguments(commonCppArgs, language: 'cpp')
|
||||
add_project_arguments(commonCppArgs, language: 'cpp')
|
||||
|
||||
@@ -41,10 +41,6 @@
|
||||
#include "config.h"
|
||||
#include "quill/LogMacros.h"
|
||||
|
||||
namespace serif::constant {
|
||||
class Constants;
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
|
||||
// interpolating polynomila function definitions
|
||||
@@ -246,7 +242,7 @@ namespace serif::eos::helmholtz {
|
||||
serif::probe::LogManager& logManager = serif::probe::LogManager::getInstance();
|
||||
quill::Logger* logger = logManager.getLogger(logFile);
|
||||
|
||||
serif::constant::Constants& constants = serif::constant::Constants::getInstance();
|
||||
fourdst::constant::Constants& constants = fourdst::constant::Constants::getInstance();
|
||||
const double pi = std::numbers::pi;
|
||||
const double amu = constants.get("u").value;
|
||||
const double h = constants.get("h").value;
|
||||
|
||||
@@ -9,7 +9,7 @@ subdir('config')
|
||||
subdir('probe')
|
||||
|
||||
# Physically Informed Libraries
|
||||
subdir('constants')
|
||||
# subdir('constants')
|
||||
subdir('composition')
|
||||
|
||||
# Asset Libraries
|
||||
|
||||
@@ -245,7 +245,7 @@ namespace serif::network::approx8{
|
||||
// a Jacobian matrix for implicit solvers
|
||||
|
||||
void Jacobian::operator() ( const vector_type &y, matrix_type &J, double /* t */, vector_type &dfdt ) const {
|
||||
serif::constant::Constants& constants = serif::constant::Constants::getInstance();
|
||||
fourdst::constant::Constants& constants = fourdst::constant::Constants::getInstance();
|
||||
const double avo = constants.get("N_a").value;
|
||||
const double clight = constants.get("c").value;
|
||||
// EOS
|
||||
@@ -350,7 +350,7 @@ namespace serif::network::approx8{
|
||||
}
|
||||
|
||||
void ODE::operator() ( const vector_type &y, vector_type &dydt, double /* t */) const {
|
||||
const serif::constant::Constants& constants = serif::constant::Constants::getInstance();
|
||||
const fourdst::constant::Constants& constants = fourdst::constant::Constants::getInstance();
|
||||
const double avo = constants.get("N_a").value;
|
||||
const double clight = constants.get("c").value;
|
||||
|
||||
|
||||
@@ -10,44 +10,44 @@ namespace py = pybind11;
|
||||
|
||||
|
||||
void register_const_bindings(pybind11::module &const_submodule) {
|
||||
py::class_<serif::constant::Constant>(const_submodule, "Constant")
|
||||
.def_readonly("name", &serif::constant::Constant::name)
|
||||
.def_readonly("value", &serif::constant::Constant::value)
|
||||
.def_readonly("uncertainty", &serif::constant::Constant::uncertainty)
|
||||
.def_readonly("unit", &serif::constant::Constant::unit)
|
||||
.def_readonly("reference", &serif::constant::Constant::reference)
|
||||
.def("__repr__", [](const serif::constant::Constant &c) {
|
||||
py::class_<fourdst::constant::Constant>(const_submodule, "Constant")
|
||||
.def_readonly("name", &fourdst::constant::Constant::name)
|
||||
.def_readonly("value", &fourdst::constant::Constant::value)
|
||||
.def_readonly("uncertainty", &fourdst::constant::Constant::uncertainty)
|
||||
.def_readonly("unit", &fourdst::constant::Constant::unit)
|
||||
.def_readonly("reference", &fourdst::constant::Constant::reference)
|
||||
.def("__repr__", [](const fourdst::constant::Constant &c) {
|
||||
return "<Constant(name='" + c.name + "', value=" + std::to_string(c.value) +
|
||||
", uncertainty=" + std::to_string(c.uncertainty) +
|
||||
", unit='" + c.unit + "')>";
|
||||
});
|
||||
|
||||
py::class_<serif::constant::Constants>(const_submodule, "Constants")
|
||||
.def_property_readonly("loaded", &serif::constant::Constants::isLoaded)
|
||||
py::class_<fourdst::constant::Constants>(const_submodule, "Constants")
|
||||
.def_property_readonly("loaded", &fourdst::constant::Constants::isLoaded)
|
||||
.def_static("get",
|
||||
[](const std::string &name) {
|
||||
return py::cast(
|
||||
serif::constant::Constants::getInstance().get(name)
|
||||
fourdst::constant::Constants::getInstance().get(name)
|
||||
);
|
||||
},
|
||||
"Get a constant by name. Returns None if not found."
|
||||
)
|
||||
.def_static("has",
|
||||
[](const std::string &name) {
|
||||
return serif::constant::Constants::getInstance().has(name);
|
||||
return fourdst::constant::Constants::getInstance().has(name);
|
||||
},
|
||||
"Check if a constant exists by name.")
|
||||
.def_static("keys",
|
||||
[]() {
|
||||
return py::cast(
|
||||
serif::constant::Constants::getInstance().keys()
|
||||
fourdst::constant::Constants::getInstance().keys()
|
||||
);
|
||||
},
|
||||
"Get a list of all constant names.")
|
||||
.def_static("__class_getitem__",
|
||||
[](const std::string &name) {
|
||||
return py::cast(
|
||||
serif::constant::Constants::getInstance().get(name)
|
||||
fourdst::constant::Constants::getInstance().get(name)
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
7
subprojects/libconstants.wrap
Normal file
7
subprojects/libconstants.wrap
Normal file
@@ -0,0 +1,7 @@
|
||||
[wrap-git]
|
||||
url = git@github.com:4D-STAR/libconstants.git
|
||||
revision = v1.1
|
||||
depth = 1
|
||||
|
||||
[provide]
|
||||
libconstants = const_dep
|
||||
@@ -13,7 +13,6 @@ foreach test_file : test_sources
|
||||
test_file,
|
||||
dependencies: [gtest_dep, config_dep, gtest_main],
|
||||
include_directories: include_directories('../../src/config/public'),
|
||||
link_with: libconst, # Link the dobj library
|
||||
install_rpath: '@loader_path/../../src' # Ensure runtime library path resolves correctly
|
||||
)
|
||||
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "const.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* @file constTest.cpp
|
||||
* @brief Unit tests for the const class.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Test suite for the const class.
|
||||
*/
|
||||
class constTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
serif::constant::Constants::getInstance();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @test Verify default constructor initializes correctly.
|
||||
*/
|
||||
TEST_F(constTest, DefaultConstructor) {
|
||||
EXPECT_NO_THROW(serif::constant::Constants::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test Verify constructor initializes with provided data and metadata.
|
||||
*/
|
||||
TEST_F(constTest, isLoaded) {
|
||||
|
||||
EXPECT_NO_THROW(serif::constant::Constants::getInstance().isLoaded());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test Verify get method returns the correct constant.
|
||||
*/
|
||||
TEST_F(constTest, GetMethod) {
|
||||
serif::constant::Constants& obj = serif::constant::Constants::getInstance();
|
||||
EXPECT_DOUBLE_EQ(obj.get("c").value, 2.99792458e10);
|
||||
EXPECT_EQ(obj.get("c").unit, "cm / s");
|
||||
EXPECT_DOUBLE_EQ(obj.get("c").uncertainty, 0.0);
|
||||
EXPECT_EQ(obj.get("c").reference, "CODATA2022");
|
||||
}
|
||||
|
||||
/**
|
||||
* @test Verify [] opperators returns the correct constant.
|
||||
*/
|
||||
TEST_F(constTest, SubscriptOperator) {
|
||||
serif::constant::Constants& obj = serif::constant::Constants::getInstance();
|
||||
EXPECT_DOUBLE_EQ(obj["c"].value, 2.99792458e10);
|
||||
EXPECT_EQ(obj["c"].unit, "cm / s");
|
||||
EXPECT_DOUBLE_EQ(obj["c"].uncertainty, 0.0);
|
||||
EXPECT_EQ(obj["c"].reference, "CODATA2022");
|
||||
}
|
||||
|
||||
/**
|
||||
* @test Verify that the has method returns the correct values
|
||||
*/
|
||||
TEST_F(constTest, HasMethod) {
|
||||
serif::constant::Constants& obj = serif::constant::Constants::getInstance();
|
||||
|
||||
EXPECT_TRUE(obj.has("c"));
|
||||
EXPECT_FALSE(obj.has("c4"));
|
||||
EXPECT_TRUE(obj.has("hbar"));
|
||||
}
|
||||
|
||||
TEST_F(constTest, KeysMethod) {
|
||||
serif::constant::Constants& obj = serif::constant::Constants::getInstance();
|
||||
std::set<std::string> checkKeys;
|
||||
checkKeys.insert("c");
|
||||
checkKeys.insert("wienK");
|
||||
checkKeys.insert("hbar");
|
||||
checkKeys.insert("g_h");
|
||||
checkKeys.insert("R_sun");
|
||||
|
||||
std::set<std::string> keys = obj.keys();
|
||||
|
||||
for (const auto& key : checkKeys) {
|
||||
bool found = keys.find(key) != keys.end();
|
||||
EXPECT_TRUE(found);
|
||||
}
|
||||
|
||||
std::set<std::string> checkBadKeys;
|
||||
checkBadKeys.insert("c4");
|
||||
checkBadKeys.insert("wienK4");
|
||||
checkBadKeys.insert("hbar4");
|
||||
checkBadKeys.insert("g_h4");
|
||||
checkBadKeys.insert("R_sun4");
|
||||
|
||||
for (const auto& key : checkBadKeys) {
|
||||
bool found = keys.find(key) != keys.end();
|
||||
EXPECT_FALSE(found);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(constTest, StreamOperator) {
|
||||
serif::constant::Constants& obj = serif::constant::Constants::getInstance();
|
||||
std::ostringstream os;
|
||||
|
||||
os << obj.get("c");
|
||||
std::string expected = "<speed of light in vacuum: 2.99792e+10±0 cm / s (CODATA2022)>\n";
|
||||
|
||||
EXPECT_EQ(os.str(), expected);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
# Test files for const
|
||||
test_sources = [
|
||||
'constTest.cpp',
|
||||
]
|
||||
|
||||
foreach test_file : test_sources
|
||||
exe_name = test_file.split('.')[0]
|
||||
message('Building test: ' + exe_name)
|
||||
|
||||
# Create an executable target for each test
|
||||
test_exe = executable(
|
||||
exe_name,
|
||||
test_file,
|
||||
dependencies: [gtest_dep, const_dep, gtest_main],
|
||||
include_directories: include_directories('../../src/constants/public'),
|
||||
link_with: libconst, # Link the dobj library
|
||||
install_rpath: '@loader_path/../../src' # Ensure runtime library path resolves correctly
|
||||
)
|
||||
|
||||
# Add the executable as a test
|
||||
test(exe_name, test_exe)
|
||||
endforeach
|
||||
@@ -4,7 +4,6 @@ gtest_main = dependency('gtest_main', required: true)
|
||||
gtest_nomain_dep = dependency('gtest', main: false, required : true)
|
||||
|
||||
# Subdirectories for unit and integration tests
|
||||
subdir('const')
|
||||
subdir('meshIO')
|
||||
subdir('probe')
|
||||
subdir('config')
|
||||
|
||||
Reference in New Issue
Block a user