Skip to content

Reorganize model evaluator implementations #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 21, 2025
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
8 changes: 4 additions & 4 deletions examples/AdjointSensitivity/AdjointSensitivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

#include <Model/PowerFlow/Bus/BusSlack.hpp>
#include <Model/PowerFlow/Generator4/Generator4.hpp>
#include <SystemModel.hpp>
#include <Model/PowerFlow/SystemModel.hpp>
#include <Solver/Dynamic/Ida.hpp>
#include <Utilities/Testing.hpp>

Expand Down Expand Up @@ -142,9 +142,9 @@ int main()
const double eps = 2e-3;

// Compute gradient of the objective function numerically
std::vector<double> dGdp(model->size_opt());
std::vector<double> dGdp(model->sizeParams());

for (unsigned i=0; i<model->size_opt(); ++i)
for (unsigned i=0; i<model->sizeParams(); ++i)
{
model->param()[i] += eps;
idas->getSavedInitialCondition();
Expand Down Expand Up @@ -185,7 +185,7 @@ int main()
int retval = 0;
std::cout << "\n\nComparison of numerical and adjoint results:\n\n";
double* neg_dGdp = idas->getAdjointIntegral();
for (unsigned i=0; i<model->size_opt(); ++i)
for (unsigned i=0; i<model->sizeParams(); ++i)
{
std::cout << "dG/dp" << i << " (numerical) = " << dGdp[i] << "\n";
std::cout << "dG/dp" << i << " (adjoint) = " << -neg_dGdp[i] << "\n\n";
Expand Down
8 changes: 4 additions & 4 deletions examples/DynamicConstrainedOpt/DynamicConstrainedOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

#include <Model/PowerFlow/Bus/BusSlack.hpp>
#include <Model/PowerFlow/Generator2/Generator2.hpp>
#include <SystemModel.hpp>
#include <Model/PowerFlow/SystemModel.hpp>
#include <Solver/Dynamic/Ida.hpp>

#include <IpIpoptApplication.hpp>
Expand Down Expand Up @@ -165,8 +165,8 @@ int main()
}

// Store dynamic objective optimization results
double* results = new double[model->size_opt()];
for(unsigned i=0; i <model->size_opt(); ++i)
double* results = new double[model->sizeParams()];
for(unsigned i=0; i <model->sizeParams(); ++i)
{
results[i] = model->param()[i];
}
Expand All @@ -193,7 +193,7 @@ int main()

// Compare results of the two optimization methods
int retval = 0;
for(unsigned i=0; i <model->size_opt(); ++i)
for(unsigned i=0; i <model->sizeParams(); ++i)
{
if(!isEqual(results[i], model->param()[i], 10*tol))
--retval;
Expand Down
2 changes: 1 addition & 1 deletion examples/GenConstLoad/GenConstLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#include <Model/PowerFlow/Load/Load.hpp>
#include <Model/PowerFlow/Generator4Governor/Generator4Governor.hpp>
#include <Solver/Dynamic/Ida.hpp>
#include <SystemModel.hpp>
#include <Model/PowerFlow/SystemModel.hpp>

#include <IpIpoptApplication.hpp>
#include <IpSolveStatistics.hpp>
Expand Down
8 changes: 4 additions & 4 deletions examples/GenInfiniteBus/GenInfiniteBus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

#include <Model/PowerFlow/Bus/BusSlack.hpp>
#include <Model/PowerFlow/Generator4/Generator4.hpp>
#include <SystemModel.hpp>
#include <Model/PowerFlow/SystemModel.hpp>
#include <Solver/Dynamic/Ida.hpp>

#include <IpIpoptApplication.hpp>
Expand Down Expand Up @@ -176,8 +176,8 @@ int main()
new IpoptInterface::DynamicConstraint<double, size_t>(idas);

// Store dynamic objective optimization results
double* results = new double[model->size_opt()];
for(unsigned i=0; i <model->size_opt(); ++i)
double* results = new double[model->sizeParams()];
for(unsigned i=0; i <model->sizeParams(); ++i)
{
results[i] = model->param()[i];
}
Expand All @@ -202,7 +202,7 @@ int main()

// Compare results of the two optimization methods
int retval = 0;
for(unsigned i=0; i <model->size_opt(); ++i)
for(unsigned i=0; i <model->sizeParams(); ++i)
{
if(!isEqual(results[i], model->param()[i], 100*tol))
--retval;
Expand Down
8 changes: 4 additions & 4 deletions examples/ParameterEstimation/ParameterEstimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#include <Solver/Optimization/DynamicConstraint.hpp>
#include <Model/PowerFlow/Bus/BusSlack.hpp>
#include <Model/PowerFlow/Generator4Param/Generator4Param.hpp>
#include <SystemModel.hpp>
#include <Model/PowerFlow/SystemModel.hpp>
#include <Solver/Dynamic/Ida.hpp>

#include <Utilities/FileIO.hpp>
Expand Down Expand Up @@ -178,8 +178,8 @@ int main()
}

// Store dynamic objective optimization results
double* results = new double[model->size_opt()];
for(unsigned i=0; i <model->size_opt(); ++i)
double* results = new double[model->sizeParams()];
for(unsigned i=0; i <model->sizeParams(); ++i)
{
results[i] = model->param()[i];
}
Expand Down Expand Up @@ -207,7 +207,7 @@ int main()

// Compare results of the two optimization methods
int retval = 0;
for(unsigned i=0; i <model->size_opt(); ++i)
for(unsigned i=0; i <model->sizeParams(); ++i)
{
if(!isEqual(results[i], model->param()[i], 100*tol))
--retval;
Expand Down
6 changes: 3 additions & 3 deletions src/Model/EvaluatorDynamics.hpp → src/Model/Evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace Model
*
*/
template <class ScalarT, typename IdxT>
class EvaluatorDynamics
class Evaluator
{
public:
typedef typename GridKit::ScalarTraits<ScalarT>::real_type real_type;

EvaluatorDynamics(){}
virtual ~EvaluatorDynamics(){}
Evaluator(){}
virtual ~Evaluator(){}

virtual int allocate() = 0;
virtual int initialize() = 0;
Expand Down
1 change: 1 addition & 0 deletions src/Model/PhasorDynamics/Branch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# [[
# Author(s):
# - Cameron Rutherford <cameron.rutherford@pnnl.gov>
# - Slaven Peles <peless@ornl.gov>
# ]]

gridkit_add_library(phasor_dynamics_branch
Expand Down
6 changes: 3 additions & 3 deletions src/Model/PhasorDynamics/BusBase.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <vector>
#include <Model/EvaluatorDynamics.hpp>
#include <Model/Evaluator.hpp>

namespace GridKit
{
Expand All @@ -12,10 +12,10 @@ namespace PhasorDynamics
*
*/
template <class ScalarT, typename IdxT>
class BusBase : public Model::EvaluatorDynamics<ScalarT, IdxT>
class BusBase : public Model::Evaluator<ScalarT, IdxT>
{
public:
using real_type = typename Model::EvaluatorDynamics<ScalarT, IdxT>::real_type;
using real_type = typename Model::Evaluator<ScalarT, IdxT>::real_type;

enum BusType{DEFAULT=1, SLACK};

Expand Down
1 change: 1 addition & 0 deletions src/Model/PhasorDynamics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
add_subdirectory(Branch)
add_subdirectory(Bus)
add_subdirectory(Load)
add_subdirectory(SynchronousMachine)
14 changes: 7 additions & 7 deletions src/Model/PhasorDynamics/Component.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <vector>
#include <Model/EvaluatorDynamics.hpp>
#include <Model/Evaluator.hpp>

namespace GridKit
{
Expand All @@ -13,10 +13,10 @@ namespace PhasorDynamics
*
*/
template <class ScalarT, typename IdxT>
class Component : public Model::EvaluatorDynamics<ScalarT, IdxT>
class Component : public Model::Evaluator<ScalarT, IdxT>
{
public:
using real_type = typename Model::EvaluatorDynamics<ScalarT, IdxT>::real_type;
using real_type = typename Model::Evaluator<ScalarT, IdxT>::real_type;

Component()
: size_(0),
Expand Down Expand Up @@ -77,8 +77,8 @@ namespace PhasorDynamics

virtual void setTolerances(real_type& rtol, real_type& atol) const
{
rtol = rtol_;
atol = atol_;
rtol = rel_tol_;
atol = abs_tol_;
}

virtual void setMaxSteps(IdxT& msa) const
Expand Down Expand Up @@ -250,8 +250,8 @@ namespace PhasorDynamics
real_type time_;
real_type alpha_;

real_type rtol_;
real_type atol_;
real_type rel_tol_;
real_type abs_tol_;

IdxT max_steps_;

Expand Down
13 changes: 13 additions & 0 deletions src/Model/PhasorDynamics/SynchronousMachine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

# [[
# Author(s):
# - Cameron Rutherford <cameron.rutherford@pnnl.gov>
# - Slaven Peles <peless@ornl.gov>
# ]]

gridkit_add_library(phasor_dynamics_synchronous_machine
SOURCES
SynchronousMachine.cpp
OUTPUT_NAME
gridkit_phasor_dynamics_synchronous_machine)

Loading