def main(): simulation = Cadet(common.common.root) simulation.filename = "f:/temp/LWE.h5" createSimulation(simulation) simulation.save() simulation.run() simulation.load() #read sensitivity data #sensitivity of protein 1 to nu 1 #s1 = simulation.root.output.sensitivity.param_000.unit_001.sens_column_outlet_comp_001 #sensitivity of protein 2 to nu 1 #s2 = simulation.root.output.sensitivity.param_000.unit_001.sens_column_outlet_comp_002 #sensitivity of protein 1 to nu 2 #s3 = simulation.root.output.sensitivity.param_001.unit_001.sens_column_outlet_comp_001 #sensitivity of protein 1 to sigma 1 #s4 = simulation.root.output.sensitivity.param_002.unit_001.sens_column_outlet_comp_001 #sensitivity of protein 1 to lambda #s5 = simulation.root.output.sensitivity.param_003.unit_001.sens_column_outlet_comp_001 #Sensitvity of first species to loads of all species (except salt) #s6 = simulation.root.output.sensitivity.param_004.unit_001.sens_column_outlet_comp_001 #Sensitvity of first species to velocity #s7 = simulation.root.output.sensitivity.param_005.unit_001.sens_column_outlet_comp_001 plotSimulation(simulation)
def main(): simulation = Cadet(common.common.root) simulation.filename = "MSSMA.h5" createSimulation(simulation) simulation.save() simulation.run() simulation.load() plotSimulation(simulation)
def main(): smb = Cadet() smb.filename = 'F:/temp/SMB.h5' createSimulation(smb) print("Simulated Created") smb.save() smb.run() smb.load() print("Simulation Run") plotSimulation(smb)
def check_cadet(self): """Wrapper around a basic CADET example for testing functionality""" if platform.system() == 'Windows': lwe_path = self.install_path / "bin" / "createLWE.exe" else: lwe_path = self.install_path / "bin" / "createLWE" ret = subprocess.run( [lwe_path.as_posix()], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.temp_dir ) if ret.returncode != 0: if ret.stdout: print('Output', ret.stdout.decode('utf-8')) if ret.stderr: print('Errors', ret.stderr.decode('utf-8')) raise CADETProcessError( "Failure: Creation of test simulation ran into problems" ) lwe_hdf5_path = Path(self.temp_dir) / 'LWE.h5' sim = CadetAPI() sim.filename = lwe_hdf5_path.as_posix() data = sim.run() os.remove(sim.filename) if data.returncode == 0: print("Test simulation completed successfully") else: print(data) raise CADETProcessError( "Simulation failed" )
def main(): simulation = Cadet(common.common.root) simulation.filename = "MSSMA_2comp.h5" createSimulation(simulation) simulation.save() data = simulation.run() print(data) simulation.load() plotSimulation(simulation)
def main(): #sim = Cadet(common.root, column_setup.root, io.root, connectivity.root) #sim.filename = "F:/temp/test_file.h5" #createSimulation(sim) #sim.save() #sim.run() #sim.load() #plotSimulation(sim) sim = Cadet(common.root, cstr.root, io.root, connectivity.root) sim.root.input['return'].unit_001.write_solution_volume = 1 sim.root.input.model.connections.switch_000.connections = [ 0, 1, -1, -1, 1.5, 1, 2, -1, -1, 1.0 ] sim.filename = "F:/temp/test_file_cstr.h5" sim.save() sim.run() sim.load() plotSimulation(sim) plotVolume(sim) writer = pandas.ExcelWriter('F:/temp/test_file_cstr.xlsx') inputs = pandas.DataFrame.from_items([ ('Time', sim.root.output.solution.solution_times), ('Concentration', sim.root.output.solution.unit_002.solution_inlet_comp_000) ]) outputs = pandas.DataFrame.from_items([ ('Time', sim.root.output.solution.solution_times), ('Concentration', sim.root.output.solution.unit_002.solution_outlet_comp_000) ]) volumes = pandas.DataFrame.from_items([ ('Time', sim.root.output.solution.solution_times), ('Volume', numpy.squeeze(sim.root.output.solution.unit_001.solution_volume)) ]) inputs.to_excel(writer, 'Input', index=False) outputs.to_excel(writer, 'Output', index=False) volumes.to_excel(writer, 'Volume', index=False) writer.save()
def main(): sim = Cadet(common.root, dpfr.root, io.root, cstr.root, connectivity.root) sim.filename = r"F:\jurgen\Pilot_test.h5" #createSimulation(sim) sim.save() sim.run() sim.load() plotSimulation(sim) #sim = Cadet(common.root, cstr.root, io.root, connectivity.root) #sim.root.input['return'].unit_001.write_solution_volume = 1 #sim.root.input.model.connections.switch_000.connections = [0, 1, -1, -1, 1.5, # 1, 2, -1, -1, 1.0] #sim.filename = r"C:\Users\Kohl\Desktop\Cadet\test_file_cstr.h5" #sim.save() #sim.run() #sim.load() #plotSimulation(sim) #plotVolume(sim) writer = pandas.ExcelWriter(r'F:\jurgen\test_file_cstr.xlsx') inputs = pandas.DataFrame.from_items([ ('Time', sim.root.output.solution.solution_times), ('Concentration', sim.root.output.solution.unit_000.solution_inlet_comp_000) ]) outputs = pandas.DataFrame.from_items([ ('Time', sim.root.output.solution.solution_times), ('Concentration', sim.root.output.solution.unit_002.solution_outlet_comp_000) ]) #volumes = pandas.DataFrame.from_items([('Time', sim.root.output.solution.solution_times), ('Volume', numpy.squeeze(sim.root.output.solution.unit_001.solution_volume))]) inputs.to_excel(writer, 'Input', index=False) outputs.to_excel(writer, 'Output', index=False) #volumes.to_excel(writer, 'Volume', index=False) writer.save()
def run(self, process, file_path=None): """Interface to the solver run function The configuration is extracted from the process object and then saved as a temporary .h5 file. After termination, the same file is processed and the results are returned. Cadet Return information: - 0: pass (everything allright) - 1: Standard Error - 2: IO Error - 3: Solver Error Parameters ---------- process : Process process to be simulated Returns ------- results : SimulationResults Simulation results including process and solver configuration. Raises ------ TypeError If process is not instance of Process See also -------- get_process_config get_simulation_results """ if not isinstance(process, Process): raise TypeError('Expected Process') cadet = CadetAPI() cadet.root = self.get_process_config(process) if file_path is None: cadet.filename = self.get_tempfile_name() else: cadet.filename = file_path cadet.save() try: start = time.time() return_information = cadet.run(timeout=self.timeout) elapsed = time.time() - start except TimeoutExpired: raise CADETProcessError('Simulator timed out') if return_information.returncode != 0: self.logger.error( 'Simulation of {} with parameters {} failed.'.format( process.name, process.config ) ) raise CADETProcessError( 'CADET Error: {}'.format(return_information.stderr) ) try: cadet.load() results = self.get_simulation_results( process, cadet, elapsed, return_information ) except TypeError: raise CADETProcessError('Unexpected error reading SimulationResults.') # Remove files if file_path is None: os.remove(cadet.filename) return results
model.root.input['return'].unit_000.write_solution_bulk = 1 model.root.input['return'].unit_000.write_solution_inlet = 1 model.root.input['return'].unit_000.write_solution_outlet = 1 # Copy settings to the other unit operations model.root.input['return'].unit_001 = model.root.input['return'].unit_000 model.root.input['return'].unit_002 = model.root.input['return'].unit_000 # Solution times model.root.input.solver.user_solution_times = np.linspace(0, 1200, 1001) # Save and run simulation model.filename = 'model.h5' model.save() data = model.run() if data.returncode == 0: print("Simulation completed successfully") model.load() else: print(data) raise Exception("Simulation failed") # Plot restuls plt.figure() time = model.root.output.solution.solution_times c = model.root.output.solution.unit_001.solution_outlet plt.plot(time / 60, c) plt.xlabel('$time~/~min$')