def transform_inhawp_to_eigen(iomin, iomout, blockidin=0, blockidout=0): """Compute the transformation to the eigenbasis for a wavepacket. Save the result back to a file. :param iomin: An :py:class:`IOManager: instance providing the simulation data. :param iomout: An :py:class:`IOManager: instance for saving the transformed data. :param blockidin: The data block from which the values are read. Default is `0`. :param blockidout: The data block to which the values are written. Default is `0`. """ parameters = iomin.load_parameters() # Number of time steps we saved timesteps = iomin.load_inhomogwavepacket_timegrid(blockid=blockidin) nrtimesteps = timesteps.shape[0] # The potential used Potential = BlockFactory().create_potential(parameters) # Basis transformator BT = BasisTransformationHAWP(Potential) # Initialize a Hagedorn wavepacket with the data descr = iomin.load_inhomogwavepacket_description(blockid=blockidin) HAWP = BlockFactory().create_wavepacket(descr) iomout.add_inhomogwavepacket(descr, timeslots=nrtimesteps, blockid=blockidout) iomout.save_inhomogwavepacket_description(HAWP.get_description(), blockid=blockidout) BT.set_matrix_builder(HAWP.get_quadrature()) # Basis shapes BS_descr = iomin.load_inhomogwavepacket_basisshapes() BS = {} for ahash, descr in BS_descr.iteritems(): BS[ahash] = BlockFactory().create_basis_shape(descr) # Iterate over all timesteps for i, step in enumerate(timesteps): print(" Compute eigentransform at timestep # " + str(step)) # Retrieve simulation data params = iomin.load_inhomogwavepacket_parameters(timestep=step, blockid=blockidin) hashes, coeffs = iomin.load_inhomogwavepacket_coefficients(timestep=step, get_hashes=True, blockid=blockidin) # Configure the wavepacket HAWP.set_parameters(params) HAWP.set_basis_shape([ BS[int(ha)] for ha in hashes ]) HAWP.set_coefficients(coeffs) # Transform to the eigenbasis. BT.transform_to_eigen(HAWP) # Save the transformed packet # Pi iomout.save_inhomogwavepacket_parameters(HAWP.get_parameters(), timestep=step, blockid=blockidout) # Basis shapes (in case they changed!) for shape in HAWP.get_basis_shape(): iomout.save_inhomogwavepacket_basisshapes(shape, blockid=blockidout) # Coefficients iomout.save_inhomogwavepacket_coefficients(HAWP.get_coefficients(), HAWP.get_basis_shape(), timestep=step, blockid=blockidout)
def read_data_inhomogeneous(iom, blockid=0): r""" :param iom: An :py:class:`IOManager` instance providing the simulation data. :param blockid: The data block from which the values are read. """ parameters = iom.load_parameters() timegrid = iom.load_inhomogwavepacket_timegrid(blockid=blockid) time = timegrid * parameters["dt"] # The potential used Potential = BlockFactory().create_potential(parameters) # Basis transformator BT = BasisTransformationHAWP(Potential) # Basis shapes BS_descr = iom.load_wavepacket_basisshapes(blockid=blockid) BS = {} for ahash, descr in BS_descr.iteritems(): BS[ahash] = BlockFactory().create_basis_shape(descr) # Initialize a Hagedorn wavepacket with the data descr = iom.load_inhomogwavepacket_description(blockid=blockid) HAWP = BlockFactory().create_wavepacket(descr) BT.set_matrix_builder(HAWP.get_quadrature()) # Store the resulting coefficients here CI = [ [] for i in xrange(HAWP.get_number_components()) ] # Iterate over all timesteps, this is an *expensive* transformation for i, step in enumerate(timegrid): print(" Computing eigentransformation at timestep "+str(step)) # Retrieve simulation data params = iom.load_inhomogwavepacket_parameters(timestep=step, blockid=blockid) hashes, coeffs = iom.load_inhomogwavepacket_coefficients(timestep=step, get_hashes=True, blockid=blockid) # Configure the wavepacket HAWP.set_parameters(params) HAWP.set_basis_shapes([ BS[int(ha)] for ha in hashes ]) HAWP.set_coefficients(coeffs) # Transform to the eigenbasis. BT.transform_to_eigen(HAWP) for index, item in enumerate(HAWP.get_coefficients()): CI[index].append(item) CI = [ transpose(hstack(item)) for item in CI ] return time, CI
def read_data_inhomogeneous(iom, blockid=0): r""" :param iom: An :py:class:`IOManager` instance providing the simulation data. :param blockid: The data block from which the values are read. """ parameters = iom.load_parameters() timegrid = iom.load_inhomogwavepacket_timegrid(blockid=blockid) dt = parameters["dt"] if "dt" in parameters else 1.0 time = timegrid * dt # The potential used Potential = BlockFactory().create_potential(parameters) # Basis transformator BT = BasisTransformationHAWP(Potential) # Initialize a Hagedorn wavepacket with the data descr = iom.load_inhomogwavepacket_description(blockid=blockid) HAWP = BlockFactory().create_wavepacket(descr) BT.set_matrix_builder(HAWP.get_quadrature()) # Store the resulting coefficients here CI = [[] for i in range(HAWP.get_number_components())] # Iterate over all timesteps, this is an *expensive* transformation for i, step in enumerate(timegrid): print(" Computing eigentransformation at timestep {}".format(step)) # Retrieve simulation data HAWP = iom.load_inhomogwavepacket(timestep=step, blockid=blockid) # Transform to the eigenbasis. BT.transform_to_eigen(HAWP) for index, item in enumerate(HAWP.get_coefficients()): CI[index].append(item) CI = [transpose(hstack(item)) for item in CI] return time, CI
def transform_inhawp_to_eigen(iomin, iomout, blockidin=0, blockidout=0): """Compute the transformation to the eigenbasis for a wavepacket. Save the result back to a file. :param iomin: An :py:class:`IOManager: instance providing the simulation data. :param iomout: An :py:class:`IOManager: instance for saving the transformed data. :param blockidin: The data block from which the values are read. Default is `0`. :param blockidout: The data block to which the values are written. Default is `0`. """ parameters = iomin.load_parameters() KEY = ("q", "p", "Q", "P", "S", "adQ") # Number of time steps we saved timesteps = iomin.load_inhomogwavepacket_timegrid(blockid=blockidin) nrtimesteps = timesteps.shape[0] # The potential used Potential = BlockFactory().create_potential(parameters) # Basis transformator BT = BasisTransformationHAWP(Potential) # Initialize a Hagedorn wavepacket with the data descr = iomin.load_inhomogwavepacket_description(blockid=blockidin) HAWP = BlockFactory().create_wavepacket(descr) iomout.add_inhomogwavepacket(descr, timeslots=nrtimesteps, blockid=blockidout, key=KEY) iomout.save_inhomogwavepacket_description(HAWP.get_description(), blockid=blockidout) BT.set_matrix_builder(HAWP.get_innerproduct()) # Basis shapes BS_descr = iomin.load_inhomogwavepacket_basisshapes(blockid=blockidin) BS = {} for ahash, descr in BS_descr.items(): BS[ahash] = BlockFactory().create_basis_shape(descr) # Iterate over all timesteps for i, step in enumerate(timesteps): print(" Compute eigentransform at timestep %d" % step) # Retrieve simulation data params = iomin.load_inhomogwavepacket_parameters(timestep=step, blockid=blockidin, key=KEY) hashes, coeffs = iomin.load_inhomogwavepacket_coefficients(timestep=step, get_hashes=True, blockid=blockidin) # Configure the wavepacket HAWP.set_parameters(params, key=KEY) HAWP.set_basis_shapes([BS[int(ha)] for ha in hashes]) HAWP.set_coefficients(coeffs) # Transform to the eigenbasis. BT.transform_to_eigen(HAWP) # Save the transformed packet # Pi iomout.save_inhomogwavepacket_parameters(HAWP.get_parameters(key=KEY), timestep=step, blockid=blockidout, key=KEY) # Basis shapes (in case they changed!) for shape in HAWP.get_basis_shapes(): iomout.save_inhomogwavepacket_basisshapes(shape, blockid=blockidout) # Coefficients iomout.save_inhomogwavepacket_coefficients(HAWP.get_coefficients(), HAWP.get_basis_shapes(), timestep=step, blockid=blockidout)