diff options
Diffstat (limited to 'src/lib/netlist/solver/nld_ms_direct2.h')
-rw-r--r-- | src/lib/netlist/solver/nld_ms_direct2.h | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/src/lib/netlist/solver/nld_ms_direct2.h b/src/lib/netlist/solver/nld_ms_direct2.h index 4004bce9cc4..01f77c3bc3c 100644 --- a/src/lib/netlist/solver/nld_ms_direct2.h +++ b/src/lib/netlist/solver/nld_ms_direct2.h @@ -13,43 +13,46 @@ namespace netlist { - namespace devices - { -class matrix_solver_direct2_t: public matrix_solver_direct_t<2,2> +namespace devices { -public: - matrix_solver_direct2_t(netlist_t &anetlist, const pstring &name, const solver_parameters_t *params) - : matrix_solver_direct_t<2, 2>(anetlist, name, params, 2) - {} - virtual unsigned vsolve_non_dynamic(const bool newton_raphson) override; + // ---------------------------------------------------------------------------------------- + // matrix_solver - Direct2 + // ---------------------------------------------------------------------------------------- + + template <typename FT> + class matrix_solver_direct2_t: public matrix_solver_direct_t<FT, 2> + { + public: -}; + using float_type = FT; -// ---------------------------------------------------------------------------------------- -// matrix_solver - Direct2 -// ---------------------------------------------------------------------------------------- + matrix_solver_direct2_t(netlist_state_t &anetlist, const pstring &name, const solver_parameters_t *params) + : matrix_solver_direct_t<double, 2>(anetlist, name, params, 2) + {} + unsigned vsolve_non_dynamic(const bool newton_raphson) override + { + this->build_LE_A(*this); + this->build_LE_RHS(*this); -inline unsigned matrix_solver_direct2_t::vsolve_non_dynamic(ATTR_UNUSED const bool newton_raphson) -{ - build_LE_A<matrix_solver_direct2_t>(); - build_LE_RHS<matrix_solver_direct2_t>(); + const float_type a = this->A(0,0); + const float_type b = this->A(0,1); + const float_type c = this->A(1,0); + const float_type d = this->A(1,1); - const nl_double a = A(0,0); - const nl_double b = A(0,1); - const nl_double c = A(1,0); - const nl_double d = A(1,1); + const float_type v1 = (a * this->RHS(1) - c * this->RHS(0)) / (a * d - b * c); + const float_type v0 = (this->RHS(0) - b * v1) / a; + std::array<float_type, 2> new_V = {v0, v1}; - nl_double new_V[2]; - new_V[1] = (a * RHS(1) - c * RHS(0)) / (a * d - b * c); - new_V[0] = (RHS(0) - b * new_V[1]) / a; + this->m_stat_calculations++; + const float_type err = (newton_raphson ? this->delta(new_V) : 0.0); + this->store(new_V); + return (err > this->m_params.m_accuracy) ? 2 : 1; + } - const nl_double err = (newton_raphson ? delta(new_V) : 0.0); - store(new_V); - return (err > this->m_params.m_accuracy) ? 2 : 1; -} + }; - } //namespace devices +} //namespace devices } // namespace netlist #endif /* NLD_MS_DIRECT2_H_ */ |