Continuing Simulation and choosing Input Simulation

Hello,

So far I was not able to find how to get the Python API to choose an input simulation, after choosing to continue a previous simulation. What I have is a thermal simulation called "Heating 0", corresponding to the first minute of an experiment. The next simulation is "Heating 1", which I continue as follows:

thermal_initial_global.InitializationOptions = thermal_initial_global.InitializationOptions.enum.ContinueSimulation

So far, so good. But if I want to do "Heating 2" based on "Heating 1", I am stuck. Everything I have tried yields a continuation of "Heating 0", because I can not choose an Input Simulation. I have searched for an appropriate function in the objects "InputSimulation" and "InputSimulationProp" using dir(), but so far without success.

Hello,
Have you tried setting up what you need (i.e. Heating 2 based on Heating 1) using the GUI and then generate the Python script using the To-Python function? Sometimes that can reveal how certain settings are implemented in the Python interface. I am not sure it will work in your case, but it is worth a try and does not take long.

Hello Sylvain,

thanks for your suggestion, I have now tried that. The code that the To-Python yielded was the following:

global_initial_condition_settings.InputSimulation = u"Heating 0"

So, putting a 'u' in front of the string seemed to be the solution. However, after coding this I received a new error:

Traceback (most recent call last):
File "\nas-fa0efsusr1\holfelrd\My Documents\Sim4Life light\4.4\Scripts\temp\temp-1.py", line 412, in <module>
main()
File "\nas-fa0efsusr1\holfelrd\My Documents\Sim4Life light\4.4\Scripts\temp\temp-1.py", line 409, in main
RunTutorial( project_path )
File "\nas-fa0efsusr1\holfelrd\My Documents\Sim4Life light\4.4\Scripts\temp\temp-1.py", line 378, in RunTutorial
thermal_sim = CreateThermalSimulation(em_sim, i)
File "\nas-fa0efsusr1\holfelrd\My Documents\Sim4Life light\4.4\Scripts\temp\temp-1.py", line 172, in CreateThermalSimulation
thermal_initial_global.InputSimulation = u"Heating 0"
File "C:\Program Files\Sim4LifeLight_v4.4.2.3851\s4l_v1_api\propbinders.py", line 103, in fsetter
api_prop.set(value)
File "C:\Program Files\Sim4LifeLight_v4.4.2.3851\s4l_v1_api\propwrappers.py", line 343, in set
raise ValueError("Invalid value, '{0}' not in {1}".format(inputvalue, self.enum))
ValueError: Invalid value, 'Heating 0' not in None

This error is also raised if I try to run the code generated from the "To-Python"- function unchanged. I have double-checked, and in the GUI you can very clearly choose an input simulation. So why does it say "None"?

For those who are interested, I have found a way to work around the issue. The python-command to continue a Simulation called:

thermal_initial_global.InitializationOptions.enum.ContinueSimulation

can only take the first argument, which in my case is "heating 0". So if you now have created "heating 1" based on "heating 0", and then proceed to delete "heating 0", the only available argument is "heating 1". This will enable you to further continue your simulation. You can delete a simulation using the following command:

document.AllSimulations.Remove(thermal_sim)

given you have returned thermal_sim, of course. If you create an empty list, you can append your thermal_sim's into it and then choose which item you want to delete.

I am sure there are more elegant methods, but if you need to do this specific task, it works.

Log in to reply