Ejemplo n.º 1
0
def compare(hc, hnc, Nsphere):
    couleurs = colors.cnames.items()
    size = 6
    fig1, ax1 = plt.subplots(figsize=((size + 3,
                                       (1. - 0) / (1. - 0) * (size + 3))),
                             dpi=110)

    vmvx, vmvy, vmpx, vmpy, YS, XS = hc
    #delt = 3.3e-8
    #print delt
    #vmvx-=delt
    #vmpx-=delt
    #vmvx*=1./2.39e-6
    #vmpx*=1./2.39e-6
    for sn in [3]:
        #if sn==0:
        couleur = couleurs[sn][0]
        x, y = config.get_centers(sn)
        #ax1.plot(vmvy[:,sn]+vmpy[:,sn],'-',label='FY '+str(x)+','+str(y),color='g',lw=2.)
        ax1.plot(vmvx[:, sn] + vmpx[:, sn],
                 '-',
                 label='FX ' + str(x) + ',' + str(y),
                 color='g',
                 lw=2.)
    vmvx, vmvy, vmpx, vmpy, YS, XS = hnc
    #vmvx*=1./2.39e-6
    #vmpx*=1./2.39e-6
    for sn in [3]:
        #if sn==0:
        couleur = couleurs[sn][0]
        x, y = round(config.get_centers(sn)[0],
                     2), round(config.get_centers(sn)[1], 2)
        #ax1.plot(vmvy[:,sn]+vmpy[:,sn],'-',label='FY '+str(x)+','+str(y),color='k',lw=1.)
        ax1.plot(vmvx[:, sn] + vmpx[:, sn],
                 '-',
                 label='FY ' + str(x) + ',' + str(y),
                 color='k',
                 lw=2.)

    #fig1, ax1 = plt.subplots(figsize=((size+3, (1.-0)/(1.-0)*(size+3))), dpi=110)

    #vmvx,vmvy,vmpx,vmpy,YS,XS = hc
    #print YS.shape
    #for sn in [3]:
    #       couleur = couleurs[sn][0]
    #       x,y=config.get_centers(sn)
    #ax1.plot(vmvy[:,sn]+vmpy[:,sn],'-',label='FY '+str(x)+','+str(y),color='g',lw=2.)
    #       ax1.plot(YS[:,sn],vmvx[:,sn]+vmpx[:,sn],'-',label='FX '+str(x)+','+str(y),color='g',lw=2.)
    #vmvx,vmvy,vmpx,vmpy,YS,XS = hnc
    #for sn in [3]:
    #       couleur = couleurs[sn][0]
    #       x,y=round(config.get_centers(sn)[0],2),round(config.get_centers(sn)[1],2)
    #ax1.plot(vmvy[:,sn]+vmpy[:,sn],'-',label='FY '+str(x)+','+str(y),color='k',lw=1.)
    #       ax1.plot(YS[:,sn],vmvx[:,sn]+vmpx[:,sn],'-',label='FY '+str(x)+','+str(y),color='k',lw=2.)

    return
Ejemplo n.º 2
0
def plot_stencils(p1, p2, pf, proj, s_n, xg, yg):  #,xp,yp):
    center = config.get_centers(s_n)
    #print center
    #circle=plt.Circle((center[0],center[1]),R,color='k',fill=False)
    size = 6
    fig, ax = plt.subplots(figsize=((size + 3,
                                     (1. - 0) / (1. - 0) * (size + 3))),
                           dpi=110)
    #fig.gca().add_artist(circle)
    #ax.add_artist(circle)
    config.plotSphere(ax, plt, False, center)
    #for i in range(5):
    #    ax.plot([xp.loc(pf[0])+i*dx+dx/2.,xp.loc(pf[0])+i*dx+dx/2.],[yp.loc(pf[1])-20*dx,yp.loc(pf[1])+20*dx],color='grey')
    #    ax.plot([xp.loc(pf[0])-i*dx+dx/2.,xp.loc(pf[0])-i*dx+dx/2.],[yp.loc(pf[1])-20*dx,yp.loc(pf[1])+20*dx],color='grey')
    #    ax.plot([xp.loc(pf[0])-20*dx,xp.loc(pf[0])+20*dx],[yp.loc(pf[1])-i*dx+dx/2.,yp.loc(pf[1])-i*dx+dx/2.],color='grey')
    #    ax.plot([xp.loc(pf[0])-20*dx,xp.loc(pf[0])+20*dx],[yp.loc(pf[1])+i*dx+dx/2.,yp.loc(pf[1])+i*dx+dx/2.],color='grey')

    for p in [p1, p2]:
        ax.plot([xg.loc(p[0])], [yg.loc(p[1])], '+', color='k')

    ax.plot([proj[0]], [proj[1]], 'x', color='r')
    cadre = 2
    ax.set_xlim([proj[0] - cadre * dx, proj[0] + cadre * dx])
    ax.set_ylim([proj[1] - cadre * dx, proj[1] + cadre * dx])

    ax.plot([xg.loc(pf[0])], [yg.loc(pf[1])], '+', color='g')

    plt.show()
    return
Ejemplo n.º 3
0
def plot_cutcell(cell, center, sn, toplot):
    #center = config.get_centers(sn)
    size = 6
    fig, ax = plt.subplots(figsize=((size + 3,
                                     (1. - 0) / (1. - 0) * (size + 3))),
                           dpi=110)
    #circle=plt.Circle((center[0],center[1]),R,color='k',fill=False)
    #fig.gca().add_artist(circle)
    #ax.add_artist(circle)

    config.plotSphere(ax, plt, False, config.get_centers(sn))

    for i in range(len(cell)):
        ax.plot([cell[i][0], cell[i - 1][0]], [cell[i][1], cell[i - 1][1]],
                '+',
                color='red')
    ax.plot([center[0]], [center[1]], 'o', color='g')

    for i in range(1, 3):
        ax.plot([center[0]], [center[1] + i * dx / 2.], 'o', color='k')
        ax.plot([center[0]], [center[1] - i * dx / 2.], 'o', color='k')
        ax.plot([center[0] + i * dx / 2.], [center[1]], 'o', color='k')
        ax.plot([center[0] - i * dx / 2.], [center[1]], 'o', color='k')

    ax.plot([toplot[0]], [toplot[1]], 'o', color='b')

    #  ax.set_xlim([center[0]-2*dx,center[0]+2*dx])
    #  ax.set_ylim([center[1]-2*dx,center[1]+2*dx])

    plt.show()
    return
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
def pointsInSphere(xg, yg, forced, pseudo, s_n):
    center = config.get_centers(s_n)
    newlyInSphere = set()
    cleared = set()
    for IJ in forced:
        if isinnodule(s_n,xg.loc_rel(yg.get_i(IJ, center[0], Lx,xg), center[0], Lx),\
                          yg.loc_rel(yg.get_j(IJ, center[1], Ly), center[1], Ly)):
            newlyInSphere.add(IJ)
    for IJ in pseudo:
        if not isinnodule(s_n,xg.loc_rel(yg.get_i(IJ, center[0], Lx,xg), center[0], Lx),\
                              yg.loc_rel(yg.get_j(IJ, center[1], Ly), center[1], Ly)):
            cleared.add(IJ)
    return newlyInSphere, cleared
Ejemplo n.º 6
0
def pointsInSphere_first(xg, yg, s_n):
    inSphere = set()
    center = config.get_centers(s_n)
    xmin, xmax = xg.fluids()
    ymin, ymax = yg.fluids()
    for iX in range(xmin, xmax):
        for iY in range(ymin, ymax):
            x = xg.loc_rel(iX, center[0], Lx)
            y = yg.loc_rel(iY, center[1], Ly)
            if isinnodule(s_n, x, y):
                IJ = iX * yg.shape() + iY
                inSphere.add(IJ)
    return inSphere
Ejemplo n.º 7
0
def reshape_psisourceTF(u, v, xp, yp, psisource, coefs_for_psisource,
                        local_bornes, local_sphere_numbers):

    s_n_loc = 0
    for s_n in local_sphere_numbers:
        center = config.get_centers(s_n)
        origine = local_bornes[s_n_loc][[0, 2]]
        for info in coefs_for_psisource[s_n_loc]:
            if not info == None:
                psisource[s_n_loc][yp.get_j(info[-1], center[1], Ly) -
                                   origine[1],
                                   yp.get_i(info[-1], center[0], Lx, xp) -
                                   origine[0]] = 0.
                psisource[s_n_loc][yp.get_j(info[-1],center[1],Ly)-origine[1], yp.get_i(info[-1],center[0],Lx,xp)-origine[0]] =\
                                   compute_massBalanceTF(u[s_n_loc],v[s_n_loc],info[:-1],s_n,origine)
        s_n_loc += 1
    return
Ejemplo n.º 8
0
def savepicture(i, fig):
    uu = (u[1:, :] + u[:-1, :]) / 2
    vv = (v[:, 1:] + v[:, :-1]) / 2
    V = np.sqrt(uu**2 + vv**2)
    #im = plt.imshow(V, interpolation='nearest', origin='lower', extent=(0.0,Lx,0.0,Ly))
    im = plt.imshow(p[1:-1, 1:-1],
                    interpolation='nearest',
                    origin='lower',
                    cmap=plt.cm.autumn,
                    extent=(0.0, Lx, 0.0, Ly))
    #CBI = plt.colorbar(im, orientation='vertical', shrink=0.6)
    step = 1
    Xg, Yg = np.meshgrid(x, y)
    plt.quiver(Xg[::step, ::step], Yg[::step, ::step], uu[::step, ::step],
               vv[::step, ::step])  ##plotting velocity
    centers = config.get_centers()
    for center in centers:
        circle = plt.Circle((center[0], center[1]), R, color='k', fill=False)
        #fig.gca().add_artist(circle)
    plt.xlabel('')
    plt.ylabel('')
    plt.savefig('osc' + '%04d.png' % i, dpi=150)
    fig.clear()
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
def isinnodule(s_n, x, y):
    center = config.get_centers(s_n)
    DX = x - center[0]
    DY = y - center[1]
    r2 = DX**2 + DY**2
    return round(r2 / R**2, 6) <= 1.
Ejemplo n.º 13
0
def isinsolid(point, normal, s_n):
    center = config.get_centers(s_n)
    scalar_prod = CF.scalr_prod(normal, center[0], center[1], point[0],
                                point[1])
    #return (scalar_prod-R <= 0.)
    return round(scalar_prod / R, 6) <= 1.
Ejemplo n.º 14
0
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