Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ jobs:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- uses: actions/setup-python@v6
with:
python-version: "3.13"
- uses: actions/download-artifact@v8
with:
pattern: dist-*
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ cmake.args = [
# Necessary to see build output from the actual compilation
build-verbosity = 1
skip = [
"pp311-macosx_arm64",
"*-win32",
"*-musllinux_*",
]
Expand Down
2 changes: 1 addition & 1 deletion src/griddyn/solvers/SolverInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static ChildClassFactoryArg<solvers::BasicSolver, SolverInterface, solvers::Basi
gBasicFactoryG(stringVec{"basic", "gauss"}, solvers::BasicSolver::Mode::gauss);
static ChildClassFactoryArg<solvers::BasicSolver, SolverInterface, solvers::BasicSolver::Mode>
gBasicFactoryGs(stringVec{"gs", "gauss-seidel"}, solvers::BasicSolver::Mode::gauss_seidel);
#ifdef GRIDYN_ENABLE_CVODE
#ifdef GRIDDYN_ENABLE_CVODE
static ChildClassFactory<solvers::BasicOdeSolver, SolverInterface>
gBasicOdeFactory(stringVec{"basicode", "euler"});
#else
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(library_gtest_sources
set(file_reader_gtest_sources
gtestHelperFunctions.cpp
libraryTests/testReaderInfo.cpp
libraryTests/testExampleReaders.cpp
libraryTests/testXML.cpp
libraryTests/testJsonReader.cpp
libraryTests/testElementReaders.cpp
Expand Down
170 changes: 93 additions & 77 deletions test/componentTests/testBlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "griddyn/simulation/Diagnostics.h"
#include <cstdio>
#include <gtest/gtest.h>
#include <iostream>
#include <map>
#include <string>
#include <utility>
Expand Down Expand Up @@ -45,9 +46,9 @@ TEST_F(BlockTests, TestGainBlock)
std::string recname = std::string(BLOCK_TEST_DIRECTORY "blocktest.dat");
TimeSeriesMulti<> ts3;
ts3.loadBinaryFile(recname);
ASSERT_GE(ts3.size(), 15u);
EXPECT_NEAR(ts3.data(0, 5) * 5, ts3.data(1, 5), std::abs(ts3.data(1, 5)) * 1e-8 + 1e-12);
EXPECT_NEAR(ts3.data(0, 15) * 5, ts3.data(1, 15), std::abs(ts3.data(1, 15)) * 1e-8 + 1e-12);
ASSERT_GE(ts3.size(), 15U);
EXPECT_NEAR(ts3.data(0, 5) * 5, ts3.data(1, 5), (std::abs(ts3.data(1, 5)) * 1e-8) + 1e-12);
EXPECT_NEAR(ts3.data(0, 15) * 5, ts3.data(1, 15), (std::abs(ts3.data(1, 15)) * 1e-8) + 1e-12);
int ret = remove(recname.c_str());

EXPECT_EQ(ret, 0);
Expand All @@ -65,8 +66,10 @@ TEST_F(BlockTests, BlockTest2)
std::string recname = std::string(BLOCK_TEST_DIRECTORY "blocktest.dat");
TimeSeriesMulti<> ts3(recname);

EXPECT_NEAR(ts3.data(0, 5) * 5, ts3.data(1, 5), std::abs(ts3.data(1, 5)) * 1e-5 + 1e-12);
EXPECT_NEAR(ts3.data(0, 280) * 5, ts3.data(1, 280), std::abs(ts3.data(1, 280)) * 1e-5 + 1e-12);
EXPECT_NEAR(ts3.data(0, 5) * 5, ts3.data(1, 5), (std::abs(ts3.data(1, 5)) * 1e-5) + 1e-12);
EXPECT_NEAR(ts3.data(0, 280) * 5,
ts3.data(1, 280),
(std::abs(ts3.data(1, 280)) * 1e-5) + 1e-12);
int ret = remove(recname.c_str());

EXPECT_EQ(ret, 0);
Expand Down Expand Up @@ -106,13 +109,13 @@ TEST_F(BlockTests, BlockTest4)
TimeSeriesMulti<> ts3;
ts3.loadBinaryFile(recname);

EXPECT_NEAR(ts3.data(1, 5), -0.5, std::abs(-0.5) * 1e-4 + 1e-12);
double iv = -0.5;
index_t pp;
for (pp = 0; pp < static_cast<index_t>(ts3.size()); ++pp) {
iv += 100 * ts3.data(0, pp) * 0.01;
EXPECT_NEAR(ts3.data(1, 5), -0.5, (std::abs(-0.5) * 1e-4) + 1e-12);
double initialValue = -0.5;
index_t pointIndex = 0;
for (pointIndex = 0; std::cmp_less(pointIndex, ts3.size()); ++pointIndex) {
initialValue += 100 * ts3.data(0, pointIndex) * 0.01;
}
EXPECT_NEAR(ts3.data(1, pp - 1), iv, std::abs(iv) * 1e-2 + 1e-12);
EXPECT_NEAR(ts3.data(1, pointIndex - 1), initialValue, (std::abs(initialValue) * 1e-2) + 1e-12);
int ret = remove(recname.c_str());

EXPECT_EQ(ret, 0);
Expand All @@ -132,9 +135,11 @@ TEST_F(BlockTests, BlockTest5)
ts3.loadBinaryFile(recname);

EXPECT_NEAR(ts3.data(1, 5), 0.0, 1e-4);
auto vm = absMax(ts3[0]);
auto vm2 = absMax(ts3[1]);
EXPECT_NEAR(vm2, vm * 5, std::abs(vm * 5) * 1e-2 + 1e-12);
auto maxInputMagnitude = absMax(ts3[0]);
auto maxOutputMagnitude = absMax(ts3[1]);
EXPECT_NEAR(maxOutputMagnitude,
maxInputMagnitude * 5,
(std::abs(maxInputMagnitude * 5) * 1e-2) + 1e-12);
int ret = remove(recname.c_str());

EXPECT_EQ(ret, 0);
Expand All @@ -156,7 +161,7 @@ TEST_F(BlockTests, BlockTest6)
EXPECT_NEAR(ts3.data(1, 5), 1.0, 1e-4);

EXPECT_NEAR(ts3.data(1, 2000), 1.0, 1e-4);
remove(recname.c_str());
(void)remove(recname.c_str());

recname = std::string(BLOCK_TEST_DIRECTORY "blocktest2.dat");
ts3.loadBinaryFile(recname);
Expand Down Expand Up @@ -194,10 +199,10 @@ TEST_F(BlockTests, DeadbandBlockTest)
TimeSeriesMulti<> ts3;
ts3.loadBinaryFile(recname);

auto mx = std::any_of(ts3[1].begin(), ts3[1].end(), [](double a) {
return ((a > 0.400001) && (a < 0.4999999));
auto hasDeadbandViolation = std::any_of(ts3[1].begin(), ts3[1].end(), [](double value) {
return ((value > 0.400001) && (value < 0.4999999));
});
EXPECT_FALSE(mx);
EXPECT_FALSE(hasDeadbandViolation);

int ret = remove(recname.c_str());

Expand All @@ -206,35 +211,42 @@ TEST_F(BlockTests, DeadbandBlockTest)

using blockdescpair = std::pair<std::string, std::vector<std::pair<std::string, double>>>;

const std::vector<blockdescpair> blockparamMap{
{"basic", {std::make_pair("k", 2.3), std::make_pair("max", 0.1)}},
{"delay", {std::make_pair("t1", 0.5)}},
{"integral", {std::make_pair("iv", 0.14)}},
{"derivative", {std::make_pair("t", 0.25)}},
{"fder", {std::make_pair("t1", 0.25), std::make_pair("t2", 0.1)}},
{"deadband", {std::make_pair("db", 0.1), std::make_pair("ramp", 0.03)}},
{"db", {std::make_pair("db", 0.08)}},
{"pid",
{std::make_pair("p", 0.7),
std::make_pair("i", 0.02),
std::make_pair("d", 0.28),
std::make_pair("t", 0.2)}},
{"control", {std::make_pair("t1", 0.2), std::make_pair("t2", 0.1)}},
{"function", {std::make_pair("gain", kPI), std::make_pair("bias", -0.05)}},
{"func", {std::make_pair("arg", 2.35)}},
};

const std::map<std::string, std::vector<std::pair<std::string, std::string>>> blockparamMapSt{
{"function", {std::make_pair("func", "sin")}},
{"func", {std::make_pair("func", "pow")}},
{"db", {std::make_pair("flags", "shifted")}},
};
std::vector<blockdescpair> makeBlockParameterMap()
{
return {
{"basic", {std::make_pair("k", 2.3), std::make_pair("max", 0.1)}},
{"delay", {std::make_pair("t1", 0.5)}},
{"integral", {std::make_pair("iv", 0.14)}},
{"derivative", {std::make_pair("t", 0.25)}},
{"fder", {std::make_pair("t1", 0.25), std::make_pair("t2", 0.1)}},
{"deadband", {std::make_pair("db", 0.1), std::make_pair("ramp", 0.03)}},
{"db", {std::make_pair("db", 0.08)}},
{"pid",
{std::make_pair("p", 0.7),
std::make_pair("i", 0.02),
std::make_pair("d", 0.28),
std::make_pair("t", 0.2)}},
{"control", {std::make_pair("t1", 0.2), std::make_pair("t2", 0.1)}},
{"function", {std::make_pair("gain", kPI), std::make_pair("bias", -0.05)}},
{"func", {std::make_pair("arg", 2.35)}},
};
}

std::map<std::string, std::vector<std::pair<std::string, std::string>>>
makeStringBlockParameterMap()
{
return {
{"function", {std::make_pair("func", "sin")}},
{"func", {std::make_pair("func", "pow")}},
{"db", {std::make_pair("flags", "shifted")}},
};
}

TEST_P(BlockCompareTests, CompareBlockTest)
{
const auto caseIndex = GetParam();
std::string fileName = std::string(BLOCK_TEST_DIRECTORY "block_test_compare.xml");
auto bf = CoreObjectFactory::instance()->getFactory("block");
auto blockFactory = CoreObjectFactory::instance()->getFactory("block");

gds = readSimXMLFile(fileName);
ASSERT_NE(gds, nullptr);
Expand All @@ -244,25 +256,27 @@ TEST_P(BlockCompareTests, CompareBlockTest)
gds->consolePrintLevel = PrintLevel::WARNING;
auto rel1 = gds->getRelay(0);
auto rel2 = gds->getRelay(1);
auto& plist = blockparamMap[caseIndex];
const auto blockParameterMap = makeBlockParameterMap();
const auto stringBlockParameterMap = makeStringBlockParameterMap();
auto& plist = blockParameterMap[caseIndex];

auto bb1 = static_cast<GridBlock*>(bf->makeObject(plist.first));
auto bb2 = static_cast<GridBlock*>(bf->makeObject(plist.first));
auto bb1 = static_cast<GridBlock*>(blockFactory->makeObject(plist.first));
auto bb2 = static_cast<GridBlock*>(blockFactory->makeObject(plist.first));

ASSERT_NE(bb1, nullptr);
ASSERT_NE(bb2, nullptr);
for (const auto& pp : plist.second) {
bb1->set(pp.first, pp.second);
bb2->set(pp.first, pp.second);
for (const auto& parameterValue : plist.second) {
bb1->set(parameterValue.first, parameterValue.second);
bb2->set(parameterValue.first, parameterValue.second);
}

auto kfind = blockparamMapSt.find(plist.first);
if (kfind != blockparamMapSt.end()) {
auto bps = blockparamMapSt.at(plist.first);
for (const auto& pp : bps) {
bb1->set(pp.first, pp.second);
auto kfind = stringBlockParameterMap.find(plist.first);
if (kfind != stringBlockParameterMap.end()) {
auto blockParameters = stringBlockParameterMap.at(plist.first);
for (const auto& parameterValue : blockParameters) {
bb1->set(parameterValue.first, parameterValue.second);

bb2->set(pp.first, pp.second);
bb2->set(parameterValue.first, parameterValue.second);
}
}
rel1->add(bb1);
Expand All @@ -273,13 +287,13 @@ TEST_P(BlockCompareTests, CompareBlockTest)

int mmatch = runJacobianCheck(gds, cDaeSolverMode, 1e-5);
if (mmatch > 0) {
printf(" mismatching Jacobian in %s\n", plist.first.c_str());
std::cout << " mismatching Jacobian in " << plist.first << '\n';
ASSERT_EQ(mmatch, 0);
}

mmatch = runResidualCheck(gds, cDaeSolverMode);
if (mmatch > 0) {
printf(" mismatching residual in %s\n", plist.first.c_str());
std::cout << " mismatching residual in " << plist.first << '\n';
ASSERT_EQ(mmatch, 0);
}

Expand All @@ -294,22 +308,22 @@ TEST_P(BlockCompareTests, CompareBlockTest)
std::string recname = std::string(BLOCK_TEST_DIRECTORY "blocktest.dat");
TimeSeriesMulti<> ts3;
ts3.loadBinaryFile(recname);
std::vector<double> df(ts3.size());
compareVec(ts3[1], ts3[2], df);
auto mx = absMax(df);
auto adf = mean(df);
EXPECT_TRUE((mx < 1e-2) || (adf < 2e-3));
std::vector<double> difference(ts3.size());
compareVec(ts3[1], ts3[2], difference);
auto maxDifference = absMax(difference);
auto meanDifference = mean(difference);
EXPECT_TRUE((maxDifference < 1e-2) || (meanDifference < 2e-3));
int ret = remove(recname.c_str());

if ((mx > 1e-2) && (adf > 2e-3)) {
printf(" mismatching results in %s\n", plist.first.c_str());
if ((maxDifference > 1e-2) && (meanDifference > 2e-3)) {
std::cout << " mismatching results in " << plist.first << '\n';
}
EXPECT_EQ(ret, 0);
}

INSTANTIATE_TEST_SUITE_P(AllBlocks, BlockCompareTests, ::testing::Range(0, 11));

#ifdef LOAD_CVODE
#ifdef GRIDDYN_ENABLE_CVODE
/** test the control block if they can handle a differential only Jacobian and an algebraic only
* Jacobian
*/
Expand All @@ -318,8 +332,10 @@ TEST_P(BlockCompareTests, BlockAlgDiffJacTest)
const auto caseIndex = GetParam();
std::string fileName = std::string(BLOCK_TEST_DIRECTORY "block_test_compare.xml");

auto bf = CoreObjectFactory::instance()->getFactory("block");
auto& plist = blockparamMap[caseIndex];
auto blockFactory = CoreObjectFactory::instance()->getFactory("block");
const auto blockParameterMap = makeBlockParameterMap();
const auto stringBlockParameterMap = makeStringBlockParameterMap();
auto& plist = blockParameterMap[caseIndex];

gds = readSimXMLFile(fileName);
ASSERT_NE(gds, nullptr);
Expand All @@ -330,24 +346,24 @@ TEST_P(BlockCompareTests, BlockAlgDiffJacTest)
auto rel1 = gds->getRelay(0);
auto rel2 = gds->getRelay(1);

auto bb1 = static_cast<GridBlock*>(bf->makeObject(plist.first));
auto bb2 = static_cast<GridBlock*>(bf->makeObject(plist.first));
auto bb1 = static_cast<GridBlock*>(blockFactory->makeObject(plist.first));
auto bb2 = static_cast<GridBlock*>(blockFactory->makeObject(plist.first));

ASSERT_NE(bb1, nullptr);
ASSERT_NE(bb2, nullptr);
for (const auto& pp : plist.second) {
bb1->set(pp.first, pp.second);
for (const auto& parameterValue : plist.second) {
bb1->set(parameterValue.first, parameterValue.second);

bb2->set(pp.first, pp.second);
bb2->set(parameterValue.first, parameterValue.second);
}

auto kfind = blockparamMapSt.find(plist.first);
if (kfind != blockparamMapSt.end()) {
auto bps = blockparamMapSt.at(plist.first);
for (const auto& pp : bps) {
bb1->set(pp.first, pp.second);
auto kfind = stringBlockParameterMap.find(plist.first);
if (kfind != stringBlockParameterMap.end()) {
auto blockParameters = stringBlockParameterMap.at(plist.first);
for (const auto& parameterValue : blockParameters) {
bb1->set(parameterValue.first, parameterValue.second);

bb2->set(pp.first, pp.second);
bb2->set(parameterValue.first, parameterValue.second);
}
}
rel1->add(bb1);
Expand Down
14 changes: 7 additions & 7 deletions test/componentTests/testExciters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ TEST_F(ExciterTests, BasicStabilityTest4)
verifyStabilityCase(*this, fileName, parameters, 0.98, 1.02, 0.97, 1.02, {"dc1a", "sexs"});
}

#ifdef LOAD_CVODE
#ifdef GRIDDYN_ENABLE_CVODE
TEST_F(ExciterTests, ExciterTest2AlgDiffTests)
{
static const std::map<std::string, std::vector<std::pair<std::string, double>>> parameters{
Expand All @@ -206,7 +206,7 @@ TEST_F(ExciterTests, ExciterTest2AlgDiffTests)

// exclist.insert(exclist.begin(), "none");
for (auto& excname : exclist) {
if (excname.compare(0, 3, "fmi") == 0) {
if (excname.starts_with("fmi")) {
continue;
}
gds = readSimXMLFile(fileName);
Expand All @@ -218,8 +218,8 @@ TEST_F(ExciterTests, ExciterTest2AlgDiffTests)
auto fnd = parameters.find(excname);

if (fnd != parameters.end()) {
for (auto& pp : fnd->second) {
obj->set(pp.first, pp.second);
for (auto& parameterValue : fnd->second) {
obj->set(parameterValue.first, parameterValue.second);
}
}

Expand Down Expand Up @@ -253,7 +253,7 @@ TEST_F(ExciterTests, ExciterAlgDiffJacobianTests)

// exclist.insert(exclist.begin(), "none");
for (auto& excname : exclist) {
if (excname.compare(0, 3, "fmi") == 0) {
if (excname.starts_with("fmi")) {
continue;
}
gds = readSimXMLFile(fileName);
Expand All @@ -265,8 +265,8 @@ TEST_F(ExciterTests, ExciterAlgDiffJacobianTests)
auto fnd = parameters.find(excname);

if (fnd != parameters.end()) {
for (auto& pp : fnd->second) {
obj->set(pp.first, pp.second);
for (auto& parameterValue : fnd->second) {
obj->set(parameterValue.first, parameterValue.second);
}
}

Expand Down
Loading