Skip to content
Closed
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 Examples/ParameterEstimation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
# - Cameron Rutherford <cameron.rutherford@pnnl.gov>
#]]

add_compile_definitions("PARAMETER_DIR=${CMAKE_CURRENT_SOURCE_DIR}")

add_executable(paramest ParameterEstimation.cpp)
target_link_libraries(paramest
GRIDKIT::bus
Expand Down
6 changes: 5 additions & 1 deletion Examples/ParameterEstimation/ParameterEstimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@
#include <Solver/Optimization/DynamicConstraint.hpp>
#include <Utilities/FileIO.hpp>
#include <Utilities/Testing.hpp>
#include <string>

#define STRING(x) #x
#define XSTRING(x) STRING(x)

int main(int argc, char** argv)
{
Expand All @@ -98,7 +101,8 @@ 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";
const std::string input_data = (argc == 2) ? argv[1] : std::string(XSTRING(PARAMETER_DIR)) + "/lookup_table.dat";

double t_init = -1.0;
double t_final = -1.0;

Expand Down
25 changes: 25 additions & 0 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,31 @@ void readMatPowerBaseMVA(SystemModelData<RealT, IdxT>& mp, std::string& line)

namespace GridKit
{

/**
* @brief Reads a file in for tabulated data
*
* @todo needs to return int for file error codes
*
* @tparam ScalarT
* @param table
* @param filename
* @param ti
* @param tf
*/
template <typename ScalarT>
void setLookupTable(std::vector<std::vector<ScalarT>>& table,
std::string filename,
ScalarT& ti,
ScalarT& tf)
{
std::ifstream idata(filename);
if (!idata.is_open()) {
///@todo swap with returing error codes instead of crashing.
std::cerr << "Error. Given file name \"" << filename<< "\" does not exsist." << std::endl;
abort();
}

std::string line;
int oldwordcount = -1;
while (std::getline(idata, line)) {
Expand All @@ -281,6 +300,12 @@ void setLookupTable(std::vector<std::vector<ScalarT>>& table,
}

size_t N = table.size();
if (N < 2) {
///@todo swap with returing error codes instead of crashing.
std::cerr << "Error. Only " << N << " data points found in file " << filename << std::endl;
abort();
}

ti = table[0][0];
tf = table[N - 1][0];
}
Expand Down