Modeling
The modeling of analog elements in pyams.lib is based on defining their behavior using the Python language while following a structured approach:
Declaring the required library;
Defining the model name;
Specifying parameters with initial values;
Defining signal types (current or voltage);
Adding sub-models if applicable;
Establishing relationships between signals and parameters.
The general structure for modeling an analog element in pyams.lib is illustrated in the following example:
from pyams.lib import model, signal # Library declaration
class NameOfElement(model): # Model definition
def __init__(self, ports): # Initialization function
# Declare signals (analog or digital) and parameters
def sub(self): # Sub-function
# Define sub-circuit or sub-model
def start(self): # Start function
# Initialize values at the start of simulation
def analog(self): # Analog function
# Define equations or analog operations
def digital(self): # Digital function
# Define digital operations
Initial and Analog Functions
The initialization function (def __init__
) is used to create ports for connections, define signals (analog or digital),
and set default values for variables and parameters. The analog function (def analog
) or digital function (def digital
) is responsible for defining the mathematical relationships between signals and parameters, representing the behavioral model of analog or digital elements .
The __init__
, analog
or ``digital``functions are the core components of a model. Additionally, there are two optional functions:
Sub-function: Used to construct sub-circuits within the model.
Start function: Initializes values when starting a simulation.
Signals and Parameters in pyams.lib
Signals in pyams.lib represent electrical quantities (voltage or current) and define how connections are established within the model. Signal declaration follows this syntax:
signal([Direction, Type, Port_p, Port_n])
where:
Direction
specifies whether the signal isin
orout
.Type
defines the signal as eithercurrent
orvoltage
.Port_p
andPort_n
indicate the positive and negative terminals of the connection.
Parameters in an analog model are constants or variables that influence circuit behavior. They are declared as follows:
param([Value, Unit, Description])
where:
Value
is the default parameter value.Unit
specifies the measurement unit.Description
provides a brief explanation of the parameter.
Allowed Operations Between Signals and Parameters
The following table summarizes the mathematical and logical operations available in pyams.lib:
Operation |
Description |
Result |
---|---|---|
+ |
Addition |
real |
- |
Subtraction |
real |
* |
multiplication |
real |
/ |
division |
real |
** |
exponentiation |
real |
== |
test for equality |
boolean |
!= |
test for inequality |
boolean |
< |
test for less than |
boolean |
<= |
test for less than or equal |
boolean |
> |
test for greater than |
boolean |
>= |
test for greater than or equal |
boolean |
+= |
get value |
real |