Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ddf1862
Use /W4 instead of /Wall to reduce irrelevant warning spam
andrewxu319 Aug 6, 2026
4439f54
Use FORCE_INLINE macro
andrewxu319 Aug 6, 2026
1fac6b7
Make Utilities functions inlined to follow ODR
andrewxu319 Aug 6, 2026
427bb64
Define M_PI
andrewxu319 Aug 6, 2026
668e0f6
Add scripts needed for test_install
andrewxu319 Aug 6, 2026
27896a6
Update docs
andrewxu319 Aug 6, 2026
9c30683
Turn off BUILD_SHARED_LIBS on Windows
andrewxu319 Aug 7, 2026
a2150a3
Use /W4 instead of /Wall to reduce irrelevant warning spam
andrewxu319 Aug 6, 2026
04d3776
Use FORCE_INLINE macro
andrewxu319 Aug 6, 2026
7a626f3
Make Utilities functions inlined to follow ODR
andrewxu319 Aug 6, 2026
e54752f
Define M_PI
andrewxu319 Aug 6, 2026
e2d31fe
Add scripts needed for test_install
andrewxu319 Aug 6, 2026
0ac5e09
Update docs
andrewxu319 Aug 6, 2026
b742912
Turn off BUILD_SHARED_LIBS on Windows
andrewxu319 Aug 7, 2026
4c2e5bc
Revert "Define M_PI"
andrewxu319 Aug 7, 2026
01e0846
Merge branch 'andrew/windows-compatibility-v2' of github.com:ORNL/Gri…
andrewxu319 Aug 7, 2026
fc0f8dc
Merge branch 'andrew/windows-compatibility-v2' of github.com:ORNL/Gri…
andrewxu319 Aug 7, 2026
946e337
Apply pre-commit fixes
andrewxu319 Aug 7, 2026
af10773
Define M_PI
andrewxu319 Aug 6, 2026
6d23ed2
Merge branch 'andrew/windows-compatibility-v2' of github.com:ORNL/Gri…
andrewxu319 Aug 7, 2026
70bb461
Apply pre-commit fixes
andrewxu319 Aug 7, 2026
bd37fac
Move FORCE_INLINE definition to Definitions.hpp.in. Putting it in CMa…
andrewxu319 Aug 7, 2026
c25b6a2
Add missing include
andrewxu319 Aug 7, 2026
937bc27
Add missing includes in Branch.hpp and BusFault.hpp
andrewxu319 Aug 7, 2026
4e34f9c
Apply pre-commit fixes
andrewxu319 Aug 7, 2026
0dcf8e2
Typo
andrewxu319 Aug 7, 2026
0194091
Apply pre-commit fixes
andrewxu319 Aug 7, 2026
7030c48
Put FORCE_INLINE back in CMakeLists (instead of header files). Add it…
andrewxu319 Aug 7, 2026
64f0d6f
Move this feature to v0.3 in changelog
andrewxu319 Aug 7, 2026
85126a9
Apply pre-commit fixes
andrewxu319 Aug 7, 2026
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: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Changelog

## v0.3

- Added Windows compatibility (G++, Clang, MSVC).

## v0.2

- Added 3, 10, 37, and 39 bus test cases.
Expand Down Expand Up @@ -77,7 +81,6 @@
- Added `REGCA` converter model implementation for PhasorDynamics.
- Remove unnecessary data copying while evaluating `PowerElectronics` models, speeding up large simulations by up to 3x
- Added `HYGOV` governor model implementation for PhasorDynamics.
- Added `REPCA` controller model implementation for PhasorDynamics.

## v0.1

Expand Down
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wconversion -Wpedantic")
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_definitions(FORCE_INLINE=[[gnu::always_inline]]\ inline)
elseif(MSVC)
add_compile_definitions(FORCE_INLINE=[[msvc::forceinline]]\ inline)
else()
add_compile_definitions(FORCE_INLINE=inline)
endif()

set(GRIDKIT_THIRD_PARTY_DIR ${PROJECT_SOURCE_DIR}/third-party)

# Ipopt support is disabled by default
Expand Down Expand Up @@ -119,7 +127,11 @@ if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")

option(BUILD_SHARED_LIBS "Build shared libraries" ON)
if(WIN32)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
else()
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
endif()

if(GRIDKIT_ENABLE_IPOPT)
include(FindIpopt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ namespace GridKit
* @param[in,out] nnz - number of nonzeros
*/
template <typename ScalarT, typename IdxT>
__attribute__((always_inline)) static void sparse_store(
FORCE_INLINE static void sparse_store(
ScalarT val,
IdxT row,
IdxT col,
Expand Down Expand Up @@ -251,7 +251,7 @@ namespace GridKit
* @tparam IdxT - matrix index data type
*/
template <typename ScalarT, typename IdxT>
__attribute__((always_inline)) static ScalarT sparse_load(IdxT, IdxT, IdxT*, IdxT*, ScalarT*)
FORCE_INLINE static ScalarT sparse_load(IdxT, IdxT, IdxT*, IdxT*, ScalarT*)
{
return 0.0;
}
Expand All @@ -263,7 +263,7 @@ namespace GridKit
* @tparam IdxT - matrix index data type
*/
template <typename ScalarT, typename IdxT>
__attribute__((always_inline)) static void ident_store(ScalarT, IdxT, IdxT)
FORCE_INLINE static void ident_store(ScalarT, IdxT, IdxT)
{
assert(0 && "should never store");
}
Expand All @@ -275,7 +275,7 @@ namespace GridKit
* @tparam IdxT - matrix index data type
*/
template <typename ScalarT, typename IdxT>
__attribute__((always_inline)) static ScalarT ident_load(IdxT row, IdxT col)
FORCE_INLINE static ScalarT ident_load(IdxT row, IdxT col)
{
row /= sizeof(ScalarT);
return (ScalarT) (row == col);
Expand Down
33 changes: 17 additions & 16 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 no-offset deadbanded value
*/
template <class ScalarT, typename RealT>
__attribute__((always_inline)) inline ScalarT deadband1(
FORCE_INLINE ScalarT deadband1(
const ScalarT x,
const RealT lower,
const RealT upper)
Expand All @@ -200,7 +201,7 @@ namespace GridKit
* @return Smooth offset deadbanded value
*/
template <class ScalarT, typename RealT>
__attribute__((always_inline)) inline ScalarT deadband2(
FORCE_INLINE ScalarT deadband2(
const ScalarT x,
const RealT lower,
const RealT upper)
Expand All @@ -222,7 +223,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 @@ -247,7 +248,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 @@ -268,7 +269,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 @@ -286,7 +287,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 @@ -305,7 +306,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 @@ -326,7 +327,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 @@ -349,7 +350,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 @@ -383,7 +384,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
29 changes: 15 additions & 14 deletions GridKit/Model/PhasorDynamics/Branch/Branch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
#pragma once

#include <GridKit/Definitions.hpp>
#include <GridKit/Model/PhasorDynamics/Branch/BranchData.hpp>
#include <GridKit/Model/PhasorDynamics/Component.hpp>
#include <GridKit/Model/PhasorDynamics/ComponentSignals.hpp>
Expand Down Expand Up @@ -135,17 +136,17 @@ namespace GridKit
typename ModelDataT::Parameters parameter,
RealT& target);

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

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

ScalarT& Vr1()
{
Expand Down Expand Up @@ -188,13 +189,13 @@ namespace GridKit
}

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

private:
Expand Down
12 changes: 6 additions & 6 deletions GridKit/Model/PhasorDynamics/Branch/BranchImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,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(
const RealT G,
const RealT B,
const ScalarT Vr,
Expand All @@ -198,7 +198,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(
const RealT G,
const RealT B,
const ScalarT* wb,
Expand Down Expand Up @@ -234,7 +234,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]] const ScalarT* y,
[[maybe_unused]] const ScalarT* yp,
const ScalarT* wb,
Expand All @@ -250,7 +250,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]] const ScalarT* y,
[[maybe_unused]] const ScalarT* yp,
const ScalarT* wb,
Expand All @@ -266,7 +266,7 @@ namespace GridKit
*
*/
template <typename scalar_type, typename index_type>
__attribute__((always_inline)) int Branch<scalar_type, index_type>::evaluateBusResidual21(
FORCE_INLINE int Branch<scalar_type, index_type>::evaluateBusResidual21(
[[maybe_unused]] const ScalarT* y,
[[maybe_unused]] const ScalarT* yp,
const ScalarT* wb,
Expand All @@ -282,7 +282,7 @@ namespace GridKit
*
*/
template <typename scalar_type, typename index_type>
__attribute__((always_inline)) int Branch<scalar_type, index_type>::evaluateBusResidual22(
FORCE_INLINE int Branch<scalar_type, index_type>::evaluateBusResidual22(
[[maybe_unused]] const ScalarT* y,
[[maybe_unused]] const ScalarT* yp,
const ScalarT* wb,
Expand Down
5 changes: 3 additions & 2 deletions GridKit/Model/PhasorDynamics/BusFault/BusFault.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Bus Fault Component - Adam Birchfield */
#pragma once

#include <GridKit/Definitions.hpp>
#include <GridKit/Model/PhasorDynamics/BusBase.hpp>
#include <GridKit/Model/PhasorDynamics/Component.hpp>
#include <GridKit/Model/PhasorDynamics/ComponentSignals.hpp>
Expand Down Expand Up @@ -116,9 +117,9 @@ namespace GridKit
}

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

private:
Expand Down
4 changes: 2 additions & 2 deletions GridKit/Model/PhasorDynamics/BusFault/BusFaultImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace GridKit
*
*/
template <typename scalar_type, typename index_type>
__attribute__((always_inline)) int BusFault<scalar_type, index_type>::evaluateBusResidual(
FORCE_INLINE int BusFault<scalar_type, index_type>::evaluateBusResidual(
const ScalarT* y,
[[maybe_unused]] const ScalarT* yp,
[[maybe_unused]] const ScalarT* wb,
Expand All @@ -228,7 +228,7 @@ namespace GridKit
*
*/
template <typename scalar_type, typename index_type>
__attribute__((always_inline)) int BusFault<scalar_type, index_type>::evaluateInternalResidual(
FORCE_INLINE int BusFault<scalar_type, index_type>::evaluateInternalResidual(
const ScalarT* y,
[[maybe_unused]] const ScalarT* yp,
const ScalarT* wb,
Expand Down
Loading