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. How can I interpolate the last snapshot of data in thermal simulation

How can I interpolate the last snapshot of data in thermal simulation

Scheduled Pinned Locked Moved Solved Python API
6 Posts 2 Posters 826 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
    Aiping
    wrote on last edited by
    #1

    I run the thermal simulation and want to interpolate only the last snapshot of data in python, how can I do that?
    Thank you

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

      Note: the following is in Sim4Life 3.4, I am not sure to what extent it works with older versions.

      There is an "Extract Snapshot" algorithm, which you can use to extract only the latest snapshot of your data. You can then use its output as an input for the "Interpolator" algorithm:

      0_1505292898775_703e5143-f412-470e-9d74-77b2a36b9d26-image.png

      0_1505293002178_649b5a47-1222-4144-b114-5c36cc5ab838-image.png

      You can do the same thing from Python (I used the "To-Python" tool)

      # -*- coding: utf-8 -*-
      # This script was auto-generated by Sim4Life version 3.4.2.2438
      
      import numpy
      import s4l_v1.analysis as analysis
      import s4l_v1.document as document
      import s4l_v1.model as model
      import s4l_v1.units as units
      from s4l_v1 import ReleaseVersion
      from s4l_v1 import Unit
      
      try:
      	# Define the version to use for default values
      	ReleaseVersion.set_active(ReleaseVersion.version3_4)
      	
      	# Creating the analysis pipeline
      	# Adding a new SimulationExtractor
      	simulation = document.AllSimulations["Heating"]
      	simulation_extractor = simulation.Results()
      
      	# Adding a new SimulationExtractor
      	simulation = document.AllSimulations["Dipole"]
      	simulation_extractor_2 = simulation.Results()
      
      	# Adding a new ThermoSensorExtractor
      	thermo_sensor_extractor = simulation_extractor["Overall Field"]
      	document.AllAlgorithms.Add(thermo_sensor_extractor)
      
      	# Adding a new EmSensorExtractor
      	em_sensor_extractor = simulation_extractor_2["Overall Field"]
      	em_sensor_extractor.FrequencySettings.ExtractedFrequency = u"All"
      	em_sensor_extractor.SurfaceCurrent.SurfaceResolution = 0.001, units.Meters
      	document.AllAlgorithms.Add(em_sensor_extractor)
      
      	# Adding a new FieldSnapshotFilter
      	inputs = [thermo_sensor_extractor.Outputs["T(x,y,z,t)"]]
      	field_snapshot_filter = analysis.field.FieldSnapshotFilter(inputs=inputs)
      	field_snapshot_filter.Snapshot = u"1806 s"
      	field_snapshot_filter.UpdateAttributes()
      	document.AllAlgorithms.Add(field_snapshot_filter)
      
      	# Adding a new FieldInterpolationFilter
      	inputs = [field_snapshot_filter.Outputs["T(x,y,z,t)"], em_sensor_extractor.Outputs["EM E(x,y,z,f0)"]]
      	field_interpolation_filter = analysis.core.FieldInterpolationFilter(inputs=inputs)
      	field_interpolation_filter.UpdateAttributes()
      	document.AllAlgorithms.Add(field_interpolation_filter)
      
      	# Adding a new SliceFieldViewer
      	inputs = [field_interpolation_filter.Outputs["T(x,y,z,t)"]]
      	slice_field_viewer = analysis.viewers.SliceFieldViewer(inputs=inputs)
      	slice_field_viewer.Data.Mode = slice_field_viewer.Data.Mode.enum.QuantityRealModulus
      	slice_field_viewer.Slice.Index = 41
      	slice_field_viewer.UpdateAttributes()
      	document.AllAlgorithms.Add(slice_field_viewer)
      
      except Exception as exc:
      	import traceback
      	traceback.print_exc(exc)
      	# Reset active version to default
      	ReleaseVersion.reset()
      	raise(exc)
      A 1 Reply Last reply
      0
      • A Offline
        A Offline
        Aiping
        wrote on last edited by
        #3

        Thanks, I will try it.

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

          @sylvain said in How can I interpolate the last snapshot of data in thermal simulation:

          field_snapshot_filter.Outputs["T(x,y,z,t)"
          Dear Sylvain,
          I tried "extract snapsho", it worked in the workbench, but in the script it doesn't work.
          Here is the error:

          "
          Traceback (most recent call last):
          File "C:\Users\yao\Documents\Sim4Life\Python Script\Myscript\extraction_sar2T_all.py", line 185, in <module>
          field_snapshot_filter.Snapshot = u"1200 s"
          File "C:\Program Files\Sim4Life_v3.4.1.2244\s4l_v1_api\propbinders.py", line 101, in fsetter
          api_prop.set(value)
          File "C:\Program Files\Sim4Life_v3.4.1.2244\s4l_v1_api\propwrappers.py", line 306, in set
          raise ValueError("Invalid value, '{0}' not in {1}".format(inputvalue, self.enum))
          ValueError: Invalid value, '1200 s' not in None
          "

          can you please help to have a look why is that?

          Thank you very much.

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

            Hi,
            Maybe try to add

            field_snapshot_filter.UpdateAttributes()

            before selecting the snapshot.

            1 Reply Last reply
            0
            • SylvainS Sylvain

              Note: the following is in Sim4Life 3.4, I am not sure to what extent it works with older versions.

              There is an "Extract Snapshot" algorithm, which you can use to extract only the latest snapshot of your data. You can then use its output as an input for the "Interpolator" algorithm:

              0_1505292898775_703e5143-f412-470e-9d74-77b2a36b9d26-image.png

              0_1505293002178_649b5a47-1222-4144-b114-5c36cc5ab838-image.png

              You can do the same thing from Python (I used the "To-Python" tool)

              # -*- coding: utf-8 -*-
              # This script was auto-generated by Sim4Life version 3.4.2.2438
              
              import numpy
              import s4l_v1.analysis as analysis
              import s4l_v1.document as document
              import s4l_v1.model as model
              import s4l_v1.units as units
              from s4l_v1 import ReleaseVersion
              from s4l_v1 import Unit
              
              try:
              	# Define the version to use for default values
              	ReleaseVersion.set_active(ReleaseVersion.version3_4)
              	
              	# Creating the analysis pipeline
              	# Adding a new SimulationExtractor
              	simulation = document.AllSimulations["Heating"]
              	simulation_extractor = simulation.Results()
              
              	# Adding a new SimulationExtractor
              	simulation = document.AllSimulations["Dipole"]
              	simulation_extractor_2 = simulation.Results()
              
              	# Adding a new ThermoSensorExtractor
              	thermo_sensor_extractor = simulation_extractor["Overall Field"]
              	document.AllAlgorithms.Add(thermo_sensor_extractor)
              
              	# Adding a new EmSensorExtractor
              	em_sensor_extractor = simulation_extractor_2["Overall Field"]
              	em_sensor_extractor.FrequencySettings.ExtractedFrequency = u"All"
              	em_sensor_extractor.SurfaceCurrent.SurfaceResolution = 0.001, units.Meters
              	document.AllAlgorithms.Add(em_sensor_extractor)
              
              	# Adding a new FieldSnapshotFilter
              	inputs = [thermo_sensor_extractor.Outputs["T(x,y,z,t)"]]
              	field_snapshot_filter = analysis.field.FieldSnapshotFilter(inputs=inputs)
              	field_snapshot_filter.Snapshot = u"1806 s"
              	field_snapshot_filter.UpdateAttributes()
              	document.AllAlgorithms.Add(field_snapshot_filter)
              
              	# Adding a new FieldInterpolationFilter
              	inputs = [field_snapshot_filter.Outputs["T(x,y,z,t)"], em_sensor_extractor.Outputs["EM E(x,y,z,f0)"]]
              	field_interpolation_filter = analysis.core.FieldInterpolationFilter(inputs=inputs)
              	field_interpolation_filter.UpdateAttributes()
              	document.AllAlgorithms.Add(field_interpolation_filter)
              
              	# Adding a new SliceFieldViewer
              	inputs = [field_interpolation_filter.Outputs["T(x,y,z,t)"]]
              	slice_field_viewer = analysis.viewers.SliceFieldViewer(inputs=inputs)
              	slice_field_viewer.Data.Mode = slice_field_viewer.Data.Mode.enum.QuantityRealModulus
              	slice_field_viewer.Slice.Index = 41
              	slice_field_viewer.UpdateAttributes()
              	document.AllAlgorithms.Add(slice_field_viewer)
              
              except Exception as exc:
              	import traceback
              	traceback.print_exc(exc)
              	# Reset active version to default
              	ReleaseVersion.reset()
              	raise(exc)
              A Offline
              A Offline
              Aiping
              wrote on last edited by
              #6

              @sylvain
              Never mind, I figured it out why.

              Thanks anyway

              1 Reply Last reply
              0
              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