testing
[gnucap-felix.git] / src / e_aux.h
blob176b48be45d9312dca2cde22da0eec20fd546dc3
1 /*$Id: e_aux.h,v 1.1 2009-10-23 12:01:45 felix Exp $ -*- C++ -*-
2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 *------------------------------------------------------------------
22 * helper functions, etc., that sort of belong to circuit elements
24 //testing=script 2007.07.13
25 #ifndef E_AUX_H
26 #define E_AUX_H
27 #include "e_node.h"
28 #include "u_status.h"
29 /*--------------------------------------------------------------------------*/
30 template <class T>
31 T port_impedance(const node_t& n1, const node_t& n2,
32 BSMATRIX<T>& mat, const T& parallel)
34 T* zapit = new T[mat.size()+2];
36 for (unsigned ii = 0; ii < mat.size()+2; ++ii) {
37 zapit[ii] = 0.;
39 if (n1.m_() != 0) {
40 zapit[n1.m_()] = 1.;
41 }else{untested();
43 if (n2.m_() != 0) {untested();
44 zapit[n2.m_()] = -1.;
45 }else{
48 mat.fbsub(zapit);
49 T raw_z = zapit[n1.m_()] - zapit[n2.m_()];
50 delete [] zapit;
51 return (parallel != 0.)
52 ? 1. / ((1./raw_z)-parallel)
53 : raw_z;
55 /*--------------------------------------------------------------------------*/
56 inline void set_sens_port(const node_t& n1, const node_t& n2)
58 std::fill_n(CKT_BASE::_sim->_sens, 1*CKT_BASE::_sim->_total_nodes+1, 0);
59 CKT_BASE::_sim->_sens[n1.m_()] = 1;
60 if(n2.m_()){
61 CKT_BASE::_sim->_sens[n2.m_()] = -1;
62 } else {
63 // weird, _sens[0] shouldnt do anything
66 /*--------------------------------------------------------------------------*/
67 inline COMPLEX port_noise(const node_t& n1, const node_t& n2){
68 set_sens_port(n1,n2);
69 ::status.back.start();
70 CKT_BASE::_sim->_acx.fbsubt(CKT_BASE::_sim->_sens);
71 ::status.back.stop();
72 double a = CARD_LIST::card_list.do_noise();
73 return a;
75 /*--------------------------------------------------------------------------*/
76 /*--------------------------------------------------------------------------*/
77 #endif
78 // vim:ts=8:sw=2:noet: