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

Implementation of Standard numeric constants and matrix utility functions. More...

Include dependency graph for Standard_functions.cpp:

Functions

int sgn (int v)
 Computes the sign of an integer.
 
MatrixXcd vectorToMatrix (const vector< vector< complex< double > > > &vec)
 Converts a 2D vector of complex numbers to an Eigen matrix.
 
MatrixXd vectorToMatrix (const vector< vector< double > > &vec)
 Converts a 2D vector of complex numbers to an Eigen matrix.
 
vector< vector< complex< double > > > matrixToVector (const MatrixXcd &mat)
 Converts an Eigen matrix of complex numbers to a 2D vector.
 
vector< vector< double > > matrixToVector (const MatrixXd &mat)
 Converts an Eigen MatrixXd to a nested real vector.
 
MatrixXcd stack_u_4x_3xN (const MatrixXcd &u1, const MatrixXcd &u2, const MatrixXcd &u3, const MatrixXcd &u4)
 Stacks four input matrices into a single block column.
 
vector< vector< complex< double > > > mat_mul (const vector< vector< complex< double > > > &A, const vector< vector< complex< double > > > &B)
 Multiplies two matrices represented as 2D vectors.
 
vector< vector< complex< double > > > mul_scalar (const vector< vector< complex< double > > > &A, const complex< double > &scalar)
 Multiplies a matrix by a scalar value.
 
vector< vector< complex< double > > > mat_add (const vector< vector< complex< double > > > &A, const vector< vector< complex< double > > > &B)
 Adds two matrices of the same dimensions.
 
vector< vector< complex< double > > > mat_sub (const vector< vector< complex< double > > > &A, const vector< vector< complex< double > > > &B)
 Subtracts one matrix from another.
 
vector< vector< complex< double > > > mat_transpose (const vector< vector< complex< double > > > &A)
 Transposes a matrix.
 
vector< vector< complex< double > > > get_block (const vector< vector< complex< double > > > &Y, int r_off, int c_off, int r_num, int c_num)
 Extracts a block (submatrix) from a given matrix.
 

Variables

const double mu_0 = 4 * M_PI * 1e-7
 Magnetic constant (permeability of free space).
 
const double epsilon_0 = 8.854e-12
 Electric constant (permittivity of free space).
 
const double gamma_num = 0.5772156649
 Euler-Mascheroni constant.
 

Detailed Description

Implementation of Standard numeric constants and matrix utility functions.

Function Documentation

◆ get_block()

vector< vector< complex< double > > > get_block ( const vector< vector< complex< double > > > &  Y,
int  r_off,
int  c_off,
int  r_num,
int  c_num 
)
extern

Extracts a block (submatrix) from a given matrix.

Extracts a rectangular sub-block from a complex matrix.

Parameters
YThe source matrix.
r_offThe starting row index of the block.
c_offThe starting column index of the block.
r_numThe number of rows in the block.
c_numThe number of columns in the block.
Returns
A new matrix containing the specified block.

References j.

Referenced by Element::apply_transformation().

◆ mat_add()

vector< vector< complex< double > > > mat_add ( const vector< vector< complex< double > > > &  A,
const vector< vector< complex< double > > > &  B 
)

Adds two matrices of the same dimensions.

Element-wise addition of two complex matrices.

Parameters
AThe first matrix.
BThe second matrix.
Returns
The resulting matrix C = A + B.

References j.

Referenced by Element::apply_transformation().

◆ mat_mul()

vector< vector< complex< double > > > mat_mul ( const vector< vector< complex< double > > > &  A,
const vector< vector< complex< double > > > &  B 
)

Multiplies two matrices represented as 2D vectors.

Complex matrix multiplication using nested vectors.

Parameters
AThe left-hand side matrix.
BThe right-hand side matrix.
Returns
The resulting matrix C = A * B.
Exceptions
std::runtime_errorif matrix dimensions are incompatible for multiplication.

References j.

Referenced by Element::apply_transformation().

◆ mat_sub()

vector< vector< complex< double > > > mat_sub ( const vector< vector< complex< double > > > &  A,
const vector< vector< complex< double > > > &  B 
)

Subtracts one matrix from another.

Element-wise subtraction of two complex matrices.

Parameters
AThe matrix from which to subtract.
BThe matrix to subtract.
Returns
The resulting matrix C = A - B.

References j.

◆ mat_transpose()

vector< vector< complex< double > > > mat_transpose ( const vector< vector< complex< double > > > &  A)

Transposes a matrix.

Transposes a complex matrix stored as nested vectors.

Parameters
AThe matrix to transpose.
Returns
The transposed matrix.

References j.

Referenced by Element::apply_transformation().

◆ matrixToVector() [1/2]

vector< vector< complex< double > > > matrixToVector ( const MatrixXcd &  mat)

Converts an Eigen matrix of complex numbers to a 2D vector.

Converts an Eigen MatrixXcd to a nested complex vector.

Parameters
matThe input Eigen::MatrixXcd.
Returns
A 2D vector representation of the input matrix.

References j.

Referenced by Converter::plotParticipationFactors().

◆ matrixToVector() [2/2]

vector< vector< double > > matrixToVector ( const MatrixXd &  mat)

Converts an Eigen MatrixXd to a nested real vector.

Parameters
matInput real matrix.
Returns
2-D vector representation.

References j.

◆ mul_scalar()

vector< vector< complex< double > > > mul_scalar ( const vector< vector< complex< double > > > &  A,
const complex< double > &  scalar 
)

Multiplies a matrix by a scalar value.

Scales every entry of a complex matrix by a scalar.

Parameters
AThe matrix to be multiplied.
scalarThe complex scalar value.
Returns
The resulting matrix C = A * scalar.

References j.

Referenced by Element::apply_transformation().

◆ sgn()

int sgn ( int  v)

Computes the sign of an integer.

Returns the sign of an integer.

Parameters
vThe integer value.
Returns
1 if v > 0, -1 if v < 0, and 0 if v == 0.

Referenced by dq_multiply().

◆ stack_u_4x_3xN()

MatrixXcd stack_u_4x_3xN ( const MatrixXcd &  u1,
const MatrixXcd &  u2,
const MatrixXcd &  u3,
const MatrixXcd &  u4 
)

Stacks four input matrices into a single block column.

Parameters
u1First input block.
u2Second input block.
u3Third input block.
u4Fourth input block.
Returns
Vertically stacked complex matrix.

◆ vectorToMatrix() [1/2]

MatrixXcd vectorToMatrix ( const vector< vector< complex< double > > > &  vec)

Converts a 2D vector of complex numbers to an Eigen matrix.

Converts a nested complex vector to an Eigen MatrixXcd.

Parameters
vecThe input 2D vector (matrix).
Returns
An Eigen::MatrixXcd representation of the input vector.
Exceptions
std::runtime_errorif the inner vectors have inconsistent lengths.

References j.

Referenced by StabilityEstimate::compute_transfer_function(), example_MMC(), and example_stability_check().

◆ vectorToMatrix() [2/2]

MatrixXd vectorToMatrix ( const vector< vector< double > > &  vec)

Converts a 2D vector of complex numbers to an Eigen matrix.

Converts a nested real vector to an Eigen MatrixXd.

Parameters
vecThe input 2D vector (matrix).
Returns
An Eigen::MatrixXcd representation of the input vector.
Exceptions
std::runtime_errorif the inner vectors have inconsistent lengths.

References j.

Variable Documentation

◆ epsilon_0

const double epsilon_0 = 8.854e-12

Electric constant (permittivity of free space).

Vacuum permittivity (F/m).

Referenced by Cable::Cable(), and Overhead_Line::Overhead_Line().

◆ gamma_num

const double gamma_num = 0.5772156649

Euler-Mascheroni constant.

Euler–Mascheroni constant.

Referenced by Cable::Cable().

◆ mu_0

const double mu_0 = 4 * M_PI * 1e-7

Magnetic constant (permeability of free space).

Vacuum permeability (H/m).

Referenced by Cable::Cable(), and Overhead_Line::Overhead_Line().