Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
26c9def
Define M_PI for MSVC
andrewxu319 Jun 9, 2026
b1c0695
Extract .string() from filename() in parseArgs for Windows
andrewxu319 Jun 9, 2026
5022813
Define FORCE_INLINE macro and make it compiler-specific
andrewxu319 Jun 9, 2026
d2e6a3e
Make sure CommonMath.hpp includes the FORCE_INLINE definition.
andrewxu319 Jun 9, 2026
af17444
Make toUpper() inline to preserve ODR.
andrewxu319 Jun 9, 2026
a5d7e80
Update docs
andrewxu319 Jun 9, 2026
04c4c6e
Remove MSVC PI_M definition. Turns out it's already defined by MSVC. …
andrewxu319 Jun 9, 2026
f45c21c
Update CHANGELOG.md
andrewxu319 Jun 10, 2026
5d62214
Apply pre-commmit fixes
andrewxu319 Jun 10, 2026
d0b0c75
Fix phasor_dynamics_systemmodel targets. (#444)
nkoukpaizan Jun 10, 2026
3e06ec4
Revert "Update docs"
andrewxu319 Jun 11, 2026
5ffbf8d
Merge branch 'andrew/windows-compatibility' of github.com:ORNL/GridKi…
andrewxu319 Jun 11, 2026
053a0cf
Apply pre-commmit fixes
andrewxu319 Jun 10, 2026
f5264f9
Merge branch 'andrew/windows-compatibility' of github.com:ORNL/GridKi…
andrewxu319 Jun 12, 2026
817619c
Define M_PI for MSVC
andrewxu319 Jun 9, 2026
e969af6
Extract .string() from filename() in parseArgs for Windows
andrewxu319 Jun 9, 2026
3636f69
Define FORCE_INLINE macro and make it compiler-specific
andrewxu319 Jun 9, 2026
f9d632b
Make sure CommonMath.hpp includes the FORCE_INLINE definition.
andrewxu319 Jun 9, 2026
ad2cd86
Make toUpper() inline to preserve ODR.
andrewxu319 Jun 9, 2026
dae871c
Update docs
andrewxu319 Jun 9, 2026
a2c4de5
Remove MSVC PI_M definition. Turns out it's already defined by MSVC. …
andrewxu319 Jun 9, 2026
cc5cab8
Update CHANGELOG.md
andrewxu319 Jun 10, 2026
7ddaca5
Revert "Update docs"
andrewxu319 Jun 11, 2026
fcceb73
Apply pre-commmit fixes
andrewxu319 Jun 10, 2026
1319d89
Merge branch 'andrew/windows-compatibility' of github.com:ORNL/GridKi…
andrewxu319 Jun 12, 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
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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specify it's mingw g++ only or list caveats with msvc. also consider testing llvm on windows as well (uncommon, but would allow enzyme to work, maybe).


## 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you used the standard syntax for attributes, such as [[gnu::always_inline]] instead of __attribute__((always_inline)), this macro wouldn't be necessary as you could write [[msvc::forceinline, gnu::always_inline]].

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least, in my testing w/ clang, clang ignores the msvc::forceinline, raising a warning but compiles just fine. perhaps msvc doesn't like seeing gnu::always_inline, but that would be weird. could just ignore that warning via flags or something like that to reduce noise. alternatively, keep the conditional macro but using the standard syntax anyway.

#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
49 changes: 25 additions & 24 deletions GridKit/Model/PhasorDynamics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,6 @@ target_link_libraries(
phasor_dynamics_components_dependency_tracking
INTERFACE GridKit::phasor_dynamics_core)

gridkit_add_library(
phasor_dynamics_systemmodel
SOURCES SystemModel.cpp SystemModelData.cpp
HEADERS SystemModel.hpp SystemModelData.hpp
LINK_LIBRARIES PUBLIC GridKit::phasor_dynamics_core
INCLUDE_DIRECTORIES
PRIVATE
${GRIDKIT_THIRD_PARTY_DIR}/nlohmann-json/include
PRIVATE
${GRIDKIT_THIRD_PARTY_DIR}/magic-enum/include)

gridkit_add_library(
phasor_dynamics_systemmodel_dependency_tracking
SOURCES SystemModelDependencyTracking.cpp
HEADERS SystemModel.hpp
LINK_LIBRARIES PUBLIC GridKit::phasor_dynamics_core)

target_link_libraries(
phasor_dynamics_components
INTERFACE GridKit::phasor_dynamics_systemmodel)
target_link_libraries(
phasor_dynamics_components_dependency_tracking
INTERFACE GridKit::phasor_dynamics_systemmodel_dependency_tracking)

add_subdirectory(Branch)
add_subdirectory(Bus)
add_subdirectory(BusFault)
Expand All @@ -70,5 +46,30 @@ add_library(GridKit::phasor_dynamics_components ALIAS phasor_dynamics_components
add_library(GridKit::phasor_dynamics_components_dependency_tracking ALIAS
phasor_dynamics_components_dependency_tracking)

gridkit_add_library(
phasor_dynamics_systemmodel
SOURCES SystemModel.cpp SystemModelData.cpp
HEADERS SystemModel.hpp SystemModelData.hpp
LINK_LIBRARIES
PUBLIC
GridKit::phasor_dynamics_core
PUBLIC
GridKit::phasor_dynamics_components
INCLUDE_DIRECTORIES
PRIVATE
${GRIDKIT_THIRD_PARTY_DIR}/nlohmann-json/include
PRIVATE
${GRIDKIT_THIRD_PARTY_DIR}/magic-enum/include)

gridkit_add_library(
phasor_dynamics_systemmodel_dependency_tracking
SOURCES SystemModelDependencyTracking.cpp
HEADERS SystemModel.hpp
LINK_LIBRARIES
PUBLIC
GridKit::phasor_dynamics_core
PUBLIC
GridKit::phasor_dynamics_components_dependency_tracking)

install(TARGETS phasor_dynamics_components phasor_dynamics_components_dependency_tracking
EXPORT gridkit-targets)
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
Loading
Loading