Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,37 @@ Always declare type aliases with the `using` keyword rather than `typedef typena
typedef typename GridKit::ScalarTraits<ScalarT>::RealT RealT; // No
```

Types that are used as template parameters should use uppercase camel name format,
similar to classes, with the `T` suffix to indicate that it is a type.
For consistency, use the same name everywhere the same type is used.
Types that are used as template parameters should use `snake_case` format, with
the `_type` suffix to indicate that it is a type. Use the keyword `typename`
rather than `class` for template type parameters.

```c++
template <typename RealT> ...; // Yes
template <typename real_type>; // No, `_type` used in a template parameter name
template <typename RealT>; // No, using format reserved for interface types
template <class real_type>; // No, using `class` keyword

template <typename real_type> ...; // Yes
```
Types used within class implementation code and provided in the public class
interface should use `UpperCamelT` format, similar to class names, but with a
`T` suffix. For consistency, create aliases for template type parameters
(*e.g.,* `using ScalarT = scalar_type;`) and use the same name everywhere the
same type is used. This applies across multiple classes in which the type has
the same meaning.

```c++
template <typename scalar_type, typename index_type>
class ExTemp
{
// Convention used in all applicable classes for scalar, index, and
// primitive floating-point types
using ScalarT = scalar_type;
using IdxT = index_type;
using RealT = GridKit::ScalarTraits<ScalarT>::RealT;

// void foo(scalar_type value); // No, using template type parameter
void foo(ScalarT value); // Yes, using interface types in code
};
```

### Constants

Expand Down
4 changes: 3 additions & 1 deletion GridKit/Model/Evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ namespace GridKit
* @brief Abstract class describing a model.
*
*/
template <class ScalarT, typename IdxT>
template <class scalar_type, typename index_type>
class Evaluator
{
public:
using ScalarT = scalar_type;
using IdxT = index_type;
using RealT = typename GridKit::ScalarTraits<ScalarT>::RealT;
using MatrixT = GridKit::LinearAlgebra::COO_Matrix<RealT, IdxT>; //\todo Use CsrMatrix
using CsrMatrixT = GridKit::LinearAlgebra::CsrMatrix<RealT, IdxT>;
Expand Down
6 changes: 2 additions & 4 deletions GridKit/Model/PhasorDynamics/Branch/Branch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ namespace GridKit
/**
* @brief Jacobian evaluation not implemented
*
* @tparam ScalarT - scalar data type
* @tparam IdxT - matrix index data type
* @return int - error code, 0 = success
*/
template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::evaluateJacobian()
template <typename scalar_type, typename index_type>
int Branch<scalar_type, index_type>::evaluateJacobian()
{
Log::misc() << "Evaluate Jacobian for Branch..." << std::endl;
Log::misc() << "Jacobian evaluation is not implemented!" << std::endl;
Expand Down
112 changes: 58 additions & 54 deletions GridKit/Model/PhasorDynamics/Branch/Branch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace GridKit
{
namespace PhasorDynamics
{
template <class ScalarT, typename IdxT>
template <typename scalar_type, typename index_type>
class BusBase;

template <typename RealT, typename IdxT>
template <typename real_type, typename index_type>
struct BranchData;
} // namespace PhasorDynamics
} // namespace GridKit
Expand All @@ -37,43 +37,45 @@ namespace GridKit
* direction is into the busses.
*
*/
template <class ScalarT, typename IdxT>
class Branch : public Component<ScalarT, IdxT>
template <typename scalar_type, typename index_type>
class Branch : public Component<scalar_type, index_type>
{
using Component<ScalarT, IdxT>::gridkit_component_id_;
using Component<ScalarT, IdxT>::size_;
using Component<ScalarT, IdxT>::nnz_;
using Component<ScalarT, IdxT>::time_;
using Component<ScalarT, IdxT>::alpha_;
using Component<ScalarT, IdxT>::y_;
using Component<ScalarT, IdxT>::yp_;
using Component<ScalarT, IdxT>::tag_;
using Component<ScalarT, IdxT>::f_;
using Component<ScalarT, IdxT>::wb_;
using Component<ScalarT, IdxT>::h_;
using Component<ScalarT, IdxT>::J_;
using Component<ScalarT, IdxT>::J_rows_buffer_;
using Component<ScalarT, IdxT>::J_cols_buffer_;
using Component<ScalarT, IdxT>::J_vals_buffer_;
using Component<ScalarT, IdxT>::variable_indices_;
using Component<ScalarT, IdxT>::residual_indices_;
using Component<scalar_type, index_type>::gridkit_component_id_;
using Component<scalar_type, index_type>::size_;
using Component<scalar_type, index_type>::nnz_;
using Component<scalar_type, index_type>::time_;
using Component<scalar_type, index_type>::alpha_;
using Component<scalar_type, index_type>::y_;
using Component<scalar_type, index_type>::yp_;
using Component<scalar_type, index_type>::tag_;
using Component<scalar_type, index_type>::f_;
using Component<scalar_type, index_type>::wb_;
using Component<scalar_type, index_type>::h_;
using Component<scalar_type, index_type>::J_;
using Component<scalar_type, index_type>::J_rows_buffer_;
using Component<scalar_type, index_type>::J_cols_buffer_;
using Component<scalar_type, index_type>::J_vals_buffer_;
using Component<scalar_type, index_type>::variable_indices_;
using Component<scalar_type, index_type>::residual_indices_;

public:
using RealT = typename Component<ScalarT, IdxT>::RealT;
using bus_type = BusBase<ScalarT, IdxT>;
using model_data_type = BranchData<RealT, IdxT>;
using MonitorT = Model::VariableMonitor<Branch, BranchData>;

Branch(bus_type* bus1, bus_type* bus2);
Branch(bus_type* bus1,
bus_type* bus2,
RealT R,
RealT X,
RealT G,
RealT B,
RealT tap = 1.0,
RealT phase = 0.0);
Branch(bus_type* bus1, bus_type* bus2, const model_data_type& data);
using ScalarT = scalar_type;
using IdxT = index_type;
using RealT = typename Component<ScalarT, IdxT>::RealT;
using BusT = BusBase<ScalarT, IdxT>;
using ModelDataT = BranchData<RealT, IdxT>;
using MonitorT = Model::VariableMonitor<Branch, BranchData>;

Branch(BusT* bus1, BusT* bus2);
Branch(BusT* bus1,
BusT* bus2,
RealT R,
RealT X,
RealT G,
RealT B,
RealT tap = 1.0,
RealT phase = 0.0);
Branch(BusT* bus1, BusT* bus2, const ModelDataT& data);
virtual ~Branch();

virtual int setGridKitComponentID(IdxT) override final;
Expand Down Expand Up @@ -123,20 +125,22 @@ namespace GridKit
const Model::VariableMonitorBase* getMonitor() const override;

private:
void initializeParameters(const model_data_type& data);
void initializeMonitor();
void setDerivedParams();
void terminalCurrent1(ScalarT& Ir, ScalarT& Ii);
void terminalCurrent2(ScalarT& Ir, ScalarT& Ii);
bool readRealParameter(const model_data_type& data,
typename model_data_type::Parameters parameter,
RealT& target);
void initializeParameters(const ModelDataT& data);
void initializeMonitor();
void setDerivedParams();
void terminalCurrent1(ScalarT& Ir, ScalarT& Ii);
void terminalCurrent2(ScalarT& Ir, ScalarT& Ii);
bool readRealParameter(const ModelDataT& data,
typename ModelDataT::Parameters parameter,
RealT& target);

static __attribute__((always_inline)) inline void addAdmittanceContribution(RealT G,
RealT B,
const ScalarT& Vr,
const ScalarT& Vi,
ScalarT& Ir,
ScalarT& Ii);

static __attribute__((always_inline)) inline void evaluateAdmittanceBlock(RealT G,
RealT B,
const ScalarT* wb,
Expand Down Expand Up @@ -189,16 +193,16 @@ namespace GridKit
__attribute__((always_inline)) inline int evaluateBusResidual22(ScalarT*, ScalarT*, ScalarT*, ScalarT*);

private:
bus_type* bus1_;
bus_type* bus2_;
RealT R_{0.0};
RealT X_{0.0};
RealT G_{0.0};
RealT B_{0.0};
RealT tap_{1.0};
RealT phase_{0.0};
IdxT bus1_id_{0};
IdxT bus2_id_{0};
BusT* bus1_;
BusT* bus2_;
RealT R_{0.0};
RealT X_{0.0};
RealT G_{0.0};
RealT B_{0.0};
RealT tap_{1.0};
RealT phase_{0.0};
IdxT bus1_id_{0};
IdxT bus2_id_{0};

RealT g11_{0.0};
RealT b11_{0.0};
Expand Down
10 changes: 5 additions & 5 deletions GridKit/Model/PhasorDynamics/Branch/BranchData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ namespace GridKit
/**
* @brief Contains modeling data for a Branch
*
* @tparam RealT Real parameter data type
* @tparam IdxT Integer parameter data type
* @tparam real_type Real parameter data type
* @tparam index_type Integer parameter data type
*
* Integer parameters are of the same type as matrix and vector indices.
*/
template <typename RealT, typename IdxT>
struct BranchData : public ComponentData<RealT,
IdxT,
template <typename real_type, typename index_type>
struct BranchData : public ComponentData<real_type,
index_type,
BranchParameters,
BranchPorts,
BranchMonitorableVariables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ namespace GridKit
/**
* @brief Jacobian evaluation not implemented
*
* @tparam ScalarT - scalar data type
* @tparam IdxT - matrix index data type
* @return int - error code, 0 = success
*/
template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::evaluateJacobian()
template <typename scalar_type, typename index_type>
int Branch<scalar_type, index_type>::evaluateJacobian()
{
Log::misc() << "Evaluate Jacobian for Branch..." << std::endl;
Log::misc() << "Jacobian evaluation is not implemented!" << std::endl;
Expand Down
6 changes: 2 additions & 4 deletions GridKit/Model/PhasorDynamics/Branch/BranchEnzyme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ namespace GridKit
/**
* @brief Jacobian evaluation experimental
*
* @tparam ScalarT - scalar data type
* @tparam IdxT - matrix index data type
* @return int - error code, 0 = success
*/
template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::evaluateJacobian()
template <typename scalar_type, typename index_type>
int Branch<scalar_type, index_type>::evaluateJacobian()
{
Log::misc() << "Evaluate Jacobian for Branch..." << std::endl;
Log::misc() << "Jacobian evaluation is experimental!" << std::endl;
Expand Down
Loading
Loading