Beispiel #1
0
    def set_wavefunction(self,
                         x_psi_: Union[str, np.ndarray],
                         y_psi_: Union[str, np.ndarray],
                         normalize=True) -> None:
        if isinstance(x_psi_, str) and isinstance(y_psi_, str):
            try:
                if x_psi_.strip().replace('.', '').replace('-', '').replace(
                        'e', '').isnumeric():
                    x_psi_ = float(x_psi_) * np.ones([self.N])
                    self.psi_name = x_psi_
                    self.psi_latex = '$%s$' % x_psi_
                    y_psi_ = float(y_psi_) * np.ones([self.N])
                    self.psi = WaveFunction2D(x_psi_, y_psi_)
                    self._msg = "$\psi(x, 0) =$ %s" % self.psi_latex
                    self._msg_i = 45
                    if normalize:
                        self.psi.normalize()
                    self.psi_base = None
                    self.psi_params = {}
                else:
                    psi_ = x_psi_.replace("^", "**")
                    f = Function(psi_, "x")
                    self.psi_base = f
                    psi_func = lambda _x: f(_x, *f.get_tupled_default_values())
                    self.psi_name = str(f)
                    self.psi_latex = "$" + f.latex_repr + "$"
                    self.psi = WaveFunction2D(psi_func)
                    self.psi_params = f.get_enumerated_default_values()
                    self._msg = r"$\psi(x, 0) =$ %s" % self.psi_latex
                    self._msg_i = 45
                    if normalize:
                        self.psi.normalize()
            except (TypeError, AttributeError, SyntaxError, ValueError,
                    NameError) as e:
                print(e)

        elif isinstance(x_psi_, np.ndarray) and isinstance(y_psi_, np.ndarray):
            # self.psi_base = None
            # self.psi_params = {}
            self.psi = WaveFunction2D(x_psi_, y_psi_)
            self.psi_name = "wavefunction"
            self.psi_latex = "$\psi(x)$"
            if normalize:
                self.psi.normalize()
        else:
            raise TypeError('Unable to parse input for psi')
Beispiel #2
0
    def set_unitary(self, potential):
        if isinstance(potential, str):
            try:
                if potential.strip().replace(".", "").replace("-", "").replace(
                        "e", "").isnumeric():
                    self.V_name = ""
                    self.V_latex = str(np.round(float(potential), 2))
                    if float(potential) == 0:
                        potential = 1e-30
                        v_f = float(potential) * np.ones([self.N])
                        self.U_t = UnitaryOperator2D(np.copy(v_f))
                        self.V_x = 0.0 * v_f
                    else:
                        v_f = scale(float(potential) * np.ones([self.N]), 15)
                        self.V_x = v_f
                        self.U_t = UnitaryOperator2D(np.copy(v_f))
                        self.V_latex = "%sk" % self.V_latex if v_f[0] > 0 \
                            else " %sk" % self.V_latex
                    self.V_params = {}
                    self.V_base = None
                else:
                    potential = potential.replace("^", "**")
                    f = Function(potential, "x")
                    self.V = lambda _x: f(_x, *f.get_tupled_default_values())
                    self.V_x = scale(self.V(self.x), 15)
                    self.V_name = str(f)
                    self.V_latex = "$" + f.multiply_latex_string("k") + "$"
                    self.U_t = UnitaryOperator2D(self.V)
                    self.V_base = f
                    self.V_params = f.get_enumerated_default_values()
            except (TypeError, AttributeError, SyntaxError, ValueError,
                    NameError) as E:
                print(E)
        elif isinstance(potential, np.ndarray):
            self.V_params = {}
            self.V_base = None
            self.V_x = scale(V, 15)
            self.V_name = "V(x)"
            self.V_latex = "$V(x)$"
            self.U_t = UnitaryOperator2D(V)
        else:
            print('Unable to parse input')

        if hasattr(self, "lines"):
            pass