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
Ejemplo n.º 2
0
def load_lincombhawp(self, timestep, blockid=0, key=("q", "p", "Q", "P", "S")):
    r"""Load a linear combination at a given timestep and return a fully configured
    :py:class:`LinearCombinationOfHAWPs` 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` we load the wavepacket.
    :param blockid: The ID of the data block to operate on.
    :return: A :py:class:`LinearCombinationOfHAWPs` instance.
    """
    from WaveBlocksND.LinearCombinationOfHAWPs import LinearCombinationOfHAWPs
    from WaveBlocksND.BlockFactory import BlockFactory
    BF = BlockFactory()

    descr = self.load_lincombhawp_description(blockid=blockid)

    # Empty linear combination
    J = self.load_lincombhawp_size(timestep=timestep, blockid=blockid)
    if J == 0:
        return None

    # A new and empty linear combination
    LC = LinearCombinationOfHAWPs(descr["dimension"],
                                  descr["ncomponents"],
                                  descr["eps"],
                                  number_packets=J)
    # Basis shapes
    K_descrs = self.load_lincombhawp_wavepacket_basisshapes(blockid=blockid)
    K = {ha: BF.create_basis_shape(de) for ha, de in K_descrs.items()}
    # Coefficients and basis shape hashes
    hashes, coeffs = self.load_lincombhawp_wavepacket_coefficients(
        timestep=timestep, get_hashes=True, blockid=blockid)
    Ks = [K[ha] for ha in np.squeeze(hashes)]
    LC.set_wavepacket_coefficients(coeffs, Ks)
    # Parameters
    Pi = self.load_lincombhawp_wavepacket_parameters(timestep=timestep,
                                                     blockid=blockid,
                                                     key=key)
    LC.set_wavepacket_parameters(Pi)
    # Cj
    Cj = self.load_lincombhawp_coefficients(timestep=timestep, blockid=blockid)
    LC.set_coefficients(Cj)

    return LC
Ejemplo n.º 3
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.º 4
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.º 5
0
def load_lincombhawp(self, timestep, blockid=0, key=("q", "p", "Q", "P", "S")):
    r"""Load a linear combination at a given timestep and return a fully configured
    :py:class:`LinearCombinationOfHAWPs` 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` we load the wavepacket.
    :param blockid: The ID of the data block to operate on.
    :return: A :py:class:`LinearCombinationOfHAWPs` instance.
    """
    from WaveBlocksND.LinearCombinationOfHAWPs import LinearCombinationOfHAWPs
    from WaveBlocksND.BlockFactory import BlockFactory
    BF = BlockFactory()

    descr = self.load_lincombhawp_description(blockid=blockid)

    # Empty linear combination
    J = self.load_lincombhawp_size(timestep=timestep, blockid=blockid)
    if J == 0:
        return None

    # A new and empty linear combination
    LC = LinearCombinationOfHAWPs(descr["dimension"], descr["ncomponents"], descr["eps"], number_packets=J)
    # Basis shapes
    K_descrs = self.load_lincombhawp_wavepacket_basisshapes(blockid=blockid)
    K = {ha: BF.create_basis_shape(de) for ha, de in K_descrs.items()}
    # Coefficients and basis shape hashes
    hashes, coeffs = self.load_lincombhawp_wavepacket_coefficients(timestep=timestep, get_hashes=True, blockid=blockid)
    Ks = [K[ha] for ha in np.squeeze(hashes)]
    LC.set_wavepacket_coefficients(coeffs, Ks)
    # Parameters
    Pi = self.load_lincombhawp_wavepacket_parameters(timestep=timestep, blockid=blockid, key=key)
    LC.set_wavepacket_parameters(Pi)
    # Cj
    Cj = self.load_lincombhawp_coefficients(timestep=timestep, blockid=blockid)
    LC.set_coefficients(Cj)

    return LC
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