Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion GridKit/Definitions.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#cmakedefine GRIDKIT_ENABLE_ENZYME
#cmakedefine GRIDKIT_ENABLE_OPENMP
#cmakedefine GRIDKIT_ENABLE_SUNDIALS_SPARSE
#cmakedefine GRIDKIT_ENABLE_THREADS
#cmakedefine GRIDKIT_ENABLE_SUNDIALS_SPARSE

#define GRIDKIT_VERSION "@GridKit_VERSION@"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ namespace GridKit
p,
q,
delta,
omega
omega,
speed
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ namespace GridKit
{ return y_.getData()[0]; });
monitor_->set(Variable::omega, [this]
{ return y_.getData()[1]; });
monitor_->set(Variable::speed, [this]
{ return 1.0 + y_.getData()[1]; });
}

/**
Expand Down
11 changes: 10 additions & 1 deletion GridKit/Testing/Tokenizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <string>
#include <vector>

#include <GridKit/Utilities/String.hpp>

namespace GridKit
{
namespace Testing
Expand All @@ -22,7 +24,14 @@ namespace GridKit
std::istringstream iss(in);
for (std::string item; std::getline(iss, item, delimiter);)
{
std::istringstream(item) >> tokens_.emplace_back();
if constexpr (std::is_same_v<T, std::string>)
{
tokens_.push_back(GridKit::Utilities::strip(item));
}
else
{
tokens_.push_back(GridKit::Utilities::parse<T>(item));
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion GridKit/Utilities/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ namespace GridKit
return str;
}

std::string strip(std::string str)
{
auto notspace = [](char c)
{ return !std::isspace(c); };
str.erase(begin(str), std::find_if(begin(str), end(str), notspace));
str.erase(std::find_if(rbegin(str), rend(str), notspace).base(), end(str));
return str;
}

/**
* @brief Attempt to parse a string to the given type
*
Expand All @@ -31,7 +40,7 @@ namespace GridKit

T ret;

auto ss = std::stringstream(str);
auto ss = std::stringstream(strip(str));
ss >> ret;

if (ss.fail() || !ss.eof())
Expand Down
33 changes: 30 additions & 3 deletions application/PhasorDynamics/AnalysisUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace GridKit
/// path to reference file for validation
fs::path reference_file;
/// Error tolerance (between output file and reference file)
double error_tol;
std::vector<double> error_tol;
/// Type of total error (relative or absolute)
Testing::ErrorType error_type;
/// Smallest value at which to scale for relative error
Expand Down Expand Up @@ -122,7 +122,23 @@ namespace GridKit
j.at("reference_file").get_to(c.reference_file);
}

c.error_tol = j.value("error_tolerance", 1.0e-4);
if (j.contains("error_tolerance"))
{
auto& tolj = j.at("error_tolerance");
if (tolj.is_array())
{
tolj.get_to(c.error_tol);
}
else
{
tolj.get_to(c.error_tol.emplace_back());
// c.error_tol.push_back(j.value("error_tolerance", 1.0e-4));
Comment thread
PhilipFackler marked this conversation as resolved.
Outdated
}
}
else
{
c.error_tol.push_back(1.0e-4);
Comment thread
nkoukpaizan marked this conversation as resolved.
Outdated
}

using ErrorType = Testing::ErrorType;
if (j.contains("error_type"))
Expand Down Expand Up @@ -270,7 +286,18 @@ namespace GridKit
}

// Check against specified tolerance
status *= errorSet->total_error.max_value < study_data.error_tol;
if (study_data.error_tol.size() > 1)
{
status *= study_data.error_tol.size() == errorSet->var_errors.size();
for (std::size_t i = 0; i < study_data.error_tol.size(); ++i)
{
status *= errorSet->var_errors[i].max_value < study_data.error_tol[i];
}
}
else
{
status *= errorSet->total_error.max_value < study_data.error_tol[0];
}

if (print_results)
{
Expand Down
8 changes: 5 additions & 3 deletions examples/Consumer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ if(GRIDKIT_ENABLE_SUNDIALS)
FILES ${_examples_dir}/PhasorDynamics/Tiny/TwoBus/Basic/TwoBusBasicJson.cpp
DESTINATION ${_rel_consumer_path}
RENAME consumer.cpp)
install(FILES ${_examples_dir}/PhasorDynamics/Tiny/TwoBus/Basic/TwoBusBasic.hpp
${_examples_dir}/PhasorDynamics/Tiny/TwoBus/Basic/TwoBusBasic.case.json
install(FILES ${_examples_dir}/PhasorDynamics/Tiny/TwoBus/Basic/TwoBusBasic.case.json
DESTINATION ${_rel_consumer_path})
list(
APPEND
Expand Down Expand Up @@ -41,4 +40,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/GridKitConsumer/CMakeLists.txt

# Add target to build and test the example project after install
add_custom_target(
test_install COMMAND ${_abs_consumer_path}/test.sh ${CMAKE_INSTALL_PREFIX} ${CMAKE_CXX_COMPILER})
test_install
COMMAND
${_abs_consumer_path}/test.sh ${CMAKE_INSTALL_PREFIX} ${CMAKE_CXX_COMPILER}
"${CMAKE_CXX_FLAGS}")
1 change: 1 addition & 0 deletions examples/Consumer/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rm -rf ${INSTALL_BUILD_CONSUME}/build/* &&
cmake -B ${INSTALL_BUILD_CONSUME}/build \
-S ${INSTALL_BUILD_CONSUME} \
-DCMAKE_CXX_COMPILER=${COMPILER} \
-DCMAKE_CXX_FLAGS="${@:3}" \
-DGridKit_DIR=${GridKit_DIR} &&

# Build and install
Expand Down
5 changes: 4 additions & 1 deletion examples/PhasorDynamics/Large/Illinois/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
gridkit_example_add_file(illinois.json)
gridkit_example_add_file(illinois.case.json)
gridkit_example_add_file(illinois.solver.json)

add_test(
NAME illinois_pdsim
COMMAND DynamicSimulation illinois.solver.json
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

gridkit_example_current_install_path(_install_path)
install(FILES illinois.case.json illinois.solver.json DESTINATION ${_install_path})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"system_model_file": "illinois.json",
"system_model_file": "illinois.case.json",
"dt_monitor": 0.004166666666666667,
"tmax": 20.0,
"events": [
Expand Down
5 changes: 4 additions & 1 deletion examples/PhasorDynamics/Large/Texas/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
gridkit_example_add_file(texas.json)
gridkit_example_add_file(texas.case.json)
gridkit_example_add_file(texas.solver.json)

add_test(
NAME texas_pdsim
COMMAND DynamicSimulation texas.solver.json
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

gridkit_example_current_install_path(_install_path)
install(FILES texas.case.json texas.solver.json DESTINATION ${_install_path})
2 changes: 1 addition & 1 deletion examples/PhasorDynamics/Large/Texas/texas.solver.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"system_model_file": "texas.json",
"system_model_file": "texas.case.json",
"dt_monitor": 0.004166666666666667,
"tmax": 20.0,
"events": [
Expand Down
5 changes: 4 additions & 1 deletion examples/PhasorDynamics/Large/WECC/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
gridkit_example_add_file(wecc.json)
gridkit_example_add_file(wecc.case.json)
gridkit_example_add_file(wecc.solver.json)

add_test(
NAME wecc_pdsim
COMMAND DynamicSimulation wecc.solver.json
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

gridkit_example_current_install_path(_install_path)
install(FILES wecc.case.json wecc.solver.json DESTINATION ${_install_path})
2 changes: 1 addition & 1 deletion examples/PhasorDynamics/Large/WECC/wecc.solver.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"system_model_file": "wecc.json",
"system_model_file": "wecc.case.json",
"dt_monitor": 0.004166666666666667,
"tmax": 20.0,
"events": [
Expand Down
5 changes: 4 additions & 1 deletion examples/PhasorDynamics/Medium/Hawaii/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
gridkit_example_add_file(hawaii.json)
gridkit_example_add_file(hawaii.case.json)
gridkit_example_add_file(hawaii.solver.json)

add_test(
NAME hawaii_pdsim
COMMAND DynamicSimulation hawaii.solver.json
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

gridkit_example_current_install_path(_install_path)
install(FILES hawaii.case.json hawaii.solver.json DESTINATION ${_install_path})
2 changes: 1 addition & 1 deletion examples/PhasorDynamics/Medium/Hawaii/hawaii.solver.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"system_model_file": "hawaii.json",
"system_model_file": "hawaii.case.json",
"dt_monitor": 0.004166666666666667,
"tmax": 10.0,
"events": [
Expand Down
5 changes: 4 additions & 1 deletion examples/PhasorDynamics/Medium/NewEngland/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gridkit_example_add_file(newengland.json)
gridkit_example_add_file(newengland.case.json)
gridkit_example_add_file(newengland.solver.json)

add_test(
Expand All @@ -10,3 +10,6 @@ add_test(
NAME newengland_ca
COMMAND ContingencyAnalysis newengland.solver.json
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

gridkit_example_current_install_path(_install_path)
install(FILES newengland.case.json newengland.solver.json DESTINATION ${_install_path})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"system_model_file": "newengland.json",
"system_model_file": "newengland.case.json",
"dt_monitor": 0.004166666666666667,
"tmax": 20.0,
"events": [
Expand Down
28 changes: 6 additions & 22 deletions examples/PhasorDynamics/Tiny/ThreeBus/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
gridkit_example_current_install_path(_install_path)

add_executable(ThreeBusBasic ThreeBusBasic.cpp)
target_link_libraries(
ThreeBusBasic GridKit::phasor_dynamics_systemmodel GridKit::solvers_dyn)
install(TARGETS ThreeBusBasic RUNTIME DESTINATION ${_install_path})

add_executable(ThreeBusBasicJson ThreeBusBasicJson.cpp)
target_link_libraries(
ThreeBusBasicJson
GridKit::phasor_dynamics_systemmodel
GridKit::solvers_dyn
GridKit::utilities_cli_args
GridKit::testing)
install(TARGETS ThreeBusBasicJson RUNTIME DESTINATION ${_install_path})
gridkit_example_add_file(ThreeBusBasic.case.json)
gridkit_example_add_file(ThreeBusBasic.ref.csv)

add_test(NAME ThreeBusBasic COMMAND ThreeBusBasic)
add_test(
NAME ThreeBusBasicJson
COMMAND ThreeBusBasicJson --case ThreeBusBasic.case.json --compare mon.csv ThreeBusBasic.ref.csv)

gridkit_example_add_file(ThreeBusBasic.solver.json)

add_test(
NAME ThreeBusBasic_pdsim
NAME ThreeBusBasic
COMMAND DynamicSimulation ThreeBusBasic.solver.json
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

gridkit_example_current_install_path(_install_path)
install(FILES ThreeBusBasic.case.json ThreeBusBasic.solver.json ThreeBusBasic.ref.csv
DESTINATION ${_install_path})
Loading
Loading