diff options
author | couriersud <couriersud@gmx.org> | 2020-04-25 18:08:04 +0200 |
---|---|---|
committer | couriersud <couriersud@gmx.org> | 2020-04-25 18:08:04 +0200 |
commit | d3ee7e21c6f52a794e67beda0d3bffa32179d03c (patch) | |
tree | 145711c33db8106a7c347014fbe390caaae98ff8 /src/lib/netlist/analog/nlid_twoterm.cpp | |
parent | 14f92c9786572699754473eecb9d47e8f95db0bb (diff) |
netlist: unify solver calls. (nw)
Calls to the solver used different paths. These changes unify these
calls and provide a common call for discontinuous state changes on
analog components (change_state).
Diffstat (limited to 'src/lib/netlist/analog/nlid_twoterm.cpp')
-rw-r--r-- | src/lib/netlist/analog/nlid_twoterm.cpp | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/src/lib/netlist/analog/nlid_twoterm.cpp b/src/lib/netlist/analog/nlid_twoterm.cpp index 2573103d06b..c57d76c821e 100644 --- a/src/lib/netlist/analog/nlid_twoterm.cpp +++ b/src/lib/netlist/analog/nlid_twoterm.cpp @@ -15,25 +15,22 @@ namespace analog // nld_twoterm // ---------------------------------------------------------------------------------------- - void NETLIB_NAME(twoterm)::solve_now() + solver::matrix_solver_t * NETLIB_NAME(twoterm)::solver() const noexcept { - // we only need to call the non-rail terminal - if (m_P.has_net() && !m_P.net().is_rail_net()) - m_P.solve_now(); - else if (m_N.has_net() && !m_N.net().is_rail_net()) - m_N.solve_now(); + auto *solv(m_P.solver()); + if (solv) + return solv; + return m_N.solver(); } - void NETLIB_NAME(twoterm)::solve_later(netlist_time delay) noexcept + + void NETLIB_NAME(twoterm)::solve_now() const { - // we only need to call the non-rail terminal - if (m_P.has_net() && !m_P.net().is_rail_net()) - m_P.schedule_solve_after(delay); - else if (m_N.has_net() && !m_N.net().is_rail_net()) - m_N.schedule_solve_after(delay); + auto *solv(solver()); + if (solv) + solv->solve_now(); } - NETLIB_UPDATE(twoterm) { // only called if connected to a rail net ==> notify the solver to recalculate @@ -66,19 +63,22 @@ namespace analog NETLIB_UPDATE_PARAM(POT) { - // FIXME: We only need to update the net first if this is a time stepping net - m_R1.solve_now(); - m_R2.solve_now(); - nl_fptype v = m_Dial(); if (m_DialIsLog()) v = (plib::exp(v) - nlconst::one()) / (plib::exp(nlconst::one()) - nlconst::one()); if (m_Reverse()) v = nlconst::one() - v; - m_R1.set_R(std::max(m_R() * v, exec().gmin())); - m_R2.set_R(std::max(m_R() * (nlconst::one() - v), exec().gmin())); - m_R1.solve_later(); - m_R2.solve_later(); + + nl_fptype r1(std::max(m_R() * v, exec().gmin())); + nl_fptype r2(std::max(m_R() * (nlconst::one() - v), exec().gmin())); + + if (m_R1.solver() == m_R2.solver()) + m_R1.change_state([this, &r1, &r2]() { m_R1.set_R(r1); m_R2.set_R(r2); }); + else + { + m_R1.change_state([this, &r1]() { m_R1.set_R(r1); }); + m_R2.change_state([this, &r2]() { m_R2.set_R(r2); }); + } } @@ -100,17 +100,17 @@ namespace analog NETLIB_UPDATE_PARAM(POT2) { - // FIXME: We only need to update the net first if this is a time stepping net - m_R1.solve_now(); - nl_fptype v = m_Dial(); if (m_DialIsLog()) v = (plib::exp(v) - nlconst::one()) / (plib::exp(nlconst::one()) - nlconst::one()); if (m_Reverse()) v = nlconst::one() - v; - m_R1.set_R(std::max(m_R() * v, exec().gmin())); - m_R1.solve_later(); + + m_R1.change_state([this, &v]() + { + m_R1.set_R(std::max(m_R() * v, exec().gmin())); + }); } // ---------------------------------------------------------------------------------------- |