📄 bus.h
字号:
#ifndef NODE_H
#define NODE_H
#include <string>
#include <boost/assert.hpp>
#include <boost/io/ios_state.hpp>
#include "Defs.h"
class ACBus {
public:
ACBus() : NodeType(PQ), P(0.0), Q(0.0), V(1.0) {}
// 按标准格式的定义
int Num;
char Name[20];
int AreaNum;
int LossZoneNum;
int NodeType;
double Fv; // Final voltage (p.u.)
double Fa; // Final angle (degree)
double Lp; // Load (MW)
double Lq; // Load (MVar)
double Gp; // Generation (MW)
double Gq; // Generation (MVAR)
double BaseVolt; // Base (kV)
double DesireVolt; // Desired volts (p.u.)
double MaxVarOrV; // Maximum MVAR or voltage limit
double MinVarOrV; // Minimum MVAR or voltage limit
double ShuntG; // Shunt conductance G (p.u.)
double ShuntB; // Shunt susceptance B (p.u.)
int RemoteBusNum; // Remote controlled bus number
double P; //节点的净功率
double Q;
double V;
};
// 2008.04.12 The class for modeling a DC bus.
class DCBus {
template < class IStream > friend IStream& operator >> ( IStream&, DCBus& );
public:
// DC bus types.
class Type {
friend class DCBus;
template < class IStream > friend IStream& operator >> ( IStream&, Type& );
friend bool operator == ( Type const&, Type const& );
friend bool operator != ( Type const&, Type const& );
private:
typedef int TypeCode;
explicit Type( TypeCode code ) : code_(code) {}
private:
TypeCode code_;
};
// Predefined DC bus types.
static const Type RECTIFIER; // +1 - Rectifier bus.
static const Type INVERTER; // -1 - Inverter bus.
public:
// DC bus control mode.
// Currently, each DC bus should have only one mode at the same time.
class CtrlMode {
friend class DCBus;
template < class IStream > friend IStream& operator >> ( IStream&, CtrlMode& );
friend bool operator == ( CtrlMode const&, CtrlMode const& );
friend bool operator != ( CtrlMode const&, CtrlMode const& );
public:
typedef unsigned int ModeCode;
private:
explicit CtrlMode( ModeCode code ) : code_(code) {}
private:
ModeCode code_;
};
// Predefined DC bus control modes.
public:
static const CtrlMode POWER; // 0x01 - Constant DC power mode.
static const CtrlMode VOLTAGE; // 0x02 - Constant DC voltage mode.
static const CtrlMode CURRENT; // 0x04 - Constant DC current mode.
static const CtrlMode ANGLE; // 0x08 - Constant DC control angle mode.
static const CtrlMode TAP; // 0x10 - Constant converting transformer tap mode.
private:
static const CtrlMode UNDEF; // 0x00 - Undefined mode.
public:
DCBus() : id_(0), type_(0), mode_(UNDEF), name_("Bad DC bus") {}
int GetID() const { return id_; }
std::string const& GetName() const { return name_; }
Type GetType() const { return type_; }
CtrlMode const& GetCtrlMode() const { return mode_; }
void SetCtrlMode( CtrlMode const& mode ) { mode_ = mode; }
double GetVoltBase() const { return volt_base_; }
double GetPower() const { return power_; }
void SetPower( double power ) { power_ = power; }
double GetVoltage() const { return voltage_; }
void SetVoltage( double voltage ) { voltage_ = voltage; }
double GetCurrent() const { return current_; }
void SetCurrent( double current ) { current_ = current; }
double GetAngle() const { return angle_; }
void SetAngle( double angle ) { angle_ = angle; }
double GetTap() const { return tap_; }
void SetTap( double tap ) { tap_ = tap; }
double GetFactor() const { return factor_; }
void SetFactor( double factor ) { factor_ = factor; }
double GetCommtX() const { return Xc_; }
double GetTransX() const { return Xt_; }
double GetMaxTap() const { return max_tap_; }
double GetMinTap() const { return min_tap_; }
double GetTapStep() const { return tap_step_; }
double GetMaxAngle() const { return max_angle_; }
double GetMinAngle() const { return min_angle_; }
private:
int id_;
int load_area_;
int loss_zone_;
int bridge_count_; // The number of converting bridges.
double volt_base_; // DC voltage base (kV).
double power_; // DC power demand (p.u.).
double voltage_; // DC voltage (p.u.).
double current_; // DC current (p.u.).
double angle_; // DC control angle (rad).
double tap_; // Commutating transformer tap.
double factor_; // Equivalent AC power factor.
double Xt_; // Commutating transformer reactance (p.u.).
double max_tap_; // Maximum tap of the commutating transformer.
double min_tap_; // Minimum tap of the commutating transformer.
double tap_step_; // Tap step of the commutating transformer.
double Xc_; // Commutation resistance (p.u.).
double max_angle_; // Maximum control angle (rad).
double min_angle_; // Minimum control angle (rad).
Type type_; // DC bus type.
CtrlMode mode_; // DC mixed control mode.
std::string name_;
};
template < class IStream >
IStream& operator >> ( IStream& in, DCBus& bus )
{
typedef DCBus::Type Type;
typedef DCBus::CtrlMode CtrlMode;
static double const deg2rad = PI / 180.0;
if( in.eof() ) {
in.setstate( std::ios::failbit | std::ios::eofbit );
return in;
}
boost::io::ios_exception_saver ies(in);
in.exceptions( std::ios::failbit | std::ios::badbit );
in >> bus.id_;
BOOST_ASSERT( bus.id_ > 0 );
in >> bus.name_;
in >> bus.load_area_;
in >> bus.loss_zone_;
in >> bus.type_;
in >> bus.mode_;
if ( bus.mode_ == DCBus::POWER ) {
in >> bus.power_;
} else if ( bus.mode_ == DCBus::VOLTAGE ) {
in >> bus.voltage_;
} else if ( bus.mode_ == DCBus::CURRENT ) {
in >> bus.current_;
} else if ( bus.mode_ == DCBus::ANGLE ) {
in >> bus.angle_;
bus.angle_ *= PI / 180.0;
} else if ( bus.mode_ == DCBus::TAP ) {
in >> bus.tap_;
} else {
// Unknown control mode.
BOOST_ASSERT(false);
}
in >> bus.angle_;
bus.angle_ *= deg2rad;
in >> bus.volt_base_;
BOOST_ASSERT( bus.volt_base_ > 0.0 );
in >> bus.bridge_count_;
BOOST_ASSERT( bus.bridge_count_ > 0 );
in >> bus.Xc_;
in >> bus.Xt_;
in >> bus.max_tap_;
in >> bus.min_tap_;
in >> bus.tap_step_;
BOOST_ASSERT( 0.0 < bus.min_tap_ && bus.min_tap_ < bus.max_tap_ );
BOOST_ASSERT( 0.0 < bus.tap_step_ && bus.tap_step_ < 1.0 );
in >> bus.max_angle_;
in >> bus.min_angle_;
BOOST_ASSERT( bus.min_angle_ <= bus.max_angle_ );
bus.max_angle_ *= PI / 180.0;
bus.min_angle_ *= PI / 180.0;
return in;
}
template < class IStream >
#ifdef NDEBUG
inline
#endif
IStream& operator >> ( IStream& in, DCBus::Type& type )
{
in >> type.code_;
BOOST_ASSERT(
type == DCBus::RECTIFIER ||
type == DCBus::INVERTER
);
return in;
}
inline
bool operator == ( DCBus::Type const& lhs, DCBus::Type const& rhs )
{
return lhs.code_ == rhs.code_;
}
inline
bool operator != ( DCBus::Type const& lhs, DCBus::Type const& rhs )
{
return lhs.code_ != rhs.code_;
}
template < class IStream >
#ifdef NDEBUG
inline
#endif
IStream& operator >> ( IStream& in, DCBus::CtrlMode& mode )
{
typedef DCBus::CtrlMode::ModeCode ModeCode;
in >> mode.code_;
BOOST_ASSERT(
mode == DCBus::POWER ||
mode == DCBus::VOLTAGE ||
mode == DCBus::CURRENT ||
mode == DCBus::ANGLE ||
mode == DCBus::TAP
);
return in;
}
inline
bool operator == ( DCBus::CtrlMode const& lhs, DCBus::CtrlMode const& rhs )
{
return lhs.code_ == rhs.code_;
}
inline
bool operator != ( DCBus::CtrlMode const& lhs, DCBus::CtrlMode const& rhs )
{
return lhs.code_ != rhs.code_;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -