Skip to content
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. Python API
  4. Continuing Simulation and choosing Input Simulation

Continuing Simulation and choosing Input Simulation

Scheduled Pinned Locked Moved Python API
4 Posts 2 Posters 430 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AmphoePai
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SylvainS Offline
      SylvainS Offline
      Sylvain
      ZMT
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AmphoePai
        wrote on last edited by
        #3

        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"?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AmphoePai
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          1
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Search