Skip to content
Open
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
5 changes: 3 additions & 2 deletions GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ if(GRIDKIT_ENABLE_ENZYME)
ClangEnzymeFlags
COMPILE_OPTIONS
PRIVATE
-mllvm
-enzyme-auto-sparsity=1
"SHELL:-mllvm -enzyme-auto-sparsity=1"
# Preserve runtime-order stores for Enzyme sparsification.
"SHELL:-mllvm -simplifycfg-sink-common=false"
-fno-math-errno)
else()
gridkit_add_library(
Expand Down
119 changes: 50 additions & 69 deletions GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/Ieeest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,85 @@

#pragma once

#include <cstddef>
#include <memory>
#include <vector>
Comment thread
nkoukpaizan marked this conversation as resolved.

#include <GridKit/Definitions.hpp>
#include <GridKit/Model/PhasorDynamics/Component.hpp>
#include <GridKit/Model/PhasorDynamics/ComponentSignals.hpp>
#include <GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestData.hpp>
#include <GridKit/Model/VariableMonitor.hpp>

namespace GridKit
{
namespace PhasorDynamics
{
namespace Stabilizer
{
template <typename real_type, typename index_type>
struct IeeestData;
} // namespace Stabilizer

template <typename scalar_type, typename index_type>
class SignalNode;

} // namespace PhasorDynamics
} // namespace GridKit

namespace GridKit
{
namespace PhasorDynamics
{
namespace Stabilizer
{
/// Internal variables of a `Ieeest`
/// Internal variables of a `Ieeest`.
enum class IeeestInternalVariables : size_t
{
X1, ///< Notch filter state 1
X2, ///< Notch filter state 2
X3, ///< Notch filter state 3
X4, ///< Notch filter state 4
X5, ///< Lead-lag 1 state
X6, ///< Lead-lag 2 state
X7, ///< Washout state
V4, ///< Notch filter output
V5, ///< Lead-lag 1 output
V6, ///< Lead-lag 2 output
V7, ///< Unlimited stabilizer signal
VSS, ///< Limited stabilizer signal (model output)
X1, ///< \f$x_1\f$ Notch-filter signal state
X2, ///< \f$x_2\f$ First derivative of the filtered signal
X3, ///< \f$x_3\f$ Second derivative of the filtered signal
X4, ///< \f$x_4\f$ Third derivative of the filtered signal
X5, ///< \f$x_5\f$ Lead-lag 1 state
X6, ///< \f$x_6\f$ Lead-lag 2 state
X7, ///< \f$x_7\f$ Washout state
V4, ///< \f$v_4\f$ Notch-filter output
V5, ///< \f$v_5\f$ Lead-lag 1 output
V6, ///< \f$v_6\f$ Lead-lag 2 output
V7, ///< \f$v_7\f$ Unlimited stabilizer signal
VSS, ///< \f$V_{\mathrm{ss}}\f$ Limited stabilizer signal and model output
MAXIMUM,
};

/// External variables of a `Ieeest`
/// External variables of a `Ieeest`.
enum class IeeestExternalVariables : size_t
{
U, ///< Stabilizer input signal
U, ///< \f$u\f$ Stabilizer input signal
MAXIMUM,
};

template <typename scalar_type, typename index_type>
class Ieeest : public Component<scalar_type, index_type>
{
using Component<scalar_type, index_type>::gridkit_component_id_;
using Component<scalar_type, index_type>::abs_tol_;
using Component<scalar_type, index_type>::allocated_;
using Component<scalar_type, index_type>::alpha_;
using Component<scalar_type, index_type>::f_;
using Component<scalar_type, index_type>::gridkit_component_id_;
using Component<scalar_type, index_type>::J_cols_buffer_;
using Component<scalar_type, index_type>::J_rows_buffer_;
using Component<scalar_type, index_type>::J_vals_buffer_;
using Component<scalar_type, index_type>::nnz_;
using Component<scalar_type, index_type>::residual_indices_;
using Component<scalar_type, index_type>::size_;
using Component<scalar_type, index_type>::tag_;
using Component<scalar_type, index_type>::abs_tol_;
using Component<scalar_type, index_type>::time_;
using Component<scalar_type, index_type>::variable_indices_;
using Component<scalar_type, index_type>::wb_;
using Component<scalar_type, index_type>::y_;
using Component<scalar_type, index_type>::yp_;
using Component<scalar_type, index_type>::wb_;
using Component<scalar_type, index_type>::h_;
using Component<scalar_type, index_type>::J_rows_buffer_;
using Component<scalar_type, index_type>::J_cols_buffer_;
using Component<scalar_type, index_type>::J_vals_buffer_;
using Component<scalar_type, index_type>::variable_indices_;
using Component<scalar_type, index_type>::residual_indices_;
using Component<scalar_type, index_type>::allocated_;

public:
using ScalarT = scalar_type;
using IdxT = index_type;
using RealT = typename Component<ScalarT, IdxT>::RealT;
using ModelDataT = IeeestData<RealT, IdxT>;
using SignalT = SignalNode<ScalarT, IdxT>;
using MonitorT = Model::VariableMonitor<Ieeest, IeeestData>;
using ScalarT = scalar_type;
using IdxT = index_type;
using RealT = typename Component<ScalarT, IdxT>::RealT;
using SignalT = SignalNode<ScalarT, IdxT>;
using ModelDataT = IeeestData<RealT, IdxT>;
using MonitorT = Model::VariableMonitor<Ieeest, IeeestData>;
using InternalVariablesT = IeeestInternalVariables;
using ExternalVariablesT = IeeestExternalVariables;

Ieeest();
Ieeest(const ModelDataT& data);
explicit Ieeest(const ModelDataT& data);
~Ieeest();

int setGridKitComponentID(IdxT) override final;
int setGridKitComponentID(IdxT component_id) override final;
int allocate() override final;
int verify() const override final;
int initialize() override final;
Expand All @@ -100,7 +93,6 @@ namespace GridKit
int evaluateResidual() override final;
int evaluateJacobian() override final;

/// Get the `ComponentSignals` from this `Ieeest`
auto getSignals()
-> ComponentSignals<ScalarT,
IdxT,
Expand All @@ -120,6 +112,12 @@ namespace GridKit
ScalarT*);

private:
void initializeParameters(const ModelDataT& data);
void initializeMonitor();
void setDerivedParameters();

static constexpr RealT TIME_CONSTANT_MINIMUM = static_cast<RealT>(1.0e-3);

RealT A1_{0};
RealT A2_{0};
RealT A3_{0};
Expand All @@ -139,34 +137,17 @@ namespace GridKit
RealT Vcu_{0};
RealT Tdelay_{0};

RealT a0_{1};
IdxT order_{0};

RealT a1_{0};
RealT a2_{0};
RealT a3_{0};
RealT a4_{0};

// Precomputed masks and safe inverse coefficients for branch-free degenerate paths.
RealT use_notch_{0};
RealT bypass_notch_{1};
RealT use_4th_order_{0};
RealT use_3rd_order_{0};
RealT use_2nd_order_{0};
RealT safe_inv_a4_{0};
RealT safe_inv_a3_{0};
RealT safe_inv_a2_{0};
RealT use_T2_block_{1};
RealT bypass_T2_block_{0};
RealT use_T4_block_{1};
RealT bypass_T4_block_{0};
RealT use_T6_block_{1};
RealT bypass_T6_block_{0};
IdxT parameter_error_count_{0};

ComponentSignals<ScalarT, IdxT, IeeestInternalVariables, IeeestExternalVariables> signals_;

std::unique_ptr<MonitorT> monitor_;

void initializeParameters(const ModelDataT& data);
void initializeMonitor();
std::unique_ptr<MonitorT> monitor_;

std::vector<ScalarT> ws_;
std::vector<IdxT> ws_indices_;
Expand Down
38 changes: 19 additions & 19 deletions GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ namespace GridKit
*/
enum class IeeestParameters
{
A1, ///< Notch filter denominator coefficient
A2, ///< Notch filter denominator coefficient
A3, ///< Notch filter denominator coefficient
A4, ///< Notch filter denominator coefficient
A5, ///< Notch filter numerator coefficient
A6, ///< Notch filter numerator coefficient
T1, ///< Lead-lag 1 numerator time constant
T2, ///< Lead-lag 1 denominator time constant
T3, ///< Lead-lag 2 numerator time constant
T4, ///< Lead-lag 2 denominator time constant
T5, ///< Washout numerator time constant
T6, ///< Washout denominator time constant
Ks, ///< Stabilizer gain
Lsmin, ///< Minimum stabilizer output limit
Lsmax, ///< Maximum stabilizer output limit
Vcl, ///< Lower input cutout threshold (not modeled)
Vcu, ///< Upper input cutout threshold (not modeled)
Tdelay, ///< Input time delay (not modeled)
A1, ///< \f$A_1\f$ Notch-filter denominator coefficient
A2, ///< \f$A_2\f$ Notch-filter denominator coefficient
A3, ///< \f$A_3\f$ Notch-filter denominator coefficient
A4, ///< \f$A_4\f$ Notch-filter denominator coefficient
A5, ///< \f$A_5\f$ Notch-filter numerator coefficient
A6, ///< \f$A_6\f$ Notch-filter numerator coefficient
T1, ///< \f$T_1\f$ Lead-lag 1 numerator time constant
T2, ///< \f$T_2\f$ Lead-lag 1 denominator time constant
T3, ///< \f$T_3\f$ Lead-lag 2 numerator time constant
T4, ///< \f$T_4\f$ Lead-lag 2 denominator time constant
T5, ///< \f$T_5\f$ Washout numerator time constant
T6, ///< \f$T_6\f$ Washout denominator time constant
Ks, ///< \f$K_s\f$ Stabilizer gain
Lsmin, ///< \f$L_s^{\min}\f$ Minimum stabilizer output limit
Lsmax, ///< \f$L_s^{\max}\f$ Maximum stabilizer output limit
Vcl, ///< \f$V_{\mathrm{cl}}\f$ Unsupported lower input-cutout threshold
Vcu, ///< \f$V_{\mathrm{cu}}\f$ Unsupported upper input-cutout threshold
Tdelay, ///< \f$T_{\mathrm{delay}}\f$ Unsupported input delay
};

/**
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace GridKit
*/
enum class IeeestMonitorableVariables
{
vss, ///< Stabilizer output (limited signal)
vss, ///< \f$V_{\mathrm{ss}}\f$ Limited stabilizer signal and model output
};

/**
Expand Down
Loading
Loading