I am a user of SEMCAD 14.8 python API and I am adapting my scripts to Sim4Life python API.
I have some questions:
@pcrespo said in Moving from SEMCAD 14.8 to Sim4Life python API:
Are SEMCAD.SetModelingMode() and SEMCAD.SetSimulationMode() required anymore? If so, what are their replacements?
No these modes are not necessary anymore. Modeling, simulation and analysis coexist in the same environment without having to call any initialization routine as in SEMCAD 14.8
The new paradigm is that your project is represented as a document
import s4l_v1.document as project # this is a singleton
you can add modeling entities, simulations and analysis algorithms to it. The model entities are added automatically (because we have a single model per project) while the simulations and the analysis algorithms need to be explicitly added,
Every part is now separated in a different package:
import s4l_v1.model as model
import s4l_v1.simulation.emfdtd as fdtd
import s4l_v1.analysis as analysis
# ... can create some modeling .entities using model..
# ... operations to create a new fdtd simulation ...
# ... can create pipelines of algorithms ...
Adding simulation and algorithm instances to the S4L document, renders then automatically in the UI.
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 ...
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.