diff --git a/.gitignore b/.gitignore index 304aea9a5..f7b5f6727 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ .directory *.orig .vscode/ - +*.DS_Store build/ diff --git a/ComponentLib/PowerFlow/Bus/BaseBus.hpp b/ComponentLib/PowerFlow/Bus/BaseBus.hpp index 4e8cbd5f1..0413201db 100644 --- a/ComponentLib/PowerFlow/Bus/BaseBus.hpp +++ b/ComponentLib/PowerFlow/Bus/BaseBus.hpp @@ -140,7 +140,7 @@ namespace ModelLib virtual ScalarT& QB() = 0; virtual const ScalarT& QB() const = 0; - virtual const int BusType() const = 0; + virtual int BusType() const = 0; virtual const IdxT BusID() const { diff --git a/ComponentLib/PowerFlow/Bus/BusPQ.hpp b/ComponentLib/PowerFlow/Bus/BusPQ.hpp index 45ed81a65..6d0c963d6 100644 --- a/ComponentLib/PowerFlow/Bus/BusPQ.hpp +++ b/ComponentLib/PowerFlow/Bus/BusPQ.hpp @@ -181,7 +181,7 @@ namespace ModelLib return fB_[1]; } - virtual const int BusType() const + virtual int BusType() const { return BaseBus::BusType::PQ; } diff --git a/ComponentLib/PowerFlow/Bus/BusPV.hpp b/ComponentLib/PowerFlow/Bus/BusPV.hpp index cf645d591..14f8def55 100644 --- a/ComponentLib/PowerFlow/Bus/BusPV.hpp +++ b/ComponentLib/PowerFlow/Bus/BusPV.hpp @@ -191,7 +191,7 @@ namespace ModelLib return QB_; } - virtual const int BusType() const + virtual int BusType() const { return BaseBus::BusType::PV; } diff --git a/ComponentLib/PowerFlow/Bus/BusSlack.hpp b/ComponentLib/PowerFlow/Bus/BusSlack.hpp index 19c27d96a..a4fce8f5a 100644 --- a/ComponentLib/PowerFlow/Bus/BusSlack.hpp +++ b/ComponentLib/PowerFlow/Bus/BusSlack.hpp @@ -180,7 +180,7 @@ namespace ModelLib return QB_; } - virtual const int BusType() const + virtual int BusType() const { return BaseBus::BusType::Slack; } diff --git a/ComponentLib/PowerFlow/Generator4Param/static_data.hpp b/ComponentLib/PowerFlow/Generator4Param/static_data.hpp deleted file mode 100644 index 88dbac519..000000000 --- a/ComponentLib/PowerFlow/Generator4Param/static_data.hpp +++ /dev/null @@ -1,101 +0,0 @@ -{ 0, 0.092182, 0.99596, -0.17574, 0.98107, 2.7864, 0.58172}, -{ 0.05, 0.032044, 0.99785, -0.15175, 0.98425, -0.058476, 0.52344}, -{ 0.1, 0.016599, 1.0006, -0.1331, 0.98738, -0.047843, 0.42635}, -{ 0.15, 0.05483, 1.0034, -0.11578, 0.99044, -0.036909, 0.48633}, -{ 0.2, 0.14141, 1.0056, -0.096146, 0.99341, -0.0096526, 0.67712}, -{ 0.25, 0.25913, 1.0067, -0.071796, 0.99616, 0.057594, 0.93888}, -{ 0.3, 0.38426, 1.0064, -0.042151, 0.9985, 0.16989, 1.1964}, -{ 0.35, 0.49314, 1.005, -0.0084123, 1.0003, 0.30164, 1.3852}, -{ 0.4, 0.5676, 1.0028, 0.02705, 1.0015, 0.41029, 1.4705}, -{ 0.45, 0.59823, 1.0004, 0.061508, 1.0024, 0.46162, 1.4465}, -{ 0.5, 0.58551, 0.99831, 0.092489, 1.0031, 0.44697, 1.3275}, -{ 0.55, 0.53921, 0.99693, 0.11815, 1.0041, 0.3845, 1.1404}, -{ 0.6, 0.47618, 0.99657, 0.13756, 1.0054, 0.30672, 0.92541}, -{ 0.65, 0.41655, 0.99727, 0.15094, 1.0069, 0.24321, 0.7317}, -{ 0.7, 0.37865, 0.99881, 0.1597, 1.0087, 0.20996, 0.60591}, -{ 0.75, 0.37438, 1.0008, 0.16612, 1.0105, 0.21157, 0.57628}, -{ 0.8, 0.40628, 1.0026, 0.17271, 1.0123, 0.24931, 0.64279}, -{ 0.85, 0.46736, 1.0038, 0.18152, 1.0138, 0.32351, 0.77782}, -{ 0.9, 0.5435, 1.0041, 0.19359, 1.0148, 0.42737, 0.93662}, -{ 0.95, 0.61757, 1.0036, 0.20876, 1.0154, 0.54119, 1.0735}, -{ 1, 0.67388, 1.0023, 0.2259, 1.0156, 0.63599, 1.1557}, -{ 1.05, 0.70183, 1.0006, 0.24337, 1.0154, 0.68574, 1.1689}, -{ 1.1, 0.69804, 0.999, 0.25946, 1.0151, 0.67947, 1.1144}, -{ 1.15, 0.66677, 0.99778, 0.27273, 1.0149, 0.62579, 1.0057}, -{ 1.2, 0.61875, 0.99726, 0.28227, 1.015, 0.54794, 0.86636}, -{ 1.25, 0.56848, 0.99754, 0.28791, 1.0155, 0.4729, 0.72906}, -{ 1.3, 0.53046, 0.99852, 0.2903, 1.0163, 0.42123, 0.62812}, -{ 1.35, 0.51537, 0.99991, 0.29083, 1.0172, 0.40344, 0.58875}, -{ 1.4, 0.52734, 1.0013, 0.29123, 1.0181, 0.42221, 0.6178}, -{ 1.45, 0.5631, 1.0024, 0.29303, 1.0188, 0.47491, 0.70149}, -{ 1.5, 0.61328, 1.0028, 0.29718, 1.0193, 0.5526, 0.81115}, -{ 1.55, 0.66527, 1.0026, 0.30377, 1.0194, 0.63849, 0.91394}, -{ 1.6, 0.70664, 1.0017, 0.31219, 1.0191, 0.71058, 0.98342}, -{ 1.65, 0.72829, 1.0005, 0.32131, 1.0186, 0.74915, 1.0051}, -{ 1.7, 0.72648, 0.9993, 0.3299, 1.018, 0.74483, 0.97655}, -{ 1.75, 0.70346, 0.99833, 0.33682, 1.0175, 0.70235, 0.90588}, -{ 1.8, 0.66675, 0.99787, 0.34134, 1.0173, 0.63805, 0.80994}, -{ 1.85, 0.62709, 0.99802, 0.34322, 1.0173, 0.5727, 0.7123}, -{ 1.9, 0.59559, 0.99871, 0.34287, 1.0176, 0.52403, 0.6382}, -{ 1.95, 0.58072, 0.99974, 0.34122, 1.0181, 0.50266, 0.60693}, -{ 2, 0.58615, 1.0008, 0.33951, 1.0186, 0.51207, 0.62506}, -{ 2.05, 0.60997, 1.0016, 0.33885, 1.0189, 0.54977, 0.68425}, -{ 2.1, 0.64547, 1.002, 0.33998, 1.0191, 0.6075, 0.76477}, -{ 2.15, 0.68324, 1.0019, 0.34304, 1.019, 0.67146, 0.8428}, -{ 2.2, 0.71374, 1.0013, 0.3476, 1.0186, 0.72486, 0.89803}, -{ 2.25, 0.72981, 1.0004, 0.35287, 1.018, 0.75305, 0.91825}, -{ 2.3, 0.72833, 0.99946, 0.35791, 1.0174, 0.749, 0.90057}, -{ 2.35, 0.71076, 0.99873, 0.36186, 1.0169, 0.71588, 0.8506}, -{ 2.4, 0.68267, 0.99837, 0.36412, 1.0166, 0.66543, 0.78114}, -{ 2.45, 0.65212, 0.99847, 0.36452, 1.0165, 0.61318, 0.70996}, -{ 2.5, 0.62752, 0.99898, 0.36334, 1.0166, 0.57309, 0.65581}, -{ 2.55, 0.61534, 0.99975, 0.36125, 1.0169, 0.55418, 0.63292}, -{ 2.6, 0.61846, 1.0006, 0.35916, 1.0171, 0.55973, 0.64633}, -{ 2.65, 0.63555, 1.0012, 0.3579, 1.0173, 0.58767, 0.69028}, -{ 2.7, 0.66163, 1.0015, 0.358, 1.0174, 0.63107, 0.75061}, -{ 2.75, 0.68963, 1.0014, 0.35959, 1.0172, 0.67891, 0.80984}, -{ 2.8, 0.71231, 1.001, 0.36238, 1.0168, 0.71845, 0.85255}, -{ 2.85, 0.7242, 1.0003, 0.36575, 1.0163, 0.73892, 0.86907}, -{ 2.9, 0.72287, 0.99958, 0.36901, 1.0158, 0.73524, 0.85679}, -{ 2.95, 0.7094, 0.99903, 0.3715, 1.0154, 0.70971, 0.81993}, -{ 3, 0.68797, 0.99876, 0.37276, 1.015, 0.67092, 0.76835}, -{ 3.05, 0.66468, 0.99883, 0.37265, 1.0149, 0.6304, 0.71561}, -{ 3.1, 0.64588, 0.99922, 0.3714, 1.0149, 0.59888, 0.67568}, -{ 3.15, 0.63643, 0.9998, 0.3695, 1.0151, 0.58359, 0.65904}, -{ 3.2, 0.63853, 1.0004, 0.36763, 1.0152, 0.58731, 0.66933}, -{ 3.25, 0.65119, 1.0009, 0.36639, 1.0153, 0.6084, 0.70238}, -{ 3.3, 0.67068, 1.0011, 0.36619, 1.0153, 0.64122, 0.74782}, -{ 3.35, 0.69166, 1.0011, 0.36714, 1.0151, 0.67717, 0.79271}, -{ 3.4, 0.70866, 1.0007, 0.369, 1.0148, 0.70663, 0.82539}, -{ 3.45, 0.71753, 1.0002, 0.37133, 1.0144, 0.72165, 0.83832}, -{ 3.5, 0.71642, 0.99968, 0.3736, 1.014, 0.71856, 0.82936}, -{ 3.55, 0.70615, 0.99926, 0.37529, 1.0136, 0.69908, 0.80173}, -{ 3.6, 0.68988, 0.99906, 0.37608, 1.0133, 0.66953, 0.76303}, -{ 3.65, 0.67221, 0.99911, 0.37585, 1.0132, 0.63849, 0.72359}, -{ 3.7, 0.65794, 0.99941, 0.37477, 1.0131, 0.61413, 0.69389}, -{ 3.75, 0.65073, 0.99984, 0.37322, 1.0132, 0.60214, 0.68163}, -{ 3.8, 0.65224, 1.0003, 0.3717, 1.0133, 0.60478, 0.68948}, -{ 3.85, 0.66172, 1.0007, 0.37066, 1.0133, 0.62075, 0.71435}, -{ 3.9, 0.67638, 1.0008, 0.37041, 1.0133, 0.64561, 0.74862}, -{ 3.95, 0.69218, 1.0008, 0.37103, 1.0131, 0.67272, 0.78261}, -{ 4, 0.70501, 1.0005, 0.37235, 1.0129, 0.6948, 0.80753}, -{ 4.05, 0.7117, 1.0002, 0.37404, 1.0125, 0.70598, 0.81755}, -{ 4.1, 0.71085, 0.99976, 0.37569, 1.0122, 0.70356, 0.81094}, -{ 4.15, 0.70308, 0.99944, 0.37691, 1.0118, 0.68882, 0.79015}, -{ 4.2, 0.69077, 0.99929, 0.37744, 1.0116, 0.66641, 0.76101}, -{ 4.25, 0.67741, 0.99933, 0.37722, 1.0115, 0.64275, 0.73138}, -{ 4.3, 0.66659, 0.99955, 0.37636, 1.0114, 0.62405, 0.70911}, -{ 4.35, 0.6611, 0.99988, 0.37516, 1.0115, 0.61473, 0.69993}, -{ 4.4, 0.66219, 1.0002, 0.37397, 1.0115, 0.61659, 0.70582}, -{ 4.45, 0.66931, 1.0005, 0.37315, 1.0115, 0.62866, 0.7245}, -{ 4.5, 0.68036, 1.0006, 0.37293, 1.0115, 0.64748, 0.75033}, -{ 4.55, 0.6923, 1.0006, 0.37336, 1.0113, 0.66796, 0.77607}, -{ 4.6, 0.70202, 1.0004, 0.37433, 1.0111, 0.6846, 0.79507}, -{ 4.65, 0.70713, 1.0001, 0.37559, 1.0108, 0.69303, 0.80285}, -{ 4.7, 0.70653, 0.99982, 0.37681, 1.0105, 0.69123, 0.79801}, -{ 4.75, 0.7007, 0.99958, 0.37772, 1.0103, 0.68014, 0.78239}, -{ 4.8, 0.69142, 0.99946, 0.37811, 1.0101, 0.6632, 0.76043}, -{ 4.85, 0.68132, 0.99949, 0.37794, 1.0099, 0.64521, 0.73809}, -{ 4.9, 0.67312, 0.99966, 0.37728, 1.0099, 0.63087, 0.7213}, -{ 4.95, 0.66892, 0.99991, 0.37636, 1.0099, 0.62362, 0.71433}, -{ 5, 0.66968, 1.0002, 0.37545, 1.0099, 0.6249, 0.71867} \ No newline at end of file diff --git a/Examples/ParameterEstimation/CMakeLists.txt b/Examples/ParameterEstimation/CMakeLists.txt index 5917256e3..212dd5cc6 100644 --- a/Examples/ParameterEstimation/CMakeLists.txt +++ b/Examples/ParameterEstimation/CMakeLists.txt @@ -74,4 +74,4 @@ set_property(TARGET paramest PROPERTY LINKER_LANGUAGE Fortran) install(TARGETS paramest RUNTIME DESTINATION bin) install(FILES lookup_table.dat DESTINATION bin) -add_test(NAME ParameterEst COMMAND $ ${CMAKE_SOURCE_DIR}/Examples/ParameterEstimation/lookup_table.dat) +add_test(NAME ParameterEst COMMAND $) diff --git a/Examples/ParameterEstimation/ParameterEstimation.cpp b/Examples/ParameterEstimation/ParameterEstimation.cpp index 5e69e600d..f73f028e7 100644 --- a/Examples/ParameterEstimation/ParameterEstimation.cpp +++ b/Examples/ParameterEstimation/ParameterEstimation.cpp @@ -60,21 +60,25 @@ #include #include +#include +#include +#include + +#include +#include #include #include #include #include -#include -#include -#include -#include #include #include +#include "lookup_table.hpp" + -int main(int argc, char** argv) +int main() { using namespace ModelLib; using namespace AnalysisManager::Sundials; @@ -98,10 +102,10 @@ int main(int argc, char** argv) // Create numerical integrator and configure it for the generator model Ida* idas = new Ida(model); - const std::string input_data = (argc == 2) ? argv[1] : "lookup_table.dat"; double t_init = -1.0; double t_final = -1.0; + std::istringstream input_data(lookup_table); GridKit::setLookupTable(gen->getLookupTable(), input_data, t_init, t_final); std::cout << "Performing parameter estimation with respect to data\nfrom " diff --git a/Examples/ParameterEstimation/lookup_table.dat b/Examples/ParameterEstimation/lookup_table.hpp similarity index 98% rename from Examples/ParameterEstimation/lookup_table.dat rename to Examples/ParameterEstimation/lookup_table.hpp index bd4785e5b..069ce1497 100644 --- a/Examples/ParameterEstimation/lookup_table.dat +++ b/Examples/ParameterEstimation/lookup_table.hpp @@ -1,4 +1,5 @@ - 0 0.092182 0.99596 -0.17574 0.98107 2.7864 0.58172 -1.5217 0.092914 0.4666 -0.18534 -0.49105 -1.3472 +std::string lookup_table = +R"( 0 0.092182 0.99596 -0.17574 0.98107 2.7864 0.58172 -1.5217 0.092914 0.4666 -0.18534 -0.49105 -1.3472 0.05 0.032044 0.99785 -0.15175 0.98425 -0.058476 0.52344 -0.80946 0.048601 0.41347 0.063192 0.20608 -3.487 0.1 0.016599 1.0006 -0.1331 0.98738 -0.047843 0.42635 0.22214 0.058264 0.34627 0.061871 0.19728 -0.34913 0.15 0.05483 1.0034 -0.11578 0.99044 -0.036909 0.48633 1.2885 0.052391 0.35895 0.060531 0.29873 2.6589 @@ -99,3 +100,4 @@ 4.9 0.67312 0.99966 0.37728 1.0099 0.63087 0.7213 -0.12935 0.0043559 -0.016631 -0.00033208 -0.22427 -0.24786 4.95 0.66892 0.99991 0.37636 1.0099 0.62362 0.71433 -0.035255 0.0053896 -0.019197 0.000302 -0.060867 -0.025908 5 0.66968 1.0002 0.37545 1.0099 0.6249 0.71867 0.064531 0.0049577 -0.016122 0.00018828 0.10945 0.19374 +)"; \ No newline at end of file diff --git a/Utilities/FileIO.hpp b/Utilities/FileIO.hpp index 825123c97..24b244b26 100644 --- a/Utilities/FileIO.hpp +++ b/Utilities/FileIO.hpp @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -251,13 +252,29 @@ void readMatPowerBaseMVA(SystemModelData& mp, std::string& line) namespace GridKit { + +/** + * @brief Reads in an input stream of tabulated data + * + * @todo needs to return int for file error codes + * + * @tparam ScalarT + * @param[out] table object in memory where the data from the input stream is + * @param[in] filename input stream to space and newline separated data + * @param[out] ti initial time returned + * @param[out] tf final time returned + * + * @pre Input stream should read space separated data. Rows are separated + * by new line. Each row od data must have the same number of entries. The + * first column of the data represents time and other columns time dependent + * variables. + */ template void setLookupTable(std::vector>& table, - std::string filename, + std::istream& idata, ScalarT& ti, ScalarT& tf) { - std::ifstream idata(filename); std::string line; int oldwordcount = -1; while (std::getline(idata, line)) { @@ -281,8 +298,20 @@ void setLookupTable(std::vector>& table, } size_t N = table.size(); - ti = table[0][0]; - tf = table[N - 1][0]; + if (N == 0) + { + // do nothing + } + else if (N == 1) + { + ti = table[0][0]; + tf = table[0][0]; + } + else + { + ti = table[0][0]; + tf = table[N - 1][0]; + } } template