Skip to content
Snippets Groups Projects
Commit 685d68c5 authored by Joglekar's avatar Joglekar
Browse files

Updated Solvers

parent 681da317
No related branches found
No related tags found
No related merge requests found
Showing
with 303 additions and 18 deletions
classdef CurrentSensor < RCComponent
properties
Vs
possource
curval
flout
end
methods
function b = CurrentSensor(p,n,flout)
b = b@RCComponent(p,n);
b.Vs = 0;
b.flout = flout;
b.hyout = 1;
b.curval = 0;
end
function [G,Bout] = ApplyMatrixStamp(b,P,dt)
ntot = P.GetSize();
b.possource = ntot+1;
P.G = [P.G,zeros(ntot,1)];
P.G = [P.G; zeros(1,ntot+1)];
P.b = [P.b; 0];
if (b.Pos > 0)
P.G(b.possource,b.Pos) = 1;
P.G(b.Pos, b.possource) = 1;
end
if (b.Neg > 0)
P.G(b.possource,b.Neg) = -1;
P.G(b.Neg,b.possource) = -1;
end
end
function Init(b,P,dt)
b.ApplyMatrixStamp(P,dt);
end
function Step(b,P,dt,t)
P.b(b.possource) = b.Vs;
end
function PostStep(b,vsol,dt)
b.curval = vsol(b.possource);
end
function flow = WriteFlowOut(b,flow)
flow(b.flout) = b.curval;
end
end
end
......@@ -15,17 +15,6 @@ classdef Diode < RCComponent
r.Vnew = 1;
end
function r = Diode(p,n)
r = r@RCComponent(p,n);
r.Ron = 1e-4;
r.Roff = 1e4;
r.linear = 0;
r.Gr = 1/r.Ron;
r.Vnew = 1;
end
function [Gout,Bout] = ApplyMatrixStamp(r,P,dt)
end
......
......@@ -4,7 +4,7 @@ classdef Division < Block
methods
function c = Division(in1,in2,out)
c = c@Block();
c.ninput = 2
c.ninput = 2;
c.noutput = 1;
c.inpos(1) = in1;
c.inpos(2) = in2;
......
classdef GreaterThan < Block
properties
tr
fa
end
methods
function c = GreaterThan(in1,in2,out,tr,fa)
c = c@Block();
c.ninput = 2;
c.inpos(1) = in1;
c.inpos(2) = in2;
c.noutput = 1;
c.outpos(1) = out;
c.tr = tr;
c.fa = fa;
end
function flag = Step(c,t,dt)
if c.u(1) > c.u(2)
c.y = c.tr;
else
c.y = c.fa;
end
flag = 1;
end
end
end
......@@ -32,11 +32,29 @@ classdef HybridSystem < handle
hy.sc.AddComponent(h);
end
function AddListComponents2Schema(hy,l)
p = size(l,2);
hy.sc.nmodels = size(hy.sc.ModelList,2);
for i=1:p
hy.sc.AddComponent(l{i});
end
end
function AddListComponents2Network(hy,l)
p = size(l,2);
hy.nw.nelements = size(hy.nw.NetList,2);
for i=1:p
hy.nw.AddComponent(l{i});
end
end
function Init(hy)
hy.nw.Initnl(hy.dt);
hy.sc.Init();
hy.vk = zeros(hy.nw.n,1);
totn = hy.nw.Plin.GetSize();
hy.vk = zeros(totn,1);
hy.t = hy.ti;
end
......@@ -46,7 +64,6 @@ classdef HybridSystem < handle
function flagend = Step(hy)
t = hy.t;
k=1;
vkold = hy.vk;
hy.nw.Plin.Resetb();
flagnl = 0;
for i=1:hy.nw.nelements
......@@ -61,6 +78,7 @@ classdef HybridSystem < handle
end
iter =1;
err = 1e5;
vkold = hy.vk;
if flagnl == 1
while iter<=hy.maxn && (err>=hy.toll)
hy.nw.Pnl = LinProb(hy.nw.Plin.GetSize());
......@@ -88,7 +106,7 @@ classdef HybridSystem < handle
for i=1:hy.nw.nelements
hy.nw.NetList{i}.PostStep(hy.vk,hy.dt);
if (hy.nw.NetList{i}.hyout > 0)
hy.nw.NetList{i}.WriteFlowOut(hy.sc.flows);
hy.sc.flows = hy.nw.NetList{i}.WriteFlowOut(hy.sc.flows);
end
end
......
classdef Hysterisis < Block
properties
th
hi
lo
status
end
methods
function c = Hysterisis(in,out,th,hi,lo)
c = c@Block();
c.ninput = 1;
c.inpos(1) = in;
c.noutput = 1;
c.outpos(1) = out;
c.th = th;
c.hi = hi;
c.lo = lo;
c.status = c.hi;
end
function flag = Step(c,t,dt)
if c.u > c.th
c.status = c.hi;
elseif c.u < -c.th
c.status = c.lo;
end
c.y = c.status;
flag = 1;
end
end
end
......@@ -12,7 +12,7 @@ classdef Integrator < Block
c.B = 1;
c.C = 1;
c.D = 0;
c.ninput = 1
c.ninput = 1;
c.noutput = 1;
c.inpos(1) = in;
c.outpos(1) = out;
......
<mxGraphModel dx="747" dy="724" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" background="#ffffff"><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="2" value="" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" parent="1" vertex="1"><mxGeometry x="160" y="190" width="30" height="30" as="geometry"/></mxCell><mxCell id="4" value="Controller" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"><mxGeometry x="250" y="175" width="120" height="60" as="geometry"/></mxCell><mxCell id="5" value="Gc(s)" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"><mxGeometry x="430" y="175" width="120" height="60" as="geometry"/></mxCell><mxCell id="6" value="Gp(s)" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"><mxGeometry x="620" y="175" width="120" height="60" as="geometry"/></mxCell><mxCell id="7" value="" style="endArrow=classic;html=1;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" parent="1" source="2" target="4" edge="1"><mxGeometry width="50" height="50" relative="1" as="geometry"><mxPoint x="160" y="310" as="sourcePoint"/><mxPoint x="210" y="260" as="targetPoint"/></mxGeometry></mxCell><mxCell id="8" value="" style="endArrow=classic;html=1;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" parent="1" source="4" target="5" edge="1"><mxGeometry width="50" height="50" relative="1" as="geometry"><mxPoint x="200" y="215" as="sourcePoint"/><mxPoint x="260" y="215" as="targetPoint"/></mxGeometry></mxCell><mxCell id="9" value="" style="endArrow=classic;html=1;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" parent="1" source="5" target="6" edge="1"><mxGeometry width="50" height="50" relative="1" as="geometry"><mxPoint x="210" y="225" as="sourcePoint"/><mxPoint x="270" y="225" as="targetPoint"/></mxGeometry></mxCell><mxCell id="10" value="" style="endArrow=classic;html=1;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" parent="1" edge="1"><mxGeometry width="50" height="50" relative="1" as="geometry"><mxPoint x="740" y="204" as="sourcePoint"/><mxPoint x="800" y="204" as="targetPoint"/><Array as="points"><mxPoint x="790" y="204"/></Array></mxGeometry></mxCell><mxCell id="11" value="Gd(s)" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"><mxGeometry x="430" y="290" width="120" height="60" as="geometry"/></mxCell><mxCell id="12" value="" style="endArrow=classic;html=1;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="1"><mxGeometry width="50" height="50" relative="1" as="geometry"><mxPoint x="100" y="204" as="sourcePoint"/><mxPoint x="160" y="204" as="targetPoint"/></mxGeometry></mxCell><mxCell id="13" value="" style="endArrow=classic;html=1;entryX=0.5;entryY=1;" edge="1" parent="1" target="2"><mxGeometry width="50" height="50" relative="1" as="geometry"><mxPoint x="175" y="320" as="sourcePoint"/><mxPoint x="270" y="225" as="targetPoint"/></mxGeometry></mxCell><mxCell id="14" value="" style="endArrow=none;html=1;entryX=0;entryY=0.5;" edge="1" parent="1" target="11"><mxGeometry width="50" height="50" relative="1" as="geometry"><mxPoint x="180" y="320" as="sourcePoint"/><mxPoint x="140" y="370" as="targetPoint"/></mxGeometry></mxCell><mxCell id="15" value="" style="endArrow=classic;html=1;entryX=1;entryY=0.5;" edge="1" parent="1" target="11"><mxGeometry width="50" height="50" relative="1" as="geometry"><mxPoint x="760" y="320" as="sourcePoint"/><mxPoint x="185" y="230" as="targetPoint"/></mxGeometry></mxCell><mxCell id="16" value="" style="endArrow=none;html=1;" edge="1" parent="1"><mxGeometry width="50" height="50" relative="1" as="geometry"><mxPoint x="760" y="210" as="sourcePoint"/><mxPoint x="760" y="320" as="targetPoint"/></mxGeometry></mxCell></root></mxGraphModel>
\ No newline at end of file
......@@ -6,7 +6,7 @@ classdef Saturation < Block
methods
function c = Saturation(in,out,min,max)
c = c@Block();
c.ninput = 1
c.ninput = 1;
c.noutput = 1;
c.inpos(1) = in;
c.outpos(1) = out;
......@@ -25,7 +25,7 @@ classdef Saturation < Block
flag = 1;
end
flag = ChangeParameters(c,value)
function flag = ChangeParameters(c,value)
c.min = value(1);
c.max = value(2);
flag = 1;
......
classdef SawTooth < Block
properties
hi
lo
f
Ts
end
methods
function c = SawTooth(out,hi,lo,f)
c = c@Block();
c.hi = hi;
c.lo = lo;
c.f = f;
c.Ts = 1/f;
c.noutput = 1;
c.outpos(1) = out;
end
function flag = Step(c,t,dt)
d = t/c.Ts-floor(t/c.Ts);
c.y = c.lo + d*(c.hi-c.lo);
flag = 1;
end
end
end
classdef Signal2Source < RCComponent
properties
Vs
possource
flin
end
methods
function b = Signal2Source(p,n,flin)
b = b@RCComponent(p,n);
b.Vs = 0;
b.flin = flin;
b.hyin = 1;
end
function [G,Bout] = ApplyMatrixStamp(b,P,dt)
ntot = P.GetSize();
b.possource = ntot+1;
P.G = [P.G,zeros(ntot,1)];
P.G = [P.G; zeros(1,ntot+1)];
P.b = [P.b; 0];
if (b.Pos > 0)
P.G(b.possource,b.Pos) = 1;
P.G(b.Pos, b.possource) = 1;
end
if (b.Neg > 0)
P.G(b.possource,b.Neg) = -1;
P.G(b.Neg,b.possource) = -1;
end
end
function Init(b,P,dt)
b.ApplyMatrixStamp(P,dt);
end
function Step(b,P,dt,t)
P.b(b.possource) = b.Vs;
end
function PostStep(b,vsol,dt)
end
function ReadFlowIn(r,flow)
r.Vs = flow(r.flin);
end
end
end
classdef SmallerThan < Block
properties
tr
fa
end
methods
function c = SmallerThan(in1,in2,out,tr,fa)
c = c@Block();
c.ninput = 2;
c.inpos(1) = in1;
c.inpos(2) = in2;
c.noutput = 1;
c.outpos(1) = out;
c.tr = tr;
c.fa = fa;
end
function flag = Step(c,t,dt)
if c.u(1) < c.u(2)
c.y = c.tr;
else
c.y = c.fa;
end
flag = 1;
end
end
end
classdef VoltageSensor < RCComponent
properties
volval
flout
end
methods
function b = VoltageSensor(p,n,flout)
b = b@RCComponent(p,n);
b.flout = flout;
b.hyout = 1;
b.volval = 0;
end
function PostStep(b,vsol,dt)
if b.Pos > 0
pos = vsol(b.Pos);
else
pos = 0;
end
if b.Neg > 0
neg = vsol(b.Neg);
else
neg = 0;
end
b.volval = pos-neg;
end
function flow = WriteFlowOut(b,flow)
flow(b.flout) = b.volval;
end
end
end
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 4
}
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="716px" height="176px" version="1.1"><defs/><g transform="translate(0.5,0.5)"><ellipse cx="82" cy="30" rx="15" ry="15" fill="#ffffff" stroke="#000000" pointer-events="none"/><rect x="157" y="0" width="120" height="60" fill="#ffffff" stroke="#000000" pointer-events="none"/><g transform="translate(190.5,23.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="52" height="12" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 53px; white-space: nowrap; word-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;">Controller</div></div></foreignObject><text x="26" y="12" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">Controller</text></switch></g><rect x="337" y="0" width="120" height="60" fill="#ffffff" stroke="#000000" pointer-events="none"/><g transform="translate(382.5,23.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="29" height="12" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 30px; white-space: nowrap; word-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;">Gc(s)</div></div></foreignObject><text x="15" y="12" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">Gc(s)</text></switch></g><rect x="527" y="0" width="120" height="60" fill="#ffffff" stroke="#000000" pointer-events="none"/><g transform="translate(571.5,23.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="30" height="12" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 31px; white-space: nowrap; word-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;">Gp(s)</div></div></foreignObject><text x="15" y="12" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">Gp(s)</text></switch></g><path d="M 97 30 L 150.63 30" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 155.88 30 L 148.88 33.5 L 150.63 30 L 148.88 26.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 277 30 L 330.63 30" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 335.88 30 L 328.88 33.5 L 330.63 30 L 328.88 26.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 457 30 L 520.63 30" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 525.88 30 L 518.88 33.5 L 520.63 30 L 518.88 26.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 647 29 L 687 29 Q 697 29 698.82 29 L 700.63 29" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 705.88 29 L 698.88 32.5 L 700.63 29 L 698.88 25.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><rect x="337" y="115" width="120" height="60" fill="#ffffff" stroke="#000000" pointer-events="none"/><g transform="translate(381.5,138.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="30" height="12" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 31px; white-space: nowrap; word-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;">Gd(s)</div></div></foreignObject><text x="15" y="12" fill="#000000" text-anchor="middle" font-size="12px" font-family="Helvetica">Gd(s)</text></switch></g><path d="M 7 29 L 60.63 29" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 65.88 29 L 58.88 32.5 L 60.63 29 L 58.88 25.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 82 145 L 82 51.37" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 82 46.12 L 85.5 53.12 L 82 51.37 L 78.5 53.12 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 87 145 L 337 145" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 667 145 L 463.37 145" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 458.12 145 L 465.12 141.5 L 463.37 145 L 465.12 148.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/><path d="M 667 35 L 667 145" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="none"/></g></svg>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment