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 prepare_simulation(self):
        r"""
        Set up a multi 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 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 = HagedornWavepacketInhomogeneous(self.parameters)
        packet.set_quadrature(None)

        # Set the parameters for each energy level
        for level, item in enumerate(self.parameters["parameters"]):
            packet.set_parameters(item, level)

        # 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 = HagedornPropagatorInhomogeneous(potential, packet, 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_inhomogwavepacket(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.nodes = nodes
        self.IOManager.save_grid(nodes, blockid="global")
        self.IOManager.save_inhomogwavepacket_parameters(self.propagator.get_wavepackets().get_parameters(), timestep=0)
        self.IOManager.save_inhomogwavepacket_coefficients(self.propagator.get_wavepackets().get_coefficients(), 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)
Пример #4
0
    def compute_parameters(self):
        r"""
        Compute some further parameters from the given ones.
        """
        # Perform the computation only if the basic values are available.
        # This is necessary to add flexibility and essentially read in *any*
        # parameter file with heavily incomplete value sets. (F.e. spawn configs)
        try:
            # The number of time steps we will perform.
            tm = TimeManager(self)
            self.params["nsteps"] = tm.compute_number_timesteps()
        except:
            pass

        if self.params.has_key("potential"):
            # Ugly hack. Should improve handling of potential libraries
            Potential = PF().create_potential(self)
            # Number of components of :math:`\Psi`
            self.params["ncomponents"] = Potential.get_number_components()
    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)