# To reproduce the data needed for clamping experiments in associated original paper, def VrampExp(simFign,simfile,Vinit, paraKeys,paras,outKeys): import opencor as oc import numpy as np # The prefix of the saved output file name: simFign # Load the simulation file simulation = oc.open_simulation(simfile) # The data object houses all the relevant information # and pointers to the OpenCOR internal data representations data = simulation.data() # Define the interval of interest for this simulation experiment start, duration,pointInterval = 0, 280, 0.1 data.set_starting_point(start) data.set_point_interval(pointInterval) data.set_ending_point(duration) # Data to save varName = np.array(['V']+outKeys) vars = np.reshape(varName, (1, len(varName))) # start to save rows=int((duration)/pointInterval+1) r = np.zeros((rows,len(varName))) for i, V in enumerate(Vinit): # Reset states and parameters simulation.reset(True) # Set constant parameter values data.states()['outputs/V'] = Vinit[i] for j, para in enumerate(paras): data.constants()[paraKeys[j]] = para simulation.run() # Access simulation results results = simulation.results() # Grab a specific algebraic variable results r[:,0]=results.states()['outputs/V'].values()[-rows:] for j, outKey in enumerate(outKeys): r[:,j+1] = results.algebraic()[outKey].values()[-rows:] # clear the results except the last run simulation.clear_results() # Save the simulation result of the last run filename='../simulatedData/sim%s.csv' % (simFign) np.savetxt(filename, vars, fmt='%s',delimiter=",") with open(filename, "ab") as f: np.savetxt(f, r, delimiter=",") f.close