from pygmsh import generate_mesh from pygmsh.built_in import Geometry geom = Geometry() circle = geom.add_circle([0.] * 3, 1., .5**3) geom.add_physical(circle.line_loop.lines, 'circle') geom.add_physical(circle.plane_surface, 'disk') m = from_meshio(generate_mesh(geom, dim=2)) basis = InteriorBasis(m, ElementTriP2()) A = asm(laplace, basis) b = asm(unit_load, basis) x = solve(*condense(A, b, D=basis.find_dofs())) area = sum(b) k = b @ x / area**2 k1, = basis.interpolator(x)(np.zeros((2, 1))) / area if __name__ == '__main__': from skfem.visuals.matplotlib import plot3, show print('area = {:.4f} (exact = {:.4f})'.format(area, np.pi)) print('k = {:.5f} (exact = 1/8/pi = {:.5f})'.format(k, 1/np.pi/8)) print("k' = {:.5f} (exact = 1/4/pi = {:.5f})".format(k1, 1/np.pi/4)) plot3(basis, x) show()
@LinearForm def rhs(v, p): w = p['prev'] return dot(grad(w), grad(v)) / np.sqrt(1 + dot(grad(w), grad(w))) basis = Basis(m, ElementTriP1()) x = basis.zeros() D = m.boundary_nodes() x[D] = np.sin(np.pi * m.p[0, D]) for itr in range(100): w = basis.interpolate(x) J = asm(jacobian, basis, prev=w) F = asm(rhs, basis, prev=w) x_prev = x.copy() x += 0.7 * solve(*condense(J, -F, D=D)) if np.linalg.norm(x - x_prev) < 1e-8: break if __name__ == "__main__": print(np.linalg.norm(x - x_prev)) if __name__ == "__main__": from skfem.visuals.matplotlib import plot3, show plot3(m, x) show()
def runTest(self): m = self.mesh_type() plot3(m, m.p[0])