#! /usr/bin/env python # from fenics import * def mitchell10 ( ): #*****************************************************************************80 # ## mitchell10 sets up Mitchell test #10. # # Interior line singularity # -Laplace(u) = f on [-1,+1]x[-1,+1] # u = u0 on the boundary. # u0 = cos(pi*y/2) for x <= beta*(y+1) # = cos(pi*y/2)+(x-beta*(y+1))**alpha for beta*(y+1) < x # f = -Laplace(u). # # Discussion: # # Suggested parameter values: # * alpha = 2.5, beta = 0.0 # * alpha = 1.1, beta = 0.0 # * alpha = 1.5, beta = 0.6 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 August 2014 # # Author: # # John Burkardt # # Reference: # # William Mitchell, # A collection of 2D elliptic problems for testing adaptive # grid refinement algorithms, # Applied Mathematics and Computation, # Volume 220, 1 September 2013, pages 350-364. # import matplotlib.pyplot as plt # # Set parameters. # alpha = 2.5 beta = 0.0 # # Define a mesh of triangles on [-1,+1]x[-1,+1] # mesh = RectangleMesh ( -1.0, -1.0, +1.0, +1.0, 4, 4 ) # # Plot the mesh. # plot ( mesh, title = 'Mitchell Test 10 Mesh' ) filename = 'mitchell10_mesh.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.close ( ) # # Define the function space. # V = FunctionSpace ( mesh, "Lagrange", 1 ) # # Define the exact solution. # u0 = Expression ( "?" ) # # Apply the boundary condition to points which are on the boundary of the mesh. # def u0_boundary ( x, on_boundary ): return on_boundary # # The value to be used at Dirichlet boundary points is U0. # bc = DirichletBC ( V, u0, u0_boundary ) # # Define the variational problem. # u = TrialFunction ( V ) v = TestFunction ( V ) f = Expression ( "?" ) a = inner ( nabla_grad ( u ), nabla_grad ( v ) ) * dx L = f * v * dx # # Compute the solution. # u = Function ( V ) solve ( a == L, u, bc ) # # Plot the solution. # plot ( u ) return def mitchell10_test ( ): #*****************************************************************************80 # ## mitchell10_test tests mitchell10. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 October 2018 # # Author: # # John Burkardt # # # Report level = only warnings or higher. # level = 30 set_log_level ( level ) print ( '' ) print ( 'mitchell10_test:' ) print ( ' FENICS/Python version' ) print ( ' Mitchell test problem #10.' ) mitchell10 ( ) # # Terminate. # print ( '' ) print ( 'mitchell10_test:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): mitchell10_test ( )