Skip to content
  • Is the function "To Polyline" available from the API?

    Python API
    2
    0 Votes
    2 Posts
    323 Views
    brynB

    I had a look but also did not find it, so I added a function ConvertToPolyline which will become available in the next release (you can test it internally next week).

  • 0 Votes
    1 Posts
    453 Views
    No one has replied
  • 0 Votes
    1 Posts
    615 Views
    No one has replied
  • Moving from SEMCAD 14.8 to Sim4Life python API

    Pinned Python API
    3
    2 Votes
    3 Posts
    1k Views
    pcrespoP

    @pcrespo said in Moving from SEMCAD 14.8 to Sim4Life python API:

    How can we synchronize the entities in a model with a simulation (say, s4l_v1.simulation.emfdtd.Simulation)? Previously, the SolidRegions in a simulation seemed to be synchronized with model entities automatically, but it seems that SolidRegions are not available in simulations anymore.

    Yes, the philosophy there changed a bit. The idea is that every context adds a new layer of information on top of the previous one. When the user starts modeling, it is expected to define the geometry of the problem. For instance, what is the shape, position and size of a given entity.

    The simulation context adds the necessary information to the geometry of the problem so that we can perform a numerical simulation. These new settings could be related with the physics of the problem (e.g. electric properties of a given geometry ) or with the numerical method (e.g. fdtd grid details for the discretization of a given geometry). Creating a simulation in the UI reveals what type of settings each simulation type adds on the associated modeling entities.

    Another big different with respect to SEMCAD is that every simulation uses a selection of entities instead of using by default all and having to unselect/ignore them. It has the same result but the producer is reversed.

    Then, coming back to the API, assume we want to simulate a dipole antenna.. To start I modeled two arms and a line to define the feed. I can retrieve them by name as follows:

    import s4l_v1.model as model entities = model.AllEntities() arm1 = entities['Arm 1'] arm2 = entities['Arm 2'] line = entities['SourceLine']

    Now i want to create a simulation that uses this geometry. In order to assign a material to these entities, I need to
    a) associate the entities to the simulation (they become simulation components)
    b) create material settings and
    c) assign these settings to the associated entities.
    The API provides a shortcut for these three operations simulation.Add*Settings . This directly returns the settings object assigned to the entity within this simulation. Then we can set the values of the different properties:

    simulation = fdtd.Simulation() # ... some general settings ... # Materials: dipole_material = simulation.AddMaterialSettings([arm1, arm2]) dipole_material.Name = 'Dipole Arms' dipole_material.MaterialType = dipole_material.MaterialType.enum.PEC

    and analogously with the line entity:

    edgesrc_settings = sim.AddEdgeSourceSettings([line,]) options = edgesrc_settings.ExcitationType.enum edgesrc_settings.ExcitationType = options.Gaussian edgesrc_settings.CenterFrequency = 300., units.MHz edgesrc_settings.Bandwidth = 300., units.MHz

    The model entity in a simulation and with all the extra layers is now referred as a simulation component. In other words, a simulation component is a geometry (defined by model entity) with several layers of settings corresponding to the physics and the numerical methods.

  • 0 Votes
    5 Posts
    803 Views
    SylvainS

    @CEiber That's a very good idea, thanks a lot!

  • 1 Votes
    1 Posts
    557 Views
    No one has replied
  • Streamline view_arbitrary plane

    Analysis & Postprocessing
    2
    1 Votes
    2 Posts
    314 Views
    SylvainS

    Hi,

    Yes, this is possible, as shown in the example below.
    Note that this sort of scripts can in principle be automatically generated using the "To Python" function from the GUI (in this case by right-clicking on the Streamline Viewer). Here, however, the autogenerated script did not fully work, as it forgets a crucial Update() call before setting up the Plane Center and Normal.

    I hope this helps!

    # Creating the analysis pipeline # Adding a new SimulationExtractor simulation = document.AllSimulations["EM"] simulation_extractor = simulation.Results() # Adding a new EmSensorExtractor em_sensor_extractor = simulation_extractor["Overall Field"] document.AllAlgorithms.Add(em_sensor_extractor) # Adding a new StreamLineViewer inputs = [em_sensor_extractor.Outputs["EM E(x,y,z,f0)"]] stream_line_viewer = analysis.viewers.StreamLineViewer(inputs=inputs) stream_line_viewer.Streamline.SeedSource = stream_line_viewer.Streamline.SeedSource.enum.PlaneSource stream_line_viewer.Update() # this line is needed, otherwise the next lines have no effect stream_line_viewer.Streamline.Plane.PlaneCenter = numpy.array([0.2, 0.05, 0.002]) stream_line_viewer.Streamline.Plane.PlaneNormal = numpy.array([0.2, 0.5, 1.2]) stream_line_viewer.Update() document.AllAlgorithms.Add(stream_line_viewer)
  • 0 Votes
    1 Posts
    401 Views
    No one has replied
  • 0 Votes
    1 Posts
    602 Views
    No one has replied
  • 0 Votes
    1 Posts
    924 Views
    No one has replied
  • Example of mask filter in postpro?

    Python API
    3
    1 Votes
    3 Posts
    827 Views
    pcrespoP

    Thanks so much!

  • Example using the model.Extrude function

    Python API
    1
    0 Votes
    1 Posts
    342 Views
    No one has replied
  • Planar cut using Python

    Python API
    3
    0 Votes
    3 Posts
    552 Views
    SylvainS

    You're welcome! Note, however, that functions that are not part of the s4l_v1 module are not checked for backward compatibility between Sim4Life versions and their signatures are in principle allowed to vary (although this is quite rare, in practice). It is recommended to always try to use functions under the s4l_v1 module when possible, since only these are "officially" part of the API.

    This said, if you need to bend an object in Sim4Life v4.x or lower, use XCoreModeling.PlanarCut 🙂

  • 1 Votes
    3 Posts
    1k Views
    SylvainS

    "Experimental" in that context means that the API may change in the future and that backward compatibility may break.

  • 0 Votes
    3 Posts
    421 Views
    SylvainS

    Brilliant, thanks!

  • Creating coils via Python

    Python API
    1
    1 Votes
    1 Posts
    430 Views
    No one has replied
  • 0 Votes
    2 Posts
    320 Views
    SylvainS

    The function you are looking for is LinkMaterialWithDatabase().

    This is how you can add new material settings with properties taken from the database

    import s4l_v1.document as document import s4l_v1.model as model sim = document.AllSimulations[0] for ent in model.AllEntities(): mats = sim.AddMaterialSettings([ent]) mats.Name = ent.Name sim.LinkMaterialWithDatabase(mats, str(ent.MaterialName))

    To modify the settings of an existing simulation and update their properties, you can do something like this:

    import s4l_v1.simulation as simulation material_settings = [s for s in sim.AllSettings if isinstance(s, simulation.fdtd.MaterialSettings)] for mats in material_settings: material_name = mats.Name sim.LinkMaterialWithDatabase(mats, material_name)
  • Nearest point to a spline

    Solved CAD Modeling
    2
    0 Votes
    2 Posts
    379 Views
    SylvainS

    got it:

    wire = GetWires(spline)[0] curve = wire.GetGeometry(transform_to_model_space=True) law = curve.GetLaw() t0 = curve.MinDistParameter(point_start)
  • How to remove warnings from deprecated functions?

    Python API
    1
    0 Votes
    1 Posts
    189 Views
    No one has replied
  • 4 Votes
    1 Posts
    1k Views
    No one has replied