Ejemplo n.º 1
0
        public void AutoItemsForPipeFail(string compName,
                                         string desc,
                                         string[] demandNames,
                                         SimVariable[] demandFailVars,
                                         string[] setVarsIf,
                                         string[] setToVals,
                                         string[] startStates,
                                         string[] turnOffStates)
        {
            if ((demandNames.Count() != demandFailVars.Count()) || (demandNames.Count() != setVarsIf.Count()) || (demandNames.Count() != setToVals.Count()))
            {
                throw new Exception("Not equal Demand names and lists");
            }


            CompDiagram addComp = new CompDiagram(compName);

            addComp.desc = desc;
            allDiagrams.Add(addComp);

            //Action addAct;
            //Event addEv;

            //all items going to have active state and failed state
            State standbyState = new State(compName + "_Standby", EnStateType.stStart, addComp);
            State activeState  = new State(compName + "_Active", EnStateType.stStandard, addComp);

            allStates.Add(standbyState);
            allStates.Add(activeState);
            List <State> failStates = new List <State>();

            State failedState = new State(compName + "_Failed", EnStateType.stStandard, addComp);

            allStates.Add(failedState);
            addComp.AddEvalVal(failedState.id, false);
            failStates.Add(failedState);
            addComp.AddEvalVal(activeState.id, true);

            //add event for a demand
            StateCngEvent demandEv;

            demandEv = new StateCngEvent(compName + "_Demand", true, false);


            //add all the start states to the related items
            foreach (string sName in startStates)
            {
                State stState = this.allStates.FindByName(sName);
                if (stState != null)
                {
                    demandEv.AddRelatedItem(stState.id);
                }
            }
            allEvents.Add(demandEv);

            TransitionAct toFailedAct = new TransitionAct("_Goto_" + compName + "_Failed");
            NowTimerEvent nowEv       = new NowTimerEvent(compName + "_Failed");

            toFailedAct.AddToState(failedState);
            allActions.Add(toFailedAct);

            //add action to move from off to on or failed for the demand
            TransitionAct demandAct = new TransitionAct("From_" + compName + "_Demand");

            for (int i = 0; i < demandFailVars.Count(); ++i)
            {
                VarValueAct setVarVal = new VarValueAct("_Set_" + compName + "_Demand_val" + i.ToString(), allVariables.FindByName(setVarsIf[i]),
                                                        setToVals[i], typeof(double), null);
                allActions.Add(setVarVal);

                State tempState = new State(compName + "_Temp" + demandNames[i], EnStateType.stStandard, addComp); //"Joint_3_Temp_SIL1"
                allStates.Add(tempState);
                tempState.AddImmediateAction(setVarVal);
                //tempState.AddImmediateAction(toFailedAct);
                tempState.AddEvent(nowEv, true, toFailedAct);

                addComp.AddEvalVal(tempState.id, false);
                failStates.Add(tempState);

                demandAct.AddToState(tempState, demandFailVars[i], demandNames[i]);
            }

            demandAct.AddToState(activeState, -1, "No joint Failure");
            allActions.Add(demandAct);
            //add the events and movement to the standbyState
            standbyState.AddEvent(demandEv, true, demandAct);



            //add event for a shutoff request
            StateCngEvent offEv = new StateCngEvent(compName + "_Stop", false);

            foreach (string sName in turnOffStates)
            {
                State endState = this.allStates.FindByName(sName);
                if (endState != null)
                {
                    offEv.AddRelatedItem(endState.id);
                }
            }
            allEvents.Add(offEv);

            //add action to move from off to on or failed for the demand
            TransitionAct offAct = new TransitionAct("_Goto_" + compName + "_Off");

            offAct.AddToState(standbyState);
            allActions.Add(offAct);

            //add the Events and movement back to the standby state
            activeState.AddEvent(offEv, true, offAct);
            foreach (State curSt in failStates)
            {
                curSt.AddEvent(offEv, true, offAct);
            }
        }