Beispiel #1
0
def get_elementbasis_par(nx, ny, Nx, Ny, A, start_c, end_c):
    #### get multiscale partition of unity(mpi version)
    ##### A is the global stiffness matrix
    (local_bddof, local_left_nodes, local_right_nodes, local_bottom_nodes,
     local_top_nodes, free_nodes) = cg.getboundary_dof(nx, ny)
    n_coarseelement = end_c - start_c + 1
    msbasis = np.zeros((4, (nx + 1) * (ny + 1), n_coarseelement))
    I = np.zeros((n_coarseelement, (nx + 1) * (ny + 1)), dtype=np.int)
    cind = 0
    #for j in range(1, Ny+1):
    #for i in range(1, Nx+1):
    for ne in range(start_c, end_c + 1):
        i, j = index1dto2d(ne + 1, Nx, Ny)

        gi = cg.getCoarsenodeselementinside(i, j, Nx, Ny, nx, ny)
        #print gi
        localA = A[gi, :]
        localA = localA[:, gi]
        msbasis[:, :,
                cind] = cg.compute_msbasis(nx, ny, localA, local_bddof,
                                           local_left_nodes, local_right_nodes,
                                           local_bottom_nodes, local_top_nodes,
                                           free_nodes)
        I[cind, :] = gi
        cind = cind + 1
        #print cind

    return msbasis, I
Beispiel #2
0
print("FEM for poisson equation on uniform rectangle mesh, python 3 version ")
# mesh
Lx = 1.  # domain size in x direction
Ly = 1.  # domain size in y direction
nx = 256  # number of elements in x direction
ny = 128  # number of elements in y direction
hx = Lx / nx  # mesh size in x direction
hy = Ly / ny  # mesh size in y direction
nnx = nx + 1  # number of points in x dirction
nny = ny + 1  # number of points in y dirction
n_nodes = nnx * nny  #number of dof
n_elements = nx * ny  # bumber of element
print("number of elements in x direction is %d " % nx)
print("number of elements in y direction is %d " % ny)
(bdnodes, left_nodes, right_nodes, bottom_nodes, top_nodes,
 free_nodes) = cg.getboundary_dof(nnx - 1, nny - 1)
n_bdnodes = bdnodes.shape[0]
x = np.linspace(0, Lx, nnx)
y = np.linspace(0, Ly, nny)
xp, yp = np.meshgrid(x, y)
xp = np.reshape(xp, nnx * nny)
yp = np.reshape(yp, nnx * nny)
## coeff of the general elliptic operator, constant here
stiff_coeff = np.ones((nny - 1, nnx - 1))

## assemble global matrix and force
print("Assembling FEM matrix... ")
local_massmatrix = cg.local_mass(hx, hy)  ## element stiff matrix
local_stiffmatrix = cg.local_stiff(hx, hy)  ## element mass matrix
Astiff = cg.assembleweightmatrix(stiff_coeff, local_stiffmatrix)
Massforce = cg.assembleweightmatrix(np.ones((nny - 1, nnx - 1)),
Beispiel #3
0
plt.close('all')
print ""
print " FEM for elliptic equation on uniform mesh "
print " Python2 version "
print " zero Dirichlet boundary condition \n"
plt.close('all')
## mesh
Lx=1.;Ly=1.;Nx=1;Ny=1;nx=100;ny=100
#Lx=1.;Ly=1.;Nx=1;Ny=1;nx=3;ny=2
Hx=Lx/Nx;Hy=Ly/Ny;hx=Lx / (nx*Nx);hy=Ly/(ny*Ny)
nnx=nx*Nx+1;nny=ny*Ny+1
n_nodes=(nx*Nx+1)*(ny*Ny+1)
n_elements=nx*ny*Nx*Ny
#print "hx is % 2.2f " %  (hx)
(bdnodes,left_nodes,right_nodes,bottom_nodes,top_nodes,free_nodes)=cg.getboundary_dof(nnx-1,nny-1);n_bdnodes=bdnodes.shape[0]
x = np.linspace(hx/2, Lx-hx/2, nx)
y = np.linspace(hy/2, Ly-hy/2, ny)
xc, yc = np.meshgrid(x, y)

## model
'''
high_value=np.power(10,6)
stiff_coeff=np.ones((nny-1,nnx-1))
stiff_coeff[ ny+1:ny*2,nx+1:(Nx-2)*nx]=high_value
stiff_coeff[ ny*3:ny*4-2,nx+1:(Nx-2)*nx]=high_value
stiff_coeff[ ny*5:ny*6-2,nx+5:(Nx-3)*nx]=high_value
stiff_coeff[ ny*7:ny*8-2,nx+5:(Nx-3)*nx]=high_value
'''
stiff_coeff=np.ones((nny-1,nnx-1))
#stiff_coeff=cg.loadmatrix('k1.txt')
Beispiel #4
0
if rank ==0:
	print ""
	print " GMsFEM for elliptic equation on uniform mesh "
	print " Python version "
	print " zero Dirichlet boundary condition "
	print " use mpi when computing the partition of unity and eigenbasis"
	print "\n"
## mesh
Lx=1.;Ly=1.;Nx=10;Ny=Nx;nx=10;ny=nx
#Lx=1.;Ly=1.;Nx=5;Ny=5;nx=200;ny=200
Hx=Lx/Nx;Hy=Ly/Ny;hx=Lx / (nx*Nx);hy=Ly/(ny*Ny)
nnx=nx*Nx+1;nny=ny*Ny+1
n_nodes=(nx*Nx+1)*(ny*Ny+1)
n_elements=nx*ny*Nx*Ny
#print "hx is % 2.2f " %  (hx)
(bdnodes,left_nodes,right_nodes,bottom_nodes,top_nodes,free_nodes)=cg.getboundary_dof(nny-1,nnx-1);n_bdnodes=bdnodes.shape[0]
x = np.linspace(hx/2, Lx-hx/2, nx)
y = np.linspace(hy/2, Ly-hy/2, ny)
xc, yc = np.meshgrid(x, y)
nbasis=10##------------------------------------------------------------------------------------------
if nx==10 and ny==10 and Nx==10 and Ny==10:
 stiff_coeff=cg.loadmatrix('k1.txt')
 stiff_coeff=np.reshape(stiff_coeff,(100,100)).transpose()
else:
 stiff_coeff=np.ones((nny-1,nnx-1))
local_massmatrix=cg.local_mass(hx,hy)
local_stiffmatrix=cg.local_stiff(hx,hy)
Astiff=cg.assembleweightmatrix(stiff_coeff,local_stiffmatrix)
## assemble global matrix and force
if rank ==0:
	print " Assembling fine scale matrix... "