diff --git a/GridKit/AutomaticDifferentiation/Enzyme/LowerSparseStorage.hpp b/GridKit/AutomaticDifferentiation/Enzyme/LowerSparseStorage.hpp index 6714a28a7..62eb08383 100644 --- a/GridKit/AutomaticDifferentiation/Enzyme/LowerSparseStorage.hpp +++ b/GridKit/AutomaticDifferentiation/Enzyme/LowerSparseStorage.hpp @@ -191,8 +191,8 @@ namespace GridKit * * @details This takes in a row, column and value and stores them in buffers * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type + * @tparam scalar_type - scalar data type + * @tparam index_type - matrix index data type * * @param[in] val - value to be stored * @param[in] row - row to be stored @@ -205,35 +205,35 @@ namespace GridKit * @param[in,out] vals - buffer where val will be stored * @param[in,out] nnz - number of nonzeros */ - template + template __attribute__((always_inline)) static void sparse_store( - ScalarT val, - IdxT row, - IdxT col, - ScalarT scaling, - const IdxT* row_indices, - const IdxT* col_indices, - IdxT* rows, - IdxT* cols, - ScalarT* vals, - IdxT& nnz) + scalar_type val, + index_type row, + index_type col, + scalar_type scaling, + const index_type* row_indices, + const index_type* col_indices, + index_type* rows, + index_type* cols, + scalar_type* vals, + index_type& nnz) { if (val == 0.0) return; - row /= sizeof(ScalarT); + row /= sizeof(scalar_type); // this template nightmare is because __attribute__((enzyme_sparse_accumulate)) does not support templates yet - if constexpr (std::is_same::value) + if constexpr (std::is_same::value) { - if constexpr (std::is_same::value) + if constexpr (std::is_same::value) inner_store_float_size_t(row, col, val, scaling, row_indices, col_indices, rows, cols, vals, nnz); else inner_store_double_size_t(row, col, val, scaling, row_indices, col_indices, rows, cols, vals, nnz); } - else if constexpr (std::is_same::value) + else if constexpr (std::is_same::value) { - if constexpr (std::is_same::value) + if constexpr (std::is_same::value) inner_store_float_long_int(row, col, val, scaling, row_indices, col_indices, rows, cols, vals, nnz); else inner_store_double_long_int(row, col, val, scaling, row_indices, col_indices, rows, cols, vals, nnz); @@ -247,11 +247,11 @@ namespace GridKit /** * @brief Enzyme sparse load * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type + * @tparam scalar_type - scalar data type + * @tparam index_type - matrix index data type */ - template - __attribute__((always_inline)) static ScalarT sparse_load(IdxT, IdxT, IdxT*, IdxT*, ScalarT*) + template + __attribute__((always_inline)) static scalar_type sparse_load(index_type, index_type, index_type*, index_type*, scalar_type*) { return 0.0; } @@ -259,11 +259,11 @@ namespace GridKit /** * @brief Enzyme identity store * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type + * @tparam scalar_type - scalar data type + * @tparam index_type - matrix index data type */ - template - __attribute__((always_inline)) static void ident_store(ScalarT, IdxT, IdxT) + template + __attribute__((always_inline)) static void ident_store(scalar_type, index_type, index_type) { assert(0 && "should never store"); } @@ -271,14 +271,14 @@ namespace GridKit /** * @brief Enzyme identity load * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type + * @tparam scalar_type - scalar data type + * @tparam index_type - matrix index data type */ - template - __attribute__((always_inline)) static ScalarT ident_load(IdxT row, IdxT col) + template + __attribute__((always_inline)) static scalar_type ident_load(index_type row, index_type col) { - row /= sizeof(ScalarT); - return (ScalarT) (row == col); + row /= sizeof(scalar_type); + return (scalar_type) (row == col); } } // namespace Sparse } // namespace Enzyme diff --git a/GridKit/CommonMath.hpp b/GridKit/CommonMath.hpp index e4a7ec87f..f2fdfbfe1 100644 --- a/GridKit/CommonMath.hpp +++ b/GridKit/CommonMath.hpp @@ -16,10 +16,10 @@ namespace GridKit * Used by @ref sigmoid, @ref ramp, and functions composed from them to set * the width of smooth transitions. * - * @tparam RealT - real data type + * @tparam real_type - real data type */ - template - inline constexpr RealT MU = 240.0; + template + inline constexpr real_type MU = 240.0; /** * @brief Scaled sigmoid activation function @@ -28,15 +28,16 @@ namespace GridKit * and finite derivatives. Large values more closely approximate a step * function, but can make the transition numerically stiff. * - * @tparam ScalarT - scalar data type + * @tparam scalar_type - scalar data type * * @param[in] x - expected to be of order 1 * @return value of the sigmoid function */ - template - __attribute__((always_inline)) inline ScalarT sigmoid(const ScalarT x) + template + __attribute__((always_inline)) inline scalar_type sigmoid(const scalar_type x) { - using RealT = typename GridKit::ScalarTraits::RealT; + using ScalarT = scalar_type; + using RealT = typename GridKit::ScalarTraits::RealT; return HALF * (ONE + std::tanh(HALF * MU * x)); } @@ -46,15 +47,16 @@ namespace GridKit * Smooth approximation to max(x, 0), using a stable softplus form with * the same scale as the rest of CommonMath. * - * @tparam ScalarT - scalar data type + * @tparam scalar_type - scalar data type * * @param[in] x - expected to be of order 1 * @return value of the smooth ramp function */ - template - __attribute__((always_inline)) inline ScalarT ramp(const ScalarT x) + template + __attribute__((always_inline)) inline scalar_type ramp(const scalar_type x) { - using RealT = typename GridKit::ScalarTraits::RealT; + using ScalarT = scalar_type; + using RealT = typename GridKit::ScalarTraits::RealT; RealT mu = MU; ScalarT a = std::abs(mu * x); @@ -70,13 +72,13 @@ namespace GridKit * @note Eventually a enzyme specialization for an exact implementation * would be nice, since the piecewise definition is C^1 continuous * - * @tparam ScalarT - scalar data type + * @tparam scalar_type - scalar data type * * @param[in] x - input signal * @return value of the quadratic ramp */ - template - __attribute__((always_inline)) inline ScalarT qramp(const ScalarT x) + template + __attribute__((always_inline)) inline scalar_type qramp(const scalar_type x) { return x * x * sigmoid(x); } @@ -87,8 +89,8 @@ namespace GridKit * Smooth approximation to max(x, y), composed from the smooth ramp * function. * - * @tparam LeftT - scalar type of x - * @tparam RightT - scalar type of y + * @tparam left_type - scalar type of x + * @tparam right_type - scalar type of y * * @param[in] x - First input signal * @param[in] y - Second input signal @@ -100,10 +102,10 @@ namespace GridKit * lets the expression promote to the differentiable scalar type without * forcing callers to cast every parameter. */ - template + template __attribute__((always_inline)) inline auto max( - const LeftT x, - const RightT y) + const left_type x, + const right_type y) { return y + ramp(x - y); } @@ -114,8 +116,8 @@ namespace GridKit * Smooth approximation to min(x, y), composed from the smooth ramp * function. * - * @tparam LeftT - scalar type of x - * @tparam RightT - scalar type of y + * @tparam left_type - scalar type of x + * @tparam right_type - scalar type of y * * @param[in] x - First input signal * @param[in] y - Second input signal @@ -127,10 +129,10 @@ namespace GridKit * lets the expression promote to the differentiable scalar type without * forcing callers to cast every parameter. */ - template + template __attribute__((always_inline)) inline auto min( - const LeftT x, - const RightT y) + const left_type x, + const right_type y) { return x - ramp(x - y); } @@ -142,20 +144,20 @@ namespace GridKit * smooth ramp function. Lower and upper bounds may be independent types * (e.g. constant Real bounds or algebraic-variable bounds). * - * @tparam ScalarT - scalar data type of the input signal - * @tparam LowerT - data type of the lower bound - * @tparam UpperT - data type of the upper bound + * @tparam scalar_type - scalar data type of the input signal + * @tparam lower_type - data type of the lower bound + * @tparam upper_type - data type of the upper bound * * @param[in] x - expected to be of order 1 * @param[in] lower - Lower limit * @param[in] upper - Upper limit * @return value of the smooth clamp function */ - template + template __attribute__((always_inline)) inline auto clamp( - const ScalarT x, - const LowerT lower, - const UpperT upper) + const scalar_type x, + const lower_type lower, + const upper_type upper) { assert(lower <= upper); return lower + ramp(x - lower) - ramp(x - upper); @@ -167,19 +169,19 @@ namespace GridKit * Smooth approximation to x - min(max(x, lower), upper), composed from the * smooth ramp function. * - * @tparam ScalarT - scalar data type - * @tparam RealT - Real data type (see GridKit::ScalarTraits::RealT) + * @tparam scalar_type - scalar data type + * @tparam real_type - Real data type (see GridKit::ScalarTraits::RealT) * * @param[in] x - Input signal * @param[in] lower - Lower breakpoint * @param[in] upper - Upper breakpoint * @return Smooth deadbanded value */ - template - __attribute__((always_inline)) inline ScalarT deadband( - const ScalarT x, - const RealT lower, - const RealT upper) + template + __attribute__((always_inline)) inline scalar_type deadband( + const scalar_type x, + const real_type lower, + const real_type upper) { assert(lower <= upper); return ramp(x - upper) - ramp(-(x - lower)); @@ -190,19 +192,19 @@ namespace GridKit * * Smooth approximation to min(max(f, -rate), rate). * - * @tparam ScalarT - scalar data type - * @tparam RealT - Real data type (see GridKit::ScalarTraits::RealT) + * @tparam scalar_type - scalar data type + * @tparam real_type - Real data type (see GridKit::ScalarTraits::RealT) * * @param[in] f - Pre-limit derivative or rate signal * @param[in] rate - Symmetric positive rate limit * @return Slew-rate-limited value of f */ - template - __attribute__((always_inline)) inline ScalarT slew( - const ScalarT f, - const RealT rate) + template + __attribute__((always_inline)) inline scalar_type slew( + const scalar_type f, + const real_type rate) { - assert(rate >= ZERO); + assert(rate >= ZERO); return clamp(f, -rate, rate); } @@ -213,8 +215,8 @@ namespace GridKit * lower, linear over [lower, upper], and saturated at height above upper. * Callers should supply lower < upper; height may be positive or negative. * - * @tparam ScalarT - scalar data type - * @tparam RealT - Real data type (see GridKit::ScalarTraits::RealT) + * @tparam scalar_type - scalar data type + * @tparam real_type - Real data type (see GridKit::ScalarTraits::RealT) * * @param[in] x - Input signal * @param[in] lower - Lower breakpoint @@ -222,12 +224,12 @@ namespace GridKit * @param[in] height - Saturated value above the upper breakpoint * @return Smooth linear segment contribution */ - template - __attribute__((always_inline)) inline ScalarT linseg( - const ScalarT x, - const RealT lower, - const RealT upper, - const RealT height) + template + __attribute__((always_inline)) inline scalar_type linseg( + const scalar_type x, + const real_type lower, + const real_type upper, + const real_type height) { assert(lower < upper); return height / (upper - lower) * (ramp(x - lower) - ramp(x - upper)); @@ -236,17 +238,17 @@ namespace GridKit /** * @brief Smooth above-limit indicator * - * @tparam ScalarT - Scalar data type - * @tparam RealT - Real data type (see GridKit::ScalarTraits::RealT) + * @tparam scalar_type - Scalar data type + * @tparam real_type - Real data type (see GridKit::ScalarTraits::RealT) * * @param[in] x - State variable * @param[in] limit_min - Minimum limit * @return Smooth indicator that x is above limit_min */ - template - __attribute__((always_inline)) inline ScalarT above( - const ScalarT x, - const RealT limit_min) + template + __attribute__((always_inline)) inline scalar_type above( + const scalar_type x, + const real_type limit_min) { return sigmoid(x - limit_min); } @@ -254,17 +256,17 @@ namespace GridKit /** * @brief Smooth below-limit indicator * - * @tparam ScalarT - Scalar data type - * @tparam RealT - Real data type (see GridKit::ScalarTraits::RealT) + * @tparam scalar_type - Scalar data type + * @tparam real_type - Real data type (see GridKit::ScalarTraits::RealT) * * @param[in] x - State variable * @param[in] limit_max - Maximum limit * @return Smooth indicator that x is below limit_max */ - template - __attribute__((always_inline)) inline ScalarT below( - const ScalarT x, - const RealT limit_max) + template + __attribute__((always_inline)) inline scalar_type below( + const scalar_type x, + const real_type limit_max) { return sigmoid(limit_max - x); } @@ -272,40 +274,40 @@ namespace GridKit /** * @brief Smooth inside-limits indicator * - * @tparam ScalarT - Scalar data type - * @tparam RealT - Real data type (see GridKit::ScalarTraits::RealT) + * @tparam scalar_type - Scalar data type + * @tparam real_type - Real data type (see GridKit::ScalarTraits::RealT) * * @param[in] x - State variable * @param[in] limit_min - Minimum limit * @param[in] limit_max - Maximum limit * @return Smooth indicator that x is inside [limit_min, limit_max] */ - template - __attribute__((always_inline)) inline ScalarT inside( - const ScalarT x, - const RealT limit_min, - const RealT limit_max) + template + __attribute__((always_inline)) inline scalar_type inside( + const scalar_type x, + const real_type limit_min, + const real_type limit_max) { assert(limit_min <= limit_max); - return above(x, limit_min) + below(x, limit_max) - ONE; + return above(x, limit_min) + below(x, limit_max) - ONE; } /** * @brief Smooth outside-limits indicator * - * @tparam ScalarT - Scalar data type - * @tparam RealT - Real data type (see GridKit::ScalarTraits::RealT) + * @tparam scalar_type - Scalar data type + * @tparam real_type - Real data type (see GridKit::ScalarTraits::RealT) * * @param[in] x - State variable * @param[in] limit_min - Minimum limit * @param[in] limit_max - Maximum limit * @return Smooth indicator that x is outside [limit_min, limit_max] */ - template - __attribute__((always_inline)) inline ScalarT outside( - const ScalarT x, - const RealT limit_min, - const RealT limit_max) + template + __attribute__((always_inline)) inline scalar_type outside( + const scalar_type x, + const real_type limit_min, + const real_type limit_max) { assert(limit_min <= limit_max); return below(x, limit_min) + above(x, limit_max); @@ -314,8 +316,8 @@ namespace GridKit /** * @brief Smooth anti-windup indicator for a limited state variable * - * @tparam ScalarT - Scalar data type - * @tparam RealT - Real data type (see GridKit::ScalarTraits::RealT) + * @tparam scalar_type - Scalar data type + * @tparam real_type - Real data type (see GridKit::ScalarTraits::RealT) * * @param[in] x - State variable * @param[in] f - Pre-limit derivative of the state variable @@ -324,14 +326,16 @@ namespace GridKit * @return Scalar value in [0, 1]: 1 when dynamics should pass through, * 0 when integration should be blocked. */ - template - __attribute__((always_inline)) inline ScalarT indicator( - const ScalarT x, - const ScalarT f, - const RealT limit_min, - const RealT limit_max) + template + __attribute__((always_inline)) inline scalar_type indicator( + const scalar_type x, + const scalar_type f, + const real_type limit_min, + const real_type limit_max) { assert(limit_min <= limit_max); + using ScalarT = scalar_type; + using RealT = real_type; ScalarT above_min = above(x, limit_min); ScalarT below_max = below(x, limit_max); @@ -349,8 +353,8 @@ namespace GridKit * passes interior dynamics, passes restoring motion from saturated limits, * and blocks motion that would push further into saturation. * - * @tparam ScalarT - Scalar data type - * @tparam RealT - Real data type (see GridKit::ScalarTraits::RealT) + * @tparam scalar_type - Scalar data type + * @tparam real_type - Real data type (see GridKit::ScalarTraits::RealT) * * @param[in] x - Limited state or limited output signal * @param[in] f - Pre-limit derivative @@ -358,12 +362,12 @@ namespace GridKit * @param[in] limit_max - Maximum limit * @return Smooth anti-windup limited derivative */ - template - __attribute__((always_inline)) inline ScalarT antiwindup( - const ScalarT x, - const ScalarT f, - const RealT limit_min, - const RealT limit_max) + template + __attribute__((always_inline)) inline scalar_type antiwindup( + const scalar_type x, + const scalar_type f, + const real_type limit_min, + const real_type limit_max) { return indicator(x, f, limit_min, limit_max) * f; } diff --git a/GridKit/Constants.hpp b/GridKit/Constants.hpp index ba58e7c38..ff46d6ae0 100644 --- a/GridKit/Constants.hpp +++ b/GridKit/Constants.hpp @@ -4,30 +4,30 @@ namespace GridKit { - template - inline constexpr IdxT INVALID_INDEX = std::numeric_limits::max(); + template + inline constexpr index_type INVALID_INDEX = std::numeric_limits::max(); - template - inline constexpr RealT ZERO = 0.0; + template + inline constexpr real_type ZERO = 0.0; - template - inline constexpr RealT ONE = 1.0; + template + inline constexpr real_type ONE = 1.0; - template - inline constexpr RealT TWO = 2.0; + template + inline constexpr real_type TWO = 2.0; - template - inline constexpr RealT THREE = 3.0; + template + inline constexpr real_type THREE = 3.0; - template - inline constexpr RealT FOUR = 4.0; + template + inline constexpr real_type FOUR = 4.0; - template - inline constexpr RealT HALF = 0.5; + template + inline constexpr real_type HALF = 0.5; - template - inline constexpr RealT QUARTER = 0.25; + template + inline constexpr real_type QUARTER = 0.25; - template - inline constexpr RealT MINUS_ONE = -1.0; + template + inline constexpr real_type MINUS_ONE = -1.0; } // namespace GridKit diff --git a/GridKit/LinearAlgebra/Solver/LinearSolver.hpp b/GridKit/LinearAlgebra/Solver/LinearSolver.hpp index 5d06ce758..7dfe95433 100644 --- a/GridKit/LinearAlgebra/Solver/LinearSolver.hpp +++ b/GridKit/LinearAlgebra/Solver/LinearSolver.hpp @@ -14,11 +14,13 @@ namespace GridKit * @brief An interface for linear solvers to be used in GridKit, such as in \ref Integrator::Rosenbrock. * */ - template + template class LinearSolver { public: - using RealT = GridKit::ScalarTraits::RealT; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = GridKit::ScalarTraits::RealT; /** * @brief Configure the solver by analyzing the given matrix. The sparsity pattern of the given matrix must be set, and future calls @@ -27,7 +29,8 @@ namespace GridKit * @param matrix The matrix to configure the solver with. * @return int An error code, or 0 if none. */ - virtual int configureSolver(GridKit::LinearAlgebra::CsrMatrix& matrix) = 0; + virtual int configureSolver(GridKit::LinearAlgebra::CsrMatrix& matrix) = 0; + /** * @brief Setup the solver with matrix data. * @@ -36,7 +39,8 @@ namespace GridKit * @pre If `reuse_factors` is true, then `setupSolver` must have been called once before with the same sparsity pattern. * @return int An error code, or 0 if none. */ - virtual int setupSolver(bool reuse_factors = false) = 0; + virtual int setupSolver(bool reuse_factors = false) = 0; + /** * @brief Perform a linear solve using the configured matrix. * diff --git a/GridKit/LinearAlgebra/Solver/ResolveSystemSolver.cpp b/GridKit/LinearAlgebra/Solver/ResolveSystemSolver.cpp index 4d6797147..0656018ac 100644 --- a/GridKit/LinearAlgebra/Solver/ResolveSystemSolver.cpp +++ b/GridKit/LinearAlgebra/Solver/ResolveSystemSolver.cpp @@ -24,8 +24,8 @@ namespace GridKit } } - template - ResolveSystemSolver::ResolveSystemSolver(ReSolve::SystemSolver& lin_solver, GridKit::memory::MemorySpace memspace) + template + ResolveSystemSolver::ResolveSystemSolver(ReSolve::SystemSolver& lin_solver, GridKit::memory::MemorySpace memspace) : lin_solver_(lin_solver), memspace_(memorySpaceAsResolve(memspace)) { } @@ -37,8 +37,8 @@ namespace GridKit * @todo Right now preconditioning doesn't work. There should be a ReSolve PR soon for this. * */ - template - int ResolveSystemSolver::configureSolver(GridKit::LinearAlgebra::CsrMatrix& matrix) + template + int ResolveSystemSolver::configureSolver(GridKit::LinearAlgebra::CsrMatrix& matrix) { matrix_ = std::make_unique(matrix.getNumRows(), matrix.getNumColumns(), matrix.getNnz()); @@ -59,8 +59,8 @@ namespace GridKit return 0; } - template - int ResolveSystemSolver::setupSolver(bool reuse_factors) + template + int ResolveSystemSolver::setupSolver(bool reuse_factors) { if (reuse_factors) { @@ -82,8 +82,8 @@ namespace GridKit * as well, this solve should correctly fill `lhs`'s data buffer. * */ - template - int ResolveSystemSolver::solve(GridKit::LinearAlgebra::Vector& rhs, GridKit::LinearAlgebra::Vector& lhs) + template + int ResolveSystemSolver::solve(GridKit::LinearAlgebra::Vector& rhs, GridKit::LinearAlgebra::Vector& lhs) { ReSolve::vector::Vector resolve_rhs(rhs.getSize()); ReSolve::vector::Vector resolve_lhs(lhs.getSize()); diff --git a/GridKit/LinearAlgebra/Solver/ResolveSystemSolver.hpp b/GridKit/LinearAlgebra/Solver/ResolveSystemSolver.hpp index 9ca55ef19..f28b3f45c 100644 --- a/GridKit/LinearAlgebra/Solver/ResolveSystemSolver.hpp +++ b/GridKit/LinearAlgebra/Solver/ResolveSystemSolver.hpp @@ -12,11 +12,13 @@ namespace GridKit { namespace LinearAlgebra { - template - class ResolveSystemSolver : public LinearSolver + template + class ResolveSystemSolver : public LinearSolver { public: - using RealT = LinearSolver::RealT; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = LinearSolver::RealT; ResolveSystemSolver(ReSolve::SystemSolver& lin_solver, GridKit::memory::MemorySpace memspace = GridKit::memory::HOST); diff --git a/GridKit/LinearAlgebra/SparseMatrix/CooMatrix.cpp b/GridKit/LinearAlgebra/SparseMatrix/CooMatrix.cpp index 37fccb935..8f54a2ab1 100644 --- a/GridKit/LinearAlgebra/SparseMatrix/CooMatrix.cpp +++ b/GridKit/LinearAlgebra/SparseMatrix/CooMatrix.cpp @@ -10,8 +10,8 @@ namespace GridKit { namespace LinearAlgebra { - template - CooMatrix::CooMatrix() + template + CooMatrix::CooMatrix() { } @@ -22,10 +22,10 @@ namespace GridKit * @param[in] m - number of columns * @param[in] nnz_ - number of non-zeros */ - template - CooMatrix::CooMatrix(IdxT n, - IdxT m, - IdxT nnz) + template + CooMatrix::CooMatrix(IdxT n, + IdxT m, + IdxT nnz) : n_{n}, m_{m}, nnz_{nnz} @@ -60,15 +60,15 @@ namespace GridKit * @param[in] memspace_src * @param[in] memspace_dst */ - template - CooMatrix::CooMatrix(IdxT n, - IdxT m, - IdxT nnz_, - IdxT** rows, - IdxT** cols, - RealT** vals, - memory::MemorySpace memspace_src, - memory::MemorySpace memspace_dst) + template + CooMatrix::CooMatrix(IdxT n, + IdxT m, + IdxT nnz_, + IdxT** rows, + IdxT** cols, + RealT** vals, + memory::MemorySpace memspace_src, + memory::MemorySpace memspace_dst) : CooMatrix(n, m, nnz_) { int control = -1; @@ -177,8 +177,8 @@ namespace GridKit } } - template - CooMatrix::~CooMatrix() + template + CooMatrix::~CooMatrix() { destroyMatrixData(memory::HOST); destroyMatrixData(memory::DEVICE); @@ -189,8 +189,8 @@ namespace GridKit /** * @brief set the matrix update flags to false (for both HOST and DEVICE). */ - template - void CooMatrix::setNotUpdated() + template + void CooMatrix::setNotUpdated() { h_data_updated_ = false; d_data_updated_ = false; @@ -201,8 +201,8 @@ namespace GridKit * * @return number of matrix rows. */ - template - IdxT CooMatrix::getNumRows() const + template + index_type CooMatrix::getNumRows() const { return n_; } @@ -212,8 +212,8 @@ namespace GridKit * * @return number of matrix columns. */ - template - IdxT CooMatrix::getNumColumns() const + template + index_type CooMatrix::getNumColumns() const { return m_; } @@ -223,8 +223,8 @@ namespace GridKit * * @return number of non-zeros. */ - template - IdxT CooMatrix::getNnz() const + template + index_type CooMatrix::getNnz() const { return nnz_; } @@ -243,11 +243,11 @@ namespace GridKit * * @return 0 if successful, 1 if not. */ - template - int CooMatrix::setDataPointers(IdxT* row_data, - IdxT* col_data, - RealT* val_data, - memory::MemorySpace memspace) + template + int CooMatrix::setDataPointers(IdxT* row_data, + IdxT* col_data, + RealT* val_data, + memory::MemorySpace memspace) { using namespace memory; @@ -308,8 +308,8 @@ namespace GridKit * @return 0 if successful, -1 if not. * */ - template - int CooMatrix::destroyMatrixData(memory::MemorySpace memspace) + template + int CooMatrix::destroyMatrixData(memory::MemorySpace memspace) { using namespace memory; switch (memspace) @@ -355,8 +355,8 @@ namespace GridKit * * @return Pointer to CSR row pointer array */ - template - IdxT* CooMatrix::getCsrRowData() + template + index_type* CooMatrix::getCsrRowData() { if (!h_data_updated_) { @@ -440,20 +440,20 @@ namespace GridKit return csr_row_data; } - template - const IdxT* CooMatrix::getMapToSorted() const + template + const index_type* CooMatrix::getMapToSorted() const { return map_to_sorted_; } - template - const IdxT* CooMatrix::getMapToDeduplicated() const + template + const index_type* CooMatrix::getMapToDeduplicated() const { return map_to_dedup_; } - template - IdxT* CooMatrix::getRowData(memory::MemorySpace memspace) + template + index_type* CooMatrix::getRowData(memory::MemorySpace memspace) { using namespace memory; @@ -468,8 +468,8 @@ namespace GridKit } } - template - IdxT* CooMatrix::getColData(memory::MemorySpace memspace) + template + index_type* CooMatrix::getColData(memory::MemorySpace memspace) { using namespace memory; @@ -484,8 +484,8 @@ namespace GridKit } } - template - RealT* CooMatrix::getValues(memory::MemorySpace memspace) + template + real_type* CooMatrix::getValues(memory::MemorySpace memspace) { using namespace memory; @@ -511,8 +511,8 @@ namespace GridKit * * @see CooMatrix::setUpdated */ - template - int CooMatrix::syncData(memory::MemorySpace memspace) + template + int CooMatrix::syncData(memory::MemorySpace memspace) { using namespace memory; @@ -591,8 +591,8 @@ namespace GridKit * * @param out - Output stream where the matrix data is printed */ - template - void CooMatrix::print(std::ostream& out, IdxT indexing_base) + template + void CooMatrix::print(std::ostream& out, IdxT indexing_base) { out << std::scientific << std::setprecision(std::numeric_limits::digits10); for (IdxT i = 0; i < nnz_; ++i) diff --git a/GridKit/LinearAlgebra/SparseMatrix/CooMatrix.hpp b/GridKit/LinearAlgebra/SparseMatrix/CooMatrix.hpp index 77cc7a541..00ab8d863 100644 --- a/GridKit/LinearAlgebra/SparseMatrix/CooMatrix.hpp +++ b/GridKit/LinearAlgebra/SparseMatrix/CooMatrix.hpp @@ -11,10 +11,13 @@ namespace GridKit namespace LinearAlgebra { - template + template class CooMatrix { public: + using RealT = real_type; + using IdxT = index_type; + CooMatrix(); CooMatrix(IdxT n, IdxT m, IdxT nnz); diff --git a/GridKit/LinearAlgebra/SparseMatrix/CsrMatrix.cpp b/GridKit/LinearAlgebra/SparseMatrix/CsrMatrix.cpp index 3325569bd..873d98b5f 100644 --- a/GridKit/LinearAlgebra/SparseMatrix/CsrMatrix.cpp +++ b/GridKit/LinearAlgebra/SparseMatrix/CsrMatrix.cpp @@ -8,8 +8,8 @@ namespace GridKit { namespace LinearAlgebra { - template - CsrMatrix::CsrMatrix() + template + CsrMatrix::CsrMatrix() { } @@ -20,10 +20,10 @@ namespace GridKit * @param[in] m - number of columns * @param[in] nnz - number of non-zeros */ - template - CsrMatrix::CsrMatrix(IdxT n, - IdxT m, - IdxT nnz) + template + CsrMatrix::CsrMatrix(IdxT n, + IdxT m, + IdxT nnz) : n_{n}, m_{m}, nnz_{nnz} @@ -58,15 +58,15 @@ namespace GridKit * @param[in] memspace_src * @param[in] memspace_dst */ - template - CsrMatrix::CsrMatrix(IdxT n, - IdxT m, - IdxT nnz, - IdxT** rows, - IdxT** cols, - RealT** vals, - memory::MemorySpace memspace_src, - memory::MemorySpace memspace_dst) + template + CsrMatrix::CsrMatrix(IdxT n, + IdxT m, + IdxT nnz, + IdxT** rows, + IdxT** cols, + RealT** vals, + memory::MemorySpace memspace_src, + memory::MemorySpace memspace_dst) : CsrMatrix(n, m, nnz) { int control = -1; @@ -175,8 +175,8 @@ namespace GridKit } } - template - CsrMatrix::~CsrMatrix() + template + CsrMatrix::~CsrMatrix() { destroyMatrixData(memory::HOST); destroyMatrixData(memory::DEVICE); @@ -185,8 +185,8 @@ namespace GridKit /** * @brief set the matrix update flags to false (for both HOST and DEVICE). */ - template - void CsrMatrix::setNotUpdated() + template + void CsrMatrix::setNotUpdated() { h_data_updated_ = false; d_data_updated_ = false; @@ -197,8 +197,8 @@ namespace GridKit * * @return number of matrix rows. */ - template - IdxT CsrMatrix::getNumRows() const + template + index_type CsrMatrix::getNumRows() const { return n_; } @@ -208,8 +208,8 @@ namespace GridKit * * @return number of matrix columns. */ - template - IdxT CsrMatrix::getNumColumns() const + template + index_type CsrMatrix::getNumColumns() const { return m_; } @@ -219,8 +219,8 @@ namespace GridKit * * @return number of non-zeros. */ - template - IdxT CsrMatrix::getNnz() const + template + index_type CsrMatrix::getNnz() const { return nnz_; } @@ -230,8 +230,8 @@ namespace GridKit * * @param[in] nnz_new - new number of non-zeros */ - template - void CsrMatrix::setNnz(IdxT nnz_new) + template + void CsrMatrix::setNnz(IdxT nnz_new) { nnz_ = nnz_new; } @@ -255,8 +255,8 @@ namespace GridKit * @note If you want to set both DEVICE and HOST memory to the same value * use syncData function. */ - template - int CsrMatrix::setUpdated(memory::MemorySpace memspace) + template + int CsrMatrix::setUpdated(memory::MemorySpace memspace) { using namespace memory; switch (memspace) @@ -287,11 +287,11 @@ namespace GridKit * * @return 0 if successful, 1 if not. */ - template - int CsrMatrix::setDataPointers(IdxT* row_data, - IdxT* col_data, - RealT* val_data, - memory::MemorySpace memspace) + template + int CsrMatrix::setDataPointers(IdxT* row_data, + IdxT* col_data, + RealT* val_data, + memory::MemorySpace memspace) { using namespace memory; @@ -352,8 +352,8 @@ namespace GridKit * @return 0 if successful, -1 if not. * */ - template - int CsrMatrix::destroyMatrixData(memory::MemorySpace memspace) + template + int CsrMatrix::destroyMatrixData(memory::MemorySpace memspace) { using namespace memory; switch (memspace) @@ -403,10 +403,10 @@ namespace GridKit * * @return 0 if successful, -1 if not. */ - template - int CsrMatrix::copyValues(const RealT* new_vals, - memory::MemorySpace memspace_in, - memory::MemorySpace memspace_out) + template + int CsrMatrix::copyValues(const RealT* new_vals, + memory::MemorySpace memspace_in, + memory::MemorySpace memspace_out) { IdxT nnz_current = nnz_; @@ -486,9 +486,9 @@ namespace GridKit * * @return 0 if successful, -1 if not. */ - template - int CsrMatrix::setValuesPointer(RealT* new_vals, - memory::MemorySpace memspace) + template + int CsrMatrix::setValuesPointer(RealT* new_vals, + memory::MemorySpace memspace) { using namespace memory; setNotUpdated(); @@ -523,8 +523,8 @@ namespace GridKit return 0; } - template - IdxT* CsrMatrix::getRowData(memory::MemorySpace memspace) + template + index_type* CsrMatrix::getRowData(memory::MemorySpace memspace) { using namespace memory; @@ -539,8 +539,8 @@ namespace GridKit } } - template - IdxT* CsrMatrix::getColData(memory::MemorySpace memspace) + template + index_type* CsrMatrix::getColData(memory::MemorySpace memspace) { using namespace memory; @@ -555,8 +555,8 @@ namespace GridKit } } - template - RealT* CsrMatrix::getValues(memory::MemorySpace memspace) + template + real_type* CsrMatrix::getValues(memory::MemorySpace memspace) { using namespace memory; @@ -571,12 +571,12 @@ namespace GridKit } } - template - int CsrMatrix::copyDataFrom(const IdxT* row_data, - const IdxT* col_data, - const RealT* val_data, - memory::MemorySpace memspace_in, - memory::MemorySpace memspace_out) + template + int CsrMatrix::copyDataFrom(const IdxT* row_data, + const IdxT* col_data, + const RealT* val_data, + memory::MemorySpace memspace_in, + memory::MemorySpace memspace_out) { // four cases (for now) IdxT nnz_current = nnz_; @@ -668,21 +668,21 @@ namespace GridKit return 0; } - template - int CsrMatrix::copyDataFrom(const IdxT* row_data, - const IdxT* col_data, - const RealT* val_data, - IdxT new_nnz, - memory::MemorySpace memspace_in, - memory::MemorySpace memspace_out) + template + int CsrMatrix::copyDataFrom(const IdxT* row_data, + const IdxT* col_data, + const RealT* val_data, + IdxT new_nnz, + memory::MemorySpace memspace_in, + memory::MemorySpace memspace_out) { destroyMatrixData(memspace_out); nnz_ = new_nnz; return copyDataFrom(row_data, col_data, val_data, memspace_in, memspace_out); } - template - int CsrMatrix::allocateMatrixData(memory::MemorySpace memspace) + template + int CsrMatrix::allocateMatrixData(memory::MemorySpace memspace) { IdxT nnz_current = nnz_; destroyMatrixData(memspace); // just in case @@ -723,8 +723,8 @@ namespace GridKit * * @see CsrMatrix::setUpdated */ - template - int CsrMatrix::syncData(memory::MemorySpace memspace) + template + int CsrMatrix::syncData(memory::MemorySpace memspace) { using namespace memory; @@ -803,8 +803,8 @@ namespace GridKit * * @param out - Output stream where the matrix data is printed */ - template - void CsrMatrix::print(std::ostream& out, IdxT indexing_base) + template + void CsrMatrix::print(std::ostream& out, IdxT indexing_base) { out << std::scientific << std::setprecision(std::numeric_limits::digits10); for (IdxT i = 0; i < n_; ++i) diff --git a/GridKit/LinearAlgebra/SparseMatrix/CsrMatrix.hpp b/GridKit/LinearAlgebra/SparseMatrix/CsrMatrix.hpp index 74029a0da..463ba4c9a 100644 --- a/GridKit/LinearAlgebra/SparseMatrix/CsrMatrix.hpp +++ b/GridKit/LinearAlgebra/SparseMatrix/CsrMatrix.hpp @@ -11,10 +11,13 @@ namespace GridKit namespace LinearAlgebra { - template + template class CsrMatrix { public: + using RealT = real_type; + using IdxT = index_type; + CsrMatrix(); CsrMatrix(IdxT n, IdxT m, IdxT nnz); diff --git a/GridKit/LinearAlgebra/Vector/Vector.cpp b/GridKit/LinearAlgebra/Vector/Vector.cpp index da10f393d..1f1073db9 100644 --- a/GridKit/LinearAlgebra/Vector/Vector.cpp +++ b/GridKit/LinearAlgebra/Vector/Vector.cpp @@ -17,8 +17,8 @@ namespace GridKit * * @param[in] n - Number of elements in the vector */ - template - Vector::Vector(IdxT n) + template + Vector::Vector(IdxT n) : n_capacity_(n), k_(1), n_size_(n), @@ -35,8 +35,8 @@ namespace GridKit * @param[in] n - Number of elements in the vector * @param[in] k - Number of vectors in multivector */ - template - Vector::Vector(IdxT n, IdxT k) + template + Vector::Vector(IdxT n, IdxT k) : n_capacity_(n), k_(k), n_size_(n), @@ -51,8 +51,8 @@ namespace GridKit * @brief destructor. * */ - template - Vector::~Vector() + template + Vector::~Vector() { if (owns_cpu_data_ && h_data_) mem_.deleteOnHost(h_data_); @@ -70,8 +70,8 @@ namespace GridKit * * @return `n_capacity_` the maximum number of elements in the vector. */ - template - IdxT Vector::getCapacity() const + template + index_type Vector::getCapacity() const { return n_capacity_; } @@ -84,8 +84,8 @@ namespace GridKit * * @return `n_size_` number of elements currently in the vector. */ - template - IdxT Vector::getSize() const + template + index_type Vector::getSize() const { return n_size_; } @@ -96,8 +96,8 @@ namespace GridKit * @return _k_, number of vectors in the multivector, * or 1 if the vector is not a multivector. */ - template - IdxT Vector::getNumVectors() const + template + index_type Vector::getNumVectors() const { return k_; } @@ -118,8 +118,8 @@ namespace GridKit * @warning This is an expert level method. Use only if you know what * you are doing. */ - template - int Vector::setData(ScalarT* data, memory::MemorySpace memspace) + template + int Vector::setData(ScalarT* data, memory::MemorySpace memspace) { using namespace memory; @@ -229,8 +229,8 @@ namespace GridKit * @warning This is an expert level method. Use only if you know what * you are doing. */ - template - int Vector::setDataUpdated(memory::MemorySpace memspace) + template + int Vector::setDataUpdated(memory::MemorySpace memspace) { assert(cpu_updated_ && gpu_updated_ && "Update flags not allocated"); @@ -261,8 +261,8 @@ namespace GridKit * @warning This is an expert level method. Use only if you know what * you are doing. */ - template - int Vector::setDataUpdated(IdxT j, memory::MemorySpace memspace) + template + int Vector::setDataUpdated(IdxT j, memory::MemorySpace memspace) { assert(cpu_updated_ && gpu_updated_ && "Update flags not allocated"); @@ -299,8 +299,8 @@ namespace GridKit * * @pre Size of _source_ is greater than or equal to the current vector size. */ - template - int Vector::copyFromExternal(const Vector& source, memory::MemorySpace memspaceSrc, memory::MemorySpace memspaceDst) + template + int Vector::copyFromExternal(const Vector& source, memory::MemorySpace memspaceSrc, memory::MemorySpace memspaceDst) { const ScalarT* source_data = source.getData(memspaceSrc); return copyFromExternal(source_data, memspaceSrc, memspaceDst); @@ -318,10 +318,10 @@ namespace GridKit * * @return 0 if successful, 1 otherwise. */ - template - int Vector::copyFromExternal(const ScalarT* source, - memory::MemorySpace memspaceSrc, - memory::MemorySpace memspaceDst) + template + int Vector::copyFromExternal(const ScalarT* source, + memory::MemorySpace memspaceSrc, + memory::MemorySpace memspaceDst) { if (source == nullptr) { @@ -402,8 +402,8 @@ namespace GridKit * change too. Make sure to use setDataUpdated function to set the update * flags correctly after changing the values. */ - template - ScalarT* Vector::getData(memory::MemorySpace memspace) + template + scalar_type* Vector::getData(memory::MemorySpace memspace) { using memory::DEVICE; using memory::HOST; @@ -437,8 +437,8 @@ namespace GridKit * @return pointer to the vector data (HOST or DEVICE). In case of multivectors, * vectors are stored column-wise. */ - template - const ScalarT* Vector::getData(memory::MemorySpace memspace) const + template + const scalar_type* Vector::getData(memory::MemorySpace memspace) const { using memory::DEVICE; using memory::HOST; @@ -478,8 +478,8 @@ namespace GridKit * If you change the values using the pointer, the vector values will * change too. Call setDataUpdated() to update the staleness flags. */ - template - ScalarT* Vector::getData(IdxT j, memory::MemorySpace memspace) + template + scalar_type* Vector::getData(IdxT j, memory::MemorySpace memspace) { using memory::DEVICE; using memory::HOST; @@ -521,8 +521,8 @@ namespace GridKit * * @pre `j` < `k_`, i.e., `j` is smaller than the number of vectors. */ - template - const ScalarT* Vector::getData(IdxT j, memory::MemorySpace memspace) const + template + const scalar_type* Vector::getData(IdxT j, memory::MemorySpace memspace) const { using memory::DEVICE; using memory::HOST; @@ -569,8 +569,8 @@ namespace GridKit * vectors in a multivector individually. * */ - template - int Vector::syncData(memory::MemorySpace memspaceDst) + template + int Vector::syncData(memory::MemorySpace memspaceDst) { using namespace memory; @@ -655,8 +655,8 @@ namespace GridKit * vectors in a multivector individually. * */ - template - int Vector::syncData(IdxT j, memory::MemorySpace memspaceDst) + template + int Vector::syncData(IdxT j, memory::MemorySpace memspaceDst) { using namespace memory; @@ -720,8 +720,8 @@ namespace GridKit * @param[in] memspace - Memory space of the data to be allocated * */ - template - int Vector::allocate(memory::MemorySpace memspace) + template + int Vector::allocate(memory::MemorySpace memspace) { using namespace memory; switch (memspace) @@ -776,8 +776,8 @@ namespace GridKit * @param[in] memspace - Memory space of the data to be zeroed (HOST or DEVICE) * */ - template - int Vector::setToZero(memory::MemorySpace memspace) + template + int Vector::setToZero(memory::MemorySpace memspace) { using namespace memory; switch (memspace) @@ -814,8 +814,8 @@ namespace GridKit * * @pre `j` < `k_`, i.e., `j` is smaller than the number of vectors. */ - template - int Vector::setToZero(IdxT j, memory::MemorySpace memspace) + template + int Vector::setToZero(IdxT j, memory::MemorySpace memspace) { using namespace memory; @@ -863,8 +863,8 @@ namespace GridKit * @param[in] memspace - Memory space of the data to be set (HOST or DEVICE) * */ - template - int Vector::setToConst(ScalarT C, memory::MemorySpace memspace) + template + int Vector::setToConst(ScalarT C, memory::MemorySpace memspace) { using namespace memory; switch (memspace) @@ -902,8 +902,8 @@ namespace GridKit * * @pre `j` < `k_`, i.e., `j` is smaller than the number of vectors. */ - template - int Vector::setToConst(IdxT j, ScalarT C, memory::MemorySpace memspace) + template + int Vector::setToConst(IdxT j, ScalarT C, memory::MemorySpace memspace) { using namespace memory; @@ -961,8 +961,8 @@ namespace GridKit * @return 0 if successful, 1 otherwise. * */ - template - int Vector::resize(IdxT new_n_size) + template + int Vector::resize(IdxT new_n_size) { assert(owns_cpu_data_ && owns_gpu_data_ && "Cannot resize if vector is not owning the data."); @@ -1030,8 +1030,8 @@ namespace GridKit * @pre _dest_ is allocated with at least _n_ elements in _memspaceDst_. * @post All elements of vector _i_ are copied to _dest_. */ - template - int Vector::copyToExternal(ScalarT* dest, IdxT i, memory::MemorySpace memspaceSrc, memory::MemorySpace memspaceDst) + template + int Vector::copyToExternal(ScalarT* dest, IdxT i, memory::MemorySpace memspaceSrc, memory::MemorySpace memspaceDst) { using namespace memory; if (i >= k_) @@ -1095,8 +1095,8 @@ namespace GridKit * @pre _dest_ is allocated in memspaceOutDst memory space. * @post All elements of all vectors in multivector are copied to the array _dest_. */ - template - int Vector::copyToExternal(ScalarT* dest, memory::MemorySpace memspaceSrc, memory::MemorySpace memspaceDst) + template + int Vector::copyToExternal(ScalarT* dest, memory::MemorySpace memspaceSrc, memory::MemorySpace memspaceDst) { using namespace memory; ScalarT* data = this->getData(memspaceSrc); @@ -1154,14 +1154,14 @@ namespace GridKit // Private methods // - template - void Vector::setHostUpdated(bool is_updated) + template + void Vector::setHostUpdated(bool is_updated) { std::fill(cpu_updated_, cpu_updated_ + k_, is_updated); } - template - void Vector::setDeviceUpdated(bool is_updated) + template + void Vector::setDeviceUpdated(bool is_updated) { std::fill(gpu_updated_, gpu_updated_ + k_, is_updated); } diff --git a/GridKit/LinearAlgebra/Vector/Vector.hpp b/GridKit/LinearAlgebra/Vector/Vector.hpp index 823b9149f..4c5699bda 100644 --- a/GridKit/LinearAlgebra/Vector/Vector.hpp +++ b/GridKit/LinearAlgebra/Vector/Vector.hpp @@ -27,10 +27,13 @@ namespace GridKit * @author Kasia Swirydowicz * @author Slaven Peles */ - template + template class Vector { public: + using ScalarT = scalar_type; + using IdxT = index_type; + Vector() : Vector(0) { diff --git a/GridKit/LinearAlgebra/Vector/VectorHandler.cpp b/GridKit/LinearAlgebra/Vector/VectorHandler.cpp index edd941d99..2b758ae50 100644 --- a/GridKit/LinearAlgebra/Vector/VectorHandler.cpp +++ b/GridKit/LinearAlgebra/Vector/VectorHandler.cpp @@ -21,8 +21,8 @@ namespace GridKit * * @return dot product of _x_ and _y_ */ - template - ScalarT VectorHandler::dot(Vector* x, Vector* y, memory::MemorySpace memspace) + template + scalar_type VectorHandler::dot(Vector* x, Vector* y, memory::MemorySpace memspace) { switch (memspace) { @@ -42,8 +42,8 @@ namespace GridKit * @param[in,out] x The vector * @param[in] memspace Memory space the operation is computed in (HOST or DEVICE) */ - template - void VectorHandler::scal(const ScalarT alpha, Vector* x, memory::MemorySpace memspace) + template + void VectorHandler::scal(const ScalarT alpha, Vector* x, memory::MemorySpace memspace) { switch (memspace) { @@ -64,8 +64,8 @@ namespace GridKit * * @return infinity norm of _x_ */ - template - ScalarT VectorHandler::amax(Vector* x, memory::MemorySpace memspace) + template + scalar_type VectorHandler::amax(Vector* x, memory::MemorySpace memspace) { switch (memspace) { @@ -86,11 +86,11 @@ namespace GridKit * @param[in,out] y The second vector (result is returned in y) * @param[in] memspace Memory space the operation is computed in (HOST or DEVICE) */ - template - void VectorHandler::axpy(const ScalarT alpha, - Vector* x, - Vector* y, - memory::MemorySpace memspace) + template + void VectorHandler::axpy(const ScalarT alpha, + Vector* x, + Vector* y, + memory::MemorySpace memspace) { switch (memspace) { @@ -123,15 +123,15 @@ namespace GridKit * @note Parameter k is not the total number of columns in V but the number * of columns to use in matrix-vector product. */ - template - void VectorHandler::gemv(char transpose, - IdxT k, - const ScalarT alpha, - const ScalarT beta, - Vector* V, - Vector* y, - Vector* x, - memory::MemorySpace memspace) + template + void VectorHandler::gemv(char transpose, + IdxT k, + const ScalarT alpha, + const ScalarT beta, + Vector* V, + Vector* y, + Vector* x, + memory::MemorySpace memspace) { switch (memspace) { @@ -156,13 +156,13 @@ namespace GridKit * * @pre _k_ > 0, _size_ > 0, _size_ = x->getSize() */ - template - void VectorHandler::axpyMulti(IdxT size, - Vector* alpha, - IdxT k, - Vector* x, - Vector* y, - memory::MemorySpace memspace) + template + void VectorHandler::axpyMulti(IdxT size, + Vector* alpha, + IdxT k, + Vector* x, + Vector* y, + memory::MemorySpace memspace) { assert(y->getSize() == x->getSize() && "Sizes of x and y must match!\n"); assert(alpha->getSize() == k && "Size of alpha must match k!\n"); @@ -193,13 +193,13 @@ namespace GridKit * @pre _size_ > 0, _k_ > 0, size = x->getSize(). * @pre _res_ needs to be allocated to k x 2 size. */ - template - void VectorHandler::dot2Multi(IdxT size, - Vector* V, - IdxT k, - Vector* x, - Vector* res, - memory::MemorySpace memspace) + template + void VectorHandler::dot2Multi(IdxT size, + Vector* V, + IdxT k, + Vector* x, + Vector* res, + memory::MemorySpace memspace) { assert(x->getSize() == V->getSize() && "Sizes of V and x do not match!\n"); assert(res->getSize() == k && "Size of `res` must match k!\n"); @@ -224,8 +224,8 @@ namespace GridKit * * @pre The diagonal vector must be of the same size as the vector. */ - template - void VectorHandler::scal(Vector* diag, Vector* vec, memory::MemorySpace memspace) + template + void VectorHandler::scal(Vector* diag, Vector* vec, memory::MemorySpace memspace) { assert(diag->getSize() == vec->getSize() && "Diagonal vector must be of the same size as the vector."); @@ -248,11 +248,11 @@ namespace GridKit * @param[in] diag_offset - the index of diag where the diagonal matrix begins (inclusive) * @param[in] memspace - Memory space the operation is computed in (HOST or DEVICE) */ - template - void VectorHandler::scal(Vector* diag, - Vector* vec, - IdxT diag_offset, - memory::MemorySpace memspace) + template + void VectorHandler::scal(Vector* diag, + Vector* vec, + IdxT diag_offset, + memory::MemorySpace memspace) { switch (memspace) { @@ -276,8 +276,8 @@ namespace GridKit * * @return 0 if successful, 1 otherwise */ - template - int VectorHandler::diagSolve(Vector* diag, Vector* vec, memory::MemorySpace memspace) + template + int VectorHandler::diagSolve(Vector* diag, Vector* vec, memory::MemorySpace memspace) { assert(diag->getSize() == vec->getSize() && "Diagonal vector must be of the same size as the vector."); @@ -304,8 +304,8 @@ namespace GridKit * * @return 0 if successful, 1 otherwise */ - template - int VectorHandler::max(Vector* x, Vector* y, Vector* out, memory::MemorySpace memspace) + template + int VectorHandler::max(Vector* x, Vector* y, Vector* out, memory::MemorySpace memspace) { assert(x->getSize() == y->getSize() && "Vectors must be the same size."); assert(x->getSize() == out->getSize() && "Vectors must be the same size."); @@ -330,8 +330,8 @@ namespace GridKit * * @return 0 if successful, 1 otherwise */ - template - int VectorHandler::abs(Vector* in, Vector* out, memory::MemorySpace memspace) + template + int VectorHandler::abs(Vector* in, Vector* out, memory::MemorySpace memspace) { assert(in->getSize() == out->getSize() && "Vector sizes do not match!\n"); diff --git a/GridKit/LinearAlgebra/Vector/VectorHandler.hpp b/GridKit/LinearAlgebra/Vector/VectorHandler.hpp index b718458c2..e3e4ae921 100644 --- a/GridKit/LinearAlgebra/Vector/VectorHandler.hpp +++ b/GridKit/LinearAlgebra/Vector/VectorHandler.hpp @@ -7,7 +7,7 @@ namespace GridKit { namespace LinearAlgebra { - template + template class Vector; /** @@ -21,10 +21,13 @@ namespace GridKit * * @author Slaven Peles */ - template + template class VectorHandler { public: + using ScalarT = scalar_type; + using IdxT = index_type; + VectorHandler() = default; ~VectorHandler() = default; diff --git a/GridKit/LinearAlgebra/Vector/VectorHandlerCpu.cpp b/GridKit/LinearAlgebra/Vector/VectorHandlerCpu.cpp index 331e61685..e592e227f 100644 --- a/GridKit/LinearAlgebra/Vector/VectorHandlerCpu.cpp +++ b/GridKit/LinearAlgebra/Vector/VectorHandlerCpu.cpp @@ -20,8 +20,8 @@ namespace GridKit * * @return dot product of _x_ and _y_ */ - template - ScalarT VectorHandlerCpu::dot(Vector* x, Vector* y) + template + scalar_type VectorHandlerCpu::dot(Vector* x, Vector* y) { const ScalarT* x_data = x->getData(memory::HOST); const ScalarT* y_data = y->getData(memory::HOST); @@ -44,8 +44,8 @@ namespace GridKit * @param[in] alpha The constant * @param[in,out] x The vector */ - template - void VectorHandlerCpu::scal(const ScalarT alpha, Vector* x) + template + void VectorHandlerCpu::scal(const ScalarT alpha, Vector* x) { ScalarT* x_data = x->getData(memory::HOST); @@ -63,8 +63,8 @@ namespace GridKit * * @return infinity norm of _x_ */ - template - ScalarT VectorHandlerCpu::amax(Vector* x) + template + scalar_type VectorHandlerCpu::amax(Vector* x) { const ScalarT* x_data = x->getData(memory::HOST); @@ -88,8 +88,8 @@ namespace GridKit * @param[in] x The first vector * @param[in,out] y The second vector (result is returned in y) */ - template - void VectorHandlerCpu::axpy(const ScalarT alpha, Vector* x, Vector* y) + template + void VectorHandlerCpu::axpy(const ScalarT alpha, Vector* x, Vector* y) { ScalarT* x_data = x->getData(memory::HOST); ScalarT* y_data = y->getData(memory::HOST); @@ -119,14 +119,14 @@ namespace GridKit * @pre If transpose = N, size of y must equal k. If transpose = T, size of * x must equal k. */ - template - void VectorHandlerCpu::gemv(char transpose, - IdxT k, - const ScalarT alpha, - const ScalarT beta, - Vector* V, - Vector* y, - Vector* x) + template + void VectorHandlerCpu::gemv(char transpose, + IdxT k, + const ScalarT alpha, + const ScalarT beta, + Vector* V, + Vector* y, + Vector* x) { // x = beta*x + alpha*V*y OR x = beta*x + alpha*V^Ty const ScalarT* V_data = V->getData(memory::HOST); @@ -189,12 +189,12 @@ namespace GridKit * * @pre _k_ > 0, _size_ > 0, _size_ = x->getSize() */ - template - void VectorHandlerCpu::axpyMulti(IdxT size, - Vector* alpha, - IdxT k, - Vector* x, - Vector* y) + template + void VectorHandlerCpu::axpyMulti(IdxT size, + Vector* alpha, + IdxT k, + Vector* x, + Vector* y) { ScalarT* alpha_data = alpha->getData(memory::HOST); ScalarT* y_data = y->getData(memory::HOST); @@ -227,12 +227,12 @@ namespace GridKit * * @pre _size_ > 0, _k_ > 0, size = x->getSize(), _res_ needs to be allocated */ - template - void VectorHandlerCpu::dot2Multi(IdxT size, - Vector* V, - IdxT k, - Vector* x, - Vector* res) + template + void VectorHandlerCpu::dot2Multi(IdxT size, + Vector* V, + IdxT k, + Vector* x, + Vector* res) { ScalarT* res_data = res->getData(memory::HOST); const ScalarT* x_data = x->getData(memory::HOST); @@ -269,8 +269,8 @@ namespace GridKit * @param[in] diag Diagonal vector * @param[in,out] vec Vector to be scaled */ - template - void VectorHandlerCpu::scal(Vector* diag, Vector* vec) + template + void VectorHandlerCpu::scal(Vector* diag, Vector* vec) { const ScalarT* diag_data = diag->getData(memory::HOST); ScalarT* vec_data = vec->getData(memory::HOST); @@ -290,8 +290,8 @@ namespace GridKit * @param[in,out] vec Vector to be scaled * @param[in] diag_offset - the index of diag where the diagonal matrix begins */ - template - void VectorHandlerCpu::scal(Vector* diag, Vector* vec, IdxT diag_offset) + template + void VectorHandlerCpu::scal(Vector* diag, Vector* vec, IdxT diag_offset) { const ScalarT* diag_data = &diag->getData(memory::HOST)[diag_offset]; ScalarT* vec_data = vec->getData(memory::HOST); @@ -317,8 +317,8 @@ namespace GridKit * * @return 0 if successful, 1 otherwise */ - template - int VectorHandlerCpu::diagSolve(Vector* diag, Vector* vec) + template + int VectorHandlerCpu::diagSolve(Vector* diag, Vector* vec) { ScalarT* diag_data = diag->getData(memory::HOST); ScalarT* vec_data = vec->getData(memory::HOST); @@ -345,8 +345,8 @@ namespace GridKit * * @return 0 if successful, 1 otherwise */ - template - int VectorHandlerCpu::max(Vector* x, Vector* y, Vector* out) + template + int VectorHandlerCpu::max(Vector* x, Vector* y, Vector* out) { const ScalarT* x_data = x->getData(memory::HOST); const ScalarT* y_data = y->getData(memory::HOST); @@ -369,8 +369,8 @@ namespace GridKit * * @return 0 if successful, 1 otherwise */ - template - int VectorHandlerCpu::abs(Vector* in, Vector* out) + template + int VectorHandlerCpu::abs(Vector* in, Vector* out) { const ScalarT* in_data = in->getData(memory::HOST); ScalarT* out_data = out->getData(memory::HOST); diff --git a/GridKit/LinearAlgebra/Vector/VectorHandlerCpu.hpp b/GridKit/LinearAlgebra/Vector/VectorHandlerCpu.hpp index 6fd527dbd..234e0797f 100644 --- a/GridKit/LinearAlgebra/Vector/VectorHandlerCpu.hpp +++ b/GridKit/LinearAlgebra/Vector/VectorHandlerCpu.hpp @@ -6,7 +6,7 @@ namespace GridKit { namespace LinearAlgebra { - template + template class Vector; /** @@ -17,10 +17,13 @@ namespace GridKit * * @author Slaven Peles */ - template + template class VectorHandlerCpu { public: + using ScalarT = scalar_type; + using IdxT = index_type; + VectorHandlerCpu() = default; ~VectorHandlerCpu() = default; diff --git a/GridKit/MemoryUtilities/MemoryUtils.hpp b/GridKit/MemoryUtilities/MemoryUtils.hpp index 4e6c7bf30..cb2894317 100644 --- a/GridKit/MemoryUtilities/MemoryUtils.hpp +++ b/GridKit/MemoryUtilities/MemoryUtils.hpp @@ -26,14 +26,16 @@ namespace GridKit * This class provides abstractions for memory management functions for * different GPU programming models. * - * @tparam Policy - Memory management policy (vendor specific) + * @tparam policy - Memory management policy (vendor specific) * * @author Slaven Peles */ - template + template class MemoryUtils { public: + using Policy = policy; + MemoryUtils() = default; ~MemoryUtils() = default; diff --git a/GridKit/MemoryUtilities/MemoryUtils.tpp b/GridKit/MemoryUtilities/MemoryUtils.tpp index fd28ddda2..7e7d21236 100644 --- a/GridKit/MemoryUtilities/MemoryUtils.tpp +++ b/GridKit/MemoryUtilities/MemoryUtils.tpp @@ -11,69 +11,69 @@ namespace GridKit { - template - void MemoryUtils::deviceSynchronize() + template + void MemoryUtils::deviceSynchronize() { Policy::deviceSynchronize(); } - template - int MemoryUtils::getLastDeviceError() + template + int MemoryUtils::getLastDeviceError() { return Policy::getLastDeviceError(); } - template - int MemoryUtils::deleteOnDevice(void* v) + template + int MemoryUtils::deleteOnDevice(void* v) { return Policy::deleteOnDevice(v); } - template + template template - int MemoryUtils::allocateArrayOnDevice(T** v, I n) + int MemoryUtils::allocateArrayOnDevice(T** v, I n) { return Policy::template allocateArrayOnDevice(v, n); } - template + template template - int MemoryUtils::allocateBufferOnDevice(T** v, I n) + int MemoryUtils::allocateBufferOnDevice(T** v, I n) { return Policy::template allocateBufferOnDevice(v, n); } - template + template template - int MemoryUtils::setZeroArrayOnDevice(T* v, I n) + int MemoryUtils::setZeroArrayOnDevice(T* v, I n) { return Policy::template setZeroArrayOnDevice(v, n); } - template + template template - int MemoryUtils::setArrayToConstOnDevice(T* v, T c, I n) + int MemoryUtils::setArrayToConstOnDevice(T* v, T c, I n) { return Policy::template setArrayToConstOnDevice(v, c, n); } - template + template template - int MemoryUtils::copyArrayDeviceToHost(T* dst, const T* src, I n) + int MemoryUtils::copyArrayDeviceToHost(T* dst, const T* src, I n) { return Policy::template copyArrayDeviceToHost(dst, src, n); } - template + template template - int MemoryUtils::copyArrayDeviceToDevice(T* dst, const T* src, I n) + int MemoryUtils::copyArrayDeviceToDevice(T* dst, const T* src, I n) { return Policy::template copyArrayDeviceToDevice(dst, src, n); } - template + template template - int MemoryUtils::copyArrayHostToDevice(T* dst, const T* src, I n) + int MemoryUtils::copyArrayHostToDevice(T* dst, const T* src, I n) { return Policy::template copyArrayHostToDevice(dst, src, n); } diff --git a/GridKit/Model/PhasorDynamics/Bus/BusDataJSONParser.hpp b/GridKit/Model/PhasorDynamics/Bus/BusDataJSONParser.hpp index 85d3449c0..b60028bc0 100644 --- a/GridKit/Model/PhasorDynamics/Bus/BusDataJSONParser.hpp +++ b/GridKit/Model/PhasorDynamics/Bus/BusDataJSONParser.hpp @@ -19,9 +19,13 @@ namespace GridKit /// JSON parser function implementation for the `BusData` type /// /// See the `README.md` in `GridKit/Model/PhasorDynamics` for more information - template - void from_json(const json& j, BusData& bd) + template + void from_json(const json& j, BusData& bd) { + using RealT = real_type; + using IdxT = index_type; + using BusDataT = BusData; + j.at("name").get_to(bd.name); std::stringstream error_context; @@ -55,11 +59,11 @@ namespace GridKit auto string_class = j.at("class").get(); if (string_class == "bus") { - bd.bus_type = BusData::BusType::DEFAULT; + bd.bus_type = BusDataT::BusType::DEFAULT; } else if (string_class == "infinite_bus") { - bd.bus_type = BusData::BusType::SLACK; + bd.bus_type = BusDataT::BusType::SLACK; } else { @@ -120,7 +124,7 @@ namespace GridKit { using magic_enum::case_insensitive; using magic_enum::enum_cast; - using MonitorableVariables = typename BusData::MonitorableVariables; + using MonitorableVariables = typename BusDataT::MonitorableVariables; for (auto& raw_monitored_variable : j.at("mon")) { auto var_name = raw_monitored_variable.get(); diff --git a/GridKit/Model/PhasorDynamics/BusFault/BusFaultDependencyTracking.cpp b/GridKit/Model/PhasorDynamics/BusFault/BusFaultDependencyTracking.cpp index 097a97d14..8fbf9624c 100644 --- a/GridKit/Model/PhasorDynamics/BusFault/BusFaultDependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/BusFault/BusFaultDependencyTracking.cpp @@ -9,7 +9,7 @@ namespace GridKit * * @return int - error code, 0 = success */ - template + template int BusFault::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for BusFault..." << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Component.hpp b/GridKit/Model/PhasorDynamics/Component.hpp index a930c8ffb..5fa91acfc 100644 --- a/GridKit/Model/PhasorDynamics/Component.hpp +++ b/GridKit/Model/PhasorDynamics/Component.hpp @@ -17,7 +17,7 @@ namespace GridKit /** * @brief Component model implementation base class. */ - template + template class Component : public Model::Evaluator { public: diff --git a/GridKit/Model/PhasorDynamics/ComponentData.hpp b/GridKit/Model/PhasorDynamics/ComponentData.hpp index bbe345230..3d234f223 100644 --- a/GridKit/Model/PhasorDynamics/ComponentData.hpp +++ b/GridKit/Model/PhasorDynamics/ComponentData.hpp @@ -19,16 +19,16 @@ namespace GridKit */ template - requires std::is_enum_v - && std::is_enum_v - && std::is_enum_v - && std::is_enum_v - && std::is_enum_v + typename parameters_type, + typename buses_type, + typename signal_inputs_type, + typename signal_outputs_type, + typename monitorable_variables_type> + requires std::is_enum_v + && std::is_enum_v + && std::is_enum_v + && std::is_enum_v + && std::is_enum_v struct ComponentData { /// Real value type @@ -36,6 +36,17 @@ namespace GridKit /// Index type using IdxT = index_type; + /// Parameters enum + using Parameters = parameters_type; + /// Buses enum + using Buses = buses_type; + /// Signal inputs enum + using SignalInputs = signal_inputs_type; + /// Signal outputs enum + using SignalOutputs = signal_outputs_type; + /// Monitorable variables enum + using MonitorableVariables = monitorable_variables_type; + /// Class of device this is for std::string device_class; @@ -54,7 +65,8 @@ namespace GridKit /// Set of variables being monitored std::set monitored_variables; - std::string disambiguation_string; ///< Disambiguation string for this device + /// Disambiguation string for this device + std::string disambiguation_string; protected: ComponentData() = default; diff --git a/GridKit/Model/PhasorDynamics/ComponentSignals.hpp b/GridKit/Model/PhasorDynamics/ComponentSignals.hpp index 827181346..021758abe 100644 --- a/GridKit/Model/PhasorDynamics/ComponentSignals.hpp +++ b/GridKit/Model/PhasorDynamics/ComponentSignals.hpp @@ -33,26 +33,33 @@ namespace GridKit /// /// @tparam scalar_type Scalar value type /// @tparam index_type Index type - /// @tparam InternalVariables An enumeration satisfying + /// @tparam internal_variables An enumeration satisfying /// `EnumHasMaximumValueAndIsSizeT` enumerating internal variables /// for the component - /// @tparam ExternalVariables An enumeration satisfying + /// @tparam external_variables An enumeration satisfying /// `EnumHasMaximumValueAndIsSizeT` enumerating external variables /// for the component /// @invariant InternalVariables::MAXIMUM is the greatest attainable /// integer value of the enum /// @invariant ExternalVariables::MAXIMUM is the greatest attainable /// integer value of the enum - template - requires EnumHasMaximumValueAndIsSizeT - && EnumHasMaximumValueAndIsSizeT + template + requires EnumHasMaximumValueAndIsSizeT + && EnumHasMaximumValueAndIsSizeT class ComponentSignals { public: /// Scalar value type - using ScalarT = scalar_type; + using ScalarT = scalar_type; /// Index type - using IdxT = index_type; + using IdxT = index_type; + /// Internal variables + using InternalVariables = internal_variables; + /// External variables + using ExternalVariables = external_variables; /// Attaches a signal node to an external variable on this component /// diff --git a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Enzyme.cpp b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Enzyme.cpp index 77c59abf4..eb653c3cd 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Enzyme.cpp +++ b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Enzyme.cpp @@ -19,7 +19,7 @@ namespace GridKit * * @return int - error code, 0 = success */ - template + template int Ieeet1::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Ieeet1..." << std::endl; diff --git a/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeDataJSONParser.hpp b/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeDataJSONParser.hpp index 4f2a18d7b..29ea16f64 100644 --- a/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeDataJSONParser.hpp +++ b/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeDataJSONParser.hpp @@ -15,8 +15,8 @@ namespace GridKit /// JSON parser function implementation for the `BusData` type /// /// See the `README.md` in `GridKit/Model/PhasorDynamics` for more information - template - void from_json(const json& j, SignalNodeData& sd) + template + void from_json(const json& j, SignalNodeData& sd) { j.at("name").get_to(sd.name); j.at("signal_id").get_to(sd.signal_id); diff --git a/GridKit/Model/PhasorDynamics/SignalSource/ConstantSignalSourceImpl.hpp b/GridKit/Model/PhasorDynamics/SignalSource/ConstantSignalSourceImpl.hpp index a541dbe00..ab24b76cf 100644 --- a/GridKit/Model/PhasorDynamics/SignalSource/ConstantSignalSourceImpl.hpp +++ b/GridKit/Model/PhasorDynamics/SignalSource/ConstantSignalSourceImpl.hpp @@ -100,7 +100,7 @@ namespace GridKit return 0; } - template + template int ConstantSignalSource::setAbsoluteTolerance(RealT) { return 0; diff --git a/GridKit/Model/PhasorDynamics/SystemModelDataJSONParser.hpp b/GridKit/Model/PhasorDynamics/SystemModelDataJSONParser.hpp index 4f28f93a0..949d8254a 100644 --- a/GridKit/Model/PhasorDynamics/SystemModelDataJSONParser.hpp +++ b/GridKit/Model/PhasorDynamics/SystemModelDataJSONParser.hpp @@ -22,9 +22,12 @@ namespace GridKit /// JSON parser function implementation for the `SystemModelData` type /// /// See the `README.md` in `GridKit/Model/PhasorDynamics` for more information - template - void from_json(const json& j, SystemModelData& sm) + template + void from_json(const json& j, SystemModelData& sm) { + using RealT = real_type; + using IdxT = index_type; + auto enum_parse = [](EnumT, KeyT&& key) { return magic_enum::enum_cast(key, magic_enum::case_insensitive); diff --git a/GridKit/Model/PowerElectronics/Bus/Bus.hpp b/GridKit/Model/PowerElectronics/Bus/Bus.hpp index 9277039f3..1b237c6ae 100644 --- a/GridKit/Model/PowerElectronics/Bus/Bus.hpp +++ b/GridKit/Model/PowerElectronics/Bus/Bus.hpp @@ -6,10 +6,13 @@ namespace GridKit { namespace PowerElectronics { - template - class Bus : public NodeBase + template + class Bus : public NodeBase { public: + using ScalarT = scalar_type; + using IdxT = index_type; + Bus() : NodeBase(1, 0) { diff --git a/GridKit/Model/PowerElectronics/Bus/GroundedBus.hpp b/GridKit/Model/PowerElectronics/Bus/GroundedBus.hpp index 88fc0d625..088d8d33c 100644 --- a/GridKit/Model/PowerElectronics/Bus/GroundedBus.hpp +++ b/GridKit/Model/PowerElectronics/Bus/GroundedBus.hpp @@ -6,12 +6,15 @@ namespace GridKit { namespace PowerElectronics { - template - class GroundedBus : public NodeBase + template + class GroundedBus : public NodeBase { - using NodeBase::y; + using NodeBase::y; public: + using ScalarT = scalar_type; + using IdxT = index_type; + GroundedBus(ScalarT voltage) : NodeBase(0, 1), voltage_(voltage) { diff --git a/GridKit/Model/PowerElectronics/Bus/MicrogridBus.hpp b/GridKit/Model/PowerElectronics/Bus/MicrogridBus.hpp index 3341af86f..34fa6fdd4 100644 --- a/GridKit/Model/PowerElectronics/Bus/MicrogridBus.hpp +++ b/GridKit/Model/PowerElectronics/Bus/MicrogridBus.hpp @@ -6,10 +6,13 @@ namespace GridKit { namespace PowerElectronics { - template - class MicrogridBus : public NodeBase + template + class MicrogridBus : public NodeBase { public: + using ScalarT = scalar_type; + using IdxT = index_type; + MicrogridBus() : NodeBase(2, 0) { diff --git a/GridKit/Model/PowerElectronics/Bus/SignalNode.hpp b/GridKit/Model/PowerElectronics/Bus/SignalNode.hpp index c98ed636f..05670dbe5 100644 --- a/GridKit/Model/PowerElectronics/Bus/SignalNode.hpp +++ b/GridKit/Model/PowerElectronics/Bus/SignalNode.hpp @@ -6,10 +6,13 @@ namespace GridKit { namespace PowerElectronics { - template - class SignalNode : public NodeBase + template + class SignalNode : public NodeBase { public: + using ScalarT = scalar_type; + using IdxT = index_type; + SignalNode() : NodeBase(1, 0) { diff --git a/GridKit/Model/PowerElectronics/Capacitor/Capacitor.cpp b/GridKit/Model/PowerElectronics/Capacitor/Capacitor.cpp index 2c2ad2ae0..d725346d4 100644 --- a/GridKit/Model/PowerElectronics/Capacitor/Capacitor.cpp +++ b/GridKit/Model/PowerElectronics/Capacitor/Capacitor.cpp @@ -17,8 +17,8 @@ namespace GridKit * Calls default ModelEvaluatorImpl constructor. */ - template - Capacitor::Capacitor(IdxT id, RealT C) + template + Capacitor::Capacitor(IdxT id, RealT C) : C_(C) { size_ = 3; @@ -29,16 +29,16 @@ namespace GridKit nnz_ = 5; } - template - Capacitor::~Capacitor() + template + Capacitor::~Capacitor() { } /** * Initialization of the grid model */ - template - int Capacitor::initialize() + template + int Capacitor::initialize() { return 0; } @@ -46,8 +46,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int Capacitor::tagDifferentiable() + template + int Capacitor::tagDifferentiable() { return 0; } @@ -56,8 +56,8 @@ namespace GridKit * @brief Evaluate the resisdual of the Capcitor * */ - template - int Capacitor::evaluateInternalResidual() + template + int Capacitor::evaluateInternalResidual() { const auto* y = y_.getData(); @@ -65,8 +65,8 @@ namespace GridKit return 0; } - template - int Capacitor::evaluateExternalResidual() + template + int Capacitor::evaluateExternalResidual() { auto* f = f_.getData(); @@ -81,12 +81,10 @@ namespace GridKit /** * @brief Compute the Jacobian dF/dy - a dF/dy' * - * @tparam ScalarT - * @tparam IdxT * @return int */ - template - int Capacitor::evaluateJacobian() + template + int Capacitor::evaluateJacobian() { this->zeroJacMatrix(); // Create dF/dy @@ -98,26 +96,26 @@ namespace GridKit return 0; } - template - int Capacitor::evaluateIntegrand() + template + int Capacitor::evaluateIntegrand() { return 0; } - template - int Capacitor::initializeAdjoint() + template + int Capacitor::initializeAdjoint() { return 0; } - template - int Capacitor::evaluateAdjointResidual() + template + int Capacitor::evaluateAdjointResidual() { return 0; } - template - int Capacitor::evaluateAdjointIntegrand() + template + int Capacitor::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerElectronics/Capacitor/Capacitor.hpp b/GridKit/Model/PowerElectronics/Capacitor/Capacitor.hpp index a45b55535..46bc321d6 100644 --- a/GridKit/Model/PowerElectronics/Capacitor/Capacitor.hpp +++ b/GridKit/Model/PowerElectronics/Capacitor/Capacitor.hpp @@ -6,7 +6,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -16,35 +16,37 @@ namespace GridKit * @brief Declaration of a Capacitor class. * */ - template - class Capacitor : public CircuitComponent + template + class Capacitor : public CircuitComponent { - using RealT = typename CircuitComponent::RealT; + using CircuitComponent::size_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::tag_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::g_; + using CircuitComponent::yB_; + using CircuitComponent::ypB_; + using CircuitComponent::fB_; + using CircuitComponent::gB_; + using CircuitComponent::param_; + using CircuitComponent::idc_; - using CircuitComponent::size_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::tag_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::g_; - using CircuitComponent::yB_; - using CircuitComponent::ypB_; - using CircuitComponent::fB_; - using CircuitComponent::gB_; - using CircuitComponent::param_; - using CircuitComponent::idc_; - - using CircuitComponent::extern_indices_; - using CircuitComponent::n_extern_; - using CircuitComponent::n_intern_; + using CircuitComponent::extern_indices_; + using CircuitComponent::n_extern_; + using CircuitComponent::n_intern_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename CircuitComponent::RealT; + Capacitor(IdxT id, RealT C); virtual ~Capacitor(); diff --git a/GridKit/Model/PowerElectronics/CircuitComponent.hpp b/GridKit/Model/PowerElectronics/CircuitComponent.hpp index 026db4df8..b8539b561 100644 --- a/GridKit/Model/PowerElectronics/CircuitComponent.hpp +++ b/GridKit/Model/PowerElectronics/CircuitComponent.hpp @@ -16,10 +16,12 @@ namespace GridKit * @brief Declaration of a CircuitComponent class. * */ - template - class CircuitComponent : public Model::Evaluator + template + class CircuitComponent : public Model::Evaluator { public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename Model::Evaluator::RealT; using CsrMatrixT = typename Model::Evaluator::CsrMatrixT; using VectorT = typename Model::Evaluator::VectorT; diff --git a/GridKit/Model/PowerElectronics/CircuitGraph.hpp b/GridKit/Model/PowerElectronics/CircuitGraph.hpp index 5a57104fb..7868d5335 100644 --- a/GridKit/Model/PowerElectronics/CircuitGraph.hpp +++ b/GridKit/Model/PowerElectronics/CircuitGraph.hpp @@ -20,9 +20,6 @@ * @todo should replace N and E with Node and Component classes respectively. * * @note Tested but currently not used in the rest of the code. - * - * @tparam IdxT - * @tparam Label */ template class CircuitGraph @@ -99,7 +96,6 @@ size_t CircuitGraph::amountHyperEdges() * * @todo need to add verbose printing for connections display * - * @tparam IdxT * @param[in] verbose if true will print connections, * otherwise just the number of nodes and edges */ diff --git a/GridKit/Model/PowerElectronics/CircuitNode.hpp b/GridKit/Model/PowerElectronics/CircuitNode.hpp index 7b1e52bf8..04d459875 100644 --- a/GridKit/Model/PowerElectronics/CircuitNode.hpp +++ b/GridKit/Model/PowerElectronics/CircuitNode.hpp @@ -12,13 +12,15 @@ namespace GridKit /** * @brief Circuit node representing a connection point. */ - template - class CircuitNode : public Model::Evaluator + template + class CircuitNode : public Model::Evaluator { + public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename Model::Evaluator::RealT; using VectorT = typename Model::Evaluator::VectorT; - public: CircuitNode() { size_ = 1; diff --git a/GridKit/Model/PowerElectronics/DistributedGenerator/DistributedGenerator.cpp b/GridKit/Model/PowerElectronics/DistributedGenerator/DistributedGenerator.cpp index 7f858f7d2..b55057eba 100644 --- a/GridKit/Model/PowerElectronics/DistributedGenerator/DistributedGenerator.cpp +++ b/GridKit/Model/PowerElectronics/DistributedGenerator/DistributedGenerator.cpp @@ -16,12 +16,12 @@ namespace GridKit * * Calls default ModelEvaluatorImpl constructor. */ - template - DistributedGenerator::DistributedGenerator(IdxT id, - DistributedGeneratorParameters parm, - bool reference_frame, - NodeT* node_ref, - NodeT* node_bus) + template + DistributedGenerator::DistributedGenerator(IdxT id, + DistributedGeneratorParameters parm, + bool reference_frame, + NodeT* node_ref, + NodeT* node_bus) : wb_(parm.wb_), wc_(parm.wc_), mp_(parm.mp_), @@ -54,16 +54,16 @@ namespace GridKit extern_indices_ = {0, 1, 2}; } - template - DistributedGenerator::~DistributedGenerator() + template + DistributedGenerator::~DistributedGenerator() { } /** * Initialization of the grid model */ - template - int DistributedGenerator::initialize() + template + int DistributedGenerator::initialize() { return 0; } @@ -71,8 +71,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int DistributedGenerator::tagDifferentiable() + template + int DistributedGenerator::tagDifferentiable() { return 0; } @@ -82,15 +82,13 @@ namespace GridKit * * @param rel_tol The relative tolerance which can be used to pick the * absolute tolerance. - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 if successful, non-zero otherwise. * * This represents a "noise" level close to zero for which pure relative * error cannot be used. */ - template - int DistributedGenerator::setAbsoluteTolerance(RealT rel_tol) + template + int DistributedGenerator::setAbsoluteTolerance(RealT rel_tol) { abs_tol_.setToConst(static_cast(rel_tol)); return 0; @@ -100,8 +98,8 @@ namespace GridKit * @brief Contributes to the resisdual of the Distributed Generator * */ - template - int DistributedGenerator::evaluateInternalResidual() + template + int DistributedGenerator::evaluateInternalResidual() { ScalarT omega = wb_ - mp_ * y_int_[0]; ScalarT delta = refframe_ ? ScalarT(0.0) : y_int_[12]; @@ -151,8 +149,8 @@ namespace GridKit return 0; } - template - int DistributedGenerator::evaluateExternalResidual() + template + int DistributedGenerator::evaluateExternalResidual() { ScalarT omega = wb_ - mp_ * y_int_[0]; ScalarT delta = refframe_ ? ScalarT(0.0) : y_int_[12]; @@ -200,12 +198,10 @@ namespace GridKit [ 0, sin(x4)/Lc, -cos(x4)/Lc, (x2*cos(x4) + x3*sin(x4))/Lc, mp*x15, 0, 0, 0, 0, 0, 0, 0, 0, 1/Lc, mp*x5 - wb, -rLc/Lc] * 'Generated from MATLAB symbolic' * - * @tparam ScalarT - * @tparam IdxT * @return int */ - template - int DistributedGenerator::evaluateJacobian() + template + int DistributedGenerator::evaluateJacobian() { this->zeroJacMatrix(); @@ -424,8 +420,8 @@ namespace GridKit return 0; } - template - int DistributedGenerator::allocate() + template + int DistributedGenerator::allocate() { CircuitComponent::allocate(); @@ -436,26 +432,26 @@ namespace GridKit return 0; } - template - int DistributedGenerator::evaluateIntegrand() + template + int DistributedGenerator::evaluateIntegrand() { return 0; } - template - int DistributedGenerator::initializeAdjoint() + template + int DistributedGenerator::initializeAdjoint() { return 0; } - template - int DistributedGenerator::evaluateAdjointResidual() + template + int DistributedGenerator::evaluateAdjointResidual() { return 0; } - template - int DistributedGenerator::evaluateAdjointIntegrand() + template + int DistributedGenerator::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerElectronics/DistributedGenerator/DistributedGenerator.hpp b/GridKit/Model/PowerElectronics/DistributedGenerator/DistributedGenerator.hpp index 505311cea..2f90ce9b5 100644 --- a/GridKit/Model/PowerElectronics/DistributedGenerator/DistributedGenerator.hpp +++ b/GridKit/Model/PowerElectronics/DistributedGenerator/DistributedGenerator.hpp @@ -7,12 +7,14 @@ namespace GridKit { - template + template class BaseBus; - template + template struct DistributedGeneratorParameters { + using RealT = real_type; + RealT wb_; RealT wc_; RealT mp_; @@ -37,37 +39,39 @@ namespace GridKit * @brief Declaration of a DistributedGenerator class. * */ - template - class DistributedGenerator : public CircuitComponent + template + class DistributedGenerator : public CircuitComponent { - using RealT = typename CircuitComponent::RealT; - using NodeT = typename PowerElectronics::NodeBase; - - using CircuitComponent::size_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::abs_tol_; - using CircuitComponent::tag_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::g_; - using CircuitComponent::yB_; - using CircuitComponent::ypB_; - using CircuitComponent::fB_; - using CircuitComponent::gB_; - using CircuitComponent::param_; - using CircuitComponent::idc_; + using CircuitComponent::size_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::tag_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::g_; + using CircuitComponent::abs_tol_; + using CircuitComponent::yB_; + using CircuitComponent::ypB_; + using CircuitComponent::fB_; + using CircuitComponent::gB_; + using CircuitComponent::param_; + using CircuitComponent::idc_; - using CircuitComponent::extern_indices_; - using CircuitComponent::n_extern_; - using CircuitComponent::n_intern_; + using CircuitComponent::extern_indices_; + using CircuitComponent::n_extern_; + using CircuitComponent::n_intern_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename CircuitComponent::RealT; + using NodeT = typename PowerElectronics::NodeBase; + DistributedGenerator(IdxT id, DistributedGeneratorParameters parm, bool reference_frame, diff --git a/GridKit/Model/PowerElectronics/InductionMotor/InductionMotor.cpp b/GridKit/Model/PowerElectronics/InductionMotor/InductionMotor.cpp index 41f45e6ae..d89e93642 100644 --- a/GridKit/Model/PowerElectronics/InductionMotor/InductionMotor.cpp +++ b/GridKit/Model/PowerElectronics/InductionMotor/InductionMotor.cpp @@ -16,15 +16,12 @@ namespace GridKit * @todo create a test case utilizing the component. * @todo create a unit test to check correctness of component * - * @tparam ScalarT - data type for scalar variables in the model - * @tparam IdxT - integer index type for the model - * * @param[in] id - unique identifier for the component * @param[in] Lls - stator leakage inductance */ - template - InductionMotor::InductionMotor(IdxT id, RealT Lls, RealT Rs, RealT Llr, RealT Rr, RealT Lms, RealT RJ, RealT P) + template + InductionMotor::InductionMotor(IdxT id, RealT Lls, RealT Rs, RealT Llr, RealT Rr, RealT Lms, RealT RJ, RealT P) : Lls_(Lls), Rs_(Rs), Llr_(Llr), @@ -40,16 +37,16 @@ namespace GridKit idc_ = id; } - template - InductionMotor::~InductionMotor() + template + InductionMotor::~InductionMotor() { } /** * Initialization of the grid model */ - template - int InductionMotor::initialize() + template + int InductionMotor::initialize() { return 0; } @@ -57,8 +54,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int InductionMotor::tagDifferentiable() + template + int InductionMotor::tagDifferentiable() { return 0; } @@ -67,8 +64,8 @@ namespace GridKit * @brief Contributes to the resisdual * */ - template - int InductionMotor::evaluateInternalResidual() + template + int InductionMotor::evaluateInternalResidual() { const auto* y = y_.getData(); @@ -80,8 +77,8 @@ namespace GridKit return 0; } - template - int InductionMotor::evaluateExternalResidual() + template + int InductionMotor::evaluateExternalResidual() { const auto* y = y_.getData(); const auto* yp = yp_.getData(); @@ -101,37 +98,35 @@ namespace GridKit * * @todo need to implement * - * @tparam ScalarT - * @tparam IdxT * @return int */ - template - int InductionMotor::evaluateJacobian() + template + int InductionMotor::evaluateJacobian() { return 0; } - template - int InductionMotor::evaluateIntegrand() + template + int InductionMotor::evaluateIntegrand() { return 0; } - template - int InductionMotor::initializeAdjoint() + template + int InductionMotor::initializeAdjoint() { return 0; } - template - int InductionMotor::evaluateAdjointResidual() + template + int InductionMotor::evaluateAdjointResidual() { return 0; } - template - int InductionMotor::evaluateAdjointIntegrand() + template + int InductionMotor::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerElectronics/InductionMotor/InductionMotor.hpp b/GridKit/Model/PowerElectronics/InductionMotor/InductionMotor.hpp index 89ea72419..5a4745056 100644 --- a/GridKit/Model/PowerElectronics/InductionMotor/InductionMotor.hpp +++ b/GridKit/Model/PowerElectronics/InductionMotor/InductionMotor.hpp @@ -6,7 +6,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -16,35 +16,37 @@ namespace GridKit * @brief Declaration of a InductionMotor class. * */ - template - class InductionMotor : public CircuitComponent + template + class InductionMotor : public CircuitComponent { - using RealT = typename CircuitComponent::RealT; + using CircuitComponent::size_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::tag_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::g_; + using CircuitComponent::yB_; + using CircuitComponent::ypB_; + using CircuitComponent::fB_; + using CircuitComponent::gB_; + using CircuitComponent::param_; + using CircuitComponent::idc_; - using CircuitComponent::size_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::tag_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::g_; - using CircuitComponent::yB_; - using CircuitComponent::ypB_; - using CircuitComponent::fB_; - using CircuitComponent::gB_; - using CircuitComponent::param_; - using CircuitComponent::idc_; - - using CircuitComponent::extern_indices_; - using CircuitComponent::n_extern_; - using CircuitComponent::n_intern_; + using CircuitComponent::extern_indices_; + using CircuitComponent::n_extern_; + using CircuitComponent::n_intern_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename CircuitComponent::RealT; + InductionMotor(IdxT id, RealT Lls, RealT Rs, RealT Llr, RealT Rr, RealT Lms, RealT RJ, RealT P); virtual ~InductionMotor(); diff --git a/GridKit/Model/PowerElectronics/Inductor/Inductor.cpp b/GridKit/Model/PowerElectronics/Inductor/Inductor.cpp index 8e86f5e17..df6e4c599 100644 --- a/GridKit/Model/PowerElectronics/Inductor/Inductor.cpp +++ b/GridKit/Model/PowerElectronics/Inductor/Inductor.cpp @@ -14,8 +14,8 @@ namespace GridKit * Calls default ModelEvaluatorImpl constructor. */ - template - Inductor::Inductor(IdxT id, RealT L, NodeT* node1, NodeT* node2) + template + Inductor::Inductor(IdxT id, RealT L, NodeT* node1, NodeT* node2) : L_(L), node1_(node1), node2_(node2) { assert(node1_->size() == 1); @@ -28,16 +28,16 @@ namespace GridKit nnz_ = 5; } - template - Inductor::~Inductor() + template + Inductor::~Inductor() { } /** * Initialization of the grid model */ - template - int Inductor::initialize() + template + int Inductor::initialize() { return 0; } @@ -45,8 +45,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int Inductor::tagDifferentiable() + template + int Inductor::tagDifferentiable() { return 0; } @@ -56,15 +56,13 @@ namespace GridKit * * @param rel_tol The relative tolerance which can be used to pick the * absolute tolerance. - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 if successful, non-zero otherwise. * * This represents a "noise" level close to zero for which pure relative * error cannot be used. */ - template - int Inductor::setAbsoluteTolerance(RealT rel_tol) + template + int Inductor::setAbsoluteTolerance(RealT rel_tol) { abs_tol_.setToConst(static_cast(rel_tol)); return 0; @@ -74,8 +72,8 @@ namespace GridKit * @brief Compute the resisdual of the component * */ - template - int Inductor::evaluateInternalResidual() + template + int Inductor::evaluateInternalResidual() { const auto* y = y_.getData(); @@ -83,8 +81,8 @@ namespace GridKit return 0; } - template - int Inductor::evaluateExternalResidual() + template + int Inductor::evaluateExternalResidual() { auto* f = f_.getData(); @@ -99,12 +97,10 @@ namespace GridKit /** * @brief Evaluate the jacobian of the component * - * @tparam ScalarT - * @tparam IdxT * @return int */ - template - int Inductor::evaluateJacobian() + template + int Inductor::evaluateJacobian() { this->zeroJacMatrix(); @@ -117,8 +113,8 @@ namespace GridKit return 0; } - template - int Inductor::allocate() + template + int Inductor::allocate() { CircuitComponent::allocate(); @@ -128,26 +124,26 @@ namespace GridKit return 0; } - template - int Inductor::evaluateIntegrand() + template + int Inductor::evaluateIntegrand() { return 0; } - template - int Inductor::initializeAdjoint() + template + int Inductor::initializeAdjoint() { return 0; } - template - int Inductor::evaluateAdjointResidual() + template + int Inductor::evaluateAdjointResidual() { return 0; } - template - int Inductor::evaluateAdjointIntegrand() + template + int Inductor::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerElectronics/Inductor/Inductor.hpp b/GridKit/Model/PowerElectronics/Inductor/Inductor.hpp index 470a91741..6a93ef233 100644 --- a/GridKit/Model/PowerElectronics/Inductor/Inductor.hpp +++ b/GridKit/Model/PowerElectronics/Inductor/Inductor.hpp @@ -7,7 +7,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -17,37 +17,39 @@ namespace GridKit * @brief Declaration of a Inductor class. * */ - template - class Inductor : public CircuitComponent + template + class Inductor : public CircuitComponent { - using RealT = typename CircuitComponent::RealT; - using NodeT = typename PowerElectronics::NodeBase; + using CircuitComponent::size_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::tag_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::g_; + using CircuitComponent::abs_tol_; + using CircuitComponent::yB_; + using CircuitComponent::ypB_; + using CircuitComponent::fB_; + using CircuitComponent::gB_; + using CircuitComponent::param_; + using CircuitComponent::idc_; - using CircuitComponent::size_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::tag_; - using CircuitComponent::abs_tol_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::g_; - using CircuitComponent::yB_; - using CircuitComponent::ypB_; - using CircuitComponent::fB_; - using CircuitComponent::gB_; - using CircuitComponent::param_; - using CircuitComponent::idc_; - - using CircuitComponent::extern_indices_; - using CircuitComponent::n_extern_; - using CircuitComponent::n_intern_; + using CircuitComponent::extern_indices_; + using CircuitComponent::n_extern_; + using CircuitComponent::n_intern_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename CircuitComponent::RealT; + using NodeT = typename PowerElectronics::NodeBase; + Inductor(IdxT id, RealT L, NodeT* node1, NodeT* node2); virtual ~Inductor(); diff --git a/GridKit/Model/PowerElectronics/LinearTransformer/CMakeLists.txt b/GridKit/Model/PowerElectronics/LinearTransformer/CMakeLists.txt index 8a2bcb6dd..be8058d8e 100644 --- a/GridKit/Model/PowerElectronics/LinearTransformer/CMakeLists.txt +++ b/GridKit/Model/PowerElectronics/LinearTransformer/CMakeLists.txt @@ -1,5 +1,5 @@ gridkit_add_library( - power_elec_lineartrasnformer + power_elec_lineartransformer SOURCES LinearTransformer.cpp HEADERS LinearTransformer.hpp LINK_LIBRARIES GridKit::dense_vector) diff --git a/GridKit/Model/PowerElectronics/LinearTransformer/LinearTransformer.cpp b/GridKit/Model/PowerElectronics/LinearTransformer/LinearTransformer.cpp index b4e2facbc..eac8779c5 100644 --- a/GridKit/Model/PowerElectronics/LinearTransformer/LinearTransformer.cpp +++ b/GridKit/Model/PowerElectronics/LinearTransformer/LinearTransformer.cpp @@ -16,9 +16,6 @@ namespace GridKit * @todo Not tested in any model yet. Should be * @todo Has not been tested for correctness * - * @tparam ScalarT - floating point type for the model - * @tparam IdxT - integer index type for the model - * * @param[in] id - unique identifier for the component * @param[in] L0 - inductance 0 * @param[in] L1 - inductance 1 @@ -27,8 +24,8 @@ namespace GridKit * @param[in] M - mutual inductance */ - template - LinearTransformer::LinearTransformer(IdxT id, RealT L0, RealT L1, RealT R0, RealT R1, RealT M) + template + LinearTransformer::LinearTransformer(IdxT id, RealT L0, RealT L1, RealT R0, RealT R1, RealT M) : L0_(L0), L1_(L1), R0_(R0), @@ -42,16 +39,16 @@ namespace GridKit idc_ = id; } - template - LinearTransformer::~LinearTransformer() + template + LinearTransformer::~LinearTransformer() { } /** * Initialization of the grid model */ - template - int LinearTransformer::initialize() + template + int LinearTransformer::initialize() { return 0; } @@ -59,8 +56,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int LinearTransformer::tagDifferentiable() + template + int LinearTransformer::tagDifferentiable() { return 0; } @@ -68,8 +65,8 @@ namespace GridKit /** * @brief Computes the component resisdual */ - template - int LinearTransformer::evaluateInternalResidual() + template + int LinearTransformer::evaluateInternalResidual() { const auto* y = y_.getData(); @@ -78,8 +75,8 @@ namespace GridKit return 0; } - template - int LinearTransformer::evaluateExternalResidual() + template + int LinearTransformer::evaluateExternalResidual() { auto* f = f_.getData(); @@ -89,32 +86,32 @@ namespace GridKit return 0; } - template - int LinearTransformer::evaluateJacobian() + template + int LinearTransformer::evaluateJacobian() { return 0; } - template - int LinearTransformer::evaluateIntegrand() + template + int LinearTransformer::evaluateIntegrand() { return 0; } - template - int LinearTransformer::initializeAdjoint() + template + int LinearTransformer::initializeAdjoint() { return 0; } - template - int LinearTransformer::evaluateAdjointResidual() + template + int LinearTransformer::evaluateAdjointResidual() { return 0; } - template - int LinearTransformer::evaluateAdjointIntegrand() + template + int LinearTransformer::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerElectronics/LinearTransformer/LinearTransformer.hpp b/GridKit/Model/PowerElectronics/LinearTransformer/LinearTransformer.hpp index 6e30b185c..700e3f07c 100644 --- a/GridKit/Model/PowerElectronics/LinearTransformer/LinearTransformer.hpp +++ b/GridKit/Model/PowerElectronics/LinearTransformer/LinearTransformer.hpp @@ -6,7 +6,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -16,35 +16,37 @@ namespace GridKit * @brief Declaration of a LinearTransformer class. * */ - template - class LinearTransformer : public CircuitComponent + template + class LinearTransformer : public CircuitComponent { - using RealT = typename CircuitComponent::RealT; + using CircuitComponent::size_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::tag_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::g_; + using CircuitComponent::yB_; + using CircuitComponent::ypB_; + using CircuitComponent::fB_; + using CircuitComponent::gB_; + using CircuitComponent::param_; + using CircuitComponent::idc_; - using CircuitComponent::size_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::tag_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::g_; - using CircuitComponent::yB_; - using CircuitComponent::ypB_; - using CircuitComponent::fB_; - using CircuitComponent::gB_; - using CircuitComponent::param_; - using CircuitComponent::idc_; - - using CircuitComponent::extern_indices_; - using CircuitComponent::n_extern_; - using CircuitComponent::n_intern_; + using CircuitComponent::extern_indices_; + using CircuitComponent::n_extern_; + using CircuitComponent::n_intern_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename CircuitComponent::RealT; + LinearTransformer(IdxT id, RealT L0, RealT L1, RealT R0, RealT R1, RealT M); virtual ~LinearTransformer(); diff --git a/GridKit/Model/PowerElectronics/MicrogridBusDQ/MicrogridBusDQ.cpp b/GridKit/Model/PowerElectronics/MicrogridBusDQ/MicrogridBusDQ.cpp index bc80a5917..681e9d211 100644 --- a/GridKit/Model/PowerElectronics/MicrogridBusDQ/MicrogridBusDQ.cpp +++ b/GridKit/Model/PowerElectronics/MicrogridBusDQ/MicrogridBusDQ.cpp @@ -19,8 +19,8 @@ namespace GridKit * of an Inverter-Based Microgrid", Nagaraju Pogaku, Milan Prodanovic, and * Timothy C. Green, Section E */ - template - MicrogridBusDQ::MicrogridBusDQ(IdxT id, RealT RN, NodeT* node1) + template + MicrogridBusDQ::MicrogridBusDQ(IdxT id, RealT RN, NodeT* node1) : RN_(RN), node1_(node1) { assert(node1_->size() == 2); @@ -33,16 +33,16 @@ namespace GridKit nnz_ = 2; } - template - MicrogridBusDQ::~MicrogridBusDQ() + template + MicrogridBusDQ::~MicrogridBusDQ() { } /** * Initialization of the grid model */ - template - int MicrogridBusDQ::initialize() + template + int MicrogridBusDQ::initialize() { return 0; } @@ -50,8 +50,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int MicrogridBusDQ::tagDifferentiable() + template + int MicrogridBusDQ::tagDifferentiable() { return 0; } @@ -61,21 +61,19 @@ namespace GridKit * * @param rel_tol The relative tolerance which can be used to pick the * absolute tolerance. - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 if successful, non-zero otherwise. * * This represents a "noise" level close to zero for which pure relative * error cannot be used. */ - template - int MicrogridBusDQ::setAbsoluteTolerance(RealT) + template + int MicrogridBusDQ::setAbsoluteTolerance(RealT) { return 0; } - template - int MicrogridBusDQ::evaluateInternalResidual() + template + int MicrogridBusDQ::evaluateInternalResidual() { return 0; } @@ -88,8 +86,8 @@ namespace GridKit * refernce to equations in class header * */ - template - int MicrogridBusDQ::evaluateExternalResidual() + template + int MicrogridBusDQ::evaluateExternalResidual() { const auto* y = y_.getData(); auto* f = f_.getData(); @@ -106,12 +104,10 @@ namespace GridKit /** * @brief Generate Jacobian * - * @tparam ScalarT - * @tparam IdxT * @return int */ - template - int MicrogridBusDQ::evaluateJacobian() + template + int MicrogridBusDQ::evaluateJacobian() { this->zeroJacMatrix(); @@ -124,8 +120,8 @@ namespace GridKit return 0; } - template - int MicrogridBusDQ::allocate() + template + int MicrogridBusDQ::allocate() { CircuitComponent::allocate(); @@ -135,26 +131,26 @@ namespace GridKit return 0; } - template - int MicrogridBusDQ::evaluateIntegrand() + template + int MicrogridBusDQ::evaluateIntegrand() { return 0; } - template - int MicrogridBusDQ::initializeAdjoint() + template + int MicrogridBusDQ::initializeAdjoint() { return 0; } - template - int MicrogridBusDQ::evaluateAdjointResidual() + template + int MicrogridBusDQ::evaluateAdjointResidual() { return 0; } - template - int MicrogridBusDQ::evaluateAdjointIntegrand() + template + int MicrogridBusDQ::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerElectronics/MicrogridBusDQ/MicrogridBusDQ.hpp b/GridKit/Model/PowerElectronics/MicrogridBusDQ/MicrogridBusDQ.hpp index 05c02d65e..e9753cefb 100644 --- a/GridKit/Model/PowerElectronics/MicrogridBusDQ/MicrogridBusDQ.hpp +++ b/GridKit/Model/PowerElectronics/MicrogridBusDQ/MicrogridBusDQ.hpp @@ -7,7 +7,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -17,37 +17,39 @@ namespace GridKit * @brief Declaration of a MicrogridBusDQ class. * */ - template - class MicrogridBusDQ : public CircuitComponent + template + class MicrogridBusDQ : public CircuitComponent { - using RealT = typename CircuitComponent::RealT; - using NodeT = typename PowerElectronics::NodeBase; + using CircuitComponent::size_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::tag_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::g_; + using CircuitComponent::abs_tol_; + using CircuitComponent::yB_; + using CircuitComponent::ypB_; + using CircuitComponent::fB_; + using CircuitComponent::gB_; + using CircuitComponent::param_; + using CircuitComponent::idc_; - using CircuitComponent::size_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::tag_; - using CircuitComponent::abs_tol_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::g_; - using CircuitComponent::yB_; - using CircuitComponent::ypB_; - using CircuitComponent::fB_; - using CircuitComponent::gB_; - using CircuitComponent::param_; - using CircuitComponent::idc_; - - using CircuitComponent::extern_indices_; - using CircuitComponent::n_extern_; - using CircuitComponent::n_intern_; + using CircuitComponent::extern_indices_; + using CircuitComponent::n_extern_; + using CircuitComponent::n_intern_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename CircuitComponent::RealT; + using NodeT = typename PowerElectronics::NodeBase; + MicrogridBusDQ(IdxT id, RealT RN, NodeT* node1); virtual ~MicrogridBusDQ(); diff --git a/GridKit/Model/PowerElectronics/MicrogridLine/MicrogridLine.cpp b/GridKit/Model/PowerElectronics/MicrogridLine/MicrogridLine.cpp index fe4915413..4c4480d15 100644 --- a/GridKit/Model/PowerElectronics/MicrogridLine/MicrogridLine.cpp +++ b/GridKit/Model/PowerElectronics/MicrogridLine/MicrogridLine.cpp @@ -21,8 +21,8 @@ namespace GridKit * @todo Consider having \omegaref as a global constant, not a node variable. */ - template - MicrogridLine::MicrogridLine(IdxT id, RealT R, RealT L, NodeT* node_ref, NodeT* bus1, NodeT* bus2) + template + MicrogridLine::MicrogridLine(IdxT id, RealT R, RealT L, NodeT* node_ref, NodeT* bus1, NodeT* bus2) : R_(R), L_(L), node_ref_(node_ref), @@ -42,16 +42,16 @@ namespace GridKit nnz_ = 14; } - template - MicrogridLine::~MicrogridLine() + template + MicrogridLine::~MicrogridLine() { } /** * Initialization of the grid model */ - template - int MicrogridLine::initialize() + template + int MicrogridLine::initialize() { return 0; } @@ -59,8 +59,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int MicrogridLine::tagDifferentiable() + template + int MicrogridLine::tagDifferentiable() { return 0; } @@ -70,15 +70,13 @@ namespace GridKit * * @param rel_tol The relative tolerance which can be used to pick the * absolute tolerance. - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 if successful, non-zero otherwise. * * This represents a "noise" level close to zero for which pure relative * error cannot be used. */ - template - int MicrogridLine::setAbsoluteTolerance(RealT rel_tol) + template + int MicrogridLine::setAbsoluteTolerance(RealT rel_tol) { abs_tol_.setToConst(static_cast(rel_tol)); return 0; @@ -88,8 +86,8 @@ namespace GridKit * @brief Evaluate residual of microgrid line * */ - template - int MicrogridLine::evaluateInternalResidual() + template + int MicrogridLine::evaluateInternalResidual() { const auto* y = y_.getData(); @@ -99,8 +97,8 @@ namespace GridKit return 0; } - template - int MicrogridLine::evaluateExternalResidual() + template + int MicrogridLine::evaluateExternalResidual() { auto* f = f_.getData(); @@ -123,12 +121,10 @@ namespace GridKit /** * @brief Generate Jacobian for Microgrid Line * - * @tparam ScalarT - * @tparam IdxT * @return int */ - template - int MicrogridLine::evaluateJacobian() + template + int MicrogridLine::evaluateJacobian() { this->zeroJacMatrix(); @@ -154,8 +150,8 @@ namespace GridKit return 0; } - template - int MicrogridLine::allocate() + template + int MicrogridLine::allocate() { CircuitComponent::allocate(); @@ -168,26 +164,26 @@ namespace GridKit return 0; } - template - int MicrogridLine::evaluateIntegrand() + template + int MicrogridLine::evaluateIntegrand() { return 0; } - template - int MicrogridLine::initializeAdjoint() + template + int MicrogridLine::initializeAdjoint() { return 0; } - template - int MicrogridLine::evaluateAdjointResidual() + template + int MicrogridLine::evaluateAdjointResidual() { return 0; } - template - int MicrogridLine::evaluateAdjointIntegrand() + template + int MicrogridLine::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerElectronics/MicrogridLine/MicrogridLine.hpp b/GridKit/Model/PowerElectronics/MicrogridLine/MicrogridLine.hpp index f63826a43..5ec9f1415 100644 --- a/GridKit/Model/PowerElectronics/MicrogridLine/MicrogridLine.hpp +++ b/GridKit/Model/PowerElectronics/MicrogridLine/MicrogridLine.hpp @@ -7,7 +7,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -17,37 +17,39 @@ namespace GridKit * @brief Declaration of a MicrogridLine class. * */ - template - class MicrogridLine : public CircuitComponent + template + class MicrogridLine : public CircuitComponent { - using RealT = typename CircuitComponent::RealT; - using NodeT = typename PowerElectronics::NodeBase; + using CircuitComponent::size_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::tag_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::g_; + using CircuitComponent::abs_tol_; + using CircuitComponent::yB_; + using CircuitComponent::ypB_; + using CircuitComponent::fB_; + using CircuitComponent::gB_; + using CircuitComponent::param_; + using CircuitComponent::idc_; - using CircuitComponent::size_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::tag_; - using CircuitComponent::abs_tol_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::g_; - using CircuitComponent::yB_; - using CircuitComponent::ypB_; - using CircuitComponent::fB_; - using CircuitComponent::gB_; - using CircuitComponent::param_; - using CircuitComponent::idc_; - - using CircuitComponent::extern_indices_; - using CircuitComponent::n_extern_; - using CircuitComponent::n_intern_; + using CircuitComponent::extern_indices_; + using CircuitComponent::n_extern_; + using CircuitComponent::n_intern_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename CircuitComponent::RealT; + using NodeT = typename PowerElectronics::NodeBase; + MicrogridLine(IdxT id, RealT R, RealT L, NodeT* node_ref, NodeT* bus1, NodeT* bus2); virtual ~MicrogridLine(); diff --git a/GridKit/Model/PowerElectronics/MicrogridLoad/MicrogridLoad.cpp b/GridKit/Model/PowerElectronics/MicrogridLoad/MicrogridLoad.cpp index b058e4984..c1cc27bbb 100644 --- a/GridKit/Model/PowerElectronics/MicrogridLoad/MicrogridLoad.cpp +++ b/GridKit/Model/PowerElectronics/MicrogridLoad/MicrogridLoad.cpp @@ -19,8 +19,8 @@ namespace GridKit * Section D */ - template - MicrogridLoad::MicrogridLoad(IdxT id, RealT R, RealT L, NodeT* node_ref, NodeT* node_bus) + template + MicrogridLoad::MicrogridLoad(IdxT id, RealT R, RealT L, NodeT* node_ref, NodeT* node_bus) : R_(R), L_(L), node_ref_(node_ref), @@ -38,16 +38,16 @@ namespace GridKit nnz_ = 10; } - template - MicrogridLoad::~MicrogridLoad() + template + MicrogridLoad::~MicrogridLoad() { } /** * Initialization of the grid model */ - template - int MicrogridLoad::initialize() + template + int MicrogridLoad::initialize() { return 0; } @@ -55,8 +55,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int MicrogridLoad::tagDifferentiable() + template + int MicrogridLoad::tagDifferentiable() { return 0; } @@ -66,15 +66,13 @@ namespace GridKit * * @param rel_tol The relative tolerance which can be used to pick the * absolute tolerance. - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 if successful, non-zero otherwise. * * This represents a "noise" level close to zero for which pure relative * error cannot be used. */ - template - int MicrogridLoad::setAbsoluteTolerance(RealT rel_tol) + template + int MicrogridLoad::setAbsoluteTolerance(RealT rel_tol) { abs_tol_.setToConst(static_cast(rel_tol)); return 0; @@ -83,8 +81,8 @@ namespace GridKit /** * @brief Eval Micro Load */ - template - int MicrogridLoad::evaluateInternalResidual() + template + int MicrogridLoad::evaluateInternalResidual() { const auto* y = y_.getData(); @@ -94,8 +92,8 @@ namespace GridKit return 0; } - template - int MicrogridLoad::evaluateExternalResidual() + template + int MicrogridLoad::evaluateExternalResidual() { auto* f = f_.getData(); @@ -116,12 +114,10 @@ namespace GridKit /** * @brief Generate Jacobian for Micro Load * - * @tparam ScalarT - * @tparam IdxT * @return int */ - template - int MicrogridLoad::evaluateJacobian() + template + int MicrogridLoad::evaluateJacobian() { this->zeroJacMatrix(); @@ -147,8 +143,8 @@ namespace GridKit return 0; } - template - int MicrogridLoad::allocate() + template + int MicrogridLoad::allocate() { CircuitComponent::allocate(); @@ -159,26 +155,26 @@ namespace GridKit return 0; } - template - int MicrogridLoad::evaluateIntegrand() + template + int MicrogridLoad::evaluateIntegrand() { return 0; } - template - int MicrogridLoad::initializeAdjoint() + template + int MicrogridLoad::initializeAdjoint() { return 0; } - template - int MicrogridLoad::evaluateAdjointResidual() + template + int MicrogridLoad::evaluateAdjointResidual() { return 0; } - template - int MicrogridLoad::evaluateAdjointIntegrand() + template + int MicrogridLoad::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerElectronics/MicrogridLoad/MicrogridLoad.hpp b/GridKit/Model/PowerElectronics/MicrogridLoad/MicrogridLoad.hpp index dae888a4a..af41c5bbc 100644 --- a/GridKit/Model/PowerElectronics/MicrogridLoad/MicrogridLoad.hpp +++ b/GridKit/Model/PowerElectronics/MicrogridLoad/MicrogridLoad.hpp @@ -7,7 +7,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -17,37 +17,39 @@ namespace GridKit * @brief Declaration of a passive MicrogridLoad class. * */ - template - class MicrogridLoad : public CircuitComponent + template + class MicrogridLoad : public CircuitComponent { - using RealT = typename CircuitComponent::RealT; - using NodeT = typename PowerElectronics::NodeBase; + using CircuitComponent::size_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::tag_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::g_; + using CircuitComponent::abs_tol_; + using CircuitComponent::yB_; + using CircuitComponent::ypB_; + using CircuitComponent::fB_; + using CircuitComponent::gB_; + using CircuitComponent::param_; + using CircuitComponent::idc_; - using CircuitComponent::size_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::tag_; - using CircuitComponent::abs_tol_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::g_; - using CircuitComponent::yB_; - using CircuitComponent::ypB_; - using CircuitComponent::fB_; - using CircuitComponent::gB_; - using CircuitComponent::param_; - using CircuitComponent::idc_; - - using CircuitComponent::extern_indices_; - using CircuitComponent::n_extern_; - using CircuitComponent::n_intern_; + using CircuitComponent::extern_indices_; + using CircuitComponent::n_extern_; + using CircuitComponent::n_intern_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename CircuitComponent::RealT; + using NodeT = typename PowerElectronics::NodeBase; + MicrogridLoad(IdxT id, RealT R, RealT L, NodeT* node_ref, NodeT* node_bus); virtual ~MicrogridLoad(); diff --git a/GridKit/Model/PowerElectronics/NodeBase.hpp b/GridKit/Model/PowerElectronics/NodeBase.hpp index 04a4c4a69..9bf7ced75 100644 --- a/GridKit/Model/PowerElectronics/NodeBase.hpp +++ b/GridKit/Model/PowerElectronics/NodeBase.hpp @@ -9,10 +9,12 @@ namespace GridKit { namespace PowerElectronics { - template - class NodeBase : public Model::Evaluator + template + class NodeBase : public Model::Evaluator { public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename Model::Evaluator::RealT; using VectorT = typename Model::Evaluator::VectorT; diff --git a/GridKit/Model/PowerElectronics/Resistor/Resistor.cpp b/GridKit/Model/PowerElectronics/Resistor/Resistor.cpp index d961867ce..8a688473e 100644 --- a/GridKit/Model/PowerElectronics/Resistor/Resistor.cpp +++ b/GridKit/Model/PowerElectronics/Resistor/Resistor.cpp @@ -15,8 +15,8 @@ namespace GridKit * Calls default ModelEvaluatorImpl constructor. */ - template - Resistor::Resistor(IdxT id, RealT R, NodeT* node1, NodeT* node2) + template + Resistor::Resistor(IdxT id, RealT R, NodeT* node1, NodeT* node2) : R_(R), node1_(node1), node2_(node2) { assert(node1_->size() == 1); @@ -29,16 +29,16 @@ namespace GridKit nnz_ = 4; } - template - Resistor::~Resistor() + template + Resistor::~Resistor() { } /** * Initialization of the grid model */ - template - int Resistor::initialize() + template + int Resistor::initialize() { return 0; } @@ -46,8 +46,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int Resistor::tagDifferentiable() + template + int Resistor::tagDifferentiable() { return 0; } @@ -57,15 +57,13 @@ namespace GridKit * * @param rel_tol The relative tolerance which can be used to pick the * absolute tolerance. - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 if successful, non-zero otherwise. * * This represents a "noise" level close to zero for which pure relative * error cannot be used. */ - template - int Resistor::setAbsoluteTolerance(RealT rel_tol) + template + int Resistor::setAbsoluteTolerance(RealT rel_tol) { abs_tol_.setToConst(static_cast(rel_tol)); return 0; @@ -75,14 +73,14 @@ namespace GridKit * @brief Computes the resistors resisdual * */ - template - int Resistor::evaluateInternalResidual() + template + int Resistor::evaluateInternalResidual() { return 0; } - template - int Resistor::evaluateExternalResidual() + template + int Resistor::evaluateExternalResidual() { const auto* y = y_.getData(); auto* f = f_.getData(); @@ -95,8 +93,8 @@ namespace GridKit return 0; } - template - int Resistor::evaluateJacobian() + template + int Resistor::evaluateJacobian() { this->zeroJacMatrix(); @@ -110,8 +108,8 @@ namespace GridKit return 0; } - template - int Resistor::allocate() + template + int Resistor::allocate() { CircuitComponent::allocate(); @@ -121,26 +119,26 @@ namespace GridKit return 0; } - template - int Resistor::evaluateIntegrand() + template + int Resistor::evaluateIntegrand() { return 0; } - template - int Resistor::initializeAdjoint() + template + int Resistor::initializeAdjoint() { return 0; } - template - int Resistor::evaluateAdjointResidual() + template + int Resistor::evaluateAdjointResidual() { return 0; } - template - int Resistor::evaluateAdjointIntegrand() + template + int Resistor::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerElectronics/Resistor/Resistor.hpp b/GridKit/Model/PowerElectronics/Resistor/Resistor.hpp index a6a08b369..3dc98e6e5 100644 --- a/GridKit/Model/PowerElectronics/Resistor/Resistor.hpp +++ b/GridKit/Model/PowerElectronics/Resistor/Resistor.hpp @@ -7,7 +7,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -17,37 +17,39 @@ namespace GridKit * @brief Declaration of a Resistor class. * */ - template - class Resistor : public CircuitComponent + template + class Resistor : public CircuitComponent { - using RealT = typename CircuitComponent::RealT; - using NodeT = typename PowerElectronics::NodeBase; + using CircuitComponent::size_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::tag_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::g_; + using CircuitComponent::abs_tol_; + using CircuitComponent::yB_; + using CircuitComponent::ypB_; + using CircuitComponent::fB_; + using CircuitComponent::gB_; + using CircuitComponent::param_; + using CircuitComponent::idc_; - using CircuitComponent::size_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::tag_; - using CircuitComponent::abs_tol_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::g_; - using CircuitComponent::yB_; - using CircuitComponent::ypB_; - using CircuitComponent::fB_; - using CircuitComponent::gB_; - using CircuitComponent::param_; - using CircuitComponent::idc_; - - using CircuitComponent::extern_indices_; - using CircuitComponent::n_extern_; - using CircuitComponent::n_intern_; + using CircuitComponent::extern_indices_; + using CircuitComponent::n_extern_; + using CircuitComponent::n_intern_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename CircuitComponent::RealT; + using NodeT = typename PowerElectronics::NodeBase; + Resistor(IdxT id, RealT R, NodeT* node1, NodeT* node2); virtual ~Resistor(); diff --git a/GridKit/Model/PowerElectronics/SynchronousMachine/SynchronousMachine.cpp b/GridKit/Model/PowerElectronics/SynchronousMachine/SynchronousMachine.cpp index 6a9ef82dc..57c188b51 100644 --- a/GridKit/Model/PowerElectronics/SynchronousMachine/SynchronousMachine.cpp +++ b/GridKit/Model/PowerElectronics/SynchronousMachine/SynchronousMachine.cpp @@ -16,9 +16,6 @@ namespace GridKit * @todo This model's equations are not finished * @todo needs to be tested for correctness * - * @tparam ScalarT - floating point type for the model - * @tparam IdxT - integer index type for the model - * * @param[in] id - unique identifier for the component * @param[in] Lls - stator leakage inductance * @param[in] Llkq - tuple of damper leakage reactances @@ -35,8 +32,8 @@ namespace GridKit * @param[in] mub - rated frequency */ - template - SynchronousMachine::SynchronousMachine(IdxT id, RealT Lls, std::tuple Llkq, RealT Llfd, RealT Llkd, RealT Lmq, RealT Lmd, RealT Rs, std::tuple Rkq, RealT Rfd, RealT Rkd, RealT RJ, RealT P, RealT mub) + template + SynchronousMachine::SynchronousMachine(IdxT id, RealT Lls, std::tuple Llkq, RealT Llfd, RealT Llkd, RealT Lmq, RealT Lmd, RealT Rs, std::tuple Rkq, RealT Rfd, RealT Rkd, RealT RJ, RealT P, RealT mub) : Lls_(Lls), Llkq_(Llkq), Llfd_(Llfd), @@ -58,16 +55,16 @@ namespace GridKit idc_ = id; } - template - SynchronousMachine::~SynchronousMachine() + template + SynchronousMachine::~SynchronousMachine() { } /** * Initialization of the grid model */ - template - int SynchronousMachine::initialize() + template + int SynchronousMachine::initialize() { return 0; } @@ -75,8 +72,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int SynchronousMachine::tagDifferentiable() + template + int SynchronousMachine::tagDifferentiable() { return 0; } @@ -86,8 +83,8 @@ namespace GridKit * * @todo not finished */ - template - int SynchronousMachine::evaluateInternalResidual() + template + int SynchronousMachine::evaluateInternalResidual() { ScalarT rkq1 = static_cast(std::get<0>(Rkq_)); [[maybe_unused]] ScalarT rkq2 = static_cast(std::get<1>(Rkq_)); @@ -111,8 +108,8 @@ namespace GridKit return 0; } - template - int SynchronousMachine::evaluateExternalResidual() + template + int SynchronousMachine::evaluateExternalResidual() { [[maybe_unused]] ScalarT rkq2 = static_cast(std::get<1>(Rkq_)); [[maybe_unused]] ScalarT llkq2 = static_cast(std::get<1>(Llkq_)); @@ -137,32 +134,32 @@ namespace GridKit return 0; } - template - int SynchronousMachine::evaluateJacobian() + template + int SynchronousMachine::evaluateJacobian() { return 0; } - template - int SynchronousMachine::evaluateIntegrand() + template + int SynchronousMachine::evaluateIntegrand() { return 0; } - template - int SynchronousMachine::initializeAdjoint() + template + int SynchronousMachine::initializeAdjoint() { return 0; } - template - int SynchronousMachine::evaluateAdjointResidual() + template + int SynchronousMachine::evaluateAdjointResidual() { return 0; } - template - int SynchronousMachine::evaluateAdjointIntegrand() + template + int SynchronousMachine::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerElectronics/SynchronousMachine/SynchronousMachine.hpp b/GridKit/Model/PowerElectronics/SynchronousMachine/SynchronousMachine.hpp index 027efcf21..d6ef458ad 100644 --- a/GridKit/Model/PowerElectronics/SynchronousMachine/SynchronousMachine.hpp +++ b/GridKit/Model/PowerElectronics/SynchronousMachine/SynchronousMachine.hpp @@ -8,7 +8,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -18,35 +18,37 @@ namespace GridKit * @brief Declaration of a SynchronousMachine class. * */ - template - class SynchronousMachine : public CircuitComponent + template + class SynchronousMachine : public CircuitComponent { - using RealT = typename CircuitComponent::RealT; + using CircuitComponent::size_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::tag_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::g_; + using CircuitComponent::yB_; + using CircuitComponent::ypB_; + using CircuitComponent::fB_; + using CircuitComponent::gB_; + using CircuitComponent::param_; + using CircuitComponent::idc_; - using CircuitComponent::size_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::tag_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::g_; - using CircuitComponent::yB_; - using CircuitComponent::ypB_; - using CircuitComponent::fB_; - using CircuitComponent::gB_; - using CircuitComponent::param_; - using CircuitComponent::idc_; - - using CircuitComponent::extern_indices_; - using CircuitComponent::n_extern_; - using CircuitComponent::n_intern_; + using CircuitComponent::extern_indices_; + using CircuitComponent::n_extern_; + using CircuitComponent::n_intern_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename CircuitComponent::RealT; + SynchronousMachine(IdxT id, RealT Lls, std::tuple Llkq, RealT Llfd, RealT Llkd, RealT Lmq, RealT Lmd, RealT Rs, std::tuple Rkq, RealT Rfd, RealT Rkd, RealT RJ, RealT P, RealT mub); virtual ~SynchronousMachine(); diff --git a/GridKit/Model/PowerElectronics/SystemModelPowerElectronics.hpp b/GridKit/Model/PowerElectronics/SystemModelPowerElectronics.hpp index 1906b760c..da7e0e478 100644 --- a/GridKit/Model/PowerElectronics/SystemModelPowerElectronics.hpp +++ b/GridKit/Model/PowerElectronics/SystemModelPowerElectronics.hpp @@ -15,32 +15,34 @@ namespace GridKit { - template - class PowerElectronicsModel : public CircuitComponent + template + class PowerElectronicsModel : public CircuitComponent { + using CircuitComponent::size_; + using CircuitComponent::n_intern_; + using CircuitComponent::n_extern_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::tag_; + using CircuitComponent::abs_tol_; + using CircuitComponent::allocated_; + using CircuitComponent::allocateVectors; + + public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename CircuitComponent::RealT; using CsrMatrixT = typename CircuitComponent::CsrMatrixT; using component_type = CircuitComponent; using node_type = PowerElectronics::NodeBase; - using CircuitComponent::size_; - using CircuitComponent::n_intern_; - using CircuitComponent::n_extern_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::tag_; - using CircuitComponent::abs_tol_; - using CircuitComponent::allocated_; - using CircuitComponent::allocateVectors; - - public: /** * @brief Default constructor for the system model * diff --git a/GridKit/Model/PowerElectronics/TransmissionLine/TransmissionLine.cpp b/GridKit/Model/PowerElectronics/TransmissionLine/TransmissionLine.cpp index 333f44afc..be5774a9a 100644 --- a/GridKit/Model/PowerElectronics/TransmissionLine/TransmissionLine.cpp +++ b/GridKit/Model/PowerElectronics/TransmissionLine/TransmissionLine.cpp @@ -19,8 +19,8 @@ namespace GridKit * @todo test for correctness */ - template - TransmissionLine::TransmissionLine(IdxT id, RealT R, RealT X, RealT B) + template + TransmissionLine::TransmissionLine(IdxT id, RealT R, RealT X, RealT B) : R_(R), X_(X), B_(B) @@ -40,16 +40,16 @@ namespace GridKit YImMatDi_ = B_ / (2.0) - YImMatOff_; } - template - TransmissionLine::~TransmissionLine() + template + TransmissionLine::~TransmissionLine() { } /** * Initialization of the grid model */ - template - int TransmissionLine::initialize() + template + int TransmissionLine::initialize() { return 0; } @@ -57,8 +57,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int TransmissionLine::tagDifferentiable() + template + int TransmissionLine::tagDifferentiable() { return 0; } @@ -81,8 +81,8 @@ namespace GridKit * * To express this for Modified Nodal Analysis the Voltages of the admittance matrix are put into voltage drops */ - template - int TransmissionLine::evaluateInternalResidual() + template + int TransmissionLine::evaluateInternalResidual() { const auto* y = y_.getData(); @@ -104,8 +104,8 @@ namespace GridKit return 0; } - template - int TransmissionLine::evaluateExternalResidual() + template + int TransmissionLine::evaluateExternalResidual() { auto* f = f_.getData(); @@ -130,12 +130,10 @@ namespace GridKit /** * @brief Generate Jacobian for Transmission Line * - * @tparam ScalarT - * @tparam IdxT * @return int */ - template - int TransmissionLine::evaluateJacobian() + template + int TransmissionLine::evaluateJacobian() { this->zeroJacMatrix(); @@ -166,26 +164,26 @@ namespace GridKit return 0; } - template - int TransmissionLine::evaluateIntegrand() + template + int TransmissionLine::evaluateIntegrand() { return 0; } - template - int TransmissionLine::initializeAdjoint() + template + int TransmissionLine::initializeAdjoint() { return 0; } - template - int TransmissionLine::evaluateAdjointResidual() + template + int TransmissionLine::evaluateAdjointResidual() { return 0; } - template - int TransmissionLine::evaluateAdjointIntegrand() + template + int TransmissionLine::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerElectronics/TransmissionLine/TransmissionLine.hpp b/GridKit/Model/PowerElectronics/TransmissionLine/TransmissionLine.hpp index d2441a1c7..da1e0e190 100644 --- a/GridKit/Model/PowerElectronics/TransmissionLine/TransmissionLine.hpp +++ b/GridKit/Model/PowerElectronics/TransmissionLine/TransmissionLine.hpp @@ -6,7 +6,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -20,35 +20,37 @@ namespace GridKit * * @note Not used in the Microgrid model. */ - template - class TransmissionLine : public CircuitComponent + template + class TransmissionLine : public CircuitComponent { - using RealT = typename CircuitComponent::RealT; + using CircuitComponent::size_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::tag_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::g_; + using CircuitComponent::yB_; + using CircuitComponent::ypB_; + using CircuitComponent::fB_; + using CircuitComponent::gB_; + using CircuitComponent::param_; + using CircuitComponent::idc_; - using CircuitComponent::size_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::tag_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::g_; - using CircuitComponent::yB_; - using CircuitComponent::ypB_; - using CircuitComponent::fB_; - using CircuitComponent::gB_; - using CircuitComponent::param_; - using CircuitComponent::idc_; - - using CircuitComponent::extern_indices_; - using CircuitComponent::n_extern_; - using CircuitComponent::n_intern_; + using CircuitComponent::extern_indices_; + using CircuitComponent::n_extern_; + using CircuitComponent::n_intern_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename CircuitComponent::RealT; + TransmissionLine(IdxT id, RealT R, RealT X, RealT B); virtual ~TransmissionLine(); diff --git a/GridKit/Model/PowerElectronics/VoltageSource/VoltageSource.cpp b/GridKit/Model/PowerElectronics/VoltageSource/VoltageSource.cpp index 1830c5670..397577125 100644 --- a/GridKit/Model/PowerElectronics/VoltageSource/VoltageSource.cpp +++ b/GridKit/Model/PowerElectronics/VoltageSource/VoltageSource.cpp @@ -15,8 +15,8 @@ namespace GridKit * Calls default ModelEvaluatorImpl constructor. */ - template - VoltageSource::VoltageSource(IdxT id, RealT V, NodeT* node1, NodeT* node2) + template + VoltageSource::VoltageSource(IdxT id, RealT V, NodeT* node1, NodeT* node2) : V_(V), node1_(node1), node2_(node2) { assert(node1_->size() == 1); @@ -29,16 +29,16 @@ namespace GridKit nnz_ = 4; } - template - VoltageSource::~VoltageSource() + template + VoltageSource::~VoltageSource() { } /** * Initialization of the grid model */ - template - int VoltageSource::initialize() + template + int VoltageSource::initialize() { return 0; } @@ -46,8 +46,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int VoltageSource::tagDifferentiable() + template + int VoltageSource::tagDifferentiable() { return 0; } @@ -57,15 +57,13 @@ namespace GridKit * * @param rel_tol The relative tolerance which can be used to pick the * absolute tolerance. - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 if successful, non-zero otherwise. * * This represents a "noise" level close to zero for which pure relative * error cannot be used. */ - template - int VoltageSource::setAbsoluteTolerance(RealT rel_tol) + template + int VoltageSource::setAbsoluteTolerance(RealT rel_tol) { abs_tol_.setToConst(static_cast(rel_tol)); return 0; @@ -74,8 +72,8 @@ namespace GridKit /** * @brief Evaluate resisdual of component */ - template - int VoltageSource::evaluateInternalResidual() + template + int VoltageSource::evaluateInternalResidual() { // internal const auto* y = y_.getData(); @@ -84,8 +82,8 @@ namespace GridKit return 0; } - template - int VoltageSource::evaluateExternalResidual() + template + int VoltageSource::evaluateExternalResidual() { auto* f = f_.getData(); @@ -97,8 +95,8 @@ namespace GridKit return 0; } - template - int VoltageSource::evaluateJacobian() + template + int VoltageSource::evaluateJacobian() { this->zeroJacMatrix(); @@ -111,8 +109,8 @@ namespace GridKit return 0; } - template - int VoltageSource::allocate() + template + int VoltageSource::allocate() { CircuitComponent::allocate(); @@ -122,26 +120,26 @@ namespace GridKit return 0; } - template - int VoltageSource::evaluateIntegrand() + template + int VoltageSource::evaluateIntegrand() { return 0; } - template - int VoltageSource::initializeAdjoint() + template + int VoltageSource::initializeAdjoint() { return 0; } - template - int VoltageSource::evaluateAdjointResidual() + template + int VoltageSource::evaluateAdjointResidual() { return 0; } - template - int VoltageSource::evaluateAdjointIntegrand() + template + int VoltageSource::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerElectronics/VoltageSource/VoltageSource.hpp b/GridKit/Model/PowerElectronics/VoltageSource/VoltageSource.hpp index b1509468d..3340e757b 100644 --- a/GridKit/Model/PowerElectronics/VoltageSource/VoltageSource.hpp +++ b/GridKit/Model/PowerElectronics/VoltageSource/VoltageSource.hpp @@ -7,7 +7,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -17,37 +17,39 @@ namespace GridKit * @brief Declaration of a VoltageSource class. * */ - template - class VoltageSource : public CircuitComponent + template + class VoltageSource : public CircuitComponent { - using RealT = typename CircuitComponent::RealT; - using NodeT = typename PowerElectronics::NodeBase; + using CircuitComponent::size_; + using CircuitComponent::nnz_; + using CircuitComponent::time_; + using CircuitComponent::alpha_; + using CircuitComponent::y_; + using CircuitComponent::y_int_; + using CircuitComponent::yp_; + using CircuitComponent::yp_int_; + using CircuitComponent::tag_; + using CircuitComponent::f_; + using CircuitComponent::f_int_; + using CircuitComponent::g_; + using CircuitComponent::abs_tol_; + using CircuitComponent::yB_; + using CircuitComponent::ypB_; + using CircuitComponent::fB_; + using CircuitComponent::gB_; + using CircuitComponent::param_; + using CircuitComponent::idc_; - using CircuitComponent::size_; - using CircuitComponent::nnz_; - using CircuitComponent::time_; - using CircuitComponent::alpha_; - using CircuitComponent::y_; - using CircuitComponent::y_int_; - using CircuitComponent::yp_; - using CircuitComponent::yp_int_; - using CircuitComponent::tag_; - using CircuitComponent::abs_tol_; - using CircuitComponent::f_; - using CircuitComponent::f_int_; - using CircuitComponent::g_; - using CircuitComponent::yB_; - using CircuitComponent::ypB_; - using CircuitComponent::fB_; - using CircuitComponent::gB_; - using CircuitComponent::param_; - using CircuitComponent::idc_; - - using CircuitComponent::extern_indices_; - using CircuitComponent::n_extern_; - using CircuitComponent::n_intern_; + using CircuitComponent::extern_indices_; + using CircuitComponent::n_extern_; + using CircuitComponent::n_intern_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename CircuitComponent::RealT; + using NodeT = typename PowerElectronics::NodeBase; + VoltageSource(IdxT id, RealT V, NodeT* node1, NodeT* node2); virtual ~VoltageSource(); diff --git a/GridKit/Model/PowerFlow/Branch/Branch.cpp b/GridKit/Model/PowerFlow/Branch/Branch.cpp index adca23ec3..f4e4ba17a 100644 --- a/GridKit/Model/PowerFlow/Branch/Branch.cpp +++ b/GridKit/Model/PowerFlow/Branch/Branch.cpp @@ -20,8 +20,8 @@ namespace GridKit * - Number of optimization parameters = 0 */ - template - Branch::Branch(bus_type* bus1, bus_type* bus2) + template + Branch::Branch(BusT* bus1, BusT* bus2) : R_(0.0), X_(0.01), G_(0.0), @@ -34,8 +34,8 @@ namespace GridKit size_ = 0; } - template - Branch::Branch(RealT R, RealT X, RealT G, RealT B, bus_type* bus1, bus_type* bus2) + template + Branch::Branch(RealT R, RealT X, RealT G, RealT B, BusT* bus1, BusT* bus2) : R_(R), X_(X), G_(G), @@ -47,8 +47,8 @@ namespace GridKit { } - template - Branch::Branch(bus_type* bus1, bus_type* bus2, BranchData& data) + template + Branch::Branch(BusT* bus1, BusT* bus2, BranchData& data) : R_(data.r), X_(data.x), G_(0.0), @@ -61,8 +61,8 @@ namespace GridKit size_ = 0; } - template - Branch::~Branch() + template + Branch::~Branch() { // std::cout << "Destroy Branch..." << std::endl; } @@ -70,8 +70,8 @@ namespace GridKit /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int Branch::allocate() + template + int Branch::allocate() { // std::cout << "Allocate Branch..." << std::endl; return 0; @@ -81,8 +81,8 @@ namespace GridKit * Initialization of the branch model * */ - template - int Branch::initialize() + template + int Branch::initialize() { return 0; } @@ -90,8 +90,8 @@ namespace GridKit /** * \brief Identify differential variables. */ - template - int Branch::tagDifferentiable() + template + int Branch::tagDifferentiable() { return 0; } @@ -101,15 +101,13 @@ namespace GridKit * * @param rel_tol The relative tolerance which can be used to pick the * absolute tolerance. - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 if successful, non-zero otherwise. * * This represents a "noise" level close to zero for which pure relative * error cannot be used. */ - template - int Branch::setAbsoluteTolerance(RealT) + template + int Branch::setAbsoluteTolerance(RealT) { return 0; } @@ -120,8 +118,8 @@ namespace GridKit * * @todo Add and verify conductance to ground (B and G) */ - template - int Branch::evaluateResidual() + template + int Branch::evaluateResidual() { // std::cout << "Evaluating branch residual ...\n"; RealT b = -X_ / (R_ * R_ + X_ * X_); @@ -145,37 +143,37 @@ namespace GridKit return 0; } - template - int Branch::evaluateJacobian() + template + int Branch::evaluateJacobian() { std::cout << "Evaluate Jacobian for Branch..." << std::endl; std::cout << "Jacobian evaluation not implemented!" << std::endl; return 0; } - template - int Branch::evaluateIntegrand() + template + int Branch::evaluateIntegrand() { // std::cout << "Evaluate Integrand for Branch..." << std::endl; return 0; } - template - int Branch::initializeAdjoint() + template + int Branch::initializeAdjoint() { // std::cout << "Initialize adjoint for Branch..." << std::endl; return 0; } - template - int Branch::evaluateAdjointResidual() + template + int Branch::evaluateAdjointResidual() { // std::cout << "Evaluate adjoint residual for Branch..." << std::endl; return 0; } - template - int Branch::evaluateAdjointIntegrand() + template + int Branch::evaluateAdjointIntegrand() { // std::cout << "Evaluate adjoint Integrand for Branch..." << std::endl; return 0; diff --git a/GridKit/Model/PowerFlow/Branch/Branch.hpp b/GridKit/Model/PowerFlow/Branch/Branch.hpp index 0e478f001..40867f1b7 100644 --- a/GridKit/Model/PowerFlow/Branch/Branch.hpp +++ b/GridKit/Model/PowerFlow/Branch/Branch.hpp @@ -6,12 +6,12 @@ // Forward declarations. namespace GridKit { - template + template class BaseBus; namespace PowerFlowData { - template + template struct BranchData; } } // namespace GridKit @@ -22,32 +22,34 @@ namespace GridKit * @brief Implementation of a pi-model branch between two buses. * */ - template - class Branch : public ModelEvaluatorImpl + template + class Branch : public ModelEvaluatorImpl { - using ModelEvaluatorImpl::size_; - using ModelEvaluatorImpl::nnz_; - using ModelEvaluatorImpl::time_; - using ModelEvaluatorImpl::alpha_; - using ModelEvaluatorImpl::y_; - using ModelEvaluatorImpl::yp_; - using ModelEvaluatorImpl::tag_; - using ModelEvaluatorImpl::f_; - using ModelEvaluatorImpl::g_; - using ModelEvaluatorImpl::yB_; - using ModelEvaluatorImpl::ypB_; - using ModelEvaluatorImpl::fB_; - using ModelEvaluatorImpl::gB_; - using ModelEvaluatorImpl::param_; - - using bus_type = BaseBus; + using ModelEvaluatorImpl::size_; + using ModelEvaluatorImpl::nnz_; + using ModelEvaluatorImpl::time_; + using ModelEvaluatorImpl::alpha_; + using ModelEvaluatorImpl::y_; + using ModelEvaluatorImpl::yp_; + using ModelEvaluatorImpl::tag_; + using ModelEvaluatorImpl::f_; + using ModelEvaluatorImpl::g_; + using ModelEvaluatorImpl::yB_; + using ModelEvaluatorImpl::ypB_; + using ModelEvaluatorImpl::fB_; + using ModelEvaluatorImpl::gB_; + using ModelEvaluatorImpl::param_; + + public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename ModelEvaluatorImpl::RealT; + using BusT = BaseBus; using BranchData = GridKit::PowerFlowData::BranchData; - public: - Branch(bus_type* bus1, bus_type* bus2); - Branch(RealT R, RealT X, RealT G, RealT B, bus_type* bus1, bus_type* bus2); - Branch(bus_type* bus1, bus_type* bus2, BranchData& data); + Branch(BusT* bus1, BusT* bus2); + Branch(RealT R, RealT X, RealT G, RealT B, BusT* bus1, BusT* bus2); + Branch(BusT* bus1, BusT* bus2, BranchData& data); virtual ~Branch(); int allocate(); @@ -137,7 +139,7 @@ namespace GridKit RealT B_; const IdxT fbusID_; const IdxT tbusID_; - bus_type* bus1_; - bus_type* bus2_; + BusT* bus1_; + BusT* bus2_; }; } // namespace GridKit diff --git a/GridKit/Model/PowerFlow/Bus/BaseBus.hpp b/GridKit/Model/PowerFlow/Bus/BaseBus.hpp index 5002f320e..975994587 100644 --- a/GridKit/Model/PowerFlow/Bus/BaseBus.hpp +++ b/GridKit/Model/PowerFlow/Bus/BaseBus.hpp @@ -17,29 +17,31 @@ namespace GridKit * bus types. Create Bus class that takes template parameter * BusType. */ - template - class BaseBus : public ModelEvaluatorImpl + template + class BaseBus : public ModelEvaluatorImpl { protected: - using ModelEvaluatorImpl::size_; - using ModelEvaluatorImpl::nnz_; - using ModelEvaluatorImpl::time_; - using ModelEvaluatorImpl::alpha_; - using ModelEvaluatorImpl::y_; - using ModelEvaluatorImpl::yp_; - using ModelEvaluatorImpl::tag_; - using ModelEvaluatorImpl::f_; - using ModelEvaluatorImpl::g_; - using ModelEvaluatorImpl::yB_; - using ModelEvaluatorImpl::ypB_; - using ModelEvaluatorImpl::fB_; - using ModelEvaluatorImpl::gB_; - using ModelEvaluatorImpl::param_; - using ModelEvaluatorImpl::param_up_; - using ModelEvaluatorImpl::param_lo_; + using ModelEvaluatorImpl::size_; + using ModelEvaluatorImpl::nnz_; + using ModelEvaluatorImpl::time_; + using ModelEvaluatorImpl::alpha_; + using ModelEvaluatorImpl::y_; + using ModelEvaluatorImpl::yp_; + using ModelEvaluatorImpl::tag_; + using ModelEvaluatorImpl::f_; + using ModelEvaluatorImpl::g_; + using ModelEvaluatorImpl::yB_; + using ModelEvaluatorImpl::ypB_; + using ModelEvaluatorImpl::fB_; + using ModelEvaluatorImpl::gB_; + using ModelEvaluatorImpl::param_; + using ModelEvaluatorImpl::param_up_; + using ModelEvaluatorImpl::param_lo_; public: - using RealT = typename ModelEvaluatorImpl::RealT; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename ModelEvaluatorImpl::RealT; enum BusType { diff --git a/GridKit/Model/PowerFlow/Bus/BusFactory.hpp b/GridKit/Model/PowerFlow/Bus/BusFactory.hpp index d17bb9762..6571223d2 100644 --- a/GridKit/Model/PowerFlow/Bus/BusFactory.hpp +++ b/GridKit/Model/PowerFlow/Bus/BusFactory.hpp @@ -9,10 +9,12 @@ namespace GridKit { - template + template class BusFactory { public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename ModelEvaluatorImpl::RealT; using BusData = GridKit::PowerFlowData::BusData; diff --git a/GridKit/Model/PowerFlow/Bus/BusPQ.cpp b/GridKit/Model/PowerFlow/Bus/BusPQ.cpp index 1d1e105d8..3270355bc 100644 --- a/GridKit/Model/PowerFlow/Bus/BusPQ.cpp +++ b/GridKit/Model/PowerFlow/Bus/BusPQ.cpp @@ -16,8 +16,8 @@ namespace GridKit * - Number of quadratures = 0 * - Number of optimization parameters = 0 */ - template - BusPQ::BusPQ() + template + BusPQ::BusPQ() : BaseBus(0), V0_(0.0), theta0_(0.0) { // std::cout << "Create BusPQ..." << std::endl; @@ -37,8 +37,8 @@ namespace GridKit * - Number of quadratures = 0 * - Number of optimization parameters = 0 */ - template - BusPQ::BusPQ(ScalarT V, ScalarT theta) + template + BusPQ::BusPQ(ScalarT V, ScalarT theta) : BaseBus(0), V0_(V), theta0_(theta) { // std::cout << "Create BusPQ..." << std::endl; @@ -47,8 +47,8 @@ namespace GridKit size_ = 2; } - template - BusPQ::BusPQ(BusData& data) + template + BusPQ::BusPQ(BusData& data) : BaseBus(data.bus_i), V0_(data.Vm), theta0_(data.Va) { // std::cout << "Create BusPQ..." << std::endl; @@ -57,8 +57,8 @@ namespace GridKit size_ = 2; } - template - BusPQ::~BusPQ() + template + BusPQ::~BusPQ() { // std::cout << "Destroy PQ bus ..." << std::endl; } @@ -66,8 +66,8 @@ namespace GridKit /*! * @brief allocate method resizes local solution and residual vectors. */ - template - int BusPQ::allocate() + template + int BusPQ::allocate() { // std::cout << "Allocate PQ bus ..." << std::endl; this->allocateVectors(size_); @@ -80,8 +80,8 @@ namespace GridKit return 0; } - template - int BusPQ::tagDifferentiable() + template + int BusPQ::tagDifferentiable() { tag_[0] = false; tag_[1] = false; @@ -93,15 +93,13 @@ namespace GridKit * * @param rel_tol The relative tolerance which can be used to pick the * absolute tolerance. - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 if successful, non-zero otherwise. * * This represents a "noise" level close to zero for which pure relative * error cannot be used. */ - template - int BusPQ::setAbsoluteTolerance(RealT rel_tol) + template + int BusPQ::setAbsoluteTolerance(RealT rel_tol) { abs_tol_.setToConst(static_cast(rel_tol)); return 0; @@ -110,8 +108,8 @@ namespace GridKit /*! * @brief initialize method sets bus variables to stored initial values. */ - template - int BusPQ::initialize() + template + int BusPQ::initialize() { // std::cout << "Initialize BusPQ..." << std::endl; auto* y = y_.getData(); @@ -134,8 +132,8 @@ namespace GridKit * _before_ component model residuals. * */ - template - int BusPQ::evaluateResidual() + template + int BusPQ::evaluateResidual() { // std::cout << "Evaluating residual of a PQ bus ...\n"; auto* f = f_.getData(); @@ -148,8 +146,8 @@ namespace GridKit /*! * @brief initialize method sets bus variables to stored initial values. */ - template - int BusPQ::initializeAdjoint() + template + int BusPQ::initializeAdjoint() { // std::cout << "Initialize BusPQ..." << std::endl; auto* yB = yB_.getData(); @@ -165,8 +163,8 @@ namespace GridKit return 0; } - template - int BusPQ::evaluateAdjointResidual() + template + int BusPQ::evaluateAdjointResidual() { auto* fB = fB_.getData(); fB[0] = 0.0; diff --git a/GridKit/Model/PowerFlow/Bus/BusPQ.hpp b/GridKit/Model/PowerFlow/Bus/BusPQ.hpp index 8519b8bc4..1a1567464 100644 --- a/GridKit/Model/PowerFlow/Bus/BusPQ.hpp +++ b/GridKit/Model/PowerFlow/Bus/BusPQ.hpp @@ -14,20 +14,22 @@ namespace GridKit * * */ - template - class BusPQ : public BaseBus + template + class BusPQ : public BaseBus { - using BaseBus::size_; - using BaseBus::y_; - using BaseBus::yp_; - using BaseBus::yB_; - using BaseBus::ypB_; - using BaseBus::f_; - using BaseBus::fB_; - using BaseBus::tag_; - using BaseBus::abs_tol_; + using BaseBus::size_; + using BaseBus::y_; + using BaseBus::yp_; + using BaseBus::yB_; + using BaseBus::ypB_; + using BaseBus::f_; + using BaseBus::fB_; + using BaseBus::tag_; + using BaseBus::abs_tol_; public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename ModelEvaluatorImpl::RealT; using BusData = GridKit::PowerFlowData::BusData; diff --git a/GridKit/Model/PowerFlow/Bus/BusPV.cpp b/GridKit/Model/PowerFlow/Bus/BusPV.cpp index 46a91cb8a..1652fde20 100644 --- a/GridKit/Model/PowerFlow/Bus/BusPV.cpp +++ b/GridKit/Model/PowerFlow/Bus/BusPV.cpp @@ -16,8 +16,8 @@ namespace GridKit * - Number of quadratures = 0 * - Number of optimization parameters = 0 */ - template - BusPV::BusPV() + template + BusPV::BusPV() : BaseBus(0), V_(0.0), theta0_(0.0) { // std::cout << "Create BusPV..." << std::endl; @@ -35,8 +35,8 @@ namespace GridKit * - Number of quadratures = 0 * - Number of optimization parameters = 0 */ - template - BusPV::BusPV(ScalarT V, ScalarT theta0) + template + BusPV::BusPV(ScalarT V, ScalarT theta0) : BaseBus(0), V_(V), theta0_(theta0) { // std::cout << "Create BusPV..." << std::endl; @@ -45,8 +45,8 @@ namespace GridKit size_ = 1; } - template - BusPV::BusPV(BusData& data) + template + BusPV::BusPV(BusData& data) : BaseBus(data.bus_i), V_(data.Vm), theta0_(data.Va) { // std::cout << "Create BusPV ..." << std::endl; @@ -55,8 +55,8 @@ namespace GridKit size_ = 1; } - template - BusPV::~BusPV() + template + BusPV::~BusPV() { // std::cout << "Destroy Gen2..." << std::endl; } @@ -64,8 +64,8 @@ namespace GridKit /*! * @brief allocate method resizes local solution and residual vectors. */ - template - int BusPV::allocate() + template + int BusPV::allocate() { // std::cout << "Allocate PV bus ..." << std::endl; this->allocateVectors(size_); @@ -78,8 +78,8 @@ namespace GridKit return 0; } - template - int BusPV::tagDifferentiable() + template + int BusPV::tagDifferentiable() { tag_[0] = false; return 0; @@ -90,15 +90,13 @@ namespace GridKit * * @param rel_tol The relative tolerance which can be used to pick the * absolute tolerance. - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 if successful, non-zero otherwise. * * This represents a "noise" level close to zero for which pure relative * error cannot be used. */ - template - int BusPV::setAbsoluteTolerance(RealT rel_tol) + template + int BusPV::setAbsoluteTolerance(RealT rel_tol) { abs_tol_.setToConst(static_cast(rel_tol)); return 0; @@ -107,8 +105,8 @@ namespace GridKit /*! * @brief initialize method sets bus variables to stored initial values. */ - template - int BusPV::initialize() + template + int BusPV::initialize() { // std::cout << "Initialize BusPV..." << std::endl; theta() = theta0_; @@ -128,8 +126,8 @@ namespace GridKit * _before_ component model residuals. * */ - template - int BusPV::evaluateResidual() + template + int BusPV::evaluateResidual() { // std::cout << "Evaluating residual of a PV bus ...\n"; P() = 0.0; // <-- Residual P @@ -143,8 +141,8 @@ namespace GridKit /*! * @brief initialize method sets bus variables to stored initial values. */ - template - int BusPV::initializeAdjoint() + template + int BusPV::initializeAdjoint() { // std::cout << "Initialize BusPV..." << std::endl; auto* yB = yB_.getData(); @@ -158,8 +156,8 @@ namespace GridKit return 0; } - template - int BusPV::evaluateAdjointResidual() + template + int BusPV::evaluateAdjointResidual() { auto* fB = fB_.getData(); fB[0] = 0.0; diff --git a/GridKit/Model/PowerFlow/Bus/BusPV.hpp b/GridKit/Model/PowerFlow/Bus/BusPV.hpp index 235414ca0..94cca3ce2 100644 --- a/GridKit/Model/PowerFlow/Bus/BusPV.hpp +++ b/GridKit/Model/PowerFlow/Bus/BusPV.hpp @@ -16,20 +16,22 @@ namespace GridKit * * */ - template - class BusPV : public BaseBus + template + class BusPV : public BaseBus { - using BaseBus::size_; - using BaseBus::y_; - using BaseBus::yp_; - using BaseBus::yB_; - using BaseBus::ypB_; - using BaseBus::f_; - using BaseBus::fB_; - using BaseBus::tag_; - using BaseBus::abs_tol_; + using BaseBus::size_; + using BaseBus::y_; + using BaseBus::yp_; + using BaseBus::yB_; + using BaseBus::ypB_; + using BaseBus::f_; + using BaseBus::fB_; + using BaseBus::tag_; + using BaseBus::abs_tol_; public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename ModelEvaluatorImpl::RealT; using BusData = GridKit::PowerFlowData::BusData; diff --git a/GridKit/Model/PowerFlow/Bus/BusSlack.cpp b/GridKit/Model/PowerFlow/Bus/BusSlack.cpp index dab1ec0a7..04c0af9dc 100644 --- a/GridKit/Model/PowerFlow/Bus/BusSlack.cpp +++ b/GridKit/Model/PowerFlow/Bus/BusSlack.cpp @@ -16,8 +16,8 @@ namespace GridKit * - Number of quadratures = 0 * - Number of optimization parameters = 0 */ - template - BusSlack::BusSlack() + template + BusSlack::BusSlack() : BaseBus(0), V_(0.0), theta_(0.0), P_(0.0), Q_(0.0), PB_(0.0), QB_(0.0) { // std::cout << "Create BusSlack..." << std::endl; @@ -35,8 +35,8 @@ namespace GridKit * - Number of quadratures = 0 * - Number of optimization parameters = 0 */ - template - BusSlack::BusSlack(ScalarT V, ScalarT theta) + template + BusSlack::BusSlack(ScalarT V, ScalarT theta) : BaseBus(0), V_(V), theta_(theta), P_(0.0), Q_(0.0), PB_(0.0), QB_(0.0) { // std::cout << "Create BusSlack..." << std::endl; @@ -46,8 +46,8 @@ namespace GridKit size_ = 0; } - template - BusSlack::BusSlack(BusData& data) + template + BusSlack::BusSlack(BusData& data) : BaseBus(data.bus_i), V_(data.Vm), theta_(data.Va) { // std::cout << "Create BusSlack..." << std::endl; @@ -57,13 +57,13 @@ namespace GridKit size_ = 0; } - template - BusSlack::~BusSlack() + template + BusSlack::~BusSlack() { } - template - int BusSlack::evaluateResidual() + template + int BusSlack::evaluateResidual() { // std::cout << "Evaluating residual of a slack bus ...\n"; P() = 0.0; @@ -71,8 +71,8 @@ namespace GridKit return 0; } - template - int BusSlack::evaluateAdjointResidual() + template + int BusSlack::evaluateAdjointResidual() { PB() = 0.0; QB() = 0.0; diff --git a/GridKit/Model/PowerFlow/Bus/BusSlack.hpp b/GridKit/Model/PowerFlow/Bus/BusSlack.hpp index 65edd619b..e0f6eeae5 100644 --- a/GridKit/Model/PowerFlow/Bus/BusSlack.hpp +++ b/GridKit/Model/PowerFlow/Bus/BusSlack.hpp @@ -15,16 +15,18 @@ namespace GridKit * * */ - template - class BusSlack : public BaseBus + template + class BusSlack : public BaseBus { - using BaseBus::size_; - using BaseBus::y_; - using BaseBus::yp_; - using BaseBus::f_; - using BaseBus::g_; + using BaseBus::size_; + using BaseBus::y_; + using BaseBus::yp_; + using BaseBus::f_; + using BaseBus::g_; public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename ModelEvaluatorImpl::RealT; using BusData = GridKit::PowerFlowData::BusData; diff --git a/GridKit/Model/PowerFlow/Generator/GeneratorBase.hpp b/GridKit/Model/PowerFlow/Generator/GeneratorBase.hpp index 142184ef2..0b9e2da41 100644 --- a/GridKit/Model/PowerFlow/Generator/GeneratorBase.hpp +++ b/GridKit/Model/PowerFlow/Generator/GeneratorBase.hpp @@ -7,7 +7,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -16,32 +16,34 @@ namespace GridKit /** * @brief Generator base class template * - * @tparam ScalarT - Scalar type - * @tparam IdxT - Matrix and vector index type + * @tparam scalar_type - Scalar type + * @tparam index_type - Matrix and vector index type */ - template - class GeneratorBase : public ModelEvaluatorImpl + template + class GeneratorBase : public ModelEvaluatorImpl { protected: - using ModelEvaluatorImpl::size_; - using ModelEvaluatorImpl::nnz_; - using ModelEvaluatorImpl::time_; - using ModelEvaluatorImpl::alpha_; - using ModelEvaluatorImpl::y_; - using ModelEvaluatorImpl::yp_; - using ModelEvaluatorImpl::tag_; - using ModelEvaluatorImpl::f_; - using ModelEvaluatorImpl::g_; - using ModelEvaluatorImpl::yB_; - using ModelEvaluatorImpl::ypB_; - using ModelEvaluatorImpl::fB_; - using ModelEvaluatorImpl::gB_; - using ModelEvaluatorImpl::param_; - - using bus_type = BaseBus; - using RealT = typename ModelEvaluatorImpl::RealT; + using ModelEvaluatorImpl::size_; + using ModelEvaluatorImpl::nnz_; + using ModelEvaluatorImpl::time_; + using ModelEvaluatorImpl::alpha_; + using ModelEvaluatorImpl::y_; + using ModelEvaluatorImpl::yp_; + using ModelEvaluatorImpl::tag_; + using ModelEvaluatorImpl::f_; + using ModelEvaluatorImpl::g_; + using ModelEvaluatorImpl::yB_; + using ModelEvaluatorImpl::ypB_; + using ModelEvaluatorImpl::fB_; + using ModelEvaluatorImpl::gB_; + using ModelEvaluatorImpl::param_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename ModelEvaluatorImpl::RealT; + using BusT = BaseBus; + GeneratorBase() { } diff --git a/GridKit/Model/PowerFlow/Generator/GeneratorFactory.hpp b/GridKit/Model/PowerFlow/Generator/GeneratorFactory.hpp index 23ebafddb..c74b3460b 100644 --- a/GridKit/Model/PowerFlow/Generator/GeneratorFactory.hpp +++ b/GridKit/Model/PowerFlow/Generator/GeneratorFactory.hpp @@ -10,10 +10,12 @@ namespace GridKit { - template + template class GeneratorFactory { public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename ModelEvaluatorImpl::RealT; using GenData = GridKit::PowerFlowData::GenData; diff --git a/GridKit/Model/PowerFlow/Generator/GeneratorPQ.cpp b/GridKit/Model/PowerFlow/Generator/GeneratorPQ.cpp index 4414b44a7..78ef3b00a 100644 --- a/GridKit/Model/PowerFlow/Generator/GeneratorPQ.cpp +++ b/GridKit/Model/PowerFlow/Generator/GeneratorPQ.cpp @@ -16,8 +16,8 @@ namespace GridKit * Calls default ModelEvaluatorImpl constructor. */ - template - GeneratorPQ::GeneratorPQ(bus_type* bus, GenData& data) + template + GeneratorPQ::GeneratorPQ(BusT* bus, GenData& data) : P_(data.Pg), Q_(data.Qg), bus_(bus) @@ -26,16 +26,16 @@ namespace GridKit size_ = 0; } - template - GeneratorPQ::~GeneratorPQ() + template + GeneratorPQ::~GeneratorPQ() { } /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int GeneratorPQ::allocate() + template + int GeneratorPQ::allocate() { return 0; } @@ -43,8 +43,8 @@ namespace GridKit /** * Initialization of the grid model */ - template - int GeneratorPQ::initialize() + template + int GeneratorPQ::initialize() { return 0; } @@ -52,8 +52,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int GeneratorPQ::tagDifferentiable() + template + int GeneratorPQ::tagDifferentiable() { return 0; } @@ -63,8 +63,8 @@ namespace GridKit * * Must be connected to a PQ bus. */ - template - int GeneratorPQ::evaluateResidual() + template + int GeneratorPQ::evaluateResidual() { // std::cout << "Evaluating load residual ...\n"; bus_->P() += P_; @@ -76,32 +76,32 @@ namespace GridKit return 0; } - template - int GeneratorPQ::evaluateJacobian() + template + int GeneratorPQ::evaluateJacobian() { return 0; } - template - int GeneratorPQ::evaluateIntegrand() + template + int GeneratorPQ::evaluateIntegrand() { return 0; } - template - int GeneratorPQ::initializeAdjoint() + template + int GeneratorPQ::initializeAdjoint() { return 0; } - template - int GeneratorPQ::evaluateAdjointResidual() + template + int GeneratorPQ::evaluateAdjointResidual() { return 0; } - template - int GeneratorPQ::evaluateAdjointIntegrand() + template + int GeneratorPQ::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerFlow/Generator/GeneratorPQ.hpp b/GridKit/Model/PowerFlow/Generator/GeneratorPQ.hpp index 8d628de53..150bdaddf 100644 --- a/GridKit/Model/PowerFlow/Generator/GeneratorPQ.hpp +++ b/GridKit/Model/PowerFlow/Generator/GeneratorPQ.hpp @@ -9,7 +9,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -19,30 +19,32 @@ namespace GridKit * @brief Implementation of a PV generator. * */ - template - class GeneratorPQ : public GeneratorBase + template + class GeneratorPQ : public GeneratorBase { - using GeneratorBase::size_; - using GeneratorBase::nnz_; - using GeneratorBase::time_; - using GeneratorBase::alpha_; - using GeneratorBase::y_; - using GeneratorBase::yp_; - using GeneratorBase::tag_; - using GeneratorBase::f_; - using GeneratorBase::g_; - using GeneratorBase::yB_; - using GeneratorBase::ypB_; - using GeneratorBase::fB_; - using GeneratorBase::gB_; - using GeneratorBase::param_; - - using bus_type = BaseBus; - using RealT = typename ModelEvaluatorImpl::RealT; - using GenData = GridKit::PowerFlowData::GenData; + using GeneratorBase::size_; + using GeneratorBase::nnz_; + using GeneratorBase::time_; + using GeneratorBase::alpha_; + using GeneratorBase::y_; + using GeneratorBase::yp_; + using GeneratorBase::tag_; + using GeneratorBase::f_; + using GeneratorBase::g_; + using GeneratorBase::yB_; + using GeneratorBase::ypB_; + using GeneratorBase::fB_; + using GeneratorBase::gB_; + using GeneratorBase::param_; public: - GeneratorPQ(bus_type* bus, GenData& data); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename ModelEvaluatorImpl::RealT; + using BusT = BaseBus; + using GenData = GridKit::PowerFlowData::GenData; + + GeneratorPQ(BusT* bus, GenData& data); virtual ~GeneratorPQ(); int allocate(); @@ -78,8 +80,8 @@ namespace GridKit } private: - ScalarT P_; - ScalarT Q_; - bus_type* bus_; + ScalarT P_; + ScalarT Q_; + BusT* bus_; }; } // namespace GridKit diff --git a/GridKit/Model/PowerFlow/Generator/GeneratorPV.cpp b/GridKit/Model/PowerFlow/Generator/GeneratorPV.cpp index 004def094..f2bcaf5d3 100644 --- a/GridKit/Model/PowerFlow/Generator/GeneratorPV.cpp +++ b/GridKit/Model/PowerFlow/Generator/GeneratorPV.cpp @@ -16,8 +16,8 @@ namespace GridKit * Calls default ModelEvaluatorImpl constructor. */ - template - GeneratorPV::GeneratorPV(bus_type* bus, GenData& data) + template + GeneratorPV::GeneratorPV(BusT* bus, GenData& data) : P_(data.Pg), // Q_(data.Qg), bus_(bus) @@ -26,16 +26,16 @@ namespace GridKit size_ = 0; } - template - GeneratorPV::~GeneratorPV() + template + GeneratorPV::~GeneratorPV() { } /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int GeneratorPV::allocate() + template + int GeneratorPV::allocate() { return 0; } @@ -43,8 +43,8 @@ namespace GridKit /** * Initialization of the grid model */ - template - int GeneratorPV::initialize() + template + int GeneratorPV::initialize() { return 0; } @@ -52,8 +52,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int GeneratorPV::tagDifferentiable() + template + int GeneratorPV::tagDifferentiable() { return 0; } @@ -63,8 +63,8 @@ namespace GridKit * * Must be connected to a PQ bus. */ - template - int GeneratorPV::evaluateResidual() + template + int GeneratorPV::evaluateResidual() { // std::cout << "Evaluating load residual ...\n"; bus_->P() += P_; @@ -76,32 +76,32 @@ namespace GridKit return 0; } - template - int GeneratorPV::evaluateJacobian() + template + int GeneratorPV::evaluateJacobian() { return 0; } - template - int GeneratorPV::evaluateIntegrand() + template + int GeneratorPV::evaluateIntegrand() { return 0; } - template - int GeneratorPV::initializeAdjoint() + template + int GeneratorPV::initializeAdjoint() { return 0; } - template - int GeneratorPV::evaluateAdjointResidual() + template + int GeneratorPV::evaluateAdjointResidual() { return 0; } - template - int GeneratorPV::evaluateAdjointIntegrand() + template + int GeneratorPV::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerFlow/Generator/GeneratorPV.hpp b/GridKit/Model/PowerFlow/Generator/GeneratorPV.hpp index 147746a93..3e4458eb6 100644 --- a/GridKit/Model/PowerFlow/Generator/GeneratorPV.hpp +++ b/GridKit/Model/PowerFlow/Generator/GeneratorPV.hpp @@ -9,7 +9,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -19,30 +19,32 @@ namespace GridKit * @brief Implementation of a PV generator. * */ - template - class GeneratorPV : public GeneratorBase + template + class GeneratorPV : public GeneratorBase { - using GeneratorBase::size_; - using GeneratorBase::nnz_; - using GeneratorBase::time_; - using GeneratorBase::alpha_; - using GeneratorBase::y_; - using GeneratorBase::yp_; - using GeneratorBase::tag_; - using GeneratorBase::f_; - using GeneratorBase::g_; - using GeneratorBase::yB_; - using GeneratorBase::ypB_; - using GeneratorBase::fB_; - using GeneratorBase::gB_; - using GeneratorBase::param_; - - using bus_type = BaseBus; - using RealT = typename ModelEvaluatorImpl::RealT; - using GenData = GridKit::PowerFlowData::GenData; + using GeneratorBase::size_; + using GeneratorBase::nnz_; + using GeneratorBase::time_; + using GeneratorBase::alpha_; + using GeneratorBase::y_; + using GeneratorBase::yp_; + using GeneratorBase::tag_; + using GeneratorBase::f_; + using GeneratorBase::g_; + using GeneratorBase::yB_; + using GeneratorBase::ypB_; + using GeneratorBase::fB_; + using GeneratorBase::gB_; + using GeneratorBase::param_; public: - GeneratorPV(bus_type* bus, GenData& data); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename ModelEvaluatorImpl::RealT; + using BusT = BaseBus; + using GenData = GridKit::PowerFlowData::GenData; + + GeneratorPV(BusT* bus, GenData& data); virtual ~GeneratorPV(); int allocate(); @@ -82,7 +84,7 @@ namespace GridKit } private: - ScalarT P_; - bus_type* bus_; + ScalarT P_; + BusT* bus_; }; } // namespace GridKit diff --git a/GridKit/Model/PowerFlow/Generator/GeneratorSlack.cpp b/GridKit/Model/PowerFlow/Generator/GeneratorSlack.cpp index b6c86a4a8..739694448 100644 --- a/GridKit/Model/PowerFlow/Generator/GeneratorSlack.cpp +++ b/GridKit/Model/PowerFlow/Generator/GeneratorSlack.cpp @@ -16,24 +16,24 @@ namespace GridKit * Calls default ModelEvaluatorImpl constructor. */ - template - GeneratorSlack::GeneratorSlack(bus_type* bus, GenData& /* data */) + template + GeneratorSlack::GeneratorSlack(BusT* bus, GenData& /* data */) : bus_(bus) { // std::cout << "Create a load model with " << size_ << " variables ...\n"; size_ = 0; } - template - GeneratorSlack::~GeneratorSlack() + template + GeneratorSlack::~GeneratorSlack() { } /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int GeneratorSlack::allocate() + template + int GeneratorSlack::allocate() { return 0; } @@ -41,8 +41,8 @@ namespace GridKit /** * Initialization of the grid model */ - template - int GeneratorSlack::initialize() + template + int GeneratorSlack::initialize() { return 0; } @@ -50,8 +50,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int GeneratorSlack::tagDifferentiable() + template + int GeneratorSlack::tagDifferentiable() { return 0; } @@ -61,8 +61,8 @@ namespace GridKit * * Must be connected to a PQ bus. */ - template - int GeneratorSlack::evaluateResidual() + template + int GeneratorSlack::evaluateResidual() { // std::cout << "Evaluating load residual ...\n"; // bus_->P() += P_; @@ -70,32 +70,32 @@ namespace GridKit return 0; } - template - int GeneratorSlack::evaluateJacobian() + template + int GeneratorSlack::evaluateJacobian() { return 0; } - template - int GeneratorSlack::evaluateIntegrand() + template + int GeneratorSlack::evaluateIntegrand() { return 0; } - template - int GeneratorSlack::initializeAdjoint() + template + int GeneratorSlack::initializeAdjoint() { return 0; } - template - int GeneratorSlack::evaluateAdjointResidual() + template + int GeneratorSlack::evaluateAdjointResidual() { return 0; } - template - int GeneratorSlack::evaluateAdjointIntegrand() + template + int GeneratorSlack::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerFlow/Generator/GeneratorSlack.hpp b/GridKit/Model/PowerFlow/Generator/GeneratorSlack.hpp index de7cb60c4..ef94b9469 100644 --- a/GridKit/Model/PowerFlow/Generator/GeneratorSlack.hpp +++ b/GridKit/Model/PowerFlow/Generator/GeneratorSlack.hpp @@ -8,7 +8,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -18,30 +18,32 @@ namespace GridKit * @brief Implementation of a power grid. * */ - template - class GeneratorSlack : public GeneratorBase + template + class GeneratorSlack : public GeneratorBase { - using GeneratorBase::size_; - using GeneratorBase::nnz_; - using GeneratorBase::time_; - using GeneratorBase::alpha_; - using GeneratorBase::y_; - using GeneratorBase::yp_; - using GeneratorBase::tag_; - using GeneratorBase::f_; - using GeneratorBase::g_; - using GeneratorBase::yB_; - using GeneratorBase::ypB_; - using GeneratorBase::fB_; - using GeneratorBase::gB_; - using GeneratorBase::param_; - - using bus_type = BaseBus; - using RealT = typename ModelEvaluatorImpl::RealT; - using GenData = GridKit::PowerFlowData::GenData; + using GeneratorBase::size_; + using GeneratorBase::nnz_; + using GeneratorBase::time_; + using GeneratorBase::alpha_; + using GeneratorBase::y_; + using GeneratorBase::yp_; + using GeneratorBase::tag_; + using GeneratorBase::f_; + using GeneratorBase::g_; + using GeneratorBase::yB_; + using GeneratorBase::ypB_; + using GeneratorBase::fB_; + using GeneratorBase::gB_; + using GeneratorBase::param_; public: - GeneratorSlack(bus_type* bus, GenData& data); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename ModelEvaluatorImpl::RealT; + using BusT = BaseBus; + using GenData = GridKit::PowerFlowData::GenData; + + GeneratorSlack(BusT* bus, GenData& data); virtual ~GeneratorSlack(); int allocate(); @@ -77,6 +79,6 @@ namespace GridKit } private: - bus_type* bus_; + BusT* bus_; }; } // namespace GridKit diff --git a/GridKit/Model/PowerFlow/Generator2/Generator2.cpp b/GridKit/Model/PowerFlow/Generator2/Generator2.cpp index 4d0ee4195..0a79672d7 100644 --- a/GridKit/Model/PowerFlow/Generator2/Generator2.cpp +++ b/GridKit/Model/PowerFlow/Generator2/Generator2.cpp @@ -19,8 +19,8 @@ namespace GridKit * - Number of quadratures = 1 * - Number of optimization parameters = 1 */ - template - Generator2::Generator2(bus_type* bus) + template + Generator2::Generator2(BusT* bus) : ModelEvaluatorImpl(2, 1, 1), H_(5.0), D_(0.005), @@ -38,38 +38,38 @@ namespace GridKit { } - template - Generator2::~Generator2() + template + Generator2::~Generator2() { } /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int Generator2::allocate() + template + int Generator2::allocate() { tag_.resize(static_cast(size_)); return 0; } - template - int Generator2::tagDifferentiable() + template + int Generator2::tagDifferentiable() { tag_[0] = true; tag_[1] = true; return 0; } - template - int Generator2::setAbsoluteTolerance(RealT rel_tol) + template + int Generator2::setAbsoluteTolerance(RealT rel_tol) { abs_tol_.setToConst(static_cast(rel_tol)); return 0; } - template - int Generator2::initialize() + template + int Generator2::initialize() { auto* y = y_.getData(); auto* yp = yp_.getData(); @@ -96,8 +96,8 @@ namespace GridKit return 0; } - template - int Generator2::evaluateResidual() + template + int Generator2::evaluateResidual() { const auto* y = y_.getData(); const auto* yp = yp_.getData(); @@ -110,16 +110,16 @@ namespace GridKit return 0; } - template - int Generator2::evaluateJacobian() + template + int Generator2::evaluateJacobian() { std::cout << "Evaluate Jacobian for Gen2..." << std::endl; std::cout << "Jacobian evaluation not implemented!" << std::endl; return 0; } - template - int Generator2::evaluateIntegrand() + template + int Generator2::evaluateIntegrand() { const auto* y = y_.getData(); auto* g = g_.getData(); @@ -129,8 +129,8 @@ namespace GridKit return 0; } - template - int Generator2::initializeAdjoint() + template + int Generator2::initializeAdjoint() { const auto* y = y_.getData(); auto* yB = yB_.getData(); @@ -147,8 +147,8 @@ namespace GridKit return 0; } - template - int Generator2::evaluateAdjointResidual() + template + int Generator2::evaluateAdjointResidual() { const auto* y = y_.getData(); const auto* yB = yB_.getData(); @@ -161,16 +161,16 @@ namespace GridKit return 0; } - // template - // int Generator2::evaluateAdjointJacobian() + // template + // int Generator2::evaluateAdjointJacobian() // { // std::cout << "Evaluate adjoint Jacobian for Gen2..." << std::endl; // std::cout << "Adjoint Jacobian evaluation not implemented!" << std::endl; // return 0; // } - template - int Generator2::evaluateAdjointIntegrand() + template + int Generator2::evaluateAdjointIntegrand() { // std::cout << "Evaluate adjoint Integrand for Gen2..." << std::endl; const auto* yB = yB_.getData(); @@ -188,8 +188,8 @@ namespace GridKit /** * Frequency penalty is used as the objective function for the generator model. */ - template - ScalarT Generator2::frequencyPenalty(ScalarT omega) + template + scalar_type Generator2::frequencyPenalty(ScalarT omega) { return c_ * pow(std::max(0.0, std::max(omega - omega_up_, omega_lo_ - omega)), beta_); } @@ -198,8 +198,8 @@ namespace GridKit * Derivative of frequency penalty cannot be written in terms of min/max functions. * Need to expand conditional statements instead. */ - template - ScalarT Generator2::frequencyPenaltyDer(ScalarT omega) + template + scalar_type Generator2::frequencyPenaltyDer(ScalarT omega) { if (omega > omega_up_) { diff --git a/GridKit/Model/PowerFlow/Generator2/Generator2.hpp b/GridKit/Model/PowerFlow/Generator2/Generator2.hpp index de429e06c..833be59fd 100644 --- a/GridKit/Model/PowerFlow/Generator2/Generator2.hpp +++ b/GridKit/Model/PowerFlow/Generator2/Generator2.hpp @@ -5,7 +5,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -15,32 +15,34 @@ namespace GridKit * @brief Implementation of a second order generator model. * */ - template - class Generator2 : public ModelEvaluatorImpl + template + class Generator2 : public ModelEvaluatorImpl { - using ModelEvaluatorImpl::size_; - using ModelEvaluatorImpl::nnz_; - using ModelEvaluatorImpl::time_; - using ModelEvaluatorImpl::alpha_; - using ModelEvaluatorImpl::y_; - using ModelEvaluatorImpl::yp_; - using ModelEvaluatorImpl::tag_; - using ModelEvaluatorImpl::abs_tol_; - using ModelEvaluatorImpl::f_; - using ModelEvaluatorImpl::g_; - using ModelEvaluatorImpl::yB_; - using ModelEvaluatorImpl::ypB_; - using ModelEvaluatorImpl::fB_; - using ModelEvaluatorImpl::gB_; - using ModelEvaluatorImpl::param_; - using ModelEvaluatorImpl::param_up_; - using ModelEvaluatorImpl::param_lo_; - - using RealT = typename ModelEvaluatorImpl::RealT; - using bus_type = BaseBus; + using ModelEvaluatorImpl::size_; + using ModelEvaluatorImpl::nnz_; + using ModelEvaluatorImpl::time_; + using ModelEvaluatorImpl::alpha_; + using ModelEvaluatorImpl::y_; + using ModelEvaluatorImpl::yp_; + using ModelEvaluatorImpl::tag_; + using ModelEvaluatorImpl::abs_tol_; + using ModelEvaluatorImpl::f_; + using ModelEvaluatorImpl::g_; + using ModelEvaluatorImpl::yB_; + using ModelEvaluatorImpl::ypB_; + using ModelEvaluatorImpl::fB_; + using ModelEvaluatorImpl::gB_; + using ModelEvaluatorImpl::param_; + using ModelEvaluatorImpl::param_up_; + using ModelEvaluatorImpl::param_lo_; public: - Generator2(bus_type* bus); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename ModelEvaluatorImpl::RealT; + using BusT = BaseBus; + + Generator2(BusT* bus); virtual ~Generator2(); int allocate(); @@ -100,7 +102,7 @@ namespace GridKit RealT c_; RealT beta_; - bus_type* bus_; + BusT* bus_; }; } // namespace GridKit diff --git a/GridKit/Model/PowerFlow/Generator4/Generator4.cpp b/GridKit/Model/PowerFlow/Generator4/Generator4.cpp index 46549d16a..438328861 100644 --- a/GridKit/Model/PowerFlow/Generator4/Generator4.cpp +++ b/GridKit/Model/PowerFlow/Generator4/Generator4.cpp @@ -18,8 +18,8 @@ namespace GridKit * - Number of quadratures = 1 * - Number of optimization parameters = 2 */ - template - Generator4::Generator4(bus_type* bus, ScalarT P0, ScalarT Q0) + template + Generator4::Generator4(BusT* bus, ScalarT P0, ScalarT Q0) : ModelEvaluatorImpl(6, 1, 2), H_(5.0), D_(0.04), @@ -44,8 +44,8 @@ namespace GridKit { } - template - Generator4::~Generator4() + template + Generator4::~Generator4() { } @@ -53,8 +53,8 @@ namespace GridKit * @brief This function will be used to allocate sparse Jacobian matrices. * */ - template - int Generator4::allocate() + template + int Generator4::allocate() { // std::cout << "Allocate Generator4..." << std::endl; tag_.resize(static_cast(size_)); @@ -83,8 +83,8 @@ namespace GridKit * \f} * */ - template - int Generator4::initialize() + template + int Generator4::initialize() { // std::cout << "Initialize Generator4..." << std::endl; @@ -145,8 +145,8 @@ namespace GridKit /** * \brief Identify differential variables. */ - template - int Generator4::tagDifferentiable() + template + int Generator4::tagDifferentiable() { tag_[0] = true; tag_[1] = true; @@ -166,15 +166,13 @@ namespace GridKit * * @param rel_tol The relative tolerance which can be used to pick the * absolute tolerance. - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 if successful, non-zero otherwise. * * This represents a "noise" level close to zero for which pure relative * error cannot be used. */ - template - int Generator4::setAbsoluteTolerance(RealT rel_tol) + template + int Generator4::setAbsoluteTolerance(RealT rel_tol) { abs_tol_.setToConst(static_cast(rel_tol)); return 0; @@ -208,8 +206,8 @@ namespace GridKit * \f$ y_4 = I_d \f$, \f$ y_5 = I_q \f$. * */ - template - int Generator4::evaluateResidual() + template + int Generator4::evaluateResidual() { // std::cout << "Evaluate residual for Generator4..." << std::endl; auto* f = f_.getData(); @@ -234,16 +232,16 @@ namespace GridKit return 0; } - template - int Generator4::evaluateJacobian() + template + int Generator4::evaluateJacobian() { std::cerr << "Evaluate Jacobian for Generator4..." << std::endl; std::cerr << "Jacobian evaluation not implemented!" << std::endl; return 0; } - template - int Generator4::evaluateIntegrand() + template + int Generator4::evaluateIntegrand() { // std::cout << "Evaluate Integrand for Generator4..." << std::endl; const auto* y = y_.getData(); @@ -254,8 +252,8 @@ namespace GridKit return 0; } - template - int Generator4::initializeAdjoint() + template + int Generator4::initializeAdjoint() { // std::cout << "Initialize adjoint for Generator4..." << std::endl; const auto* y = y_.getData(); @@ -289,8 +287,8 @@ namespace GridKit * \f} * */ - template - int Generator4::evaluateAdjointResidual() + template + int Generator4::evaluateAdjointResidual() { // std::cout << "Evaluate adjoint residual for Generator4..." << std::endl; ScalarT sinPhi = sin(delta() - theta()); @@ -313,16 +311,16 @@ namespace GridKit return 0; } - // template - // int Generator4::evaluateAdjointJacobian() + // template + // int Generator4::evaluateAdjointJacobian() // { // std::cout << "Evaluate adjoint Jacobian for Generator4..." << std::endl; // std::cout << "Adjoint Jacobian evaluation not implemented!" << std::endl; // return 0; // } - template - int Generator4::evaluateAdjointIntegrand() + template + int Generator4::evaluateAdjointIntegrand() { // std::cout << "Evaluate adjoint Integrand for Generator4..." << std::endl; const auto* yB = yB_.getData(); @@ -346,8 +344,8 @@ namespace GridKit * \f[ P_g = E_q' I_q + E_d' I_d + (X_q' - X_d') I_q I_d - R_a (I_d^2 + I_q^2) \f] * */ - template - ScalarT Generator4::Pg() + template + scalar_type Generator4::Pg() { const auto* y = y_.getData(); return y[5] * V() * cos(theta() - y[0]) + y[4] * V() * sin(theta() - y[0]); @@ -358,8 +356,8 @@ namespace GridKit * * \f[ Q_g = E_q' I_d - E_d' I_q - X_d' I_d^2 - X_q' I_q^2 \f] */ - template - ScalarT Generator4::Qg() + template + scalar_type Generator4::Qg() { const auto* y = y_.getData(); return y[5] * V() * sin(theta() - y[0]) - y[4] * V() * cos(theta() - y[0]); @@ -368,8 +366,8 @@ namespace GridKit /** * Frequency penalty is used as the objective function for the generator model. */ - template - ScalarT Generator4::frequencyPenalty(ScalarT omega) + template + scalar_type Generator4::frequencyPenalty(ScalarT omega) { return c_ * pow(std::max(0.0, std::max(omega - omega_up_, omega_lo_ - omega)), beta_); } @@ -378,8 +376,8 @@ namespace GridKit * Derivative of frequency penalty cannot be written in terms of min/max functions. * Need to expand conditional statements instead. */ - template - ScalarT Generator4::frequencyPenaltyDer(ScalarT omega) + template + scalar_type Generator4::frequencyPenaltyDer(ScalarT omega) { if (omega > omega_up_) { diff --git a/GridKit/Model/PowerFlow/Generator4/Generator4.hpp b/GridKit/Model/PowerFlow/Generator4/Generator4.hpp index f5d0e862d..31393e1e6 100644 --- a/GridKit/Model/PowerFlow/Generator4/Generator4.hpp +++ b/GridKit/Model/PowerFlow/Generator4/Generator4.hpp @@ -5,7 +5,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -15,32 +15,34 @@ namespace GridKit * @brief Implementation of a fourth order generator model. * */ - template - class Generator4 : public ModelEvaluatorImpl + template + class Generator4 : public ModelEvaluatorImpl { - using ModelEvaluatorImpl::size_; - using ModelEvaluatorImpl::nnz_; - using ModelEvaluatorImpl::time_; - using ModelEvaluatorImpl::alpha_; - using ModelEvaluatorImpl::y_; - using ModelEvaluatorImpl::yp_; - using ModelEvaluatorImpl::tag_; - using ModelEvaluatorImpl::abs_tol_; - using ModelEvaluatorImpl::f_; - using ModelEvaluatorImpl::g_; - using ModelEvaluatorImpl::yB_; - using ModelEvaluatorImpl::ypB_; - using ModelEvaluatorImpl::fB_; - using ModelEvaluatorImpl::gB_; - using ModelEvaluatorImpl::param_; - using ModelEvaluatorImpl::param_up_; - using ModelEvaluatorImpl::param_lo_; - - using RealT = typename ModelEvaluatorImpl::RealT; - using bus_type = BaseBus; + using ModelEvaluatorImpl::size_; + using ModelEvaluatorImpl::nnz_; + using ModelEvaluatorImpl::time_; + using ModelEvaluatorImpl::alpha_; + using ModelEvaluatorImpl::y_; + using ModelEvaluatorImpl::yp_; + using ModelEvaluatorImpl::tag_; + using ModelEvaluatorImpl::abs_tol_; + using ModelEvaluatorImpl::f_; + using ModelEvaluatorImpl::g_; + using ModelEvaluatorImpl::yB_; + using ModelEvaluatorImpl::ypB_; + using ModelEvaluatorImpl::fB_; + using ModelEvaluatorImpl::gB_; + using ModelEvaluatorImpl::param_; + using ModelEvaluatorImpl::param_up_; + using ModelEvaluatorImpl::param_lo_; public: - Generator4(BaseBus* bus, ScalarT P0 = 1.0, ScalarT Q0 = 0.0); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename ModelEvaluatorImpl::RealT; + using BusT = BaseBus; + + Generator4(BusT* bus, ScalarT P0 = 1.0, ScalarT Q0 = 0.0); virtual ~Generator4(); int allocate(); @@ -196,7 +198,7 @@ namespace GridKit ScalarT P0_; ScalarT Q0_; - bus_type* bus_; + BusT* bus_; }; } // namespace GridKit diff --git a/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.cpp b/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.cpp index f7c33ae01..8d40765b2 100644 --- a/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.cpp +++ b/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.cpp @@ -20,8 +20,8 @@ namespace GridKit * - Number of optimization parameters = 2 * */ - template - Generator4Governor::Generator4Governor(bus_type* bus, ScalarT P0, ScalarT Q0) + template + Generator4Governor::Generator4Governor(BusT* bus, ScalarT P0, ScalarT Q0) : ModelEvaluatorImpl(9, 1, 2), H_(5.0), D_(0.04), @@ -54,8 +54,8 @@ namespace GridKit { } - template - Generator4Governor::~Generator4Governor() + template + Generator4Governor::~Generator4Governor() { // std::cout << "Destroy Gen2..." << std::endl; } @@ -63,8 +63,8 @@ namespace GridKit /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int Generator4Governor::allocate() + template + int Generator4Governor::allocate() { // std::cout << "Allocate Gen2..." << std::endl; tag_.resize(static_cast(size_)); @@ -93,8 +93,8 @@ namespace GridKit * \f} * */ - template - int Generator4Governor::initialize() + template + int Generator4Governor::initialize() { // std::cout << "Initialize Generator4Governor..." << std::endl; @@ -162,8 +162,8 @@ namespace GridKit /** * \brief Identify differential variables. */ - template - int Generator4Governor::tagDifferentiable() + template + int Generator4Governor::tagDifferentiable() { // std::cout << "size of tag vector is " << tag_.size() << "\n"; tag_[static_cast(offsetGen_ + 0)] = true; @@ -180,8 +180,8 @@ namespace GridKit return 0; } - template - int Generator4Governor::setAbsoluteTolerance(RealT rel_tol) + template + int Generator4Governor::setAbsoluteTolerance(RealT rel_tol) { abs_tol_.setToConst(static_cast(rel_tol)); return 0; @@ -223,8 +223,8 @@ namespace GridKit * */ - template - int Generator4Governor::evaluateResidual() + template + int Generator4Governor::evaluateResidual() { const auto* y = y_.getData(); const auto* yp = yp_.getData(); @@ -261,16 +261,16 @@ namespace GridKit * * */ - template - int Generator4Governor::evaluateJacobian() + template + int Generator4Governor::evaluateJacobian() { std::cout << "Evaluate Jacobian for Gen2..." << std::endl; std::cout << "Jacobian evaluation not implemented!" << std::endl; return 0; } - template - int Generator4Governor::evaluateIntegrand() + template + int Generator4Governor::evaluateIntegrand() { // std::cout << "Evaluate Integrand for Gen2..." << std::endl; auto* g = g_.getData(); @@ -280,8 +280,8 @@ namespace GridKit return 0; } - template - int Generator4Governor::initializeAdjoint() + template + int Generator4Governor::initializeAdjoint() { // std::cout << "Initialize adjoint for Generator4Governor..." << std::endl; auto* yB = yB_.getData(); @@ -327,8 +327,8 @@ namespace GridKit * * */ - template - int Generator4Governor::evaluateAdjointResidual() + template + int Generator4Governor::evaluateAdjointResidual() { // std::cout << "Evaluate adjoint residual for Gen2..." << std::endl; ScalarT sinPhi = sin(delta() - theta()); @@ -370,16 +370,16 @@ namespace GridKit return 0; } - // template - // int Generator4Governor::evaluateAdjointJacobian() + // template + // int Generator4Governor::evaluateAdjointJacobian() // { // std::cout << "Evaluate adjoint Jacobian for Gen2..." << std::endl; // std::cout << "Adjoint Jacobian evaluation not implemented!" << std::endl; // return 0; // } - template - int Generator4Governor::evaluateAdjointIntegrand() + template + int Generator4Governor::evaluateAdjointIntegrand() { // std::cout << "Evaluate adjoint Integrand for Gen2..." << std::endl; const auto* y = y_.getData(); @@ -407,8 +407,8 @@ namespace GridKit * \f[ P_g = E_q' I_q + E_d' I_d + (X_q' - X_d') I_q I_d - R_a (I_d^2 + I_q^2) \f] * */ - template - ScalarT Generator4Governor::Pg() + template + scalar_type Generator4Governor::Pg() { return Iq() * Eqp() + Id() * Edp() + (Xqp_ - Xdp_) * Id() * Iq() - Rs_ * (Id() * Id() + Iq() * Iq()); } @@ -418,8 +418,8 @@ namespace GridKit * * \f[ Q_g = E_q' I_d - E_d' I_q - X_d' I_d^2 - X_q' I_q^2 \f] */ - template - ScalarT Generator4Governor::Qg() + template + scalar_type Generator4Governor::Qg() { return -Iq() * Edp() + Id() * Eqp() - Xdp_ * Id() * Id() - Xqp_ * Iq() * Iq(); } @@ -430,8 +430,8 @@ namespace GridKit * @todo Use smooth penalty function! * */ - template - ScalarT Generator4Governor::frequencyPenalty(ScalarT omega) + template + scalar_type Generator4Governor::frequencyPenalty(ScalarT omega) { return c_ * pow(std::max(0.0, std::max(omega - omega_up_, omega_lo_ - omega)), beta_); } @@ -443,8 +443,8 @@ namespace GridKit * @todo Use smooth penalty function! * */ - template - ScalarT Generator4Governor::frequencyPenaltyDer(ScalarT omega) + template + scalar_type Generator4Governor::frequencyPenaltyDer(ScalarT omega) { if (omega > omega_up_) { @@ -460,26 +460,26 @@ namespace GridKit } } - template - ScalarT Generator4Governor::Lm(ScalarT Pm) + template + scalar_type Generator4Governor::Lm(ScalarT Pm) { return Pm0_ + deltaPm_ * std::tanh(Pm); } - template - ScalarT Generator4Governor::dLm(ScalarT Pm) + template + scalar_type Generator4Governor::dLm(ScalarT Pm) { return deltaPm_ / (std::cosh(Pm) * std::cosh(Pm)); } - template - ScalarT Generator4Governor::Ln(ScalarT Pn) + template + scalar_type Generator4Governor::Ln(ScalarT Pn) { return deltaPn_ * std::tanh(Pn); } - template - ScalarT Generator4Governor::dLn(ScalarT Pn) + template + scalar_type Generator4Governor::dLn(ScalarT Pn) { return deltaPn_ / (std::cosh(Pn) * std::cosh(Pn)); } diff --git a/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.hpp b/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.hpp index 3fd7e37b7..86018233f 100644 --- a/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.hpp +++ b/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.hpp @@ -5,7 +5,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -16,32 +16,34 @@ namespace GridKit * a simple governor. * */ - template - class Generator4Governor : public ModelEvaluatorImpl + template + class Generator4Governor : public ModelEvaluatorImpl { - using ModelEvaluatorImpl::size_; - using ModelEvaluatorImpl::nnz_; - using ModelEvaluatorImpl::time_; - using ModelEvaluatorImpl::alpha_; - using ModelEvaluatorImpl::y_; - using ModelEvaluatorImpl::yp_; - using ModelEvaluatorImpl::tag_; - using ModelEvaluatorImpl::abs_tol_; - using ModelEvaluatorImpl::f_; - using ModelEvaluatorImpl::g_; - using ModelEvaluatorImpl::yB_; - using ModelEvaluatorImpl::ypB_; - using ModelEvaluatorImpl::fB_; - using ModelEvaluatorImpl::gB_; - using ModelEvaluatorImpl::param_; - using ModelEvaluatorImpl::param_up_; - using ModelEvaluatorImpl::param_lo_; + using ModelEvaluatorImpl::size_; + using ModelEvaluatorImpl::nnz_; + using ModelEvaluatorImpl::time_; + using ModelEvaluatorImpl::alpha_; + using ModelEvaluatorImpl::y_; + using ModelEvaluatorImpl::yp_; + using ModelEvaluatorImpl::tag_; + using ModelEvaluatorImpl::abs_tol_; + using ModelEvaluatorImpl::f_; + using ModelEvaluatorImpl::g_; + using ModelEvaluatorImpl::yB_; + using ModelEvaluatorImpl::ypB_; + using ModelEvaluatorImpl::fB_; + using ModelEvaluatorImpl::gB_; + using ModelEvaluatorImpl::param_; + using ModelEvaluatorImpl::param_up_; + using ModelEvaluatorImpl::param_lo_; public: - using RealT = typename ModelEvaluatorImpl::RealT; - using bus_type = BaseBus; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename ModelEvaluatorImpl::RealT; + using BusT = BaseBus; - Generator4Governor(bus_type* bus, ScalarT P0, ScalarT Q0); + Generator4Governor(BusT* bus, ScalarT P0, ScalarT Q0); virtual ~Generator4Governor(); int allocate(); @@ -257,7 +259,7 @@ namespace GridKit ScalarT Q0_; // Bus to which the generator is connected - bus_type* bus_; + BusT* bus_; }; } // namespace GridKit diff --git a/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.cpp b/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.cpp index 418bc7f33..bda21291c 100644 --- a/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.cpp +++ b/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.cpp @@ -19,8 +19,8 @@ namespace GridKit * - Number of quadratures = 1 * - Number of optimization parameters = 1 */ - template - Generator4Param::Generator4Param(bus_type* bus, ScalarT P0, ScalarT Q0) + template + Generator4Param::Generator4Param(BusT* bus, ScalarT P0, ScalarT Q0) : ModelEvaluatorImpl(6, 1, 1), H_(5.0), D_(0.04), @@ -41,8 +41,8 @@ namespace GridKit { } - template - Generator4Param::~Generator4Param() + template + Generator4Param::~Generator4Param() { } @@ -50,8 +50,8 @@ namespace GridKit * @brief This function will be used to allocate sparse Jacobian matrices. * */ - template - int Generator4Param::allocate() + template + int Generator4Param::allocate() { // std::cout << "Allocate Generator4Param..." << std::endl; tag_.resize(static_cast(size_)); @@ -80,8 +80,8 @@ namespace GridKit * \f} * */ - template - int Generator4Param::initialize() + template + int Generator4Param::initialize() { // std::cout << "Initialize Generator4Param..." << std::endl; @@ -138,8 +138,8 @@ namespace GridKit /** * \brief Identify differential variables. */ - template - int Generator4Param::tagDifferentiable() + template + int Generator4Param::tagDifferentiable() { tag_[0] = true; tag_[1] = true; @@ -154,8 +154,8 @@ namespace GridKit return 0; } - template - int Generator4Param::setAbsoluteTolerance(RealT rel_tol) + template + int Generator4Param::setAbsoluteTolerance(RealT rel_tol) { abs_tol_.setToConst(static_cast(rel_tol)); return 0; @@ -189,8 +189,8 @@ namespace GridKit * \f$ y_4 = I_d \f$, \f$ y_5 = I_q \f$. * */ - template - int Generator4Param::evaluateResidual() + template + int Generator4Param::evaluateResidual() { // std::cout << "Evaluate residual for Generator4Param..." << std::endl; auto* f = f_.getData(); @@ -217,16 +217,16 @@ namespace GridKit return 0; } - template - int Generator4Param::evaluateJacobian() + template + int Generator4Param::evaluateJacobian() { std::cerr << "Evaluate Jacobian for Generator4Param..." << std::endl; std::cerr << "Jacobian evaluation not implemented!" << std::endl; return 0; } - template - int Generator4Param::evaluateIntegrand() + template + int Generator4Param::evaluateIntegrand() { // std::cout << "Evaluate Integrand for Generator4Param..." << std::endl; auto* g = g_.getData(); @@ -236,8 +236,8 @@ namespace GridKit return 0; } - template - int Generator4Param::initializeAdjoint() + template + int Generator4Param::initializeAdjoint() { // std::cout << "Initialize adjoint for Generator4Param..." << std::endl; auto* yB = yB_.getData(); @@ -271,8 +271,8 @@ namespace GridKit * \f} * */ - template - int Generator4Param::evaluateAdjointResidual() + template + int Generator4Param::evaluateAdjointResidual() { // std::cout << "Evaluate adjoint residual for Generator4Param..." << std::endl; ScalarT sinPhi = sin(delta() - theta()); @@ -295,16 +295,16 @@ namespace GridKit return 0; } - // template - // int Generator4Param::evaluateAdjointJacobian() + // template + // int Generator4Param::evaluateAdjointJacobian() // { // std::cout << "Evaluate adjoint Jacobian for Generator4Param..." << std::endl; // std::cout << "Adjoint Jacobian evaluation not implemented!" << std::endl; // return 0; // } - template - int Generator4Param::evaluateAdjointIntegrand() + template + int Generator4Param::evaluateAdjointIntegrand() { // std::cout << "Evaluate adjoint Integrand for Generator4Param..." << std::endl; const auto* yB = yB_.getData(); @@ -327,8 +327,8 @@ namespace GridKit * \f[ P_g = E_q' I_q + E_d' I_d + (X_q' - X_d') I_q I_d - R_a (I_d^2 + I_q^2) \f] * */ - template - ScalarT Generator4Param::Pg() + template + scalar_type Generator4Param::Pg() { const auto* y = y_.getData(); return y[5] * V() * cos(theta() - y[0]) + y[4] * V() * sin(theta() - y[0]); @@ -339,8 +339,8 @@ namespace GridKit * * \f[ Q_g = E_q' I_d - E_d' I_q - X_d' I_d^2 - X_q' I_q^2 \f] */ - template - ScalarT Generator4Param::Qg() + template + scalar_type Generator4Param::Qg() { const auto* y = y_.getData(); return y[5] * V() * sin(theta() - y[0]) - y[4] * V() * cos(theta() - y[0]); @@ -351,8 +351,8 @@ namespace GridKit * * @todo Look-up table should probably live outside the generator model. */ - template - ScalarT Generator4Param::trajectoryPenalty(ScalarT t) const + template + scalar_type Generator4Param::trajectoryPenalty(ScalarT t) const { size_t N = table_.size(); double ti = table_[0][0]; @@ -389,8 +389,8 @@ namespace GridKit return (d * d + q * q); } - template - ScalarT Generator4Param::trajectoryPenaltyDerEdp(ScalarT t) const + template + scalar_type Generator4Param::trajectoryPenaltyDerEdp(ScalarT t) const { size_t N = table_.size(); double ti = table_[0][0]; @@ -420,8 +420,8 @@ namespace GridKit return 2.0 * d; } - template - ScalarT Generator4Param::trajectoryPenaltyDerEqp(ScalarT t) const + template + scalar_type Generator4Param::trajectoryPenaltyDerEqp(ScalarT t) const { size_t N = table_.size(); double ti = table_[0][0]; diff --git a/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.hpp b/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.hpp index d01c5b043..2c7cc8e21 100644 --- a/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.hpp +++ b/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.hpp @@ -5,7 +5,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -15,32 +15,34 @@ namespace GridKit * @brief Implementation of a fourth order generator model. * */ - template - class Generator4Param : public ModelEvaluatorImpl + template + class Generator4Param : public ModelEvaluatorImpl { - using ModelEvaluatorImpl::size_; - using ModelEvaluatorImpl::nnz_; - using ModelEvaluatorImpl::time_; - using ModelEvaluatorImpl::alpha_; - using ModelEvaluatorImpl::y_; - using ModelEvaluatorImpl::yp_; - using ModelEvaluatorImpl::tag_; - using ModelEvaluatorImpl::abs_tol_; - using ModelEvaluatorImpl::f_; - using ModelEvaluatorImpl::g_; - using ModelEvaluatorImpl::yB_; - using ModelEvaluatorImpl::ypB_; - using ModelEvaluatorImpl::fB_; - using ModelEvaluatorImpl::gB_; - using ModelEvaluatorImpl::param_; - using ModelEvaluatorImpl::param_up_; - using ModelEvaluatorImpl::param_lo_; - - using RealT = typename ModelEvaluatorImpl::RealT; - using bus_type = BaseBus; + using ModelEvaluatorImpl::size_; + using ModelEvaluatorImpl::nnz_; + using ModelEvaluatorImpl::time_; + using ModelEvaluatorImpl::alpha_; + using ModelEvaluatorImpl::y_; + using ModelEvaluatorImpl::yp_; + using ModelEvaluatorImpl::tag_; + using ModelEvaluatorImpl::abs_tol_; + using ModelEvaluatorImpl::f_; + using ModelEvaluatorImpl::g_; + using ModelEvaluatorImpl::yB_; + using ModelEvaluatorImpl::ypB_; + using ModelEvaluatorImpl::fB_; + using ModelEvaluatorImpl::gB_; + using ModelEvaluatorImpl::param_; + using ModelEvaluatorImpl::param_up_; + using ModelEvaluatorImpl::param_lo_; public: - Generator4Param(BaseBus* bus, ScalarT P0 = 1.0, ScalarT Q0 = 0.0); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename ModelEvaluatorImpl::RealT; + using BusT = BaseBus; + + Generator4Param(BusT* bus, ScalarT P0 = 1.0, ScalarT Q0 = 0.0); virtual ~Generator4Param(); int allocate(); @@ -209,7 +211,7 @@ namespace GridKit ScalarT P0_; ScalarT Q0_; - bus_type* bus_; + BusT* bus_; /// Look-up table data. @todo This should be part of a separate model. std::vector> table_; diff --git a/GridKit/Model/PowerFlow/Load/Load.cpp b/GridKit/Model/PowerFlow/Load/Load.cpp index 6313180e1..b62ccc4f6 100644 --- a/GridKit/Model/PowerFlow/Load/Load.cpp +++ b/GridKit/Model/PowerFlow/Load/Load.cpp @@ -16,8 +16,8 @@ namespace GridKit * Calls default ModelEvaluatorImpl constructor. */ - template - Load::Load(bus_type* bus, ScalarT P, ScalarT Q) + template + Load::Load(BusT* bus, ScalarT P, ScalarT Q) : P_(P), Q_(Q), busID_(0), @@ -27,8 +27,8 @@ namespace GridKit size_ = 0; } - template - Load::Load(bus_type* bus, LoadData& data) + template + Load::Load(BusT* bus, LoadData& data) : P_(data.Pd), Q_(data.Qd), busID_(data.bus_i), @@ -38,16 +38,16 @@ namespace GridKit size_ = 0; } - template - Load::~Load() + template + Load::~Load() { } /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int Load::allocate() + template + int Load::allocate() { return 0; } @@ -55,8 +55,8 @@ namespace GridKit /** * Initialization of the grid model */ - template - int Load::initialize() + template + int Load::initialize() { return 0; } @@ -64,8 +64,8 @@ namespace GridKit /* * \brief Identify differential variables */ - template - int Load::tagDifferentiable() + template + int Load::tagDifferentiable() { return 0; } @@ -75,15 +75,13 @@ namespace GridKit * * @param rel_tol The relative tolerance which can be used to pick the * absolute tolerance. - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 if successful, non-zero otherwise. * * This represents a "noise" level close to zero for which pure relative * error cannot be used. */ - template - int Load::setAbsoluteTolerance(RealT) + template + int Load::setAbsoluteTolerance(RealT) { return 0; } @@ -93,8 +91,8 @@ namespace GridKit * * Must be connected to a PQ bus. */ - template - int Load::evaluateResidual() + template + int Load::evaluateResidual() { // std::cout << "Evaluating load residual ...\n"; bus_->P() -= P_; @@ -106,32 +104,32 @@ namespace GridKit return 0; } - template - int Load::evaluateJacobian() + template + int Load::evaluateJacobian() { return 0; } - template - int Load::evaluateIntegrand() + template + int Load::evaluateIntegrand() { return 0; } - template - int Load::initializeAdjoint() + template + int Load::initializeAdjoint() { return 0; } - template - int Load::evaluateAdjointResidual() + template + int Load::evaluateAdjointResidual() { return 0; } - template - int Load::evaluateAdjointIntegrand() + template + int Load::evaluateAdjointIntegrand() { return 0; } diff --git a/GridKit/Model/PowerFlow/Load/Load.hpp b/GridKit/Model/PowerFlow/Load/Load.hpp index 256ccda8e..051a626d8 100644 --- a/GridKit/Model/PowerFlow/Load/Load.hpp +++ b/GridKit/Model/PowerFlow/Load/Load.hpp @@ -6,7 +6,7 @@ namespace GridKit { - template + template class BaseBus; } @@ -16,31 +16,33 @@ namespace GridKit * @brief Declaration of a passive load class. * */ - template - class Load : public ModelEvaluatorImpl + template + class Load : public ModelEvaluatorImpl { - using ModelEvaluatorImpl::size_; - using ModelEvaluatorImpl::nnz_; - using ModelEvaluatorImpl::time_; - using ModelEvaluatorImpl::alpha_; - using ModelEvaluatorImpl::y_; - using ModelEvaluatorImpl::yp_; - using ModelEvaluatorImpl::tag_; - using ModelEvaluatorImpl::f_; - using ModelEvaluatorImpl::g_; - using ModelEvaluatorImpl::yB_; - using ModelEvaluatorImpl::ypB_; - using ModelEvaluatorImpl::fB_; - using ModelEvaluatorImpl::gB_; - using ModelEvaluatorImpl::param_; + using ModelEvaluatorImpl::size_; + using ModelEvaluatorImpl::nnz_; + using ModelEvaluatorImpl::time_; + using ModelEvaluatorImpl::alpha_; + using ModelEvaluatorImpl::y_; + using ModelEvaluatorImpl::yp_; + using ModelEvaluatorImpl::tag_; + using ModelEvaluatorImpl::f_; + using ModelEvaluatorImpl::g_; + using ModelEvaluatorImpl::yB_; + using ModelEvaluatorImpl::ypB_; + using ModelEvaluatorImpl::fB_; + using ModelEvaluatorImpl::gB_; + using ModelEvaluatorImpl::param_; + public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename ModelEvaluatorImpl::RealT; - using bus_type = BaseBus; + using BusT = BaseBus; using LoadData = GridKit::PowerFlowData::LoadData; - public: - Load(bus_type* bus, ScalarT P, ScalarT Q); - Load(bus_type* bus, LoadData& data); + Load(BusT* bus, ScalarT P, ScalarT Q); + Load(BusT* bus, LoadData& data); virtual ~Load(); int allocate(); @@ -66,6 +68,6 @@ namespace GridKit ScalarT P_; ScalarT Q_; const IdxT busID_; - bus_type* bus_; + BusT* bus_; }; } // namespace GridKit diff --git a/GridKit/Model/PowerFlow/MatpowerParser.hpp b/GridKit/Model/PowerFlow/MatpowerParser.hpp index f192da27d..efdcab4b9 100644 --- a/GridKit/Model/PowerFlow/MatpowerParser.hpp +++ b/GridKit/Model/PowerFlow/MatpowerParser.hpp @@ -96,8 +96,8 @@ namespace GridKit throw std::runtime_error(matlab_syntax_error); } - template - void readMatPowerBusRow(const std::string& row, BusData& br, LoadData& lr) + template + void readMatPowerBusRow(const std::string& row, BusData& br, LoadData& lr) { logs() << "Parsing MATPOWER bus row\n"; std::stringstream is(row); @@ -122,8 +122,8 @@ namespace GridKit // return br; } - template - void readMatPowerGenRow(GenData& gr, std::string& row) + template + void readMatPowerGenRow(GenData& gr, std::string& row) { logs() << "Parsing MATPOWER gen row\n"; std::stringstream is(row); @@ -134,8 +134,8 @@ namespace GridKit checkEndOfMatrixRow(is); } - template - void readMatPowerBranchRow(BranchData& br, std::string& row) + template + void readMatPowerBranchRow(BranchData& br, std::string& row) { logs() << "Parsing MATPOWER branch row\n"; std::stringstream is(row); @@ -145,9 +145,10 @@ namespace GridKit checkEndOfMatrixRow(is); } - template - void readMatPowerGenCostRow(GenCostData& gcr, std::string& row) + template + void readMatPowerGenCostRow(GenCostData& gcr, std::string& row) { + using RealT = real_type; logs() << "Parsing MATPOWER gen cost row\n"; // Ensure last character is semicolon. rtrim(row); @@ -163,8 +164,8 @@ namespace GridKit } } - template - void readMatPowerVersion(SystemModelData& mp, std::string& line) + template + void readMatPowerVersion(SystemModelData& mp, std::string& line) { logs() << "Parsing matpower version\n"; std::regex pat("mpc\\.version\\s*=\\s*'([0-9])';"); @@ -179,8 +180,8 @@ namespace GridKit } } - template - void readMatPowerBaseMVA(SystemModelData& mp, std::string& line) + template + void readMatPowerBaseMVA(SystemModelData& mp, std::string& line) { std::regex pat("mpc\\.baseMVA\\s*=\\s*([0-9]+);"); std::smatch matches; @@ -195,22 +196,22 @@ namespace GridKit } } - template - void readMatPowerFile(SystemModelData& mp, std::string& filename) + template + void readMatPowerFile(SystemModelData& mp, std::string& filename) { std::ifstream ifs{filename}; readMatPower(mp, ifs); } - template - void readMatPower(SystemModelData& mp, std::istream& is) + template + void readMatPower(SystemModelData& mp, std::istream& is) { + using RealT = real_type; + using IdxT = index_type; using BusDataT = BusData; using GenDataT = GenData; - using BranchDataT = BranchData; - using GenCostDataT = GenCostData; + using BranchDataT = BranchData; + using GenCostDataT = GenCostData; using LoadDataT = LoadData; for (std::string line; std::getline(is, line);) diff --git a/GridKit/Model/PowerFlow/MiniGrid/MiniGrid.cpp b/GridKit/Model/PowerFlow/MiniGrid/MiniGrid.cpp index bf87dca13..b20cfeaa6 100644 --- a/GridKit/Model/PowerFlow/MiniGrid/MiniGrid.cpp +++ b/GridKit/Model/PowerFlow/MiniGrid/MiniGrid.cpp @@ -16,8 +16,8 @@ namespace GridKit * Calls default ModelEvaluatorImpl constructor. */ - template - MiniGrid::MiniGrid() + template + MiniGrid::MiniGrid() : ModelEvaluatorImpl(3, 0, 0), Pl2_(2.5), Ql2_(-0.8), @@ -33,16 +33,16 @@ namespace GridKit // std::cout << "Create a load model with " << size_ << " variables ...\n"; } - template - MiniGrid::~MiniGrid() + template + MiniGrid::~MiniGrid() { } /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int MiniGrid::allocate() + template + int MiniGrid::allocate() { return 0; } @@ -50,8 +50,8 @@ namespace GridKit /** * Initialization of the grid model */ - template - int MiniGrid::initialize() + template + int MiniGrid::initialize() { th2() = 0.0; // th2 V2() = 1.0; // V2 @@ -65,8 +65,8 @@ namespace GridKit * * Must be connected to a PQ bus. */ - template - int MiniGrid::evaluateResidual() + template + int MiniGrid::evaluateResidual() { auto* f = f_.getData(); f[0] = -Pl2_ - V2() * (V1_ * B12_ * sin(th2() - th1_) + V3_ * B23_ * sin(th2() - th3())); @@ -78,8 +78,8 @@ namespace GridKit return 0; } - template - int MiniGrid::evaluateJacobian() + template + int MiniGrid::evaluateJacobian() { return 0; } diff --git a/GridKit/Model/PowerFlow/MiniGrid/MiniGrid.hpp b/GridKit/Model/PowerFlow/MiniGrid/MiniGrid.hpp index 7c8fb5132..5065242da 100644 --- a/GridKit/Model/PowerFlow/MiniGrid/MiniGrid.hpp +++ b/GridKit/Model/PowerFlow/MiniGrid/MiniGrid.hpp @@ -10,18 +10,20 @@ namespace GridKit * @brief Implementation of a power grid. * */ - template - class MiniGrid : public ModelEvaluatorImpl + template + class MiniGrid : public ModelEvaluatorImpl { - using ModelEvaluatorImpl::size_; - using ModelEvaluatorImpl::nnz_; - using ModelEvaluatorImpl::time_; - using ModelEvaluatorImpl::y_; - using ModelEvaluatorImpl::f_; - - using RealT = typename ModelEvaluatorImpl::RealT; + using ModelEvaluatorImpl::size_; + using ModelEvaluatorImpl::nnz_; + using ModelEvaluatorImpl::time_; + using ModelEvaluatorImpl::y_; + using ModelEvaluatorImpl::f_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename ModelEvaluatorImpl::RealT; + MiniGrid(); virtual ~MiniGrid(); diff --git a/GridKit/Model/PowerFlow/ModelEvaluatorImpl.hpp b/GridKit/Model/PowerFlow/ModelEvaluatorImpl.hpp index cc7123e2e..d5153c214 100644 --- a/GridKit/Model/PowerFlow/ModelEvaluatorImpl.hpp +++ b/GridKit/Model/PowerFlow/ModelEvaluatorImpl.hpp @@ -12,10 +12,12 @@ namespace GridKit * @brief Model implementation base class. * */ - template - class ModelEvaluatorImpl : public Model::Evaluator + template + class ModelEvaluatorImpl : public Model::Evaluator { public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename Model::Evaluator::RealT; using VectorT = typename Model::Evaluator::VectorT; diff --git a/GridKit/Model/PowerFlow/PowerFlowData.hpp b/GridKit/Model/PowerFlow/PowerFlowData.hpp index 2c674a7a6..8914a02d5 100644 --- a/GridKit/Model/PowerFlow/PowerFlowData.hpp +++ b/GridKit/Model/PowerFlow/PowerFlowData.hpp @@ -20,9 +20,12 @@ namespace GridKit namespace PowerFlowData { - template + template struct BusData { + using RealT = real_type; + using IdxT = index_type; + IdxT bus_i; ///< Bus ID IdxT type; ///< Bus type: 1 = PQ, 2 = PV, 3 = ref, 4 = isolated RealT Gs; ///< Shunt conductance (MW demanded at V = 1.0 p.u.) @@ -54,9 +57,12 @@ namespace GridKit } }; - template + template struct LoadData { + using RealT = real_type; + using IdxT = index_type; + IdxT bus_i; ///< Bus ID RealT Pd; ///< Active power demand [MW] RealT Qd; ///< Reactive power demand [MVAr] @@ -72,9 +78,12 @@ namespace GridKit } }; - template + template struct GenData { + using RealT = real_type; + using IdxT = index_type; + IdxT bus; ///< Bus ID RealT Pg; ///< Active power output [MW] RealT Qg; ///< Reactive power output [MVAr] @@ -126,9 +135,12 @@ namespace GridKit } }; - template + template struct BranchData { + using RealT = real_type; + using IdxT = index_type; + IdxT fbus; ///< "From" bus ID IdxT tbus; ///< "To" bus ID RealT r; ///< Resistance (p.u.) @@ -164,9 +176,12 @@ namespace GridKit } }; - template + template struct GenCostData { + using RealT = real_type; + using IdxT = index_type; + IdxT kind; IdxT startup; IdxT shutdown; @@ -187,9 +202,11 @@ namespace GridKit } }; - template + template struct SystemModelData { + using RealT = real_type; + using IdxT = index_type; using BusDataT = BusData; using GenDataT = GenData; using BranchDataT = BranchData; diff --git a/GridKit/Model/PowerFlow/SystemModel.hpp b/GridKit/Model/PowerFlow/SystemModel.hpp index 586dde1c4..6b5723845 100644 --- a/GridKit/Model/PowerFlow/SystemModel.hpp +++ b/GridKit/Model/PowerFlow/SystemModel.hpp @@ -21,35 +21,37 @@ namespace GridKit * @todo Address thread safety for the system model methods. * */ - template - class SystemModel : public ModelEvaluatorImpl + template + class SystemModel : public ModelEvaluatorImpl { - using bus_type = Model::Evaluator; - using component_type = Model::Evaluator; - using RealT = typename ModelEvaluatorImpl::RealT; - using VectorT = typename ModelEvaluatorImpl::VectorT; - - using ModelEvaluatorImpl::size_; - using ModelEvaluatorImpl::size_quad_; - using ModelEvaluatorImpl::size_opt_; - using ModelEvaluatorImpl::nnz_; - using ModelEvaluatorImpl::time_; - using ModelEvaluatorImpl::alpha_; - using ModelEvaluatorImpl::y_; - using ModelEvaluatorImpl::yp_; - using ModelEvaluatorImpl::yB_; - using ModelEvaluatorImpl::ypB_; - using ModelEvaluatorImpl::tag_; - using ModelEvaluatorImpl::abs_tol_; - using ModelEvaluatorImpl::f_; - using ModelEvaluatorImpl::fB_; - using ModelEvaluatorImpl::g_; - using ModelEvaluatorImpl::gB_; - using ModelEvaluatorImpl::param_; - using ModelEvaluatorImpl::param_up_; - using ModelEvaluatorImpl::param_lo_; + using ModelEvaluatorImpl::size_; + using ModelEvaluatorImpl::size_quad_; + using ModelEvaluatorImpl::size_opt_; + using ModelEvaluatorImpl::nnz_; + using ModelEvaluatorImpl::time_; + using ModelEvaluatorImpl::alpha_; + using ModelEvaluatorImpl::y_; + using ModelEvaluatorImpl::yp_; + using ModelEvaluatorImpl::yB_; + using ModelEvaluatorImpl::ypB_; + using ModelEvaluatorImpl::tag_; + using ModelEvaluatorImpl::f_; + using ModelEvaluatorImpl::fB_; + using ModelEvaluatorImpl::g_; + using ModelEvaluatorImpl::gB_; + using ModelEvaluatorImpl::abs_tol_; + using ModelEvaluatorImpl::param_; + using ModelEvaluatorImpl::param_up_; + using ModelEvaluatorImpl::param_lo_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename ModelEvaluatorImpl::RealT; + using BusT = Model::Evaluator; + using ComponentT = Model::Evaluator; + using VectorT = typename ModelEvaluatorImpl::VectorT; + /** * @brief Constructor for the system model */ @@ -992,19 +994,19 @@ namespace GridKit } } - void addBus(bus_type* bus) + void addBus(BusT* bus) { buses_.push_back(bus); } - void addComponent(component_type* component) + void addComponent(ComponentT* component) { components_.push_back(component); } private: - std::vector buses_; - std::vector components_; + std::vector buses_; + std::vector components_; }; // class SystemModel diff --git a/GridKit/Model/PowerFlow/SystemModelPowerFlow.hpp b/GridKit/Model/PowerFlow/SystemModelPowerFlow.hpp index 4a938151e..f9253f0df 100644 --- a/GridKit/Model/PowerFlow/SystemModelPowerFlow.hpp +++ b/GridKit/Model/PowerFlow/SystemModelPowerFlow.hpp @@ -30,34 +30,36 @@ namespace GridKit * @todo Tolerance management needs to be reconsidered. * */ - template - class SystemSteadyStateModel : public ModelEvaluatorImpl + template + class SystemSteadyStateModel : public ModelEvaluatorImpl { - using bus_type = BaseBus; - using component_type = ModelEvaluatorImpl; - using RealT = typename ModelEvaluatorImpl::RealT; - - using ModelEvaluatorImpl::size_; - // using ModelEvaluatorImpl::size_quad_; - // using ModelEvaluatorImpl::size_opt_; - using ModelEvaluatorImpl::nnz_; - // using ModelEvaluatorImpl::time_; - // using ModelEvaluatorImpl::alpha_; - using ModelEvaluatorImpl::y_; - // using ModelEvaluatorImpl::yp_; - // using ModelEvaluatorImpl::yB_; - // using ModelEvaluatorImpl::ypB_; - using ModelEvaluatorImpl::tag_; - using ModelEvaluatorImpl::abs_tol_; - using ModelEvaluatorImpl::f_; - // using ModelEvaluatorImpl::fB_; - // using ModelEvaluatorImpl::g_; - // using ModelEvaluatorImpl::gB_; - // using ModelEvaluatorImpl::param_; - // using ModelEvaluatorImpl::param_up_; - // using ModelEvaluatorImpl::param_lo_; + using ModelEvaluatorImpl::size_; + // using ModelEvaluatorImpl::size_quad_; + // using ModelEvaluatorImpl::size_opt_; + using ModelEvaluatorImpl::nnz_; + // using ModelEvaluatorImpl::time_; + // using ModelEvaluatorImpl::alpha_; + using ModelEvaluatorImpl::y_; + // using ModelEvaluatorImpl::yp_; + // using ModelEvaluatorImpl::yB_; + // using ModelEvaluatorImpl::ypB_; + using ModelEvaluatorImpl::tag_; + using ModelEvaluatorImpl::f_; + // using ModelEvaluatorImpl::fB_; + // using ModelEvaluatorImpl::g_; + // using ModelEvaluatorImpl::gB_; + using ModelEvaluatorImpl::abs_tol_; + // using ModelEvaluatorImpl::param_; + // using ModelEvaluatorImpl::param_up_; + // using ModelEvaluatorImpl::param_lo_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename ModelEvaluatorImpl::RealT; + using BusT = BaseBus; + using ComponentT = ModelEvaluatorImpl; + /** * @brief Constructor for the system model */ @@ -402,17 +404,17 @@ namespace GridKit { } - void addBus(bus_type* bus) + void addBus(BusT* bus) { buses_.push_back(bus); } - void addComponent(component_type* component) + void addComponent(ComponentT* component) { components_.push_back(component); } - bus_type* getBus(IdxT busid) + BusT* getBus(IdxT busid) { // Need to implement mapping of bus IDs to buses in the system model assert((buses_[busid - 1])->BusID() == busid); @@ -420,8 +422,8 @@ namespace GridKit } private: - std::vector buses_; - std::vector components_; + std::vector buses_; + std::vector components_; }; // class SystemSteadyStateModel diff --git a/GridKit/Model/VariableMonitor.hpp b/GridKit/Model/VariableMonitor.hpp index 4c8a6fce9..a07c33ef2 100644 --- a/GridKit/Model/VariableMonitor.hpp +++ b/GridKit/Model/VariableMonitor.hpp @@ -28,12 +28,12 @@ namespace GridKit namespace VariableMonitorDetail { - template - std::string formatReal(RealT value) + template + std::string formatReal(real_type value) { - std::array buffer{}; - constexpr auto precision = std::numeric_limits::digits10 + 1; + constexpr auto precision = std::numeric_limits::digits10 + 1; + std::array buffer{}; auto [ptr, ec] = std::to_chars(buffer.data(), buffer.data() + buffer.size(), value, diff --git a/GridKit/Model/VariableMonitorController.hpp b/GridKit/Model/VariableMonitorController.hpp index bac4ce084..ed604aad1 100644 --- a/GridKit/Model/VariableMonitorController.hpp +++ b/GridKit/Model/VariableMonitorController.hpp @@ -130,8 +130,8 @@ namespace GridKit /** * @brief Organize header output for this and all submonitors */ - template - void printFullHeader(std::ostream& os, FormatT fmt) const + template + void printFullHeader(std::ostream& os, format_type fmt) const { buffer_.clear(); appendHeader(buffer_, fmt); @@ -155,8 +155,8 @@ namespace GridKit /** * @brief Organize variable output for this and all submonitors */ - template - void printFull(std::ostream& os, FormatT fmt) const + template + void printFull(std::ostream& os, format_type fmt) const { buffer_.clear(); append(buffer_, fmt); @@ -186,8 +186,8 @@ namespace GridKit /** * @brief Organize footer output for this and all submonitors */ - template - void printFullFooter(std::ostream& os, FormatT fmt) const + template + void printFullFooter(std::ostream& os, format_type fmt) const { buffer_.clear(); appendFooter(buffer_, fmt); @@ -414,8 +414,8 @@ namespace GridKit FormatT format; }; - template - Sink(ArgT&&, FormatT) -> Sink; + template + Sink(arg_type&&, format_type) -> Sink; /// Variant type for all possible sink types using SinkVariant = std::variant, Sink, Sink>; diff --git a/GridKit/Model/VariableMonitorImpl.hpp b/GridKit/Model/VariableMonitorImpl.hpp index 682692c3c..470234769 100644 --- a/GridKit/Model/VariableMonitorImpl.hpp +++ b/GridKit/Model/VariableMonitorImpl.hpp @@ -98,8 +98,8 @@ namespace GridKit * @note This does not designate the variable for printing. It defines how * to get the variable if it is printed. */ - template - void set(VariableEnum v, FuncT f) + template + void set(VariableEnum v, func_type f) { f_[static_cast(enum_integer(v))] = ValueFormatter{f}; } @@ -109,9 +109,11 @@ namespace GridKit /** * @brief Functors to handle printing different types */ - template + template struct ValueFormatterImpl { + using FuncT = func_type; + FuncT f; std::string operator()() const @@ -130,18 +132,18 @@ namespace GridKit } }; - template + template using ValueFormatterType = - ValueFormatterImpl>; + ValueFormatterImpl>; class ValueFormatter { public: ValueFormatter() = default; - template - ValueFormatter(FuncT f) - : impl_{ValueFormatterType{f}} + template + ValueFormatter(func_type f) + : impl_{ValueFormatterType{f}} { } diff --git a/GridKit/ScalarTraits.hpp b/GridKit/ScalarTraits.hpp index d8ef9e2f9..8d870bc69 100644 --- a/GridKit/ScalarTraits.hpp +++ b/GridKit/ScalarTraits.hpp @@ -3,7 +3,7 @@ namespace GridKit { - template + template class ScalarTraits { }; diff --git a/GridKit/Solver/Dynamic/DynamicSolver.hpp b/GridKit/Solver/Dynamic/DynamicSolver.hpp index 147f58f78..cda9a2003 100644 --- a/GridKit/Solver/Dynamic/DynamicSolver.hpp +++ b/GridKit/Solver/Dynamic/DynamicSolver.hpp @@ -5,10 +5,13 @@ namespace AnalysisManager { - template + template class DynamicSolver { public: + using ScalarT = scalar_type; + using IdxT = index_type; + DynamicSolver(GridKit::Model::Evaluator* model) : model_(model) { diff --git a/GridKit/Solver/Dynamic/Ida.cpp b/GridKit/Solver/Dynamic/Ida.cpp index cce34900d..e2690da59 100644 --- a/GridKit/Solver/Dynamic/Ida.cpp +++ b/GridKit/Solver/Dynamic/Ida.cpp @@ -19,8 +19,8 @@ namespace AnalysisManager namespace Sundials { - template - Ida::Ida(GridKit::Model::Evaluator* model) + template + Ida::Ida(GridKit::Model::Evaluator* model) : DynamicSolver(model) { int retval = 0; @@ -36,11 +36,11 @@ namespace AnalysisManager * * @note if sysmodel is freed before this will fail. May want something agnostic to this * - * @tparam ScalarT - * @tparam IdxT + * @tparam scalar_type + * @tparam index_type */ - template - Ida::~Ida() + template + Ida::~Ida() { deleteQuadrature(); deleteAdjoint(); @@ -51,12 +51,9 @@ namespace AnalysisManager /** * @brief Configure the simulation - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::configureSimulation() + template + int Ida::configureSimulation() { int retval = 0; @@ -106,12 +103,9 @@ namespace AnalysisManager * * @note This currently uses pre-processor directives to set dense or sparse * linear solvers - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::configureLinearSolver() + template + int Ida::configureLinearSolver() { int retval = 0; @@ -143,12 +137,9 @@ namespace AnalysisManager * @brief Configure a sparse linear solver * * @note This method is only available if SUNDIALS is configured with KLU - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::configureLinearSolverSparse() + template + int Ida::configureLinearSolverSparse() { int retval = 0; @@ -177,12 +168,9 @@ namespace AnalysisManager /** * @brief Configure a dense linear solver - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::configureLinearSolverDense() + template + int Ida::configureLinearSolverDense() { int retval = 0; @@ -202,12 +190,9 @@ namespace AnalysisManager /** * @brief Get default initial condition - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::getDefaultInitialCondition() + template + int Ida::getDefaultInitialCondition() { model_->initialize(); @@ -219,12 +204,9 @@ namespace AnalysisManager /** * @brief Initialize the simulation - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::initializeSimulation(RealT t0, bool findConsistent) + template + int Ida::initializeSimulation(RealT t0, bool findConsistent) { int retval = 0; @@ -262,8 +244,8 @@ namespace AnalysisManager * the final interval is epsilon-sized, it is folded into the previous * monitor step. */ - template - int Ida::getMonitorStepCount(RealT tf, RealT dt_monitor) const + template + int Ida::getMonitorStepCount(RealT tf, RealT dt_monitor) const { if (dt_monitor <= 0.0) { @@ -283,8 +265,8 @@ namespace AnalysisManager * The final monitor target is pinned exactly to `tf` to avoid roundoff in * repeated time-step arithmetic. */ - template - typename Ida::RealT Ida::getMonitorTime(RealT tf, RealT dt_monitor, int step, int nsteps) const + template + typename Ida::RealT Ida::getMonitorTime(RealT tf, RealT dt_monitor, int step, int nsteps) const { return step == nsteps ? tf : std::fma((RealT) step, dt_monitor, t_init_); } @@ -292,8 +274,8 @@ namespace AnalysisManager /** * @brief Copy the current IDA solution vectors into the model and set time. */ - template - void Ida::updateModelState(RealT t) + template + void Ida::updateModelState(RealT t) { copyVec(yy_, model_->y()); copyVec(yp_, model_->yp()); @@ -306,8 +288,8 @@ namespace AnalysisManager * When `dt_monitor` is zero, the simulation runs directly to the final * time. The final time is always solved and monitored. */ - template - int Ida::runSimulation(RealT tf, RealT dt_monitor, const std::optional> step_callback) + template + int Ida::runSimulation(RealT tf, RealT dt_monitor, const std::optional> step_callback) { int retval = 0; int nsteps = getMonitorStepCount(tf, dt_monitor); @@ -344,12 +326,9 @@ namespace AnalysisManager /** * @brief Delete the simulation - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::deleteSimulation() + template + int Ida::deleteSimulation() { N_VDestroy(yy_); N_VDestroy(yp_); @@ -364,12 +343,9 @@ namespace AnalysisManager /** * @brief Configure quadrature - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::configureQuadrature() + template + int Ida::configureQuadrature() { int retval = 0; @@ -393,12 +369,9 @@ namespace AnalysisManager /** * @brief Initialize quadrature - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::initializeQuadrature() + template + int Ida::initializeQuadrature() { int retval = 0; @@ -418,8 +391,8 @@ namespace AnalysisManager * When `dt_monitor` is zero, the simulation runs directly to the final * time. The final time is always solved. */ - template - int Ida::runSimulationQuadrature(RealT tf, RealT dt_monitor) + template + int Ida::runSimulationQuadrature(RealT tf, RealT dt_monitor) { int retval = 0; int nsteps = getMonitorStepCount(tf, dt_monitor); @@ -448,12 +421,9 @@ namespace AnalysisManager /** * @brief Delete quadrature - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::deleteQuadrature() + template + int Ida::deleteQuadrature() { IDAQuadFree(solver_); N_VDestroy(q_); @@ -463,12 +433,9 @@ namespace AnalysisManager /** * @brief Configure adjoint - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::configureAdjoint() + template + int Ida::configureAdjoint() { // Allocate adjoint vector, derivatives and quadrature yyB_ = N_VNew_Serial(static_cast(model_->size()), context_); @@ -485,12 +452,9 @@ namespace AnalysisManager /** * @brief Initialize adjoint - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::initializeAdjoint(IdxT steps) + template + int Ida::initializeAdjoint(IdxT steps) { int retval = 0; @@ -503,12 +467,9 @@ namespace AnalysisManager /** * @brief Initialize backward simulation - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::initializeBackwardSimulation(RealT tf) + template + int Ida::initializeBackwardSimulation(RealT tf) { int retval = 0; @@ -572,12 +533,9 @@ namespace AnalysisManager * @brief Configure linear solver for backward simulation * * @note This only supports dense linear solvers at the moment - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::configureLinearSolverBackward() + template + int Ida::configureLinearSolverBackward() { int retval = 0; @@ -604,8 +562,8 @@ namespace AnalysisManager * When `dt_monitor` is zero, the simulation runs directly to the final * time. The final time is always solved. */ - template - int Ida::runForwardSimulation(RealT tf, RealT dt_monitor) + template + int Ida::runForwardSimulation(RealT tf, RealT dt_monitor) { int retval = 0; int ncheck; @@ -635,12 +593,9 @@ namespace AnalysisManager /** * @brief Run backward simulation - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::runBackwardSimulation(RealT t_init) + template + int Ida::runBackwardSimulation(RealT t_init) { int retval = 0; long int nstB; @@ -669,12 +624,9 @@ namespace AnalysisManager /** * @brief Delete adjoint - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::deleteAdjoint() + template + int Ida::deleteAdjoint() { IDAAdjFree(solver_); return 0; @@ -682,12 +634,9 @@ namespace AnalysisManager /** * @brief Delete backward simulation - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::deleteBackwardSimulation() + template + int Ida::deleteBackwardSimulation() { N_VDestroy(yyB_); N_VDestroy(ypB_); @@ -700,12 +649,9 @@ namespace AnalysisManager /** * @brief Residual evaluation - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::Residual(RealT tres, N_Vector yy, N_Vector yp, N_Vector rr, void* user_data) + template + int Ida::Residual(RealT tres, N_Vector yy, N_Vector yp, N_Vector rr, void* user_data) { GridKit::Model::Evaluator* model = static_cast*>(user_data); @@ -723,12 +669,9 @@ namespace AnalysisManager * @brief Jacobian evaluation * * @note The model Jacobian is stored in CSR format. - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::Jac(RealT t, RealT cj, N_Vector yy, N_Vector yp, N_Vector, SUNMatrix J, void* user_data, N_Vector, N_Vector, N_Vector) + template + int Ida::Jac(RealT t, RealT cj, N_Vector yy, N_Vector yp, N_Vector, SUNMatrix J, void* user_data, N_Vector, N_Vector, N_Vector) { GridKit::Model::Evaluator* model = static_cast*>(user_data); @@ -765,12 +708,9 @@ namespace AnalysisManager /** * @brief Integrand evaluation - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::Integrand(RealT tt, N_Vector yy, N_Vector yp, N_Vector rhsQ, void* user_data) + template + int Ida::Integrand(RealT tt, N_Vector yy, N_Vector yp, N_Vector rhsQ, void* user_data) { GridKit::Model::Evaluator* model = static_cast*>(user_data); @@ -786,12 +726,9 @@ namespace AnalysisManager /** * @brief Adjoint residual evaluation - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::adjointResidual(RealT tt, N_Vector yy, N_Vector yp, N_Vector yyB, N_Vector ypB, N_Vector rrB, void* user_data) + template + int Ida::adjointResidual(RealT tt, N_Vector yy, N_Vector yp, N_Vector yyB, N_Vector ypB, N_Vector rrB, void* user_data) { GridKit::Model::Evaluator* model = static_cast*>(user_data); @@ -809,12 +746,9 @@ namespace AnalysisManager /** * @brief Adjoint integrand evaluation - * - * @tparam ScalarT - * @tparam IdxT */ - template - int Ida::adjointIntegrand(RealT tt, N_Vector yy, N_Vector yp, N_Vector yyB, N_Vector ypB, N_Vector rhsQB, void* user_data) + template + int Ida::adjointIntegrand(RealT tt, N_Vector yy, N_Vector yp, N_Vector yyB, N_Vector ypB, N_Vector rhsQB, void* user_data) { GridKit::Model::Evaluator* model = static_cast*>(user_data); @@ -832,12 +766,9 @@ namespace AnalysisManager /** * @brief Copy SUNDIALS N_Vector to Vector - * - * @tparam ScalarT - * @tparam IdxT */ - template - void Ida::copyVec(const N_Vector x, VectorT& y) + template + void Ida::copyVec(const N_Vector x, VectorT& y) { const auto xsize = static_cast(N_VGetLength(x)); const auto ysize = static_cast(y.getSize()); @@ -855,12 +786,9 @@ namespace AnalysisManager /** * @brief Copy Vector to SUNDIALS N_Vector - * - * @tparam ScalarT - * @tparam IdxT */ - template - void Ida::copyVec(const VectorT& x, N_Vector y) + template + void Ida::copyVec(const VectorT& x, N_Vector y) { const auto ysize = static_cast(N_VGetLength(y)); const auto xsize = static_cast(x.getSize()); @@ -878,12 +806,9 @@ namespace AnalysisManager /** * @brief Copy std::vector to SUNDIALS N_Vector - * - * @tparam ScalarT - * @tparam IdxT */ - template - void Ida::copyVec(const std::vector& x, N_Vector y) + template + void Ida::copyVec(const std::vector& x, N_Vector y) { const auto ysize = static_cast(N_VGetLength(y)); if (x.size() != ysize) @@ -899,12 +824,9 @@ namespace AnalysisManager /** * @brief Print output - * - * @tparam ScalarT - * @tparam IdxT */ - template - void Ida::printOutput(RealT t) const + template + void Ida::printOutput(RealT t) const { RealT* yval = N_VGetArrayPointer(yy_); RealT* ypval = N_VGetArrayPointer(yp_); @@ -923,12 +845,9 @@ namespace AnalysisManager /** * @brief Special print - * - * @tparam ScalarT - * @tparam IdxT */ - template - void Ida::printSpecial(RealT t, N_Vector y) const + template + void Ida::printSpecial(RealT t, N_Vector y) const { RealT* yval = N_VGetArrayPointer(y); IdxT N = static_cast(N_VGetLength(y)); @@ -943,12 +862,9 @@ namespace AnalysisManager /** * @brief Print final stats - * - * @tparam ScalarT - * @tparam IdxT */ - template - void Ida::printFinalStats() const + template + void Ida::printFinalStats() const { int retval = IDAPrintAllStats(solver_, stdout, SUN_OUTPUTFORMAT_TABLE); checkOutput(retval, "IDAPrintAllStats"); @@ -996,8 +912,8 @@ namespace AnalysisManager * Several statistics returned by IDA are ignored because they are about the current state of IDA, * rather than about the simulation at large. */ - template - IdaStats Ida::getStats() const + template + IdaStats Ida::getStats() const { IdaStats stats; @@ -1026,12 +942,9 @@ namespace AnalysisManager /** * @brief Check SUNDIALS allocation - * - * @tparam ScalarT - * @tparam IdxT */ - template - void Ida::checkAllocation(void* v, const char* functionName) + template + void Ida::checkAllocation(void* v, const char* functionName) { if (v == NULL) { @@ -1042,12 +955,9 @@ namespace AnalysisManager /** * @brief Check SUNDIALS output - * - * @tparam ScalarT - * @tparam IdxT */ - template - void Ida::checkOutput(int retval, const char* functionName) + template + void Ida::checkOutput(int retval, const char* functionName) { if (retval < 0) { @@ -1060,11 +970,9 @@ namespace AnalysisManager * @brief Set fixed step size and tolerances for the nonlinear solver * * @param time_step The fixed step size to use or 0 for adaptive - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setFixedStep(ScalarT time_step) + template + void Ida::setFixedStep(ScalarT time_step) { time_step_ = time_step; } @@ -1074,11 +982,9 @@ namespace AnalysisManager * the backward simulation * * @param time_step The fixed step size to use or 0 for adaptive - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setBackwardFixedStep(ScalarT time_step) + template + void Ida::setBackwardFixedStep(ScalarT time_step) { backward_time_step_ = time_step; } @@ -1091,12 +997,10 @@ namespace AnalysisManager * @param abs_tol_override If positive, this value will be used as the * absolute tolerance rather than the model's default absolute * tolerance - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setTolerance(ScalarT rel_tol, - ScalarT abs_tol_override) + template + void Ida::setTolerance(ScalarT rel_tol, + ScalarT abs_tol_override) { rel_tol_ = rel_tol; abs_tol_override_ = abs_tol_override; @@ -1110,12 +1014,10 @@ namespace AnalysisManager * @param abs_tol_override If positive, this value will be used as the * absolute tolerance rather than the model's default absolute * tolerance - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setBackwardTolerance(ScalarT rel_tol, - ScalarT abs_tol_override) + template + void Ida::setBackwardTolerance(ScalarT rel_tol, + ScalarT abs_tol_override) { backward_rel_tol_ = rel_tol; backward_abs_tol_override_ = abs_tol_override; @@ -1129,12 +1031,10 @@ namespace AnalysisManager * @param abs_tol_override If positive, this value will be used as the * absolute tolerance rather than the model's default absolute * tolerance - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setQuadratureTolerance(ScalarT rel_tol, - ScalarT abs_tol_override) + template + void Ida::setQuadratureTolerance(ScalarT rel_tol, + ScalarT abs_tol_override) { quadrature_rel_tol_ = rel_tol; quadrature_abs_tol_override_ = abs_tol_override; @@ -1148,12 +1048,10 @@ namespace AnalysisManager * @param abs_tol_override If positive, this value will be used as the * absolute tolerance rather than the model's default absolute * tolerance - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setBackwardQuadratureTolerance(ScalarT rel_tol, - ScalarT abs_tol_override) + template + void Ida::setBackwardQuadratureTolerance(ScalarT rel_tol, + ScalarT abs_tol_override) { backward_quadrature_rel_tol_ = rel_tol; backward_quadrature_abs_tol_override_ = abs_tol_override; @@ -1164,11 +1062,9 @@ namespace AnalysisManager * * @param suppress If true, algebraic variables are excluded from IDA's * local error test - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setSuppressAlgebraicErrors(bool suppress) + template + void Ida::setSuppressAlgebraicErrors(bool suppress) { suppress_alg_ = suppress; } @@ -1179,11 +1075,9 @@ namespace AnalysisManager * * @param suppress If true, algebraic variables are excluded from IDA's * local error test - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setBackwardSuppressAlgebraicErrors(bool suppress) + template + void Ida::setBackwardSuppressAlgebraicErrors(bool suppress) { backward_suppress_alg_ = suppress; } @@ -1192,11 +1086,9 @@ namespace AnalysisManager * @brief Set the maximum number of steps * * @param max_steps The maximum number of steps - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setMaxSteps(IdxT max_steps) + template + void Ida::setMaxSteps(IdxT max_steps) { max_steps_ = max_steps; } @@ -1205,11 +1097,9 @@ namespace AnalysisManager * @brief Set the maximum number of steps for the backward simulation * * @param max_steps The maximum number of steps - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setBackwardMaxSteps(IdxT max_steps) + template + void Ida::setBackwardMaxSteps(IdxT max_steps) { backward_max_steps_ = max_steps; } @@ -1226,16 +1116,14 @@ namespace AnalysisManager * @param max_steps The maximum number of steps * @param suppress_alg If true, algebraic variables are excluded from IDA's * local error test - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setIDAOptions(void* mem, - ScalarT time_step, - ScalarT rel_tol, - ScalarT abs_tol_override, - IdxT max_steps, - bool suppress_alg) + template + void Ida::setIDAOptions(void* mem, + ScalarT time_step, + ScalarT rel_tol, + ScalarT abs_tol_override, + IdxT max_steps, + bool suppress_alg) { int retval = 0; retval = IDASetMinStep(mem, time_step); @@ -1290,14 +1178,12 @@ namespace AnalysisManager * tolerance * @param abs_tol_fac A factor to apply to the absolute tolerance if not * overridden - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setTolerance(void* mem, - ScalarT rel_tol, - ScalarT abs_tol_override, - ScalarT abs_tol_fac) + template + void Ida::setTolerance(void* mem, + ScalarT rel_tol, + ScalarT abs_tol_override, + ScalarT abs_tol_fac) { int retval = 0; @@ -1331,13 +1217,11 @@ namespace AnalysisManager * tolerance * @param abs_tol_fac A factor to apply to the absolute tolerance if not * overridden - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - void Ida::setQuadratureTolerance(void* mem, - ScalarT rel_tol, - ScalarT abs_tol_override) + template + void Ida::setQuadratureTolerance(void* mem, + ScalarT rel_tol, + ScalarT abs_tol_override) { int retval = 0; diff --git a/GridKit/Solver/Dynamic/Ida.hpp b/GridKit/Solver/Dynamic/Ida.hpp index bbe87f8df..63cc38828 100644 --- a/GridKit/Solver/Dynamic/Ida.hpp +++ b/GridKit/Solver/Dynamic/Ida.hpp @@ -40,16 +40,18 @@ namespace AnalysisManager std::string report() const; }; - template - class Ida : public DynamicSolver + template + class Ida : public DynamicSolver { - using DynamicSolver::model_; + using DynamicSolver::model_; + public: + using ScalarT = scalar_type; + using IdxT = index_type; using EvaluatorT = GridKit::Model::Evaluator; using RealT = typename GridKit::ScalarTraits::RealT; using VectorT = typename EvaluatorT::VectorT; - public: Ida(GridKit::Model::Evaluator* model); ~Ida(); diff --git a/GridKit/Solver/Dynamic/Native/AdaptiveStep.cpp b/GridKit/Solver/Dynamic/Native/AdaptiveStep.cpp index 23cc0f306..5cdb74e2d 100644 --- a/GridKit/Solver/Dynamic/Native/AdaptiveStep.cpp +++ b/GridKit/Solver/Dynamic/Native/AdaptiveStep.cpp @@ -15,8 +15,8 @@ namespace AnalysisManager * \f[h_{new} = h * \min \left\{fac_{max}, \max\left\{fac_{min}, fac_{scale} \cdot e ^{-1/p}\right\}\right\}.\f] * */ - template - StepControl AdaptiveStep::nextStep(RealT err, StepControl prev_step, uint8_t method_order) + template + StepControl AdaptiveStep::nextStep(RealT err, StepControl prev_step, uint8_t method_order) { StepControl next_step = prev_step; diff --git a/GridKit/Solver/Dynamic/Native/AdaptiveStep.hpp b/GridKit/Solver/Dynamic/Native/AdaptiveStep.hpp index 11740696b..8666ec295 100644 --- a/GridKit/Solver/Dynamic/Native/AdaptiveStep.hpp +++ b/GridKit/Solver/Dynamic/Native/AdaptiveStep.hpp @@ -12,9 +12,13 @@ namespace AnalysisManager * based on an error estimate. * */ - template - class AdaptiveStep : public StepController + template + class AdaptiveStep : public StepController { + public: + using RealT = real_type; + + private: /** * @brief Parameters for the step controller. * diff --git a/GridKit/Solver/Dynamic/Native/ErrorNorm.hpp b/GridKit/Solver/Dynamic/Native/ErrorNorm.hpp index 279e9255f..ef0acfa7c 100644 --- a/GridKit/Solver/Dynamic/Native/ErrorNorm.hpp +++ b/GridKit/Solver/Dynamic/Native/ErrorNorm.hpp @@ -12,13 +12,15 @@ namespace AnalysisManager * @brief Interface for error norms. Used to calculate the `err` parameter in `StepController::nextStep` based on a residual state error vector. * */ - template + template class ErrorNorm { - using State = GridKit::LinearAlgebra::Vector; - using RealT = typename GridKit::ScalarTraits::RealT; - public: + using ScalarT = scalar_type; + using IdxT = index_type; + using State = GridKit::LinearAlgebra::Vector; + using RealT = typename GridKit::ScalarTraits::RealT; + /** * @brief Calculate an error to be used by a step controller. Typically, an error > 1 indicates an error which does not meet tolerances, while * an error < 1 indicates an error which meets tolerances. For that reason, tolerances should be included in the calculation of the error. diff --git a/GridKit/Solver/Dynamic/Native/FixedStep.cpp b/GridKit/Solver/Dynamic/Native/FixedStep.cpp index 965627ac0..cca25cfba 100644 --- a/GridKit/Solver/Dynamic/Native/FixedStep.cpp +++ b/GridKit/Solver/Dynamic/Native/FixedStep.cpp @@ -8,8 +8,8 @@ namespace AnalysisManager * @brief Fixed step - accept every step, no matter the error, and keep the step size the same. * */ - template - StepControl FixedStep::nextStep([[maybe_unused]] RealT err, StepControl prev_step, [[maybe_unused]] uint8_t method_order) + template + StepControl FixedStep::nextStep([[maybe_unused]] RealT err, StepControl prev_step, [[maybe_unused]] uint8_t method_order) { return StepControl{ .accept_ = true, diff --git a/GridKit/Solver/Dynamic/Native/FixedStep.hpp b/GridKit/Solver/Dynamic/Native/FixedStep.hpp index 82edda6cf..91d638743 100644 --- a/GridKit/Solver/Dynamic/Native/FixedStep.hpp +++ b/GridKit/Solver/Dynamic/Native/FixedStep.hpp @@ -14,9 +14,11 @@ namespace AnalysisManager * To set the fixed size, set the `Rosenbrock::Parameters::starting_step` parameter. * */ - template - class FixedStep : public StepController + template + class FixedStep : public StepController { + using RealT = real_type; + StepControl nextStep(RealT err, StepControl prev_step, uint8_t method_order) final; /** diff --git a/GridKit/Solver/Dynamic/Native/InfNorm.cpp b/GridKit/Solver/Dynamic/Native/InfNorm.cpp index f1edc419e..608286cd3 100644 --- a/GridKit/Solver/Dynamic/Native/InfNorm.cpp +++ b/GridKit/Solver/Dynamic/Native/InfNorm.cpp @@ -23,8 +23,9 @@ namespace AnalysisManager * @param memspace The memory space to be used for performing linear lagebra operations. * @see `Rosenbrock::errorEstimate()` */ - template - InfNorm::RealT InfNorm::errorNorm(State& err, State& y, State& yprev, GridKit::LinearAlgebra::VectorHandler& handler, GridKit::memory::MemorySpace memspace) const + template + InfNorm::RealT InfNorm::errorNorm( + State& err, State& y, State& yprev, GridKit::LinearAlgebra::VectorHandler& handler, GridKit::memory::MemorySpace memspace) const { if (int err_code = workspace_.out_->copyFromExternal(&err, memspace, memspace)) { diff --git a/GridKit/Solver/Dynamic/Native/InfNorm.hpp b/GridKit/Solver/Dynamic/Native/InfNorm.hpp index 6cc7a39a3..7d879f528 100644 --- a/GridKit/Solver/Dynamic/Native/InfNorm.hpp +++ b/GridKit/Solver/Dynamic/Native/InfNorm.hpp @@ -15,12 +15,16 @@ namespace AnalysisManager * to meet tolerance. * */ - template - class InfNorm : public ErrorNorm + template + class InfNorm : public ErrorNorm { - using State = GridKit::LinearAlgebra::Vector; - using RealT = ErrorNorm::RealT; + public: + using ScalarT = scalar_type; + using IdxT = index_type; + using State = GridKit::LinearAlgebra::Vector; + using RealT = ErrorNorm::RealT; + private: /** * @brief A workspace for the linear algebra operations required to calculate the norm. * diff --git a/GridKit/Solver/Dynamic/Native/StepControl.hpp b/GridKit/Solver/Dynamic/Native/StepControl.hpp index 5dc678a4c..21c87f28f 100644 --- a/GridKit/Solver/Dynamic/Native/StepControl.hpp +++ b/GridKit/Solver/Dynamic/Native/StepControl.hpp @@ -8,15 +8,18 @@ namespace AnalysisManager * @brief Define control flow for `StepController`s to be able to control the step size of a `Rosenbrock` integrator. * */ - template + template struct StepControl { + using RealT = real_type; + /** * @brief Whether or not the step is accepted. A rejected step will cause the time step controller to discard * the next state and re-step with the new `step_size`. * */ - bool accept_; + bool accept_; + /** * @brief The step size the next step should take. * diff --git a/GridKit/Solver/Dynamic/Native/StepController.hpp b/GridKit/Solver/Dynamic/Native/StepController.hpp index 8c8abe5f8..cb6f4dbde 100644 --- a/GridKit/Solver/Dynamic/Native/StepController.hpp +++ b/GridKit/Solver/Dynamic/Native/StepController.hpp @@ -14,10 +14,12 @@ namespace AnalysisManager * * @todo It may be best to have \ref usesError() return a reference to the \ref ErrorNorm that should be used. */ - template + template class StepController { public: + using RealT = real_type; + /** * @brief Decide the control flow for the next step, based on information gathered by the integrator about the current step. * @@ -28,11 +30,12 @@ namespace AnalysisManager * @return StepControl */ virtual StepControl nextStep(RealT err, StepControl prev_step, uint8_t method_order) = 0; + /** * @brief Return whether or not the `nextStep` method implementation uses the `err` parameter. If `false`, this parameter is not calculated. * */ - virtual bool usesError() const = 0; + virtual bool usesError() const = 0; }; } // namespace NativeDynamicSolver } // namespace AnalysisManager diff --git a/GridKit/Solver/Dynamic/Rosenbrock.cpp b/GridKit/Solver/Dynamic/Rosenbrock.cpp index 057f69b3c..9ccdf666f 100644 --- a/GridKit/Solver/Dynamic/Rosenbrock.cpp +++ b/GridKit/Solver/Dynamic/Rosenbrock.cpp @@ -32,8 +32,8 @@ namespace AnalysisManager * Useful if you would like to plot step info. * */ - template - std::string Rosenbrock::StepInfo::csvReport() const + template + std::string Rosenbrock::StepInfo::csvReport() const { std::stringstream out; out << std::scientific << std::setprecision(20) @@ -55,8 +55,8 @@ namespace AnalysisManager * Useful for debug dumps. * */ - template - std::string Rosenbrock::StepInfo::report() const + template + std::string Rosenbrock::StepInfo::report() const { std::stringstream out; out << std::scientific << std::setprecision(20) @@ -78,8 +78,8 @@ namespace AnalysisManager * Useful for reporting at the end of a simulation. * */ - template - std::string Rosenbrock::Stats::report() const + template + std::string Rosenbrock::Stats::report() const { std::stringstream out; out << "Rejections: " << rejections_.size() @@ -103,8 +103,8 @@ namespace AnalysisManager * * @todo Right now, the step numbers for \ref rejections_ and \ref skip_lu_steps_ are impossible to tell apart from the different simulations. */ - template - typename Rosenbrock::Stats& Rosenbrock::Stats::operator+=(const Stats& other) + template + typename Rosenbrock::Stats& Rosenbrock::Stats::operator+=(const Stats& other) { rejections_.insert(rejections_.end(), other.rejections_.begin(), other.rejections_.end()); skip_lu_steps_.insert(skip_lu_steps_.end(), other.skip_lu_steps_.begin(), other.skip_lu_steps_.end()); @@ -134,8 +134,8 @@ namespace AnalysisManager * * @param stage The stage being checked. */ - template - constexpr bool Rosenbrock::Tableau::canReuseAsum(size_t stage) const + template + constexpr bool Rosenbrock::Tableau::canReuseAsum(size_t stage) const { assert(stage < num_stages_); @@ -166,8 +166,8 @@ namespace AnalysisManager * Therefore, this method will return `false`. * */ - template - constexpr bool Rosenbrock::Tableau::canReuseAsumForOut() const + template + constexpr bool Rosenbrock::Tableau::canReuseAsumForOut() const { if (num_stages_ == 1) return false; @@ -193,8 +193,8 @@ namespace AnalysisManager * @pre This function is only valid to call if there is an embedded error estimator and its coefficients * are included in this tableau. */ - template - constexpr std::optional Rosenbrock::Tableau::errorEstimatorStage() const + template + constexpr std::optional Rosenbrock::Tableau::errorEstimatorStage() const { assert(e_); @@ -227,13 +227,13 @@ namespace AnalysisManager * does not need error (such as `FixedStep`), so `nullptr` can be passed in that circumstance. * @param memspace The memory space that linear algebra operations should be performed in. */ - template - Rosenbrock::Rosenbrock(Tableau&& tab, - GridKit::Model::Evaluator* model, - GridKit::LinearAlgebra::LinearSolver& lin_solver, - GridKit::LinearAlgebra::VectorHandler& vector_handler, - const ErrorNorm* err_norm, - GridKit::memory::MemorySpace memspace) + template + Rosenbrock::Rosenbrock(Tableau&& tab, + GridKit::Model::Evaluator* model, + GridKit::LinearAlgebra::LinearSolver& lin_solver, + GridKit::LinearAlgebra::VectorHandler& vector_handler, + const ErrorNorm* err_norm, + GridKit::memory::MemorySpace memspace) : tab_(std::move(tab)), model_(model), lin_solver_(lin_solver), @@ -253,8 +253,8 @@ namespace AnalysisManager * * @return An error code, with 0 as success. */ - template - int Rosenbrock::allocate() + template + int Rosenbrock::allocate() { size_t size = static_cast(model_->size()); @@ -329,8 +329,8 @@ namespace AnalysisManager * @param t0 The starting simulation time. * @return An error code, with 0 as success. */ - template - int Rosenbrock::initializeSimulation(RealT t0) + template + int Rosenbrock::initializeSimulation(RealT t0) { current_time_ = t0; BUBBLE_FAIL(y_cur_->copyFromExternal(model_->y().getData(), memspace_, memspace_)); @@ -399,12 +399,12 @@ namespace AnalysisManager * an can be queried separately by the callback if needed. Useful for debugging simulations. * @return An error code, with 0 as success. */ - template - int Rosenbrock::integrate(const std::vector& out_times, - StepController& step_controller, - Parameters params, - std::optional> out_cb, - std::optional> step_cb) + template + int Rosenbrock::integrate(const std::vector& out_times, + StepController& step_controller, + Parameters params, + std::optional> out_cb, + std::optional> step_cb) { constexpr RealT ONE = GridKit::ONE; constexpr RealT ZERO = GridKit::ZERO; @@ -637,8 +637,8 @@ namespace AnalysisManager * @param dt \f(h\f) in the above formula. The next state \f(y_1\f) will be an estimate of the state at \f(t_1 = t_0 + h\f). * @return An error code, with 0 as success. */ - template - int Rosenbrock::timeStep(RealT t0, RealT dt) + template + int Rosenbrock::timeStep(RealT t0, RealT dt) { constexpr RealT ZERO = GridKit::ZERO; constexpr RealT MINUS_ONE = GridKit::MINUS_ONE; @@ -780,8 +780,8 @@ namespace AnalysisManager * * @return A reference to the estimated error. */ - template - Rosenbrock::State& Rosenbrock::errorEstimate() const + template + Rosenbrock::State& Rosenbrock::errorEstimate() const { // Test to see if the tableau allows us to use a stage as the error estimate, // avoiding extra computation. @@ -826,8 +826,8 @@ namespace AnalysisManager * * @return An error code, with 0 as success. */ - template - int Rosenbrock::calcDenseCoeff() + template + int Rosenbrock::calcDenseCoeff() { if (tab_.order_ > 2) { @@ -876,8 +876,8 @@ namespace AnalysisManager * @param theta The fraction of time during the last step taken to calculate the interpolation at. \f(\theta = \frac{t - t_0}{h}\f) * @return An error code, with 0 as success. */ - template - int Rosenbrock::interpDense(RealT theta) + template + int Rosenbrock::interpDense(RealT theta) { constexpr RealT ONE = GridKit::ONE; diff --git a/GridKit/Solver/Dynamic/Rosenbrock.hpp b/GridKit/Solver/Dynamic/Rosenbrock.hpp index 234d94fb3..ae335d581 100644 --- a/GridKit/Solver/Dynamic/Rosenbrock.hpp +++ b/GridKit/Solver/Dynamic/Rosenbrock.hpp @@ -28,13 +28,15 @@ namespace AnalysisManager * * For the list of available Rosenbrock methods, see `Rosenbrock::Tableau`. */ - template + template class Rosenbrock { - using RealT = typename GridKit::ScalarTraits::RealT; - using State = GridKit::LinearAlgebra::Vector; - public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename GridKit::ScalarTraits::RealT; + using State = GridKit::LinearAlgebra::Vector; + /** * @brief Keeps track of a variety of notable properties of a single step. * diff --git a/GridKit/Solver/Dynamic/RosenbrockTableaus.cpp b/GridKit/Solver/Dynamic/RosenbrockTableaus.cpp index 4fd952bc2..fc7b15aab 100644 --- a/GridKit/Solver/Dynamic/RosenbrockTableaus.cpp +++ b/GridKit/Solver/Dynamic/RosenbrockTableaus.cpp @@ -4,8 +4,8 @@ namespace AnalysisManager { namespace NativeDynamicSolver { - template - Rosenbrock::Tableau Rosenbrock::Tableau::linImplicitEuler() + template + Rosenbrock::Tableau Rosenbrock::Tableau::linImplicitEuler() { constexpr size_t num_stages = 1; @@ -43,8 +43,8 @@ namespace AnalysisManager * * */ - template - Rosenbrock::Tableau Rosenbrock::Tableau::rodas5p() + template + Rosenbrock::Tableau Rosenbrock::Tableau::rodas5p() { constexpr size_t num_stages = 8; diff --git a/GridKit/Solver/Optimization/DynamicConstraint.cpp b/GridKit/Solver/Optimization/DynamicConstraint.cpp index f4fd7332c..2f7a95def 100644 --- a/GridKit/Solver/Optimization/DynamicConstraint.cpp +++ b/GridKit/Solver/Optimization/DynamicConstraint.cpp @@ -9,11 +9,11 @@ namespace AnalysisManager namespace IpoptInterface { - template - DynamicConstraint::DynamicConstraint(Sundials::Ida* integrator, - RealT t_init, - RealT t_final, - RealT dt_monitor) + template + DynamicConstraint::DynamicConstraint(Sundials::Ida* integrator, + RealT t_init, + RealT t_final, + RealT dt_monitor) : OptimizationSolver(integrator), t_init_(t_init), t_final_(t_final), @@ -22,13 +22,13 @@ namespace AnalysisManager model_ = integrator_->getModel(); } - template - DynamicConstraint::~DynamicConstraint() + template + DynamicConstraint::~DynamicConstraint() { } - template - bool DynamicConstraint::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, Index& nnz_h_lag, IndexStyleEnum& index_style) + template + bool DynamicConstraint::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, Index& nnz_h_lag, IndexStyleEnum& index_style) { // This code handles one objective function assert(model_->sizeQuadrature() == 1); @@ -52,13 +52,13 @@ namespace AnalysisManager return true; } - template - bool DynamicConstraint::get_bounds_info([[maybe_unused]] Index n, - Number* x_l, - Number* x_u, - [[maybe_unused]] Index m, - Number* g_l, - Number* g_u) + template + bool DynamicConstraint::get_bounds_info([[maybe_unused]] Index n, + Number* x_l, + Number* x_u, + [[maybe_unused]] Index m, + Number* g_l, + Number* g_u) { // Check if sizes are set correctly assert(n == (Index) (model_->sizeParams() + 1)); @@ -84,16 +84,16 @@ namespace AnalysisManager return true; } - template - bool DynamicConstraint::get_starting_point([[maybe_unused]] Index n, - [[maybe_unused]] bool init_x, - Number* x, - [[maybe_unused]] bool init_z, - [[maybe_unused]] Number* z_L, - [[maybe_unused]] Number* z_U, - [[maybe_unused]] Index m, - [[maybe_unused]] bool init_lambda, - [[maybe_unused]] Number* lambda) + template + bool DynamicConstraint::get_starting_point([[maybe_unused]] Index n, + [[maybe_unused]] bool init_x, + Number* x, + [[maybe_unused]] bool init_z, + [[maybe_unused]] Number* z_L, + [[maybe_unused]] Number* z_U, + [[maybe_unused]] Index m, + [[maybe_unused]] bool init_lambda, + [[maybe_unused]] Number* lambda) { // Only initial values for x provided. assert(init_x == true); @@ -111,11 +111,11 @@ namespace AnalysisManager return true; } - template - bool DynamicConstraint::eval_f([[maybe_unused]] Index n, - const Number* x, - [[maybe_unused]] bool new_x, - Number& obj_value) + template + bool DynamicConstraint::eval_f([[maybe_unused]] Index n, + const Number* x, + [[maybe_unused]] bool new_x, + Number& obj_value) { // Set objective to fictitious optimization parameter x[n-1] obj_value = x[model_->sizeParams()]; @@ -123,11 +123,11 @@ namespace AnalysisManager return true; } - template - bool DynamicConstraint::eval_grad_f([[maybe_unused]] Index n, - [[maybe_unused]] const Number* x, - [[maybe_unused]] bool new_x, - Number* grad_f) + template + bool DynamicConstraint::eval_grad_f([[maybe_unused]] Index n, + [[maybe_unused]] const Number* x, + [[maybe_unused]] bool new_x, + Number* grad_f) { // Objective function equals to the fictitious parameter x[n-1]. // Gradient, then assumes the simple form: @@ -138,12 +138,12 @@ namespace AnalysisManager return true; } - template - bool DynamicConstraint::eval_g([[maybe_unused]] Index n, - const Number* x, - [[maybe_unused]] bool new_x, - [[maybe_unused]] Index m, - Number* g) + template + bool DynamicConstraint::eval_g([[maybe_unused]] Index n, + const Number* x, + [[maybe_unused]] bool new_x, + [[maybe_unused]] Index m, + Number* g) { // Update optimization parameters auto* param = model_->param().getData(); @@ -173,15 +173,15 @@ namespace AnalysisManager return true; } - template - bool DynamicConstraint::eval_jac_g([[maybe_unused]] Index n, - const Number* x, - [[maybe_unused]] bool new_x, - [[maybe_unused]] Index m, - [[maybe_unused]] Index nele_jac, - Index* iRow, - Index* jCol, - Number* values) + template + bool DynamicConstraint::eval_jac_g([[maybe_unused]] Index n, + const Number* x, + [[maybe_unused]] bool new_x, + [[maybe_unused]] Index m, + [[maybe_unused]] Index nele_jac, + Index* iRow, + Index* jCol, + Number* values) { // Set Jacobian sparsity pattern ... if (!values) @@ -241,34 +241,34 @@ namespace AnalysisManager return true; } - template - bool DynamicConstraint::eval_h([[maybe_unused]] Index n, - [[maybe_unused]] const Number* x, - [[maybe_unused]] bool new_x, - [[maybe_unused]] Number obj_factor, - [[maybe_unused]] Index m, - [[maybe_unused]] const Number* lambda, - [[maybe_unused]] bool new_lambda, - [[maybe_unused]] Index nele_hess, - [[maybe_unused]] Index* iRow, - [[maybe_unused]] Index* jCol, - [[maybe_unused]] Number* values) + template + bool DynamicConstraint::eval_h([[maybe_unused]] Index n, + [[maybe_unused]] const Number* x, + [[maybe_unused]] bool new_x, + [[maybe_unused]] Number obj_factor, + [[maybe_unused]] Index m, + [[maybe_unused]] const Number* lambda, + [[maybe_unused]] bool new_lambda, + [[maybe_unused]] Index nele_hess, + [[maybe_unused]] Index* iRow, + [[maybe_unused]] Index* jCol, + [[maybe_unused]] Number* values) { return true; } - template - void DynamicConstraint::finalize_solution([[maybe_unused]] SolverReturn status, - [[maybe_unused]] Index n, - [[maybe_unused]] const Number* x, - [[maybe_unused]] const Number* z_L, - [[maybe_unused]] const Number* z_U, - [[maybe_unused]] Index m, - [[maybe_unused]] const Number* g, - [[maybe_unused]] const Number* lambda, - [[maybe_unused]] Number obj_value, - [[maybe_unused]] const IpoptData* ip_data, - [[maybe_unused]] IpoptCalculatedQuantities* ip_cq) + template + void DynamicConstraint::finalize_solution([[maybe_unused]] SolverReturn status, + [[maybe_unused]] Index n, + [[maybe_unused]] const Number* x, + [[maybe_unused]] const Number* z_L, + [[maybe_unused]] const Number* z_U, + [[maybe_unused]] Index m, + [[maybe_unused]] const Number* g, + [[maybe_unused]] const Number* lambda, + [[maybe_unused]] Number obj_value, + [[maybe_unused]] const IpoptData* ip_data, + [[maybe_unused]] IpoptCalculatedQuantities* ip_cq) { } diff --git a/GridKit/Solver/Optimization/DynamicConstraint.hpp b/GridKit/Solver/Optimization/DynamicConstraint.hpp index 9a2495f80..43a66809a 100644 --- a/GridKit/Solver/Optimization/DynamicConstraint.hpp +++ b/GridKit/Solver/Optimization/DynamicConstraint.hpp @@ -24,13 +24,11 @@ namespace AnalysisManager * 1-parameter optimization problems. * */ - template - class DynamicConstraint : public Ipopt::TNLP, public OptimizationSolver + template + class DynamicConstraint : public Ipopt::TNLP, public OptimizationSolver { - using OptimizationSolver::integrator_; - using OptimizationSolver::model_; - - using RealT = typename GridKit::ScalarTraits::RealT; + using OptimizationSolver::integrator_; + using OptimizationSolver::model_; using Index = Ipopt::Index; using Number = Ipopt::Number; @@ -39,6 +37,10 @@ namespace AnalysisManager using IpoptData = Ipopt::IpoptData; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename GridKit::ScalarTraits::RealT; + DynamicConstraint(Sundials::Ida* integrator, RealT t_init, RealT t_final, diff --git a/GridKit/Solver/Optimization/DynamicObjective.cpp b/GridKit/Solver/Optimization/DynamicObjective.cpp index a6f27e50a..529ce87b0 100644 --- a/GridKit/Solver/Optimization/DynamicObjective.cpp +++ b/GridKit/Solver/Optimization/DynamicObjective.cpp @@ -9,11 +9,11 @@ namespace AnalysisManager namespace IpoptInterface { - template - DynamicObjective::DynamicObjective(Sundials::Ida* integrator, - RealT t_init, - RealT t_final, - RealT dt_monitor) + template + DynamicObjective::DynamicObjective(Sundials::Ida* integrator, + RealT t_init, + RealT t_final, + RealT dt_monitor) : OptimizationSolver(integrator), t_init_(t_init), t_final_(t_final), @@ -22,13 +22,13 @@ namespace AnalysisManager model_ = integrator_->getModel(); } - template - DynamicObjective::~DynamicObjective() + template + DynamicObjective::~DynamicObjective() { } - template - bool DynamicObjective::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, Index& nnz_h_lag, IndexStyleEnum& index_style) + template + bool DynamicObjective::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, Index& nnz_h_lag, IndexStyleEnum& index_style) { // This code handles one objective function assert(model_->sizeQuadrature() == 1); @@ -51,13 +51,13 @@ namespace AnalysisManager return true; } - template - bool DynamicObjective::get_bounds_info([[maybe_unused]] Index n, - Number* x_l, - Number* x_u, - [[maybe_unused]] Index m, - [[maybe_unused]] Number* g_l, - [[maybe_unused]] Number* g_u) + template + bool DynamicObjective::get_bounds_info([[maybe_unused]] Index n, + Number* x_l, + Number* x_u, + [[maybe_unused]] Index m, + [[maybe_unused]] Number* g_l, + [[maybe_unused]] Number* g_u) { // Check if sizes are set correctly assert(n == (Index) model_->sizeParams()); @@ -75,16 +75,16 @@ namespace AnalysisManager return true; } - template - bool DynamicObjective::get_starting_point([[maybe_unused]] Index n, - [[maybe_unused]] bool init_x, - Number* x, - [[maybe_unused]] bool init_z, - [[maybe_unused]] Number* z_L, - [[maybe_unused]] Number* z_U, - [[maybe_unused]] Index m, - [[maybe_unused]] bool init_lambda, - [[maybe_unused]] Number* lambda) + template + bool DynamicObjective::get_starting_point([[maybe_unused]] Index n, + [[maybe_unused]] bool init_x, + Number* x, + [[maybe_unused]] bool init_z, + [[maybe_unused]] Number* z_L, + [[maybe_unused]] Number* z_U, + [[maybe_unused]] Index m, + [[maybe_unused]] bool init_lambda, + [[maybe_unused]] Number* lambda) { // Only initial values for x provided. assert(init_x == true); @@ -99,11 +99,11 @@ namespace AnalysisManager return true; } - template - bool DynamicObjective::eval_f([[maybe_unused]] Index n, - const Number* x, - [[maybe_unused]] bool new_x, - Number& obj_value) + template + bool DynamicObjective::eval_f([[maybe_unused]] Index n, + const Number* x, + [[maybe_unused]] bool new_x, + Number& obj_value) { // Update optimization parameters auto* param = model_->param().getData(); @@ -123,11 +123,11 @@ namespace AnalysisManager return true; } - template - bool DynamicObjective::eval_grad_f([[maybe_unused]] Index n, - const Number* x, - [[maybe_unused]] bool new_x, - Number* grad_f) + template + bool DynamicObjective::eval_grad_f([[maybe_unused]] Index n, + const Number* x, + [[maybe_unused]] bool new_x, + Number* grad_f) { assert(model_->sizeParams() == static_cast(n)); // Update optimization parameters @@ -158,57 +158,57 @@ namespace AnalysisManager return true; } - template - bool DynamicObjective::eval_g([[maybe_unused]] Index n, - [[maybe_unused]] const Number* x, - [[maybe_unused]] bool new_x, - [[maybe_unused]] Index m, - [[maybe_unused]] Number* g) + template + bool DynamicObjective::eval_g([[maybe_unused]] Index n, + [[maybe_unused]] const Number* x, + [[maybe_unused]] bool new_x, + [[maybe_unused]] Index m, + [[maybe_unused]] Number* g) { return true; } - template - bool DynamicObjective::eval_jac_g([[maybe_unused]] Index n, - [[maybe_unused]] const Number* x, - [[maybe_unused]] bool new_x, - [[maybe_unused]] Index m, - [[maybe_unused]] Index nele_jac, - [[maybe_unused]] Index* iRow, - [[maybe_unused]] Index* jCol, - [[maybe_unused]] Number* values) + template + bool DynamicObjective::eval_jac_g([[maybe_unused]] Index n, + [[maybe_unused]] const Number* x, + [[maybe_unused]] bool new_x, + [[maybe_unused]] Index m, + [[maybe_unused]] Index nele_jac, + [[maybe_unused]] Index* iRow, + [[maybe_unused]] Index* jCol, + [[maybe_unused]] Number* values) { return true; } - template - bool DynamicObjective::eval_h([[maybe_unused]] Index n, - [[maybe_unused]] const Number* x, - [[maybe_unused]] bool new_x, - [[maybe_unused]] Number obj_factor, - [[maybe_unused]] Index m, - [[maybe_unused]] const Number* lambda, - [[maybe_unused]] bool new_lambda, - [[maybe_unused]] Index nele_hess, - [[maybe_unused]] Index* iRow, - [[maybe_unused]] Index* jCol, - [[maybe_unused]] Number* values) + template + bool DynamicObjective::eval_h([[maybe_unused]] Index n, + [[maybe_unused]] const Number* x, + [[maybe_unused]] bool new_x, + [[maybe_unused]] Number obj_factor, + [[maybe_unused]] Index m, + [[maybe_unused]] const Number* lambda, + [[maybe_unused]] bool new_lambda, + [[maybe_unused]] Index nele_hess, + [[maybe_unused]] Index* iRow, + [[maybe_unused]] Index* jCol, + [[maybe_unused]] Number* values) { return true; } - template - void DynamicObjective::finalize_solution([[maybe_unused]] SolverReturn status, - [[maybe_unused]] Index n, - [[maybe_unused]] const Number* x, - [[maybe_unused]] const Number* z_L, - [[maybe_unused]] const Number* z_U, - [[maybe_unused]] Index m, - [[maybe_unused]] const Number* g, - [[maybe_unused]] const Number* lambda, - [[maybe_unused]] Number obj_value, - [[maybe_unused]] const IpoptData* ip_data, - [[maybe_unused]] IpoptCalculatedQuantities* ip_cq) + template + void DynamicObjective::finalize_solution([[maybe_unused]] SolverReturn status, + [[maybe_unused]] Index n, + [[maybe_unused]] const Number* x, + [[maybe_unused]] const Number* z_L, + [[maybe_unused]] const Number* z_U, + [[maybe_unused]] Index m, + [[maybe_unused]] const Number* g, + [[maybe_unused]] const Number* lambda, + [[maybe_unused]] Number obj_value, + [[maybe_unused]] const IpoptData* ip_data, + [[maybe_unused]] IpoptCalculatedQuantities* ip_cq) { } diff --git a/GridKit/Solver/Optimization/DynamicObjective.hpp b/GridKit/Solver/Optimization/DynamicObjective.hpp index 72a5763b0..c3869d40e 100644 --- a/GridKit/Solver/Optimization/DynamicObjective.hpp +++ b/GridKit/Solver/Optimization/DynamicObjective.hpp @@ -20,13 +20,11 @@ namespace AnalysisManager * and the gradient. * */ - template - class DynamicObjective : public Ipopt::TNLP, public OptimizationSolver + template + class DynamicObjective : public Ipopt::TNLP, public OptimizationSolver { - using OptimizationSolver::integrator_; - using OptimizationSolver::model_; - - using RealT = typename GridKit::ScalarTraits::RealT; + using OptimizationSolver::integrator_; + using OptimizationSolver::model_; using Index = Ipopt::Index; using Number = Ipopt::Number; @@ -35,6 +33,10 @@ namespace AnalysisManager using IpoptData = Ipopt::IpoptData; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename GridKit::ScalarTraits::RealT; + DynamicObjective(Sundials::Ida* integrator, RealT t_init, RealT t_final, diff --git a/GridKit/Solver/Optimization/OptimizationSolver.hpp b/GridKit/Solver/Optimization/OptimizationSolver.hpp index e073a98df..24860cc47 100644 --- a/GridKit/Solver/Optimization/OptimizationSolver.hpp +++ b/GridKit/Solver/Optimization/OptimizationSolver.hpp @@ -6,13 +6,16 @@ namespace AnalysisManager { - template + template class DynamicSolver; - template + template class OptimizationSolver { public: + using ScalarT = scalar_type; + using IdxT = index_type; + OptimizationSolver() { } diff --git a/GridKit/Solver/SteadyState/Kinsol.cpp b/GridKit/Solver/SteadyState/Kinsol.cpp index acf4442b0..ff5a46c9f 100644 --- a/GridKit/Solver/SteadyState/Kinsol.cpp +++ b/GridKit/Solver/SteadyState/Kinsol.cpp @@ -26,8 +26,8 @@ namespace AnalysisManager namespace Sundials { - template - Kinsol::Kinsol(GridKit::Model::Evaluator* model) + template + Kinsol::Kinsol(GridKit::Model::Evaluator* model) : SteadyStateSolver(model) { int retval = 0; @@ -39,16 +39,16 @@ namespace AnalysisManager solver_ = KINCreate(context_); } - template - Kinsol::~Kinsol() + template + Kinsol::~Kinsol() { deleteSimulation(); SUNContext_Free(&context_); solver_ = nullptr; } - template - int Kinsol::configureSimulation() + template + int Kinsol::configureSimulation() { int retval = 0; @@ -76,8 +76,8 @@ namespace AnalysisManager return this->configureLinearSolver(); } - template - int Kinsol::configureLinearSolver() + template + int Kinsol::configureLinearSolver() { int retval = 0; @@ -96,8 +96,8 @@ namespace AnalysisManager return retval; } - template - int Kinsol::getDefaultInitialCondition() + template + int Kinsol::getDefaultInitialCondition() { model_->initialize(); @@ -106,8 +106,8 @@ namespace AnalysisManager return 0; } - template - int Kinsol::runSimulation() + template + int Kinsol::runSimulation() { int retval = 0; N_VConst(1.0, scale_); @@ -118,8 +118,8 @@ namespace AnalysisManager return retval; } - template - int Kinsol::deleteSimulation() + template + int Kinsol::deleteSimulation() { KINFree(&solver_); N_VDestroy(this->yy_); @@ -130,8 +130,8 @@ namespace AnalysisManager return 0; } - template - int Kinsol::Residual(N_Vector yy, N_Vector rr, void* user_data) + template + int Kinsol::Residual(N_Vector yy, N_Vector rr, void* user_data) { GridKit::Model::Evaluator* model = static_cast*>(user_data); @@ -144,24 +144,24 @@ namespace AnalysisManager return 0; } - template - void Kinsol::copyVec(const N_Vector x, VectorT& y) + template + void Kinsol::copyVec(const N_Vector x, VectorT& y) { const ScalarT* xdata = N_VGetArrayPointer(x); std::copy_n(xdata, static_cast(y.getSize()), y.getData()); y.setDataUpdated(); } - template - void Kinsol::copyVec(const VectorT& x, N_Vector y) + template + void Kinsol::copyVec(const VectorT& x, N_Vector y) { const auto* xdata = x.getData(); auto* ydata = N_VGetArrayPointer(y); std::copy_n(xdata, static_cast(x.getSize()), ydata); } - template - void Kinsol::printOutput() const + template + void Kinsol::printOutput() const { sunrealtype* yval = N_VGetArrayPointer(yy_); @@ -173,8 +173,8 @@ namespace AnalysisManager std::cout << "\n"; } - template - void Kinsol::printSpecial(sunrealtype t, N_Vector y) const + template + void Kinsol::printSpecial(sunrealtype t, N_Vector y) const { sunrealtype* yval = N_VGetArrayPointer_Serial(y); IdxT N = static_cast(N_VGetLength_Serial(y)); @@ -187,15 +187,15 @@ namespace AnalysisManager std::cout << "},\n"; } - template - void Kinsol::printFinalStats() const + template + void Kinsol::printFinalStats() const { int retval = KINPrintAllStats(solver_, stdout, SUN_OUTPUTFORMAT_TABLE); checkOutput(retval, "KINPrintAllStats"); } - template - void Kinsol::checkAllocation(void* v, const char* functionName) + template + void Kinsol::checkAllocation(void* v, const char* functionName) { if (v == NULL) { @@ -204,8 +204,8 @@ namespace AnalysisManager } } - template - void Kinsol::checkOutput(int retval, const char* functionName) + template + void Kinsol::checkOutput(int retval, const char* functionName) { if (retval < 0) { @@ -214,8 +214,8 @@ namespace AnalysisManager } } - template - void Kinsol::setTolerance(ScalarT tol) + template + void Kinsol::setTolerance(ScalarT tol) { int retval = KINSetFuncNormTol(solver_, tol); checkOutput(retval, "KINSetFuncNormTol"); diff --git a/GridKit/Solver/SteadyState/Kinsol.hpp b/GridKit/Solver/SteadyState/Kinsol.hpp index ef992d44c..b4c260132 100644 --- a/GridKit/Solver/SteadyState/Kinsol.hpp +++ b/GridKit/Solver/SteadyState/Kinsol.hpp @@ -24,17 +24,19 @@ namespace AnalysisManager { namespace Sundials { - template - class Kinsol : public SteadyStateSolver + template + class Kinsol : public SteadyStateSolver { - using SteadyStateSolver::model_; + using SteadyStateSolver::model_; + public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename GridKit::ScalarTraits::RealT; using VectorT = typename GridKit::Model::Evaluator::VectorT; static_assert(std::is_same_v, "RealT must be the same type as sunrealtype"); - public: Kinsol(GridKit::Model::Evaluator* model); ~Kinsol(); diff --git a/GridKit/Solver/SteadyState/SteadyStateSolver.hpp b/GridKit/Solver/SteadyState/SteadyStateSolver.hpp index 19643e331..ae9d72e93 100644 --- a/GridKit/Solver/SteadyState/SteadyStateSolver.hpp +++ b/GridKit/Solver/SteadyState/SteadyStateSolver.hpp @@ -4,10 +4,13 @@ namespace AnalysisManager { - template + template class SteadyStateSolver { public: + using ScalarT = scalar_type; + using IdxT = index_type; + SteadyStateSolver(GridKit::Model::Evaluator* model) : model_(model) { diff --git a/GridKit/Utilities/FileIO.hpp b/GridKit/Utilities/FileIO.hpp index 1e4c2b3d9..85b24fb14 100644 --- a/GridKit/Utilities/FileIO.hpp +++ b/GridKit/Utilities/FileIO.hpp @@ -21,7 +21,7 @@ namespace GridKit * * @todo needs to return int for file error codes * - * @tparam ScalarT + * @tparam scalar_type * @param[out] table object in memory where the data from the input stream is * @param[in] filename input stream to space and newline separated data * @param[out] ti initial time returned @@ -32,11 +32,11 @@ namespace GridKit * first column of the data represents time and other columns time dependent * variables. */ - template - void setLookupTable(std::vector>& table, - std::istream& idata, - ScalarT& ti, - ScalarT& tf) + template + void setLookupTable(std::vector>& table, + std::istream& idata, + scalar_type& ti, + scalar_type& tf) { std::string line; int oldwordcount = -1; @@ -83,8 +83,8 @@ namespace GridKit } } - template - void printLookupTable(std::vector> const& table) + template + void printLookupTable(std::vector> const& table) { for (size_t i = 0; i < table.size(); ++i) { diff --git a/GridKit/Utilities/MapFromCsr.hpp b/GridKit/Utilities/MapFromCsr.hpp index 6a4028f32..8269c7a56 100644 --- a/GridKit/Utilities/MapFromCsr.hpp +++ b/GridKit/Utilities/MapFromCsr.hpp @@ -15,9 +15,12 @@ namespace GridKit { namespace Testing { - template - std::vector MapFromCsr(LinearAlgebra::CsrMatrix* matrix) + template + std::vector MapFromCsr(LinearAlgebra::CsrMatrix* matrix) { + using RealT = real_type; + using IdxT = index_type; + IdxT* row_data = matrix->getRowData(); IdxT* column_data = matrix->getColData(); RealT* values = matrix->getValues(); diff --git a/tests/UnitTests/AutomaticDifferentiation/DependencyTracking/DependencyTrackingTests.hpp b/tests/UnitTests/AutomaticDifferentiation/DependencyTracking/DependencyTrackingTests.hpp index 5345fae5b..5c42bc5fd 100644 --- a/tests/UnitTests/AutomaticDifferentiation/DependencyTracking/DependencyTrackingTests.hpp +++ b/tests/UnitTests/AutomaticDifferentiation/DependencyTracking/DependencyTrackingTests.hpp @@ -9,10 +9,13 @@ namespace GridKit { namespace Testing { - template + template class SparsityPatternTests { public: + using ScalarT = scalar_type; + using IdxT = index_type; + SparsityPatternTests() = default; ~SparsityPatternTests() = default; diff --git a/tests/UnitTests/AutomaticDifferentiation/Enzyme/EnzymeTests.hpp b/tests/UnitTests/AutomaticDifferentiation/Enzyme/EnzymeTests.hpp index 79696db29..fa40911b5 100644 --- a/tests/UnitTests/AutomaticDifferentiation/Enzyme/EnzymeTests.hpp +++ b/tests/UnitTests/AutomaticDifferentiation/Enzyme/EnzymeTests.hpp @@ -18,10 +18,12 @@ namespace GridKit { namespace Testing { - template + template class EnzymeTests { public: + using ScalarT = scalar_type; + using IdxT = index_type; using SparseMatrix = GridKit::LinearAlgebra::CooMatrix; EnzymeTests() = default; diff --git a/tests/UnitTests/LinearAlgebra/SparseMatrix/SparseCooTests.hpp b/tests/UnitTests/LinearAlgebra/SparseMatrix/SparseCooTests.hpp index 9ee684253..6a5a4629d 100644 --- a/tests/UnitTests/LinearAlgebra/SparseMatrix/SparseCooTests.hpp +++ b/tests/UnitTests/LinearAlgebra/SparseMatrix/SparseCooTests.hpp @@ -7,13 +7,14 @@ namespace GridKit { using namespace LinearAlgebra; - template + template class SparseCooTests { - + public: + using ScalarT = scalar_type; + using IdxT = index_type; using CooMatrix = LinearAlgebra::CooMatrix; - public: SparseCooTests(memory::MemorySpace memspace = memory::HOST) : memspace_(memspace) { diff --git a/tests/UnitTests/LinearAlgebra/SparseMatrix/SparseCsrTests.hpp b/tests/UnitTests/LinearAlgebra/SparseMatrix/SparseCsrTests.hpp index cc9cac5b6..284220433 100644 --- a/tests/UnitTests/LinearAlgebra/SparseMatrix/SparseCsrTests.hpp +++ b/tests/UnitTests/LinearAlgebra/SparseMatrix/SparseCsrTests.hpp @@ -7,13 +7,14 @@ namespace GridKit { using namespace LinearAlgebra; - template + template class SparseTests { - + public: + using ScalarT = scalar_type; + using IdxT = index_type; using CsrMatrix = LinearAlgebra::CsrMatrix; - public: SparseTests(memory::MemorySpace memspace = memory::HOST) : memspace_(memspace) { diff --git a/tests/UnitTests/LinearAlgebra/SparseMatrix/runSparseCooTests.cpp b/tests/UnitTests/LinearAlgebra/SparseMatrix/runSparseCooTests.cpp index 7d74afa69..476cd1ec0 100644 --- a/tests/UnitTests/LinearAlgebra/SparseMatrix/runSparseCooTests.cpp +++ b/tests/UnitTests/LinearAlgebra/SparseMatrix/runSparseCooTests.cpp @@ -11,9 +11,12 @@ using namespace Testing; * @param[in] memspace - memory space for the tests * @param[out] result - test results */ -template +template void runTests(const std::string& backend, memory::MemorySpace memspace, TestingResults& result) { + using ScalarT = scalar_type; + using IdxT = index_type; + std::cout << "Running tests on " << backend << ":\n"; SparseCooTests test(memspace); diff --git a/tests/UnitTests/LinearAlgebra/SparseMatrix/runSparseCsrTests.cpp b/tests/UnitTests/LinearAlgebra/SparseMatrix/runSparseCsrTests.cpp index 066237c4c..f4e84af23 100644 --- a/tests/UnitTests/LinearAlgebra/SparseMatrix/runSparseCsrTests.cpp +++ b/tests/UnitTests/LinearAlgebra/SparseMatrix/runSparseCsrTests.cpp @@ -10,9 +10,12 @@ using namespace Testing; * @param[in] backend - name of the hardware backend * @param[out] result - test results */ -template +template void runTests(const std::string& backend, memory::MemorySpace memspace, TestingResults& result) { + using ScalarT = scalar_type; + using IdxT = index_type; + std::cout << "Running tests on " << backend << ":\n"; SparseTests test(memspace); diff --git a/tests/UnitTests/LinearAlgebra/Vector/VectorHandlerTests.hpp b/tests/UnitTests/LinearAlgebra/Vector/VectorHandlerTests.hpp index 748a065f0..5c56cdc07 100644 --- a/tests/UnitTests/LinearAlgebra/Vector/VectorHandlerTests.hpp +++ b/tests/UnitTests/LinearAlgebra/Vector/VectorHandlerTests.hpp @@ -17,10 +17,13 @@ namespace GridKit /** * @class Tests for the vector handler. */ - template + template class VectorHandlerTests { public: + using ScalarT = scalar_type; + using IdxT = index_type; + VectorHandlerTests(VectorHandler& handler, memory::MemorySpace memspace = memory::HOST) : handler_(handler), memspace_(memspace) diff --git a/tests/UnitTests/LinearAlgebra/Vector/VectorTests.hpp b/tests/UnitTests/LinearAlgebra/Vector/VectorTests.hpp index a250b4d5c..d48ed2521 100644 --- a/tests/UnitTests/LinearAlgebra/Vector/VectorTests.hpp +++ b/tests/UnitTests/LinearAlgebra/Vector/VectorTests.hpp @@ -21,10 +21,13 @@ namespace GridKit /** * @class Tests for vector operations. */ - template + template class VectorTests { public: + using ScalarT = scalar_type; + using IdxT = index_type; + VectorTests(memory::MemorySpace memspace = memory::HOST) : memspace_(memspace) { diff --git a/tests/UnitTests/Math/SmoothnessIndicatorTests.hpp b/tests/UnitTests/Math/SmoothnessIndicatorTests.hpp index 1ce2d8b1f..5bf9f7f46 100644 --- a/tests/UnitTests/Math/SmoothnessIndicatorTests.hpp +++ b/tests/UnitTests/Math/SmoothnessIndicatorTests.hpp @@ -13,11 +13,12 @@ namespace GridKit { namespace Testing { - template + template class SmoothnessIndicatorTests { private: - using RealT = typename GridKit::ScalarTraits::RealT; + using ScalarT = scalar_type; + using RealT = typename GridKit::ScalarTraits::RealT; static constexpr RealT kSmoothTolerance = 1.0e-2; static constexpr RealT kNearOne = 1.0 - kSmoothTolerance; diff --git a/tests/UnitTests/PhasorDynamics/BranchTests.hpp b/tests/UnitTests/PhasorDynamics/BranchTests.hpp index 5ce555e19..4fddabd93 100644 --- a/tests/UnitTests/PhasorDynamics/BranchTests.hpp +++ b/tests/UnitTests/PhasorDynamics/BranchTests.hpp @@ -18,13 +18,14 @@ namespace GridKit { using Log = ::GridKit::Utilities::Logger; - template + template class BranchTests { - private: - using RealT = typename PhasorDynamics::Component::RealT; - public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename PhasorDynamics::Component::RealT; + BranchTests() = default; ~BranchTests() = default; diff --git a/tests/UnitTests/PhasorDynamics/BusFaultTests.hpp b/tests/UnitTests/PhasorDynamics/BusFaultTests.hpp index 8ac45f8d8..c118b2896 100644 --- a/tests/UnitTests/PhasorDynamics/BusFaultTests.hpp +++ b/tests/UnitTests/PhasorDynamics/BusFaultTests.hpp @@ -17,13 +17,14 @@ namespace GridKit namespace Testing { - template + template class BusFaultTests { - private: - using RealT = typename PhasorDynamics::Component::RealT; - public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename PhasorDynamics::Component::RealT; + BusFaultTests() = default; ~BusFaultTests() = default; diff --git a/tests/UnitTests/PhasorDynamics/BusTests.hpp b/tests/UnitTests/PhasorDynamics/BusTests.hpp index a1ebb7593..464709ccf 100644 --- a/tests/UnitTests/PhasorDynamics/BusTests.hpp +++ b/tests/UnitTests/PhasorDynamics/BusTests.hpp @@ -10,10 +10,13 @@ namespace GridKit { namespace Testing { - template + template class BusTests { public: + using ScalarT = scalar_type; + using IdxT = index_type; + BusTests() = default; ~BusTests() = default; diff --git a/tests/UnitTests/PhasorDynamics/BusToSignalAdapterTests.hpp b/tests/UnitTests/PhasorDynamics/BusToSignalAdapterTests.hpp index ae4a8fafd..41c50fdb3 100644 --- a/tests/UnitTests/PhasorDynamics/BusToSignalAdapterTests.hpp +++ b/tests/UnitTests/PhasorDynamics/BusToSignalAdapterTests.hpp @@ -12,10 +12,12 @@ namespace GridKit { namespace Testing { - template + template class BusToSignalAdapterTests { public: + using ScalarT = scalar_type; + using IdxT = index_type; using AdapterT = PhasorDynamics::BusToSignalAdapter; using RealT = typename AdapterT::RealT; using BusT = PhasorDynamics::Bus; diff --git a/tests/UnitTests/PhasorDynamics/ExciterIeeet1Tests.hpp b/tests/UnitTests/PhasorDynamics/ExciterIeeet1Tests.hpp index 0b7c9de4e..4ee3adec4 100644 --- a/tests/UnitTests/PhasorDynamics/ExciterIeeet1Tests.hpp +++ b/tests/UnitTests/PhasorDynamics/ExciterIeeet1Tests.hpp @@ -21,11 +21,13 @@ namespace GridKit { using Log = ::GridKit::Utilities::Logger; - template + template class ExciterIeeet1Tests { public: - using RealT = typename PhasorDynamics::Component::RealT; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename PhasorDynamics::Component::RealT; ExciterIeeet1Tests() = default; ~ExciterIeeet1Tests() = default; diff --git a/tests/UnitTests/PhasorDynamics/ExciterSexsPtiTests.hpp b/tests/UnitTests/PhasorDynamics/ExciterSexsPtiTests.hpp index 670503d19..188b2e145 100644 --- a/tests/UnitTests/PhasorDynamics/ExciterSexsPtiTests.hpp +++ b/tests/UnitTests/PhasorDynamics/ExciterSexsPtiTests.hpp @@ -23,11 +23,13 @@ namespace GridKit { using Log = GridKit::Utilities::Logger; - template + template class ExciterSexsPtiTests { public: - using RealT = typename PhasorDynamics::Component::RealT; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename PhasorDynamics::Component::RealT; ExciterSexsPtiTests() = default; ~ExciterSexsPtiTests() = default; diff --git a/tests/UnitTests/PhasorDynamics/GenClassicalTests.hpp b/tests/UnitTests/PhasorDynamics/GenClassicalTests.hpp index 4ec020934..cef5018bf 100644 --- a/tests/UnitTests/PhasorDynamics/GenClassicalTests.hpp +++ b/tests/UnitTests/PhasorDynamics/GenClassicalTests.hpp @@ -27,10 +27,12 @@ namespace GridKit namespace Testing { - template + template class GenClassicalTests { private: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename PhasorDynamics::Component::RealT; using GenClassicalDataT = PhasorDynamics::GenClassicalData; static constexpr ScalarT tol_ = 10 * std::numeric_limits::epsilon(); diff --git a/tests/UnitTests/PhasorDynamics/GenrouTests.hpp b/tests/UnitTests/PhasorDynamics/GenrouTests.hpp index 2e4123056..001cdfc83 100644 --- a/tests/UnitTests/PhasorDynamics/GenrouTests.hpp +++ b/tests/UnitTests/PhasorDynamics/GenrouTests.hpp @@ -18,10 +18,12 @@ namespace GridKit namespace Testing { - template + template class GenrouTests { private: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename PhasorDynamics::Component::RealT; using GenrouDataT = PhasorDynamics::GenrouData; static constexpr ScalarT tol_ = 10 * std::numeric_limits::epsilon(); // added this: was not originally there diff --git a/tests/UnitTests/PhasorDynamics/GensalTests.hpp b/tests/UnitTests/PhasorDynamics/GensalTests.hpp index f101273e1..609121c07 100644 --- a/tests/UnitTests/PhasorDynamics/GensalTests.hpp +++ b/tests/UnitTests/PhasorDynamics/GensalTests.hpp @@ -19,10 +19,12 @@ namespace GridKit namespace Testing { - template + template class GensalTests { private: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename PhasorDynamics::Component::RealT; using GensalDataT = PhasorDynamics::GensalData; static constexpr ScalarT tol_ = 10 * std::numeric_limits::epsilon(); diff --git a/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp b/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp index 134446e51..5c1235a1f 100644 --- a/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp +++ b/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp @@ -21,10 +21,12 @@ namespace GridKit namespace Testing { - template + template class GovernorTgov1Tests { private: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename PhasorDynamics::Component::RealT; using real_type = typename PhasorDynamics::Component::RealT; static constexpr ScalarT tol_ = 10 * std::numeric_limits::epsilon(); diff --git a/tests/UnitTests/PhasorDynamics/LoadZIPTests.hpp b/tests/UnitTests/PhasorDynamics/LoadZIPTests.hpp index 23d932ea3..8b23c0968 100644 --- a/tests/UnitTests/PhasorDynamics/LoadZIPTests.hpp +++ b/tests/UnitTests/PhasorDynamics/LoadZIPTests.hpp @@ -19,12 +19,14 @@ namespace GridKit { namespace Testing { - template + template class LoadZIPTests { public: - using RealT = typename PhasorDynamics::Component::RealT; - using DataT = PhasorDynamics::LoadZIPData; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename PhasorDynamics::Component::RealT; + using DataT = PhasorDynamics::LoadZIPData; LoadZIPTests() = default; ~LoadZIPTests() = default; diff --git a/tests/UnitTests/PhasorDynamics/LoadZTests.hpp b/tests/UnitTests/PhasorDynamics/LoadZTests.hpp index c0ac99d78..fb292fecb 100644 --- a/tests/UnitTests/PhasorDynamics/LoadZTests.hpp +++ b/tests/UnitTests/PhasorDynamics/LoadZTests.hpp @@ -18,12 +18,14 @@ namespace GridKit { namespace Testing { - template + template class LoadZTests { public: - using RealT = typename PhasorDynamics::Component::RealT; - using DataT = PhasorDynamics::LoadZData; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename PhasorDynamics::Component::RealT; + using DataT = PhasorDynamics::LoadZData; LoadZTests() = default; ~LoadZTests() = default; diff --git a/tests/UnitTests/PhasorDynamics/StabilizerIeeestTests.hpp b/tests/UnitTests/PhasorDynamics/StabilizerIeeestTests.hpp index 14cd9cd88..e76c64bc7 100644 --- a/tests/UnitTests/PhasorDynamics/StabilizerIeeestTests.hpp +++ b/tests/UnitTests/PhasorDynamics/StabilizerIeeestTests.hpp @@ -17,11 +17,13 @@ namespace GridKit { namespace Testing { - template + template class StabilizerIeeestTests { public: - using RealT = typename PhasorDynamics::Component::RealT; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename PhasorDynamics::Component::RealT; StabilizerIeeestTests() = default; ~StabilizerIeeestTests() = default; diff --git a/tests/UnitTests/PhasorDynamics/SystemSingleComponentTests.hpp b/tests/UnitTests/PhasorDynamics/SystemSingleComponentTests.hpp index 2ffcfbc6d..3d7c876dc 100644 --- a/tests/UnitTests/PhasorDynamics/SystemSingleComponentTests.hpp +++ b/tests/UnitTests/PhasorDynamics/SystemSingleComponentTests.hpp @@ -12,13 +12,14 @@ namespace GridKit { /// Smoke test for components (single component connected to an infinite bus) /// through the system model with the minimal constructors - template + template class SystemSingleComponentTests { - private: - using RealT = typename PhasorDynamics::Component::RealT; - public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename PhasorDynamics::Component::RealT; + SystemSingleComponentTests() = default; ~SystemSingleComponentTests() = default; diff --git a/tests/UnitTests/PhasorDynamics/SystemTests.hpp b/tests/UnitTests/PhasorDynamics/SystemTests.hpp index c0d416828..34f9bfc79 100644 --- a/tests/UnitTests/PhasorDynamics/SystemTests.hpp +++ b/tests/UnitTests/PhasorDynamics/SystemTests.hpp @@ -30,13 +30,14 @@ namespace GridKit using Log = ::GridKit::Utilities::Logger; - template + template class SystemTests { - private: - using RealT = typename PhasorDynamics::Component::RealT; - public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename PhasorDynamics::Component::RealT; + SystemTests() = default; ~SystemTests() = default; diff --git a/tests/UnitTests/PowerElectronics/CircuitNodeTests.hpp b/tests/UnitTests/PowerElectronics/CircuitNodeTests.hpp index bc380f972..5af9fe3bd 100644 --- a/tests/UnitTests/PowerElectronics/CircuitNodeTests.hpp +++ b/tests/UnitTests/PowerElectronics/CircuitNodeTests.hpp @@ -10,10 +10,13 @@ namespace GridKit { namespace Testing { - template + template class NodeTests { public: + using ScalarT = scalar_type; + using IdxT = index_type; + NodeTests() = default; ~NodeTests() = default; diff --git a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp index 655f83afa..5ac78880e 100644 --- a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp +++ b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp @@ -11,10 +11,12 @@ namespace GridKit { namespace Model { - template - class NullEvaluator : public Model::Evaluator + template + class NullEvaluator : public Model::Evaluator { public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename Model::Evaluator::RealT; using VectorT = typename Model::Evaluator::VectorT; @@ -300,19 +302,21 @@ namespace GridKit bool allocated_{false}; }; - template - class AlgebraicErrorControlEvaluator : public NullEvaluator + template + class AlgebraicErrorControlEvaluator : public NullEvaluator { protected: - using NullEvaluator::allocated_; - using NullEvaluator::y_; - using NullEvaluator::yp_; - using NullEvaluator::abs_tol_; - using NullEvaluator::tag_; - using NullEvaluator::f_; + using NullEvaluator::allocated_; + using NullEvaluator::y_; + using NullEvaluator::yp_; + using NullEvaluator::abs_tol_; + using NullEvaluator::tag_; + using NullEvaluator::f_; public: - using RealT = typename NullEvaluator::RealT; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename NullEvaluator::RealT; int initialize() override { @@ -373,10 +377,13 @@ namespace GridKit namespace Testing { - template + template class IdaTests { public: + using ScalarT = scalar_type; + using IdxT = index_type; + TestOutcome callback() { const unsigned n_steps = 100; diff --git a/tests/UnitTests/Solver/Dynamic/RosenbrockTests.hpp b/tests/UnitTests/Solver/Dynamic/RosenbrockTests.hpp index d16ce8e99..95bcb759e 100644 --- a/tests/UnitTests/Solver/Dynamic/RosenbrockTests.hpp +++ b/tests/UnitTests/Solver/Dynamic/RosenbrockTests.hpp @@ -29,10 +29,12 @@ namespace GridKit * The valid simulation time interval is \f([0.5,2]\f) and the model is initialized at \f(t = 0.5\f). * */ - template - class TrigonometricDaeEvaluator : public Model::Evaluator + template + class TrigonometricDaeEvaluator : public Model::Evaluator { public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename Model::Evaluator::RealT; using VectorT = typename Model::Evaluator::VectorT; @@ -363,9 +365,11 @@ namespace GridKit namespace Testing { - template + template class RosenbrockTests { + using ScalarT = scalar_type; + using IdxT = index_type; using Rosenbrock = AnalysisManager::NativeDynamicSolver::Rosenbrock; using RealT = typename GridKit::ScalarTraits::RealT; using VectorT = typename Model::Evaluator::VectorT; diff --git a/tests/UnitTests/Utilities/CaseFormatTests.hpp b/tests/UnitTests/Utilities/CaseFormatTests.hpp index fd0f0d2de..ff91fc490 100644 --- a/tests/UnitTests/Utilities/CaseFormatTests.hpp +++ b/tests/UnitTests/Utilities/CaseFormatTests.hpp @@ -21,10 +21,13 @@ namespace GridKit { using json = nlohmann::json; - template + template class CaseFormatTests { public: + using RealT = real_type; + using IdxT = index_type; + CaseFormatTests() = default; ~CaseFormatTests() = default;