I am trying to change parameter with setParameter in OMPython where I have loaded Modelica model and solved it. I want to change parameter with other numerical values but getting error message:
| info | setParameters() failed : It is not possible to set the following signal "Nass", It seems to be structural, final, protected or evaluated or has a non-constant binding, use sendExpression(setParameterValue(CyclicLoading, Nass, 12000), parsed=false) and rebuild the model using buildModel() API
OMPython code before setParameter introduced:
from OMPython import ModelicaSystem
from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
modelpath="C:/work/code/modelica/"
Nom_fichier_mo="CyclicLoading.mo"
Nom_fich="CyclicLoading"
fich_res_Modelica_mat="Resultat_av_CyclicLoading.mat"
mod=ModelicaSystem(modelpath+Nom_fichier_mo,Nom_fich,["Modelica","CyclicLoading"])
mod.buildModel()
Directory_cd=omc.sendExpression("cd()")
resultatSimluation=mod.simulate(resultfile=f"{fich_res_Modelica_mat}")
Solution_var=mod.getSolutions()
OMPython code after setParameter introduced:
from OMPython import ModelicaSystem
from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
modelpath="C:/work/code/modelica/"
Nom_fichier_mo="CyclicLoading.mo"
Nom_fich="CyclicLoading"
fich_res_Modelica_mat="Resultat_av_CyclicLoading.mat"
mod=ModelicaSystem(modelpath+Nom_fichier_mo,Nom_fich,["Modelica","CyclicLoading"])
mod.buildModel()
**mod.setParameters("Nass=12000") **
Directory_cd=omc.sendExpression("cd()")
resultatSimluation=mod.simulate(resultfile=f"{fich_res_Modelica_mat}")
Solution_var=mod.getSolutions()
Trying to change parameters given in open modelica code by changing it with open modelica Python API command. Resulted into error message: | info | setParameters() failed : It is not possible to set the following signal "Nass", It seems to be structural, final, protected or evaluated or has a non-constant binding, use sendExpression(setParameterValue(CyclicLoading, Nass, 12000), parsed=false) and rebuild the model using buildModel() API
There are a number of situations where it is not allowed to change a parameter according to the Modelica specification.
For the following model HelloWorld
model HelloWorld "Model"
Real x(start=1, fixed = true);
parameter Real a = 1; // Changable parameter
Real y[N];
parameter Integer N = 2; // Structural parameter
final parameter Real b = 3; // Final parameter
protected
parameter Real c = 4; // Protected parameter
public
parameter Real d = 2*a; // Evaluated parameter
model M
parameter Real e = 5; // Changable parameter
end M;
M m(e=d); // Non-constant binding of e
equation
der(x) = a*b*c*d*x;
for i in 1:N loop
y[i] = time;
end for;
end HelloWorld;
it is only allowed to change the value of parameter a
.
Without seeing your Modelica model I assume that you encountered one of these cases when trying to change Nass
.