From 0dfa500a4a4a72805d3ea42eb24c6e2922cffa72 Mon Sep 17 00:00:00 2001 From: couriersud Date: Thu, 16 Jul 2020 09:34:57 +0200 Subject: [PATCH] netlist: Fix Inductor state saving. --- src/lib/netlist/analog/nlid_twoterm.cpp | 5 +++++ src/lib/netlist/analog/nlid_twoterm.h | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib/netlist/analog/nlid_twoterm.cpp b/src/lib/netlist/analog/nlid_twoterm.cpp index 0fc84c06d43..97b3f5e55ac 100644 --- a/src/lib/netlist/analog/nlid_twoterm.cpp +++ b/src/lib/netlist/analog/nlid_twoterm.cpp @@ -43,6 +43,7 @@ namespace analog NETLIB_RESET(R_base) { + // FIXME: this reset is causing issues. Remove. NETLIB_NAME(twoterm)::reset(); set_R(plib::reciprocal(exec().gmin())); } @@ -135,6 +136,7 @@ namespace analog if (ts_type == timestep_type::FORWARD) { m_last_I = m_I; + m_last_G = m_G; // Gpar should support convergence m_I += m_G * deltaV(); m_G = step / m_L() + m_gmin; @@ -142,7 +144,10 @@ namespace analog -m_G, m_G, m_I); } else + { m_I = m_last_I; + m_G = m_last_G; + } } // ---------------------------------------------------------------------------------------- diff --git a/src/lib/netlist/analog/nlid_twoterm.h b/src/lib/netlist/analog/nlid_twoterm.h index 8a970ac16ac..d7574a1cb35 100644 --- a/src/lib/netlist/analog/nlid_twoterm.h +++ b/src/lib/netlist/analog/nlid_twoterm.h @@ -415,9 +415,10 @@ namespace analog NETLIB_CONSTRUCTOR(L) , m_L(*this, "L", nlconst::magic(1e-6)) , m_gmin(nlconst::zero()) - , m_G(nlconst::zero()) - , m_I(nlconst::zero()) - , m_last_I(nlconst::zero()) + , m_G(*this, "m_G", nlconst::zero()) + , m_I(*this, "m_I", nlconst::zero()) + , m_last_I(*this, "m_last_I", nlconst::zero()) + , m_last_G(*this, "m_last_G", nlconst::zero()) { //register_term("1", m_P); //register_term("2", m_N); @@ -435,9 +436,10 @@ namespace analog param_fp_t m_L; nl_fptype m_gmin; - nl_fptype m_G; - nl_fptype m_I; - nl_fptype m_last_I; + state_var m_G; + state_var m_I; + state_var m_last_I; + state_var m_last_G; }; /// \brief Class representing the diode model paramers.