Example #1
0
    def __initializePoints(self, P_arrays):
        """ Rearrange the list of surfaces into a single vector of unique points 

        Input

        P_arrays: list of ndarrays (nu,nv,3)
            Each element of the list is an nu x nv array of x-y-z coordinates

        """

        self.P = numpy.zeros((self.nP, 3), order='F')
        for k in range(self.nsurf):
            nu = P_arrays[k].shape[0]
            nv = P_arrays[k].shape[1]
            PUBSlib.populatep(self.nP, nu, nv, k + 1, self.nsurf, self.nedge,
                              self.ngroup, self.nvert, self.surf_vert,
                              self.surf_edge, self.edge_group, self.group_n,
                              self.surf_index_P, self.edge_index_P,
                              P_arrays[k], self.P)
        PUBSlib.avgboundaries(self.nP, self.nedge, self.ngroup, self.nvert,
                              self.edge_group, self.group_n, self.vert_count,
                              self.edge_count, self.edge_index_P, self.P)
        self.vert_symm, self.edge_symm = PUBSlib.determinesymm(
            self.symmPlane + 1, 1e-10, 1e-8, self.nP, self.nedge, self.ngroup,
            self.nvert, self.edge_group, self.group_n, self.P)
        self.P = numpy.hstack([self.P, numpy.zeros((self.nP, 3), order='F')])
Example #2
0
    def evaluateBases(self, surf, u, v, uder=0, vder=0):
        """ Return matrix that multiples with C to give n points 
        corresponding to (s,u,v).

        Input

        surf: integer(n)
            0-based surface index

        u: double(n)
            Parametric coordinate [0,1]

        v: double(n)
            Parametric coordinate [0,1]

        Output

        B: double(n,nC)
            Matrix whose rows correspond to the requested points

        """

        nB = PUBSlib.evaluatebnnz(surf.shape[0], self.nsurf, self.nedge,
                                  self.ngroup, self.surf_edge, self.edge_group,
                                  self.group_k, surf + 1)
        Ba, Bi, Bj = PUBSlib.evaluatebases(
            uder, vder, surf.shape[0], nB, self.nD, self.nsurf, self.nedge,
            self.ngroup, self.nvert, self.surf_vert, self.surf_edge,
            self.edge_group, self.group_k, self.group_m, self.group_d,
            self.surf_index_C, self.edge_index_C, self.knot_index, surf + 1, u,
            v)
        B = scipy.sparse.csc_matrix((Ba, (Bi, Bj)),
                                    shape=(surf.shape[0], self.nC))
        return B
Example #3
0
    def evaluateBases(self, surf, u, v, uder=0, vder=0):
        """ Return matrix that multiples with C to give n points 
        corresponding to (s,u,v).

        Input

        surf: integer(n)
            0-based surface index

        u: double(n)
            Parametric coordinate [0,1]

        v: double(n)
            Parametric coordinate [0,1]

        Output

        B: double(n,nC)
            Matrix whose rows correspond to the requested points

        """

        nB = PUBSlib.evaluatebnnz(surf.shape[0], self.nsurf, self.nedge, self.ngroup, self.surf_edge, self.edge_group, self.group_k, surf+1)
        Ba, Bi, Bj = PUBSlib.evaluatebases(uder, vder, surf.shape[0], nB, self.nD, self.nsurf, self.nedge, self.ngroup, self.nvert, self.surf_vert, self.surf_edge, self.edge_group, self.group_k, self.group_m, self.group_d, self.surf_index_C, self.edge_index_C, self.knot_index, surf+1, u, v)
        B = scipy.sparse.csc_matrix((Ba,(Bi,Bj)),shape=(surf.shape[0],self.nC))
        return B
Example #4
0
    def evaluateProjection(self, P0, surfs=None, Q=None):
        """ Computes projections from P0 to the supplied list of surfaces
            and returns the parametric coordinates of the closest point

        * Input *
        P0: double(n,3)
            List of n points to project onto the B-spline surface model
        surfs: integer(n)
            List of surfaces (0-based) to check
        Q: double(n,3)
            Optional list of directions along which to evaluate projection

        * Output *
        surf: integer(n)
            0-based list of surfaces of the projected points
        u: double(n)
            List of parametric coordinates in u of the projected points
        v: double(n)
            List of parametric coordinates in v of the projected points

        """

        if surfs==None:
            surfs = numpy.linspace(1,self.nsurf,self.nsurf)
        else:
            surfs = numpy.array(surfs) + 1
        if Q==None:
            surf,u,v = PUBSlib.evaluateprojection(P0.shape[0],surfs.shape[0],self.nD,self.nT,self.nC,self.nP,self.nsurf,self.nedge,self.ngroup,self.nvert,surfs,self.surf_vert,self.surf_edge,self.edge_group,self.group_k,self.group_m,self.group_n,self.group_d,self.surf_index_P,self.edge_index_P,self.surf_index_C,self.edge_index_C,self.knot_index,self.T,self.C[:,:3],self.P[:,:3],P0)
        else:
            surf,u,v = PUBSlib.evaluatepjtnalongq(P0.shape[0],surfs.shape[0],self.nD,self.nT,self.nC,self.nP,self.nsurf,self.nedge,self.ngroup,self.nvert,surfs,self.surf_vert,self.surf_edge,self.edge_group,self.group_k,self.group_m,self.group_n,self.group_d,self.surf_index_P,self.edge_index_P,self.surf_index_C,self.edge_index_C,self.knot_index,self.T,self.C[:,:3],self.P[:,:3],P0,Q)
        surf -= 1
        return surf,u,v
Example #5
0
    def __initializeTopology(self, P_arrays, ratio):
        """ Determine connectivities - mappings from surfaces to vertices and edges; from edges to groups
            Initialize order (k), # control points (m), and # points (n) for each edge 

        Input

        P_arrays: list of doubles(nu,nv,3)
            Each element of the list is an nu x nv array of x-y-z coordinates

        """

        self.nsurf = len(P_arrays)
        Ps = numpy.zeros((self.nsurf, 3, 3, 3), order='F')
        for k in range(self.nsurf):
            nu = P_arrays[k].shape[0]
            nv = P_arrays[k].shape[1]
            for i in range(2):
                for j in range(2):
                    Ps[k, -i, -j] = P_arrays[k][-i, -j]
            for i in range(2):
                Ps[k, -i,
                   1] += 0.5 * P_arrays[k][-i,
                                           int(numpy.ceil((nv - 1) / 2.0))]
                Ps[k, -i,
                   1] += 0.5 * P_arrays[k][-i,
                                           int(numpy.floor((nv - 1) / 2.0))]
            for j in range(2):
                Ps[k, 1,
                   -j] += 0.5 * P_arrays[k][int(numpy.ceil(
                       (nu - 1) / 2.0)), -j]
                Ps[k, 1,
                   -j] += 0.5 * P_arrays[k][int(numpy.floor(
                       (nu - 1) / 2.0)), -j]

        self.nvert, self.nedge, self.surf_vert, self.surf_edge = PUBSlib.initializeconnectivities(
            self.nsurf, 1e-13, 1e-5, Ps)
        self.vert_count, self.edge_count = PUBSlib.initializevecounts(
            self.nsurf, self.nvert, self.nedge, self.surf_vert, self.surf_edge)
        self.ngroup, self.edge_group = PUBSlib.initializegroups(
            self.nsurf, self.nedge, self.surf_edge)
        self.surf_c1 = numpy.zeros((self.nsurf, 3, 3), bool, order='F')
        self.edge_c1 = numpy.zeros((self.nedge, 2), bool, order='F')

        ns = numpy.zeros((self.nsurf, 2), order='F')
        for k in range(self.nsurf):
            ns[k, :] = P_arrays[k].shape[0:2]
        k = 4
        self.group_k, self.group_m, self.group_n = PUBSlib.initializekmn(
            k, self.nsurf, self.nedge, self.ngroup, ratio, ns, self.surf_edge,
            self.edge_group)

        if self.printInfo:
            print '# Surfaces =', self.nsurf
            print '# Vertices =', self.nvert
            print '# Edges =', self.nedge
            print '# Groups =', self.ngroup
Example #6
0
    def computeCindices(self):
        """ Compute where each vertex, edge, and surface is located in the global list of Cs """

        self.surf_index_C = PUBSlib.computesurfindices(self.nsurf, self.nedge, self.ngroup, self.surf_edge, self.edge_group, self.group_m)
        self.edge_index_C = PUBSlib.computeedgeindices(self.nedge, self.ngroup, self.edge_group, self.group_m)
        self.nC = self.nvert
        self.nC += self.edge_index_C[-1,1]
        self.nC += self.surf_index_C[-1,1]

        if self.printInfo:
            print '# Control points =',self.nC
Example #7
0
    def evaluateProjection(self, P0, surfs=None, Q=None):
        """ Computes projections from P0 to the supplied list of surfaces
            and returns the parametric coordinates of the closest point

        Input

        P0: double(n,3)
            List of n points to project onto the B-spline surface model

        surfs: integer(n)
            List of surfaces (0-based) to check

        Q: double(n,3)
            Optional list of directions along which to evaluate projection

        Output

        surf: integer(n)
            0-based list of surfaces of the projected points

        u: double(n)
            List of parametric coordinates in u of the projected points
            
        v: double(n)
            List of parametric coordinates in v of the projected points

        """

        if surfs is None:
            surfs = numpy.linspace(1, self.nsurf, self.nsurf)
        else:
            surfs = numpy.array(surfs) + 1
        if Q is None:
            surf, u, v = PUBSlib.evaluateprojection(
                P0.shape[0], surfs.shape[0], self.nD, self.nT, self.nC,
                self.nP, self.nsurf, self.nedge, self.ngroup, self.nvert,
                surfs, self.surf_vert, self.surf_edge, self.edge_group,
                self.group_k, self.group_m, self.group_n, self.group_d,
                self.surf_index_P, self.edge_index_P, self.surf_index_C,
                self.edge_index_C, self.knot_index, self.T, self.C[:, :3],
                self.P[:, :3], P0)
        else:
            surf, u, v = PUBSlib.evaluatepjtnalongq(
                P0.shape[0], surfs.shape[0], self.nD, self.nT, self.nC,
                self.nP, self.nsurf, self.nedge, self.ngroup, self.nvert,
                surfs, self.surf_vert, self.surf_edge, self.edge_group,
                self.group_k, self.group_m, self.group_n, self.group_d,
                self.surf_index_P, self.edge_index_P, self.surf_index_C,
                self.edge_index_C, self.knot_index, self.T, self.C[:, :3],
                self.P[:, :3], P0, Q)
        surf -= 1
        return surf, u, v
Example #8
0
    def computeQindices(self):
        """ Compute where each vertex, edge, and surface is located in the global list of Qs """

        self.surf_index_Q = PUBSlib.computesurfindices(self.nsurf, self.nedge, self.ngroup, self.surf_edge, self.edge_group, self.group_m)
        self.edge_index_Q = PUBSlib.computeedgeindicesq(self.nsurf, self.nedge, self.ngroup, self.surf_edge, self.edge_group, self.group_m, self.surf_c1)
        self.vert_index_Q = PUBSlib.computevertindicesq(self.nsurf, self.nedge, self.nvert, self.surf_vert, self.surf_edge, self.surf_c1, self.edge_c1)
        self.nQ = 0
        self.nQ += max(self.vert_index_Q)
        self.nQ += max(self.edge_index_Q[:,1])
        self.nQ += self.surf_index_Q[-1,1]

        self.Q = numpy.zeros((self.nQ,self.nvar),order='F')  
        if self.printInfo:
            print '# Degrees of freedom =',self.nQ
Example #9
0
    def computePindices(self):
        """ Compute where each vertex, edge, and surface is located in the global list of Ps """

        self.surf_index_P = PUBSlib.computesurfindices(self.nsurf, self.nedge, self.ngroup, self.surf_edge, self.edge_group, self.group_n)
        self.edge_index_P = PUBSlib.computeedgeindices(self.nedge, self.ngroup, self.edge_group, self.group_n)
        self.nT = 0
        self.nT += self.edge_index_P[-1,1]
        self.nT += 2*self.surf_index_P[-1,1]
        self.nP = self.nvert
        self.nP += self.edge_index_P[-1,1]
        self.nP += self.surf_index_P[-1,1]

        if self.printInfo:
            print '# Points =',self.nP
Example #10
0
    def computeDindices(self):
        """ Compute where each knot vector is located in the global list of knots """

        self.nD = 0
        for i in range(self.ngroup):
            self.nD += self.group_m[i] + self.group_k[i]
        self.knot_index = PUBSlib.computeknotindices(self.ngroup, self.group_k, self.group_m)
Example #11
0
    def evaluatePoint(self,surf,u,v,uder=0,vder=0):
        """ Return point or 1st or 2nd parametric derivative 

        Input

        surf: integer
            0-based surface index

        u: double
            Parametric coordinate [0,1]

        v: double
            Parametric coordinate [0,1]

        uder: integer
            Order of the desired derivative in the u direction

        vder: integer
            Order of the desired derivative in the v direction

        Output

        return: double(3)
            x-y-z values of the point or derivative requested

        """

        ugroup = self.edge_group[abs(self.surf_edge[surf,0,0])-1]
        vgroup = self.edge_group[abs(self.surf_edge[surf,1,0])-1]
        ku = self.group_k[ugroup-1]
        kv = self.group_k[vgroup-1]   
        mu = self.group_m[ugroup-1]
        mv = self.group_m[vgroup-1]
        P = PUBSlib.evaluatepoint(surf+1,uder,vder,ku,kv,mu,mv,self.nvar,self.nD,self.nC,self.nsurf,self.nedge,self.ngroup,self.nvert,u,v,self.surf_vert,self.surf_edge,self.edge_group,self.group_d,self.surf_index_C,self.edge_index_C,self.knot_index,self.C)
        return P
Example #12
0
    def __initializePoints(self, P_arrays):
        """ Rearrange the list of surfaces into a single vector of unique points 

        * Input *
        P_arrays: list of ndarrays (nu,nv,3)
            Each element of the list is an nu x nv array of x-y-z coordinates

        """

        self.P = numpy.zeros((self.nP,3),order='F')
        for k in range(self.nsurf):
            nu = P_arrays[k].shape[0]
            nv = P_arrays[k].shape[1]
            PUBSlib.populatep(self.nP, nu, nv, k+1, self.nsurf, self.nedge, self.ngroup, self.nvert, self.surf_vert, self.surf_edge, self.edge_group, self.group_n, self.surf_index_P, self.edge_index_P, P_arrays[k], self.P)
        PUBSlib.avgboundaries(self.nP, self.nedge, self.ngroup, self.nvert, self.edge_group, self.group_n, self.vert_count, self.edge_count, self.edge_index_P, self.P)
        self.vert_symm, self.edge_symm = PUBSlib.determinesymm(self.symmPlane+1, 1e-10, 1e-8, self.nP, self.nedge, self.ngroup, self.nvert, self.edge_group, self.group_n, self.P)
        self.P = numpy.hstack([self.P,numpy.zeros((self.nP,3),order='F')])
Example #13
0
    def computeCindices(self):
        """ Compute where each vertex, edge, and surface is located in the global list of Cs """

        self.surf_index_C = PUBSlib.computesurfindices(self.nsurf, self.nedge,
                                                       self.ngroup,
                                                       self.surf_edge,
                                                       self.edge_group,
                                                       self.group_m)
        self.edge_index_C = PUBSlib.computeedgeindices(self.nedge, self.ngroup,
                                                       self.edge_group,
                                                       self.group_m)
        self.nC = self.nvert
        self.nC += self.edge_index_C[-1, 1]
        self.nC += self.surf_index_C[-1, 1]

        if self.printInfo:
            print '# Control points =', self.nC
Example #14
0
    def computeDindices(self):
        """ Compute where each knot vector is located in the global list of knots """

        self.nD = 0
        for i in range(self.ngroup):
            self.nD += self.group_m[i] + self.group_k[i]
        self.knot_index = PUBSlib.computeknotindices(self.ngroup, self.group_k,
                                                     self.group_m)
Example #15
0
    def computeParameters(self):
        """ Compute the global list of parameter values """

        self.T = PUBSlib.computeparameters(self.nT, self.nD, self.nsurf,
                                           self.nedge, self.ngroup,
                                           self.surf_edge, self.edge_group,
                                           self.group_k, self.group_m,
                                           self.group_n, self.group_d,
                                           self.knot_index)
Example #16
0
    def getIndex(self, surf, u, v, quantity):
        """ Return the index of a Q, C, or P entry in the global list 

        Input

        surf: integer
            0-based surface index

        u: double
            Parametric coordinate [0,1]

        v: double
            Parametric coordinate [0,1]

        quantity: integer
            0 for P; 1 for C; 2 for Q

        Output

        return: integer
            0-based index in the Q, C, or P vector corresponding to (surf,u,v)

        """

        ugroup = self.edge_group[abs(self.surf_edge[surf, 0, 0]) - 1]
        vgroup = self.edge_group[abs(self.surf_edge[surf, 1, 0]) - 1]
        if quantity == 0:
            surf_index = self.surf_index_P
            edge_index = self.edge_index_P
            nvert = self.nvert
            group_m = self.group_n
        elif quantity == 1:
            surf_index = self.surf_index_C
            edge_index = self.edge_index_C
            nvert = self.nvert
            group_m = self.group_m
        elif quantity == 2:
            surf_index = self.surf_index_Q
            edge_index = self.edge_index_Q
            nvert = max(self.vert_index_Q)
            group_m = self.group_m
        mu = group_m[ugroup - 1]
        mv = group_m[vgroup - 1]
        if u < 0:
            u += mu
        if v < 0:
            v += mv
        if (u == 0 or u == mu - 1) and (v == 0
                                        or v == mv - 1) and quantity == 2:
            vert = self.surf_vert[surf,
                                  int(u / (mu - 1)),
                                  int(v / (mv - 1))] - 1
            return self.vert_index_Q[vert] - 1
        else:
            return PUBSlib.getindex(surf + 1, u + 1, v + 1, mu, mv, self.nsurf,
                                    self.nedge, nvert, self.surf_vert,
                                    self.surf_edge, surf_index, edge_index) - 1
Example #17
0
    def __initializeTopology(self, P_arrays, ratio):
        """ Determine connectivities - mappings from surfaces to vertices and edges; from edges to groups
            Initialize order (k), # control points (m), and # points (n) for each edge 

        Input

        P_arrays: list of doubles(nu,nv,3)
            Each element of the list is an nu x nv array of x-y-z coordinates

        """

        self.nsurf = len(P_arrays)
        Ps = numpy.zeros((self.nsurf,3,3,3),order='F')
        for k in range(self.nsurf):
            nu = P_arrays[k].shape[0]
            nv = P_arrays[k].shape[1]
            for i in range(2):
                for j in range(2):
                    Ps[k,-i,-j] = P_arrays[k][-i,-j]
            for i in range(2):
                Ps[k,-i,1] += 0.5*P_arrays[k][-i,int(numpy.ceil((nv-1)/2.0))]
                Ps[k,-i,1] += 0.5*P_arrays[k][-i,int(numpy.floor((nv-1)/2.0))]
            for j in range(2):
                Ps[k,1,-j] += 0.5*P_arrays[k][int(numpy.ceil((nu-1)/2.0)),-j]
                Ps[k,1,-j] += 0.5*P_arrays[k][int(numpy.floor((nu-1)/2.0)),-j]

        self.nvert,self.nedge,self.surf_vert,self.surf_edge = PUBSlib.initializeconnectivities(self.nsurf,1e-13,1e-5,Ps)
        self.vert_count,self.edge_count = PUBSlib.initializevecounts(self.nsurf,self.nvert,self.nedge,self.surf_vert,self.surf_edge)
        self.ngroup,self.edge_group = PUBSlib.initializegroups(self.nsurf,self.nedge,self.surf_edge)
        self.surf_c1 = numpy.zeros((self.nsurf,3,3),bool,order='F')
        self.edge_c1 = numpy.zeros((self.nedge,2),bool,order='F')

        ns = numpy.zeros((self.nsurf,2),order='F')
        for k in range(self.nsurf):
            ns[k,:] = P_arrays[k].shape[0:2]
        k = 4
        self.group_k, self.group_m, self.group_n = PUBSlib.initializekmn(k, self.nsurf, self.nedge, self.ngroup, ratio, ns, self.surf_edge, self.edge_group)

        if self.printInfo:
            print '# Surfaces =',self.nsurf
            print '# Vertices =',self.nvert
            print '# Edges =',self.nedge
            print '# Groups =',self.ngroup
Example #18
0
    def computePindices(self):
        """ Compute where each vertex, edge, and surface is located in the global list of Ps """

        self.surf_index_P = PUBSlib.computesurfindices(self.nsurf, self.nedge,
                                                       self.ngroup,
                                                       self.surf_edge,
                                                       self.edge_group,
                                                       self.group_n)
        self.edge_index_P = PUBSlib.computeedgeindices(self.nedge, self.ngroup,
                                                       self.edge_group,
                                                       self.group_n)
        self.nT = 0
        self.nT += self.edge_index_P[-1, 1]
        self.nT += 2 * self.surf_index_P[-1, 1]
        self.nP = self.nvert
        self.nP += self.edge_index_P[-1, 1]
        self.nP += self.surf_index_P[-1, 1]

        if self.printInfo:
            print '# Points =', self.nP
Example #19
0
    def exportPstr(self, surfs=None):
        if surfs is None:
            surfs = range(self.nsurf)

        Ps = []
        for s in surfs:
            nu, nv = self.Nuv[s,:]
            P = PUBSlib.inflatevector(nu, nv, self.nvar, nu*nv, self.P0[self.Np0[s]:self.Np0[s+1],:])
            Ps.append(P)

        return Ps
Example #20
0
    def exportPstr(self, surfs=None):
        if surfs is None:
            surfs = range(self.nsurf)

        Ps = []
        for s in surfs:
            nu, nv = self.Nuv[s, :]
            P = PUBSlib.inflatevector(nu, nv, self.nvar, nu * nv,
                                      self.P0[self.Np0[s]:self.Np0[s + 1], :])
            Ps.append(P)

        return Ps
Example #21
0
    def computeJacobian(self):
        """ Compute the global Jacobian """

        self.nJ = PUBSlib.computejnnz(self.nsurf,self.nedge,self.ngroup,self.nvert,self.surf_edge,self.edge_group,self.group_k,self.group_n,self.edge_count)
        Ja, Ji, Jj = PUBSlib.computejacobian(self.nJ, self.nT, self.nD, self.nsurf, self.nedge, self.ngroup, self.nvert, self.surf_vert, self.surf_edge, self.edge_group, self.group_k, self.group_m, self.group_n, self.group_d, self.surf_index_P, self.edge_index_P, self.surf_index_C, self.edge_index_C, self.knot_index, self.edge_count, self.T)
        self.J = scipy.sparse.csc_matrix((Ja,(Ji,Jj)))

        self.Nuv = PUBSlib.getsurfacesizes(self.nsurf, self.nedge, self.ngroup, self.surf_edge, self.edge_group, self.group_n)
        self.Np0 = numpy.zeros(self.nsurf+1)
        for s in range(self.nsurf+1):
            self.Np0[s] = int(sum(self.Nuv[:s,0]*self.Nuv[:s,1]))
        surf = numpy.zeros(self.Np0[-1],int)
        u = numpy.zeros(self.Np0[-1])
        v = numpy.zeros(self.Np0[-1])
        for s in range(self.nsurf):
            T = PUBSlib.getsurfacet(s+1, self.Nuv[s,0], self.Nuv[s,1], self.nT, self.nsurf, self.nedge, self.surf_edge, self.surf_index_P, self.edge_index_P, self.T)
            surf[self.Np0[s]:self.Np0[s+1]] = s
            u[self.Np0[s]:self.Np0[s+1]] = T[:,:,0].flatten(order='F')
            v[self.Np0[s]:self.Np0[s+1]] = T[:,:,1].flatten(order='F')
        self.J0 = self.evaluateBases(surf, u, v, 0, 0)
        self.Ju = self.evaluateBases(surf, u, v, 1, 0)
        self.Jv = self.evaluateBases(surf, u, v, 0, 1)

        self.nM = PUBSlib.computemnnz(self.nsurf,self.nedge,self.ngroup,self.nvert,self.surf_edge,self.edge_group,self.group_m,self.surf_index_C, self.edge_index_Q, self.vert_index_Q, self.edge_count, self.surf_c1, self.edge_c1)
        Ma, Mi, Mj = PUBSlib.computedofmapping(self.nM,self.nsurf,self.nedge,self.ngroup,self.nvert,self.surf_vert,self.surf_edge,self.edge_group,self.group_m,self.surf_index_C,self.edge_index_C,self.edge_index_Q,self.vert_index_Q, self.edge_count,self.surf_c1,self.edge_c1)
        self.M = scipy.sparse.csc_matrix((Ma,(Mi,Mj)))
        self.JM = self.J.dot(self.M)

        if self.printInfo:
            print '# Jacobian non-zeros =',self.JM.nnz
Example #22
0
    def getIndex(self, surf, u, v, quantity):
        """ Return the index of a Q, C, or P entry in the global list 

        Input

        surf: integer
            0-based surface index

        u: double
            Parametric coordinate [0,1]

        v: double
            Parametric coordinate [0,1]

        quantity: integer
            0 for P; 1 for C; 2 for Q

        Output

        return: integer
            0-based index in the Q, C, or P vector corresponding to (surf,u,v)

        """

        ugroup = self.edge_group[abs(self.surf_edge[surf,0,0])-1]
        vgroup = self.edge_group[abs(self.surf_edge[surf,1,0])-1]
        if quantity==0:
            surf_index = self.surf_index_P
            edge_index = self.edge_index_P
            nvert = self.nvert
            group_m = self.group_n
        elif quantity==1:
            surf_index = self.surf_index_C
            edge_index = self.edge_index_C
            nvert = self.nvert
            group_m = self.group_m
        elif quantity==2:
            surf_index = self.surf_index_Q
            edge_index = self.edge_index_Q
            nvert = max(self.vert_index_Q)
            group_m = self.group_m            
        mu = group_m[ugroup-1]
        mv = group_m[vgroup-1]
        if u < 0:
            u += mu
        if v < 0:
            v += mv
        if (u==0 or u==mu-1) and (v==0 or v==mv-1) and quantity==2:
            vert = self.surf_vert[surf,int(u/(mu-1)),int(v/(mv-1))] - 1
            return self.vert_index_Q[vert] - 1
        else:
            return PUBSlib.getindex(surf+1,u+1,v+1,mu,mv,self.nsurf,self.nedge,nvert,self.surf_vert,self.surf_edge,surf_index,edge_index) - 1
Example #23
0
    def computeQindices(self):
        """ Compute where each vertex, edge, and surface is located in the global list of Qs """

        self.surf_index_Q = PUBSlib.computesurfindices(self.nsurf, self.nedge,
                                                       self.ngroup,
                                                       self.surf_edge,
                                                       self.edge_group,
                                                       self.group_m)
        self.edge_index_Q = PUBSlib.computeedgeindicesq(
            self.nsurf, self.nedge, self.ngroup, self.surf_edge,
            self.edge_group, self.group_m, self.surf_c1)
        self.vert_index_Q = PUBSlib.computevertindicesq(
            self.nsurf, self.nedge, self.nvert, self.surf_vert, self.surf_edge,
            self.surf_c1, self.edge_c1)
        self.nQ = 0
        self.nQ += max(self.vert_index_Q)
        self.nQ += max(self.edge_index_Q[:, 1])
        self.nQ += self.surf_index_Q[-1, 1]

        self.Q = numpy.zeros((self.nQ, self.nvar), order='F')
        if self.printInfo:
            print '# Degrees of freedom =', self.nQ
Example #24
0
    def computeTopology(self):
        nmem = self.nmem
        oml0 = self.geometry.oml0

        Ps = numpy.zeros((oml0.nsurf,3,3,3),order='F')
        for s in range(oml0.nsurf):
            for i in range(3):
                for j in range(3):
                    Ps[s,i,j] = oml0.evaluatePoint(s,i/2.0,j/2.0)[:3]
        nvertS,ngroupS,surf_vert,surf_group = PUBSlib.initializeconnectivities(oml0.nsurf,1e-13,1e-5,Ps)
        nvertM,ngroupM,mem_vert,mem_group = PSMlib.computemembertopology(nmem, self.membersInt, self.membersFlt)
        mem_group[:,:,:] += ngroupS

        self.surf_group = surf_group
        self.mem_group = mem_group
        self.ngroupS = ngroupS
        self.ngroupM = ngroupM
Example #25
0
    def computeJacobian(self):
        """ Compute the global Jacobian """

        self.nJ = PUBSlib.computejnnz(self.nsurf, self.nedge, self.ngroup,
                                      self.nvert, self.surf_edge,
                                      self.edge_group, self.group_k,
                                      self.group_n, self.edge_count)
        Ja, Ji, Jj = PUBSlib.computejacobian(
            self.nJ, self.nT, self.nD, self.nsurf, self.nedge, self.ngroup,
            self.nvert, self.surf_vert, self.surf_edge, self.edge_group,
            self.group_k, self.group_m, self.group_n, self.group_d,
            self.surf_index_P, self.edge_index_P, self.surf_index_C,
            self.edge_index_C, self.knot_index, self.edge_count, self.T)
        self.J = scipy.sparse.csc_matrix((Ja, (Ji, Jj)))

        self.Nuv = PUBSlib.getsurfacesizes(self.nsurf, self.nedge, self.ngroup,
                                           self.surf_edge, self.edge_group,
                                           self.group_n)
        self.Np0 = numpy.zeros(self.nsurf + 1)
        for s in range(self.nsurf + 1):
            self.Np0[s] = int(sum(self.Nuv[:s, 0] * self.Nuv[:s, 1]))
        surf = numpy.zeros(self.Np0[-1], int)
        u = numpy.zeros(self.Np0[-1])
        v = numpy.zeros(self.Np0[-1])
        for s in range(self.nsurf):
            T = PUBSlib.getsurfacet(s + 1, self.Nuv[s, 0], self.Nuv[s, 1],
                                    self.nT, self.nsurf, self.nedge,
                                    self.surf_edge, self.surf_index_P,
                                    self.edge_index_P, self.T)
            surf[self.Np0[s]:self.Np0[s + 1]] = s
            u[self.Np0[s]:self.Np0[s + 1]] = T[:, :, 0].flatten(order='F')
            v[self.Np0[s]:self.Np0[s + 1]] = T[:, :, 1].flatten(order='F')
        self.J0 = self.evaluateBases(surf, u, v, 0, 0)
        self.Ju = self.evaluateBases(surf, u, v, 1, 0)
        self.Jv = self.evaluateBases(surf, u, v, 0, 1)

        self.nM = PUBSlib.computemnnz(self.nsurf, self.nedge, self.ngroup,
                                      self.nvert, self.surf_edge,
                                      self.edge_group, self.group_m,
                                      self.surf_index_C, self.edge_index_Q,
                                      self.vert_index_Q, self.edge_count,
                                      self.surf_c1, self.edge_c1)
        Ma, Mi, Mj = PUBSlib.computedofmapping(
            self.nM, self.nsurf, self.nedge, self.ngroup, self.nvert,
            self.surf_vert, self.surf_edge, self.edge_group, self.group_m,
            self.surf_index_C, self.edge_index_C, self.edge_index_Q,
            self.vert_index_Q, self.edge_count, self.surf_c1, self.edge_c1)
        self.M = scipy.sparse.csc_matrix((Ma, (Mi, Mj)))
        self.JM = self.J.dot(self.M)

        if self.printInfo:
            print '# Jacobian non-zeros =', self.JM.nnz
Example #26
0
    def computeTopology(self):
        nmem = self.nmem
        oml0 = self.geometry.oml0

        Ps = numpy.zeros((oml0.nsurf, 3, 3, 3), order='F')
        for s in range(oml0.nsurf):
            for i in range(3):
                for j in range(3):
                    Ps[s, i, j] = oml0.evaluatePoint(s, i / 2.0, j / 2.0)[:3]
        nvertS, ngroupS, surf_vert, surf_group = PUBSlib.initializeconnectivities(
            oml0.nsurf, 1e-13, 1e-5, Ps)
        nvertM, ngroupM, mem_vert, mem_group = PSMlib.computemembertopology(
            nmem, self.membersInt, self.membersFlt)
        mem_group[:, :, :] += ngroupS

        self.surf_group = surf_group
        self.mem_group = mem_group
        self.ngroupS = ngroupS
        self.ngroupM = ngroupM
Example #27
0
    def evaluatePoint(self, surf, u, v, uder=0, vder=0):
        """ Return point or 1st or 2nd parametric derivative 

        Input

        surf: integer
            0-based surface index

        u: double
            Parametric coordinate [0,1]

        v: double
            Parametric coordinate [0,1]

        uder: integer
            Order of the desired derivative in the u direction

        vder: integer
            Order of the desired derivative in the v direction

        Output

        return: double(3)
            x-y-z values of the point or derivative requested

        """

        ugroup = self.edge_group[abs(self.surf_edge[surf, 0, 0]) - 1]
        vgroup = self.edge_group[abs(self.surf_edge[surf, 1, 0]) - 1]
        ku = self.group_k[ugroup - 1]
        kv = self.group_k[vgroup - 1]
        mu = self.group_m[ugroup - 1]
        mv = self.group_m[vgroup - 1]
        P = PUBSlib.evaluatepoint(
            surf + 1, uder, vder, ku, kv, mu, mv, self.nvar, self.nD, self.nC,
            self.nsurf, self.nedge, self.ngroup, self.nvert, u, v,
            self.surf_vert, self.surf_edge, self.edge_group, self.group_d,
            self.surf_index_C, self.edge_index_C, self.knot_index, self.C)
        return P
Example #28
0
    def meshStructure(self, members, lengths):
        oml0 = self.oml0

        nmem = len(members)
        faces = -numpy.ones((nmem,4,2),int,order='F')
        coords = numpy.zeros((nmem,4,2,2,3),order='F')
        for imem in range(nmem):
            key = members.keys()[imem]
            for icontr in range(len(members[key])):
                faces[imem,icontr,0] = self.inds[members[key][icontr][0]]
                faces[imem,icontr,1] = members[key][icontr][1]
                coords[imem,icontr,0,0,:] = members[key][icontr][2]
                coords[imem,icontr,1,0,:] = members[key][icontr][3]
                coords[imem,icontr,0,1,:] = members[key][icontr][4]
                coords[imem,icontr,1,1,:] = members[key][icontr][5]

        surfs = numpy.linspace(0,oml0.nsurf-1,oml0.nsurf)
        s = numpy.zeros(4*oml0.nsurf)
        s[0::4] = surfs
        s[1::4] = surfs
        s[2::4] = surfs
        s[3::4] = surfs
        u = numpy.zeros(4*oml0.nsurf)
        u[1::4] = 1.
        u[3::4] = 1.
        v = numpy.zeros(4*oml0.nsurf)
        v[2::4] = 1.
        v[3::4] = 1.
        quadsS = numpy.zeros((oml0.nsurf,4),order='F')
        quadsS[:,0] = 4*surfs + 0
        quadsS[:,1] = 4*surfs + 1
        quadsS[:,2] = 4*surfs + 3
        quadsS[:,3] = 4*surfs + 2
        B = oml0.evaluateBases(s,u,v)
        nodesS = B.dot(oml0.C[:,:3])
        oml0.export.write2TecQuads('john.dat',nodesS,quadsS)

        #oml0.C[:,:] = -1.0
        #for k in range(len(self.comps)):
        #    c = self.keys[k]
        #    comp = self.comps[c]
        #    for f in range(len(comp.Ks)):
        #        ni, nj = comp.Ks[f].shape
        #        for i in range(ni):
        #            for j in range(nj):
        #                surf = comp.Ks[f][i,j]
        #                mu, mv = oml0.edgeProperty(surf,1)
        #                ugroup = oml0.edge_group[abs(oml0.surf_edge[surf,0,0])-1]
        #                vgroup = oml0.edge_group[abs(oml0.surf_edge[surf,1,0])-1]
        #                mu = oml0.group_m[ugroup-1]
        #                mv = oml0.group_m[vgroup-1]
        #                for u in range(mu):
        #                    for v in range(mv):
        #                        oml0.C[oml0.getIndex(surf,u,v,1),:3] = [u/(mu-1), v/(mv-1), 0]

        oml0.C[:,:] = -1.0
        for surf in range(oml0.nsurf):
            mu, mv = oml0.edgeProperty(surf,1)
            ugroup = oml0.edge_group[abs(oml0.surf_edge[surf,0,0])-1]
            vgroup = oml0.edge_group[abs(oml0.surf_edge[surf,1,0])-1]
            mu = oml0.group_m[ugroup-1]
            mv = oml0.group_m[vgroup-1]
            for u in range(mu):
                for v in range(mv):
                    oml0.C[oml0.getIndex(surf,u,v,1),:3] = [u/(mu-1), v/(mv-1), 0]
                    print u/(mu-1), v/(mv-1)

        oml0.computePointsC()
        #oml0.export.write2TecQuads('john2.dat',nodesM,quadsM)
        oml0.write2Tec('test2')
        oml0.write2TecC('test2')

        self.computePoints()
        print oml0.C[oml0.getIndex(147,-1, 0,1),:3]
        print oml0.C[oml0.getIndex(144,-1,-1,1),:3]
        print oml0.C[oml0.getIndex( 49, 0, 0,1),:3]


        s = numpy.zeros(4*nmem)
        P = numpy.zeros((4*nmem,3),order='F')
        Q = numpy.zeros((4*nmem,3),order='F')
        w = numpy.zeros((4*nmem,4),order='F')
        mems = numpy.linspace(0,nmem-1,nmem)
        Q[:,2] = 1.
        Bs = []
        ws = []
        for icontr in range(4):
            for imem in range(nmem):
                k = faces[imem,icontr,0]
                f = faces[imem,icontr,1]
                c = self.keys[k]
                comp = self.comps[c]
                ni, nj = comp.Ks[f].shape
                for i in range(2):
                    for j in range(2):
                        u, v = coords[imem,icontr,i,j,:2]
                        ii = int(numpy.floor(u*ni))
                        jj = int(numpy.floor(v*nj))
                        s[4*imem+2*j+i] = comp.Ks[f][ii,jj]
                        P[4*imem+2*j+i,0] = u*ni - ii
                        P[4*imem+2*j+i,1] = v*nj - jj
                        w[4*imem+2*j+i,icontr] = coords[imem,icontr,i,j,2]
            surf,u,v = oml0.evaluateProjection(P, Q=Q)
            Bs.append(oml0.evaluateBases(surf, u, v))


        quadsM = numpy.zeros((nmem,4),order='F')
        quadsM[:,0] = 4*mems + 0
        quadsM[:,1] = 4*mems + 1
        quadsM[:,2] = 4*mems + 3
        quadsM[:,3] = 4*mems + 2
        nodesM = numpy.zeros((4*nmem,3),order='F')
        for icontr in range(4):
            for k in range(3):
                nodesM[:,k] += w[:,icontr] * Bs[icontr].dot(oml0.C[:,k])
            
        oml0.export.write2TecQuads('john2.dat',nodesM,quadsM)

        exit()



        Ps = numpy.zeros((oml0.nsurf,3,3,3),order='F')
        for s in range(oml0.nsurf):
            for i in range(3):
                for j in range(3):
                    Ps[s,i,j] = oml0.evaluatePoint(s,i/2.0,j/2.0)[:3]
        nvertS,ngroupS,surf_vert,surf_group = PUBSlib.initializeconnectivities(oml0.nsurf,1e-13,1e-5,Ps)

        nvertM,ngroupM,mem_vert,mem_group = PSMlib.computemembertopology(nmem, faces, coords)
        mem_group[:,:,:] += ngroupS
        ngroup = ngroupS + ngroupM

        nint = PSMlib.countfaceintersections(nmem, coords)
        intFaces, intCoords = PSMlib.computefaceintersections(nmem, nint, faces, coords)

        groupIntCount = numpy.zeros(ngroup,int)
        meshesS = []
        for k in range(len(self.comps)):
            c = self.keys[k]
            comp = self.comps[c]
            meshes = []
            for f in range(len(comp.Ks)):
                ni, nj = comp.Ks[f].shape
                nedge = PSMlib.countfaceedges(k, f, ni, nj, nint, intFaces)
                edges, edge_group = PSMlib.computefaceedges(k, f, ni, nj, oml0.nsurf, nint, nmem, nedge, comp.Ks[f], surf_group, mem_group, intFaces, intCoords)
                mesh = QuadMesh(0.2,edges)
                mesh.computeIntersections()
                mesh.computeDivisions()
                mesh.deleteDuplicateVerts()
                groupIntCount = PSMlib.countgroupintersections(mesh.verts.shape[0], mesh.edges.shape[0], ngroup, mesh.verts, mesh.edges, edge_group, groupIntCount)
                meshes.append([mesh,edge_group])
            meshesS.append(meshes)

        meshesM = []
        for imem in range(nmem):
            edges, edge_group = PSMlib.computememberedges(imem+1, nmem, mem_group)
            mesh = QuadMesh(1e6,edges)
            meshesM.append([mesh,edge_group])

        groupIntPtr = PSMlib.computegroupintptr(ngroup, groupIntCount)
        nint = groupIntPtr[-1,-1]
        groupInts = numpy.zeros(nint)
        for k in range(len(self.comps)):
            c = self.keys[k]
            comp = self.comps[c]
            for f in range(len(comp.Ks)):
                mesh, edge_group = meshesS[k][f]
                groupInts = PSMlib.computegroupintersections(mesh.verts.shape[0], mesh.edges.shape[0], ngroup, nint, mesh.verts, mesh.edges, edge_group, groupIntPtr, groupInts)
                #print groupInts

        for k in range(len(self.comps)):
            c = self.keys[k]
            comp = self.comps[c]
            for f in range(len(comp.Ks)):
                mesh, edge_group = meshesS[k][f]
                nvert = PSMlib.countintersectionverts(mesh.edges.shape[0], ngroup, edge_group, groupIntPtr)
                mesh.verts = PSMlib.computeintersectionverts(mesh.verts.shape[0], mesh.edges.shape[0], ngroup, nint, nvert + mesh.verts.shape[0], mesh.verts, mesh.edges, edge_group, groupIntPtr, groupInts)
                print 'QM1', k, f
                mesh.mesh()
                #edges[:,:,0] *= lengths[k,0]
                #edges[:,:,1] *= lengths[k,1]
                if k==1 and f==0 and 0:
                    import pylab
                    mesh.plot(111,pt=False,pq=False)
                    pylab.show()
                    exit()

        for imem in range(nmem):
            mesh, edge_group = meshesM[imem]
            nvert = PSMlib.countintersectionverts(mesh.edges.shape[0], ngroup, edge_group, groupIntPtr)
            mesh.verts = PSMlib.computeintersectionverts(mesh.verts.shape[0], mesh.edges.shape[0], ngroup, nint, nvert + mesh.verts.shape[0], mesh.verts, mesh.edges, edge_group, groupIntPtr, groupInts)
            print 'QM2', imem
            mesh.mesh()
            if 0:
                import pylab
                mesh.plot(111,pt=False,pq=False)
                pylab.show()
                exit()
            meshesM.append([mesh,edge_group])

        oml0.C[:,:] = -1.0
        for k in range(len(self.comps)):
            c = self.keys[k]
            comp = self.comps[c]
            for f in range(len(comp.Ks)):
                ni, nj = comp.Ks[f].shape
                for i in range(ni):
                    for j in range(nj):
                        surf = comp.Ks[f][i,j]
                        mu, mv = oml0.edgeProperty(surf,1)
                        for u in range(mu):
                            uu = u/(mu-1)
                            for v in range(mv):
                                vv = v/(mv-1)
                                oml0.C[oml0.getIndex(surf,u,v,1),:3] = [(uu+i)/ni, (vv+j)/nj, 0]
        oml0.computePointsC()
        #oml0.write2Tec('test2')
        #oml0.write2TecC('test2')
        #exit()

        Bs = []
        quads = []
        nquad0 = 0
        for k in range(len(self.comps)):
            c = self.keys[k]
            comp = self.comps[c]
            for f in range(len(comp.Ks)):
                mesh, edge_group = meshesS[k][f]
                ni, nj = comp.Ks[f].shape
                print mesh.verts.shape[0]
                P0, surfs, Q = PSMlib.computeprojtninputs(mesh.verts.shape[0], ni, nj, mesh.verts, comp.Ks[f])
                surf,u,v = oml0.evaluateProjection(P0, comp.Ks[f].flatten(), Q)
                Bs.append(oml0.evaluateBases(surf,u,v))
                quads.append(nquad0 + mesh.quads - 1)
                #quads.append(mesh.quads - 1)
                nquad0 += mesh.verts.shape[0]

        self.computePoints()

        #i = 0
        #for k in range(len(self.comps)):
        #    c = self.keys[k]
        #    comp = self.comps[c]
        #    for f in range(len(comp.Ks)):
        #        P = Bs[i].dot(oml0.C[:,:3])
        #        oml0.export.write2TecQuads('data'+str(k)+'-'+str(f)+'.dat',P,quads[i]-1)
        #        i += 1

        import scipy.sparse
        B = scipy.sparse.vstack(Bs)
        P = B.dot(oml0.C[:,:3])
        quads = numpy.vstack(quads)
        oml0.export.write2TecQuads('john.dat',P,quads)#mesh.quads-1)
Example #29
0
    def write2EGADS(self, filename):
        """ BROKEN """
        model = self.model
        Ps = []
        for surf in range(model.nsurf):
            ugroup = model.edge_group[abs(model.surf_edge[surf, 0, 0]) - 1]
            vgroup = model.edge_group[abs(model.surf_edge[surf, 1, 0]) - 1]
            nu = model.group_n[ugroup - 1]
            nv = model.group_n[vgroup - 1]
            P = PUBSlib.getsurfacep(surf + 1, model.nP, nu, nv, model.nvar,
                                    model.nsurf, model.nedge, model.nvert,
                                    model.surf_vert, model.surf_edge,
                                    model.surf_index_P, model.edge_index_P,
                                    model.P)
            Ps.append(P[:, :, :])
            Ps.append(copy.copy(P[::-1, :, :]))
            Ps[-1][:, :, 2] *= -1

        oml0 = PUBS.PUBS(Ps)

        file = open(filename + '.dat', "w")

        file.write(str(oml0.nvert) + '\n')
        file.write(str(oml0.nedge) + '\n')
        file.write(str(oml0.nsurf) + '\n')

        for i in range(oml0.nvert):
            file.write(str(oml0.C[i, 0]) + ' ')
            file.write(str(oml0.C[i, 1]) + ' ')
            file.write(str(oml0.C[i, 2]) + '\n')

        edgePtr = numpy.zeros((oml0.nedge, 3), int)
        for i in range(oml0.nsurf):
            for u in range(2):
                for v in range(2):
                    edgePtr[abs(oml0.surf_edge[i, u, v]) - 1, :] = [i, u, v]
        ms = PUBSlib.getsurfacesizes(oml0.nsurf, oml0.nedge, oml0.ngroup,
                                     oml0.surf_edge, oml0.edge_group,
                                     oml0.group_m)
        for i in range(oml0.nedge):
            surf = edgePtr[i, 0]
            edge0 = edgePtr[i, 1]
            edge1 = edgePtr[i, 2]
            if edge0 == 0:
                if edge1 == 0:
                    start = [0, 0]
                    end = [1, 0]
                else:
                    start = [0, 1]
                    end = [1, 1]
            else:
                if edge1 == 0:
                    start = [0, 0]
                    end = [0, 1]
                else:
                    start = [1, 0]
                    end = [1, 1]
            if oml0.surf_edge[surf, edge0, edge1] < 0:
                temp = start
                start = end
                end = temp
            file.write(str(oml0.surf_vert[surf, start[0], start[1]]) + ' ')
            file.write(str(oml0.surf_vert[surf, end[0], end[1]]) + '\n')
            group = oml0.edge_group[i] - 1
            k = oml0.group_k[group]
            m = oml0.group_m[group]
            file.write(str(k) + ' ')
            file.write(str(m) + '\n')
            d = oml0.group_d[oml0.knot_index[group, 0]:oml0.knot_index[group,
                                                                       1]]
            for j in range(d.shape[0]):
                file.write(str(d[j]) + ' ')
            file.write('\n')
            C = PUBSlib.getsurfacep(surf + 1, oml0.nC, ms[surf, 0],
                                    ms[surf, 1], oml0.nvar, oml0.nsurf,
                                    oml0.nedge, oml0.nvert, oml0.surf_vert,
                                    oml0.surf_edge, oml0.surf_index_C,
                                    oml0.edge_index_C, oml0.C)
            if edge0 == 0:
                if edge1 == 0:
                    edgeCs = copy.copy(C[:, 0, :])
                else:
                    edgeCs = copy.copy(C[:, -1, :])
            else:
                if edge1 == 0:
                    edgeCs = copy.copy(C[0, :, :])
                else:
                    edgeCs = copy.copy(C[-1, :, :])
            if oml0.surf_edge[surf, edge0, edge1] < 0:
                edgeCs[:, :] = copy.copy(edgeCs[::-1, :])
            for j in range(edgeCs.shape[0]):
                file.write(str(edgeCs[j, 0]) + ' ')
                file.write(str(edgeCs[j, 1]) + ' ')
                file.write(str(edgeCs[j, 2]) + '\n')

        for i in range(oml0.nsurf):
            for u in range(2):
                for v in range(2):
                    file.write(str(oml0.surf_edge[i, u, v]) + ' ')
            file.write('\n')
            ugroup = oml0.edge_group[abs(oml0.surf_edge[i, 0, 0]) - 1] - 1
            vgroup = oml0.edge_group[abs(oml0.surf_edge[i, 1, 0]) - 1] - 1
            ku = oml0.group_k[ugroup]
            mu = oml0.group_m[ugroup]
            kv = oml0.group_k[vgroup]
            mv = oml0.group_m[vgroup]
            file.write(str(ku) + ' ')
            file.write(str(mu) + ' ')
            file.write(str(kv) + ' ')
            file.write(str(mv) + ' ')
            file.write('\n')
            d = oml0.group_d[oml0.knot_index[ugroup, 0]:oml0.knot_index[ugroup,
                                                                        1]]
            for j in range(d.shape[0]):
                file.write(str(d[j]) + ' ')
            file.write('\n')
            d = oml0.group_d[oml0.knot_index[vgroup, 0]:oml0.knot_index[vgroup,
                                                                        1]]
            for j in range(d.shape[0]):
                file.write(str(d[j]) + ' ')
            file.write('\n')
            C = PUBSlib.getsurfacep(i + 1, oml0.nC, ms[i, 0], ms[i, 1],
                                    oml0.nvar, oml0.nsurf, oml0.nedge,
                                    oml0.nvert, oml0.surf_vert, oml0.surf_edge,
                                    oml0.surf_index_C, oml0.edge_index_C,
                                    oml0.C)
            for v in range(C.shape[1]):
                for u in range(C.shape[0]):
                    file.write(str(C[u, v, 0]) + ' ')
                    file.write(str(C[u, v, 1]) + ' ')
                    file.write(str(C[u, v, 2]) + '\n')

        file.close()
Example #30
0
    def computeKnots(self):
        """ Compute the global list of knots """

        self.group_d = PUBSlib.computeknots(self.ngroup, self.nD, self.group_k,
                                            self.group_m)
Example #31
0
    def write2EGADS(self,filename):
        """ BROKEN """
        model = self.model
        Ps = []
        for surf in range(model.nsurf):
            ugroup = model.edge_group[abs(model.surf_edge[surf,0,0])-1]
            vgroup = model.edge_group[abs(model.surf_edge[surf,1,0])-1]
            nu = model.group_n[ugroup-1]
            nv = model.group_n[vgroup-1]      
            P = PUBSlib.getsurfacep(surf+1, model.nP, nu, nv, model.nvar, model.nsurf, model.nedge, model.nvert, model.surf_vert, model.surf_edge, model.surf_index_P, model.edge_index_P, model.P)
            Ps.append(P[:,:,:])
            Ps.append(copy.copy(P[::-1,:,:]))
            Ps[-1][:,:,2] *= -1

        oml0 = PUBS.PUBS(Ps)

        file = open(filename+'.dat',"w")

        file.write(str(oml0.nvert)+'\n')
        file.write(str(oml0.nedge)+'\n')
        file.write(str(oml0.nsurf)+'\n')

        for i in range(oml0.nvert):
            file.write(str(oml0.C[i,0])+' ')
            file.write(str(oml0.C[i,1])+' ')
            file.write(str(oml0.C[i,2])+'\n')

        edgePtr = numpy.zeros((oml0.nedge,3),int)
        for i in range(oml0.nsurf):
            for u in range(2):
                for v in range(2):
                    edgePtr[abs(oml0.surf_edge[i,u,v])-1,:] = [i,u,v]
        ms = PUBSlib.getsurfacesizes(oml0.nsurf, oml0.nedge, oml0.ngroup, oml0.surf_edge, oml0.edge_group, oml0.group_m)
        for i in range(oml0.nedge):
            surf = edgePtr[i,0]
            edge0 = edgePtr[i,1]
            edge1 = edgePtr[i,2]
            if edge0==0:
                if edge1==0:
                    start = [0,0]
                    end = [1,0]
                else:
                    start = [0,1]
                    end = [1,1]
            else:
                if edge1==0:
                    start = [0,0]
                    end = [0,1]
                else:
                    start = [1,0]
                    end = [1,1]
            if oml0.surf_edge[surf,edge0,edge1] < 0:
                temp = start
                start = end
                end = temp
            file.write(str(oml0.surf_vert[surf,start[0],start[1]])+' ')
            file.write(str(oml0.surf_vert[surf,end[0],end[1]])+'\n')
            group = oml0.edge_group[i] - 1
            k = oml0.group_k[group]
            m = oml0.group_m[group]
            file.write(str(k)+' ')
            file.write(str(m)+'\n')
            d = oml0.group_d[oml0.knot_index[group,0]:oml0.knot_index[group,1]]
            for j in range(d.shape[0]):
                file.write(str(d[j])+' ')
            file.write('\n')
            C = PUBSlib.getsurfacep(surf+1, oml0.nC, ms[surf,0], ms[surf,1], oml0.nvar, oml0.nsurf, oml0.nedge, oml0.nvert, oml0.surf_vert, oml0.surf_edge, oml0.surf_index_C, oml0.edge_index_C, oml0.C)
            if edge0==0:
                if edge1==0:
                    edgeCs = copy.copy(C[:,0,:])
                else:
                    edgeCs = copy.copy(C[:,-1,:])
            else:
                if edge1==0:
                    edgeCs = copy.copy(C[0,:,:])
                else:
                    edgeCs = copy.copy(C[-1,:,:])
            if oml0.surf_edge[surf,edge0,edge1] < 0:
                edgeCs[:,:] = copy.copy(edgeCs[::-1,:])
            for j in range(edgeCs.shape[0]):
                file.write(str(edgeCs[j,0])+' ')
                file.write(str(edgeCs[j,1])+' ')
                file.write(str(edgeCs[j,2])+'\n')

        for i in range(oml0.nsurf):
            for u in range(2):
                for v in range(2):
                    file.write(str(oml0.surf_edge[i,u,v])+' ')
            file.write('\n')
            ugroup = oml0.edge_group[abs(oml0.surf_edge[i,0,0])-1] - 1
            vgroup = oml0.edge_group[abs(oml0.surf_edge[i,1,0])-1] - 1
            ku = oml0.group_k[ugroup]
            mu = oml0.group_m[ugroup]
            kv = oml0.group_k[vgroup]
            mv = oml0.group_m[vgroup]
            file.write(str(ku)+' ')
            file.write(str(mu)+' ')
            file.write(str(kv)+' ')
            file.write(str(mv)+' ')
            file.write('\n')    
            d = oml0.group_d[oml0.knot_index[ugroup,0]:oml0.knot_index[ugroup,1]]
            for j in range(d.shape[0]):
                file.write(str(d[j])+' ')
            file.write('\n') 
            d = oml0.group_d[oml0.knot_index[vgroup,0]:oml0.knot_index[vgroup,1]]
            for j in range(d.shape[0]):
                file.write(str(d[j])+' ')
            file.write('\n')
            C = PUBSlib.getsurfacep(i+1, oml0.nC, ms[i,0], ms[i,1], oml0.nvar, oml0.nsurf, oml0.nedge, oml0.nvert, oml0.surf_vert, oml0.surf_edge, oml0.surf_index_C, oml0.edge_index_C, oml0.C)
            for v in range(C.shape[1]):
                for u in range(C.shape[0]):
                    file.write(str(C[u,v,0])+' ')
                    file.write(str(C[u,v,1])+' ')
                    file.write(str(C[u,v,2])+'\n')

        file.close()
Example #32
0
    def computeKnots(self):
        """ Compute the global list of knots """

        self.group_d = PUBSlib.computeknots(self.ngroup,self.nD,self.group_k,self.group_m)
Example #33
0
    def computeParameters(self):
        """ Compute the global list of parameter values """

        self.T = PUBSlib.computeparameters(self.nT, self.nD, self.nsurf, self.nedge, self.ngroup, self.surf_edge, self.edge_group, self.group_k, self.group_m, self.group_n, self.group_d, self.knot_index)