Harmony
HARMONic stabilitY assessment of PE-penetrated power systems
Loading...
Searching...
No Matches
DQsym_Conversion_Functions.cpp File Reference

Implementation of Dynamic-phasor arithmetic and abc ↔ dqn domain conversions. More...

Include dependency graph for DQsym_Conversion_Functions.cpp:

Functions

MatrixXcd dq_add (const MatrixXcd &a, const MatrixXcd &b)
 Adds two complex matrices element-wise, handling different sizes.
 
MatrixXcd dq_subtract (const MatrixXcd &a, const MatrixXcd &b)
 Subtracts one complex matrix from another element-wise, handling different sizes.
 
MatrixXcd dq_multiply (const MatrixXcd &x_coef1_in, const MatrixXcd &y_coef1_in)
 Three-phase product of two dynamic-phasor series (harmonic convolution).
 
MatrixXcd dq_integrate (MatrixXcd &Zpnz_old, MatrixXcd &Xpnz_old, const MatrixXcd &Xpnz, double dt, double w)
 Dynamic-phasor (DQ0) integrator per harmonic order.
 
void convertToPhasor (const MatrixXcd &A, const MatrixXcd &B, const MatrixXcd &C, const MatrixXcd &D, MatrixXcd &Adc, MatrixXcd &Bdc, MatrixXcd &Cdc, MatrixXcd &Ddc)
 Convert state-space matrices into the phasor/DQ0 domain.
 
MatrixXcd truncateHarmonics (const MatrixXcd &X, int nColsToKeep)
 Truncates harmonic columns beyond nKeep in a coefficient matrix.
 
Vector3d dqn2abc_at_time (const MatrixXcd &Xdcpnz_c, double theta)
 Reconstruct abc instantaneous values from dynamic phasor pnz coefficients at one angle theta.
 
std::vector< Vector3d > dqn2abc_groups_at_time (const MatrixXcd &Y, double theta)
 Convert all 3-row output groups of Y to abc at a single electrical angle.
 
ABCResult simulate_dqn2abc (const MatrixXcd &Xdcpnz_c, double freq_hz, double t0, double t1, double Ts)
 Simulate abc waveform reconstruction over a time interval from dynamic phasor coefficients.
 

Detailed Description

Implementation of Dynamic-phasor arithmetic and abc ↔ dqn domain conversions.

Function Documentation

◆ convertToPhasor()

void convertToPhasor ( const MatrixXcd &  A,
const MatrixXcd &  B,
const MatrixXcd &  C,
const MatrixXcd &  D,
MatrixXcd &  Adc,
MatrixXcd &  Bdc,
MatrixXcd &  Cdc,
MatrixXcd &  Ddc 
)

Convert state-space matrices into the phasor/DQ0 domain.

Converts abc-stacked state-space matrices to phasor/sequence domain.

References j.

Referenced by DQsym::DSSS().

◆ dq_add()

MatrixXcd dq_add ( const MatrixXcd &  a,
const MatrixXcd &  b 
)

Adds two complex matrices element-wise, handling different sizes.

Element-wise addition of two dynamic-phasor coefficient matrices.

This function computes the sum of two matrices, a and b. If the matrices have different dimensions, the result matrix is sized to encompass both, effectively zero-padding the smaller matrix before addition.

Parameters
aThe first matrix operand.
bThe second matrix operand.
Returns
A new matrix representing the sum of a and b.

Referenced by example_DQsym_math_operations().

◆ dq_integrate()

MatrixXcd dq_integrate ( MatrixXcd &  Zpnz_old,
MatrixXcd &  Xpnz_old,
const MatrixXcd &  Xpnz,
double  dt,
double  w 
)

Dynamic-phasor (DQ0) integrator per harmonic order.

Integrates a dynamic-phasor signal over one time step.

Referenced by example_DQsym_math_operations().

◆ dq_multiply()

MatrixXcd dq_multiply ( const MatrixXcd &  x_coef1_in,
const MatrixXcd &  y_coef1_in 
)

Three-phase product of two dynamic-phasor series (harmonic convolution).

Multiplies two dynamic-phasor coefficient matrices (convolution in harmonic domain).

C++ translation aligned with MATLAB: Zdcpnz_c = SICO_DPs_3ph(x_coef1, y_coef1, N)

Input convention:

  • 3 rows = abc phases
  • column 0 = DC term
  • column k = harmonic k

Output:

  • 3 x (2N+1) matrix in abc basis, where N = max(input harmonic order)

References s, and sgn().

Referenced by example_DQsym_math_operations(), and MMC::simulateInputStep().

◆ dq_subtract()

MatrixXcd dq_subtract ( const MatrixXcd &  a,
const MatrixXcd &  b 
)

Subtracts one complex matrix from another element-wise, handling different sizes.

Element-wise subtraction of two dynamic-phasor coefficient matrices.

This function computes the difference of two matrices, a - b. If the matrices have different dimensions, the result matrix is sized to encompass both, effectively zero-padding the smaller matrix before subtraction.

Parameters
aThe matrix to subtract from (minuend).
bThe matrix to subtract (subtrahend).
Returns
A new matrix representing the difference a - b.

Referenced by example_DQsym_math_operations().

◆ dqn2abc_at_time()

Vector3d dqn2abc_at_time ( const MatrixXcd &  Xdcpnz_c,
double  theta 
)

Reconstruct abc instantaneous values from dynamic phasor pnz coefficients at one angle theta.

Reconstructs abc phase values from a 3×H dqn block at one angle.

Input format:

  • rows = 3 : positive, negative, zero sequence
  • cols = harmonic orders, where col(0) is DC and col(h) is harmonic h
Parameters
Xdcpnz_c3 x Nh complex coefficient matrix
thetaelectrical angle [rad]
Returns
Vector3d instantaneous abc values at theta

Referenced by dqn2abc_groups_at_time(), and simulate_dqn2abc().

◆ dqn2abc_groups_at_time()

std::vector< Vector3d > dqn2abc_groups_at_time ( const MatrixXcd &  Y,
double  theta 
)

Convert all 3-row output groups of Y to abc at a single electrical angle.

Reconstructs abc values for all 3-row output groups at one angle.

Y is expected to have rows grouped as:

  • rows 0..2 : group 1
  • rows 3..5 : group 2
  • rows 6..8 : group 3
  • ...

Each 3-row group is interpreted as a 3xH dynamic-phasor sequence matrix and converted to one instantaneous abc vector at the supplied angle theta.

Parameters
YA matrix with row count equal to 3 * number_of_groups.
thetaElectrical angle [rad] at this one instant in time.
Returns
A vector of abc instantaneous vectors, one per 3-row group.

References dqn2abc_at_time().

Referenced by example_DQsym_DSSS2(), example_DQsym_RLC(), and DQsym::run().

◆ simulate_dqn2abc()

ABCResult simulate_dqn2abc ( const MatrixXcd &  Xdcpnz_c,
double  freq_hz,
double  t0,
double  t1,
double  Ts 
)

Simulate abc waveform reconstruction over a time interval from dynamic phasor coefficients.

Simulates abc waveform reconstruction over a time interval.

Parameters
Xdcpnz_c3 x Nh complex coefficient matrix
freq_hzbase electrical frequency [Hz]
t0start time [s]
t1end time [s]
Tssample time [s]
Returns
ABCResult containing time vector and Nx3 abc waveform matrix

References dqn2abc_at_time(), ABCResult::t, and ABCResult::Xabc.

Referenced by example_DQsym_math_operations().

◆ truncateHarmonics()

MatrixXcd truncateHarmonics ( const MatrixXcd &  X,
int  nColsToKeep 
)

Truncates harmonic columns beyond nKeep in a coefficient matrix.

Parameters
XInput coefficient matrix (3 rows × H columns).
nColsToKeepNumber of harmonic columns to retain.
Returns
Truncated matrix.

Referenced by MMC::simulateInputStep().