Output 'out' is a vector.

Pulse have a delay and then are periodic.
Pulses are sequentially pushed to each vector element (node pair).
This commit is contained in:
Holger Vogt 2025-05-19 22:28:01 +02:00
parent 40375934da
commit 87e2b365fd
2 changed files with 92 additions and 29 deletions

View File

@ -60,7 +60,23 @@ NON-STANDARD FEATURES
/*=== LOCAL VARIABLES & TYPEDEFS =======*/
static void
cm_seegen_callback(ARGS, Mif_Callback_Reason_t reason)
{
switch (reason) {
case MIF_CB_DESTROY: {
double *last_t_value = STATIC_VAR (last_t_value);
if (last_t_value)
free(last_t_value);
STATIC_VAR (last_t_value) = NULL;
int *pulse_number = STATIC_VAR (pulse_number);
if (pulse_number)
free(pulse_number);
STATIC_VAR (pulse_number) = NULL;
break;
}
}
}
/*=== FUNCTION PROTOTYPE DEFINITIONS ===*/
@ -108,12 +124,15 @@ NON-STANDARD FEATURES
void cm_seegen(ARGS) /* structure holding parms,
inputs, outputs, etc. */
{
double talpha;
double tbeta;
double tdelay;
double inull;
double out;
double tcurr = TIME;
double talpha; /* parameter alpha */
double tbeta; /* parameter beta */
double tdelay; /* delay until first pulse */
double inull; /* max. current of pulse */
double tperiod; /* pulse repetition period */
double out; /* output current */
double *last_t_value; /* static storage of next pulse time */
int *pulse_number; /* static storage of next pulse time */
double tcurr = TIME; /* current simulation time */
/* Retrieve frequently used parameters... */
@ -121,14 +140,35 @@ void cm_seegen(ARGS) /* structure holding parms,
talpha = PARAM(talpha);
tbeta = PARAM(tbeta);
tdelay = PARAM(tdelay);
tperiod = PARAM(tperiod);
inull = PARAM(inull);
if (tcurr < tdelay)
out = 0;
else
out = inull * (exp(-(tcurr-tdelay)/talpha) - exp(-(tcurr-tdelay)/tbeta));
if (INIT==1) {
/* Allocate storage for last_t_value */
STATIC_VAR(last_t_value) = (double *) malloc(sizeof(double));
last_t_value = (double *) STATIC_VAR(last_t_value);
*last_t_value = tdelay;
STATIC_VAR(pulse_number) = (int *) malloc(sizeof(int));
pulse_number = (int *) STATIC_VAR(pulse_number);
*pulse_number = 1;
}
else {
OUTPUT(out) = out;
last_t_value = (double *) STATIC_VAR(last_t_value);
pulse_number = (int *) STATIC_VAR(pulse_number);
if (tcurr < *last_t_value)
out = 0;
else
out = inull * (exp(-(tcurr-*last_t_value)/talpha) - exp(-(tcurr-*last_t_value)/tbeta));
if (tcurr > *last_t_value + tperiod * 0.9) {
*last_t_value = *last_t_value + tperiod;
(*pulse_number)++;
}
if (*pulse_number - 1 < PORT_SIZE(out))
OUTPUT(out[*pulse_number - 1]) = out;
}
}

View File

@ -30,13 +30,13 @@ Description: "single event effect generator"
PORT_TABLE:
Port_Name: out
Description: "output"
Direction: out
Port_Name: out
Description: "output"
Direction: out
Default_Type: i
Allowed_Types: [i,id]
Vector: no
Vector_Bounds: -
Vector: yes
Vector_Bounds: [1 -]
Null_Allowed: no
@ -44,23 +44,46 @@ PARAMETER_TABLE:
Parameter_Name: talpha tbeta
Description: "alpha" "beta"
Data_Type: real real
Data_Type: real real
Default_Value: 500e-12 10e-12
Limits: - -
Vector: no no
Vector_Bounds: - -
Null_Allowed: yes yes
Limits: - -
Vector: no no
Vector_Bounds: - -
Null_Allowed: yes yes
PARAMETER_TABLE:
Parameter_Name: tdelay inull
Description: "pulse delay" "max current"
Data_Type: real real
Default_Value: 0 200e-6
Limits: - -
Vector: no no
Vector_Bounds: - -
Null_Allowed: yes yes
Data_Type: real real
Default_Value: 0 200e-6
Limits: - -
Vector: no no
Vector_Bounds: - -
Null_Allowed: yes yes
PARAMETER_TABLE:
Parameter_Name: tperiod
Description: "pulse repetition"
Data_Type: real
Default_Value: 0
Limits: -
Vector: no
Vector_Bounds: -
Null_Allowed: yes
STATIC_VAR_TABLE:
Static_Var_Name: last_t_value
Data_Type: pointer
Vector: no
Description: "next pulse start time"
STATIC_VAR_TABLE:
Static_Var_Name: pulse_number
Data_Type: pointer
Vector: no
Description: "number of pulse"