trunk/src/emu/netlist/analog/nld_solver.c
| r30708 | r30709 | |
| 78 | 78 | } |
| 79 | 79 | { |
| 80 | 80 | netlist_terminal_t *pterm = dynamic_cast<netlist_terminal_t *>(p); |
| 81 | | // for gauss seidel |
| 82 | | pterm->m_new_analog_ptr = &pterm->m_otherterm->net().as_analog().m_new_Analog; |
| 83 | | #if 0 |
| 84 | | if (pterm->m_otherterm->net().isRailNet()) |
| 85 | | m_nets[k].m_rails.add(pterm); |
| 86 | | else |
| 87 | | m_nets[k].m_terms.add(pterm); |
| 88 | | #endif |
| 89 | 81 | add_term(k, pterm); |
| 90 | 82 | } |
| 91 | 83 | NL_VERBOSE_OUT(("Added terminal\n")); |
| r30708 | r30709 | |
| 336 | 328 | if (term->m_otherterm->net().isRailNet()) |
| 337 | 329 | { |
| 338 | 330 | //m_nets[k].m_rails.add(pterm); |
| 339 | | m_rails[k].add(terms_t(term, -1)); |
| 331 | m_rails[k].add(term, -1); |
| 340 | 332 | } |
| 341 | 333 | else |
| 342 | 334 | { |
| 343 | 335 | int ot = get_net_idx(&term->m_otherterm->net()); |
| 344 | 336 | if (ot>=0) |
| 345 | 337 | { |
| 346 | | m_terms[k].add(terms_t(term, ot)); |
| 338 | m_terms[k].add(term, ot); |
| 347 | 339 | SOLVER_VERBOSE_OUT(("Net %d Term %s %f %f\n", k, terms[i]->name().cstr(), terms[i]->m_gt, terms[i]->m_go)); |
| 348 | 340 | } |
| 349 | 341 | /* Should this be allowed ? */ |
| 350 | 342 | else // if (ot<0) |
| 351 | 343 | { |
| 352 | | m_rails[k].add(terms_t(term, ot)); |
| 344 | m_rails[k].add(term, ot); |
| 353 | 345 | netlist().error("found term with missing othernet %s\n", term->name().cstr()); |
| 354 | 346 | } |
| 355 | 347 | } |
| r30708 | r30709 | |
| 424 | 416 | double rhsk = 0.0; |
| 425 | 417 | double akk = 0.0; |
| 426 | 418 | const int terms_count = m_terms[k].count(); |
| 427 | | const terms_t *terms = m_terms[k]; |
| 419 | const netlist_terminal_t * const *terms = m_terms[k].terms(); |
| 420 | const int *net_other = m_terms[k].net_other(); |
| 428 | 421 | |
| 429 | 422 | for (int i = 0; i < terms_count; i++) |
| 430 | 423 | { |
| 431 | 424 | //printf("A %d %d %s %f %f\n",t.net_this, t.net_other, t.term->name().cstr(), t.term->m_gt, t.term->m_go); |
| 432 | 425 | |
| 433 | | rhsk = rhsk + terms[i].m_term->m_Idr; |
| 434 | | akk = akk + terms[i].m_term->m_gt; |
| 435 | | m_A[k][terms[i].m_net_other] += -terms[i].m_term->m_go; |
| 426 | rhsk = rhsk + terms[i]->m_Idr; |
| 427 | akk = akk + terms[i]->m_gt; |
| 428 | m_A[k][net_other[i]] += -terms[i]->m_go; |
| 436 | 429 | } |
| 437 | 430 | |
| 438 | 431 | const int rails_count = m_rails[k].count(); |
| 439 | | const terms_t *rails = m_rails[k]; |
| 432 | const netlist_terminal_t * const *rails = m_rails[k].terms(); |
| 440 | 433 | |
| 441 | 434 | for (int i = 0; i < rails_count; i++) |
| 442 | 435 | { |
| 443 | | const terms_t t = rails[i]; |
| 444 | | |
| 445 | | rhsk = rhsk + t.m_term->m_Idr + t.m_term->m_go * t.m_term->m_otherterm->net().as_analog().Q_Analog(); |
| 446 | | akk = akk + t.m_term->m_gt; |
| 436 | rhsk = rhsk + rails[i]->m_Idr + rails[i]->m_go * rails[i]->m_otherterm->net().as_analog().Q_Analog(); |
| 437 | akk = akk + rails[i]->m_gt; |
| 447 | 438 | } |
| 448 | 439 | m_RHS[k] = rhsk; |
| 449 | 440 | m_A[k][k] += akk; |
| r30708 | r30709 | |
| 738 | 729 | double w[_storage_N]; |
| 739 | 730 | double one_m_w[_storage_N]; |
| 740 | 731 | double RHS[_storage_N]; |
| 732 | double new_V[_storage_N]; |
| 741 | 733 | |
| 742 | 734 | for (int k = 0; k < iN; k++) |
| 743 | 735 | { |
| 744 | | this->m_nets[k]->m_new_Analog = this->m_nets[k]->m_cur_Analog; |
| 736 | new_V[k] = this->m_nets[k]->m_new_Analog = this->m_nets[k]->m_cur_Analog; |
| 745 | 737 | } |
| 746 | 738 | |
| 747 | 739 | for (int k = 0; k < iN; k++) |
| r30708 | r30709 | |
| 750 | 742 | double gabs_t = 0.0; |
| 751 | 743 | double RHS_t = 0.0; |
| 752 | 744 | |
| 753 | | const typename netlist_matrix_solver_direct_t<m_N, _storage_N>::xlist_t &terms = this->m_terms[k]; |
| 754 | | const typename netlist_matrix_solver_direct_t<m_N, _storage_N>::xlist_t &rails = this->m_rails[k]; |
| 755 | | const int term_count = terms.count(); |
| 756 | | const int rail_count = rails.count(); |
| 745 | { |
| 746 | const netlist_terminal_t * const * rails = this->m_rails[k].terms(); |
| 747 | //const int * othernet = this->m_rails[k].m_othernet; |
| 748 | const int rail_count = this->m_rails[k].count(); |
| 757 | 749 | |
| 758 | | for (int i = 0; i < rail_count; i++) |
| 750 | for (int i = 0; i < rail_count; i++) |
| 751 | { |
| 752 | const netlist_terminal_t *rail = rails[i]; |
| 753 | gtot_t += rail->m_gt; |
| 754 | gabs_t += fabs(rail->m_go); |
| 755 | RHS_t += rail->m_Idr; |
| 756 | // this may point to a rail net ... |
| 757 | RHS_t += rail->m_go * rail->m_otherterm->net().as_analog().Q_Analog(); |
| 758 | } |
| 759 | } |
| 759 | 760 | { |
| 760 | | const netlist_terminal_t *rail = rails[i].m_term; |
| 761 | | gtot_t += rail->m_gt; |
| 762 | | gabs_t += fabs(rail->m_go); |
| 763 | | RHS_t += rail->m_Idr; |
| 764 | | RHS_t += rail->m_go * rail->m_otherterm->net().as_analog().Q_Analog(); |
| 765 | | } |
| 761 | const netlist_terminal_t * const * terms = this->m_terms[k].terms(); |
| 762 | const int term_count = this->m_terms[k].count(); |
| 766 | 763 | |
| 767 | | for (int i = 0; i < term_count; i++) |
| 768 | | { |
| 769 | | const netlist_terminal_t *term = terms[i].m_term; |
| 770 | | gtot_t += term->m_gt; |
| 771 | | gabs_t += fabs(term->m_go); |
| 772 | | RHS_t += term->m_Idr; |
| 764 | for (int i = 0; i < term_count; i++) |
| 765 | { |
| 766 | const netlist_terminal_t *term = terms[i]; |
| 767 | gtot_t += term->m_gt; |
| 768 | gabs_t += fabs(term->m_go); |
| 769 | RHS_t += term->m_Idr; |
| 770 | } |
| 773 | 771 | } |
| 774 | | |
| 775 | 772 | gabs_t *= 1.0; |
| 776 | 773 | if (gabs_t > gtot_t) |
| 777 | 774 | { |
| r30708 | r30709 | |
| 794 | 791 | |
| 795 | 792 | for (int k = 0; k < iN; k++) |
| 796 | 793 | { |
| 797 | | netlist_analog_net_t & RESTRICT net = *this->m_nets[k]; |
| 798 | | const typename netlist_matrix_solver_direct_t<m_N, _storage_N>::xlist_t &terms = this->m_terms[k]; |
| 799 | | const int term_count = terms.count(); |
| 794 | //netlist_analog_net_t & RESTRICT net = *this->m_nets[k]; |
| 795 | const netlist_terminal_t * const * terms = this->m_terms[k].terms(); |
| 796 | const int * net_other = this->m_terms[k].net_other(); |
| 797 | const int term_count = this->m_terms[k].count(); |
| 798 | |
| 800 | 799 | double Idrive = 0; |
| 801 | 800 | |
| 802 | 801 | for (int i = 0; i < term_count; i++) |
| 803 | | Idrive += terms[i].m_term->m_go * *(terms[i].m_term->m_new_analog_ptr); |
| 802 | Idrive += terms[i]->m_go * new_V[net_other[i]]; |
| 804 | 803 | |
| 805 | 804 | //double new_val = (net->m_cur_Analog * gabs[k] + iIdr) / (gtot[k]); |
| 806 | | const double new_val = net.m_new_Analog * one_m_w[k] + (Idrive + RHS[k]) * w[k]; |
| 805 | const double new_val = new_V[k] * one_m_w[k] + (Idrive + RHS[k]) * w[k]; |
| 807 | 806 | |
| 808 | | const double e = (new_val - net.m_new_Analog); |
| 809 | | cerr = (fabs(e) > cerr ? fabs(e) : cerr); |
| 807 | const double e = fabs(new_val - new_V[k]); |
| 808 | cerr = (e > cerr ? e : cerr); |
| 810 | 809 | |
| 811 | | net.m_new_Analog = new_val; |
| 810 | new_V[k] = new_val; |
| 812 | 811 | } |
| 813 | 812 | if (cerr > this->m_params.m_accuracy) |
| 814 | 813 | { |
| r30708 | r30709 | |
| 817 | 816 | resched_cnt++; |
| 818 | 817 | } while (resched && (resched_cnt < this->m_params.m_gs_loops)); |
| 819 | 818 | |
| 819 | for (int k = 0; k < iN; k++) |
| 820 | { |
| 821 | this->m_nets[k]->m_new_Analog = this->m_nets[k]->m_cur_Analog = new_V[k]; |
| 822 | } |
| 823 | |
| 824 | |
| 820 | 825 | this->m_gs_total += resched_cnt; |
| 821 | 826 | if (resched) |
| 822 | 827 | { |
| r30708 | r30709 | |
| 829 | 834 | else { |
| 830 | 835 | this->m_calculations++; |
| 831 | 836 | |
| 832 | | for (int k = 0; k < this->N(); k++) |
| 833 | | this->m_nets[k]->m_cur_Analog = this->m_nets[k]->m_new_Analog; |
| 837 | //for (int k = 0; k < this->N(); k++) |
| 838 | // this->m_nets[k]->m_cur_Analog = this->m_nets[k]->m_new_Analog; |
| 834 | 839 | |
| 835 | 840 | return resched_cnt; |
| 836 | 841 | } |
trunk/src/emu/netlist/analog/nld_solver.h
| r30708 | r30709 | |
| 70 | 70 | |
| 71 | 71 | protected: |
| 72 | 72 | |
| 73 | class ATTR_ALIGNED(64) terms_t{ |
| 74 | |
| 75 | public: |
| 76 | terms_t() {} |
| 77 | |
| 78 | void clear() |
| 79 | { |
| 80 | m_term.clear(); |
| 81 | m_net_other.clear(); |
| 82 | } |
| 83 | |
| 84 | void add(netlist_terminal_t *term, int net_other) |
| 85 | { |
| 86 | m_term.add(term); |
| 87 | m_net_other.add(net_other); |
| 88 | } |
| 89 | |
| 90 | inline int count() { return m_term.count(); } |
| 91 | |
| 92 | inline netlist_terminal_t **terms() { return m_term; } |
| 93 | inline int *net_other() { return m_net_other; } |
| 94 | |
| 95 | private: |
| 96 | plinearlist_t<netlist_terminal_t *> m_term; |
| 97 | plinearlist_t<int> m_net_other; |
| 98 | |
| 99 | }; |
| 100 | |
| 73 | 101 | ATTR_COLD void setup(netlist_analog_net_t::list_t &nets); |
| 74 | 102 | |
| 75 | 103 | // return true if a reschedule is needed ... |
| r30708 | r30709 | |
| 137 | 165 | ATTR_ALIGNED(64) double m_RHS[_storage_N]; |
| 138 | 166 | ATTR_ALIGNED(64) double m_last_RHS[_storage_N]; // right hand side - contains currents |
| 139 | 167 | |
| 140 | | struct ATTR_ALIGNED(64) terms_t{ |
| 141 | | |
| 142 | | terms_t(netlist_terminal_t *term, int net_other) |
| 143 | | : m_term(term), m_net_other(net_other) |
| 144 | | {} |
| 145 | | terms_t() |
| 146 | | : m_term(NULL), m_net_other(-1) |
| 147 | | {} |
| 148 | | |
| 149 | | ATTR_ALIGNED(64) netlist_terminal_t ATTR_ALIGNED(64) * RESTRICT m_term; |
| 150 | | int m_net_other; |
| 151 | | }; |
| 152 | | |
| 153 | | typedef plinearlist_t<terms_t> xlist_t; |
| 154 | | xlist_t m_terms[_storage_N]; |
| 155 | | xlist_t m_rails[_storage_N]; |
| 168 | terms_t m_terms[_storage_N]; |
| 169 | terms_t m_rails[_storage_N]; |
| 156 | 170 | plinearlist_t<double> xx[_storage_N]; |
| 157 | 171 | |
| 158 | 172 | private: |