rts-sim-module/sys/iscs_sys/iscs_pscada_rectifier.go
2023-12-22 15:29:57 +08:00

84 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/repository"
)
type RectifierSystem struct {
query *ecs.Query
}
func NewRectifierSystem() *RectifierSystem {
return &RectifierSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.RectifierType, component.DeviceExceptionType)),
}
}
func (s *RectifierSystem) Update(w ecs.World) {
wd := entity.GetWorldData(w)
s.query.Each(w, func(entry *ecs.Entry) {
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)
//
rectifier.Normal = exception.Exception.Non()
}
// 整流器电能传递
// 当线路接通时零线和负极电压规定值为1当线路断开时零线和负极电压规定值为0
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}
}
}
}
}