コード例 #1
0
ファイル: quad.py プロジェクト: memmett/PyIPM
    def setup(self, L, U, N, discontinuities=None, **kwargs):

        super(GaussQuad, self).setup(L, U, N, **kwargs)

        k = self.k
        L = self.L
        U = self.U
        N = self.N

        if k:
            # compute quad weights and points
            if self.qtype == 'GaussLegendre':
                from scipy.special.orthogonal import p_roots
                xi, w = p_roots(k)
            elif self.qtype == 'ClenshawCurtis':
                import nodes
                xi = np.asarray(map(float, nodes.clenshaw_curtis_nodes(k-1)))
                w  = np.asarray(map(float, nodes.clenshaw_curtis_weights(k-1)))

            # compute cell edges and adjust if necessary
            edges = np.linspace(L, U, N+1)
            jumps = getattr(self, 'discontinuities', discontinuities)
            if self.adjust and jumps:
                edges = adjust(edges, jumps)

            # compute quad weights and points
            x = np.zeros(k*N)
            P = np.zeros(k*N)

            for i in range(N):
                dx2 = 0.5 * (edges[i+1] - edges[i])
                for l in range(k):
                    x[i*k+l] = edges[i] + dx2 * (xi[l] + 1.0)
                    P[i*k+l] = dx2 * w[l]

            self.P = P
            self.x = x

        else:

            # compute quad weights and points
            if self.qtype == 'GaussLegendre':
                from scipy.special.orthogonal import p_roots
                xi, w = p_roots(N)
            elif self.qtype == 'ClenshawCurtis':
                import nodes
                xi = np.asarray(map(float, nodes.clenshaw_curtis_nodes(N-1)))
                w  = np.asarray(map(float, nodes.clenshaw_curtis_weights(N-1)))

            self.P = w * (U - L)/2.0
            self.x = (U + L)/2 + (U - L)/2 * xi
コード例 #2
0
ファイル: clark.py プロジェクト: memmett/PyIPM
    def __init__(self, k=None, qtype='GaussLegendre'):

        if k:
            if qtype == 'GaussLegendre':
                name = 'GENClarkGL(' + str(k) + ')'
                from scipy.special.orthogonal import p_roots
                self.xi, self.w = p_roots(k)
            elif qtype == 'ClenshawCurtis':
                name = 'GENClarkCC(' + str(k) + ')'
                import nodes
                self.xi = np.asarray(map(float, nodes.clenshaw_curtis_nodes(k-1)))
                self.w  = np.asarray(map(float, nodes.clenshaw_curtis_weights(k-1)))
        else:
            name = 'GENClarkQP'

        self.k = k
        self.name = name