mirror of
https://github.com/holub/mame
synced 2025-07-02 16:49:22 +03:00
Use c++11 features to use more templates.
This commit is contained in:
parent
0d1e57cc40
commit
fc31cd6289
@ -10,6 +10,8 @@
|
||||
|
||||
#include "solver/nld_solver.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
NETLIB_NAMESPACE_DEVICES_START()
|
||||
|
||||
class terms_t
|
||||
@ -120,6 +122,11 @@ protected:
|
||||
template <typename T>
|
||||
T delta(const T * RESTRICT V);
|
||||
|
||||
template <typename T>
|
||||
void build_LE_A(T & child);
|
||||
template <typename T>
|
||||
void build_LE_RHS(T & child);
|
||||
|
||||
pvector_t<terms_t *> m_terms;
|
||||
pvector_t<analog_net_t *> m_nets;
|
||||
pvector_t<analog_output_t *> m_inps;
|
||||
@ -174,6 +181,61 @@ void matrix_solver_t::store(const T * RESTRICT V)
|
||||
this->m_nets[i]->m_cur_Analog = V[i];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void matrix_solver_t::build_LE_A(T & child)
|
||||
{
|
||||
static_assert(std::is_base_of<matrix_solver_t, T>::value, "T must derive from matrix_solver_t");
|
||||
|
||||
const unsigned iN = child.N();
|
||||
for (unsigned k = 0; k < iN; k++)
|
||||
{
|
||||
for (unsigned i=0; i < iN; i++)
|
||||
child.A(k,i) = 0.0;
|
||||
|
||||
const unsigned terms_count = m_terms[k]->count();
|
||||
const unsigned railstart = m_terms[k]->m_railstart;
|
||||
const nl_double * RESTRICT gt = m_terms[k]->gt();
|
||||
|
||||
{
|
||||
nl_double akk = 0.0;
|
||||
for (unsigned i = 0; i < terms_count; i++)
|
||||
akk += gt[i];
|
||||
|
||||
child.A(k,k) = akk;
|
||||
}
|
||||
|
||||
const nl_double * RESTRICT go = m_terms[k]->go();
|
||||
const int * RESTRICT net_other = m_terms[k]->net_other();
|
||||
|
||||
for (unsigned i = 0; i < railstart; i++)
|
||||
child.A(k,net_other[i]) -= go[i];
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void matrix_solver_t::build_LE_RHS(T & child)
|
||||
{
|
||||
const unsigned iN = child.N();
|
||||
for (unsigned k = 0; k < iN; k++)
|
||||
{
|
||||
nl_double rhsk_a = 0.0;
|
||||
nl_double rhsk_b = 0.0;
|
||||
|
||||
const unsigned 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();
|
||||
|
||||
for (unsigned i = 0; i < terms_count; i++)
|
||||
rhsk_a = rhsk_a + Idr[i];
|
||||
|
||||
for (unsigned 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];
|
||||
|
||||
child.RHS(k) = rhsk_a + rhsk_b;
|
||||
}
|
||||
}
|
||||
|
||||
NETLIB_NAMESPACE_DEVICES_END()
|
||||
|
||||
|
@ -118,6 +118,7 @@ class matrix_solver_direct_t: public matrix_solver_t, public thr_intf
|
||||
class matrix_solver_direct_t: public matrix_solver_t
|
||||
#endif
|
||||
{
|
||||
friend class matrix_solver_t;
|
||||
public:
|
||||
|
||||
matrix_solver_direct_t(const solver_parameters_t *params, const int size);
|
||||
@ -134,8 +135,6 @@ protected:
|
||||
|
||||
inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; }
|
||||
|
||||
void build_LE_A();
|
||||
void build_LE_RHS();
|
||||
void LE_solve();
|
||||
|
||||
template <typename T>
|
||||
@ -360,59 +359,6 @@ ATTR_COLD void matrix_solver_direct_t<m_N, _storage_N>::vsetup(analog_net_t::lis
|
||||
}
|
||||
|
||||
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
void matrix_solver_direct_t<m_N, _storage_N>::build_LE_A()
|
||||
{
|
||||
const unsigned iN = N();
|
||||
for (unsigned k = 0; k < iN; k++)
|
||||
{
|
||||
for (unsigned i=0; i < iN; i++)
|
||||
A(k,i) = 0.0;
|
||||
|
||||
const unsigned terms_count = m_terms[k]->count();
|
||||
const unsigned railstart = m_terms[k]->m_railstart;
|
||||
const nl_double * RESTRICT gt = m_terms[k]->gt();
|
||||
|
||||
{
|
||||
nl_double akk = 0.0;
|
||||
for (unsigned i = 0; i < terms_count; i++)
|
||||
akk += gt[i];
|
||||
|
||||
A(k,k) = akk;
|
||||
}
|
||||
|
||||
const nl_double * RESTRICT go = m_terms[k]->go();
|
||||
const int * RESTRICT net_other = m_terms[k]->net_other();
|
||||
|
||||
for (unsigned i = 0; i < railstart; i++)
|
||||
A(k,net_other[i]) -= go[i];
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
void matrix_solver_direct_t<m_N, _storage_N>::build_LE_RHS()
|
||||
{
|
||||
const unsigned iN = N();
|
||||
for (unsigned k = 0; k < iN; k++)
|
||||
{
|
||||
nl_double rhsk_a = 0.0;
|
||||
nl_double rhsk_b = 0.0;
|
||||
|
||||
const unsigned 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();
|
||||
|
||||
for (unsigned i = 0; i < terms_count; i++)
|
||||
rhsk_a = rhsk_a + Idr[i];
|
||||
|
||||
for (unsigned 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];
|
||||
|
||||
RHS(k) = rhsk_a + rhsk_b;
|
||||
}
|
||||
}
|
||||
|
||||
#if TEST_PARALLEL
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
@ -622,8 +568,8 @@ int matrix_solver_direct_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
inline int matrix_solver_direct_t<m_N, _storage_N>::vsolve_non_dynamic(const bool newton_raphson)
|
||||
{
|
||||
this->build_LE_A();
|
||||
this->build_LE_RHS();
|
||||
this->build_LE_A(*this);
|
||||
this->build_LE_RHS(*this);
|
||||
|
||||
for (unsigned i=0, iN=N(); i < iN; i++)
|
||||
m_last_RHS[i] = RHS(i);
|
||||
|
@ -30,8 +30,8 @@ public:
|
||||
|
||||
inline int matrix_solver_direct1_t::vsolve_non_dynamic(ATTR_UNUSED const bool newton_raphson)
|
||||
{
|
||||
this->build_LE_A();
|
||||
this->build_LE_RHS();
|
||||
this->build_LE_A(*this);
|
||||
this->build_LE_RHS(*this);
|
||||
//NL_VERBOSE_OUT(("{1} {2}\n", new_val, m_RHS[0] / m_A[0][0]);
|
||||
|
||||
nl_double new_val[1] = { RHS(0) / A(0,0) };
|
||||
|
@ -30,8 +30,8 @@ public:
|
||||
|
||||
inline int matrix_solver_direct2_t::vsolve_non_dynamic(ATTR_UNUSED const bool newton_raphson)
|
||||
{
|
||||
build_LE_A();
|
||||
build_LE_RHS();
|
||||
build_LE_A(*this);
|
||||
build_LE_RHS(*this);
|
||||
|
||||
const nl_double a = A(0,0);
|
||||
const nl_double b = A(0,1);
|
||||
|
@ -48,6 +48,8 @@ NETLIB_NAMESPACE_DEVICES_START()
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
class matrix_solver_sm_t: public matrix_solver_t
|
||||
{
|
||||
friend class matrix_solver_t;
|
||||
|
||||
public:
|
||||
|
||||
matrix_solver_sm_t(const solver_parameters_t *params, const int size);
|
||||
@ -64,8 +66,6 @@ protected:
|
||||
|
||||
inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; }
|
||||
|
||||
void build_LE_A();
|
||||
void build_LE_RHS();
|
||||
void LE_invert();
|
||||
|
||||
template <typename T>
|
||||
@ -243,59 +243,6 @@ ATTR_COLD void matrix_solver_sm_t<m_N, _storage_N>::vsetup(analog_net_t::list_t
|
||||
}
|
||||
|
||||
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
void matrix_solver_sm_t<m_N, _storage_N>::build_LE_A()
|
||||
{
|
||||
const unsigned iN = N();
|
||||
for (unsigned k = 0; k < iN; k++)
|
||||
{
|
||||
for (unsigned i=0; i < iN; i++)
|
||||
A(k,i) = 0.0;
|
||||
|
||||
const unsigned terms_count = m_terms[k]->count();
|
||||
const unsigned railstart = m_terms[k]->m_railstart;
|
||||
const nl_double * RESTRICT gt = m_terms[k]->gt();
|
||||
|
||||
{
|
||||
nl_double akk = 0.0;
|
||||
for (unsigned i = 0; i < terms_count; i++)
|
||||
akk += gt[i];
|
||||
|
||||
A(k,k) = akk;
|
||||
}
|
||||
|
||||
const nl_double * RESTRICT go = m_terms[k]->go();
|
||||
const int * RESTRICT net_other = m_terms[k]->net_other();
|
||||
|
||||
for (unsigned i = 0; i < railstart; i++)
|
||||
A(k,net_other[i]) -= go[i];
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
void matrix_solver_sm_t<m_N, _storage_N>::build_LE_RHS()
|
||||
{
|
||||
const unsigned iN = N();
|
||||
for (unsigned k = 0; k < iN; k++)
|
||||
{
|
||||
nl_double rhsk_a = 0.0;
|
||||
nl_double rhsk_b = 0.0;
|
||||
|
||||
const unsigned 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();
|
||||
|
||||
for (unsigned i = 0; i < terms_count; i++)
|
||||
rhsk_a = rhsk_a + Idr[i];
|
||||
|
||||
for (unsigned 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];
|
||||
|
||||
RHS(k) = rhsk_a + rhsk_b;
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
void matrix_solver_sm_t<m_N, _storage_N>::LE_invert()
|
||||
@ -473,8 +420,8 @@ int matrix_solver_sm_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const boo
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
inline int matrix_solver_sm_t<m_N, _storage_N>::vsolve_non_dynamic(const bool newton_raphson)
|
||||
{
|
||||
this->build_LE_A();
|
||||
this->build_LE_RHS();
|
||||
this->build_LE_A(*this);
|
||||
this->build_LE_RHS(*this);
|
||||
|
||||
for (unsigned i=0, iN=N(); i < iN; i++)
|
||||
m_last_RHS[i] = RHS(i);
|
||||
|
@ -128,8 +128,8 @@ int matrix_solver_SOR_mat_t<m_N, _storage_N>::vsolve_non_dynamic(const bool newt
|
||||
|
||||
int resched_cnt = 0;
|
||||
|
||||
this->build_LE_A();
|
||||
this->build_LE_RHS();
|
||||
this->build_LE_A(*this);
|
||||
this->build_LE_RHS(*this);
|
||||
|
||||
#if 0
|
||||
static int ws_cnt = 0;
|
||||
|
@ -55,6 +55,7 @@ NETLIB_NAMESPACE_DEVICES_START()
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
class matrix_solver_w_t: public matrix_solver_t
|
||||
{
|
||||
friend class matrix_solver_t;
|
||||
public:
|
||||
|
||||
matrix_solver_w_t(const solver_parameters_t *params, const int size);
|
||||
@ -71,8 +72,6 @@ protected:
|
||||
|
||||
inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; }
|
||||
|
||||
void build_LE_A();
|
||||
void build_LE_RHS();
|
||||
void LE_invert();
|
||||
|
||||
template <typename T>
|
||||
@ -257,59 +256,6 @@ ATTR_COLD void matrix_solver_w_t<m_N, _storage_N>::vsetup(analog_net_t::list_t &
|
||||
}
|
||||
|
||||
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
void matrix_solver_w_t<m_N, _storage_N>::build_LE_A()
|
||||
{
|
||||
const unsigned iN = N();
|
||||
for (unsigned k = 0; k < iN; k++)
|
||||
{
|
||||
for (unsigned i=0; i < iN; i++)
|
||||
A(k,i) = 0.0;
|
||||
|
||||
const unsigned terms_count = m_terms[k]->count();
|
||||
const unsigned railstart = m_terms[k]->m_railstart;
|
||||
const nl_double * RESTRICT gt = m_terms[k]->gt();
|
||||
|
||||
{
|
||||
nl_double akk = 0.0;
|
||||
for (unsigned i = 0; i < terms_count; i++)
|
||||
akk += gt[i];
|
||||
|
||||
A(k,k) = akk;
|
||||
}
|
||||
|
||||
const nl_double * RESTRICT go = m_terms[k]->go();
|
||||
const int * RESTRICT net_other = m_terms[k]->net_other();
|
||||
|
||||
for (unsigned i = 0; i < railstart; i++)
|
||||
A(k,net_other[i]) -= go[i];
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
void matrix_solver_w_t<m_N, _storage_N>::build_LE_RHS()
|
||||
{
|
||||
const unsigned iN = N();
|
||||
for (unsigned k = 0; k < iN; k++)
|
||||
{
|
||||
nl_double rhsk_a = 0.0;
|
||||
nl_double rhsk_b = 0.0;
|
||||
|
||||
const unsigned 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();
|
||||
|
||||
for (unsigned i = 0; i < terms_count; i++)
|
||||
rhsk_a = rhsk_a + Idr[i];
|
||||
|
||||
for (unsigned 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];
|
||||
|
||||
RHS(k) = rhsk_a + rhsk_b;
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
void matrix_solver_w_t<m_N, _storage_N>::LE_invert()
|
||||
@ -536,8 +482,8 @@ int matrix_solver_w_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const bool
|
||||
template <unsigned m_N, unsigned _storage_N>
|
||||
inline int matrix_solver_w_t<m_N, _storage_N>::vsolve_non_dynamic(const bool newton_raphson)
|
||||
{
|
||||
this->build_LE_A();
|
||||
this->build_LE_RHS();
|
||||
this->build_LE_A(*this);
|
||||
this->build_LE_RHS(*this);
|
||||
|
||||
for (unsigned i=0, iN=N(); i < iN; i++)
|
||||
m_last_RHS[i] = RHS(i);
|
||||
|
Loading…
Reference in New Issue
Block a user