@@ -180,3 +180,80 @@ def test_submesh_mixed_cell_solve():
180180 pgfplot (Function (V_t ).interpolate (sol .subfunctions [0 ] - g_t ), "mesh_tri.txt" , degree = 2 )
181181 pgfplot (Function (V_q ).interpolate (sol .subfunctions [1 ] - g_q ), "mesh_quad.txt" , degree = 2 )
182182
183+
184+ def _test_submesh_mixed_cell_solve_convergence (nref , degree ):
185+ dim = 2
186+ label_ext = 1
187+ label_interf = 2
188+ distribution_parameters_noop = {
189+ "partition" : False ,
190+ "overlap_type" : (DistributedMeshOverlapType .NONE , 0 ),
191+ }
192+ mesh = Mesh (os .path .join (cwd , ".." , "meshes" , "mixed_cell_unit_square.msh" ), distribution_parameters = distribution_parameters_noop )
193+ #mesh = MeshHierarchy(mesh, 1)[-1]
194+ plex = mesh .topology_dm
195+ for _ in range (nref ):
196+ plex = plex .refine ()
197+ plex .removeLabel ("pyop2_core" )
198+ plex .removeLabel ("pyop2_owned" )
199+ plex .removeLabel ("pyop2_ghost" )
200+ mesh = Mesh (plex )
201+ h = 0.1 / 2 ** nref # roughly
202+ mesh .topology_dm .markBoundaryFaces (dmcommon .FACE_SETS_LABEL , label_ext )
203+ mesh_t = Submesh (mesh , dim , PETSc .DM .PolytopeType .TRIANGLE , label_name = "celltype" , name = "mesh_tri" )
204+ x_t , y_t = SpatialCoordinate (mesh_t )
205+ n_t = FacetNormal (mesh_t )
206+ mesh_q = Submesh (mesh , dim , PETSc .DM .PolytopeType .QUADRILATERAL , label_name = "celltype" , name = "mesh_quad" )
207+ x_q , y_q = SpatialCoordinate (mesh_q )
208+ n_q = FacetNormal (mesh_q )
209+ V_t = FunctionSpace (mesh_t , "P" , degree )
210+ V_q = FunctionSpace (mesh_q , "Q" , degree )
211+ V = V_t * V_q
212+ u = TrialFunction (V )
213+ v = TestFunction (V )
214+ u_t , u_q = split (u )
215+ v_t , v_q = split (v )
216+ dx_t = Measure ("dx" , mesh_t )
217+ dx_q = Measure ("dx" , mesh_q )
218+ ds_t = Measure ("ds" , mesh_t , intersect_measures = (Measure ("ds" , mesh_q ),))
219+ ds_q = Measure ("ds" , mesh_q , intersect_measures = (Measure ("ds" , mesh_t ),))
220+ g_t = cos (2 * pi * x_t ) * cos (2 * pi * y_t )
221+ g_q = cos (2 * pi * x_q ) * cos (2 * pi * y_q )
222+ f_t = 8 * pi ** 2 * g_t
223+ f_q = 8 * pi ** 2 * g_q
224+ a = (
225+ inner (grad (u_t ), grad (v_t )) * dx_t +
226+ inner (grad (u_q ), grad (v_q )) * dx_q
227+ - inner (
228+ (grad (u_q ) + grad (u_t )) / 2 ,
229+ (v_q * n_q + v_t * n_t )
230+ ) * ds_q (label_interf )
231+ - inner (
232+ (u_q * n_q + u_t * n_t ),
233+ (grad (v_q ) + grad (v_t )) / 2
234+ ) * ds_t (label_interf )
235+ + 100 / h * inner (u_q - u_t , v_q - v_t ) * ds_q (label_interf )
236+ )
237+ L = (
238+ inner (f_t , v_t ) * dx_t +
239+ inner (f_q , v_q ) * dx_q
240+ )
241+ sol = Function (V )
242+ bc_q = DirichletBC (V .sub (1 ), g_q , label_ext )
243+ solve (a == L , sol , bcs = [bc_q ])
244+ sol_t , sol_q = split (sol )
245+ L2error_t = assemble (inner (sol_t - g_t , sol_t - g_t ) * dx_t )
246+ L2error_q = assemble (inner (sol_q - g_q , sol_q - g_q ) * dx_q )
247+ H1error_t = assemble ((inner (sol_t - g_t , sol_t - g_t ) + inner (grad (sol_t - g_t ), grad (sol_t - g_t )))* dx_t )
248+ H1error_q = assemble ((inner (sol_q - g_q , sol_q - g_q ) + inner (grad (sol_q - g_q ), grad (sol_q - g_q )))* dx_q )
249+ return sqrt (L2error_t + L2error_q ), sqrt (H1error_t + H1error_q )
250+
251+
252+ @pytest .mark .parallel (nprocs = 8 )
253+ def test_submesh_mixed_cell_solve_convergence ():
254+ for degree in range (1 , 5 ):
255+ print ("degree: " , degree )
256+ for nref in range (4 ):
257+ print ("nref: " , nref )
258+ L2error , H1error = _test_submesh_mixed_cell_solve_convergence (nref , degree )
259+ print ('%.4f, %.4f\n ' % (np .log2 (L2error ), np .log2 (H1error )))
0 commit comments