@@ -463,14 +463,15 @@ class Quantity:
463463 """
464464 To represent quantities details
465465 """
466- def __init__ (self , name , start , changable , variability , description , causality ):
466+ def __init__ (self , name , start , changable , variability , description , causality , alias , aliasvariable ):
467467 self .name = name
468468 self .start = start
469469 self .changable = changable
470470 self .description = description
471471 self .variability = variability
472472 self .causality = causality
473-
473+ self .alias = alias
474+ self .aliasvariable = aliasvariable
474475
475476
476477
@@ -493,6 +494,11 @@ def __init__(self, fileName = None, modelName = None, lmodel = None): #1
493494 if fileName is None :
494495 return "File does not exist"
495496 self .tree = None
497+
498+ self .linearquantitiesList = [] #linearization quantity list
499+ self .linearinputs = [] #linearization input list
500+ self .linearoutputs = [] #linearization output list
501+ self .linearstates = [] #linearization states list
496502 self .quantitiesList = [] #detail list of all Modelica quantity variables inc. name, changable, description, etc
497503 self .qNamesList = [] #for all quantities name list
498504 self .cNamesList = [] #for continuous quantities name list
@@ -521,7 +527,7 @@ def __init__(self, fileName = None, modelName = None, lmodel = None): #1
521527 self .outputFlag = False
522528 self .csvFile = '' #for storing inputs condition
523529 if not os .path .exists (self .fileName ): #if file does not eixt
524- print ("Error: File does not exist!!!" )
530+ print ("File Error:" + os . path . abspath ( self . fileName ) + " does not exist!!!" )
525531 return
526532
527533 (head , tail ) = os .path .split (self .fileName )#to store directory/path and file)
@@ -575,14 +581,15 @@ def __loadingModel(self, fName, mName, lmodel):
575581 return
576582
577583 # build model
578- buildModelError = ''
584+ # buildModelError = ''
579585 self .getconn .sendExpression ("setCommandLineOptions(\" +d=initialization\" )" )
580586 #buildModelResult=self.getconn.sendExpression("buildModel("+ mName +")")
581587 buildModelResult = self .requestApi ("buildModel" , mName )
582588 buildModelError = self .requestApi ("getErrorString" )
583-
584- if buildModelError :
589+
590+ if ( '' in buildModelResult ) :
585591 print (buildModelError )
592+ return
586593
587594 self .xmlFile = buildModelResult [1 ]
588595 self .tree = ET .parse (self .xmlFile )
@@ -629,11 +636,13 @@ def __createQuantitiesList(self):
629636 description = sv .get ('description' )
630637 variability = sv .get ('variability' )
631638 causality = sv .get ('causality' )
639+ alias = sv .get ('alias' )
640+ aliasvariable = sv .get ('aliasVariable' )
632641 ch = sv .getchildren ()
633642 start = None
634643 for att in ch :
635644 start = att .get ('start' )
636- self .quantitiesList .append (Quantity (name , start , changable , variability , description , causality ))
645+ self .quantitiesList .append (Quantity (name , start , changable , variability , description , causality , alias , aliasvariable ))
637646 return self .quantitiesList
638647
639648 #to get list of all quantities names
@@ -684,23 +693,23 @@ def getQuantities(self, names = None):#3
684693 qlistnames = []
685694 for q in self .quantitiesList :
686695 if names == q .name :
687- qlistnames .append ({'Name' :q .name , 'Value' :q .start ,'Changeable' : q .changable , 'Variability' : q .variability , 'Description' :q .description })
696+ qlistnames .append ({'Name' :q .name , 'Value' :q .start ,'Changeable' : q .changable , 'Variability' : q .variability , 'alias' : q . alias , 'aliasvariable' : q . aliasvariable , ' Description' :q .description })
688697 break
689698 return qlistnames
690699 elif isinstance (names , list ):
691700 qlist = []
692701 for n in names :
693702 for q in self .quantitiesList :
694703 if n == q .name :
695- qlist .append ({'Name' :q .name , 'Value' :q .start ,'Changeable' : q .changable , 'Variability' : q .variability , 'Description' :q .description })
704+ qlist .append ({'Name' :q .name , 'Value' :q .start ,'Changeable' : q .changable , 'Variability' : q .variability ,'alias' : q . alias , 'aliasvariable' : q . aliasvariable , 'Description' :q .description })
696705 break
697706 return qlist
698707 else :
699708 print ('Error!!! Incorrect format' )
700709 else :
701710 qlist = []
702711 for q in self .quantitiesList :
703- qlist .append ({'Name' :q .name , 'Value' :q .start ,'Changeable' : q .changable , 'Variability' : q .variability , 'Description' :q .description })
712+ qlist .append ({'Name' :q .name , 'Value' :q .start ,'Changeable' : q .changable , 'Variability' : q .variability , 'alias' : q . alias , 'aliasvariable' : q . aliasvariable , ' Description' :q .description })
704713 return qlist
705714 except Exception as e :
706715 print (e )
@@ -793,7 +802,10 @@ def getOutputs(self, *names):#7
793802 """
794803
795804 try :
796- if self .simulationFlag :
805+ if not self .simulationFlag :
806+ return self .__getXXXs (names , self .__getOutputNames (), self .__getOutputValues ())
807+
808+ else :
797809 if len (names ) == 0 :
798810 op = self .__getOutputNames ()
799811 opTuple = tuple (op )
@@ -815,8 +827,8 @@ def getOutputs(self, *names):#7
815827 if len (tupVal ) == 1 :
816828 tupVal , = tupVal
817829 return tupVal
818- else :
819- print ('The model is not simulated yet!!!' )
830+ # else:
831+ # print ('The model is not simulated yet!!!')
820832
821833 except Exception :
822834 if pyparsing .ParseException :
@@ -1110,7 +1122,6 @@ def simulate(self):#11
11101122 #subprocess.call(cmd, shell = False)
11111123 self .simulationFlag = True
11121124 resultfilename = self .modelName + '_res.mat'
1113- print ("Simulation success Result file generated at: " + os .path .join (os .getcwd (),resultfilename ))
11141125 return
11151126 else :
11161127 print ("Error: application file not generated yet" )
@@ -1138,7 +1149,6 @@ def simulate(self):#11
11381149 self .simulationFlag = True
11391150 #self.outputFlag = True
11401151 resultfilename = self .modelName + '_res.mat'
1141- print ("Simulation success Result file generated at: " + os .path .join (os .getcwd (),resultfilename ))
11421152 return
11431153 else :
11441154 print ("Error: application file not generated yet" )
@@ -1525,9 +1535,9 @@ def linearize(self):#22
15251535
15261536 try :
15271537 cName = self .modelName
1528- self .requestApi ("setCommandLineOptions" , "+generateSymbolicLinearization" )
1538+ #self.requestApi("setCommandLineOptions", "+generateSymbolicLinearization")
1539+ self .getconn .sendExpression ("setCommandLineOptions(\" +generateSymbolicLinearization\" )" )
15291540 properties = "{}={}, {}={}, {}={}, {}={}, {}={}, {}='{}'" .format (self .linearizeOptionsNamesList [0 ],self .linearizeOptionsValuesList [0 ],self .linearizeOptionsNamesList [1 ],self .linearizeOptionsValuesList [1 ],self .linearizeOptionsNamesList [2 ],self .linearizeOptionsValuesList [2 ],self .linearizeOptionsNamesList [3 ],self .linearizeOptionsValuesList [3 ],self .linearizeOptionsNamesList [4 ],self .linearizeOptionsValuesList [4 ],self .linearizeOptionsNamesList [5 ],self .linearizeOptionsValuesList [5 ])
1530-
15311541 if self .inputFlag :
15321542 nameVal = self .getInputs ()
15331543 for n in nameVal :
@@ -1549,6 +1559,8 @@ def linearize(self):#22
15491559 linearizeError = self .requestApi ('getErrorString' )
15501560 if linearizeError :
15511561 print (linearizeError )
1562+
1563+ ## code to get the matrix and linear inputs, outputs and states
15521564 getLinFile = '{}_{}.{}' .format ('linear' , self .modelName , 'mo' )
15531565 checkLinFile = os .path .exists (getLinFile )
15541566 if checkLinFile :
@@ -1558,7 +1570,8 @@ def linearize(self):#22
15581570 self .requestApi ('buildModel' , linModelName )
15591571 lin = ModelicaSystem (getLinFile , linModelName )
15601572 lin .linearizationFlag = True
1561-
1573+ self .linearquantitiesList = lin .getQuantities ()
1574+ self .getLinearQuantityInformation ()
15621575 A = []
15631576 B = []
15641577 C = []
@@ -1582,6 +1595,27 @@ def linearize(self):#22
15821595 except Exception as e :
15831596 raise e
15841597
1598+ def getLinearQuantityInformation (self ):
1599+ ## function which extracts linearised states, inputs and outputs
1600+ for i in xrange (len (self .linearquantitiesList )):
1601+ if (self .linearquantitiesList [i ]['alias' ]== 'alias' ):
1602+ name = self .linearquantitiesList [i ]['Name' ]
1603+ if (name [1 ]== 'x' ):
1604+ self .linearstates .append (name [3 :- 1 ])
1605+ if (name [1 ]== 'u' ):
1606+ self .linearinputs .append (name [3 :- 1 ])
1607+ if (name [1 ]== 'y' ):
1608+ self .linearoutputs .append (name [3 :- 1 ])
1609+
1610+ def getLinearInputs (self ):
1611+ return self .linearinputs
1612+
1613+ def getLinearOutputs (self ):
1614+ return self .linearoutputs
1615+
1616+ def getLinearStates (self ):
1617+ return self .linearstates
1618+
15851619 def __getMatrix (self , xParameter , sizeParameter ):
15861620 paraKeys = self .__getParameterNames ()
15871621 xElemNames = []
0 commit comments