diff --git a/sys/iscs_sys/iscs_pscada_circuit_breaker.go b/sys/iscs_sys/iscs_pscada_circuit_breaker.go new file mode 100644 index 0000000..f468522 --- /dev/null +++ b/sys/iscs_sys/iscs_pscada_circuit_breaker.go @@ -0,0 +1,93 @@ +package iscs_sys + +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/entity" + "joylink.club/rtsssimulation/repository" +) + +type CircuitBreakerSystem struct { + query *ecs.Query +} + +func NewCircuitBreakerSystem() *CircuitBreakerSystem { + return &CircuitBreakerSystem{ + query: ecs.NewQuery(filter.Contains(component.UidType, component.CircuitBreakerType)), + } +} +func (s *CircuitBreakerSystem) Update(w ecs.World) { + s.circuitBreakerTransPower(w) + +} + +// 断路器传递电能 +func (s *CircuitBreakerSystem) circuitBreakerTransPower(w ecs.World) { + wd := entity.GetWorldData(w) + s.query.Each(w, func(entry *ecs.Entry) { + breakerId := component.UidType.Get(entry).Id + closed := component.CircuitBreakerType.Get(entry).Closed + breakerModel := (wd.Repo.FindById(breakerId)).(*repository.CircuitBreaker) + //断路器A端连接的管线 + breakerPortA := breakerModel.PortA + //断路器B端连接的管线 + breakerPortB := breakerModel.PortB + //传递电能 + towPipePortsTransPower(wd, closed, breakerPortA, breakerPortB) + }) +} + +// 两位置开关传递电能(断路器、手车、隔离开关) +func towPipePortsTransPower( + wd *component.WorldData, + closed bool, + breakerPortA *repository.PipePort, + breakerPortB *repository.PipePort) { + //断路器A端连接的管线 + breakerPortAPipeEntry := wd.EntityMap[breakerPortA.Device().Id()] + breakerPortAPipe := component.PowerPipeType.Get(breakerPortAPipeEntry) + //断路器B端连接的管线 + breakerPortBPipeEntry := wd.EntityMap[breakerPortB.Device().Id()] + breakerPortBPipe := component.PowerPipeType.Get(breakerPortBPipeEntry) + //A->B + for portAPipePsId, portAPipePs := range breakerPortAPipe.Sources { //A + portBPipePs, ok := breakerPortBPipe.Sources[portAPipePsId] //B + if ok { + if portAPipePs.Fresh > portBPipePs.Fresh { + *breakerPortBPipe.Sources[portAPipePsId] = *portAPipePs + breakerPortBPipe.Sources[portAPipePsId].Fresh -= 1 + if !closed { + breakerPortBPipe.Sources[portAPipePsId].Voltage = 0 + } + } + } else { + breakerPortBPipe.Sources[portAPipePsId] = &component.ElePower{} + *breakerPortBPipe.Sources[portAPipePsId] = *portAPipePs + breakerPortBPipe.Sources[portAPipePsId].Fresh -= 1 + if !closed { + breakerPortBPipe.Sources[portAPipePsId].Voltage = 0 + } + } + } + //B->A + for portBPipePsId, portBPipePs := range breakerPortBPipe.Sources { //B + portAPipePs, ok := breakerPortAPipe.Sources[portBPipePsId] //A + if ok { + if portBPipePs.Fresh > portAPipePs.Fresh { + *breakerPortAPipe.Sources[portBPipePsId] = *portBPipePs + breakerPortAPipe.Sources[portBPipePsId].Fresh -= 1 + if !closed { + breakerPortAPipe.Sources[portBPipePsId].Voltage = 0 + } + } + } else { + breakerPortAPipe.Sources[portBPipePsId] = &component.ElePower{} + *breakerPortAPipe.Sources[portBPipePsId] = *portBPipePs + breakerPortAPipe.Sources[portBPipePsId].Fresh -= 1 + if !closed { + breakerPortAPipe.Sources[portBPipePsId].Voltage = 0 + } + } + } +} diff --git a/sys/iscs_sys/iscs_pscada_disconnector.go b/sys/iscs_sys/iscs_pscada_disconnector.go new file mode 100644 index 0000000..46d5967 --- /dev/null +++ b/sys/iscs_sys/iscs_pscada_disconnector.go @@ -0,0 +1,35 @@ +package iscs_sys + +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/entity" + "joylink.club/rtsssimulation/repository" +) + +type DisconnectorSystem struct { + query *ecs.Query +} + +func NewDisconnectorSystem() *DisconnectorSystem { + return &DisconnectorSystem{ + query: ecs.NewQuery(filter.Contains(component.UidType, component.DisconnectorType)), + } +} +func (s *DisconnectorSystem) Update(w ecs.World) { + s.disconnectorTransPower(w) +} + +// 隔离开关传递电能 +func (s *DisconnectorSystem) disconnectorTransPower(w ecs.World) { + wd := entity.GetWorldData(w) + s.query.Each(w, func(entry *ecs.Entry) { + breakerId := component.UidType.Get(entry).Id + closed := component.DisconnectorType.Get(entry).Closed + breakerModel := (wd.Repo.FindById(breakerId)).(*repository.Disconnector) + breakerPortA := breakerModel.PortA + breakerPortB := breakerModel.PortB + towPipePortsTransPower(wd, closed, breakerPortA, breakerPortB) + }) +} diff --git a/sys/iscs_sys/iscs_pscada_handcart.go b/sys/iscs_sys/iscs_pscada_handcart.go new file mode 100644 index 0000000..ed4e273 --- /dev/null +++ b/sys/iscs_sys/iscs_pscada_handcart.go @@ -0,0 +1,35 @@ +package iscs_sys + +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/entity" + "joylink.club/rtsssimulation/repository" +) + +type HandcartSystem struct { + query *ecs.Query +} + +func NewHandcartSystem() *HandcartSystem { + return &HandcartSystem{ + query: ecs.NewQuery(filter.Contains(component.UidType, component.HandcartSwitchType)), + } +} +func (s *HandcartSystem) Update(w ecs.World) { + s.handcartTransPower(w) +} + +// 手车传递电能 +func (s *HandcartSystem) handcartTransPower(w ecs.World) { + wd := entity.GetWorldData(w) + s.query.Each(w, func(entry *ecs.Entry) { + breakerId := component.UidType.Get(entry).Id + closed := component.HandcartSwitchType.Get(entry).Position == component.HpClosed + breakerModel := (wd.Repo.FindById(breakerId)).(*repository.HandcartSwitch) + breakerPortA := breakerModel.PortA + breakerPortB := breakerModel.PortB + towPipePortsTransPower(wd, closed, breakerPortA, breakerPortB) + }) +} diff --git a/sys/iscs_sys/iscs_pscada_pipe_fitting.go b/sys/iscs_sys/iscs_pscada_pipe_fitting.go new file mode 100644 index 0000000..2c6c1bd --- /dev/null +++ b/sys/iscs_sys/iscs_pscada_pipe_fitting.go @@ -0,0 +1,59 @@ +package iscs_sys + +import ( + "joylink.club/ecs" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/entity" +) + +type PipeFittingSystem struct { +} + +func NewPipeFittingSystem() *PipeFittingSystem { + return &PipeFittingSystem{} +} + +// Update 母线管件电能传递 +func (s *PipeFittingSystem) Update(w ecs.World) { + wd := entity.GetWorldData(w) + for _, pf := range wd.Repo.PipeFittingMap { + if pf.IsEle() { + //与管件连接的所有管线 + pipes := pf.Ports() + //筛选出相对电源 + pipePsMap := make(map[string]*component.ElePower) + for _, pipePort := range pipes { + pipeEntry := wd.EntityMap[pipePort.Device().Id()] + powerPipe := component.PowerPipeType.Get(pipeEntry) + for epId, ep := range powerPipe.Sources { + pipePs, ok := pipePsMap[epId] + if ok { + if ep.Fresh > pipePs.Fresh { + pipePsMap[epId] = ep + } + } else { + pipePsMap[epId] = ep + } + } + } + //管件连接的管线间电能传递 + for _, pipePort := range pipes { + for pipePsId, pipePs := range pipePsMap { //相对电源 + pipeEntry := wd.EntityMap[pipePort.Device().Id()] + powerPipe := component.PowerPipeType.Get(pipeEntry) + pipePortPs, ok := powerPipe.Sources[pipePsId] + if ok { + if pipePs.Fresh > pipePortPs.Fresh { + *powerPipe.Sources[pipePsId] = *pipePs + powerPipe.Sources[pipePsId].Fresh -= 1 //保证相对性 + } + } else { + powerPipe.Sources[pipePsId] = &component.ElePower{} + *powerPipe.Sources[pipePsId] = *pipePs + powerPipe.Sources[pipePsId].Fresh -= 1 //保证相对性 + } + } + } + } + } +} diff --git a/sys/iscs_sys/iscs_pscada_power_pipe.go b/sys/iscs_sys/iscs_pscada_power_pipe.go new file mode 100644 index 0000000..a49ecfc --- /dev/null +++ b/sys/iscs_sys/iscs_pscada_power_pipe.go @@ -0,0 +1,35 @@ +package iscs_sys + +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" +) + +type PowerPipeSystem struct { + query *ecs.Query +} + +func NewPowerPipeSystem() *PowerPipeSystem { + return &PowerPipeSystem{ + query: ecs.NewQuery(filter.Contains(component.PowerPipeType)), + } +} + +// Update 电力母线中电力计算 +func (s *PowerPipeSystem) Update(w ecs.World) { + s.query.Each(w, func(entry *ecs.Entry) { + pipe := component.PowerPipeType.Get(entry) + voltage := uint32(0) + ac := false + for _, power := range pipe.Sources { + if power.Voltage > voltage { + voltage = power.Voltage + ac = power.Ac + } + } + // + pipe.Voltage = voltage + pipe.Ac = ac + }) +} diff --git a/sys/iscs_sys/iscs_pscada_power_souce.go b/sys/iscs_sys/iscs_pscada_power_souce.go new file mode 100644 index 0000000..0b78a6e --- /dev/null +++ b/sys/iscs_sys/iscs_pscada_power_souce.go @@ -0,0 +1,34 @@ +package iscs_sys + +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/entity" + "joylink.club/rtsssimulation/repository" + "time" +) + +type PowerSourceSystem struct { + query *ecs.Query +} + +func NewPowerSourceSystem() *PowerSourceSystem { + return &PowerSourceSystem{ + query: ecs.NewQuery(filter.Contains(component.UidType, component.PowerSourceType)), + } +} +func (s *PowerSourceSystem) Update(w ecs.World) { + wd := entity.GetWorldData(w) + s.query.Each(w, func(entry *ecs.Entry) { + psId := component.UidType.Get(entry).Id + ps := component.PowerSourceType.Get(entry) + // + psModel := (wd.Repo.FindById(psId)).(*repository.PowerSource) + pipeId := psModel.PortA.Device().Id() + //电源传递电力给母线 + pipeEntry := wd.EntityMap[pipeId] + powerPipe := component.PowerPipeType.Get(pipeEntry) + powerPipe.TransPower(psId, &component.ElePower{Ac: ps.Ac, Voltage: ps.Voltage, Fresh: time.Now().UnixMilli()}) + }) +} diff --git a/sys/iscs_sys/iscs_pscada_power_transmission.go b/sys/iscs_sys/iscs_pscada_power_transmission.go deleted file mode 100644 index 050b245..0000000 --- a/sys/iscs_sys/iscs_pscada_power_transmission.go +++ /dev/null @@ -1,283 +0,0 @@ -package iscs_sys - -import ( - "joylink.club/ecs" - "joylink.club/ecs/filter" - "joylink.club/rtsssimulation/component" - "joylink.club/rtsssimulation/entity" - "joylink.club/rtsssimulation/repository" - "time" -) - -// PowerTransmissionSystem 电力传递系统(电压传递) -type PowerTransmissionSystem struct { - queryPowerSource *ecs.Query //电力电源 - queryPowerPipe *ecs.Query //电力母线 - queryCircuitBreaker *ecs.Query //断路器 - queryHandcart *ecs.Query //手车 - queryDisconnector *ecs.Query //隔离开关 - query3PositionSwitch *ecs.Query //三工位隔离开关 - queryRectifier *ecs.Query //整流器 -} - -func NewPowerTransmissionSystem() *PowerTransmissionSystem { - return &PowerTransmissionSystem{ - queryPowerSource: ecs.NewQuery(filter.Contains(component.UidType, component.PowerSourceType)), - queryPowerPipe: ecs.NewQuery(filter.Contains(component.PowerPipeType)), - queryCircuitBreaker: ecs.NewQuery(filter.Contains(component.UidType, component.CircuitBreakerType)), - queryHandcart: ecs.NewQuery(filter.Contains(component.UidType, component.HandcartSwitchType)), - queryDisconnector: ecs.NewQuery(filter.Contains(component.UidType, component.DisconnectorType)), - query3PositionSwitch: ecs.NewQuery(filter.Contains(component.UidType, component.ThreePositionSwitchType)), - queryRectifier: ecs.NewQuery(filter.Contains(component.UidType, component.RectifierType)), - } -} -func (s *PowerTransmissionSystem) Update(w ecs.World) { - s.powerSourceTransPower(w) - s.circuitBreakerTransPower(w) - s.handcartTransPower(w) - s.disconnectorTransPower(w) - s.threePositionSwitchTransPower(w) - s.pipeFittingTransPower(w) - s.rectifierTransPower(w) - s.powerPipePower(w) -} - -// 整流器电能传递 -// 当线路接通时零线和负极电压规定值为1,当线路断开时零线和负极电压规定值为0 -func (s *PowerTransmissionSystem) rectifierTransPower(w ecs.World) { - wd := entity.GetWorldData(w) - s.queryRectifier.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 *PowerTransmissionSystem) threePositionSwitchTransPower(w ecs.World) { - wd := entity.GetWorldData(w) - s.query3PositionSwitch.Each(w, func(entry *ecs.Entry) { - breakerId := component.UidType.Get(entry).Id - closed := component.ThreePositionSwitchType.Get(entry).Position == component.StpClosedWorking - breakerModel := (wd.Repo.FindById(breakerId)).(*repository.ThreePositionSwitch) - breakerPortA := breakerModel.PortA - breakerPortB := breakerModel.PortB - s.towPipePortsTransPower(wd, closed, breakerPortA, breakerPortB) - }) -} - -// 隔离开关传递电能 -func (s *PowerTransmissionSystem) disconnectorTransPower(w ecs.World) { - wd := entity.GetWorldData(w) - s.queryHandcart.Each(w, func(entry *ecs.Entry) { - breakerId := component.UidType.Get(entry).Id - closed := component.DisconnectorType.Get(entry).Closed - breakerModel := (wd.Repo.FindById(breakerId)).(*repository.Disconnector) - breakerPortA := breakerModel.PortA - breakerPortB := breakerModel.PortB - s.towPipePortsTransPower(wd, closed, breakerPortA, breakerPortB) - }) -} - -// 手车传递电能 -func (s *PowerTransmissionSystem) handcartTransPower(w ecs.World) { - wd := entity.GetWorldData(w) - s.queryHandcart.Each(w, func(entry *ecs.Entry) { - breakerId := component.UidType.Get(entry).Id - closed := component.HandcartSwitchType.Get(entry).Position == component.HpClosed - breakerModel := (wd.Repo.FindById(breakerId)).(*repository.HandcartSwitch) - breakerPortA := breakerModel.PortA - breakerPortB := breakerModel.PortB - s.towPipePortsTransPower(wd, closed, breakerPortA, breakerPortB) - }) -} - -// 断路器传递电能 -func (s *PowerTransmissionSystem) circuitBreakerTransPower(w ecs.World) { - wd := entity.GetWorldData(w) - s.queryCircuitBreaker.Each(w, func(entry *ecs.Entry) { - breakerId := component.UidType.Get(entry).Id - closed := component.CircuitBreakerType.Get(entry).Closed - breakerModel := (wd.Repo.FindById(breakerId)).(*repository.CircuitBreaker) - //断路器A端连接的管线 - breakerPortA := breakerModel.PortA - //断路器B端连接的管线 - breakerPortB := breakerModel.PortB - //传递电能 - s.towPipePortsTransPower(wd, closed, breakerPortA, breakerPortB) - }) -} - -// 电力母线中电力计算 -func (s *PowerTransmissionSystem) powerPipePower(w ecs.World) { - s.queryPowerPipe.Each(w, func(entry *ecs.Entry) { - pipe := component.PowerPipeType.Get(entry) - voltage := uint32(0) - ac := false - for _, power := range pipe.Sources { - if power.Voltage > voltage { - voltage = power.Voltage - ac = power.Ac - } - } - // - pipe.Voltage = voltage - pipe.Ac = ac - }) -} - -// 电源传递电能 -func (s *PowerTransmissionSystem) powerSourceTransPower(w ecs.World) { - wd := entity.GetWorldData(w) - s.queryPowerSource.Each(w, func(entry *ecs.Entry) { - psId := component.UidType.Get(entry).Id - ps := component.PowerSourceType.Get(entry) - // - psModel := (wd.Repo.FindById(psId)).(*repository.PowerSource) - pipeId := psModel.PortA.Device().Id() - //电源传递电力给母线 - pipeEntry := wd.EntityMap[pipeId] - powerPipe := component.PowerPipeType.Get(pipeEntry) - powerPipe.TransPower(psId, &component.ElePower{Ac: ps.Ac, Voltage: ps.Voltage, Fresh: time.Now().UnixMilli()}) - }) -} - -// 母线管件传递电能 -func (s *PowerTransmissionSystem) pipeFittingTransPower(w ecs.World) { - wd := entity.GetWorldData(w) - for _, pf := range wd.Repo.PipeFittingMap { - if pf.IsEle() { - //与管件连接的所有管线 - pipes := pf.Ports() - //筛选出相对电源 - pipePsMap := make(map[string]*component.ElePower) - for _, pipePort := range pipes { - pipeEntry := wd.EntityMap[pipePort.Device().Id()] - powerPipe := component.PowerPipeType.Get(pipeEntry) - for epId, ep := range powerPipe.Sources { - pipePs, ok := pipePsMap[epId] - if ok { - if ep.Fresh > pipePs.Fresh { - pipePsMap[epId] = ep - } - } else { - pipePsMap[epId] = ep - } - } - } - //管件连接的管线间电能传递 - for _, pipePort := range pipes { - for pipePsId, pipePs := range pipePsMap { //相对电源 - pipeEntry := wd.EntityMap[pipePort.Device().Id()] - powerPipe := component.PowerPipeType.Get(pipeEntry) - pipePortPs, ok := powerPipe.Sources[pipePsId] - if ok { - if pipePs.Fresh > pipePortPs.Fresh { - *powerPipe.Sources[pipePsId] = *pipePs - powerPipe.Sources[pipePsId].Fresh -= 1 //保证相对性 - } - } else { - powerPipe.Sources[pipePsId] = &component.ElePower{} - *powerPipe.Sources[pipePsId] = *pipePs - powerPipe.Sources[pipePsId].Fresh -= 1 //保证相对性 - } - } - } - } - } -} - -// 两位置开关传递电能(断路器、手车、隔离开关) -func (s *PowerTransmissionSystem) towPipePortsTransPower( - wd *component.WorldData, - closed bool, - breakerPortA *repository.PipePort, - breakerPortB *repository.PipePort) { - //断路器A端连接的管线 - breakerPortAPipeEntry := wd.EntityMap[breakerPortA.Device().Id()] - breakerPortAPipe := component.PowerPipeType.Get(breakerPortAPipeEntry) - //断路器B端连接的管线 - breakerPortBPipeEntry := wd.EntityMap[breakerPortB.Device().Id()] - breakerPortBPipe := component.PowerPipeType.Get(breakerPortBPipeEntry) - //A->B - for portAPipePsId, portAPipePs := range breakerPortAPipe.Sources { //A - portBPipePs, ok := breakerPortBPipe.Sources[portAPipePsId] //B - if ok { - if portAPipePs.Fresh > portBPipePs.Fresh { - *breakerPortBPipe.Sources[portAPipePsId] = *portAPipePs - breakerPortBPipe.Sources[portAPipePsId].Fresh -= 1 - if !closed { - breakerPortBPipe.Sources[portAPipePsId].Voltage = 0 - } - } - } else { - breakerPortBPipe.Sources[portAPipePsId] = &component.ElePower{} - *breakerPortBPipe.Sources[portAPipePsId] = *portAPipePs - breakerPortBPipe.Sources[portAPipePsId].Fresh -= 1 - if !closed { - breakerPortBPipe.Sources[portAPipePsId].Voltage = 0 - } - } - } - //B->A - for portBPipePsId, portBPipePs := range breakerPortBPipe.Sources { //B - portAPipePs, ok := breakerPortAPipe.Sources[portBPipePsId] //A - if ok { - if portBPipePs.Fresh > portAPipePs.Fresh { - *breakerPortAPipe.Sources[portBPipePsId] = *portBPipePs - breakerPortAPipe.Sources[portBPipePsId].Fresh -= 1 - if !closed { - breakerPortAPipe.Sources[portBPipePsId].Voltage = 0 - } - } - } else { - breakerPortAPipe.Sources[portBPipePsId] = &component.ElePower{} - *breakerPortAPipe.Sources[portBPipePsId] = *portBPipePs - breakerPortAPipe.Sources[portBPipePsId].Fresh -= 1 - if !closed { - breakerPortAPipe.Sources[portBPipePsId].Voltage = 0 - } - } - } -} diff --git a/sys/iscs_sys/iscs_pscada_rectifier.go b/sys/iscs_sys/iscs_pscada_rectifier.go new file mode 100644 index 0000000..f275247 --- /dev/null +++ b/sys/iscs_sys/iscs_pscada_rectifier.go @@ -0,0 +1,74 @@ +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)), + } +} +func (s *RectifierSystem) Update(w ecs.World) { + s.rectifierTransPower(w) +} + +// 整流器电能传递 +// 当线路接通时零线和负极电压规定值为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} + } + } + } + + }) +} diff --git a/sys/iscs_sys/iscs_pscada_switch.go b/sys/iscs_sys/iscs_pscada_switch.go deleted file mode 100644 index 6821c86..0000000 --- a/sys/iscs_sys/iscs_pscada_switch.go +++ /dev/null @@ -1,9 +0,0 @@ -package iscs_sys - -import "joylink.club/ecs" - -// PscadaSwitchSystem ISCS 电力监控系统开关相关 -type PscadaSwitchSystem struct { - queryCircuitBreaker *ecs.Query - queryThreePositionSwitch *ecs.Query -} diff --git a/sys/iscs_sys/iscs_pscada_three_position_switch.go b/sys/iscs_sys/iscs_pscada_three_position_switch.go new file mode 100644 index 0000000..db76c85 --- /dev/null +++ b/sys/iscs_sys/iscs_pscada_three_position_switch.go @@ -0,0 +1,36 @@ +package iscs_sys + +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" + "joylink.club/rtsssimulation/entity" + "joylink.club/rtsssimulation/repository" +) + +type ThreePositionSwitchSystem struct { + query *ecs.Query +} + +func NewThreePositionSwitchSystem() *ThreePositionSwitchSystem { + return &ThreePositionSwitchSystem{ + query: ecs.NewQuery(filter.Contains(component.UidType, component.ThreePositionSwitchType)), + } +} + +func (s *ThreePositionSwitchSystem) Update(w ecs.World) { + s.threePositionSwitchTransPower(w) +} + +// 三工位隔离开关传递电能 +func (s *ThreePositionSwitchSystem) threePositionSwitchTransPower(w ecs.World) { + wd := entity.GetWorldData(w) + s.query.Each(w, func(entry *ecs.Entry) { + breakerId := component.UidType.Get(entry).Id + closed := component.ThreePositionSwitchType.Get(entry).Position == component.StpClosedWorking + breakerModel := (wd.Repo.FindById(breakerId)).(*repository.ThreePositionSwitch) + breakerPortA := breakerModel.PortA + breakerPortB := breakerModel.PortB + towPipePortsTransPower(wd, closed, breakerPortA, breakerPortB) + }) +} diff --git a/sys/iscs_sys/iscs_pscada_voltage_transformer.go b/sys/iscs_sys/iscs_pscada_voltage_transformer.go new file mode 100644 index 0000000..fb0b86a --- /dev/null +++ b/sys/iscs_sys/iscs_pscada_voltage_transformer.go @@ -0,0 +1,25 @@ +package iscs_sys + +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" +) + +type VoltageTransformerSystem struct { + query *ecs.Query +} + +func NewVoltageTransformerSystem() *VoltageTransformerSystem { + return &VoltageTransformerSystem{ + query: ecs.NewQuery(filter.Contains(component.UidType, component.VoltageTransformerType)), + } +} +func (s *VoltageTransformerSystem) Update(w ecs.World) { + s.voltageTransformerTransPower(w) +} + +// 变压器电力传递 +func (s *VoltageTransformerSystem) voltageTransformerTransPower(w ecs.World) { + +}