vcvs.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 "matrix.h"
00013 #include "vcvs.h"
00014 
00015 VCVS::VCVS( const double gain )
00016         : Element::Element()
00017 {
00018         m_g = gain;
00019         m_numCBranches = 1;
00020         m_numCNodes = 4;
00021 }
00022 
00023 
00024 VCVS::~VCVS()
00025 {
00026 }
00027 
00028 
00029 void VCVS::setGain( const double g )
00030 {
00031         if ( g == m_g )
00032                 return;
00033         
00034         if (p_eSet)
00035                 p_eSet->setCacheInvalidated();
00036         
00037         m_g = -m_g;
00038         add_initial_dc();
00039 
00040         m_g = g;
00041         add_initial_dc();
00042 }
00043 
00044 
00045 void VCVS::add_map()
00046 {
00047         if (!b_status)
00048                 return;
00049         
00050         if ( !p_cnode[0]->isGround )
00051         {
00052                 p_A->setUse_c( p_cbranch[0]->n(), p_cnode[0]->n(), Map::et_stable, false );
00053         }
00054         if ( !p_cnode[1]->isGround  )
00055         {
00056                 p_A->setUse_c( p_cbranch[0]->n(), p_cnode[1]->n(), Map::et_stable, false );
00057         }
00058         if ( !p_cnode[2]->isGround  )
00059         {
00060                 p_A->setUse_b( p_cnode[2]->n(), p_cbranch[0]->n(), Map::et_constant, true );
00061                 p_A->setUse_c( p_cbranch[0]->n(), p_cnode[2]->n(), Map::et_constant, true );
00062         }
00063         if ( !p_cnode[3]->isGround  )
00064         {
00065                 p_A->setUse_b( p_cnode[3]->n(), p_cbranch[0]->n(), Map::et_constant, true );
00066                 p_A->setUse_c( p_cbranch[0]->n(), p_cnode[3]->n(), Map::et_constant, true );
00067         }
00068 }
00069 
00070 
00071 void VCVS::add_initial_dc()
00072 {
00073         if (!b_status)
00074                 return;
00075         
00076         A_c( 0, 0 ) -= m_g;
00077         A_c( 0, 1 ) += m_g;
00078         A_b( 2, 0 ) = 1;
00079         A_c( 0, 2 ) = 1;
00080         A_b( 3, 0 ) = -1;
00081         A_c( 0, 3 ) = -1;
00082 }
00083 
00084 
00085 void VCVS::updateCurrents()
00086 {
00087         if (!b_status) return;
00088         m_cnodeI[0] = m_cnodeI[1] = 0.;
00089         m_cnodeI[3] = p_cbranch[0]->i;
00090         m_cnodeI[2] = -m_cnodeI[3];
00091 }
00092 
00093 

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