def _get_Q(self, ms, ns, P0): nsurf = ns.shape[0] Ps = [] for i in xrange(nsurf): P = numpy.zeros((ns[i] + 1, 4, 3), order='F') for j in xrange(4): P[:, j, :] = P0[sum(ns[:i]):sum(ns[:i + 1]) + 1, :] P[:, j, 2] = j Ps.append(P) bse = BSEmodel(Ps) for i in xrange(nsurf): bse.set_bspline_option('num_cp', i, 'u', ms[i] + 1) bse.set_bspline_option('num_pt', i, 'u', ns[i] + 1) bse.set_bspline_option('num_pt', i, 'v', 4) bse.assemble() cp = bse.vec['cp_str'].array pt = bse.vec['pt_str'].array jac = bse.jac['d(pt_str)/d(cp_str)'] for i in xrange(nsurf): bse.vec['pt_str'].surfs[i][:, :, :] = Ps[i] mtx = jac.T.dot(jac) rhs = jac.T.dot(pt) for dim in xrange(3): cp[:, dim] = scipy.sparse.linalg.cg(mtx, rhs[:, dim])[0] Q = numpy.zeros((sum(ms) + 1, 3), order='F') for i in xrange(nsurf): Q[sum(ms[:i]):sum(ms[:i+1])+1,:] = \ bse.vec['cp_str'].surfs[i][:,0,:] return Q
def _get_Q(self, ms, ns, P0): nsurf = ns.shape[0] Ps = [] for i in xrange(nsurf): P = numpy.zeros((ns[i]+1,4,3), order='F') for j in xrange(4): P[:,j,:] = P0[sum(ns[:i]):sum(ns[:i+1])+1,:] P[:,j,2] = j Ps.append(P) bse = BSEmodel(Ps) for i in xrange(nsurf): bse.set_bspline_option('num_cp', i, 'u', ms[i]+1) bse.set_bspline_option('num_pt', i, 'u', ns[i]+1) bse.set_bspline_option('num_pt', i, 'v', 4) bse.assemble() cp = bse.vec['cp_str'].array pt = bse.vec['pt_str'].array jac = bse.jac['d(pt_str)/d(cp_str)'] for i in xrange(nsurf): bse.vec['pt_str'].surfs[i][:,:,:] = Ps[i] mtx = jac.T.dot(jac) rhs = jac.T.dot(pt) for dim in xrange(3): cp[:, dim] = scipy.sparse.linalg.cg(mtx, rhs[:, dim])[0] Q = numpy.zeros((sum(ms) + 1,3),order='F') for i in xrange(nsurf): Q[sum(ms[:i]):sum(ms[:i+1])+1,:] = \ bse.vec['cp_str'].surfs[i][:,0,:] return Q
def _get_P(self, nP, airfoil): P = numpy.zeros((airfoil.shape[0],4,3),order='F') for j in range(4): P[:,j,:2] = airfoil[:,:] P[:,j,2] = j bse = BSEmodel([P]) bse.set_bspline_option('num_pt', 0, 'u', airfoil.shape[0]) bse.set_bspline_option('num_cp', 0, 'u', int(airfoil.shape[0]/3)) bse.set_bspline_option('num_pt', 0, 'v', 4) bse.set_bspline_option('num_cp', 0, 'v', 4) bse.assemble() cp = bse.vec['cp_str'].array pt = bse.vec['pt_str'].array jac = bse.jac['d(pt_str)/d(cp_str)'] bse.vec['pt_str'].surfs[0][:, :, :] = P mtx = jac.T.dot(jac) rhs = jac.T.dot(pt) for dim in xrange(3): cp[:, dim] = scipy.sparse.linalg.cg(mtx, rhs[:, dim])[0] fit = numpy.array(cp) bse.set_bspline_option('num_pt', 0, 'u', nP) bse.assemble() cp = bse.vec['cp_str'].array pt = bse.vec['pt_str'].array cp[:, :] = fit[:, :] bse.apply_jacobian('pt_str', 'd(pt_str)/d(cp_str)', 'cp_str') return bse.vec['pt_str'].surfs[0][:, 0, :]
def _get_P(self, nP, airfoils, name, bunch_LE, bunch_TE): def bunch_start(ind, a): ind[:] = ind**a def bunch_end(ind, a): ind[:] = 1 - (1-ind)**a airfoil = airfoils[name] P = numpy.zeros((airfoil.shape[0],4,3),order='F') for j in range(4): P[:,j,:2] = airfoil[:,:] P[:,j,2] = j bse = BSEmodel([P]) bse.set_bspline_option('num_pt', 0, 'u', airfoil.shape[0]) bse.set_bspline_option('num_cp', 0, 'u', int(airfoil.shape[0]/3)) bse.set_bspline_option('num_pt', 0, 'v', 4) bse.set_bspline_option('num_cp', 0, 'v', 4) bse.assemble() cp = bse.vec['cp_str'].array pt = bse.vec['pt_str'].array jac = bse.jac['d(pt_str)/d(cp_str)'] bse.vec['pt_str'].surfs[0][:, :, :] = P mtx = jac.T.dot(jac) rhs = jac.T.dot(pt) for dim in range(3): cp[:, dim] = scipy.sparse.linalg.cg(mtx, rhs[:, dim])[0] fit = numpy.array(cp) bse.set_bspline_option('num_pt', 0, 'u', nP) bse.assemble() cp = bse.vec['cp_str'].array pt = bse.vec['pt_str'].array cp[:, :] = fit[:, :] surfs = numpy.zeros(nP).astype(int) ind_u = numpy.linspace(0, 1, nP) if name == 'upp': bunch_start(ind_u, bunch_TE) bunch_end(ind_u, bunch_LE) elif name == 'low': bunch_start(ind_u, bunch_LE) bunch_end(ind_u, bunch_TE) ind_v = numpy.zeros(nP) bse.add_jacobian('new', surfs, ind_u, ind_v, 3) bse.apply_jacobian('new', 'd(new)/d(cp_str)', 'cp_str') return bse.vec['new'].array[:, :]
def _get_P(self, nP, airfoils, name, bunch_LE, bunch_TE): def bunch_start(ind, a): ind[:] = ind**a def bunch_end(ind, a): ind[:] = 1 - (1-ind)**a airfoil = airfoils[name] P = numpy.zeros((airfoil.shape[0],4,3),order='F') for j in range(4): P[:,j,:2] = airfoil[:,:] P[:,j,2] = j bse = BSEmodel([P]) bse.set_bspline_option('num_pt', 0, 'u', airfoil.shape[0]) bse.set_bspline_option('num_cp', 0, 'u', int(airfoil.shape[0]/3)) bse.set_bspline_option('num_pt', 0, 'v', 4) bse.set_bspline_option('num_cp', 0, 'v', 4) bse.assemble() cp = bse.vec['cp_str'].array pt = bse.vec['pt_str'].array jac = bse.jac['d(pt_str)/d(cp_str)'] bse.vec['pt_str'].surfs[0][:, :, :] = P mtx = jac.T.dot(jac) rhs = jac.T.dot(pt) for dim in xrange(3): cp[:, dim] = scipy.sparse.linalg.cg(mtx, rhs[:, dim])[0] fit = numpy.array(cp) bse.set_bspline_option('num_pt', 0, 'u', nP) bse.assemble() cp = bse.vec['cp_str'].array pt = bse.vec['pt_str'].array cp[:, :] = fit[:, :] surfs = numpy.zeros(nP).astype(int) ind_u = numpy.linspace(0, 1, nP) if name == 'upp': bunch_start(ind_u, bunch_TE) bunch_end(ind_u, bunch_LE) elif name == 'low': bunch_start(ind_u, bunch_LE) bunch_end(ind_u, bunch_TE) ind_v = numpy.zeros(nP) bse.add_jacobian('new', surfs, ind_u, ind_v, 3) bse.apply_jacobian('new', 'd(new)/d(cp_str)', 'cp_str') return bse.vec['new'].array[:, :]