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: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
.directory
*.orig
.vscode/

*.DS_Store
build/
2 changes: 1 addition & 1 deletion ComponentLib/PowerFlow/Bus/BaseBus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion ComponentLib/PowerFlow/Bus/BusPQ.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ namespace ModelLib
return fB_[1];
}

virtual const int BusType() const
virtual int BusType() const
{
return BaseBus<ScalarT, IdxT>::BusType::PQ;
}
Expand Down
2 changes: 1 addition & 1 deletion ComponentLib/PowerFlow/Bus/BusPV.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ namespace ModelLib
return QB_;
}

virtual const int BusType() const
virtual int BusType() const
{
return BaseBus<ScalarT, IdxT>::BusType::PV;
}
Expand Down
2 changes: 1 addition & 1 deletion ComponentLib/PowerFlow/Bus/BusSlack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ namespace ModelLib
return QB_;
}

virtual const int BusType() const
virtual int BusType() const
{
return BaseBus<ScalarT, IdxT>::BusType::Slack;
}
Expand Down
101 changes: 0 additions & 101 deletions ComponentLib/PowerFlow/Generator4Param/static_data.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion Examples/ParameterEstimation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_FILE:paramest> ${CMAKE_SOURCE_DIR}/Examples/ParameterEstimation/lookup_table.dat)
add_test(NAME ParameterEst COMMAND $<TARGET_FILE:paramest>)
16 changes: 10 additions & 6 deletions Examples/ParameterEstimation/ParameterEstimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,25 @@

#include <iostream>
#include <iomanip>
#include <string>

#include <IpIpoptApplication.hpp>
#include <IpSolveStatistics.hpp>

#include <Solver/Optimization/DynamicObjective.hpp>
#include <Solver/Optimization/DynamicConstraint.hpp>
#include <ComponentLib/PowerFlow/Bus/BusSlack.hpp>
#include <ComponentLib/PowerFlow/Generator4Param/Generator4Param.hpp>
#include <SystemModel.hpp>
#include <Solver/Dynamic/Ida.hpp>

#include <IpIpoptApplication.hpp>
#include <IpSolveStatistics.hpp>
#include <Solver/Optimization/DynamicObjective.hpp>
#include <Solver/Optimization/DynamicConstraint.hpp>
#include <Utilities/FileIO.hpp>
#include <Utilities/Testing.hpp>

#include "lookup_table.hpp"


int main(int argc, char** argv)
int main()
{
using namespace ModelLib;
using namespace AnalysisManager::Sundials;
Expand All @@ -98,10 +102,10 @@ int main(int argc, char** argv)
// Create numerical integrator and configure it for the generator model
Ida<double, size_t>* idas = new Ida<double, size_t>(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 "
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
)";
37 changes: 33 additions & 4 deletions Utilities/FileIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#include <fstream>
#include <iostream>
#include <memory>
#include <ostream>
#include <regex>
#include <sstream>
#include <vector>
Expand Down Expand Up @@ -251,13 +252,29 @@ void readMatPowerBaseMVA(SystemModelData<RealT, IdxT>& 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 <typename ScalarT>
void setLookupTable(std::vector<std::vector<ScalarT>>& 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)) {
Expand All @@ -281,8 +298,20 @@ void setLookupTable(std::vector<std::vector<ScalarT>>& 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 <typename ScalarT>
Expand Down