rts-sim-module/sys/iscs_sys/iscs_pscada_rectifier.go
2024-01-05 15:21:29 +08:00

86 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 := perfectPipeElectricity(portLPipeEntry)
//
portZPipeEntry := wd.EntityMap[portZ.Device().Id()]
portZPipe := perfectPipeElectricity(portZPipeEntry)
portFPipeEntry := wd.EntityMap[portF.Device().Id()]
portFPipe := perfectPipeElectricity(portFPipeEntry)
//L->Z、F
for lpsId, lps := range portLPipe.Sources {
if lps.Ac {
dcVoltage := uint32(float64(lps.U) * 0.9) //交流电压转直流电压
//L->Z
zps, zpsOk := portZPipe.Sources[lpsId]
if zpsOk {
zps.U = dcVoltage
zps.Fresh = lps.Fresh - 1
zps.Ac = false
zps.Sx = false
} else {
portZPipe.Sources[lpsId] = &component.ElectricitySource{Ac: false, Sx: false, U: dcVoltage, Fresh: lps.Fresh - 1}
}
//L->F
fps, fpsOk := portFPipe.Sources[lpsId]
dcFVoltage := uint32(0)
if dcVoltage > 0 {
dcFVoltage = 1
}
if fpsOk {
fps.U = dcFVoltage
fps.Fresh = lps.Fresh - 1
fps.Ac = false
fps.Sx = false
} else {
portFPipe.Sources[lpsId] = &component.ElectricitySource{Ac: false, Sx: false, U: dcFVoltage, Fresh: lps.Fresh - 1}
}
}
}
}