@@ -954,7 +954,7 @@ def xmlparse(self):
954954 for sv in rootCQ .iter ('ScalarVariable' ):
955955 scalar = {}
956956 scalar ["name" ] = sv .get ('name' )
957- scalar ["changable " ] = sv .get ('isValueChangeable' )
957+ scalar ["changeable " ] = sv .get ('isValueChangeable' )
958958 scalar ["description" ] = sv .get ('description' )
959959 scalar ["variability" ] = sv .get ('variability' )
960960 scalar ["causality" ] = sv .get ('causality' )
@@ -1318,7 +1318,7 @@ def strip_space(self,name):
13181318 elif (isinstance (name ,list )):
13191319 return [x .replace (" " ,"" ) for x in name ]
13201320
1321- def setMethodHelper (self ,args1 ,args2 ,args3 ,args4 = None ):
1321+ def setMethodHelper (self ,args1 ,args2 ,args3 ,args4 = None , verbose = None ):
13221322 """
13231323 Helper function for setParameter(),setContinuous(),setSimulationOptions(),setLinearizationOption(),setOptimizationOption()
13241324 args1 - string or list of string given by user
@@ -1330,23 +1330,32 @@ def setMethodHelper(self,args1,args2,args3,args4=None):
13301330 args1 = self .strip_space (args1 )
13311331 value = args1 .split ("=" )
13321332 if value [0 ] in args2 :
1333- args2 [value [0 ]]= value [1 ]
1334- if (args4 != None ):
1335- args4 [value [0 ]]= value [1 ]
1333+ if (args3 == "parameter" and self .isParameterChangeable (value [0 ], value [1 ], verbose )):
1334+ args2 [value [0 ]]= value [1 ]
1335+ if (args4 != None ):
1336+ args4 [value [0 ]]= value [1 ]
1337+ elif (args3 != "parameter" ):
1338+ args2 [value [0 ]]= value [1 ]
1339+ if (args4 != None ):
1340+ args4 [value [0 ]]= value [1 ]
13361341 else :
1337- print (value [0 ], "! is not a", args3 , " variable" )
1342+ print (" \" " + value [0 ] + " \" " + " is not a" + args3 + " variable" )
13381343 return
13391344 elif (isinstance (args1 ,list )):
13401345 args1 = self .strip_space (args1 )
13411346 for var in args1 :
13421347 value = var .split ("=" )
13431348 if value [0 ] in args2 :
1344- args2 [value [0 ]]= value [1 ]
1345- if (args4 != None ):
1346- args4 [value [0 ]]= value [1 ]
1349+ if (args3 == "parameter" and self .isParameterChangeable (value [0 ], value [1 ], verbose )):
1350+ args2 [value [0 ]]= value [1 ]
1351+ if (args4 != None ):
1352+ args4 [value [0 ]]= value [1 ]
1353+ elif (args3 != "parameter" ):
1354+ args2 [value [0 ]]= value [1 ]
1355+ if (args4 != None ):
1356+ args4 [value [0 ]]= value [1 ]
13471357 else :
1348- print (value [0 ], "!is not a" , args3 ,"variable" )
1349- return
1358+ print ("\" " + value [0 ] + "\" " + " is not a " + args3 + " variable" )
13501359
13511360 def setContinuous (self , cvals ): # 13
13521361 """
@@ -1358,15 +1367,23 @@ def setContinuous(self, cvals): # 13
13581367 """
13591368 return self .setMethodHelper (cvals ,self .continuouslist ,"continuous" ,self .overridevariables )
13601369
1361- def setParameters (self , pvals ): # 14
1370+ def setParameters (self , pvals , verbose = True ): # 14
13621371 """
13631372 This method is used to set parameter values. It can be called:
13641373 with a sequence of parameter name and assigning corresponding value as arguments as show in the example below:
13651374 usage
13661375 >>> setParameters("Name=value")
13671376 >>> setParameters(["Name1=value1","Name2=value2"])
13681377 """
1369- return self .setMethodHelper (pvals ,self .paramlist ,"parameter" ,self .overridevariables )
1378+ return self .setMethodHelper (pvals ,self .paramlist ,"parameter" ,self .overridevariables , verbose )
1379+
1380+ def isParameterChangeable (self , name , value , verbose ):
1381+ q = self .getQuantities (name )
1382+ if (q [0 ]["changeable" ] == "false" ):
1383+ if verbose :
1384+ print ("| info | setParameters() failed : It is not possible to set the following signal " + "\" " + name + "\" " + ", It seems to be structural, final, protected or evaluated or has a non-constant binding, use sendExpression(setParameterValue(" + self .modelName + ", " + name + ", " + value + "), parsed=false)" + " and rebuild the model using buildModel() API" )
1385+ return False
1386+ return True
13701387
13711388 def setSimulationOptions (self , simOptions ): # 16
13721389 """
0 commit comments