Skip to content
Open
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
- Added `BusToSignalAdapter` component for communicating bus voltages and injection currents.
- Added cmake-format hooks, including in pre-commit.
- Added off-nominal tap ratio and phase shift support to the PhasorDynamics `Branch` model.
- Added portable Vector class to GridKit
- Added portable Vector class to GridKit.
- Added Windows compatibility.

## v0.1

Expand Down
31 changes: 16 additions & 15 deletions GridKit/CommonMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cmath>

#include <GridKit/Constants.hpp>
#include <GridKit/Definitions.hpp>
#include <GridKit/ScalarTraits.hpp>

namespace GridKit
Expand Down Expand Up @@ -34,7 +35,7 @@ namespace GridKit
* @return value of the sigmoid function
*/
template <class ScalarT>
__attribute__((always_inline)) inline ScalarT sigmoid(const ScalarT x)
FORCE_INLINE ScalarT sigmoid(const ScalarT x)
{
using RealT = typename GridKit::ScalarTraits<ScalarT>::RealT;
return HALF<RealT> * (ONE<RealT> + std::tanh(HALF<RealT> * MU<RealT> * x));
Expand All @@ -52,7 +53,7 @@ namespace GridKit
* @return value of the smooth ramp function
*/
template <class ScalarT>
__attribute__((always_inline)) inline ScalarT ramp(const ScalarT x)
FORCE_INLINE ScalarT ramp(const ScalarT x)
{
using RealT = typename GridKit::ScalarTraits<ScalarT>::RealT;

Expand All @@ -76,7 +77,7 @@ namespace GridKit
* @return value of the quadratic ramp
*/
template <class ScalarT>
__attribute__((always_inline)) inline ScalarT qramp(const ScalarT x)
FORCE_INLINE ScalarT qramp(const ScalarT x)
{
return x * x * sigmoid(x);
}
Expand All @@ -101,7 +102,7 @@ namespace GridKit
* forcing callers to cast every parameter.
*/
template <class LeftT, class RightT>
__attribute__((always_inline)) inline auto max(
FORCE_INLINE auto max(
const LeftT x,
const RightT y)
{
Expand All @@ -128,7 +129,7 @@ namespace GridKit
* forcing callers to cast every parameter.
*/
template <class LeftT, class RightT>
__attribute__((always_inline)) inline auto min(
FORCE_INLINE auto min(
const LeftT x,
const RightT y)
{
Expand All @@ -152,7 +153,7 @@ namespace GridKit
* @return value of the smooth clamp function
*/
template <class ScalarT, typename LowerT, typename UpperT>
__attribute__((always_inline)) inline auto clamp(
FORCE_INLINE auto clamp(
const ScalarT x,
const LowerT lower,
const UpperT upper)
Expand All @@ -176,7 +177,7 @@ namespace GridKit
* @return Smooth deadbanded value
*/
template <class ScalarT, typename RealT>
__attribute__((always_inline)) inline ScalarT deadband(
FORCE_INLINE ScalarT deadband(
const ScalarT x,
const RealT lower,
const RealT upper)
Expand All @@ -198,7 +199,7 @@ namespace GridKit
* @return Slew-rate-limited value of f
*/
template <class ScalarT, typename RealT>
__attribute__((always_inline)) inline ScalarT slew(
FORCE_INLINE ScalarT slew(
const ScalarT f,
const RealT rate)
{
Expand All @@ -223,7 +224,7 @@ namespace GridKit
* @return Smooth linear segment contribution
*/
template <class ScalarT, typename RealT>
__attribute__((always_inline)) inline ScalarT linseg(
FORCE_INLINE ScalarT linseg(
const ScalarT x,
const RealT lower,
const RealT upper,
Expand All @@ -244,7 +245,7 @@ namespace GridKit
* @return Smooth indicator that x is above limit_min
*/
template <class ScalarT, typename RealT>
__attribute__((always_inline)) inline ScalarT above(
FORCE_INLINE ScalarT above(
const ScalarT x,
const RealT limit_min)
{
Expand All @@ -262,7 +263,7 @@ namespace GridKit
* @return Smooth indicator that x is below limit_max
*/
template <class ScalarT, typename RealT>
__attribute__((always_inline)) inline ScalarT below(
FORCE_INLINE ScalarT below(
const ScalarT x,
const RealT limit_max)
{
Expand All @@ -281,7 +282,7 @@ namespace GridKit
* @return Smooth indicator that x is inside [limit_min, limit_max]
*/
template <class ScalarT, typename RealT>
__attribute__((always_inline)) inline ScalarT inside(
FORCE_INLINE ScalarT inside(
const ScalarT x,
const RealT limit_min,
const RealT limit_max)
Expand All @@ -302,7 +303,7 @@ namespace GridKit
* @return Smooth indicator that x is outside [limit_min, limit_max]
*/
template <class ScalarT, typename RealT>
__attribute__((always_inline)) inline ScalarT outside(
FORCE_INLINE ScalarT outside(
const ScalarT x,
const RealT limit_min,
const RealT limit_max)
Expand All @@ -325,7 +326,7 @@ namespace GridKit
* 0 when integration should be blocked.
*/
template <class ScalarT, typename RealT>
__attribute__((always_inline)) inline ScalarT indicator(
FORCE_INLINE ScalarT indicator(
const ScalarT x,
const ScalarT f,
const RealT limit_min,
Expand Down Expand Up @@ -359,7 +360,7 @@ namespace GridKit
* @return Smooth anti-windup limited derivative
*/
template <class ScalarT, typename RealT>
__attribute__((always_inline)) inline ScalarT antiwindup(
FORCE_INLINE ScalarT antiwindup(
const ScalarT x,
const ScalarT f,
const RealT limit_min,
Expand Down
8 changes: 8 additions & 0 deletions GridKit/Definitions.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@
#define GRIDKIT_VERSION_MAJOR "@GridKit_VERSION_MAJOR@"
#define GRIDKIT_VERSION_MINOR "@GridKit_VERSION_MINOR@"
#define GRIDKIT_VERSION_PATCH "@GridKit_VERSION_PATCH@"

#if defined(__MINGW32__) || defined(__clang__) || defined(__GNUC__)
#define FORCE_INLINE __attribute__((always_inline)) inline
#elif defined(_MSC_VER)
#define FORCE_INLINE [[msvc::forceinline]] inline
#else
#define FORCE_INLINE __attribute__((always_inline)) inline
#endif
30 changes: 15 additions & 15 deletions GridKit/Model/PhasorDynamics/Branch/Branch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ namespace GridKit
typename ModelDataT::Parameters parameter,
RealT& target);

static __attribute__((always_inline)) inline void addAdmittanceContribution(RealT G,
RealT B,
const ScalarT& Vr,
const ScalarT& Vi,
ScalarT& Ir,
ScalarT& Ii);

static __attribute__((always_inline)) inline void evaluateAdmittanceBlock(RealT G,
RealT B,
const ScalarT* wb,
ScalarT* h);
static FORCE_INLINE void addAdmittanceContribution(RealT G,
RealT B,
const ScalarT& Vr,
const ScalarT& Vi,
ScalarT& Ir,
ScalarT& Ii);

static FORCE_INLINE void evaluateAdmittanceBlock(RealT G,
RealT B,
const ScalarT* wb,
ScalarT* h);

ScalarT& Vr1()
{
Expand Down Expand Up @@ -187,10 +187,10 @@ namespace GridKit
}

public:
__attribute__((always_inline)) inline int evaluateBusResidual11(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
__attribute__((always_inline)) inline int evaluateBusResidual12(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
__attribute__((always_inline)) inline int evaluateBusResidual21(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
__attribute__((always_inline)) inline int evaluateBusResidual22(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateBusResidual11(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateBusResidual12(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateBusResidual21(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateBusResidual22(ScalarT*, ScalarT*, ScalarT*, ScalarT*);

private:
BusT* bus1_;
Expand Down
8 changes: 4 additions & 4 deletions GridKit/Model/PhasorDynamics/Branch/BranchImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ namespace GridKit
}

template <typename scalar_type, typename index_type>
__attribute__((always_inline)) inline void Branch<scalar_type, index_type>::addAdmittanceContribution(
FORCE_INLINE void Branch<scalar_type, index_type>::addAdmittanceContribution(
RealT G,
RealT B,
const ScalarT& Vr,
Expand All @@ -187,7 +187,7 @@ namespace GridKit
}

template <typename scalar_type, typename index_type>
__attribute__((always_inline)) inline void Branch<scalar_type, index_type>::evaluateAdmittanceBlock(
FORCE_INLINE void Branch<scalar_type, index_type>::evaluateAdmittanceBlock(
RealT G,
RealT B,
const ScalarT* wb,
Expand All @@ -205,7 +205,7 @@ namespace GridKit
*
*/
template <typename scalar_type, typename index_type>
__attribute__((always_inline)) inline int Branch<scalar_type, index_type>::evaluateBusResidual11(
FORCE_INLINE int Branch<scalar_type, index_type>::evaluateBusResidual11(
[[maybe_unused]] ScalarT* y,
[[maybe_unused]] ScalarT* yp,
ScalarT* wb,
Expand All @@ -221,7 +221,7 @@ namespace GridKit
*
*/
template <typename scalar_type, typename index_type>
__attribute__((always_inline)) inline int Branch<scalar_type, index_type>::evaluateBusResidual12(
FORCE_INLINE int Branch<scalar_type, index_type>::evaluateBusResidual12(
[[maybe_unused]] ScalarT* y,
[[maybe_unused]] ScalarT* yp,
ScalarT* wb,
Expand Down
2 changes: 1 addition & 1 deletion GridKit/Model/PhasorDynamics/BusFault/BusFault.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace GridKit
}

public:
__attribute__((always_inline)) inline int evaluateBusResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateBusResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);

private:
BusT* bus_;
Expand Down
2 changes: 1 addition & 1 deletion GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace GridKit

const Model::VariableMonitorBase* getMonitor() const override;

__attribute__((always_inline)) inline int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*);

private:
// Signal pointers
Expand Down
2 changes: 1 addition & 1 deletion GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ namespace GridKit
*
*/
template <typename scalar_type, typename index_type>
__attribute__((always_inline)) inline int Ieeet1<scalar_type, index_type>::evaluateInternalResidual(
FORCE_INLINE int Ieeet1<scalar_type, index_type>::evaluateInternalResidual(
ScalarT* y,
ScalarT* yp,
ScalarT* wb,
Expand Down
2 changes: 1 addition & 1 deletion GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPti.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace GridKit

const Model::VariableMonitorBase* getMonitor() const override;

__attribute__((always_inline)) inline int evaluateInternalResidual(
FORCE_INLINE int evaluateInternalResidual(
ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ namespace GridKit
}

template <typename scalar_type, typename index_type>
__attribute__((always_inline)) inline int SexsPti<scalar_type, index_type>::evaluateInternalResidual(
FORCE_INLINE int SexsPti<scalar_type, index_type>::evaluateInternalResidual(
ScalarT* y,
ScalarT* yp,
ScalarT* wb,
Expand Down
2 changes: 1 addition & 1 deletion GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace GridKit
}

public:
__attribute__((always_inline)) inline int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*);

private:
// Input parameters
Expand Down
2 changes: 1 addition & 1 deletion GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ namespace GridKit
*
*/
template <typename scalar_type, typename index_type>
__attribute__((always_inline)) inline int Tgov1<scalar_type, index_type>::evaluateInternalResidual(
FORCE_INLINE int Tgov1<scalar_type, index_type>::evaluateInternalResidual(
ScalarT* y,
ScalarT* yp,
[[maybe_unused]] ScalarT* wb,
Expand Down
4 changes: 2 additions & 2 deletions GridKit/Model/PhasorDynamics/Load/Load.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ namespace GridKit
const Model::VariableMonitorBase* getMonitor() const override;

public:
__attribute__((always_inline)) inline int evaluateBusResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
__attribute__((always_inline)) inline int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateBusResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);

private:
BusT* bus_{nullptr};
Expand Down
4 changes: 2 additions & 2 deletions GridKit/Model/PhasorDynamics/LoadZIP/LoadZIP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ namespace GridKit
const Model::VariableMonitorBase* getMonitor() const override;

public:
__attribute__((always_inline)) inline int evaluateBusResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
__attribute__((always_inline)) inline int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateBusResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);

private:
BusT* bus_{nullptr};
Expand Down
2 changes: 1 addition & 1 deletion GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/Ieeest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace GridKit

const Model::VariableMonitorBase* getMonitor() const override;

__attribute__((always_inline)) inline int evaluateInternalResidual(
FORCE_INLINE int evaluateInternalResidual(
ScalarT*,
ScalarT*,
[[maybe_unused]] ScalarT*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ namespace GridKit
}

template <typename scalar_type, typename index_type>
__attribute__((always_inline)) inline int Ieeest<scalar_type, index_type>::evaluateInternalResidual(
FORCE_INLINE int Ieeest<scalar_type, index_type>::evaluateInternalResidual(
ScalarT* y,
ScalarT* yp,
[[maybe_unused]] ScalarT* wb,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ namespace GridKit
}

public:
__attribute__((always_inline)) inline int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*);
__attribute__((always_inline)) inline int evaluateBusResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateBusResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);

private:
/* Identification */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ namespace GridKit
*
*/
template <typename scalar_type, typename index_type>
__attribute__((always_inline)) inline int Genrou<scalar_type, index_type>::evaluateInternalResidual(
FORCE_INLINE int Genrou<scalar_type, index_type>::evaluateInternalResidual(
ScalarT* y,
ScalarT* yp,
ScalarT* wb,
Expand Down Expand Up @@ -606,7 +606,7 @@ namespace GridKit
*
*/
template <typename scalar_type, typename index_type>
__attribute__((always_inline)) inline int Genrou<scalar_type, index_type>::evaluateBusResidual(
FORCE_INLINE int Genrou<scalar_type, index_type>::evaluateBusResidual(
ScalarT* y,
[[maybe_unused]] ScalarT* yp,
ScalarT* wb,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ namespace GridKit
}

public:
__attribute__((always_inline)) inline int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*);
__attribute__((always_inline)) inline int evaluateBusResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*);
FORCE_INLINE int evaluateBusResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*);

private:
/* Identification */
Expand Down
Loading
Loading