#! /usr/bin/env python3 # from dolfin import * from mshr import * def annulus_flow ( ): #*****************************************************************************80 # ## annulus_flow solves Navier-Stokes flow in an off-center annulus. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 27 November 2018 # # Author: # # Michael Schneier # # Modifier: # # John Burkardt # import numpy as np import matplotlib.pyplot as plt from numpy import linalg as LA from scipy.sparse.linalg.eigen.arpack import eigsh from scipy import sparse, io import time import pdb # # Time info and viscosity coefficents # t_init = 0.0 t_final = 10.0 t_num = 1000 # # Reduce computational time range to 100th of original for example run. # t_init = 0.0 t_final = 0.1 t_num = 10 # # Set other time parameters. # dt = ( t_final - t_init ) / t_num eps_be = dt t = t_init # # Viscosity coefficient. # nu = 0.001 # # Generate the mesh. # circle_outx = 0.0 circle_outy = 0.0 circle_outr = 1.0 circle_inx = 0.5 circle_iny = 0.0 circle_inr = 0.1 domain = Circle ( Point(circle_outx,circle_outy), circle_outr ) \ - Circle ( Point(circle_inx,circle_iny), circle_inr ) mesh = generate_mesh ( domain, 30 ) # # Plot the mesh. # plot ( mesh, title = 'annulus flow mesh' ) filename = 'annulus_flow_mesh.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.close ( ) # # Declare Finite Elements for velocity, pressure, and Taylor-Hood. # P2 = VectorElement ( "P", triangle, 2 ) P1 = FiniteElement ( "P", triangle, 1 ) TH = P2 * P1 # # Declare Function Spaces for velocity, pressure, and Taylor-Hood. # V = VectorFunctionSpace ( mesh, "P", 2 ) Q = FunctionSpace ( mesh, "P", 1 ) W = FunctionSpace ( mesh, TH ) # # Declare formal Finite Element Functions # ( u, p ) = TrialFunctions ( W ) ( v, q ) = TestFunctions ( W ) # # Define some functions. # w = Function ( W ) u0 = Function ( V ) p0 = Function ( Q ) # # Macros needed for weak formulation. # def contract(u,v): return inner(nabla_grad(u),nabla_grad(v)) def b(u,v,w): return 0.5*(inner(dot(u,nabla_grad(v)),w)-inner(dot(u,nabla_grad(w)),v)) # # Declare Boundary Conditions. # def u0_boundary(x, on_boundary): return on_boundary noslip = Constant((0.0, 0.0)) def lower_boundary_fixed_point(x,on_boundary): tol=1E-15 return (abs(x[1]) < tol) and (abs(x[0]-0.5)