File indexing completed on 2024-05-12 13:49:29
0001 /*************************************************************************** 0002 * Copyright (C) 2003-2004 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #include "currentsignal.h" 0012 #include "element.h" 0013 0014 CurrentSignal::CurrentSignal(double delta, double current) 0015 : Reactive::Reactive(delta) 0016 { 0017 m_current = current; 0018 m_oldCurrent = m_newCurrent = 0.0; 0019 m_numCNodes = 2; 0020 } 0021 0022 CurrentSignal::~CurrentSignal() 0023 { 0024 } 0025 0026 void CurrentSignal::setCurrent(double i) 0027 { 0028 // Instead of calling step again, we can just "adjust" what the current should be 0029 m_newCurrent *= i / m_current; 0030 m_current = i; 0031 addCurrents(); 0032 } 0033 0034 void CurrentSignal::add_initial_dc() 0035 { 0036 m_oldCurrent = 0.0; 0037 // time_step() will handle everything for us now :) 0038 } 0039 0040 void CurrentSignal::updateCurrents() 0041 { 0042 m_cnodeI[1] = m_newCurrent; 0043 m_cnodeI[0] = -m_newCurrent; 0044 } 0045 0046 void CurrentSignal::time_step() 0047 { 0048 m_newCurrent = m_current * advance(m_delta); 0049 addCurrents(); 0050 } 0051 0052 void CurrentSignal::addCurrents() 0053 { 0054 if (!b_status) 0055 return; 0056 0057 if (m_newCurrent == m_oldCurrent) 0058 return; 0059 0060 b_i(0) -= m_newCurrent - m_oldCurrent; 0061 b_i(1) += m_newCurrent - m_oldCurrent; 0062 0063 m_oldCurrent = m_newCurrent; 0064 }