當前位置: 首頁>>代碼示例>>Python>>正文


Python BlockFactory.evaluate_eigenvalues_at方法代碼示例

本文整理匯總了Python中WaveBlocksND.BlockFactory.evaluate_eigenvalues_at方法的典型用法代碼示例。如果您正苦於以下問題:Python BlockFactory.evaluate_eigenvalues_at方法的具體用法?Python BlockFactory.evaluate_eigenvalues_at怎麽用?Python BlockFactory.evaluate_eigenvalues_at使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WaveBlocksND.BlockFactory的用法示例。


在下文中一共展示了BlockFactory.evaluate_eigenvalues_at方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: latex

# 需要導入模塊: from WaveBlocksND import BlockFactory [as 別名]
# 或者: from WaveBlocksND.BlockFactory import evaluate_eigenvalues_at [as 別名]
        potformula = latex(sympify(potdef["potential"]))
    else:
        potformula = latex(Matrix(sympify(potdef["potential"])))

    if potdef.has_key("defaults"):
        potdefaults = potdef["defaults"]
    else:
        potdefaults = {}

    # Create the potential "the right way"
    params["potential"] = potdef
    P = BlockFactory().create_potential(params)

    if len(potdef["variables"]) == 1:
        # Plot the potential
        values = P.evaluate_eigenvalues_at(x)

        figure(figsize=(4,3))
        for value in values:
            plot(squeeze(x), squeeze(value))
        grid(True)
        xlabel(r"$x$")
        ylabel(r"$\lambda_i\left(x\right)$")
        xlim(min(x), max(x))
        savefig(potdef["name"] + ".png")

    elif len(potdef["variables"]) == 2:
        values = P.evaluate_eigenvalues_at(G)

        f = mlab.figure()
        for value in values:
開發者ID:Bredoto,項目名稱:WaveBlocksND,代碼行數:33,代碼來源:documentPotentialLibrary.py

示例2: compute_energy

# 需要導入模塊: from WaveBlocksND import BlockFactory [as 別名]
# 或者: from WaveBlocksND.BlockFactory import evaluate_eigenvalues_at [as 別名]
def compute_energy(iom, blockid=0, eigentrafo=True, iseigen=True):
    """
    :param iom: An :py:class:`IOManager: instance providing the simulation data.
    :param blockid: The data block from which the values are read. Default is `0`.
    :param eigentrafo: Whether to make a transformation into the eigenbasis.
    :type eigentrafo: Boolean, default is ``True``.
    :param iseigen: Whether the data is assumed to be in the eigenbasis.
    :type iseigen: Boolean, default is ``True``

    """
    parameters = iom.load_parameters()

    # Number of time steps we saved
    timesteps = iom.load_wavefunction_timegrid(blockid=blockid)
    nrtimesteps = timesteps.shape[0]

    # Construct grid from the parameters
    grid = BlockFactory().create_grid(parameters)

    # The potential used
    Potential = BlockFactory().create_potential(parameters)

    # The operators
    KO = KineticOperator(grid)
    KO.calculate_operator(parameters["eps"])
    opT = KO
    if eigentrafo is True:
        opV = Potential.evaluate_at(grid)
    else:
        if iseigen is True:
            opV = Potential.evaluate_eigenvalues_at(grid, as_matrix=True)
        else:
            opV = Potential.evaluate_at(grid, as_matrix=True)

    # Basis transformator
    if eigentrafo is True:
        BT = BasisTransformationWF(Potential)
        BT.set_grid(grid)

    # And two empty wavefunctions
    WF = WaveFunction(parameters)
    WF.set_grid(grid)
    WF2 = WaveFunction(parameters)
    WF2.set_grid(grid)

    # We want to save norms, thus add a data slot to the data file
    iom.add_energy(parameters, timeslots=nrtimesteps, blockid=blockid)

    nst = Potential.get_number_components()

    if eigentrafo is True:

        # Iterate over all timesteps
        for i, step in enumerate(timesteps):
            print(" Computing energies of timestep # " + str(step))

            # Retrieve simulation data
            values = iom.load_wavefunction(timestep=step, blockid=blockid)
            values = [ values[j,...] for j in xrange(parameters["ncomponents"]) ]
            WF.set_values(values)

            # Project wavefunction values to eigenbasis
            BT.transform_to_eigen(WF)

            ekinlist = []
            epotlist = []

            # For each component of |Psi>
            values = WF.get_values()

            for index, item in enumerate(values):
                # tmp is the Vector (0, 0, 0, \psi_i, 0, 0, ...)
                tmp = [ zeros(item.shape) for z in xrange(nst) ]
                tmp[index] = item
                WF2.set_values(tmp)

                # Project this vector to the canonical basis
                BT.transform_to_canonical(WF2)

                # And calculate the energies of these components
                ekinlist.append(WF2.kinetic_energy(opT, summed=True))
                epotlist.append(WF2.potential_energy(opV, summed=True))

            iom.save_energy((ekinlist, epotlist), timestep=step, blockid=blockid)

    else:

        # Iterate over all timesteps
        for i, step in enumerate(timesteps):
            print(" Computing energies of timestep # " + str(step))

            # Retrieve simulation data
            values = iom.load_wavefunction(timestep=step, blockid=blockid)
            values = [ values[j,...] for j in xrange(parameters["ncomponents"]) ]
            WF.set_values(values)

            # And calculate the energies of these components
            ekinlist = WF.kinetic_energy(opT, summed=False)
            epotlist = WF.potential_energy(opV, summed=False)

#.........這裏部分代碼省略.........
開發者ID:GaZ3ll3,項目名稱:WaveBlocksND,代碼行數:103,代碼來源:EnergiesWavefunction.py


注:本文中的WaveBlocksND.BlockFactory.evaluate_eigenvalues_at方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。