From 44fd33ea7d3d3b94221a52d8f1668f79e533410f Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 8 Feb 2026 15:47:04 +0100 Subject: [PATCH] Add a command 'degsim' to reset the circuit, remove the monitors, and add the degradation model to each degraded device. Use function preparedegsim() to add the model with parameters from degdatahash. --- .../degradation/Inverter_degmon_new_2.cir | 2 ++ src/frontend/commands.c | 6 +++++- src/frontend/inp.c | 16 +++++++++++++++- src/frontend/inpdeg.c | 10 ++++++++++ src/frontend/runcoms2.c | 19 +++++++++++++++++++ src/frontend/runcoms2.h | 1 + 6 files changed, 52 insertions(+), 2 deletions(-) diff --git a/examples/degradation/Inverter_degmon_new_2.cir b/examples/degradation/Inverter_degmon_new_2.cir index 1b8c1b27d..51870e30e 100644 --- a/examples/degradation/Inverter_degmon_new_2.cir +++ b/examples/degradation/Inverter_degmon_new_2.cir @@ -32,6 +32,8 @@ pre_osdi ../lib/ngspice/psp103_nqs.osdi pre_osdi ../lib/ngspice/psp103.osdi run rusage +degsim +run *set nolegend set xbrushwidth=3 plot xnot1.mon1 xnot2.mon1 xnot3.mon1 diff --git a/src/frontend/commands.c b/src/frontend/commands.c index 3de1ba6fb..41a127c34 100644 --- a/src/frontend/commands.c +++ b/src/frontend/commands.c @@ -448,7 +448,11 @@ struct comm spcp_coms[] = { { "reset", com_rset, TRUE, TRUE, { 0, 0, 0, 0 }, E_DEFHMASK, 0, 0, NULL, - ": Terminate a simulation after a breakpoint (formerly 'end')." } , + ": Remove current ciuit, reload circuit from internal storage." } , + { "degsim", com_degsim, TRUE, TRUE, + { 0, 0, 0, 0 }, E_DEFHMASK, 0, 0, + NULL, + ": Remove current circuit, reload and modify circuit." } , { "run", com_run, TRUE, TRUE, { 0, 0, 0, 0 }, E_DEFHMASK, 0, 1, NULL, diff --git a/src/frontend/inp.c b/src/frontend/inp.c index e17977c78..79a5cc016 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -64,6 +64,8 @@ static void rem_unused_mos_models(struct card* deck); extern void com_optran(wordlist * wl); extern void tprint(struct card *deck); +static bool wantdegsim = FALSE; +extern int preparedegsim(struct card* deck); //void inp_source_recent(void); //void inp_mc_free(void); @@ -1091,7 +1093,15 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) if (newcompat.hs || newcompat.spe) rem_unused_mos_models(deck->nextcard); #endif - /* Parsing the circuit 5. + /* If compatmode is de and degsim is set by command 'degsim', + translate the netlist by removing the monitors and adding the + extra degradation elements. */ + if (wantdegsim && newcompat.de) { + wantdegsim = FALSE; + preparedegsim(deck); + } + + /* Parsing the circuit 5. This is the next major step: load deck into ft_curckt -- the current circuit. */ if(inp_dodeck(deck, tt, wl_first, FALSE, options, filename) != 0) @@ -2679,6 +2689,10 @@ struct mlist { bool checked; }; +void setdegsim(void) { + wantdegsim = TRUE; +} + #ifdef REM_UNUSED /* Finally get rid of unused MOS models */ static void rem_unused_mos_models(struct card* deck) { diff --git a/src/frontend/inpdeg.c b/src/frontend/inpdeg.c index d33ff436b..605f29d0c 100644 --- a/src/frontend/inpdeg.c +++ b/src/frontend/inpdeg.c @@ -15,6 +15,8 @@ License: Modified BSD #include "inpcom.h" +int preparedegsim(struct card* deck); + /* maximum number of model parameters */ #define DEGPARAMAX 64 /* maximum number of models */ @@ -296,3 +298,11 @@ int remsqrbra(struct card* deck) { } return 0; } + +/* Remove the degradation monitors. + Add current measurement, delta_vg and current source. + Use the data retrieved from degdatahash */ +int preparedegsim(struct card* deck) { + fprintf(stdout, "Note: degradation simulation prepared.\n"); + return 0; +} diff --git a/src/frontend/runcoms2.c b/src/frontend/runcoms2.c index baf43ee79..e06d3501d 100644 --- a/src/frontend/runcoms2.c +++ b/src/frontend/runcoms2.c @@ -36,6 +36,8 @@ extern void line_free_x(struct card *deck, bool recurse); extern INPmodel *modtab; extern NGHASHPTR modtabhash; +extern void setdegsim(void); + #ifdef SHARED_MODULE extern void exec_controls(wordlist *newcontrols); #endif @@ -169,6 +171,23 @@ com_resume(wordlist *wl) } +/* Throw out the circuit struct and recreate it from the deck. */ +void +com_degsim(wordlist* wl) +{ + NG_IGNORE(wl); + + if (ft_curckt == NULL) { + fprintf(cp_err, "Warning: there is no circuit loaded.\n"); + fprintf(cp_err, " Command 'reset' is ignored.\n"); + return; + } + com_remcirc(NULL); + setdegsim(); + inp_source_recent(); +} + + /* Throw out the circuit struct and recreate it from the deck. */ void com_rset(wordlist *wl) diff --git a/src/frontend/runcoms2.h b/src/frontend/runcoms2.h index 957a64ece..7c52e5776 100644 --- a/src/frontend/runcoms2.h +++ b/src/frontend/runcoms2.h @@ -9,5 +9,6 @@ void com_resume(wordlist *wl); void com_rset(wordlist *wl); void com_remcirc(wordlist *wl); +void com_degsim(wordlist* wl); #endif