Ejemplo n.º 1
0
def load_wavepacket(self, timestep, blockid=0, key=("q", "p", "Q", "P", "S", "adQ")):
    r"""Load a wavepacket at a given timestep and return a fully configured instance.
    This method just calls some other :py:class:`IOManager` methods in the correct
    order. It is included only for convenience and is not particularly efficient.

    :param timestep: The timestep :math:`n` at which we load the wavepacket.
    :param key: Specify which parameters to load. All are independent.
    :type key: Tuple of valid identifier strings that are ``q``, ``p``, ``Q``, ``P``, ``S`` and ``adQ``.
               Default is ``("q", "p", "Q", "P", "S", "adQ")``.
    :param blockid: The ID of the data block to operate on.
    :return: A :py:class:`HagedornWavepacket` instance.
    """
    from WaveBlocksND.BlockFactory import BlockFactory
    BF = BlockFactory()

    descr = self.load_wavepacket_description(blockid=blockid)
    HAWP = BF.create_wavepacket(descr)

    # Parameters and coefficients
    Pi = self.load_wavepacket_parameters(timestep=timestep, blockid=blockid, key=key)
    hashes, coeffs = self.load_wavepacket_coefficients(timestep=timestep, get_hashes=True, blockid=blockid)

    # Basis shapes
    Ks = []
    for ahash in hashes:
        K_descr = self.load_wavepacket_basisshapes(the_hash=ahash, blockid=blockid)
        Ks.append(BF.create_basis_shape(K_descr))

    # Configure the wavepacket
    HAWP.set_parameters(Pi, key=key)
    HAWP.set_basis_shapes(Ks)
    HAWP.set_coefficients(coeffs)

    return HAWP
    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: :py:class:`ValueError` For invalid or missing input data.
        """
        BF = BlockFactory()

        # The potential instance
        potential = BF.create_potential(self.parameters)

        # Project the initial values to the canonical basis
        BT = BasisTransformationHAWP(potential)

        # Finally create and initialize the propagator instance
        # TODO: Attach the "leading_component to the hawp as codata
        self.propagator = BF.create_propagator(self.parameters, potential)

        # Create suitable wavepackets
        for packet_descr in self.parameters["initvals"]:
            packet = BF.create_wavepacket(packet_descr)
            # Transform to canonical basis
            BT.set_matrix_builder(packet.get_innerproduct())
            BT.transform_to_canonical(packet)
            # And hand over
            self.propagator.add_wavepacket((packet, ))

        # Add storage for each packet
        npackets = len(self.parameters["initvals"])
        slots = self._tm.compute_number_events()
        key = ("q", "p", "Q", "P", "S", "adQ")

        for i in range(npackets):
            bid = self.IOManager.create_block(
                dt=self.parameters.get("dt", 0.0))
            self.IOManager.add_inhomogwavepacket(self.parameters,
                                                 timeslots=slots,
                                                 blockid=bid,
                                                 key=key)

        # Write some initial values to disk
        for packet in self.propagator.get_wavepackets():
            self.IOManager.save_inhomogwavepacket_description(
                packet.get_description())

        if self._tm.is_event(0):
            for packet in self.propagator.get_wavepackets():
                # Pi
                self.IOManager.save_inhomogwavepacket_parameters(
                    packet.get_parameters(key=key), timestep=0, key=key)
                # Basis shapes
                for shape in packet.get_basis_shapes():
                    self.IOManager.save_inhomogwavepacket_basisshapes(shape)
                # Coefficients
                self.IOManager.save_inhomogwavepacket_coefficients(
                    packet.get_coefficients(),
                    packet.get_basis_shapes(),
                    timestep=0)
Ejemplo n.º 3
0
    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: :py:class:`ValueError` For invalid or missing input data.
        """
        BF = BlockFactory()

        # The potential instance
        potential = BF.create_potential(self.parameters)

        # Project the initial values to the canonical basis
        BT = BasisTransformationHAWP(potential)

        # Finally create and initialize the propagator instance
        # TODO: Attach the "leading_component to the hawp as codata
        self.propagator = BF.create_propagator(self.parameters, potential)

        # Create suitable wavepackets
        chi = self.parameters["leading_component"]

        for packet_descr in self.parameters["initvals"]:
            packet = BF.create_wavepacket(packet_descr)
            # Transform to canonical basis
            BT.set_matrix_builder(packet.get_innerproduct())
            BT.transform_to_canonical(packet)
            # And hand over
            self.propagator.add_wavepacket((packet, chi))

        # Add storage for each packet
        npackets = len(self.parameters["initvals"])
        slots = self._tm.compute_number_events()
        key = ("q", "p", "Q", "P", "S", "adQ")

        for i in range(npackets):
            bid = self.IOManager.create_block(dt=self.parameters.get("dt", 0.0))
            self.IOManager.add_wavepacket(self.parameters, timeslots=slots, blockid=bid, key=key)

        # Write some initial values to disk
        for packet in self.propagator.get_wavepackets():
            self.IOManager.save_wavepacket_description(packet.get_description())

        if self._tm.is_event(0):
            for packet in self.propagator.get_wavepackets():
                # Pi
                self.IOManager.save_wavepacket_parameters(packet.get_parameters(key=key), timestep=0, key=key)
                # Basis shapes
                for shape in packet.get_basis_shapes():
                    self.IOManager.save_wavepacket_basisshapes(shape)
                # Coefficients
                self.IOManager.save_wavepacket_coefficients(packet.get_coefficients(), packet.get_basis_shapes(), timestep=0)
Ejemplo n.º 4
0
def load_wavepacket(self,
                    timestep,
                    blockid=0,
                    key=("q", "p", "Q", "P", "S", "adQ")):
    r"""Load a wavepacket at a given timestep and return a fully configured instance.
    This method just calls some other :py:class:`IOManager` methods in the correct
    order. It is included only for convenience and is not particularly efficient.

    :param timestep: The timestep :math:`n` at which we load the wavepacket.
    :param key: Specify which parameters to load. All are independent.
    :type key: Tuple of valid identifier strings that are ``q``, ``p``, ``Q``, ``P``, ``S`` and ``adQ``.
               Default is ``("q", "p", "Q", "P", "S", "adQ")``.
    :param blockid: The ID of the data block to operate on.
    :return: A :py:class:`HagedornWavepacket` instance.
    """
    from WaveBlocksND.BlockFactory import BlockFactory
    BF = BlockFactory()

    descr = self.load_wavepacket_description(blockid=blockid)
    HAWP = BF.create_wavepacket(descr)

    # Parameters and coefficients
    Pi = self.load_wavepacket_parameters(timestep=timestep,
                                         blockid=blockid,
                                         key=key)
    hashes, coeffs = self.load_wavepacket_coefficients(timestep=timestep,
                                                       get_hashes=True,
                                                       blockid=blockid)

    # Basis shapes
    Ks = []
    for ahash in hashes:
        K_descr = self.load_wavepacket_basisshapes(the_hash=ahash,
                                                   blockid=blockid)
        Ks.append(BF.create_basis_shape(K_descr))

    # Configure the wavepacket
    HAWP.set_parameters(Pi, key=key)
    HAWP.set_basis_shapes(Ks)
    HAWP.set_coefficients(coeffs)

    return HAWP
Ejemplo n.º 5
0
def load_wavepacket_inhomogeneous(iom, timestep, blockid=0):
    r"""Utility function to load an inhomogeneous
    wavepacket from an :py:class:`IOManager` instance.

    :param iom: The :py:class:`IOManager` instance from which to load data.
    :param timestep: Load the data corresponding to the given `timestep`.
    :param blockid: The `datablock` from which to read the data.
                    Default is the block with `blockid=0`.

    Note: This function is a pure utility function and is not efficient. It is
          built for interactive use only and should not be use in scripts.
    """
    if not iom.has_inhomogwavepacket(blockid=blockid):
        print("There is no (inhomogeneous) wavepacket to load in block {}".
              format(blockid))
        return

    BF = BlockFactory()

    wpd = iom.load_inhomogwavepacket_description(blockid=blockid)
    HAWP = BF.create_wavepacket(wpd)

    # Basis shapes
    BS_descr = iom.load_inhomogwavepacket_basisshapes(blockid=blockid)
    BS = {}
    for ahash, descr in BS_descr.items():
        BS[ahash] = BF.create_basis_shape(descr)

    KEY = ("q", "p", "Q", "P", "S", "adQ")
    # Retrieve simulation data
    params = iom.load_inhomogwavepacket_parameters(timestep=timestep,
                                                   blockid=blockid,
                                                   key=KEY)
    hashes, coeffs = iom.load_inhomogwavepacket_coefficients(timestep=timestep,
                                                             get_hashes=True,
                                                             blockid=blockid)
    # Configure the wavepacket
    HAWP.set_parameters(params, key=KEY)
    HAWP.set_basis_shapes([BS[int(ha)] for ha in hashes])
    HAWP.set_coefficients(coeffs)

    return HAWP
Ejemplo n.º 6
0
def load_wavepacket_inhomogeneous(iom, timestep, blockid=0):
    r"""Utility function to load an inhomogeneous
    wavepacket from an :py:class:`IOManager` instance.

    :param iom: The :py:class:`IOManager` instance from which to load data.
    :param timestep: Load the data corresponding to the given `timestep`.
    :param blockid: The `datablock` from which to read the data.
                    Default is the block with `blockid=0`.

    Note: This function is a pure utility function and is not efficient. It is
          built for interactive use only and should not be use in scripts.
    """
    if not iom.has_inhomogwavepacket(blockid=blockid):
        print("There is no (inhomogeneous) wavepacket to load in block {}".format(blockid))
        return

    BF = BlockFactory()

    wpd = iom.load_inhomogwavepacket_description(blockid=blockid)
    HAWP = BF.create_wavepacket(wpd)

    # Basis shapes
    BS_descr = iom.load_inhomogwavepacket_basisshapes(blockid=blockid)
    BS = {}
    for ahash, descr in BS_descr.items():
        BS[ahash] = BF.create_basis_shape(descr)

    KEY = ("q", "p", "Q", "P", "S", "adQ")
    # Retrieve simulation data
    params = iom.load_inhomogwavepacket_parameters(timestep=timestep, blockid=blockid, key=KEY)
    hashes, coeffs = iom.load_inhomogwavepacket_coefficients(timestep=timestep, get_hashes=True, blockid=blockid)
    # Configure the wavepacket
    HAWP.set_parameters(params, key=KEY)
    HAWP.set_basis_shapes([BS[int(ha)] for ha in hashes])
    HAWP.set_coefficients(coeffs)

    return HAWP