00001
00002
00003
00004
00005
00006
00007
00008
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