예제 #1
0
파일: test_asm.py 프로젝트: mfkiwl/sp.fem
    def runTest(self):
        # solve Poisson by standard P1 method
        # and P1(dg) interior penalty method.
        #
        # this will test interior facet assembly and normal
        # vectors.
        from spfem.mesh import MeshTri
        from spfem.asm import AssemblerElement
        from spfem.element import ElementTriP1, ElementTriDG
        from spfem.utils import direct
        import numpy as np

        m = MeshTri()
        m.refine(3)

        e = ElementTriDG(ElementTriP1())
        e1 = ElementTriP1()
        a = AssemblerElement(m, e)
        a1 = AssemblerElement(m, e1)
        b1 = AssemblerElement(m, e1, e)

        A = a.iasm(lambda du, dv: du[0]*dv[0] + du[1]*dv[1])
        M = a.iasm(lambda u, v: u*v)
        b = a.iasm(lambda v, x: np.sin(2.0*np.pi*x[0])*v)

        B1 = a.fasm(lambda u1,u2,v1,v2,h: 1/h*(u1-u2)*(v1-v2), interior=True)
        B2 = a.fasm(lambda u,v,h: 1/h*u*v)
        B=B1+B2

        C1 = a.fasm(lambda du1,du2,v1,v2,n: 0.5*(du1[0]*n[0]*v1 - du2[0]*n[0]*v2
                                           + du1[1]*n[1]*v1 - du2[1]*n[1]*v2), interior=True)
        C2 = a.fasm(lambda du,v,n: (du[0]*n[0]+du[1]*n[1])*v)
        C=C1+C2

        D = C+C.T

        eps = 1e-3
        eta = 1e5
        x = direct(A + eta*B - 0*D, b)

        K = a1.iasm(lambda du, dv: du[0]*dv[0] + du[1]*dv[1])
        f = a1.iasm(lambda v, x: np.sin(2.0*np.pi*x[0])*v)

        y = direct(K, f, I=m.interior_nodes())

        P = b1.iasm(lambda u,v: u*v)

        self.assertAlmostEqual(np.linalg.norm(x-direct(M,P*y)),0,places=4)
예제 #2
0
def C2(T):
    trT = T[0, 0] + T[1, 1]
    return np.array([[2. * mu2 * T[0, 0] + lam2 * trT, 2. * mu2 * T[0, 1]],
                     [2. * mu2 * T[1, 0], 2. * mu2 * T[1, 1] + lam2 * trT]])


def dudv1(du, dv):
    return ddot(C1(Eps(du)), Eps(dv))


def dudv2(du, dv):
    return ddot(C2(Eps(du)), Eps(dv))


K1 = a1.iasm(dudv1)
K2 = a2.iasm(dudv2)

B1low = m1.nodes_satisfying(lambda x, y: y == -1.0)
B1up = m1.nodes_satisfying(lambda x, y: (y == 0.0) * (x <= scale) *
                           (x >= -scale))
B2up = m2.nodes_satisfying(lambda x, y: y == 1.0)
B2low = m2.nodes_satisfying(lambda x, y: y == 0.0)


def glue_dofs(Ax, Ay, bx, by, ix, iy, Ix, Iy):
    import scipy.sparse as spsp

    indices1 = np.arange(Ax.shape[0])
    indices2 = np.arange(Ay.shape[0])
예제 #3
0
    trT=T[0,0]+T[1,1]
    return np.array([[2.*mu1*T[0,0]+lam1*trT,2.*mu1*T[0,1]],
                     [2.*mu1*T[1,0],2.*mu1*T[1,1]+lam1*trT]])

def C2(T):
    trT=T[0,0]+T[1,1]
    return np.array([[2.*mu2*T[0,0]+lam2*trT,2.*mu2*T[0,1]],
                     [2.*mu2*T[1,0],2.*mu2*T[1,1]+lam2*trT]])

def dudv1(du,dv):
    return ddot(C1(Eps(du)),Eps(dv))

def dudv2(du,dv):
    return ddot(C2(Eps(du)),Eps(dv))

K1=a1.iasm(dudv1)
K2=a2.iasm(dudv2)

B1low=m1.nodes_satisfying(lambda x,y:y==-1.0)
B1up=m1.nodes_satisfying(lambda x,y:(y==0.0)*(x<=scale)*(x>=-scale))
B2up=m2.nodes_satisfying(lambda x,y:y==1.0)
B2low=m2.nodes_satisfying(lambda x,y:y==0.0)

def glue_dofs(Ax,Ay,bx,by,ix,iy,Ix,Iy):
    import scipy.sparse as spsp

    indices1=np.arange(Ax.shape[0])
    indices2=np.arange(Ay.shape[0])

    ix1=np.setdiff1d(indices1,ix)
    ix2=ix