mirror of
https://github.com/holub/mame
synced 2025-04-25 17:56:43 +03:00
netlist: analog readability refactoring. (nw)
Change the sign of go (or in other terms a12 and a21 matrix stencil elements). This should make further optimization of matrix population easier. In addition hopefully improve the readability of the code by sacrifying overloads for more verbose member names.
This commit is contained in:
parent
8aef30ee42
commit
d00de16b41
@ -293,10 +293,10 @@ NETLIB_RESET(QBJT_switch)
|
||||
|
||||
m_state_on = 0;
|
||||
|
||||
m_RB.set(exec().gmin(), 0.0, 0.0);
|
||||
m_RC.set(exec().gmin(), 0.0, 0.0);
|
||||
m_RB.set_G_V_I(exec().gmin(), 0.0, 0.0);
|
||||
m_RC.set_G_V_I(exec().gmin(), 0.0, 0.0);
|
||||
|
||||
m_BC_dummy.set(exec().gmin() / 10.0, 0.0, 0.0);
|
||||
m_BC_dummy.set_G_V_I(exec().gmin() / 10.0, 0.0, 0.0);
|
||||
|
||||
}
|
||||
|
||||
@ -351,8 +351,8 @@ NETLIB_UPDATE_TERMINALS(QBJT_switch)
|
||||
const nl_double gc = new_state ? m_gC : exec().gmin();
|
||||
const nl_double v = new_state ? m_V * m : 0;
|
||||
|
||||
m_RB.set(gb, v, 0.0);
|
||||
m_RC.set(gc, 0.0, 0.0);
|
||||
m_RB.set_G_V_I(gb, v, 0.0);
|
||||
m_RC.set_G_V_I(gc, 0.0, 0.0);
|
||||
m_state_on = new_state;
|
||||
}
|
||||
}
|
||||
|
@ -26,14 +26,14 @@ NETLIB_RESET(VCCS)
|
||||
const nl_double m_mult = m_G() * m_gfac; // 1.0 ==> 1V ==> 1A
|
||||
const nl_double GI = plib::constants<nl_double>::one() / m_RI();
|
||||
|
||||
m_IP.set(GI);
|
||||
m_IN.set(GI);
|
||||
m_IP.set_conductivity(GI);
|
||||
m_IN.set_conductivity(GI);
|
||||
|
||||
m_OP.set(m_mult, plib::constants<nl_double>::zero());
|
||||
m_OP1.set(-m_mult, plib::constants<nl_double>::zero());
|
||||
m_OP.set_go_gt(-m_mult, plib::constants<nl_double>::zero());
|
||||
m_OP1.set_go_gt(m_mult, plib::constants<nl_double>::zero());
|
||||
|
||||
m_ON.set(-m_mult, plib::constants<nl_double>::zero());
|
||||
m_ON1.set(m_mult, plib::constants<nl_double>::zero());
|
||||
m_ON.set_go_gt(m_mult, plib::constants<nl_double>::zero());
|
||||
m_ON1.set_go_gt(-m_mult, plib::constants<nl_double>::zero());
|
||||
}
|
||||
|
||||
NETLIB_UPDATE(VCCS)
|
||||
@ -79,11 +79,11 @@ NETLIB_UPDATE_TERMINALS(LVCCS)
|
||||
const nl_double beta = m_mult * (1.0 - X*X);
|
||||
const nl_double I = m_cur_limit() * X - beta * m_vi;
|
||||
|
||||
m_OP.set(beta, plib::constants<nl_double>::zero(), I);
|
||||
m_OP1.set(-beta, plib::constants<nl_double>::zero());
|
||||
m_OP.set_go_gt_I(-beta, plib::constants<nl_double>::zero(), I);
|
||||
m_OP1.set_go_gt(beta, plib::constants<nl_double>::zero());
|
||||
|
||||
m_ON.set(-beta, plib::constants<nl_double>::zero(), -I);
|
||||
m_ON1.set(beta, plib::constants<nl_double>::zero());
|
||||
m_ON.set_go_gt_I(beta, plib::constants<nl_double>::zero(), -I);
|
||||
m_ON1.set_go_gt(-beta, plib::constants<nl_double>::zero());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
@ -109,8 +109,8 @@ NETLIB_RESET(VCVS)
|
||||
m_gfac = plib::constants<nl_double>::one() / m_RO();
|
||||
NETLIB_NAME(VCCS)::reset();
|
||||
|
||||
m_OP2.set(plib::constants<nl_double>::one() / m_RO());
|
||||
m_ON2.set(plib::constants<nl_double>::one() / m_RO());
|
||||
m_OP2.set_conductivity(plib::constants<nl_double>::one() / m_RO());
|
||||
m_ON2.set_conductivity(plib::constants<nl_double>::one() / m_RO());
|
||||
}
|
||||
|
||||
} //namespace analog
|
||||
|
@ -198,7 +198,7 @@ NETLIB_UPDATE_PARAM(POT2)
|
||||
NETLIB_RESET(C)
|
||||
{
|
||||
// FIXME: Startup conditions
|
||||
set(exec().gmin(), 0.0, -5.0 / exec().gmin());
|
||||
set_G_V_I(exec().gmin(), 0.0, -5.0 / exec().gmin());
|
||||
//set(exec().gmin(), 0.0, 0.0);
|
||||
}
|
||||
|
||||
@ -255,7 +255,7 @@ NETLIB_RESET(D)
|
||||
nl_double n = m_model.m_N;
|
||||
|
||||
m_D.set_param(Is, n, exec().gmin());
|
||||
set(m_D.G(), 0.0, m_D.Ieq());
|
||||
set_G_V_I(m_D.G(), 0.0, m_D.Ieq());
|
||||
}
|
||||
|
||||
NETLIB_UPDATE_PARAM(D)
|
||||
|
@ -86,11 +86,11 @@ public:
|
||||
|
||||
void solve_later(netlist_time delay = netlist_time::from_nsec(1));
|
||||
|
||||
void set(const nl_double G, const nl_double V, const nl_double I)
|
||||
void set_G_V_I(const nl_double G, const nl_double V, const nl_double I)
|
||||
{
|
||||
/* GO, GT, I */
|
||||
m_P.set( G, G, ( V) * G - I);
|
||||
m_N.set( G, G, ( -V) * G + I);
|
||||
m_P.set_go_gt_I( -G, G, ( V) * G - I);
|
||||
m_N.set_go_gt_I( -G, G, ( -V) * G + I);
|
||||
}
|
||||
|
||||
nl_double deltaV() const
|
||||
@ -98,12 +98,12 @@ public:
|
||||
return m_P.net().Q_Analog() - m_N.net().Q_Analog();
|
||||
}
|
||||
|
||||
void set_mat(const nl_double a11, const nl_double a12, const nl_double r1,
|
||||
const nl_double a21, const nl_double a22, const nl_double r2)
|
||||
void set_mat(const nl_double a11, const nl_double a12, const nl_double rhs1,
|
||||
const nl_double a21, const nl_double a22, const nl_double rhs2)
|
||||
{
|
||||
/* GO, GT, I */
|
||||
m_P.set(-a12, a11, r1);
|
||||
m_N.set(-a21, a22, r2);
|
||||
m_P.set_go_gt_I(a12, a11, rhs1);
|
||||
m_N.set_go_gt_I(a21, a22, rhs2);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -420,7 +420,7 @@ public:
|
||||
NETLIB_TIMESTEPI()
|
||||
{
|
||||
m_t += step;
|
||||
this->set(1.0 / m_R(),
|
||||
this->set_G_V_I(1.0 / m_R(),
|
||||
m_compiled.evaluate(std::vector<double>({m_t})),
|
||||
0.0);
|
||||
}
|
||||
@ -431,7 +431,7 @@ protected:
|
||||
NETLIB_RESETI()
|
||||
{
|
||||
NETLIB_NAME(twoterm)::reset();
|
||||
this->set(1.0 / m_R(), m_V(), 0.0);
|
||||
this->set_G_V_I(1.0 / m_R(), m_V(), 0.0);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -69,7 +69,7 @@ namespace netlist
|
||||
{
|
||||
//m_V0.initial(0.0);
|
||||
//m_RV.do_reset();
|
||||
m_RV.set(plib::constants<nl_double>::one() / R_LOW, 0.0, 0.0);
|
||||
m_RV.set_G_V_I(plib::constants<nl_double>::one() / R_LOW, 0.0, 0.0);
|
||||
m_inc = netlist_time::from_double(1.0 / m_FREQ());
|
||||
if (m_FREQ() < 24000 || m_FREQ() > 56000)
|
||||
log().warning(MW_1_FREQUENCY_OUTSIDE_OF_SPECS_1, m_FREQ());
|
||||
@ -108,7 +108,7 @@ namespace netlist
|
||||
// We only need to update the net first if this is a time stepping net
|
||||
if (m_is_timestep)
|
||||
m_RV.update();
|
||||
m_RV.set(plib::constants<nl_double>::one() / R, V, plib::constants<nl_double>::zero());
|
||||
m_RV.set_G_V_I(plib::constants<nl_double>::one() / R, V, plib::constants<nl_double>::zero());
|
||||
m_RV.solve_later(NLTIME_FROM_NS(1));
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ namespace netlist
|
||||
double V = m_VIN() / static_cast<double>(1 << m_num())
|
||||
* static_cast<double>(m_val());
|
||||
|
||||
this->set(1.0 / m_R(), V, 0.0);
|
||||
this->set_G_V_I(1.0 / m_R(), V, 0.0);
|
||||
}
|
||||
} //namespace analog
|
||||
|
||||
|
@ -85,8 +85,8 @@ namespace netlist
|
||||
m_RVI.reset();
|
||||
m_RVO.reset();
|
||||
m_is_timestep = m_RVO.m_P.net().solver()->has_timestep_devices();
|
||||
m_RVI.set(plib::constants<nl_double>::one() / m_model.m_RI, m_model.m_VI, 0.0);
|
||||
m_RVO.set(plib::constants<nl_double>::one() / m_model.m_ROL, m_model.m_VOL, 0.0);
|
||||
m_RVI.set_G_V_I(plib::constants<nl_double>::one() / m_model.m_RI, m_model.m_VI, 0.0);
|
||||
m_RVO.set_G_V_I(plib::constants<nl_double>::one() / m_model.m_ROL, m_model.m_VOL, 0.0);
|
||||
}
|
||||
|
||||
NETLIB_UPDATEI()
|
||||
@ -98,7 +98,7 @@ namespace netlist
|
||||
m_last_state = 0;
|
||||
if (m_is_timestep)
|
||||
m_RVO.update();
|
||||
m_RVO.set(plib::constants<nl_double>::one() / m_model.m_ROH, m_model.m_VOH, 0.0);
|
||||
m_RVO.set_G_V_I(plib::constants<nl_double>::one() / m_model.m_ROH, m_model.m_VOH, 0.0);
|
||||
m_RVO.solve_later();
|
||||
}
|
||||
}
|
||||
@ -109,7 +109,7 @@ namespace netlist
|
||||
m_last_state = 1;
|
||||
if (m_is_timestep)
|
||||
m_RVO.update();
|
||||
m_RVO.set(plib::constants<nl_double>::one() / m_model.m_ROL, m_model.m_VOL, 0.0);
|
||||
m_RVO.set_G_V_I(plib::constants<nl_double>::one() / m_model.m_ROL, m_model.m_VOL, 0.0);
|
||||
m_RVO.solve_later();
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ namespace netlist
|
||||
m_last_state = -1;
|
||||
m_RV.reset();
|
||||
m_is_timestep = m_RV.m_P.net().solver()->has_timestep_devices();
|
||||
m_RV.set(plib::constants<nl_double>::one() / logic_family()->R_low(),
|
||||
m_RV.set_G_V_I(plib::constants<nl_double>::one() / logic_family()->R_low(),
|
||||
logic_family()->low_V(0.0, supply_V), 0.0);
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ namespace netlist
|
||||
{
|
||||
m_RV.update();
|
||||
}
|
||||
m_RV.set(plib::constants<nl_double>::one() / R, V, 0.0);
|
||||
m_RV.set_G_V_I(plib::constants<nl_double>::one() / R, V, 0.0);
|
||||
m_RV.solve_later();
|
||||
}
|
||||
}
|
||||
|
@ -280,8 +280,8 @@ namespace netlist
|
||||
|
||||
NETLIB_RESETI()
|
||||
{
|
||||
m_RIN.set(1.0 / m_p_RIN(),0,0);
|
||||
m_ROUT.set(1.0 / m_p_ROUT(),0,0);
|
||||
m_RIN.set_G_V_I(1.0 / m_p_RIN(),0,0);
|
||||
m_ROUT.set_G_V_I(1.0 / m_p_ROUT(),0,0);
|
||||
}
|
||||
|
||||
NETLIB_UPDATEI()
|
||||
|
@ -601,17 +601,17 @@ namespace netlist
|
||||
|
||||
nl_double operator ()() const NL_NOEXCEPT;
|
||||
|
||||
void set(const nl_double G) noexcept
|
||||
void set_conductivity(const nl_double G) noexcept
|
||||
{
|
||||
set(G,G, 0.0);
|
||||
set_go_gt_I(-G, G, 0.0);
|
||||
}
|
||||
|
||||
void set(const nl_double GO, const nl_double GT) noexcept
|
||||
void set_go_gt(const nl_double GO, const nl_double GT) noexcept
|
||||
{
|
||||
set(GO, GT, 0.0);
|
||||
set_go_gt_I(GO, GT, 0.0);
|
||||
}
|
||||
|
||||
void set(const nl_double GO, const nl_double GT, const nl_double I) noexcept
|
||||
void set_go_gt_I(const nl_double GO, const nl_double GT, const nl_double I) noexcept
|
||||
{
|
||||
if (m_go1 != nullptr)
|
||||
{
|
||||
|
@ -357,7 +357,7 @@ namespace devices
|
||||
state().save(*this, m_terms[k]->m_h_n_m_1, this->name(), "m_h_n_m_1." + num);
|
||||
|
||||
// FIXME: This shouldn't be necessary, recalculate on each entry ...
|
||||
state().save(*this, m_gon[k],"GO" + num, this->name(), m_terms[k]->count());
|
||||
state().save(*this, m_gonn[k],"GO" + num, this->name(), m_terms[k]->count());
|
||||
state().save(*this, m_gtn[k],"GT" + num, this->name(), m_terms[k]->count());
|
||||
state().save(*this, m_Idrn[k],"IDR" + num, this->name(), m_terms[k]->count());
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ namespace devices
|
||||
|
||||
m_mat_ptr.resize(iN, max_rail+1);
|
||||
m_gtn.resize(iN, max_count);
|
||||
m_gon.resize(iN, max_count);
|
||||
m_gonn.resize(iN, max_count);
|
||||
m_Idrn.resize(iN, max_count);
|
||||
m_connected_net_Vn.resize(iN, max_count);
|
||||
|
||||
@ -192,7 +192,7 @@ namespace devices
|
||||
|
||||
for (std::size_t i = 0; i < count; i++)
|
||||
{
|
||||
m_terms[k]->terms()[i]->set_ptrs(&m_gtn[k][i], &m_gon[k][i], &m_Idrn[k][i]);
|
||||
m_terms[k]->terms()[i]->set_ptrs(&m_gtn[k][i], &m_gonn[k][i], &m_Idrn[k][i]);
|
||||
m_connected_net_Vn[k][i] = m_terms[k]->terms()[i]->otherterm()->net().Q_Analog_state_ptr();
|
||||
}
|
||||
}
|
||||
@ -208,13 +208,13 @@ namespace devices
|
||||
|
||||
const std::size_t term_count = net->count();
|
||||
const std::size_t railstart = net->m_railstart;
|
||||
const auto &go = m_gon[k];
|
||||
const auto &go = m_gonn[k];
|
||||
const auto > = m_gtn[k];
|
||||
const auto &Idr = m_Idrn[k];
|
||||
const auto &cnV = m_connected_net_Vn[k];
|
||||
|
||||
for (std::size_t i = 0; i < railstart; i++)
|
||||
*tcr_r[i] -= go[i];
|
||||
*tcr_r[i] += go[i];
|
||||
|
||||
typename FT::value_type gtot_t = 0.0;
|
||||
typename FT::value_type RHS_t = 0.0;
|
||||
@ -232,7 +232,7 @@ namespace devices
|
||||
|
||||
for (std::size_t i = railstart; i < term_count; i++)
|
||||
{
|
||||
RHS_t += (/*m_Idr[i]*/ + go[i] * *cnV[i]);
|
||||
RHS_t += (/*m_Idr[i]*/ (- go[i]) * *cnV[i]);
|
||||
}
|
||||
|
||||
RHS[k] = RHS_t;
|
||||
@ -245,7 +245,7 @@ namespace devices
|
||||
template <typename T>
|
||||
using aligned_alloc = plib::aligned_allocator<T, PALIGN_VECTOROPT>;
|
||||
|
||||
plib::pmatrix2d<nl_double, aligned_alloc<nl_double>> m_gon;
|
||||
plib::pmatrix2d<nl_double, aligned_alloc<nl_double>> m_gonn;
|
||||
plib::pmatrix2d<nl_double, aligned_alloc<nl_double>> m_gtn;
|
||||
plib::pmatrix2d<nl_double, aligned_alloc<nl_double>> m_Idrn;
|
||||
plib::pmatrix2d<nl_double *, aligned_alloc<nl_double *>> m_mat_ptr;
|
||||
@ -335,11 +335,11 @@ namespace devices
|
||||
Ak[k] = akk;
|
||||
}
|
||||
|
||||
const float_type * const go = m_gon[k];
|
||||
const float_type * const go = m_gonn[k];
|
||||
int * net_other = terms->m_connected_net_idx.data();
|
||||
|
||||
for (std::size_t i = 0; i < railstart; i++)
|
||||
Ak[net_other[i]] -= go[i];
|
||||
Ak[net_other[i]] += go[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -356,7 +356,7 @@ namespace devices
|
||||
float_type rhsk_b = 0.0;
|
||||
|
||||
const std::size_t terms_count = m_terms[k]->count();
|
||||
const float_type * const go = m_gon[k];
|
||||
const float_type * const go = m_gonn[k];
|
||||
const float_type * const Idr = m_Idrn[k];
|
||||
const float_type * const * other_cur_analog = m_connected_net_Vn[k];
|
||||
|
||||
@ -365,7 +365,7 @@ namespace devices
|
||||
|
||||
for (std::size_t i = m_terms[k]->m_railstart; i < terms_count; i++)
|
||||
//rhsk = rhsk + go[i] * terms[i]->m_otherterm->net().as_analog().Q_Analog();
|
||||
rhsk_b = rhsk_b + go[i] * *other_cur_analog[i];
|
||||
rhsk_b = rhsk_b - go[i] * *other_cur_analog[i];
|
||||
|
||||
child.RHS(k) = rhsk_a + rhsk_b;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ unsigned matrix_solver_SOR_t<FT, SIZE>::vsolve_non_dynamic(const bool newton_rap
|
||||
|
||||
const std::size_t term_count = this->m_terms[k]->count();
|
||||
const float_type * const gt = this->m_gtn[k];
|
||||
const float_type * const go = this->m_gon[k];
|
||||
const float_type * const go = this->m_gonn[k];
|
||||
const float_type * const Idr = this->m_Idrn[k];
|
||||
auto other_cur_analog = this->m_connected_net_Vn[k];
|
||||
|
||||
@ -99,7 +99,7 @@ unsigned matrix_solver_SOR_t<FT, SIZE>::vsolve_non_dynamic(const bool newton_rap
|
||||
}
|
||||
|
||||
for (std::size_t i = this->m_terms[k]->m_railstart; i < term_count; i++)
|
||||
RHS_t = RHS_t + go[i] * *other_cur_analog[i];
|
||||
RHS_t = RHS_t - go[i] * *other_cur_analog[i];
|
||||
|
||||
RHS[k] = RHS_t;
|
||||
|
||||
@ -136,11 +136,11 @@ unsigned matrix_solver_SOR_t<FT, SIZE>::vsolve_non_dynamic(const bool newton_rap
|
||||
{
|
||||
const int * net_other = this->m_terms[k]->m_connected_net_idx.data();
|
||||
const std::size_t railstart = this->m_terms[k]->m_railstart;
|
||||
const float_type * go = this->m_gon[k];
|
||||
const float_type * go = this->m_gonn[k];
|
||||
|
||||
float_type Idrive = 0.0;
|
||||
for (std::size_t i = 0; i < railstart; i++)
|
||||
Idrive = Idrive + go[i] * this->m_new_V[static_cast<std::size_t>(net_other[i])];
|
||||
Idrive = Idrive - go[i] * this->m_new_V[static_cast<std::size_t>(net_other[i])];
|
||||
|
||||
const float_type new_val = this->m_new_V[k] * one_m_w[k] + (Idrive + RHS[k]) * w[k];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user