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

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

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)

Thanks, I will try it.

@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.

Hi,
Maybe try to add

field_snapshot_filter.UpdateAttributes()

before selecting the snapshot.

@sylvain
Never mind, I figured it out why.

Thanks anyway