#! /usr/bin/env python # from fenics import * def mitchell07 ( ): #*****************************************************************************80 # ## mitchell07 sets up Mitchell test #7. # # Boundary line singularity # -Laplace(u) = f on the unit square. # u = u0 on the boundary. # u0 = x^alpha # f = - alpha * ( alpha - 1 ) * x^(alpha-2) # # Discussion: # # The parameter alpha should be 0.5 or greater. It determines the # strength of the singularity. # # Suggested parameter values: # * alpha = 0.6 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 24 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 = 0.6 # # Divide the unit square [0,1]x[0,1] into a 4x4 mesh of quadrilaterals, and # split each into triangles. # mesh = UnitSquareMesh ( 4, 4 ) # # Plot the mesh. # plot ( mesh, title = 'Mitchell Test 07 Mesh' ) filename = 'mitchell07_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 ( "pow ( x[0], alpha )", alpha = alpha, degree = 10 ) # # 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 ) # # The right hand side function is simply -Laplacian(u0). # We have a singularity in F at X = 0. # f = Expression ( "- alpha * ( alpha - 1.0 ) * pow ( x[0]+0.000001, alpha - 2 )", alpha = alpha, degree = 10 ) # 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 mitchell07_test ( ): #*****************************************************************************80 # ## mitchell07_test tests mitchell07. # # 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 ( 'mitchell07_test:' ) print ( ' FENICS/Python version' ) print ( ' Mitchell test problem #7.' ) mitchell07 ( ) # # Terminate. # print ( '' ) print ( 'mitchell07_test:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): mitchell07_test ( )