Minor refactoring with focus on a bit more readability. (nw)

This commit is contained in:
couriersud 2017-01-07 03:36:46 +01:00
parent e788dc5dbe
commit 4dfd26b248
12 changed files with 94 additions and 77 deletions

View File

@ -165,9 +165,12 @@ NETLIB_UPDATE_TERMINALS(QBJT_EB)
const nl_double Ie = (sIe + gee * m_gD_BE.Vd() - gec * m_gD_BC.Vd()) * polarity;
const nl_double Ic = (sIc - gce * m_gD_BE.Vd() + gcc * m_gD_BC.Vd()) * polarity;
m_D_EB.set_mat(gee, gec - gee, gce - gee, gee - gec, Ie, -Ie);
m_D_CB.set_mat(gcc, gce - gcc, gec - gcc, gcc - gce, Ic, -Ic);
m_D_EC.set_mat( 0, -gec, -gce, 0, 0, 0);
m_D_EB.set_mat( gee, gec - gee, -Ie,
gce - gee, gee - gec, Ie);
m_D_CB.set_mat( gcc, gce - gcc, -Ic,
gec - gcc, gcc - gce, Ic);
m_D_EC.set_mat( 0, -gec, 0,
-gce, 0, 0);
}

View File

@ -211,7 +211,9 @@ NETLIB_TIMESTEP(C)
/* Gpar should support convergence */
const nl_double G = m_C() / step + m_GParallel;
const nl_double I = -G * deltaV();
set(G, 0.0, I);
set_mat( G, -G, -I,
-G, G, I);
//set(G, 0.0, I);
}
// ----------------------------------------------------------------------------------------
@ -220,13 +222,16 @@ NETLIB_TIMESTEP(C)
NETLIB_RESET(L)
{
set(netlist().gmin(), 0.0, 5.0 / netlist().gmin());
m_GParallel = netlist().gmin();
m_I = 0.0;
m_G = m_GParallel;
set_mat( m_G, -m_G, -m_I,
-m_G, m_G, m_I);
//set(1.0/NETLIST_GMIN, 0.0, -5.0 * NETLIST_GMIN);
}
NETLIB_UPDATE_PARAM(L)
{
m_GParallel = netlist().gmin();
}
NETLIB_UPDATE(L)
@ -239,7 +244,9 @@ NETLIB_TIMESTEP(L)
/* Gpar should support convergence */
m_I += m_I + m_G * deltaV();
m_G = step / m_L() + m_GParallel;
set(m_G, 0.0, m_I);
set_mat( m_G, -m_G, -m_I,
-m_G, m_G, m_I);
//set(m_G, 0.0, m_I);
}
// ----------------------------------------------------------------------------------------
@ -271,7 +278,11 @@ NETLIB_UPDATE(D)
NETLIB_UPDATE_TERMINALS(D)
{
m_D.update_diode(deltaV());
set(m_D.G(), 0.0, m_D.Ieq());
const nl_double G = m_D.G();
const nl_double I = m_D.Ieq();
set_mat( G, -G, -I,
-G, G, I);
//set(m_D.G(), 0.0, m_D.Ieq());
}
// ----------------------------------------------------------------------------------------
@ -296,7 +307,11 @@ NETLIB_UPDATE(VS)
NETLIB_RESET(CS)
{
NETLIB_NAME(twoterm)::reset();
this->set(0.0, 0.0, m_I());
const nl_double I = m_I();
set_mat(0.0, 0.0, -I,
0.0, 0.0, I);
//this->set(0.0, 0.0, m_I());
}
NETLIB_UPDATE(CS)

View File

@ -137,13 +137,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 a21, const nl_double a22,
const nl_double r1, const nl_double r2)
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)
{
/* GO, GT, I */
m_P.set(-a12, a11, -r1);
m_N.set(-a21, a22, -r2);
m_P.set(-a12, a11, r1);
m_N.set(-a21, a22, r2);
}
private:
@ -169,7 +168,9 @@ NETLIB_OBJECT_DERIVED(R_base, twoterm)
public:
inline void set_R(const nl_double R)
{
set(NL_FCONST(1.0) / R, 0.0, 0.0);
const nl_double G = NL_FCONST(1.0) / R;
set_mat( G, -G, 0.0,
-G, G, 0.0);
}
protected:

View File

@ -138,7 +138,6 @@ const logic_family_desc_t *family_CD4XXX()
detail::queue_t::queue_t(netlist_t &nl)
: timed_queue<net_t *, netlist_time>(512)
, object_t("QUEUE")
, netlist_ref(nl)
, plib::state_manager_t::callback_t()
, m_qsize(0)

View File

@ -372,7 +372,7 @@ namespace netlist
/*! The base class for netlist devices, terminals and parameters.
*
* This class serves as the base class for all device, terminal and
* objects. It provides new and delete operators to supported e.g. pooled
* objects. It provides new and delete operators to support e.g. pooled
* memory allocation to enhance locality. Please refer to \ref USE_MEMPOOL as
* well.
*/
@ -1139,7 +1139,6 @@ namespace netlist
class detail::queue_t :
public timed_queue<net_t *, netlist_time>,
public detail::object_t,
public detail::netlist_ref,
public plib::state_manager_t::callback_t
{

View File

@ -17,7 +17,7 @@ proxied_analog_output_t::~proxied_analog_output_t()
{
}
terms_t::terms_t()
terms_for_net_t::terms_for_net_t()
: m_railstart(0)
, m_last_V(0.0)
, m_DD_n_m_1(0.0)
@ -25,46 +25,46 @@ terms_t::terms_t()
{
}
void terms_t::clear()
void terms_for_net_t::clear()
{
m_term.clear();
m_net_other.clear();
m_terms.clear();
m_connected_net_idx.clear();
m_gt.clear();
m_go.clear();
m_Idr.clear();
m_other_curanalog.clear();
m_connected_net_V.clear();
}
void terms_t::add(terminal_t *term, int net_other, bool sorted)
void terms_for_net_t::add(terminal_t *term, int net_other, bool sorted)
{
if (sorted)
for (unsigned i=0; i < m_net_other.size(); i++)
for (unsigned i=0; i < m_connected_net_idx.size(); i++)
{
if (m_net_other[i] > net_other)
if (m_connected_net_idx[i] > net_other)
{
plib::container::insert_at(m_term, i, term);
plib::container::insert_at(m_net_other, i, net_other);
plib::container::insert_at(m_terms, i, term);
plib::container::insert_at(m_connected_net_idx, i, net_other);
plib::container::insert_at(m_gt, i, 0.0);
plib::container::insert_at(m_go, i, 0.0);
plib::container::insert_at(m_Idr, i, 0.0);
plib::container::insert_at(m_other_curanalog, i, nullptr);
plib::container::insert_at(m_connected_net_V, i, nullptr);
return;
}
}
m_term.push_back(term);
m_net_other.push_back(net_other);
m_terms.push_back(term);
m_connected_net_idx.push_back(net_other);
m_gt.push_back(0.0);
m_go.push_back(0.0);
m_Idr.push_back(0.0);
m_other_curanalog.push_back(nullptr);
m_connected_net_V.push_back(nullptr);
}
void terms_t::set_pointers()
void terms_for_net_t::set_pointers()
{
for (unsigned i = 0; i < count(); i++)
{
m_term[i]->set_ptrs(&m_gt[i], &m_go[i], &m_Idr[i]);
m_other_curanalog[i] = m_term[i]->m_otherterm->net().m_cur_Analog.ptr();
m_terms[i]->set_ptrs(&m_gt[i], &m_go[i], &m_Idr[i]);
m_connected_net_V[i] = m_terms[i]->m_otherterm->net().m_cur_Analog.ptr();
}
}
@ -108,8 +108,8 @@ void matrix_solver_t::setup_base(analog_net_t::list_t &nets)
for (auto & net : nets)
{
m_nets.push_back(net);
m_terms.push_back(plib::palloc<terms_t>());
m_rails_temp.push_back(plib::palloc<terms_t>());
m_terms.push_back(plib::palloc<terms_for_net_t>());
m_rails_temp.push_back(plib::palloc<terms_for_net_t>());
}
for (std::size_t k = 0; k < nets.size(); k++)
@ -183,7 +183,7 @@ void matrix_solver_t::setup_matrix()
{
m_terms[k]->m_railstart = m_terms[k]->count();
for (std::size_t i = 0; i < m_rails_temp[k]->count(); i++)
this->m_terms[k]->add(m_rails_temp[k]->terms()[i], m_rails_temp[k]->net_other()[i], false);
this->m_terms[k]->add(m_rails_temp[k]->terms()[i], m_rails_temp[k]->connected_net_idx()[i], false);
m_rails_temp[k]->clear(); // no longer needed
m_terms[k]->set_pointers();
@ -230,7 +230,7 @@ void matrix_solver_t::setup_matrix()
for (unsigned k = 0; k < iN; k++)
{
int *other = m_terms[k]->net_other();
int *other = m_terms[k]->connected_net_idx();
for (unsigned i = 0; i < m_terms[k]->count(); i++)
if (other[i] != -1)
other[i] = get_net_idx(&m_terms[k]->terms()[i]->m_otherterm->net());
@ -240,9 +240,9 @@ void matrix_solver_t::setup_matrix()
/* create a list of non zero elements. */
for (unsigned k = 0; k < iN; k++)
{
terms_t * t = m_terms[k];
terms_for_net_t * t = m_terms[k];
/* pretty brutal */
int *other = t->net_other();
int *other = t->connected_net_idx();
t->m_nz.clear();
@ -262,9 +262,9 @@ void matrix_solver_t::setup_matrix()
*/
for (unsigned k = 0; k < iN; k++)
{
terms_t * t = m_terms[k];
terms_for_net_t * t = m_terms[k];
/* pretty brutal */
int *other = t->net_other();
int *other = t->connected_net_idx();
if (k==0)
t->m_nzrd.clear();
@ -497,7 +497,7 @@ netlist_time matrix_solver_t::compute_next_timestep(const double cur_ts)
for (std::size_t k = 0, iN=m_terms.size(); k < iN; k++)
{
analog_net_t *n = m_nets[k];
terms_t *t = m_terms[k];
terms_for_net_t *t = m_terms[k];
const nl_double DD_n = (n->Q_Analog() - t->m_last_V);
const nl_double hn = cur_ts;

View File

@ -36,25 +36,25 @@ namespace netlist
};
class terms_t
class terms_for_net_t
{
P_PREVENT_COPYING(terms_t)
P_PREVENT_COPYING(terms_for_net_t)
public:
terms_t();
terms_for_net_t();
void clear();
void add(terminal_t *term, int net_other, bool sorted);
inline std::size_t count() { return m_term.size(); }
inline std::size_t count() { return m_terms.size(); }
inline terminal_t **terms() { return m_term.data(); }
inline int *net_other() { return m_net_other.data(); }
inline terminal_t **terms() { return m_terms.data(); }
inline int *connected_net_idx() { return m_connected_net_idx.data(); }
inline nl_double *gt() { return m_gt.data(); }
inline nl_double *go() { return m_go.data(); }
inline nl_double *Idr() { return m_Idr.data(); }
inline nl_double **other_curanalog() { return m_other_curanalog.data(); }
inline nl_double **connected_net_V() { return m_connected_net_V.data(); }
void set_pointers();
@ -70,12 +70,12 @@ public:
nl_double m_h_n_m_1;
private:
std::vector<int> m_net_other;
std::vector<int> m_connected_net_idx;
std::vector<nl_double> m_go;
std::vector<nl_double> m_gt;
std::vector<nl_double> m_Idr;
std::vector<nl_double *> m_other_curanalog;
std::vector<terminal_t *> m_term;
std::vector<nl_double *> m_connected_net_V;
std::vector<terminal_t *> m_terms;
};
@ -163,11 +163,11 @@ protected:
template <typename T>
void build_LE_RHS();
std::vector<terms_t *> m_terms;
std::vector<terms_for_net_t *> m_terms;
std::vector<analog_net_t *> m_nets;
std::vector<std::unique_ptr<proxied_analog_output_t>> m_inps;
std::vector<terms_t *> m_rails_temp;
std::vector<terms_for_net_t *> m_rails_temp;
const solver_parameters_t &m_params;
@ -244,7 +244,7 @@ void matrix_solver_t::build_LE_A()
}
const nl_double * RESTRICT go = m_terms[k]->go();
const int * RESTRICT net_other = m_terms[k]->net_other();
const int * RESTRICT net_other = m_terms[k]->connected_net_idx();
for (std::size_t i = 0; i < railstart; i++)
child.A(k,net_other[i]) -= go[i];
@ -266,7 +266,7 @@ void matrix_solver_t::build_LE_RHS()
const std::size_t terms_count = m_terms[k]->count();
const nl_double * RESTRICT go = m_terms[k]->go();
const nl_double * RESTRICT Idr = m_terms[k]->Idr();
const nl_double * const * RESTRICT other_cur_analog = m_terms[k]->other_curanalog();
const nl_double * const * RESTRICT other_cur_analog = m_terms[k]->connected_net_V();
for (std::size_t i = 0; i < terms_count; i++)
rhsk_a = rhsk_a + Idr[i];

View File

@ -203,7 +203,7 @@ void matrix_solver_direct_t<m_N, storage_N>::vsetup(analog_net_t::list_t &nets)
/* add RHS element */
for (unsigned k = 0; k < N(); k++)
{
terms_t * t = m_terms[k];
terms_for_net_t * t = m_terms[k];
if (!plib::container::contains(t->m_nzrd, N()))
t->m_nzrd.push_back(N());

View File

@ -146,7 +146,7 @@ protected:
nl_double m_last_RHS[storage_N]; // right hand side - contains currents
nl_double m_last_V[storage_N];
terms_t *m_rails_temp;
terms_for_net_t *m_rails_temp;
private:
nl_ext_double m_A[storage_N][((storage_N + 7) / 8) * 8];
@ -248,7 +248,7 @@ void matrix_solver_direct_t<m_N, storage_N>::vsetup(analog_net_t::list_t &nets)
{
m_terms[k]->m_railstart = m_terms[k]->count();
for (unsigned i = 0; i < m_rails_temp[k].count(); i++)
this->m_terms[k]->add(m_rails_temp[k].terms()[i], m_rails_temp[k].net_other()[i], false);
this->m_terms[k]->add(m_rails_temp[k].terms()[i], m_rails_temp[k].connected_net_idx()[i], false);
m_rails_temp[k].clear(); // no longer needed
m_terms[k]->set_pointers();
@ -290,7 +290,7 @@ void matrix_solver_direct_t<m_N, storage_N>::vsetup(analog_net_t::list_t &nets)
for (unsigned k = 0; k < N(); k++)
{
int *other = m_terms[k]->net_other();
int *other = m_terms[k]->connected_net_idx();
for (unsigned i = 0; i < m_terms[k]->count(); i++)
if (other[i] != -1)
other[i] = get_net_idx(&m_terms[k]->terms()[i]->m_otherterm->net());
@ -304,9 +304,9 @@ void matrix_solver_direct_t<m_N, storage_N>::vsetup(analog_net_t::list_t &nets)
*/
for (unsigned k = 0; k < N(); k++)
{
terms_t * t = m_terms[k];
terms_for_net_t * t = m_terms[k];
/* pretty brutal */
int *other = t->net_other();
int *other = t->connected_net_idx();
t->m_nz.clear();
@ -384,7 +384,7 @@ void matrix_solver_direct_t<m_N, storage_N>::build_LE_A()
const unsigned railstart = m_terms[k]->m_railstart;
const nl_double * RESTRICT gt = m_terms[k]->gt();
const nl_double * RESTRICT go = m_terms[k]->go();
const int * RESTRICT net_other = m_terms[k]->net_other();
const int * RESTRICT net_other = m_terms[k]->connected_net_idx();
for (unsigned i = 0; i < terms_count; i++)
akk = akk + gt[i];
@ -408,7 +408,7 @@ void matrix_solver_direct_t<m_N, storage_N>::build_LE_RHS(nl_double * RESTRICT r
const int terms_count = m_terms[k]->count();
const nl_double * RESTRICT go = m_terms[k]->go();
const nl_double * RESTRICT Idr = m_terms[k]->Idr();
const nl_double * const * RESTRICT other_cur_analog = m_terms[k]->other_curanalog();
const nl_double * const * RESTRICT other_cur_analog = m_terms[k]->connected_net_V();
for (int i = 0; i < terms_count; i++)
rhsk_a = rhsk_a + Idr[i];
@ -607,7 +607,7 @@ matrix_solver_direct_t<m_N, storage_N>::matrix_solver_direct_t(const solver_para
, m_dim(size)
, m_lp_fact(0)
{
m_rails_temp = palloc_array(terms_t, N());
m_rails_temp = palloc_array(terms_for_net_t, N());
for (unsigned k = 0; k < N(); k++)
{
@ -621,11 +621,11 @@ matrix_solver_direct_t<m_N, storage_N>::matrix_solver_direct_t(const eSolverType
, m_dim(size)
, m_lp_fact(0)
{
m_rails_temp = palloc_array(terms_t, N());
m_rails_temp = palloc_array(terms_for_net_t, N());
for (unsigned k = 0; k < N(); k++)
{
m_terms[k] = palloc(terms_t);
m_terms[k] = palloc(terms_for_net_t);
m_last_RHS[k] = 0.0;
}
}

View File

@ -150,7 +150,7 @@ void matrix_solver_GCR_t<m_N, storage_N>::vsetup(analog_net_t::list_t &nets)
/* build pointers into the compressed row format matrix for each terminal */
for (unsigned j=0; j< this->m_terms[k]->m_railstart;j++)
{
int other = this->m_terms[k]->net_other()[j];
int other = this->m_terms[k]->connected_net_idx()[j];
for (unsigned i = mat.ia[k]; i < nz; i++)
if (other == static_cast<int>(mat.ja[i]))
{
@ -251,7 +251,7 @@ unsigned matrix_solver_GCR_t<m_N, storage_N>::vsolve_non_dynamic(const bool newt
for (unsigned k = 0; k < iN; k++)
{
terms_t *t = this->m_terms[k];
terms_for_net_t *t = this->m_terms[k];
nl_double gtot_t = 0.0;
nl_double RHS_t = 0.0;
@ -260,7 +260,7 @@ unsigned matrix_solver_GCR_t<m_N, storage_N>::vsolve_non_dynamic(const bool newt
const nl_double * const RESTRICT gt = t->gt();
const nl_double * const RESTRICT go = t->go();
const nl_double * const RESTRICT Idr = t->Idr();
const nl_double * const * RESTRICT other_cur_analog = t->other_curanalog();
const nl_double * const * RESTRICT other_cur_analog = t->connected_net_V();
#if (0 ||NL_USE_SSE)
__m128d mg = mm_set_pd(0.0, 0.0);

View File

@ -81,7 +81,7 @@ void matrix_solver_GMRES_t<m_N, storage_N>::vsetup(analog_net_t::list_t &nets)
for (unsigned k=0; k<iN; k++)
{
terms_t * RESTRICT row = this->m_terms[k];
terms_for_net_t * RESTRICT row = this->m_terms[k];
mat.ia[k] = nz;
for (unsigned j=0; j<row->m_nz.size(); j++)
@ -97,7 +97,7 @@ void matrix_solver_GMRES_t<m_N, storage_N>::vsetup(analog_net_t::list_t &nets)
for (unsigned j=0; j< this->m_terms[k]->m_railstart;j++)
{
for (unsigned i = mat.ia[k]; i<nz; i++)
if (this->m_terms[k]->net_other()[j] == static_cast<int>(mat.ja[i]))
if (this->m_terms[k]->connected_net_idx()[j] == static_cast<int>(mat.ja[i]))
{
m_term_cr[k].push_back(i);
break;
@ -140,7 +140,7 @@ unsigned matrix_solver_GMRES_t<m_N, storage_N>::vsolve_non_dynamic(const bool ne
const nl_double * const RESTRICT gt = this->m_terms[k]->gt();
const nl_double * const RESTRICT go = this->m_terms[k]->go();
const nl_double * const RESTRICT Idr = this->m_terms[k]->Idr();
const nl_double * const * RESTRICT other_cur_analog = this->m_terms[k]->other_curanalog();
const nl_double * const * RESTRICT other_cur_analog = this->m_terms[k]->connected_net_V();
new_V[k] = this->m_nets[k]->m_cur_Analog;

View File

@ -84,7 +84,7 @@ unsigned matrix_solver_SOR_t<m_N, storage_N>::vsolve_non_dynamic(const bool newt
const nl_double * const RESTRICT gt = this->m_terms[k]->gt();
const nl_double * const RESTRICT go = this->m_terms[k]->go();
const nl_double * const RESTRICT Idr = this->m_terms[k]->Idr();
const nl_double * const *other_cur_analog = this->m_terms[k]->other_curanalog();
const nl_double * const *other_cur_analog = this->m_terms[k]->connected_net_V();
new_V[k] = this->m_nets[k]->m_cur_Analog;
@ -137,7 +137,7 @@ unsigned matrix_solver_SOR_t<m_N, storage_N>::vsolve_non_dynamic(const bool newt
nl_double err = 0;
for (unsigned k = 0; k < iN; k++)
{
const int * RESTRICT net_other = this->m_terms[k]->net_other();
const int * RESTRICT net_other = this->m_terms[k]->connected_net_idx();
const std::size_t railstart = this->m_terms[k]->m_railstart;
const nl_double * RESTRICT go = this->m_terms[k]->go();