Skip to content
Draft
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
4 changes: 3 additions & 1 deletion .github/workflows/build_test_linux_fedora.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ jobs:
PYTHONPATH: "${{ github.workspace }}/build"
run: |
cp -r python/src/dpsim build/
pytest -n auto --cov --cov-branch --cov-report=xml examples/Notebooks/
pytest -n auto -vv -ra --tb=long --showlocals --durations=20 \
--cov --cov-branch --cov-report=xml --cov-report=term-missing \
examples/Notebooks/

- name: Archive notebook outputs
uses: actions/upload-artifact@v4
Expand Down
34 changes: 34 additions & 0 deletions dpsim-models/include/dpsim-models/Base/Base_Exciter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: 2025 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University
// SPDX-License-Identifier: MPL-2.0

#pragma once

#include <dpsim-models/Definitions.h>

namespace CPS {
namespace Base {

class ExciterParameters {
public:
ExciterParameters(){};
virtual ~ExciterParameters() = default;
};

/// @brief Base model for exciters
class Exciter {

public:
virtual ~Exciter() = default;

/// Sets exciter parameters
virtual void
setParameters(std::shared_ptr<Base::ExciterParameters> parameters) = 0;

/// Initializes exciter variables
virtual void initialize(Real Vh_init, Real Ef_init) = 0;

/// @param V_pss: Output of PSS
virtual Real step(Real Vd, Real Vq, Real dt, Real Vpss = 0) = 0;
};
} // namespace Base
} // namespace CPS
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#pragma once

#include <dpsim-models/Base/Base_Exciter.h>
#include <dpsim-models/MNASimPowerComp.h>
#include <dpsim-models/Signal/Exciter.h>
#include <dpsim-models/Signal/TurbineGovernorType1.h>
#include <dpsim-models/Solver/MNAInterface.h>

Expand Down Expand Up @@ -39,6 +39,8 @@ class ReducedOrderSynchronGenerator : public MNASimPowerComp<VarType> {
/// (0,0) = Id
/// (1,0) = Iq
const Attribute<Matrix>::Ptr mIdq;
/// Electrical power
const Attribute<Complex>::Ptr mPower;
/// stator electrical torque
const Attribute<Real>::Ptr mElecTorque;
/// Mechanical torque
Expand Down Expand Up @@ -89,9 +91,14 @@ class ReducedOrderSynchronGenerator : public MNASimPowerComp<VarType> {
void
addGovernor(std::shared_ptr<Signal::TurbineGovernorType1> turbineGovernor);
/// Add voltage regulator and exciter
void addExciter(std::shared_ptr<Base::Exciter> exciter,
std::shared_ptr<Base::ExciterParameters> params);
/// Add already constructed regulator and exciter
void addExciter(std::shared_ptr<Base::Exciter> exciter);

// Deprecated method
void addExciter(Real Ta, Real Ka, Real Te, Real Ke, Real Tf, Real Kf,
Real Tr);
void addExciter(std::shared_ptr<Signal::Exciter> exciter);

/// ### Setters ###
void scaleInertiaConstant(Real scalingFactor);
Expand Down Expand Up @@ -262,11 +269,12 @@ class ReducedOrderSynchronGenerator : public MNASimPowerComp<VarType> {
/// Signal component modelling governor control and steam turbine
std::shared_ptr<Signal::TurbineGovernorType1> mTurbineGovernor;
/// Signal component modelling voltage regulator and exciter
std::shared_ptr<Signal::Exciter> mExciter;
std::shared_ptr<Base::Exciter> mExciter;

///
Real mTimeStep;
Real mSimTime;
Real mVpss = 0;
};
} // namespace Base
} // namespace CPS
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#pragma once

#include <dpsim-models/AttributeList.h>
#include <dpsim-models/Base/Base_Exciter.h>
#include <dpsim-models/Definitions.h>
#include <dpsim-models/Signal/Exciter.h>
#include <dpsim-models/Signal/TurbineGovernor.h>

namespace CPS {
Expand All @@ -35,7 +35,14 @@ class SynchronGenerator {
/// Add governor and turbine
void addGovernor(Real Ta, Real Tb, Real Tc, Real Fa, Real Fb, Real Fc, Real K,
Real Tsr, Real Tsm, Real Tm_init, Real PmRef);

/// Add voltage regulator and exciter
void addExciter(std::shared_ptr<Base::Exciter> exciter,
std::shared_ptr<Base::ExciterParameters> params);
/// Add already constructed regulator and exciter
void addExciter(std::shared_ptr<Base::Exciter> exciter);

// Deprecated method
void addExciter(Real Ta, Real Ka, Real Te, Real Ke, Real Tf, Real Kf,
Real Tr);

Expand Down Expand Up @@ -362,7 +369,7 @@ class SynchronGenerator {
/// Signal component modelling governor control and steam turbine
std::shared_ptr<Signal::TurbineGovernor> mTurbineGovernor;
/// Signal component modelling voltage regulator and exciter
std::shared_ptr<Signal::Exciter> mExciter;
std::shared_ptr<Base::Exciter> mExciter;
};
} // namespace Base
} // namespace CPS
5 changes: 4 additions & 1 deletion dpsim-models/include/dpsim-models/Components.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@
#include <dpsim-models/Signal/DecouplingLine.h>
#include <dpsim-models/Signal/DecouplingLineEMT.h>
#include <dpsim-models/Signal/DecouplingLineEMT_Ph3.h>
#include <dpsim-models/Signal/Exciter.h>
#include <dpsim-models/Signal/ExciterDC1.h>
#include <dpsim-models/Signal/ExciterDC1Simp.h>
#include <dpsim-models/Signal/ExciterST1Simp.h>
#include <dpsim-models/Signal/ExciterStatic.h>
#include <dpsim-models/Signal/FIRFilter.h>
#include <dpsim-models/Signal/FrequencyRampGenerator.h>
#include <dpsim-models/Signal/Integrator.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#pragma once

#include <dpsim-models/Base/Base_Exciter.h>
#include <dpsim-models/Base/Base_SynchronGenerator.h>
#include <dpsim-models/Signal/Exciter.h>
#include <dpsim-models/Signal/TurbineGovernor.h>
#include <dpsim-models/SimPowerComp.h>
#include <dpsim-models/Solver/MNAInterface.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

#pragma once

#include <dpsim-models/Base/Base_Exciter.h>
#include <dpsim-models/Base/Base_SynchronGenerator.h>
#include <dpsim-models/EMT/EMT_Ph1_Resistor.h>
#include <dpsim-models/EMT/EMT_Ph1_VoltageSource.h>
#include <dpsim-models/MNASimPowerComp.h>
#include <dpsim-models/Signal/Exciter.h>
#include <dpsim-models/Signal/TurbineGovernor.h>
#include <dpsim-models/Solver/MNAInterface.h>
#include <dpsim-models/Solver/MNAVariableCompInterface.h>
Expand Down
26 changes: 25 additions & 1 deletion dpsim-models/include/dpsim-models/Factory.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#include <map>

#include <dpsim-models/Definitions.h>
#include <dpsim-models/Logger.h>
#include <map>

#include <dpsim-models/Base/Base_Exciter.h>
#include <dpsim-models/Base/Base_ReducedOrderSynchronGenerator.h>

#include <dpsim-models/DP/DP_Ph1_SynchronGenerator4OrderPCM.h>
#include <dpsim-models/DP/DP_Ph1_SynchronGenerator4OrderTPM.h>
#include <dpsim-models/DP/DP_Ph1_SynchronGenerator6OrderPCM.h>

#include <dpsim-models/Signal/ExciterDC1.h>
#include <dpsim-models/Signal/ExciterDC1Simp.h>
#include <dpsim-models/Signal/ExciterST1Simp.h>
#include <dpsim-models/Signal/ExciterStatic.h>

#pragma once

template <class BaseClass> class Creator {
Expand Down Expand Up @@ -84,6 +92,22 @@ template <class BaseClass> class FactoryRegistration {
}
};

namespace ExciterFactory {
void registerExciters() {
FactoryRegistration<CPS::Base::Exciter> _ExciterDC1(
"DC1", new DerivedCreator<CPS::Signal::ExciterDC1, CPS::Base::Exciter>);
FactoryRegistration<CPS::Base::Exciter> _ExciterDC1Simp(
"DC1Simp",
new DerivedCreator<CPS::Signal::ExciterDC1Simp, CPS::Base::Exciter>);
FactoryRegistration<CPS::Base::Exciter> _ExciterST1Simp(
"ST1",
new DerivedCreator<CPS::Signal::ExciterST1Simp, CPS::Base::Exciter>);
FactoryRegistration<CPS::Base::Exciter> _ExciterStatic(
"Static",
new DerivedCreator<CPS::Signal::ExciterStatic, CPS::Base::Exciter>);
}
} // namespace ExciterFactory

namespace SynchronGeneratorFactory {
namespace SP {
namespace Ph1 {
Expand Down
36 changes: 36 additions & 0 deletions dpsim-models/include/dpsim-models/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#pragma once

#include <memory>

#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
#include <spdlog/spdlog.h>

Expand All @@ -19,6 +21,7 @@

#include <spdlog/fmt/ostr.h>

#include <dpsim-models/Attribute.h>
#include <dpsim-models/Definitions.h>
#include <dpsim-models/MathUtils.h>

Expand Down Expand Up @@ -72,6 +75,8 @@ class Logger {

#if FMT_VERSION >= 90000
template <>
class fmt::formatter<CPS::String> : public fmt::ostream_formatter {};
template <>
class fmt::formatter<CPS::Complex> : public fmt::ostream_formatter {};
template <>
class fmt::formatter<CPS::Vector> : public fmt::ostream_formatter {};
Expand Down Expand Up @@ -115,4 +120,35 @@ class fmt::formatter<Eigen::Block<CPS::Matrix>>
template <>
class fmt::formatter<Eigen::Block<CPS::MatrixComp>>
: public fmt::ostream_formatter {};

namespace fmt {
template <typename T> struct formatter<CPS::Attribute<T>> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) {
return ctx.begin();
}

template <typename FormatContext>
auto format(const CPS::Attribute<T> &attr, FormatContext &ctx) const {
auto &nc = const_cast<CPS::Attribute<T> &>(attr);
return fmt::format_to(ctx.out(), "{}", nc.get());
}
};

template <typename T> struct formatter<std::shared_ptr<CPS::Attribute<T>>> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) {
return ctx.begin();
}

template <typename FormatContext>
auto format(const std::shared_ptr<CPS::Attribute<T>> &p,
FormatContext &ctx) const {
if (!p)
return fmt::format_to(ctx.out(), "<null>");
auto &nc = const_cast<CPS::Attribute<T> &>(*p);
return fmt::format_to(ctx.out(), "{}", nc.get());
}
};

} // namespace fmt

#endif
83 changes: 0 additions & 83 deletions dpsim-models/include/dpsim-models/Signal/Exciter.h

This file was deleted.

Loading
Loading