def simulateDynamic(self): """ Perform a dynamic simulation. The results can be displayed with the graph(...) function and stored with the store function. The funcion getAttributes(...) returns the simulation result of a speciffic attribute. """ # Compute the initial values if necessary. if self.initialValues == None: self.initialize() # create the array of output time points. Note: no rounding is better self.time = linspace( 0.0, self.p_solutionParameters_simulationTime, self.p_solutionParameters_simulationTime / self.p_solutionParameters_reportingInterval + 1, ) # Create space for storing simulation results # dim 1: time; dim 2: the different variables # -> vector of variables (state and algebraic) lies horizontally self.resultArray = zeros((len(self.time), self.stateVectorLen + self.algVectorLen), "float64") self.resultArray[0, 0 : self.stateVectorLen] = self.initialValues # create integrator object and care for intitial values solver = ( odeInt(self.dynamic) .set_integrator("vode", nsteps=5000) # IGNORE:E1102 .set_initial_value(self.initialValues, self.time[0]) ) # compute the numerical solution i = 1 while solver.successful() and i < len(self.time): # do time step solver.integrate(self.time[i]) # save state vars (and time) self.time[i] = solver.t # in case solver does not hit end time self.resultArray[i, 0 : self.stateVectorLen] = solver.y # compute algebraic variables (again) self.resultArray[i, self.stateVectorLen :] = self.dynamic( # IGNORE:E1111 solver.t, solver.y, returnAlgVars=True ) i += 1 # generate run time error if not solver.successful(): print >> sys.stderr, "error: simulation was terminated" # return # run final function self.final()
def simulateDynamic(self): """ Perform a dynamic simulation. The results can be displayed with the graph(...) function. The funcion variable(...) returns the simulation result of a speciffic variable as a vector. """ #Compute the initial values if necessary. if not self.initialValues: self.initialize() #create the array of output time points. Note: no rounding is better self.time = linspace(0.0, self.p_solutionParameters_simulationTime, self.p_solutionParameters_simulationTime/ self.p_solutionParameters_reportingInterval + 1) #Create space for storing simulation results #dim 1: time; dim 2: the different variables #-> vector of variables (state and algebraic) lies horizontally self.resultArray = zeros((len(self.time), self.stateVectorLen + self.algVectorLen), 'float64') self.resultArray[0,0:self.stateVectorLen] = self.initialValues #create integrator object and care for intitial values solver = odeInt(self.dynamic).set_integrator('vode') \ .set_initial_value(self.initialValues, self.time[0]) #compute the numerical solution #TODO: deal with the state variables i=1 while solver.successful() and i < len(self.time): # y0 = self.resultArray[i-1] # tStart = self.time[i-1] # tEnd = self.time[i] #do time step solver.integrate(self.time[i]) #save state vars (and time) self.time[i] = solver.t #in case solver does not hit end time self.resultArray[i,0:self.stateVectorLen] = solver.y #compute algebraic variables (again) self.resultArray[i,self.stateVectorLen:] = \ self.dynamic(solver.t, solver.y, returnAlgVars=True) i += 1 #generate run time error if not solver.successful(): print 'error: simulation was terminated'