Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. from firedrake import *
  2. from firedrake.petsc import PETSc
  3. parameters['coffee']['O2'] = False
  4.  
  5. L = 1.0
  6. H = 1.0
  7. nlayers = 20
  8. dz = H/nlayers
  9.  
  10. m = PeriodicIntervalMesh(nlayers, length=1.0)
  11. mesh = ExtrudedMesh(m, layers=nlayers, layer_height=dz)
  12.  
  13. #1D spaces in horizontal
  14. IUh0 = FiniteElement("CG", "interval", 1)
  15. IUh1 = FiniteElement("DG", "interval", 0)
  16.  
  17. #1D spaces in vertical
  18. IUv0 = FiniteElement("CG", "interval", 1)
  19. IUv1 = FiniteElement("DG", "interval", 0)
  20.  
  21. #DG space
  22. V2_elt = OuterProductElement(IUh1, IUv1)
  23. V2 = FunctionSpace(mesh, V2_elt)
  24.  
  25. #Velocity space
  26. V1_v = OuterProductElement(IUh1, IUv0)
  27. V1_h = OuterProductElement(IUh0, IUv1)
  28. V1_elt = HDiv(V1_v) + HDiv(V1_h)
  29. V1 = FunctionSpace(mesh,V1_elt)
  30.  
  31. #Facet space and broken space for hybridisation
  32. V1f = FunctionSpace(mesh,FacetElement(V1_elt))
  33. V1b = FunctionSpace(mesh,BrokenElement(V1_elt))
  34.  
  35. V1t = FunctionSpace(mesh, V1_v)
  36.  
  37. #(u,w),v,p
  38. W = MixedFunctionSpace((V1,V2,V1t,V2))
  39.  
  40. #rhs variable
  41. F = project(Expression(("exp(x[1])*sin(x[0])+sinh(x[1])")),V2)
  42.  
  43. #Get F
  44. u, v, b, p = TrialFunctions(W)
  45. w, dv, gamma, q = TestFunctions(W)
  46.  
  47. #Boundary conditions
  48. bcs = [DirichletBC(W[0], Expression(("0.", "0.")), "bottom"),
  49. DirichletBC(W[0], Expression(("0.", "0.")), "top")]
  50. #bcs=[]
  51.  
  52. f = Constant(1.0)
  53.  
  54. a = (
  55. inner(w,u) - w[0]*f*v - div(w)*p + div(u)*q
  56. + dv*v + f*dv*u[0] + gamma*b + gamma*u[1]
  57. )*dx
  58.  
  59. L = q*F*dx
  60.  
  61. aP = (
  62. (inner(w,u) + div(w)*div(u))
  63. + p*q + dv*v + gamma*b
  64. )*dx
  65.  
  66. nullspace = MixedVectorSpaceBasis(W, [W.sub(0),
  67. W.sub(1),
  68. W.sub(2),
  69. VectorSpaceBasis(constant=True)
  70. ])
  71.  
  72.  
  73. solver_parameters = {'ksp_type':'gmres',
  74. 'pc_type': 'fieldsplit',
  75. 'pc_fieldsplit_type': 'additive',
  76. 'ksp_converged_reason': True,
  77. 'ksp_monitor':True,
  78. 'fieldsplit_0_ksp_type': 'preonly',
  79. 'fieldsplit_1_ksp_type': 'preonly',
  80. 'fieldsplit_2_ksp_type': 'preonly',
  81. 'fieldsplit_3_ksp_type': 'preonly',
  82. 'fieldsplit_0_pc_type': 'lu',
  83. 'fieldsplit_1_pc_type': 'lu',
  84. 'fieldsplit_2_pc_type': 'lu',
  85. 'fieldsplit_3_pc_type': 'lu'}
  86.  
  87. w1 = Function(W)
  88. uproblem = LinearVariationalProblem(a,L,w1,bcs=bcs,
  89. aP = aP)
  90. usolver = LinearVariationalSolver(uproblem,nullspace=nullspace,
  91. solver_parameters=solver_parameters)
  92. usolver.solve()
  93. u,v, b,p = w1.split()
  94. File('u1.pvd') << u
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement