currentsignal.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 "currentsignal.h"
00012 #include "element.h"
00013 
00014 CurrentSignal::CurrentSignal( const double delta, const double current )
00015         : Reactive::Reactive(delta)
00016 {
00017         m_current = current;
00018         m_oldCurrent = m_newCurrent = 0.;
00019         m_numCNodes = 2;
00020 }
00021 
00022 CurrentSignal::~CurrentSignal()
00023 {
00024 }
00025 
00026 void CurrentSignal::setCurrent( const double i )
00027 {
00028         if ( m_oldCurrent != m_newCurrent ) add_initial_dc();
00029         m_newCurrent *= i/m_current; // Instead of calling step again, we can just "adjust" what the current should be
00030         m_current = i;
00031         add_initial_dc();
00032 }
00033 
00034 
00035 void CurrentSignal::add_map()
00036 {
00037         // We don't need a map for current signal :-)
00038 }
00039 
00040 
00041 void CurrentSignal::add_initial_dc()
00042 {
00043         if ( !b_status )
00044                 return;
00045         
00046         if ( m_newCurrent == m_oldCurrent )
00047                 return;
00048 
00049         b_i( 0 ) -= m_newCurrent-m_oldCurrent;
00050         b_i( 1 ) += m_newCurrent-m_oldCurrent;
00051         
00052         m_oldCurrent = m_newCurrent;
00053 }
00054 
00055 void CurrentSignal::updateCurrents()
00056 {
00057         m_cnodeI[1] = m_newCurrent;
00058         m_cnodeI[0] = -m_newCurrent;
00059 }
00060 
00061 void CurrentSignal::time_step()
00062 {
00063         add_initial_dc(); // Make sure our old and new are synced
00064         m_newCurrent = m_current*advance();
00065         add_initial_dc();
00066 }

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