voltagesource.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 "voltagesource.h"
00012 #include "elementset.h"
00013 
00014 VoltageSource::VoltageSource( const double voltage )
00015         : Element::Element()
00016 {
00017         m_v = voltage;
00018         m_numCBranches = 1;
00019         m_numCNodes = 2;
00020 }
00021 
00022 VoltageSource::~VoltageSource()
00023 {
00024 }
00025 
00026 void VoltageSource::setVoltage( const double v )
00027 {
00028         if ( m_v == v ) return;
00029         
00030         if (p_eSet)
00031                 p_eSet->setCacheInvalidated();
00032         
00033         m_v = v;
00034         add_initial_dc();
00035 }
00036 
00037 
00038 void VoltageSource::add_map()
00039 {
00040         if (!b_status) return;
00041         
00042         if ( !p_cnode[0]->isGround )
00043         {
00044                 p_A->setUse_b( p_cnode[0]->n(), p_cbranch[0]->n(), Map::et_constant, true );
00045                 p_A->setUse_c( p_cbranch[0]->n(), p_cnode[0]->n(), Map::et_constant, true );
00046         }
00047         
00048         if ( !p_cnode[1]->isGround )
00049         {
00050                 p_A->setUse_b( p_cnode[1]->n(), p_cbranch[0]->n(), Map::et_constant, true );
00051                 p_A->setUse_c( p_cbranch[0]->n(), p_cnode[1]->n(), Map::et_constant, true );
00052         }
00053 }
00054 
00055 
00056 void VoltageSource::add_initial_dc()
00057 {
00058         if (!b_status)
00059                 return;
00060         
00061         A_b( 0, 0 ) = -1;
00062         A_c( 0, 0 ) = -1;
00063         A_b( 1, 0 ) = 1;
00064         A_c( 0, 1 ) = 1;
00065         
00066         b_v( 0 ) = m_v;
00067 }
00068 
00069 void VoltageSource::updateCurrents()
00070 {
00071         if (!b_status) return;
00072         m_cnodeI[0] = p_cbranch[0]->i;
00073         m_cnodeI[1] = -m_cnodeI[0];
00074 }
00075 
00076 

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