def preprocess_pseudo(u, v, p, xp, yp, s_n, ffsf, ffsp, origine): [dusdt, dvsdt], [us, vs] = config.get_solidVeloPosit(s_n)[:-1] proju = config.get_pseudo(0, s_n)[1] projv = config.get_pseudo(1, s_n)[1] projp = config.get_pseudo(2, s_n)[1] # arbitrarily: N = int(2 * math.pi * R / dx) dAngle = 2. * math.pi / N computationPoints = np.arange(N) * dAngle curvilinearU = curvilinear(proju) curvilinearV = curvilinear(projv) curvilinearP = curvilinear(projp) fFu, sF_coefsu, fFv, sF_coefsv = ffsf fFp, sF_coefsp = ffsp surfaceStressFieldu = surfaceStress(fFu, sF_coefsu, u, us, origine[0] - 1, origine[1]) surfaceStressFieldv = surfaceStress(fFv, sF_coefsv, v, vs, origine[0], origine[1] - 1) DuDt = [dusdt, dvsdt] surfaceStressFieldp = linearizePressure_surface(fFp, sF_coefsp, p, DuDt, origine, s_n) return surfaceStressFieldu,curvilinearU,\ surfaceStressFieldv,curvilinearV,\ surfaceStressFieldp,curvilinearP,\ computationPoints
def ibm(xg, yg, potent_pseudo, s_n, field_numb, Or, nonewsf): center = config.get_centers(s_n) flags_slice = config.get_flags_slice(field_numb, s_n) solidpop = config.get_solidPops(s_n)[field_numb] #X,Y = np.array(map(yg.get_i,solidpop))-Or[0], np.array(map(yg.get_j,solidpop))-Or[1] X, Y = np.array([yg.get_i(x, center[0], Lx, xg) for x in solidpop]) - Or[0], np.array( [yg.get_j(x, center[1], Ly) for x in solidpop]) - Or[1] flags_slice[X, Y] = -1 if nonewsf: forcedPoints = config.get_forcing(field_numb, s_n)[0] pseudoPoints = config.get_pseudo(field_numb, s_n)[0] #X,Y = np.array(map(yg.get_i,forcedPoints))-Or[0], np.array(map(yg.get_j,forcedPoints))-Or[1] X, Y = np.array([yg.get_i(x, center[0], Lx, xg) for x in forcedPoints]) - Or[0], np.array([ yg.get_j(x, center[1], Ly) for x in forcedPoints ]) - Or[1] flags_slice[X, Y] = 1 #X,Y = np.array(map(yg.get_i,pseudoPoints))-Or[0], np.array(map(yg.get_j,pseudoPoints))-Or[1] X, Y = np.array([yg.get_i(x, center[0], Lx, xg) for x in pseudoPoints]) - Or[0], np.array([ yg.get_j(x, center[1], Ly) for x in pseudoPoints ]) - Or[1] flags_slice[X, Y] = -2 else: forcedPoints = [] pseudoPoints = [] # search forced and pseudo CF.search_forced_and_pseudo(potent_pseudo, flags_slice, pseudoPoints, forcedPoints, xg, yg, neighbours4, Or[0], Or[1], center, Lx, Ly) # PROJECTIONS if field_numb == 2: projectionsF = np.zeros((len(forcedPoints), 4)) normal_projection(s_n, forcedPoints, xg, yg, projectionsF, center) else: projectionsF = None pseudoPoints = np.array(pseudoPoints, dtype=np.int) projectionsP = np.zeros((len(pseudoPoints), 4)) normal_projection(s_n, pseudoPoints, xg, yg, projectionsP, center) return forcedPoints, projectionsF, pseudoPoints, projectionsP
def linearizePressure_surface(interp_points, sF_coefsp, field, DuDt, Or, s_n): forced, proj = config.get_pseudo(2, s_n) fF = np.zeros(len(forced)) for n in range(len(forced)): forcedIJ = forced[n] p1, p2 = interp_points[n][0], interp_points[n][1] #fF[n] = CF.interp_neuman(proj[n][2:],proj[n][:2],p1,p2,xg,yg,[-DuDt[0],-DuDt[1]],field,Or) fF[n] = (proj[n][2] * (-DuDt[0]) + proj[n][3] * (-DuDt[1])) * sF_coefsp[n][0] + field[ p1[1] - Or[1], p1[0] - Or[0]] * sF_coefsp[n][1] + field[ p2[1] - Or[1], p2[0] - Or[0]] * sF_coefsp[n][2] #fF[n][1] = proj[n][0] #fF[n][2] = proj[n][1] return fF
def reshape_poisson(xu, yu, xv, yv, xp, yp, rsc, slw, s_n, fFu, fFv, Or, ax): center = config.get_centers(s_n) is_coef_written = np.zeros(((nx + 1) * (ny + 1), ), dtype=np.bool_) coefs = np.zeros((nx + 1) * (ny + 1)) pseudou = config.get_pseudo(0, s_n)[0] flagsu = config.get_flags_slice(0, s_n) pseudov = config.get_pseudo(1, s_n)[0] flagsv = config.get_flags_slice(1, s_n) indptr, indices, data = np.zeros(((nx + 1) * (ny + 1) + 1, ), dtype=np.int), [], [] forcedp = config.get_forcing(2, s_n)[0] projections = config.get_forcing(2, s_n)[1] coefs_for_psisource = [None] * len(forcedp) # local variables normal_cell = np.zeros(2, dtype=np.float) tolin = np.zeros(2, dtype=np.float) anchor = np.zeros(2, dtype=np.int) pline = np.zeros((2, 2), dtype=np.int) cline = np.zeros(2, dtype=np.float) #NR=config.get_round() for n in range(len(forcedp)): if rsc[n] is None: ' not a cut-cell ' # not a cut-cell i else: # cut-cell IJ = forcedp[n] # print center,yp.get_j_abs(IJ),yp.get_j(IJ,center[1],Ly) cell = np.array(rsc[n]) solidwall = slw[n] written_places = init_tables( CF.IJ_ij_xg(yp.get_i_abs(IJ), yp.get_j_abs(IJ), xp, yp), is_coef_written, coefs) _vsx, _vsy, _u, _ui, _uj, _v, _vi, _vj = [], [], [], [], [], [], [], [] barycentre = [ np.sum(cell[:, 0]) / cell.shape[0], np.sum(cell[:, 1]) / cell.shape[0] ] if not ax is None: import matplotlib.pyplot as plt #here we load matplotlib, calling it 'plt' plt.plot(barycentre[0], barycentre[1], '+', color='m') for npoint in range(len(cell)): p1 = cell[npoint - 1] p2 = cell[npoint] d = CF.dist(p1[0], p1[1], p2[0], p2[1]) if not ax is None: plt.plot([p1[0], p2[0]], [p1[1], p2[1]], color='g') plt.plot([p1[0], p2[0]], [p1[1], p2[1]], 'o', color='r') if not d == 0.: #normal_cell[:] = [round(-(p1[1]-p2[1])/d,10),round((p1[0]-p2[0])/d,10)] normal_cell[:] = [ -(p1[1] - p2[1]) / d, (p1[0] - p2[0]) / d ] tolin[:] = [(p1[0] + p2[0]) / 2., (p1[1] + p2[1]) / 2.] #plt.plot(tolin[0],tolin[1],'o',color='b') if bool_normal(normal_cell, tolin, xp, yp, barycentre): normal_cell = -normal_cell if solidwall[npoint - 1] == 1 and solidwall[npoint] == 1: #_vsx.append(d/config.dt*normal_cell[0]) #_vsy.append(d/config.dt*normal_cell[1]) _vsx.append(d * normal_cell[0]) _vsy.append(d * normal_cell[1]) else: if not normal_cell[0] == 0.: solid_FSI.linearizeFlux( 0, tolin, xu, yu, xv, yv, xp, yp, [ yp.get_i(IJ, center[0], Lx, xp), yp.get_j(IJ, center[1], Ly) ], pline, cline) for fij in range(2): indi, wli = pline[fij], cline[fij] #coef_to_add = round(d/dx*wli*normal_cell[0],NR) coef_to_add = d / dx * wli * normal_cell[0] coef_to_add_p = d / dx * wli * normal_cell[0] if not coef_to_add == 0.: if flagsu[indi[0] - (Or[0] - 1), indi[1] - (Or[1])] == -2: iw = CF.find_first( CF.IJ_ij_yg( indi[0], indi[1], xu, yu), pseudou ) #indi[0]*yu.shape()+indi[1],pseudou) pf0, pf1, p10, p11, p20, p21, coefs1, coefs2, coefs0 = fFu[ iw] add_coefs((xu.ind_perio(p10),\ yu.ind_perio(p11)),coef_to_add_p*coefs1,is_coef_written, coefs, written_places,1,0,xp,yp) add_coefs((xu.ind_perio(p20),\ yu.ind_perio(p21)),coef_to_add_p*coefs2,is_coef_written, coefs, written_places,1,0,xp,yp) else: add_coefs((xu.ind_perio(indi[0]),\ yu.ind_perio(indi[1])),coef_to_add_p,is_coef_written, coefs, written_places,1,0,xp,yp) #append_(_u,_ui,_uj,dx/config.dt*coef_to_add,indi[0],indi[1]) append_(_u, _ui, _uj, dx * coef_to_add, indi[0], indi[1]) if not normal_cell[1] == 0.: solid_FSI.linearizeFlux( 1, tolin, xv, yv, xu, yu, xp, yp, [ yp.get_i(IJ, center[0], Lx, xp), yp.get_j(IJ, center[1], Ly) ], pline, cline) for fij in range(2): indi, wli = pline[fij], cline[fij] #coef_to_add = round(d/dx*wli*normal_cell[1],NR) coef_to_add = d / dx * wli * normal_cell[1] coef_to_add_p = d / dx * wli * normal_cell[1] if not coef_to_add == 0.: if flagsv[indi[0] - (Or[0]), indi[1] - (Or[1] - 1)] == -2: iw = CF.find_first( CF.IJ_ij_yg( indi[0], indi[1], xv, yv), pseudov ) #indi[0]*yv.shape()+indi[1],pseudov) pf0, pf1, p10, p11, p20, p21, coefs1, coefs2, coefs0 = fFv[ iw] add_coefs((xv.ind_perio(p10),\ yv.ind_perio(p11)),coef_to_add_p*coefs1,is_coef_written, coefs, written_places,0,1,xp,yp) add_coefs((xv.ind_perio(p20),\ yv.ind_perio(p21)),coef_to_add_p*coefs2,is_coef_written, coefs, written_places,0,1,xp,yp) else: add_coefs((xv.ind_perio(indi[0]),\ yv.ind_perio(indi[1])),coef_to_add_p,is_coef_written, coefs, written_places,0,1,xp,yp) #append_(_v,_vi,_vj,dx/config.dt*coef_to_add,indi[0],indi[1]) append_(_v, _vi, _vj, dx * coef_to_add, indi[0], indi[1]) coefs_for_psisource[n] = _vsx, _vsy, _u, _ui, _uj, _v, _vi, _vj, IJ update_csr((yp.get_i_abs(IJ), yp.get_j_abs(IJ)), indptr, indices, data, coefs, written_places, xp, yp) return (-0.25 * np.array(data, dtype=np.float), np.array(indices, dtype=np.int), indptr), coefs_for_psisource
def reshape_cells(xp, yp, s_n, Or): center = config.get_centers(s_n) flagsp = config.get_flags_slice(2, s_n) flagsu = config.get_flags_slice(0, s_n) flagsv = config.get_flags_slice(1, s_n) forcedp, projectionsFp = config.get_forcing(2, s_n) pseudop, projectionsPp = config.get_pseudo(2, s_n) flags = np.zeros(4, dtype=np.int8) recutcells = [None] * len(forcedp) solidwall = [None] * len(forcedp) for n in range(len(forcedp)): IJ = forcedp[n] prjx, prjy = projectionsFp[n][0], projectionsFp[n][1] normal = projectionsFp[n][2], projectionsFp[n][3] xpxijp, ypyijp = xp.loc(yp.get_i(IJ, center[0], Lx, xp)), yp.loc( yp.get_j(IJ, center[1], Ly)) coins = [[xpxijp-dx/2., ypyijp-dx/2.],\ [xpxijp+dx/2., ypyijp-dx/2.],\ [xpxijp+dx/2., ypyijp+dx/2.],\ [xpxijp-dx/2., ypyijp+dx/2.]] flags[:] = 0 for c in range(4): #if solid_FSI.isinsolid(coins[c],normal,s_n): flags[c] = 1 if solid_FSI.isinnodule(s_n, coins[c][0], coins[c][1]): flags[c] = 1 if np.sum(flags) > 0: # cut-cell temprc, tempsolid = [], [] for c in range(4): if flags[c] == 1: coinsinfluid = [] if flags[c - 1] == 0: coinsinfluid.append(c - 1) if c < 3: if flags[c + 1] == 0: coinsinfluid.append(c + 1) else: if flags[0] == 0: coinsinfluid.append(0) for cif in coinsinfluid: cross = intersec(coins[c], coins[cif], [prjx, prjy], normal) temprc.append([cross[0], cross[1]]) tempsolid.append(1) else: temprc.append(coins[c]) tempsolid.append(0) recutcells[n] = temprc solidwall[n] = tempsolid #oldcutcells = config.get_cutcellspartner(s_n) #cutcellspartner = np.zeros((len(pseudop),2), dtype='int64') for n in range(len(pseudop)): IJ = pseudop[n] prjx, prjy = projectionsPp[n][0], projectionsPp[n][1] normal = projectionsPp[n][2], projectionsPp[n][3] _xijp, _yijp = yp.get_i(IJ, center[0], Lx, xp), yp.get_j(IJ, center[1], Ly) xpxijp, ypyijp = xp.loc(yp.get_i(IJ, center[0], Lx, xp)), yp.loc( yp.get_j(IJ, center[1], Ly)) coins = [[xpxijp-dx/2., ypyijp-dx/2.],\ [xpxijp+dx/2., ypyijp-dx/2.],\ [xpxijp+dx/2., ypyijp+dx/2.],\ [xpxijp-dx/2., ypyijp+dx/2.]] flags[:] = 1 for c in range(4): #if not solid_FSI.isinsolid(coins[c],normal,s_n): flags[c] = 0 if not solid_FSI.isinnodule(s_n, coins[c][0], coins[c][1]): flags[c] = 0 if np.sum(flags) < 4: # cut-cell maxnormal = 0. if flagsp[_xijp + 1 - Or[0], _yijp - Or[1]] == 1: if normal[ 0] > maxnormal: # and (not recutcells[forcedp.index((_xijp+1)*(ny+1) + _yijp)] == None): maxnormal = normal[0] ijwin = CF.IJ_ij_yg(_xijp + 1, _yijp, xp, yp) #(_xijp+1)*(ny+1) + _yijp forbid = [1, 2] if flagsp[_xijp - 1 - Or[0], _yijp - Or[1]] == 1: if -normal[ 0] > maxnormal: # and (not recutcells[forcedp.index((_xijp-1)*(ny+1) + _yijp)] == None): maxnormal = -normal[0] ijwin = CF.IJ_ij_yg(_xijp - 1, _yijp, xp, yp) #(_xijp-1)*(ny+1) + _yijp forbid = [0, 3, -1] if flagsp[_xijp - Or[0], _yijp + 1 - Or[1]] == 1: if normal[ 1] > maxnormal: # and (not recutcells[forcedp.index((_xijp)*(ny+1) + _yijp+1)] == None): maxnormal = normal[1] ijwin = CF.IJ_ij_yg(_xijp, _yijp + 1, xp, yp) #_xijp*(ny+1) + (_yijp+1) forbid = [2, 3, -1] if flagsp[_xijp - Or[0], _yijp - 1 - Or[1]] == 1: if -normal[ 1] > maxnormal: # and (not recutcells[forcedp.index((_xijp)*(ny+1) + _yijp-1)] == None): maxnormal = -normal[1] ijwin = CF.IJ_ij_yg(_xijp, _yijp - 1, xp, yp) #_xijp*(ny+1) + (_yijp-1) forbid = [0, 1] # cutcellspartner[n] = IJ,ijwin try: partner = forcedp.index(ijwin) except: print 'partner not found', IJ, _xijp, _yijp partneriscut = (not recutcells[partner] == None) normal_intersec = normal if not partneriscut: #prjx,prjy = projectionsPp[n][0],projectionsPp[n][1] xp_xijp, yp_yijp = xp.loc( yp.get_i(ijwin, center[0], Lx, xp)), yp.loc(yp.get_j(ijwin, center[1], Ly)) recutcells[partner] = [[xp_xijp-dx/2., yp_yijp-dx/2.],\ [xp_xijp+dx/2., yp_yijp-dx/2.],\ [xp_xijp+dx/2., yp_yijp+dx/2.],\ [xp_xijp-dx/2., yp_yijp+dx/2.]] solidwall[partner] = [0, 0, 0, 0] forbid = [] #else: # prjx,prjy = projectionsFp[partner][0],projectionsFp[partner][1] # normal_intersec = projectionsFp[partner][2],projectionsFp[partner][3] prjx, prjy = projectionsPp[n][0], projectionsPp[n][1] for c in range(4): if flags[c] == 0: coinsinsolid = [] if flags[c - 1] == 1: coinsinsolid.append(c - 1) if c < 3: if flags[c + 1] == 1: coinsinsolid.append(c + 1) else: if flags[0] == 1: coinsinsolid.append(0) for cis in coinsinsolid: if not (c in forbid and cis in forbid): cross = intersec(coins[c], coins[cis], [prjx, prjy], normal_intersec) recutcells[partner].append([cross[0], cross[1]]) solidwall[partner].append(1) #config.set_cutcellspartner(s_n,cutcellspartner) for n in range(len(forcedp)): if not recutcells[n] is None: #cut cell cell = np.array(recutcells[n]) xanc, yanc = [ np.sum(cell[:, 0]) / cell.shape[0], np.sum(cell[:, 1]) / cell.shape[0] ] nsol = 0 sw = [] for sol in solidwall[n]: if sol == 1: sw.append(nsol) nsol += 1 if len(sw) > 2: swatt = [] maximum = 0. nfirst = 0 for SW1 in sw[:-1]: for SW2 in sw[nfirst:]: measure = CF.na_vec_prod(xanc, yanc, recutcells[n][SW1][0], recutcells[n][SW1][1], recutcells[n][SW2][0], recutcells[n][SW2][1]) if measure > maximum: maximum = measure swatt = [SW1, SW2] nfirst += 1 recutcells[n] = [ recutcells[n][i] for i in range(cell.shape[0]) if (solidwall[n][i] == 0 or i in swatt) ] solidwall[n] = [ solidwall[n][i] for i in range(cell.shape[0]) if (solidwall[n][i] == 0 or i in swatt) ] temp = [] for point in recutcells[n]: Xo = point[0] - xanc Yo = point[1] - yanc temp.append(math.atan2(Yo, Xo)) #temprc,tempsw,snort,indices_toswap,indices_todelete = [],[],0,[],[] temp = np.argsort(temp) recutcells[n] = [recutcells[n][i] for i in temp] solidwall[n] = [solidwall[n][i] for i in temp] return recutcells, solidwall
def ghostcellCorr(xg, yg, s_n, Or, ax): center = config.get_centers(s_n) flags_slice = config.get_flags_slice(2, s_n) forced, projections = config.get_pseudo(2, s_n) indptr, indices, data = np.zeros((nx + 1) * (ny + 1) + 1, dtype=np.int), [], [] indptr_penal, indices_penal, data_penal = np.zeros((nx + 1) * (ny + 1) + 1, dtype=np.int), [], [] interp_points = np.zeros((len(forced), 2, 2), dtype=np.int) nint = range(len(forced)) solid = config.get_solidPops(s_n)[2] sF_coefs = np.empty((len(forced), 3)) for n in nint: projection = projections[n] proj = projection[0], projection[1] n_x = projection[2] n_y = projection[3] pf = yg.get_i(forced[n], center[0], Lx, xg), yg.get_j(forced[n], center[1], Ly) anchor = pf layer = False coefs, p1, p2 = search_pressure(anchor, xg, yg, proj, flags_slice, Or, projections[n][2:4], layer) sF_coefs[n, :] = coefs interp_points[n][0][:] = p1 interp_points[n][1][:] = p2 #layer = True #coefs,p1,p2 = search_pressure(anchor,xg,yg,proj,flags_slice,Or,projections[n][2:4],layer) pf_abs = yg.get_i_abs(forced[n]), yg.get_j_abs(forced[n]) #pf = xg.ind_perio(pf[0]),yg.ind_perio(pf[1]) p1[0] = xg.ind_perio(p1[0]) #+pf_abs[0]-pf[0]) p1[1] = yg.ind_perio(p1[1]) #+pf_abs[1]-pf[1]) p2[0] = xg.ind_perio(p2[0]) #+pf_abs[0]-pf[0]) p2[1] = yg.ind_perio(p2[1]) #+pf_abs[1]-pf[1]) #pf = pf_abs line = pf_abs[1] * (xg.shape()) + pf_abs[0] IJ_1 = p1[1] * (xg.shape()) + p1[0] IJ_2 = p2[1] * (xg.shape()) + p2[0] if not ax is None: #np.amax(np.abs(coefs)) > 0.95: col = 'k' DY = 0. # if s_n==1: DY,col = -1.,'r' import matplotlib.pyplot as plt #here we load matplotlib, calling it 'plt' plt.plot([ xg.loc(pf[0] + 2), xg.loc(pf[0] - 2), xg.loc(pf[0]), xg.loc(pf[0]) ], [ yg.loc(pf[1]), yg.loc(pf[1]), yg.loc(pf[1] + 2), yg.loc(pf[1] - 2) ], '+', color='b') plt.plot([ xg.loc(pf[0] + 1), xg.loc(pf[0] - 1), xg.loc(pf[0]), xg.loc(pf[0]) ], [ yg.loc(pf[1]), yg.loc(pf[1]), yg.loc(pf[1] + 1), yg.loc(pf[1] - 1) ], '+', color='b') plt.plot( [xg.loc(p1[0]), xg.loc(pf[0]), xg.loc(p2[0])], [yg.loc(p1[1]) + DY, yg.loc(pf[1]) + DY, yg.loc(p2[1]) + DY], color='k') plt.plot([xg.loc(p1[0]), xg.loc(p2[0]), CF.loc_perio(proj[0], Lx)], [yg.loc(p1[1]), yg.loc(p2[1]), CF.loc_perio(proj[1], Ly)], 'o', color='k') plt.plot(xg.loc(pf[0]), yg.loc(pf[1]), 'o', color='g') plt.plot(CF.loc_perio(proj[0], Lx), CF.loc_perio(proj[1], Ly), '+', color='r') plt.plot([ CF.loc_perio(proj[0], Lx), CF.loc_perio(proj[0] + dx * n_x, Lx) ], [ CF.loc_perio(proj[1], Ly), CF.loc_perio(proj[1] + dx * n_y, Ly) ], color='k') #line = CF.IJ_ij_xg(pf[0],pf[1],xg,yg)#pf[1]*(nx+1)+pf[0] #IJ_1 = CF.IJ_ij_xg(p1[0],p1[1],xg,yg)#p1[1]*(xg.shape())+p1[0] #IJ_2 = CF.IJ_ij_xg(p2[0],p2[1],xg,yg)#p2[1]*(xg.shape())+p2[0] #print coefs indptr[line + 1:] += 2 indices[indptr[line]:indptr[line]] = [IJ_1, IJ_2] data[indptr[line]:indptr[line]] = [-coefs[1], -coefs[2]] #Neumann if False: plt.show() for IJs in solid: #ps = yg.get_i(IJs,center[0],Lx), yg.get_j(IJs,center[1],Ly) ps = yg.get_i_abs(IJs), yg.get_j_abs(IJs) #line = CF.IJ_ij_xg(ps[0],ps[1],xg,yg)#ps[1]*xg.shape()+ps[0] line = ps[1] * xg.shape() + ps[0] #ps = yg.get_i(IJs), yg.get_j(IJs) #line = ps[1]*(nx+1)+ps[0] indptr_penal[line + 1:] += 4 indices_penal[indptr_penal[line]:indptr_penal[line]] = [ line + 1, line - 1, line + (nx + 1), line - (nx + 1) ] data_penal[indptr_penal[line]:indptr_penal[line]] = [ 0.25, 0.25, 0.25, 0.25 ] #[-1.,-1.,-1.,-1.,+4.] return (np.array(data, dtype=np.float),np.array(indices, dtype=np.int),indptr),sF_coefs,\ (np.array(data_penal, dtype=np.float),np.array(indices_penal, dtype=np.int),indptr_penal),\ interp_points
def linearizeVelocity_pseudoCNi(indice_field, xg, yg, s_n, Or, ax): # mirror point makes BL velocity look bad on fixed cylinder case center = config.get_centers(s_n) flags_slice = config.get_flags_slice(indice_field, s_n) flags_slice_P = config.get_flags_slice(2, s_n) forcedP, projections = config.get_pseudo(indice_field, s_n) nint = range(len(forcedP)) fF = np.zeros( len(forcedP), dtype='int64,int64,int64,int64,int64,int64,float64,float64,float64') data = np.zeros(2 * len(forcedP), dtype='float64') IJ = np.zeros((2, 2 * len(forcedP)), dtype=np.int) fF8 = np.zeros(len(forcedP), dtype='float64') sF_coefs = np.empty((len(forcedP), 3)) sF_points = np.empty((len(forcedP), 4)) for n in nint: proj = projections[n][0], projections[n][1] n_x = projections[n][2] n_y = projections[n][3] pf = yg.get_i(forcedP[n], center[0], Lx, xg), yg.get_j(forcedP[n], center[1], Ly) anchor = pf layer = True coefs, goefs, p1, p2 = search_velocity(anchor, xg, yg, proj, flags_slice, Or, projections[n][2:4], layer) #FORCE sF_coefs[n, :] = goefs sF_points[n, :] = p1[0], p1[1], p2[0], p2[1] #sF_coefs[n,:] = np.round(sF_coefs[n,:],5) #coefs = np.round(coefs,5) #layer = True #coefs,goefs,p1,p2 = search_velocity(anchor,xg,yg,proj,flags_slice,Or,projections[n][2:4],layer) #BOUNDARY CONDITION fF[n] = pf[0],pf[1],p1[0],p1[1],p2[0],p2[1],\ coefs[1],coefs[2],coefs[0] pf_abs = yg.get_i_abs(forcedP[n]), yg.get_j_abs(forcedP[n]) #pf = xg.ind_perio(pf[0]),yg.ind_perio(pf[1]) p1[0] = xg.ind_perio(p1[0]) #+pf_abs[0]-pf[0]) p1[1] = yg.ind_perio(p1[1]) #+pf_abs[1]-pf[1]) p2[0] = xg.ind_perio(p2[0]) #+pf_abs[0]-pf[0]) p2[1] = yg.ind_perio(p2[1]) #+pf_abs[1]-pf[1]) #pf = pf_abs IJ_f = pf_abs[1] * (xg.shape()) + pf_abs[0] IJ_1 = p1[1] * (xg.shape()) + p1[0] IJ_2 = p2[1] * (xg.shape()) + p2[0] #if math.fabs(coefs[0])>300: if not ax is None: col = 'k' DY = 0. # if s_n==2: DY,col = +1.,'r' #print sF_coefs[n,:],coefs #print gn1*gn2 import matplotlib.pyplot as plt #here we load matplotlib, calling it 'plt' #pf = yg.get_i_abs(forcedP[n]), yg.get_j_abs(forcedP[n]) plt.plot([ xg.loc(pf[0] + 2), xg.loc(pf[0] - 2), xg.loc(pf[0]), xg.loc(pf[0]) ], [ yg.loc(pf[1]), yg.loc(pf[1]), yg.loc(pf[1] + 2), yg.loc(pf[1] - 2) ], '+', color='b') plt.plot([ xg.loc(pf[0] + 1), xg.loc(pf[0] - 1), xg.loc(pf[0]), xg.loc(pf[0]) ], [ yg.loc(pf[1]), yg.loc(pf[1]), yg.loc(pf[1] + 1), yg.loc(pf[1] - 1) ], '+', color='b') plt.plot([xg.loc(p1[0]), xg.loc(pf_abs[0]), xg.loc(p2[0])], [ yg.loc(p1[1]) + DY, yg.loc(pf_abs[1]) + DY, yg.loc(p2[1]) + DY ], color=col) plt.plot([xg.loc(p1[0]), xg.loc(p2[0]), CF.loc_perio(proj[0], Lx)], [ yg.loc(p1[1]) + DY, yg.loc(p2[1]) + DY, CF.loc_perio(proj[1], Ly) + DY ], 'o', color='k') plt.plot(xg.loc(pf_abs[0]), yg.loc(pf_abs[1]), 'o', color='g') plt.plot(CF.loc_perio(proj[0], Lx), CF.loc_perio(proj[1], Ly), '+', color='r') plt.plot([ CF.loc_perio(proj[0], Lx), CF.loc_perio(proj[0] + dx * n_x, Lx) ], [ CF.loc_perio(proj[1], Ly), CF.loc_perio(proj[1] + dx * n_y, Ly) ], color='k') #if np.amax(np.abs(np.array([gns,gn1,gn2])))>100.: print gns,gn1,gn2 #if True or np.amax(np.abs(coefs))>2.: print coefs fF8[n] = coefs[0] # CNi data[2 * n], IJ[0, 2 * n], IJ[1, 2 * n] = coefs[1], IJ_f, IJ_1 data[2 * n + 1], IJ[0, 2 * n + 1], IJ[1, 2 * n + 1] = coefs[2], IJ_f, IJ_2 #plt.show() solid = config.get_solidPops(s_n)[indice_field] indptr_penal, indices_penal, data_penal = np.zeros( xg.shape() * yg.shape() + 1, dtype=np.int), [], [] for IJs in solid: #ps = yg.get_i(IJs,center[0],Lx), yg.get_j(IJs,center[1],Ly) ps = yg.get_i_abs(IJs), yg.get_j_abs(IJs) #print ps #print yg.get_i_abs(IJs), yg.get_j_abs(IJs) #line = CF.IJ_ij_xg(ps[0],ps[1],xg,yg)#ps[1]*xg.shape()+ps[0] line = ps[1] * xg.shape() + ps[0] indptr_penal[line + 1:] += 5 if ps[0] == 0: # and indice_field==0: indices_penal[indptr_penal[line]:indptr_penal[line]] = [ line + 1, line + xg.shape() - 2, line + xg.shape(), line - xg.shape(), line ] #elif ps[0] == nx-1 and indice_field==0: # indices_penal[indptr_penal[line]:indptr_penal[line]] = [line-xg.shape()+2,line-1,line+xg.shape(),line-xg.shape(),line] elif ps[1] == 0: # and indice_field==1: indices_penal[indptr_penal[line]:indptr_penal[line]] = [ line + 1, line - 1, line + xg.shape(), line + (yg.shape() - 2) * xg.shape(), line ] #elif ps[1] == ny-1 and indice_field==1: # indices_penal[indptr_penal[line]:indptr_penal[line]] = [line+1,line-1,line-(yg.shape()-2)*xg.shape(),line-xg.shape(),line] else: indices_penal[indptr_penal[line]:indptr_penal[line]] = [ line + 1, line - 1, line + xg.shape(), line - xg.shape(), line ] data_penal[indptr_penal[line]:indptr_penal[line]] = [ 1., 1., 1., 1., -4. ] #[-1.,-1.,-1.,-1.,+4.] csr_penal = (0.5 * nu / dx**2 * np.array(data_penal, dtype=np.float), np.array(indices_penal, dtype=np.int), indptr_penal) mat_penal = csr_matrix(csr_penal, shape=(xg.shape() * yg.shape(), xg.shape() * yg.shape())) mat_ibm = csr_matrix( (data, IJ), shape=(xg.shape() * yg.shape(), xg.shape() * yg.shape())) return fF, sF_coefs, mat_penal, mat_ibm, fF8, sF_points