Skip to content
Draft
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: 1 addition & 1 deletion GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ namespace GridKit
{
using Variable = ModelDataT::MonitorableVariables;
monitor_->set(Variable::efd, [this]
{ return efd_signal_->read(); });
{ return y_[7]; });
monitor_->set(Variable::ksat, [this]
{ return SB_ * Math::qramp(y_[2] - SA_); });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ namespace GridKit
p,
q,
delta,
omega
omega,
speed
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ namespace GridKit
{ return y_[0]; });
monitor_->set(Variable::omega, [this]
{ return y_[1]; });
monitor_->set(Variable::speed, [this]
{ return 1.0 + y_[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 @@ -61,7 +61,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 @@ -110,7 +110,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));
}
}
else
{
c.error_tol.push_back(1.0e-4);
}

using ErrorType = Testing::ErrorType;
if (j.contains("error_type"))
Expand Down Expand Up @@ -258,7 +274,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
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": 0.00416666666666,
"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": 0.00416666666666,
"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": 0.00416666666666,
"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": 0.00416666666666,
"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": 0.00416666666666,
"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