Dear all,

for some projects, it is valuable to be able to plot a specific parameter on a surface. For instance, consider you want to plot energy density in spherical capacitor which is proportional to square of electric field. for this purpose, you can write python code like below:

import numpy
import s4l_v1 as s4l
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

# Define the version to use for default values
ReleaseVersion.set_active(ReleaseVersion.version5_2)

# Creating the analysis pipeline
# Adding a new SimulationExtractor
simulation = document.AllSimulations["LF Unstructured"]
simulation_extractor = simulation.Results()

# Adding a new ModelToGridFilter
inputs = []
model_to_grid_filter = analysis.core.ModelToGridFilter(inputs=inputs)
model_to_grid_filter.Name = "desired surface"
model_to_grid_filter.Entity = model.AllEntities()["desired surface"]
model_to_grid_filter.MaximumEdgeLength = 0.1e-3, units.Meters
model_to_grid_filter.UpdateAttributes()
document.AllAlgorithms.Add(model_to_grid_filter)

# Adding a new EmSensorExtractor
em_sensor_extractor = simulation_extractor["Overall Field"]
em_sensor_extractor.FrequencySettings.ExtractedFrequency = u"All"
document.AllAlgorithms.Add(em_sensor_extractor)

# Adding a new FieldInterpolationFilter
inputs = [em_sensor_extractor.Outputs["EM E(x,y,z,f0)"], model_to_grid_filter.Outputs["Surface"]]
field_interpolation_filter = analysis.core.FieldInterpolationFilter(inputs=inputs)
field_interpolation_filter.UpdateAttributes()
document.AllAlgorithms.Add(field_interpolation_filter)

#
field = field_interpolation_filter.Outputs[0]
field.Update()

#get data
data = field.Data.Field(0)

#compute desired value
out=data**2

#
target_grid=model_to_grid_filter.Outputs[0].Data

#
energy_density= s4l.analysis.core.ComplexFloatFieldData()
energy_density.Allocate(1,target_grid.NumberOfPoints, 1)
energy_density.Grid = target_grid
energy_density.Quantity.Name = "out"
energy_density.SnapshotQuantity = field.Data.SnapshotQuantity
energy_density.Snapshots = field.Data.Snapshots
energy_density.ValueLocation = field.Data.ValueLocation
energy_density.SetField(0, out)
energy_density.Check()

source = s4l.analysis.core.TrivialProducer()
source.SetDataObject(energy_density)

inputs = [source.Outputs["out"]]
surface_viewer = analysis.viewers.SurfaceViewer(inputs=inputs)
surface_viewer.Data.Mode = surface_viewer.Data.Mode.enum.QuantityRealPart
surface_viewer.UpdateAttributes()
document.AllAlgorithms.Add(surface_viewer)	
surface_viewer.Update()