diff --git a/sys/iscs_sys/iscs_pscada_circuit_breaker.go b/sys/iscs_sys/iscs_pscada_circuit_breaker.go index 9dd1c55..ff588d8 100644 --- a/sys/iscs_sys/iscs_pscada_circuit_breaker.go +++ b/sys/iscs_sys/iscs_pscada_circuit_breaker.go @@ -46,16 +46,10 @@ func towPipePortsTransPower( breakerPortB *repository.PipePort) { //断路器A端连接的管线 breakerPortAPipeEntry := wd.EntityMap[breakerPortA.Device().Id()] - if !breakerPortAPipeEntry.HasComponent(component.PipeElectricityType) { - breakerPortAPipeEntry.AddComponent(component.PipeElectricityType) - } - breakerPortAPipe := component.PipeElectricityType.Get(breakerPortAPipeEntry) + breakerPortAPipe := perfectPipeElectricity(breakerPortAPipeEntry) //断路器B端连接的管线 breakerPortBPipeEntry := wd.EntityMap[breakerPortB.Device().Id()] - if !breakerPortBPipeEntry.HasComponent(component.PipeElectricityType) { - breakerPortBPipeEntry.AddComponent(component.PipeElectricityType) - } - breakerPortBPipe := component.PipeElectricityType.Get(breakerPortBPipeEntry) + breakerPortBPipe := perfectPipeElectricity(breakerPortBPipeEntry) //A->B for portAPipePsId, portAPipePs := range breakerPortAPipe.Sources { //A diff --git a/sys/iscs_sys/iscs_pscada_earthing_device.go b/sys/iscs_sys/iscs_pscada_earthing_device.go index 8d7b442..d7af10e 100644 --- a/sys/iscs_sys/iscs_pscada_earthing_device.go +++ b/sys/iscs_sys/iscs_pscada_earthing_device.go @@ -8,6 +8,7 @@ import ( "joylink.club/rtsssimulation/repository" ) +// 接地 type EarthingDeviceSystem struct { query *ecs.Query } @@ -28,10 +29,7 @@ func (s *EarthingDeviceSystem) Update(w ecs.World) { edModel := (wd.Repo.FindById(edId)).(*repository.EarthingDevice) if edModel.PortA != nil { edPipeEntry := wd.EntityMap[edModel.PortA.Device().Id()] - if !edPipeEntry.HasComponent(component.PipeElectricityType) { - edPipeEntry.AddComponent(component.PipeElectricityType) - } - edPipe := component.PipeElectricityType.Get(edPipeEntry) + edPipe := perfectPipeElectricity(edPipeEntry) ed.Voltage = edPipe.U } else { ed.Voltage = 0 //零电压 diff --git a/sys/iscs_sys/iscs_pscada_pipe_fitting.go b/sys/iscs_sys/iscs_pscada_pipe_fitting.go index 1539012..61d50e2 100644 --- a/sys/iscs_sys/iscs_pscada_pipe_fitting.go +++ b/sys/iscs_sys/iscs_pscada_pipe_fitting.go @@ -1,12 +1,10 @@ package iscs_sys import ( - "fmt" "joylink.club/ecs" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/entity" "joylink.club/rtsssimulation/repository" - "log/slog" ) type PipeFittingSystem struct { @@ -20,11 +18,13 @@ func NewPipeFittingSystem() *PipeFittingSystem { func (s *PipeFittingSystem) Update(w ecs.World) { wd := entity.GetWorldData(w) for _, pf := range wd.Repo.PipeFittingMap { - if s.initPipeFitting(wd, pf) && s.isPipeFittingEle(wd, pf) { + if s.isPipeFittingEle(wd, pf) { //管件为电力管件 //筛选出相对电源 pipePsMap := s.findEleSourcePipe(wd, pf) //管件连接的管线间电能传递 s.transEle(wd, pf, pipePsMap) + } else { //流体管件 + } } } @@ -35,17 +35,15 @@ func (s *PipeFittingSystem) findEleSourcePipe(wd *component.WorldData, pf *repos pipePsMap := make(map[string]*component.ElectricitySource) for _, pipePort := range pf.Ports() { pipeEntry := wd.EntityMap[pipePort.Device().Id()] - if pipeEntry.HasComponent(component.PipeElectricityType) { - powerPipe := component.PipeElectricityType.Get(pipeEntry) - for epId, ep := range powerPipe.Sources { - pipePs, ok := pipePsMap[epId] - if ok { - if ep.Fresh > pipePs.Fresh { - pipePsMap[epId] = ep - } - } else { + powerPipe := perfectPipeElectricity(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 } } } @@ -57,7 +55,7 @@ func (s *PipeFittingSystem) transEle(wd *component.WorldData, pf *repository.Pip for _, pipePort := range pf.Ports() { for pipePsId, pipePs := range pipePsMap { //相对电源 pipeEntry := wd.EntityMap[pipePort.Device().Id()] - powerPipe := component.PipeElectricityType.Get(pipeEntry) + powerPipe := perfectPipeElectricity(pipeEntry) pipePortPs, ok := powerPipe.Sources[pipePsId] if ok { if pipePs.Fresh > pipePortPs.Fresh { @@ -73,7 +71,7 @@ func (s *PipeFittingSystem) transEle(wd *component.WorldData, pf *repository.Pip } } -// 判断该管件是否为连接电线 +// 与管件连接的管线只要有一个为电线则其他的都为电线 func (s *PipeFittingSystem) isPipeFittingEle(wd *component.WorldData, pf *repository.PipeFitting) bool { for _, pipePort := range pf.Ports() { pipeEntry := wd.EntityMap[pipePort.Device().Id()] @@ -85,57 +83,9 @@ func (s *PipeFittingSystem) isPipeFittingEle(wd *component.WorldData, pf *reposi return false } -// 由于初始的管线是无性质的,现根据管件的某个已有性质的管线来初始化管件其他的管线 -func (s *PipeFittingSystem) initPipeFitting(wd *component.WorldData, pf *repository.PipeFitting) bool { - pipeMatter := component.PmtNon - for _, pipePort := range pf.Ports() { - pipeEntry := wd.EntityMap[pipePort.Device().Id()] - pipe := component.PipeType.Get(pipeEntry) - if !pipe.Matter.IsNon() { - pipeMatter = pipe.Matter - break - } - } - // - if pipeMatter.IsNon() { - return false - } - // - for _, pipePort := range pf.Ports() { - pipeEntry := wd.EntityMap[pipePort.Device().Id()] - pipe := component.PipeType.Get(pipeEntry) - pipe.Matter = pipeMatter - switch pipe.Matter { - case component.PmtElectricity: - { - if !pipeEntry.HasComponent(component.PipeElectricityType) { - pipeEntry.AddComponent(component.PipeElectricityType) - component.PipeElectricityType.Set(pipeEntry, component.NewPipeElectricity()) - } - } - case component.PmtAir: - fallthrough - case component.PmtOil: - fallthrough - case component.PmtSmoke: - fallthrough - case component.PmtWater: - { - if !pipeEntry.HasComponent(component.PipeFluidType) { - pipeEntry.AddComponent(component.PipeFluidType) - component.PipeFluidType.Set(pipeEntry, component.NewPipeFluid()) - } - } - default: - slog.Warn(fmt.Sprintf("PipeFittingSystem.initPipeFitting 未处理的管道物质[%d]", pipe.Matter)) - } - } - // - return true -} - -// 从电线实体获取电线 -func getPipeElectricity(pipeEntry *ecs.Entry) *component.PipeElectricity { +// 完善电线实体并获取电线状态 +func perfectPipeElectricity(pipeEntry *ecs.Entry) *component.PipeElectricity { + component.PipeType.Get(pipeEntry).Matter = component.PmtElectricity if !pipeEntry.HasComponent(component.PipeElectricityType) { pipeEntry.AddComponent(component.PipeElectricityType) } diff --git a/sys/iscs_sys/iscs_pscada_power_souce.go b/sys/iscs_sys/iscs_pscada_power_souce.go index 57d1902..01223cb 100644 --- a/sys/iscs_sys/iscs_pscada_power_souce.go +++ b/sys/iscs_sys/iscs_pscada_power_souce.go @@ -39,13 +39,7 @@ func (s *PowerSourceSystem) Update(w ecs.World) { func (s *PowerSourceSystem) transPower(wd *component.WorldData, pipeId string, ps *component.ElectricitySource, psId string) { pipeEntry := wd.EntityMap[pipeId] - if !pipeEntry.HasComponent(component.PipeElectricityType) { - pipeEntry.AddComponent(component.PipeElectricityType) - component.PipeElectricityType.Set(pipeEntry, component.NewPipeElectricity()) - } - pipe := component.PipeType.Get(pipeEntry) - pipe.Matter = component.PmtElectricity // - powerPipe := component.PipeElectricityType.Get(pipeEntry) + powerPipe := perfectPipeElectricity(pipeEntry) powerPipe.TransPower(psId, ps) } diff --git a/sys/iscs_sys/iscs_pscada_rectifier.go b/sys/iscs_sys/iscs_pscada_rectifier.go index 4de16c7..e9287a5 100644 --- a/sys/iscs_sys/iscs_pscada_rectifier.go +++ b/sys/iscs_sys/iscs_pscada_rectifier.go @@ -45,12 +45,12 @@ func (s *RectifierSystem) rectifierTransPower(wd *component.WorldData, entry *ec portF := rectifierModel.PortD //直负 // portLPipeEntry := wd.EntityMap[portL.Device().Id()] - portLPipe := component.PipeElectricityType.Get(portLPipeEntry) + portLPipe := perfectPipeElectricity(portLPipeEntry) // portZPipeEntry := wd.EntityMap[portZ.Device().Id()] - portZPipe := component.PipeElectricityType.Get(portZPipeEntry) + portZPipe := perfectPipeElectricity(portZPipeEntry) portFPipeEntry := wd.EntityMap[portF.Device().Id()] - portFPipe := component.PipeElectricityType.Get(portFPipeEntry) + portFPipe := perfectPipeElectricity(portFPipeEntry) //L->Z、F for lpsId, lps := range portLPipe.Sources { if lps.Ac { diff --git a/sys/iscs_sys/iscs_pscada_voltage_transformer.go b/sys/iscs_sys/iscs_pscada_voltage_transformer.go index 250aea9..4cf0ac1 100644 --- a/sys/iscs_sys/iscs_pscada_voltage_transformer.go +++ b/sys/iscs_sys/iscs_pscada_voltage_transformer.go @@ -37,20 +37,20 @@ func (s *VoltageTransformerSystem) voltageTransformerTransPower(wd *component.Wo // vtPortA := vtModel.PortA vtPortAEntry := wd.EntityMap[vtPortA.Device().Id()] - vtPortAPipe := getPipeElectricity(vtPortAEntry) //变压器一次侧连接的管线 + vtPortAPipe := perfectPipeElectricity(vtPortAEntry) //变压器一次侧连接的管线 // var vtPortBPipe *component.PipeElectricity = nil if vtModel.PortB != nil { vtPortB := vtModel.PortB vtPortBEntry := wd.EntityMap[vtPortB.Device().Id()] - vtPortBPipe = getPipeElectricity(vtPortBEntry) + vtPortBPipe = perfectPipeElectricity(vtPortBEntry) } // var vtPortCPipe *component.PipeElectricity = nil if vtModel.PortC != nil { vtPortC := vtModel.PortC vtPortCEntry := wd.EntityMap[vtPortC.Device().Id()] - vtPortCPipe = getPipeElectricity(vtPortCEntry) + vtPortCPipe = perfectPipeElectricity(vtPortCEntry) } //变压比 rate := float64(vtModel.E2) / float64(vtModel.E1)