resistance.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003-2004 by David Saxton                               *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "elementset.h"
00012 #include "resistance.h"
00013 
00014 // #include <kdebug.h>
00015 
00016 Resistance::Resistance( const double resistance )
00017         : Element::Element()
00018 {
00019         m_g = resistance < 1e-9 ? 1e9 : 1./resistance;
00020         m_numCNodes = 2;
00021 //      kdDebug() << k_funcinfo << endl;
00022 }
00023 
00024 Resistance::~Resistance()
00025 {
00026 //      kdDebug() << k_funcinfo << endl;
00027 }
00028 
00029 void Resistance::setConductance( const double g )
00030 {
00031         if ( g == m_g ) return;
00032 
00033         if (p_eSet) p_eSet->setCacheInvalidated();
00034 
00035         // Remove old resistance
00036         m_g = -m_g;
00037         add_initial_dc();
00038 
00039         m_g = g;
00040         add_initial_dc();
00041 }
00042 
00043 void Resistance::setResistance( const double r )
00044 {
00045         setConductance( r < 1e-9 ? 1e9 : 1./r );
00046 }
00047 
00048 void Resistance::add_map()
00049 {
00050         if(!b_status) return;
00051          
00052         if( !p_cnode[0]->isGround ) {
00053                 p_A->setUse( p_cnode[0]->n(), p_cnode[0]->n(), Map::et_stable, false );
00054         }
00055         if ( !p_cnode[1]->isGround ) {
00056                 p_A->setUse( p_cnode[1]->n(), p_cnode[1]->n(), Map::et_stable, false );
00057         }
00058         
00059         if ( !p_cnode[0]->isGround && !p_cnode[1]->isGround )
00060         {
00061                 p_A->setUse( p_cnode[0]->n(), p_cnode[1]->n(), Map::et_stable, false );
00062                 p_A->setUse( p_cnode[1]->n(), p_cnode[0]->n(), Map::et_stable, false );
00063         }
00064 }
00065 
00066 void Resistance::add_initial_dc()
00067 {
00068         if (!b_status) return;
00069         
00070         A_g( 0, 0 ) += m_g;
00071         A_g( 1, 1 ) += m_g;
00072         A_g( 0, 1 ) -= m_g;
00073         A_g( 1, 0 ) -= m_g;
00074 }
00075 
00076 void Resistance::updateCurrents()
00077 {
00078         if (!b_status) return;
00079         const double v=p_cnode[0]->v-p_cnode[1]->v; 
00080         m_cnodeI[1] = v*m_g;
00081         m_cnodeI[0] = -m_cnodeI[1];
00082 }
00083 

Generated on Tue May 8 17:05:32 2007 for KTechLab by  doxygen 1.5.1