コード例 #1
0
ファイル: BREXI.py プロジェクト: Kevin2599/sweet
    def setup(self, N, quadrature_method="gauss"):
        self.N = N
        self.quadrature_method = quadrature_method

        if quadrature_method == "gauss":
            A, b, c = rkanalysis.gauss(N)
            self.quadrature_method_short = "G"

        elif quadrature_method == "chebyshev":
            A, b, c = rkanalysis.chebyshev(N)
            self.quadrature_method_short = "C"

        elif quadrature_method == "radau":
            A, b, c = rkanalysis.radau(N)
            self.quadrature_method_short = "R"

        else:
            raise Exception("Quadrature method '" + quadrature_method +
                            "' not supported")

        # Create modified/unified REXI form
        A, b, c = rkanalysis.butcher_diag(A, b)
        alphas, betas = rkanalysis.butcher2rexi(A, b)
        gamma = self.efloat.to(1.0) - numpy.sum(betas / alphas)

        coeffs = REXICoefficients()
        coeffs.function_name = "phi0"
        coeffs.efloat = self.efloat
        coeffs.alphas = alphas
        coeffs.betas = betas
        coeffs.gamma = gamma

        coeffs.unique_id_string = self.getUniqueId()

        return coeffs
コード例 #2
0
    def setup(self,
              function_name,
              N: int,
              R: float = None,
              lambda_shift: complex = None,
              lambda_max_real: float = None,
              lambda_include_imag: float = None):
        self.alphas = []
        self.betas = []
        self.function_name = ""

        if lambda_shift != None:
            self.setup_shifted_circle(function_name,
                                      N=N,
                                      R=R,
                                      lambda_shift=lambda_shift)

        elif lambda_max_real != None:
            self.setup_limited_circle(function_name,
                                      N=N,
                                      lambda_max_real=lambda_max_real,
                                      lambda_include_imag=lambda_include_imag)

        else:
            self.setup_circle(function_name, N=N, R=R)

        coeffs = REXICoefficients()
        coeffs.alphas = self.alphas[:]
        coeffs.betas = self.betas[:]
        coeffs.gamma = 0
        coeffs.function_name = self.function_name

        coeffs.unique_id_string = self.getUniqueId()

        return coeffs
コード例 #3
0
ファイル: BREXI.py プロジェクト: valentinaschueller/sweet
    def setup(self, N, quadrature_method="gauss_legendre", tanhsinh_h=None):
        self.N = N
        self.quadrature_method = quadrature_method
        self.quadrature_method_short = quadrature_method[0].upper()

        co = rk_co.rk_co(N, quadrature_method)
        """
        Step 1) Diagonalization
        """
        """
        Compute Eigendecomposition with Eigenvalues in D
        """
        D, E = numpy.linalg.eig(co.A)
        """
        Compute diagonal-only W so that
            W * E^-1 * ONES = ONES
        with ONES a vector with only ones
        """
        #
        # E^-1 * ONES = eta
        # <=> E*eta = ONE
        # <=> eta = solve(E, ONE)
        #
        eta = numpy.linalg.solve(E, numpy.ones(N))

        #
        # W * eta = ONES
        # diag-only W
        # diag(W) = eta^-1
        # diag(W_inv) = eta
        #
        W_inv = numpy.diag(eta)
        b_tilde = co.b.T.dot(E.dot(W_inv))

        # Create modified/unified REXI form
        """
        Step 2) Get REXI formulation
        """

        gamma = 1.0 - numpy.sum(b_tilde / D)
        alphas = 1 / D
        betas = -b_tilde / (D * D)

        coeffs = REXICoefficients()
        coeffs.function_name = "phi0"
        coeffs.efloat = self.efloat
        coeffs.alphas = alphas
        coeffs.betas = betas
        coeffs.gamma = gamma

        coeffs.unique_id_string = self.getUniqueId()

        return coeffs
コード例 #4
0
ファイル: CIREXI.py プロジェクト: valentinaschueller/sweet
    def setup(self,
              function_name,
              N: int,
              R: float = None,
              lambda_shift: complex = None,
              lambda_max_real: float = None,
              lambda_include_imag: float = None,
              half_shifted: bool = True):
        self.alphas = []
        self.betas = []
        self.function_name = ""

        if lambda_shift != None:
            self.setup_shifted_circle(function_name,
                                      N=N,
                                      R=R,
                                      lambda_shift=lambda_shift,
                                      half_shifted=half_shifted)

        elif lambda_max_real != None:
            self.setup_limited_circle(function_name,
                                      N=N,
                                      lambda_max_real=lambda_max_real,
                                      lambda_include_imag=lambda_include_imag,
                                      half_shifted=half_shifted)

        elif lambda_include_imag != None:
            self.setup_circle(function_name,
                              N=N,
                              R=lambda_include_imag,
                              half_shifted=half_shifted)

        elif R != None:
            self.setup_shifted_circle(function_name, N=N, R=R, lambda_shift=0)

        else:
            raise Exception(
                "Can't calculate circle radius, please provide imag/real limits."
            )

        coeffs = REXICoefficients()
        coeffs.alphas = self.alphas[:]
        coeffs.betas = self.betas[:]
        coeffs.gamma = 0
        coeffs.function_name = self.function_name

        coeffs.unique_id_string = self.getUniqueId()

        return coeffs
コード例 #5
0
    def setup(self,
              function_name,
              N: int,
              lambda_max_real: float = None,
              lambda_max_imag: float = None):
        """
        Setup coefficients for Cauchy contour integral coefficients
        using an ellipse with height given by lambda_max_imag
        and width given by lambda_max_real
        See doc/rexi/rexi_wit_laplace for details

        Args:
            N (int):
                Number of points on Cauchy contour.

        """

        self.alphas = []
        self.betas = []
        self.function_name = function_name
        self.N = N
        gamma = lambda_max_imag
        delta = lambda_max_real
        r = np.sqrt((1 - delta / gamma) / (1 + delta / gamma))
        d = r + (1.0 / r)
        self.fun = Functions(function_name, efloat_mode=self.efloat_mode)

        #print("Setting up ellipse:")
        #print("gamma: ", gamma)
        #print("delta: ", delta)
        #print("r:     ", r)

        if lambda_max_real == None or lambda_max_imag == None:
            raise Exception(
                "ELREXI: please provide max imag and real values of contour")

        c1 = (gamma * self.efloat.i / d)
        c2 = -(gamma / d)
        for j in range(N):
            theta_j = self.efloat.pi2 * (j + self.efloat.to(0.5)) / N

            # sampling position of support point
            sn = c1 * (r * self.efloat.exp(self.efloat.i * theta_j) +
                       (1.0 / r) * self.efloat.exp(-self.efloat.i * theta_j))

            #metric term
            sn_prime = c2 * (
                r * self.efloat.exp(self.efloat.i * theta_j) -
                (1.0 / r) * self.efloat.exp(-self.efloat.i * theta_j))

            self.betas.append(-self.efloat.i * self.fun.eval(sn) * sn_prime /
                              N)
            self.alphas.append(sn)

        coeffs = REXICoefficients()
        coeffs.alphas = self.alphas[:]
        coeffs.betas = self.betas[:]
        coeffs.gamma = 0
        coeffs.function_name = self.function_name

        self.unique_id_string = ""
        self.unique_id_string += self.function_name
        self.unique_id_string += "_N" + str(self.N)
        self.unique_id_string += "_im" + str(self.efloat.re(lambda_max_imag))
        self.unique_id_string += "_re" + str(self.efloat.re(lambda_max_real))

        coeffs.unique_id_string = self.getUniqueId()

        return coeffs
コード例 #6
0
ファイル: TREXI.py プロジェクト: Kevin2599/sweet
    def setup(
            self,
            # gaussian approximation of phi function
            M=None,  # Number of basis functions
            h=None,  # spacing of basisfunctions
            test_min=None,  # Test range
            test_max=None,
            function_name="phi0",  # function to approximate

            # parameters which are specific to basis_function_name = "gaussianorig"
        ratgauss_N=None,
            ratgauss_basis_function_spacing=1.0,
            ratgauss_basis_function_rat_shift=None,
            reduce_to_half=False,
            floatmode=None):
        self.M = M
        self.h = h

        self.test_min = test_min
        self.test_max = test_max

        self.function_name = function_name

        self.ratgauss_N = ratgauss_N
        self.ratgauss_basis_function_spacing = ratgauss_basis_function_spacing
        self.ratgauss_basis_function_rat_shift = ratgauss_basis_function_rat_shift

        self.reduce_to_half = reduce_to_half

        if self.function_name == "phi0":
            self.setup_rexi_gaussianorig_phi0(floatmode=floatmode)

            # setup range of approximation interval
            self.test_max = self.h * self.M - self.efloat.pi
            self.test_min = -self.test_max

            #
            # \return \f$ cos(x) + i*sin(x) \f$
            #
            def eval_fun(i_x):
                return self.efloat.re(self.efloat.exp(self.efloat.i * i_x))

            self.eval_fun = eval_fun

            def eval_exp(i_x, i_u0):
                return self.efloat.re(
                    self.efloat.exp(self.efloat.i * i_x) * i_u0)

            self.eval_exp = eval_exp

            #
            # \return \f$ cos(x) + i*sin(x) \f$
            #
            def eval_fun_cplx(i_x):
                return self.efloat.exp(self.efloat.i * i_x)

            self.eval_fun_cplx = eval_fun_cplx

            def eval_exp_cplx(i_x, i_u0):
                return self.efloat.exp(self.efloat.i * i_x) * i_u0

            self.eval_exp_cplx = eval_exp_cplx

        else:
            raise Exception("TODO")

        self.unique_id_string = ""
        self.unique_id_string += "_" + function_name
        self.unique_id_string += "_" + str(M)
        self.unique_id_string += "_" + str(h)

        coeffs = REXICoefficients()
        coeffs.function_name = function_name
        coeffs.efloat = self.efloat
        coeffs.alphas = self.alpha
        coeffs.betas = self.beta
        coeffs.gamma = 0

        coeffs.unique_id_string = self.getUniqueId()

        return coeffs