Unable to change parameter value in SSP
Description
When I change a parameter value in an .ssd file from the python api, it does not have an effect on a certain FMU.
Steps to reproduce the behavior
My python script:
from OMSimulator import SSP as oms_ssp
from OMSimulator import CRef
from OMSimulator import Capi as oms_capi
try: oms_capi.terminate("model") except OSError: pass try: oms_capi.delete("model") except OSError: pass
oms_model = oms_ssp("ParkerSimPack.ssp") oms_model.activeVariantName = "D16_auto_stimuli" oms_model_inst = oms_model.instantiate()
oms_model_inst.setResultFile('D16_auto_stimuli_results.csv')
oms_model_inst.initialize()
oms_model_inst.setValue(CRef("D16_auto_stimuli","interface_model.k_p"),0)
oms_model_inst.simulate()
oms_model_inst.terminate() oms_model_inst.delete()
Expected behavior
When I plot the results in Matlab i get:
But, the variagble theta should be zero after I have changed the parameter value of k_p to 0. If I simulate in easy-ssp I get (which I expect in OMSimulator as well):
Model
Version and OS
-
Version: 'OMSimulator v3.0.0.post103-g53bba5e-win'
-
OS: Win11 64 bit
@larsviktorlarsson i can reproduce the issue, i will debug more and fix the issue
@larsviktorlarsson I did some debugging and i found few things, the composite model has algebraic loops, due to the following connections
valve_model.qA -> interface_model.qA.out.y
valve_model.qB -> interface_model.qB.out.y
And when you set the value, you have to set it before initialization, so it should be
oms_model_inst = oms_model.instantiate()
oms_model_inst.setResultFile('D16_auto_stimuli_results.csv')
oms_model_inst.setValue(CRef("D16_auto_stimuli","interface_model.k_p"),0) // set it before initialize
oms_model_inst.initialize()
But this does not solve the issue, but you can see that parameter value for interface_model.k_p is changed to 0 in the plots. So the change of parameter value works, but it does not produce the desired result according to you and i hope the value k_p is internally has some equations which are dependent on it. But i don't see any connection with interface_model.k_p to other fmu component.
Since i cannot see the model i don't know how these change in value in k_p is affection the simulation results.
Test1:
In the .ssd file , currently the value of k_p is set to 130 and if you directly change in the .ssd file to 0, then you get the correct results as you mentioned
Test 2:
Eliminate the above the two connections and it also produces the desired result.
Test 3:
If you completely eliminate the valve model, then you also get the desired result, You can do that by following
oms_model = oms_ssp("ParkerSimPack.ssp")
oms_model.activeVariantName = "D16_auto_stimuli"
oms_model.delete(CRef('D16_auto_stimuli', 'valve_model')) ## delete the whole valve model from the system
oms_model_inst = oms_model.instantiate()
oms_model_inst.setResultFile('D16_auto_stimuli_results.csv')
oms_model_inst.setValue(CRef("D16_auto_stimuli","interface_model.k_p"),0)
oms_model_inst.initialize()
oms_model_inst.simulate()
oms_model_inst.terminate()
oms_model_inst.delete()
@larsviktorlarsson ping
@arun3688, I have looked into it together with @robha67. The valve model has direct feed through, but, if we have interpreted the modelDescription file for the interface fmu (Hopsan) correctly, the complete system model should not contain an algebraic loop since the Hopsan model should break them. How does OMSImulator identify algebraic loops? Via the ModelStructure element of the modelDescription files? If so, is there a problem in the OMSimulator identification procedure, or can you tell if there is an error in any of the modelDescription files? @robbr48, I will add you to this conversation as it involves an Hopsan fmu.