#! /usr/bin/env python # from fenics import * def mitchell02 ( ): #*****************************************************************************80 # ## mitchell02 sets up Mitchell test #2. # # Reentrant corner # -Laplace(u) = f on [-1,+1]x[-1,+1] with a section removed from the clockwise # side of the positive X axis with angle omega, # u = u0 on the boundary. # u0 = r^alpha sin(alpha*theta) # f = -(u0'') # # Set omega = 3pi/2 for the L-domain problem. # # 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 # # Define parameters. # The symbol "pi" is predefined. # omega = 3 * pi / 2 alpha = pi / omega # # The precomputed mesh should be read from the given file. # mesh = Mesh ( "mitchell02_mesh.xml" ) # # Plot the mesh. # plot ( mesh, title = 'Mitchell Test 02 Mesh' ) filename = 'mitchell02_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 ( sqrt(x[0]*x[0]+x[1]*x[1]), alpha )" "* sin ( alpha * atan2(x[1],x[0]) )", \ 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 ) # # Got to figure out the correct value of F here! # Unless it's a miracle, f=0 is NOT the right value. # f = Expression ( "0.0", degree = 0 ) 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, title = 'Mitchell Test 02 Solution' ) filename = 'mitchell02_solution.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.close ( ) return def mitchell02_test ( ): #*****************************************************************************80 # ## mitchell02_test tests mitchell02. # # 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 ( 'mitchell02_test:' ) print ( ' FENICS/Python version' ) print ( ' Mitchell test problem #2.' ) mitchell02 ( ) # # Terminate. # print ( '' ) print ( 'mitchell02_test:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): mitchell02_test ( )