[docs]deftest_mass_matrix_exactly_integrated(self):UNodal=np.ones(3)# value of U doesn't matterquadRule=QuadratureRule.create_quadrature_rule_on_triangle(degree=2)stateVar=Noneshape,shapeGrad=Interpolants.compute_shapes(self.parentElement,quadRule.xigauss)vol=FunctionSpace.compute_element_volumes(self.coords,self.conn,self.parentElement,shape,quadRule.wgauss)deff(u,gradu,state,X):return0.5*u*ucompute_mass=jax.hessian(lambdaU:FunctionSpace.integrate_element(U,self.coords,stateVar,shape,shapeGrad,vol,self.conn,f,modify_element_gradient=FunctionSpace.default_modify_element_gradient))M=compute_mass(UNodal)area=0.5*np.cross(self.coords[1,:]-self.coords[0,:],self.coords[2,:]-self.coords[0,:])MExact=area/12.0*np.array([[2.,1.,1.],[1.,2.,1.],[1.,1.,2.]])self.assertTrue(np.allclose(M,MExact,atol=1e-14,rtol=1e-10))
[docs]deftest_mass_matrix_inexactly_integrated_with_low_order_quadrature(self):UNodal=np.ones(3)# value of U doesn't matterquadRule=QuadratureRule.create_quadrature_rule_on_triangle(degree=1)stateVar=Noneshape,shapeGrad=Interpolants.compute_shapes(self.parentElement,quadRule.xigauss)vol=FunctionSpace.compute_element_volumes(self.coords,self.conn,self.parentElement,shape,quadRule.wgauss)deff(u,gradu,state,X):return0.5*u*ucompute_mass=jax.hessian(lambdaU:FunctionSpace.integrate_element(U,self.coords,stateVar,shape,shapeGrad,vol,self.conn,f,modify_element_gradient=FunctionSpace.default_modify_element_gradient))M=compute_mass(UNodal)area=0.5*np.cross(self.coords[1,:]-self.coords[0,:],self.coords[2,:]-self.coords[0,:])MExact=area/12.0*np.array([[2.,1.,1.],[1.,2.,1.],[1.,1.,2.]])self.assertFalse(np.allclose(M,MExact,atol=1e-14,rtol=1e-10))
[docs]defsetUp(self):self.quadratureRule=QuadratureRule.create_quadrature_rule_on_triangle(degree=1)# meshself.Nx=7self.Ny=7self.xRange=[0.,1.]self.yRange=[0.,1.]self.targetDispGrad=np.array([[0.1,-0.2],[0.4,-0.1]])self.mesh,self.U=self.create_mesh_and_disp(self.Nx,self.Ny,self.xRange,self.yRange,lambdax:self.targetDispGrad.dot(x))# function spaceself.fs=FunctionSpace.construct_function_space(self.mesh,self.quadratureRule)nElements=Mesh.num_elements(self.mesh)nQuadPoints=len(self.quadratureRule)self.state=np.zeros((nElements,nQuadPoints,1))self.props=np.array([1.,0.3])self.dt=0.0
[docs]deftest_integrate_linear_field_single_point_quadrature(self):Ix=FunctionSpace.integrate_over_block(self.fs,self.U,self.state,self.props,self.dt,lambdau,gradu,state,props,X,dt:gradu[0,0],self.mesh.blocks['block'])# displacement at x=1 should match integralidx=np.argmax(self.mesh.coords[:,0])expected=self.U[idx,0]*(self.yRange[1]-self.yRange[0])self.assertNear(Ix,expected,14)Iy=FunctionSpace.integrate_over_block(self.fs,self.U,self.state,self.props,self.dt,lambdau,gradu,state,props,X,dt:gradu[1,1],self.mesh.blocks['block'])idx=np.argmax(self.mesh.coords[:,1])expected=self.U[idx,1]*(self.xRange[1]-self.xRange[0])self.assertNear(Iy,expected,14)
[docs]defsetUp(self):self.quadratureRule=QuadratureRule.create_quadrature_rule_on_triangle(degree=2)# meshself.Nx=7self.Ny=7self.xRange=[0.,1.]self.yRange=[0.,1.]self.targetDispGrad=np.array([[0.1,-0.2],[0.4,-0.1]])self.mesh,self.U=self.create_mesh_and_disp(self.Nx,self.Ny,self.xRange,self.yRange,lambdax:self.targetDispGrad.dot(x))# function spaceself.fs=FunctionSpace.construct_function_space(self.mesh,self.quadratureRule)nElements=Mesh.num_elements(self.mesh)nQuadPoints=len(self.quadratureRule)self.state=np.zeros((nElements,nQuadPoints,))self.props=np.array([1.,0.3])self.dt=0.0
[docs]deftest_integrate_over_half_block(self):nElements=Mesh.num_elements(self.mesh)# this test will only work with an even number of elements# put this in so that if test is modified to odd number,# we understand why it failsself.assertEqual(nElements%2,0)blockWithHalfTheVolume=slice(0,nElements//2)integral=FunctionSpace.integrate_over_block(self.fs,self.U,self.state,self.props,self.dt,lambdau,gradu,state,props,X,dt:1.0,blockWithHalfTheVolume)self.assertNear(integral,1.0/2.0,14)
[docs]deftest_integrate_over_half_block_indices(self):nElements=Mesh.num_elements(self.mesh)# this test will only work with an even number of elements# put this in so that if test is modified to odd number,# we understand why it failsself.assertEqual(nElements%2,0)blockWithHalfTheVolume=np.arange(nElements//2)integral=FunctionSpace.integrate_over_block(self.fs,self.U,self.state,self.props,self.dt,lambdau,gradu,state,props,X,dt:1.0,blockWithHalfTheVolume)self.assertNear(integral,1.0/2.0,14)
[docs]defsetUp(self)->None:self.quadratureRule=QuadratureRule.create_quadrature_rule_on_triangle(degree=2)# meshself.Nx=7self.Ny=7self.xRange=[0.,3.]self.yRange=[0.,1.]self.A=np.array([[0.1,-0.2],[0.4,-0.1]])self.b=2.5self.mesh,self.U=self.create_mesh_and_disp(self.Nx,self.Ny,self.xRange,self.yRange,lambdax:np.array([0.0,x[0]]))# function spaceself.fs=FunctionSpace.construct_function_space(self.mesh,self.quadratureRule)nElements=Mesh.num_elements(self.mesh)nQuadPoints=len(self.quadratureRule)self.state=np.zeros((nElements,nQuadPoints,))self.props=np.array([1.,0.3])self.dt=0.0