iscs pscada 一次图 电力传递实现

This commit is contained in:
xzb 2023-12-22 09:46:11 +08:00
parent f0433ef838
commit f5c28fcdec
8 changed files with 140 additions and 116 deletions

View File

@ -49,9 +49,7 @@ const (
// Rectifier 整流器
// 具体异常-故障、报警、通信中断
type Rectifier struct {
Normal bool //true-正常
InputAcV uint32 //输入交流电压
OutputDcV uint32 //输出直流电压
Normal bool //true-正常
}
// Disconnector 隔离开关
@ -74,9 +72,7 @@ type LightningArrester struct {
// VoltageTransformer 变压器
// 具体异常-故障、报警、通信中断
type VoltageTransformer struct {
Normal bool //true-正常
InputV uint32 //输入电压值单位V
OutputV uint32 //输出电压值单位V
Normal bool //true-正常
}
////////////////////////////////////////////////////////////
@ -92,8 +88,11 @@ func (p *PowerPipe) TransPower(powerSourceId string, power *ElePower) {
ep, ok := p.Sources[powerSourceId]
if ok {
*ep = *power
ep.Fresh -= 1
} else {
p.Sources[powerSourceId] = power
p.Sources[powerSourceId] = &ElePower{}
*p.Sources[powerSourceId] = *power
p.Sources[powerSourceId].Fresh -= 1
}
}

View File

@ -5,6 +5,7 @@ import (
"joylink.club/rtsssimulation/sys/circuit_sys"
"joylink.club/rtsssimulation/sys/common_sys"
"joylink.club/rtsssimulation/sys/device_sys"
"joylink.club/rtsssimulation/sys/iscs_sys"
)
// 添加系统到World
@ -41,3 +42,18 @@ func BindSystem(w ecs.World) {
device_sys.NewBaliseSystem(),
)
}
// ISCS 系统
func bindIscsSystem(w ecs.World) {
w.AddSystem(iscs_sys.NewIscsExceptionSystem(),
iscs_sys.NewDevicePlacingSystem(),
iscs_sys.NewPowerSourceSystem(),
iscs_sys.NewCircuitBreakerSystem(),
iscs_sys.NewDisconnectorSystem(),
iscs_sys.NewHandcartSystem(),
iscs_sys.NewThreePositionSwitchSystem(),
iscs_sys.NewPipeFittingSystem(),
iscs_sys.NewRectifierSystem(),
iscs_sys.NewVoltageTransformerSystem(),
iscs_sys.NewPowerPipeSystem())
}

View File

@ -14,7 +14,7 @@ type CircuitBreakerSystem struct {
func NewCircuitBreakerSystem() *CircuitBreakerSystem {
return &CircuitBreakerSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.CircuitBreakerType, component.DeviceExceptionType)),
query: ecs.NewQuery(filter.Contains(component.UidType, component.CircuitBreakerType)),
}
}
func (s *CircuitBreakerSystem) Update(w ecs.World) {

View File

@ -14,7 +14,7 @@ type DisconnectorSystem struct {
func NewDisconnectorSystem() *DisconnectorSystem {
return &DisconnectorSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.DisconnectorType, component.DeviceExceptionType)),
query: ecs.NewQuery(filter.Contains(component.UidType, component.DisconnectorType)),
}
}
func (s *DisconnectorSystem) Update(w ecs.World) {

View File

@ -14,7 +14,7 @@ type HandcartSystem struct {
func NewHandcartSystem() *HandcartSystem {
return &HandcartSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.HandcartSwitchType, component.DeviceExceptionType)),
query: ecs.NewQuery(filter.Contains(component.UidType, component.HandcartSwitchType)),
}
}
func (s *HandcartSystem) Update(w ecs.World) {

View File

@ -19,65 +19,66 @@ func NewRectifierSystem() *RectifierSystem {
}
}
func (s *RectifierSystem) Update(w ecs.World) {
wd := entity.GetWorldData(w)
s.query.Each(w, func(entry *ecs.Entry) {
rectifier := component.RectifierType.Get(entry)
exception := component.DeviceExceptionType.Get(entry)
//
rectifier.Normal = exception.Exception == consts.DeviceExceptionNon
s.rectifierTransPower(wd, entry)
s.rectifier(wd, entry)
})
}
// 整流器其他一般信息计算收集
func (s *RectifierSystem) rectifier(wd *component.WorldData, entry *ecs.Entry) {
rectifier := component.RectifierType.Get(entry)
exception := component.DeviceExceptionType.Get(entry)
//
s.rectifierTransPower(w)
rectifier.Normal = exception.Exception == consts.DeviceExceptionNon
}
// 整流器电能传递
// 当线路接通时零线和负极电压规定值为1当线路断开时零线和负极电压规定值为0
func (s *RectifierSystem) rectifierTransPower(w ecs.World) {
wd := entity.GetWorldData(w)
s.query.Each(w, func(entry *ecs.Entry) {
rectifierId := component.UidType.Get(entry).Id
rectifierModel := wd.Repo.FindById(rectifierId).(*repository.Rectifier)
//
portL := rectifierModel.PortA //交火
//portN := rectifierModel.PortB //交零
portZ := rectifierModel.PortC //直正
portF := rectifierModel.PortD //直负
//
portLPipeEntry := wd.EntityMap[portL.Device().Id()]
portLPipe := component.PowerPipeType.Get(portLPipeEntry)
//
portZPipeEntry := wd.EntityMap[portZ.Device().Id()]
portZPipe := component.PowerPipeType.Get(portZPipeEntry)
portFPipeEntry := wd.EntityMap[portF.Device().Id()]
portFPipe := component.PowerPipeType.Get(portFPipeEntry)
//L->Z、F
for lpsId, lps := range portLPipe.Sources {
if lps.Ac {
dcVoltage := uint32(float64(lps.Voltage) * 0.9) //交流电压转直流电压
//L->Z
zps, zpsOk := portZPipe.Sources[lpsId]
if zpsOk {
zps.Voltage = dcVoltage
zps.Fresh = lps.Fresh - 1
zps.Ac = false
} else {
portZPipe.Sources[lpsId] = &component.ElePower{Ac: false, Voltage: dcVoltage, Fresh: lps.Fresh - 1}
}
//L->F
fps, fpsOk := portFPipe.Sources[lpsId]
dcFVoltage := uint32(0)
if dcVoltage > 0 {
dcFVoltage = 1
}
if fpsOk {
fps.Voltage = dcFVoltage
fps.Fresh = lps.Fresh - 1
fps.Ac = false
} else {
portFPipe.Sources[lpsId] = &component.ElePower{Ac: false, Voltage: dcFVoltage, Fresh: lps.Fresh - 1}
}
func (s *RectifierSystem) rectifierTransPower(wd *component.WorldData, entry *ecs.Entry) {
rectifierId := component.UidType.Get(entry).Id
rectifierModel := wd.Repo.FindById(rectifierId).(*repository.Rectifier)
//
portL := rectifierModel.PortA //交火
//portN := rectifierModel.PortB //交零
portZ := rectifierModel.PortC //直正
portF := rectifierModel.PortD //直负
//
portLPipeEntry := wd.EntityMap[portL.Device().Id()]
portLPipe := component.PowerPipeType.Get(portLPipeEntry)
//
portZPipeEntry := wd.EntityMap[portZ.Device().Id()]
portZPipe := component.PowerPipeType.Get(portZPipeEntry)
portFPipeEntry := wd.EntityMap[portF.Device().Id()]
portFPipe := component.PowerPipeType.Get(portFPipeEntry)
//L->Z、F
for lpsId, lps := range portLPipe.Sources {
if lps.Ac {
dcVoltage := uint32(float64(lps.Voltage) * 0.9) //交流电压转直流电压
//L->Z
zps, zpsOk := portZPipe.Sources[lpsId]
if zpsOk {
zps.Voltage = dcVoltage
zps.Fresh = lps.Fresh - 1
zps.Ac = false
} else {
portZPipe.Sources[lpsId] = &component.ElePower{Ac: false, Voltage: dcVoltage, Fresh: lps.Fresh - 1}
}
//L->F
fps, fpsOk := portFPipe.Sources[lpsId]
dcFVoltage := uint32(0)
if dcVoltage > 0 {
dcFVoltage = 1
}
if fpsOk {
fps.Voltage = dcFVoltage
fps.Fresh = lps.Fresh - 1
fps.Ac = false
} else {
portFPipe.Sources[lpsId] = &component.ElePower{Ac: false, Voltage: dcFVoltage, Fresh: lps.Fresh - 1}
}
}
}
})
}

View File

@ -14,7 +14,7 @@ type ThreePositionSwitchSystem struct {
func NewThreePositionSwitchSystem() *ThreePositionSwitchSystem {
return &ThreePositionSwitchSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.ThreePositionSwitchType, component.DeviceExceptionType)),
query: ecs.NewQuery(filter.Contains(component.UidType, component.ThreePositionSwitchType)),
}
}

View File

@ -4,6 +4,7 @@ import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/repository"
)
@ -18,63 +19,70 @@ func NewVoltageTransformerSystem() *VoltageTransformerSystem {
}
}
func (s *VoltageTransformerSystem) Update(w ecs.World) {
s.voltageTransformerTransPower(w)
wd := entity.GetWorldData(w)
s.query.Each(w, func(entry *ecs.Entry) {
s.voltageTransformerTransPower(wd, entry)
s.voltageTransformer(wd, entry)
})
}
func (s *VoltageTransformerSystem) voltageTransformer(wd *component.WorldData, entry *ecs.Entry) {
vt := component.VoltageTransformerType.Get(entry)
vt.Normal = component.DeviceExceptionType.Get(entry).Exception == consts.DeviceExceptionNon
}
// 变压器电力传递
func (s *VoltageTransformerSystem) voltageTransformerTransPower(w ecs.World) {
wd := entity.GetWorldData(w)
s.query.Each(w, func(entry *ecs.Entry) {
vtId := component.UidType.Get(entry).Id
vtModel := wd.Repo.FindById(vtId).(*repository.VoltageTransformer)
//
vtPortA := vtModel.PortA
vtPortAEntry := wd.EntityMap[vtPortA.Device().Id()]
vtPortAPipe := component.PowerPipeType.Get(vtPortAEntry) //变压器一次侧连接的管线
//
var vtPortBPipe *component.PowerPipe = nil
if vtModel.PortB != nil {
vtPortB := vtModel.PortB
vtPortBEntry := wd.EntityMap[vtPortB.Device().Id()]
vtPortBPipe = component.PowerPipeType.Get(vtPortBEntry)
}
//
var vtPortCPipe *component.PowerPipe = nil
if vtModel.PortC != nil {
vtPortC := vtModel.PortC
vtPortCEntry := wd.EntityMap[vtPortC.Device().Id()]
vtPortCPipe = component.PowerPipeType.Get(vtPortCEntry)
}
//变压比
rate := float64(vtModel.E2) / float64(vtModel.E1)
//A->B、C ,电能从一次侧向二次侧传递
for psId, ps := range vtPortAPipe.Sources {
//二次侧输出电压
outV := uint32(rate * float64(ps.Voltage))
if vtPortBPipe != nil { //二次侧火线
portBPs, ok := vtPortBPipe.Sources[psId]
if ok {
portBPs.Voltage = outV
portBPs.Ac = ps.Ac
portBPs.Fresh = ps.Fresh - 1
} else {
vtPortBPipe.Sources[psId] = &component.ElePower{Ac: ps.Ac, Voltage: outV, Fresh: ps.Fresh - 1}
}
}
if vtPortCPipe != nil { //二次侧零线
portCPs, ok := vtPortCPipe.Sources[psId]
cV := uint32(0)
if outV > 0 { //当二次火线电压大于零时二次侧零线电压值1表示零电位
cV = 1
}
if ok {
portCPs.Voltage = cV
portCPs.Ac = ps.Ac
portCPs.Fresh = ps.Fresh - 1
} else {
vtPortCPipe.Sources[psId] = &component.ElePower{Ac: ps.Ac, Voltage: cV, Fresh: ps.Fresh - 1}
}
func (s *VoltageTransformerSystem) voltageTransformerTransPower(wd *component.WorldData, entry *ecs.Entry) {
vtId := component.UidType.Get(entry).Id
vtModel := wd.Repo.FindById(vtId).(*repository.VoltageTransformer)
//
vtPortA := vtModel.PortA
vtPortAEntry := wd.EntityMap[vtPortA.Device().Id()]
vtPortAPipe := component.PowerPipeType.Get(vtPortAEntry) //变压器一次侧连接的管线
//
var vtPortBPipe *component.PowerPipe = nil
if vtModel.PortB != nil {
vtPortB := vtModel.PortB
vtPortBEntry := wd.EntityMap[vtPortB.Device().Id()]
vtPortBPipe = component.PowerPipeType.Get(vtPortBEntry)
}
//
var vtPortCPipe *component.PowerPipe = nil
if vtModel.PortC != nil {
vtPortC := vtModel.PortC
vtPortCEntry := wd.EntityMap[vtPortC.Device().Id()]
vtPortCPipe = component.PowerPipeType.Get(vtPortCEntry)
}
//变压比
rate := float64(vtModel.E2) / float64(vtModel.E1)
//A->B、C ,电能从一次侧向二次侧传递
for psId, ps := range vtPortAPipe.Sources {
//二次侧输出电压
outV := uint32(rate * float64(ps.Voltage))
if vtPortBPipe != nil { //二次侧火线
portBPs, ok := vtPortBPipe.Sources[psId]
if ok {
portBPs.Voltage = outV
portBPs.Ac = ps.Ac
portBPs.Fresh = ps.Fresh - 1
} else {
vtPortBPipe.Sources[psId] = &component.ElePower{Ac: ps.Ac, Voltage: outV, Fresh: ps.Fresh - 1}
}
}
})
if vtPortCPipe != nil { //二次侧零线
portCPs, ok := vtPortCPipe.Sources[psId]
cV := uint32(0)
if outV > 0 { //当二次火线电压大于零时二次侧零线电压值1表示零电位
cV = 1
}
if ok {
portCPs.Voltage = cV
portCPs.Ac = ps.Ac
portCPs.Fresh = ps.Fresh - 1
} else {
vtPortCPipe.Sources[psId] = &component.ElePower{Ac: ps.Ac, Voltage: cV, Fresh: ps.Fresh - 1}
}
}
}
}