def runTest(self): F=lambda x,y: 100.0*((x>=0.4)&(x<=0.6)&(y>=0.4)&(y<=0.6)) G=lambda x,y: (y==0)*1.0+(y==1)*(-1.0) a=fasm.AssemblerElement(self.mesh,felem.ElementTriP1()) dudv=lambda du,dv: du[0]*dv[0]+du[1]*dv[1] K=a.iasm(dudv) uv=lambda u,v: u*v B=a.fasm(uv) fv=lambda v,x: F(x[0],x[1])*v f=a.iasm(fv) gv=lambda v,x: G(x[0],x[1])*v g=a.fasm(gv) D=np.nonzero(self.mesh.p[0,:]==0)[0] I=np.setdiff1d(np.arange(0,self.mesh.p.shape[1]),D) x=np.zeros(K.shape[0]) x[I]=scipy.sparse.linalg.spsolve(K[np.ix_(I,I)]+B[np.ix_(I,I)], f[I]+g[I]) self.assertAlmostEqual(np.max(x),1.89635971369,places=2)
def runTest(self): m=fmsh.MeshTri() m.refine(4) # split mesh into two sets of triangles I1=np.arange(m.t.shape[1]/2) I2=np.setdiff1d(np.arange(m.t.shape[1]),I1) bix=m.boundary_facets() bix1=bix[0:len(bix)/2] bix2=np.setdiff1d(bix,bix1) a=fasm.AssemblerElement(m,felem.ElementTriP1()) def dudv(du,dv): return du[0]*dv[0]+du[1]*dv[1] A=a.iasm(dudv) A1=a.iasm(dudv,tind=I1) A2=a.iasm(dudv,tind=I2) B=a.fasm(dudv) B1=a.fasm(dudv,find=bix1) B2=a.fasm(dudv,find=bix2) f=a.iasm(lambda v: 1*v) I=m.interior_nodes() x=np.zeros(A.shape[0]) x[I]=scipy.sparse.linalg.spsolve((A+B)[I].T[I].T,f[I]) X=np.zeros(A.shape[0]) X[I]=scipy.sparse.linalg.spsolve((A1+B1)[I].T[I].T+(A2+B2)[I].T[I].T,f[I]) self.assertAlmostEqual(np.linalg.norm(x-X),0.0,places=10)
def runTest(self): bilin=lambda u,v,du,dv,x,h: du[0]*dv[0]+du[1]*dv[1] lin=lambda v,dv,x,h: 1*v a=fasm.AssemblerElement(self.mesh,felem.ElementTriP1()) A=a.iasm(bilin) f=a.iasm(lin) x=np.zeros(A.shape[0]) I=self.I x[I]=scipy.sparse.linalg.spsolve(A[np.ix_(I,I)],f[I]) self.assertAlmostEqual(np.max(x),0.073614737354524146)
def runTest(self): m=fmsh.MeshTri() m.refine(5) a=fasm.AssemblerAbstract(m,felem.AbstractElementTriPp(1)) b=fasm.AssemblerElement(m,felem.ElementTriP1()) A=a.iasm(lambda u,v: u*v) B=b.iasm(lambda u,v: u*v) self.assertAlmostEqual(np.sum(A.data),np.sum(B.data),places=10) C=a.iasm(lambda du,v: du[0]*v) D=b.iasm(lambda du,v: du[0]*v) self.assertAlmostEqual(C.data[0],D.data[0],places=10)
def runTest(self): m = spfem.mesh.MeshTri() m.refine(2) e = felem.ElementTriP1() a = fasm.AssemblerElement(m, e) N1 = a.fasm(lambda v, n: n[0] * v, normals=True) N2 = a.fasm(lambda v, n: n[1] * v, normals=True) vec1 = np.ones(N1.shape[0]) vec2 = np.zeros(N1.shape[0]) self.assertAlmostEqual(N1.dot(vec1) + N2.dot(vec2), 0.0) self.assertAlmostEqual(N1.dot(vec2) + N2.dot(vec1), 0.0) self.assertAlmostEqual(N1.dot(vec1) + N2.dot(vec1), 0.0) self.assertAlmostEqual(N1.dot(vec2) + N2.dot(vec2), 0.0)
def runTest(self): m=fmsh.MeshTri() m.refine(3) a=fasm.AssemblerElement(m,felem.ElementTriP1()) def G(x,y): return np.sin(np.pi*x) u=G(m.p[0,:],m.p[1,:]) # interpolate just the values and compare def v1(v,w): return w[0]*v def v2(u,v): return u*v f=a.fasm(v1,interp={0:u}) A=a.fasm(v2) self.assertAlmostEqual(np.linalg.norm(f-A*u),0.0,places=10)
def runTest(self): mesh=self.mesh a=fasm.AssemblerElement(self.mesh,felem.ElementTriP1()) D=self.D I=self.I def G(x,y): return np.sin(np.pi*x) u=G(mesh.p[0,:],mesh.p[1,:]) # interpolate just the values and compare def v1(v,w): return w[0]*v def v2(u,v): return u*v f=a.iasm(v1,interp={0:u}) A=a.iasm(v2) self.assertAlmostEqual(np.linalg.norm(f-A*u),0.0,places=10)
def runTest(self): I=self.I D=self.D a=fasm.AssemblerElement(self.mesh,felem.ElementTriP1()) def dudv(du,dv): return du[0]*dv[0]+du[1]*dv[1] K=a.iasm(dudv) def fv(v,x): return 2*np.pi**2*np.sin(np.pi*x[0])*np.sin(np.pi*x[1])*v f=a.iasm(fv) x=np.zeros(K.shape[0]) x[I]=scipy.sparse.linalg.spsolve(K[np.ix_(I,I)],f[I]) def truex(): X=self.mesh.p[0,:] Y=self.mesh.p[1,:] return np.sin(np.pi*X)*np.sin(np.pi*Y) self.assertAlmostEqual(np.max(x-truex()),0.0,places=3)
def runTest(self): mesh = fmsh.MeshTri() mesh.refine(2) def G(x, y): return x**3 * np.sin(20.0 * y) def U(x): return G(x[0], x[1]) def dUdx(x): return 3.0 * x[0]**2 * np.sin(20.0 * x[1]) def dUdy(x): return 20.0 * x[0]**3 * np.cos(20.0 * x[1]) dU = {0: dUdx, 1: dUdy} def dudv(du, dv): return du[0] * dv[0] + du[1] * dv[1] gamma = 100 def uv(u, v, du, dv, x, h, n): return gamma * 1 / h * u * v - du[0] * n[0] * v - du[1] * n[ 1] * v - u * dv[0] * n[0] - u * dv[1] * n[1] def fv(v, dv, x): return (-6.0 * x[0] * np.sin(20.0 * x[1]) + 400.0 * x[0]**3 * np.sin(20.0 * x[1])) * v def gv(v, dv, x, h, n): return G(x[0], x[1]) * v + gamma * 1 / h * G( x[0], x[1]) * v - dv[0] * n[0] * G( x[0], x[1]) - dv[1] * n[1] * G(x[0], x[1]) hs = np.array([]) errs = np.array([]) for itr in range(4): mesh.refine() a = fasm.AssemblerElement(mesh, felem.ElementTriP1()) D = mesh.boundary_nodes() I = mesh.interior_nodes() K = a.iasm(dudv) B = a.fasm(uv, normals=True) f = a.iasm(fv) g = a.fasm(gv, normals=True) x = np.zeros(K.shape[0]) x = spsolve(K + B, f + g) hs = np.append(hs, mesh.param()) errs = np.append(errs, np.sqrt(a.L2error(x, U)**2 + a.H1error(x, dU)**2)) pfit = np.polyfit(np.log10(hs), np.log10(errs), 1) # check that the convergence rate matches theory self.assertTrue(pfit[0] >= 0.99)