DPsim
Loading...
Searching...
No Matches
HydroTurbine.cpp
1// SPDX-FileCopyrightText: 2026 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University
2// SPDX-License-Identifier: MPL-2.0
3
4#include <dpsim-models/Signal/HydroTurbine.h>
5
6using namespace CPS;
7using namespace CPS::Signal;
8
9Signal::HydroTurbine::HydroTurbine(const String &name,
10 CPS::Logger::Level logLevel)
11 : SimSignalComp(name, name, logLevel), mX1(mAttributes->create<Real>("X1")),
12 mPm(mAttributes->create<Real>("Pm")) {}
13
14void HydroTurbine::setParameters(
15 std::shared_ptr<Base::TurbineParameters> parameters) {
16 auto params =
17 std::dynamic_pointer_cast<Signal::HydroTurbineParameters>(parameters);
18 if (!params) {
19 SPDLOG_LOGGER_ERROR(
20 mSLog,
21 "Type of parameters class of {} has to be HydroTurbineParameters!",
22 this->name());
23 throw CPS::TypeException();
24 }
25 if (params->Tw == 0) {
26 SPDLOG_LOGGER_ERROR(mSLog, "Tw must not be zero for {}", this->name());
27 throw CPS::InvalidArgumentException();
28 }
29 mParameters = params;
30
31 SPDLOG_LOGGER_INFO(mSLog,
32 "Hydro turbine parameters:"
33 "\nTw: {:e}",
34 mParameters->Tw);
35 mSLog->flush();
36}
37
39 if (Pminit < 0 || Pminit > 1) {
40 SPDLOG_LOGGER_ERROR(
41 mSLog,
42 "Initial mechanical power of hydro turbine {} must be in [0, 1] pu",
43 this->name());
45 }
46 **mX1 = Pminit;
47 mX1_next = Pminit;
48 **mPm = Pminit;
49
50 SPDLOG_LOGGER_INFO(mSLog,
51 "Hydro turbine initial values:"
52 "\nX1: {:f}"
53 "\nPm: {:f}",
54 **mX1, **mPm);
55 mSLog->flush();
56}
57
58Real HydroTurbine::step(Real Pgv, Real dt) {
59 // Shift pre-computed next value into current
60 **mX1 = mX1_next;
61
62 // Forward-Euler integration: PT1 with time constant Tw/2
63 mX1_next = **mX1 + (2.0 * dt / mParameters->Tw) * (Pgv - **mX1);
64
65 // Mechanical power output
66 **mPm = 3.0 * **mX1 - 2.0 * Pgv;
67
68 return **mPm;
69}
void initializeStates(Real Pminit) final
Set steady-state initial values (call after setParameters, before first step)
Real step(Real Pgv, Real dt) final
Step the turbine with valve/gate opening Pgv and return mechanical power Pm.
Logger::Log mSLog
Component logger.