|
|
@@ -104,12 +104,12 @@ class RKPreprocessor:
|
|
|
RK.addConnection("RK-K_%d" % (s+1), "RK-K_%d" % j, "k_%d" % (s+1))
|
|
|
|
|
|
# Initial Conditions
|
|
|
- RK.addBlock(NegatorBlock("neg"))
|
|
|
- RK.addBlock(AdderBlock("ICSum"))
|
|
|
- RK.addConnection("RKSum", "neg")
|
|
|
- RK.addConnection("neg", "ICSum")
|
|
|
- RK.addConnection("IC", "ICSum")
|
|
|
- RK.addConnection("ICSum", "delay", "IC")
|
|
|
+ # RK.addBlock(NegatorBlock("neg"))
|
|
|
+ # RK.addBlock(AdderBlock("ICSum"))
|
|
|
+ # RK.addConnection("RKSum", "neg")
|
|
|
+ # RK.addConnection("neg", "ICSum")
|
|
|
+ RK.addConnection("IC", "delay", "IC")
|
|
|
+ # RK.addConnection("ICSum", "delay", "IC")
|
|
|
|
|
|
# Loop
|
|
|
RK.addBlock(AdderBlock("YSum"))
|
|
|
@@ -148,14 +148,12 @@ class RKPreprocessor:
|
|
|
K.addConnection("k_%d" % j, "Mult_%d" % j)
|
|
|
K.addConnection("Mult_%d" % j, "KSum")
|
|
|
for y in fy:
|
|
|
- K.addInputPort(y)
|
|
|
K.addBlock(AdderBlock("YSum-%s" % y))
|
|
|
K.addConnection(y, "YSum-%s" % y)
|
|
|
K.addConnection("KSum", "YSum-%s" % y)
|
|
|
K.addConnection("YSum-%s" % y, f.getBlockName(), y)
|
|
|
else:
|
|
|
for y in fy:
|
|
|
- K.addInputPort(y)
|
|
|
K.addConnection(y, f.getBlockName(), y)
|
|
|
|
|
|
# Finishing Up
|
|
|
@@ -183,11 +181,13 @@ if __name__ == '__main__':
|
|
|
self.addBlock(AdderBlock("sum"))
|
|
|
self.addBlock(ConstantBlock("one", value=(1)))
|
|
|
self.addBlock(ConstantBlock("time", value=(DELTA_T)))
|
|
|
+ self.addBlock(SplitBlock("split"))
|
|
|
|
|
|
# Create the Connections
|
|
|
self.addConnection("IC", "int", output_port_name='OUT1', input_port_name='IC')
|
|
|
- self.addConnection("int", "mult", output_port_name='OUT1', input_port_name='IN1')
|
|
|
- self.addConnection("int", "mult", output_port_name='OUT1', input_port_name='IN2')
|
|
|
+ self.addConnection("int", "split")
|
|
|
+ self.addConnection("split", "mult", output_port_name='OUT1')
|
|
|
+ self.addConnection("split", "mult", output_port_name='OUT2')
|
|
|
self.addConnection("int", "y", output_port_name='OUT1')
|
|
|
self.addConnection("mult", "sum", output_port_name='OUT1', input_port_name='IN2')
|
|
|
self.addConnection("one", "sum", output_port_name='OUT1', input_port_name='IN1')
|
|
|
@@ -196,21 +196,21 @@ if __name__ == '__main__':
|
|
|
|
|
|
prep = RKPreprocessor(BT.Heun())
|
|
|
model = prep.preprocess(Test("Test"))
|
|
|
- draw(model.findBlock("RK.RK-K_2")[0], "test.dot")
|
|
|
+ draw(model.findBlock("RK")[0], "test.dot")
|
|
|
# model = Test("Test")
|
|
|
|
|
|
- # from CBD.simulator import Simulator
|
|
|
- # sim = Simulator(model)
|
|
|
- # sim.setDeltaT(0.1)
|
|
|
- # sim.run(1.4)
|
|
|
- #
|
|
|
- # s = model.getSignal("y")
|
|
|
- # L = len(s)
|
|
|
- #
|
|
|
- # print("+------------+------------+")
|
|
|
- # print("| TIME | VALUE |")
|
|
|
- # print("+------------+------------+")
|
|
|
- # for i in range(L):
|
|
|
- # t, v = s[i]
|
|
|
- # print(f"| {t:10.7f} | {v:10.7f} |")
|
|
|
- # print("+------------+------------+")
|
|
|
+ from CBD.simulator import Simulator
|
|
|
+ sim = Simulator(model)
|
|
|
+ sim.setDeltaT(0.1)
|
|
|
+ sim.run(1.4)
|
|
|
+
|
|
|
+ s = model.getSignal("y")
|
|
|
+ L = len(s)
|
|
|
+
|
|
|
+ print("+------------+------------+")
|
|
|
+ print("| TIME | VALUE |")
|
|
|
+ print("+------------+------------+")
|
|
|
+ for i in range(L):
|
|
|
+ t, v = s[i]
|
|
|
+ print(f"| {t:10.7f} | {v:10.7f} |")
|
|
|
+ print("+------------+------------+")
|