def __init__(self, block_name): CBD.__init__(self, block_name, input_ports=[], output_ports=["OUT1"]) #blocks self.addBlock(NegatorBlock("Negator")) self.addBlock(DerivatorBlock("Derivator1")) self.addBlock(DerivatorBlock("Derivator2")) draw(DerivatorBlock("derivative"), "output/Derivator.dot") self.addBlock(ConstantBlock("V0", 1)) self.addBlock(ConstantBlock("Zero", 0)) self.addBlock(ConstantBlock("DeltaT", 0.001)) # Connections self.addConnection("Negator", "Derivator1") self.addConnection("V0", "Derivator1", input_port_name="IC") self.addConnection("DeltaT", "Derivator1", output_port_name="OUT1", input_port_name="delta_t") self.addConnection("Derivator1", "Derivator2") self.addConnection("Zero", "Derivator2", input_port_name="IC") self.addConnection("DeltaT", "Derivator2", output_port_name="OUT1", input_port_name="delta_t") self.addConnection("Derivator2", "Negator", output_port_name="OUT1") self.addConnection("Derivator2", "OUT1", output_port_name="OUT1")
def __init__(self, block_name): CBD.__init__(self, block_name, input_ports=[], output_ports=["OUT1"]) #blocks self.addBlock(NegatorBlock("Negator")) self.addBlock(IntegratorBlock("Integrator1")) self.addBlock(IntegratorBlock("Integrator2")) draw(IntegratorBlock("integral"), "output/Integrator.dot") self.addBlock(ConstantBlock("X0", 0)) self.addBlock(ConstantBlock("V0", 1)) self.addBlock(ConstantBlock("DeltaT", 0.001)) #connections self.addConnection("Negator", "Integrator1") self.addConnection("V0", "Integrator1", input_port_name="IC") self.addConnection("DeltaT", "Integrator1", output_port_name="OUT1", input_port_name="delta_t") self.addConnection("Integrator1", "Integrator2") self.addConnection("X0", "Integrator2", input_port_name="IC") self.addConnection("DeltaT", "Integrator2", output_port_name="OUT1", input_port_name="delta_t") self.addConnection("Integrator2", "Negator", output_port_name="OUT1") self.addConnection("Integrator2", "OUT1", output_port_name="OUT1")
def __init__(self, block_name): CBD.__init__(self, block_name, input_ports=[], output_ports=["OutMultipleFive"]) #Blocks counterBlock = Counter(block_name="counter") draw(counterBlock, "Counter.dot") self.addBlock(counterBlock) timesFiveBlock = TimesFive(block_name="timesFive") draw(timesFiveBlock, "TimesFive.dot") self.addBlock(timesFiveBlock) self.addConnection("counter", "timesFive", input_port_name="InNumber", output_port_name="OutCount") self.addConnection("timesFive", "OutMultipleFive", output_port_name="OutTimesFive")
block_name, input_ports=[], output_ports=["OutEven"]) self.addBlock(Counter(block_name="counter")) self.addBlock(Double(block_name="double")) self.addConnection("counter", "double", input_port_name="InNumber", output_port_name="OutCount") self.addConnection("double", "OutEven", output_port_name="OutDouble") cbd = EvenNumberGen("number_gen") draw(cbd, "number_gen.dot") draw(cbd.getBlockByName("counter"), "counter.dot") cbd.run(10) times = [] output = [] for timeValuePair in cbd.getSignal("OutEven"): times.append(timeValuePair.time) output.append(timeValuePair.value) #Plot # output_file("./number_gen.html", title="Even Numbers") p = figure(title="Even Numbers", x_axis_label='time', y_axis_label='N') p.circle(x=times, y=output, legend="Even numbers") show(p)
self.addBlock(ConstantBlock(block_name="two", value=2.0)) self.addBlock(ConstantBlock(block_name="three", value=3.0)) self.addBlock(ProductBlock(block_name="product")) self.addBlock(AdderBlock(block_name="adder")) self.addBlock(NegatorBlock(block_name="negator")) self.addConnection("two", "product") self.addConnection("three", "negator") self.addConnection("negator", "adder") self.addConnection("product", "adder") self.addConnection("adder", "product") # LOOP LatexWriter.latexWrite = True latexWriter.writeBeginDocument("equations.tex") latexWriter.writeTitle("Assignment 2 - Task 3 - CBD") latexWriter.writeNewSection("Equations") latexWriter.writeBeginArray() linearLoopCBD1 = LinearLoopCBD1("linearLoopCBD1") linearLoopCBD1.run(1) draw(linearLoopCBD1, "linearLoopCBD1.dot") # Uncomment this if you want to execute this CBD. # linearLoopCBD2 = LinearLoopCBD2("linearLoopCBD2") # linearLoopCBD2.run(1) # draw(linearLoopCBD2, "linearLoopCBD2.dot") latexWriter.writeEndArray() latexWriter.writeEndDocument()
self.addConnection("Product", "Integrator") self.addConnection("AdderDeltaT", "Integrator", output_port_name="OUT1", input_port_name="delta_t") self.addConnection("Zero", "Integrator", output_port_name="OUT1", input_port_name="IC") #output self.addConnection("Integrator", "OUT1", output_port_name="OUT1") cbd = CBDSimulation("CBDSimulation1") draw(cbd, "CBDSimulation1.dot") cbd.run(5) times = [] output = [] for timeValuePair in cbd.getSignal(): times.append(timeValuePair.time) output.append(timeValuePair.value) print output, times #Plot p = figure(title="CBD Simulation 1", x_axis_label='time', y_axis_label='N') p.circle(x=times, y=output) show(p)