def initializeModel(self): self.compiler = SimulationCompiler(self.model) self.compiler.createModelGraph() self.compiler.plotDependencyGraph() self.compiler.generateSimulationSequence() self.compiler.printSimulationSequence() numRealStates = len(self.compiler.realStates) numStateSwitches = len(self.compiler.stateEventDefinitions) # Run initializing functions self.model.recursiveInitialize() # Initialize vector of continuous states self.y0 = np.zeros(numRealStates) self.updateStateVector(self.y0) print("Initial values: {}".format(self.y0)) # Create vector for storing state derivatives self.yDot = np.zeros(numRealStates) # Initialize state switch vector self.sw0 = np.zeros(numStateSwitches, dtype=np.bool) self.eventIndicators = np.ones(numStateSwitches) # Configure solver self.setUp()
class TransientSimulation(Explicit_Problem): def __init__(self, model): self.model = model def initializeModel(self): self.compiler = SimulationCompiler(self.model) self.compiler.createModelGraph() self.compiler.plotDependencyGraph() self.compiler.generateSimulationSequence() self.compiler.printSimulationSequence() numRealStates = len(self.compiler.realStates) numStateSwitches = len(self.compiler.stateEventDefinitions) # Run initializing functions self.model.recursiveInitialize() # Initialize vector of continuous states self.y0 = np.zeros(numRealStates) self.updateStateVector(self.y0) print ("Initial values: {}".format(self.y0)) # Create vector for storing state derivatives self.yDot = np.zeros(numRealStates) # Initialize state switch vector self.sw0 = np.zeros(numStateSwitches, dtype = np.bool) self.eventIndicators = np.ones(numStateSwitches) # Configure solver self.setUp() def run(self, tFinal, tPrint): """ Runs the transient simulation """ # Remember the final time self.tFinal = tFinal # Run simulation self.result = self.simSolver.simulate( tfinal = tFinal, ncp = math.floor(tFinal/tPrint) ) ######### # Methods required by Assimulo ######### def rhs(self, t, y, sw): """ Callback method for the Assimulo solver to compute derivatives """ try: self.computeDerivatives(t, y, self.yDot) except Exception, e: # Log the error if it happens in the compute() function print('Exception at time {}: {}'.format(t, e)) raise e return self.yDot
def initializeModel(self): self.compiler = SimulationCompiler(self.model) self.compiler.createModelGraph() self.compiler.plotDependencyGraph() self.compiler.generateSimulationSequence() self.compiler.printSimulationSequence() numRealStates = len(self.compiler.realStates) numStateSwitches = len(self.compiler.stateEventDefinitions) # Run initializing functions self.model.recursiveInitialize() # Initialize vector of continuous states self.y0 = np.zeros(numRealStates) self.updateStateVector(self.y0) print ("Initial values: {}".format(self.y0)) # Create vector for storing state derivatives self.yDot = np.zeros(numRealStates) # Initialize state switch vector self.sw0 = np.zeros(numStateSwitches, dtype = np.bool) self.eventIndicators = np.ones(numStateSwitches) # Configure solver self.setUp()
class TransientSimulation(Explicit_Problem): def __init__(self, model): self.model = model def initializeModel(self): self.compiler = SimulationCompiler(self.model) self.compiler.createModelGraph() self.compiler.plotDependencyGraph() self.compiler.generateSimulationSequence() self.compiler.printSimulationSequence() numRealStates = len(self.compiler.realStates) numStateSwitches = len(self.compiler.stateEventDefinitions) # Run initializing functions self.model.recursiveInitialize() # Initialize vector of continuous states self.y0 = np.zeros(numRealStates) self.updateStateVector(self.y0) print("Initial values: {}".format(self.y0)) # Create vector for storing state derivatives self.yDot = np.zeros(numRealStates) # Initialize state switch vector self.sw0 = np.zeros(numStateSwitches, dtype=np.bool) self.eventIndicators = np.ones(numStateSwitches) # Configure solver self.setUp() def run(self, tFinal, tPrint): """ Runs the transient simulation """ # Remember the final time self.tFinal = tFinal # Run simulation self.result = self.simSolver.simulate(tfinal=tFinal, ncp=math.floor(tFinal / tPrint)) ######### # Methods required by Assimulo ######### def rhs(self, t, y, sw): """ Callback method for the Assimulo solver to compute derivatives """ try: self.computeDerivatives(t, y, self.yDot) except Exception, e: # Log the error if it happens in the compute() function print('Exception at time {}: {}'.format(t, e)) raise e return self.yDot