Skip to content

Spice model architecture and Spice Model Editor rework

Mikolaj Wielgus requested to merge mwielgus/kicad:model-editor into master

Description

Currently, Spice models that can be assigned to symbols are described by just 5 strings (stored in fields), aggregated in a plain struct, that are later merely concatenated into Spice commands during netlist export. Each model processed the same way (apart from some if statements). This MR changes the internal architecture to instead store models in objects deriving from a polymorphic SIM_MODEL class, allowing to handle each model differently, in the usual obiect-oriented fashion.

The old models are automatically (on the fly when Spice Model Editor is opened) converted to raw (plaintext) models implemented in a SIM_MODEL_SPICE class (all classes named SIM_MODEL_* derive from SIM_MODEL), preserving the original behavior.

Some device models, primarily semiconductors (which have just too many parameters), are implemented using a generic SIM_MODEL_NGSPICE class that sources its model descriptions (mostly the parameters) from eeschema/sim/ngspice_models.cpp that was mostly automatically extracted from Ngspice with a Bash script.

The remaining models are implemented in SIM_MODEL_BEHAVIORAL (behavioral devices: RLC, voltage sources, current sources), SIM_MODEL_IDEAL (ideal RLC), SIM_MODEL_PASSIVE (non-ideal RLC), SIM_MODEL_SOURCE (voltage and current sources), SIM_MODEL_SUBCKT (Spice subcircuits), SIM_MODEL_TLINE (transmission lines), SIM_MODEL_XSPICE (XSPICE devices, not implemented yet) classes.

The Spice netlist exporter and the Spice Model Editor dialog are completely rewritten to use SIM_MODEL objects.

Minimum Ngspice version is ngspice-37.

Files

New files under the eeschema/ directory:

  • netlist_exporters/netlist_exporter_spice.{cpp,h} hold the new NETLIST_EXPORTER_SPICE class that implements the new Spice exporter. eeschema/netlist_exporter/netlist_exporter_pspice.{cpp,h} that contained the old exporter is deleted.
  • dialogs/dialog_sim_model_base.{cpp,h} and dialogs/dialog_sim_model.{cpp,h} hold the new Spice Model Editor dialog, DIALOG_SIM_MODEL. dialogs/dialog_spice_model_base.{cpp,h,fbp} and dialogs/dialog_spice_model_base.{cpp,h,fbp} that contained the old dialog are deleted.
  • sim/ngspice_models.cpp hold SIM_MODEL_NGSPICE model descriptions, which were automatically extracted from Ngspice.
  • sim/sim_property.{cpp,h} hold SIM_PROPERTY, a subclass of wxStringProperty, used to display model parameters in Spice Model Editor.
  • sim/sim_library.{cpp,h} hold the SIM_LIBRARY abstract class that represents a model library.
  • sim/sim_library_spice.{cpp,h} hold SIM_LIBRARY_SPICE, an implementation of SIM_LIBRARY (the only one so far), which represents a Spice netlist file with models.
  • sim/sim_model.{cpp,h} hold SIM_MODEL, the base class for all models.
  • sim/sim_model_*.{cpp,h} hold subclasses of SIM_MODEL.
  • sim/sim_value.{cpp,h} hold SIM_VALUE (abstract class) and its implementations.
  • sim/spice_grammar.h holds the PEG grammar used to parse Spice netlists.

Some QA tests for the new features are created under the qa/ directory.

Edited by Mikolaj Wielgus

Merge request reports

Loading