-
Notifications
You must be signed in to change notification settings - Fork 0
/
Switch.cpp
66 lines (54 loc) · 1.18 KB
/
Switch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Switch.cpp
// Hbridge
//
// Created by Amy Landau on 3/24/17.
// Copyright © 2017 Amy Landau. All rights reserved.
//
#include "Switch.hpp"
#include <cmath>
#include <iostream>
Switch::Switch(int nodei, int nodej){
this->nodei = nodei;
this->nodej = nodej;
}
void Switch::Init(){
this-> nodep = GetNextNode();
AddJacobian(nodei, nodep, 1.0);
AddJacobian(nodej, nodep, -1.0);
AddJacobian(nodep, nodei, 1.0);
AddJacobian(nodep, nodej, -1.0);
}
void Switch::Changestate(int newstate)
{
if( newstate != state)
{
switch(newstate)
{
case 0:
AddJacobian(nodep, nodep, Roff);
AddBEquivalent(nodep, GetVoltage());
case 1:
AddJacobian(nodep, nodep, Ron);
AddBEquivalent(nodep, -Ron*GetCurrent());
}
}
return;
}
void Switch::DC(){
Step(0, 0);
}
double Switch::GetVoltage(){
return GetStateDifference(nodei, nodej);
}
double Switch::GetCurrent(){
// look at diode:
switch(state)
{
case 0:
return GetVoltage() / Roff;
case 1:
return GetVoltage() / Ron;
}
return 0;
}