def prepare_simulation(self): r""" Set up a Hagedorn propagator for the simulation loop. Set the potential and initial values according to the configuration. :raise ValueError: For invalid or missing input data. """ potential = PF().create_potential(self.parameters) N = potential.get_number_components() # Check for enough initial values if self.parameters["leading_component"] > N: raise ValueError("Leading component index out of range.") if len(self.parameters["parameters"]) < N: raise ValueError("Too few initial states given. Parameters are missing.") if len(self.parameters["coefficients"]) < N: raise ValueError("Too few initial states given. Coefficients are missing.") # Create a suitable wave packet packet = HagedornWavepacket(self.parameters) # See if we have a list of parameter tuples or just a single 5-tuple # This is for compatibility with the inhomogeneous case. try: # We have a list of parameter tuples, take the one given by the leading component len(self.parameters["parameters"][0]) parameters = self.parameters["parameters"][self.parameters["leading_component"]] except TypeError: # We have just a single 5-tuple of parameters, take it. parameters = self.parameters["parameters"] # Set the Hagedorn parameters packet.set_parameters(parameters) packet.set_quadrature(None) # Set the initial values for component, data in enumerate(self.parameters["coefficients"]): for index, value in data: packet.set_coefficient(component, index, value) # Project the initial values to the canonical basis packet.project_to_canonical(potential) # Finally create and initialize the propagator instace self.propagator = HagedornPropagator(potential, packet, self.parameters["leading_component"], self.parameters) # Which data do we want to save tm = self.parameters.get_timemanager() slots = tm.compute_number_saves() self.IOManager.add_grid(self.parameters, blockid="global") self.IOManager.add_wavepacket(self.parameters, timeslots=slots) # Write some initial values to disk nodes = self.parameters["f"] * sp.pi * sp.arange(-1, 1, 2.0 / self.parameters["ngn"], dtype=np.complexfloating) self.IOManager.save_grid(nodes, blockid="global") self.IOManager.save_wavepacket_parameters(self.propagator.get_wavepackets().get_parameters(), timestep=0) self.IOManager.save_wavepacket_coefficients(self.propagator.get_wavepackets().get_coefficients(), timestep=0)
def spawn(self, info): r""" Really spawn the new wavepackets :math:`\tilde{\Psi}`. This method appends the new :py:class:`HagedornWavepacket` instances to the list :py:attr:`packets` of packets. """ WP = info # Initialize an empty wavepacket for spawning SWP = HagedornWavepacket(self.parameters) SWP.set_quadrature(None) # Initialize a Spawner AS = AdiabaticSpawner(self.parameters) # Estimate the parameter set Pi Pi = AS.estimate_parameters(WP, component=0) # Spawn a new packet if Pi is not None: SWP.set_parameters(Pi) # Project the coefficients from mother to child AS.project_coefficients(WP, SWP) print(" Spawned a new wavepacket with ID "+str(SWP.get_id())+".") # Append the spawned packet to the world self.packets.append((SWP,0))
def spawn(self, info): r""" Really spawn the new wavepackets :math:`\tilde{\Psi}`. This method appends the new :py:class:`HagedornWavepacket` instances to the list :py:attr:`packets` of packets. """ # Transform the packet to the eigenbasis where spawning has to happen WP, component = info WP.project_to_eigen(self.potential) # Prepare the potential (this functions are idempotent) self.potential.calculate_local_quadratic(diagonal_component=component) self.potential.calculate_local_remainder(diagonal_component=component) # Initialize an empty wavepacket for spawning SWP = HagedornWavepacket(self.parameters) SWP.set_quadrature(None) # Initialize a Spawner NAS = NonAdiabaticSpawner(self.parameters) # Estimate the parameter set Pi Pi = NAS.estimate_parameters(WP, component=component) # Spawn a new packet if Pi is not None: SWP.set_parameters(Pi) # Project the coefficients from mother to child NAS.project_coefficients(WP, SWP, component=component) # Transform both packets back to the canonical basis where propagation happens WP.project_to_canonical(self.potential) SWP.project_to_canonical(self.potential) print(" Spawned a new wavepacket with ID "+str(SWP.get_id())+".") # Append the spawned packet to the world self.packets.append((SWP,component))
def create_wavepacket(self, description): wp_type = description["type"] if wp_type == "HagedornWavepacket": from HagedornWavepacket import HagedornWavepacket # Initialize a packet WP = HagedornWavepacket(description["dimension"], description["ncomponents"], description["eps"]) # Set parameters if description.has_key("Pi"): Pi = description["Pi"] WP.set_parameters(Pi) # Configure basis shapes if description.has_key("basis_shapes"): for component, shapedescr in enumerate(description["basis_shapes"]): BS = self.create_basis_shape(shapedescr) WP.set_basis_shapes(BS, component=component) # Set coefficients if description.has_key("coefficients"): for component, data in enumerate(description["coefficients"]): BS = WP.get_basis_shapes(component=component) for index, value in data: if BS.contains(index): WP.set_coefficient(component, index, value) else: print("Warning: dropped coefficient with index "+str(index)) # And the inner product if description.has_key("innerproduct"): IP = self.create_inner_product(description["innerproduct"]) WP.set_innerproduct(IP) else: print("Warning: no inner product specified!") elif wp_type == "HagedornWavepacketInhomogeneous": from HagedornWavepacketInhomogeneous import HagedornWavepacketInhomogeneous # Initialize a packet WP = HagedornWavepacketInhomogeneous(description["dimension"], description["ncomponents"], description["eps"]) # Set parameters if description.has_key("Pi"): Pi = description["Pi"] WP.set_parameters(Pi) # Configure basis shapes if description.has_key("basis_shapes"): for component, shapedescr in enumerate(description["basis_shapes"]): BS = self.create_basis_shape(shapedescr) WP.set_basis_shapes(BS, component=component) # Set coefficients if description.has_key("coefficients"): for component, data in enumerate(description["coefficients"]): for index, value in data: WP.set_coefficient(component, index, value) # And the quadrature if description.has_key("innerproduct"): IP = self.create_inner_product(description["innerproduct"]) WP.set_innerproduct(IP) else: print("Warning: no inner product specified!") else: raise ValueError("Unknown wavepacket type "+str(wp_type)) return WP
def create_wavepacket(self, description): wp_type = description["type"] if wp_type == "HagedornWavepacket": from HagedornWavepacket import HagedornWavepacket # Initialize a packet WP = HagedornWavepacket(description["dimension"], description["ncomponents"], description["eps"]) # Set parameters if description.has_key("Pi"): Pi = description["Pi"] WP.set_parameters(Pi) # Configure basis shapes if description.has_key("basis_shapes"): for component, shapedescr in enumerate(description["basis_shapes"]): BS = self.create_basis_shape(shapedescr) WP.set_basis_shape(BS, component=component) # Set coefficients if description.has_key("coefficients"): for component, data in enumerate(description["coefficients"]): for index, value in data: WP.set_coefficient(component, index, value) # And the quadrature if description.has_key("quadrature"): QE = self.create_quadrature(description["quadrature"]) WP.set_quadrature(QE) else: print("Warning: no quadrature specified!") elif wp_type == "HagedornWavepacketInhomogeneous": from HagedornWavepacketInhomogeneous import HagedornWavepacketInhomogeneous # Initialize a packet WP = HagedornWavepacketInhomogeneous( description["dimension"], description["ncomponents"], description["eps"] ) # Set parameters if description.has_key("Pi"): Pi = description["Pi"] WP.set_parameters(Pi) # Configure basis shapes if description.has_key("basis_shapes"): for component, shapedescr in enumerate(description["basis_shapes"]): BS = self.create_basis_shape(shapedescr) WP.set_basis_shape(BS, component=component) # Set coefficients if description.has_key("coefficients"): for component, data in enumerate(description["coefficients"]): for index, value in data: WP.set_coefficient(component, index, value) # And the quadrature if description.has_key("quadrature"): QE = self.create_quadrature(description["quadrature"]) WP.set_quadrature(QE) else: print("Warning: no quadrature specified!") else: raise ValueError("Unknown wavepacket type " + str(wp_type)) return WP
def create_wavepacket(self, description): wp_type = description["type"] if wp_type == "HagedornWavepacket": from HagedornWavepacket import HagedornWavepacket # Initialize a packet WP = HagedornWavepacket(description["dimension"], description["ncomponents"], description["eps"]) # Set parameters if description.has_key("Pi"): Pi = description["Pi"] WP.set_parameters(Pi) # Configure basis shapes if description.has_key("basis_shapes"): for component, shapedescr in enumerate( description["basis_shapes"]): BS = self.create_basis_shape(shapedescr) WP.set_basis_shape(BS, component=component) # Set coefficients if description.has_key("coefficients"): for component, data in enumerate(description["coefficients"]): for index, value in data: WP.set_coefficient(component, index, value) # And the quadrature if description.has_key("quadrature"): QE = self.create_quadrature(description["quadrature"]) WP.set_quadrature(QE) else: print("Warning: no quadrature specified!") elif wp_type == "HagedornWavepacketInhomogeneous": from HagedornWavepacketInhomogeneous import HagedornWavepacketInhomogeneous # Initialize a packet WP = HagedornWavepacketInhomogeneous(description["dimension"], description["ncomponents"], description["eps"]) # Set parameters if description.has_key("Pi"): Pi = description["Pi"] WP.set_parameters(Pi) # Configure basis shapes if description.has_key("basis_shapes"): for component, shapedescr in enumerate( description["basis_shapes"]): BS = self.create_basis_shape(shapedescr) WP.set_basis_shape(BS, component=component) # Set coefficients if description.has_key("coefficients"): for component, data in enumerate(description["coefficients"]): for index, value in data: WP.set_coefficient(component, index, value) # And the quadrature if description.has_key("quadrature"): QE = self.create_quadrature(description["quadrature"]) WP.set_quadrature(QE) else: print("Warning: no quadrature specified!") else: raise ValueError("Unknown wavepacket type " + str(wp_type)) return WP
def prepare_simulation(self): r""" Set up a Fourier propagator for the simulation loop. Set the potential and initial values according to the configuration. :raise ValueError: For invalid or missing input data. """ # Compute the position space grid points nodes = self.parameters["f"] * sp.pi * sp.arange(-1, 1, 2.0/self.parameters["ngn"], dtype=np.complexfloating) # The potential instance potential = PF().create_potential(self.parameters) # Check for enough initial values if not self.parameters.has_key("initial_values"): if len(self.parameters["parameters"]) < potential.get_number_components(): raise ValueError("Too few initial states given. Parameters are missing.") if len(self.parameters["coefficients"]) < potential.get_number_components(): raise ValueError("Too few initial states given. Coefficients are missing.") # Calculate the initial values sampled from a hagedorn wave packet d = dict([("ncomponents", 1), ("basis_size", self.parameters["basis_size"]), ("eps", self.parameters["eps"])]) # Initial values given in the "fourier" specific format if self.parameters.has_key("initial_values"): initialvalues = [ np.zeros(nodes.shape, dtype=np.complexfloating) for i in xrange(self.parameters["ncomponents"]) ] for level, params, coeffs in self.parameters["initial_values"]: hwp = HagedornWavepacket(d) hwp.set_parameters(params) for index, value in coeffs: hwp.set_coefficient(0, index, value) iv = hwp.evaluate_at(nodes, component=0, prefactor=True) initialvalues[level] = initialvalues[level] + iv # Initial value read in compatibility mode to the packet algorithms else: # See if we have a list of parameter tuples or just a single 5-tuple # This is for compatibility with the inhomogeneous case. try: # We have a list of parameter tuples this is ok for the loop below len(self.parameters["parameters"][0]) parameters = self.parameters["parameters"] except TypeError: # We have just a single 5-tuple of parameters, we need to replicate for looping parameters = [ self.parameters["parameters"] for i in xrange(self.parameters["ncomponents"]) ] initialvalues = [] for level, item in enumerate(parameters): hwp = HagedornWavepacket(d) hwp.set_parameters(item) # Set the coefficients of the basis functions for index, value in self.parameters["coefficients"][level]: hwp.set_coefficient(0, index, value) iv = hwp.evaluate_at(nodes, component=0, prefactor=True) initialvalues.append(iv) # Project the initial values to the canonical basis initialvalues = potential.project_to_canonical(nodes, initialvalues) # Store the initial values in a WaveFunction object IV = WaveFunction(self.parameters) IV.set_grid(nodes) IV.set_values(initialvalues) # Finally create and initialize the propagator instace self.propagator = FourierPropagator(potential, IV, self.parameters) # Which data do we want to save tm = self.parameters.get_timemanager() slots = tm.compute_number_saves() print(tm) self.IOManager.add_grid(self.parameters, blockid="global") self.IOManager.add_fourieroperators(self.parameters) self.IOManager.add_wavefunction(self.parameters, timeslots=slots) # Write some initial values to disk self.IOManager.save_grid(nodes, blockid="global") self.IOManager.save_fourieroperators(self.propagator.get_operators()) self.IOManager.save_wavefunction(IV.get_values(), timestep=0)
def prepare_simulation(self): r""" Set up a Spawning propagator for the simulation loop. Set the potential and initial values according to the configuration. :raise ValueError: For invalid or missing input data. """ potential = PotentialFactory().create_potential(self.parameters) N = potential.get_number_components() # Check for enough initial values if self.parameters["leading_component"] > N: raise ValueError("Leading component index out of range.") if len(self.parameters["parameters"]) < N: raise ValueError("Too few initial states given. Parameters are missing.") if len(self.parameters["coefficients"]) < N: raise ValueError("Too few initial states given. Coefficients are missing.") # Create a suitable wave packet packet = HagedornWavepacket(self.parameters) packet.set_parameters(self.parameters["parameters"][self.parameters["leading_component"]]) packet.set_quadrature(None) # Set the initial values for component, data in enumerate(self.parameters["coefficients"]): for index, value in data: packet.set_coefficient(component, index, value) # Project the initial values to the canonical basis packet.project_to_canonical(potential) # Finally create and initialize the propagator instace inner = HagedornPropagator(potential, packet, self.parameters["leading_component"], self.parameters) self.propagator = SpawnAdiabaticPropagator(inner, potential, packet, self.parameters["leading_component"], self.parameters) # Write some initial values to disk slots = self.tm.compute_number_saves() for packet in self.propagator.get_wavepackets(): bid = self.iom.create_block(groupid=self.gid) self.iom.add_wavepacket(self.parameters, timeslots=slots, blockid=bid) self.iom.save_wavepacket_coefficients(packet.get_coefficients(), blockid=bid, timestep=0) self.iom.save_wavepacket_parameters(packet.get_parameters(), blockid=bid, timestep=0)