@@ -458,3 +458,86 @@ def test_submesh_solve_cell_cell_equation_bc(nref, degree, simplex):
458458 solve (a == L , sol , bcs = [dbc , ebc ])
459459 assert sqrt (assemble (inner (sol [0 ] - x * y , sol [0 ] - x * y ) * dx_outer )) < 1.e-12
460460 assert sqrt (assemble (inner (sol [1 ] - x * y , sol [1 ] - x * y ) * dx_inner )) < 1.e-12
461+
462+
463+ @pytest .mark .parallel (nprocs = 8 )
464+ @pytest .mark .parametrize ('simplex' , [True , False ])
465+ @pytest .mark .parametrize ('direction' , [0 , 1 , 2 ])
466+ def test_submesh_solve_cell_facet_3d (simplex , direction ):
467+ dim = 3
468+ distribution_parameters = {
469+ "overlap_type" : (DistributedMeshOverlapType .RIDGE , 1 ),
470+ }
471+ if simplex :
472+ nref = 3
473+ mesh = BoxMesh (2 ** nref , 2 ** nref , 2 ** nref , 1. , 1. , 1. , hexahedral = False , distribution_parameters = distribution_parameters )
474+ xyz = SpatialCoordinate (mesh )
475+ DG0 = FunctionSpace (mesh , "DG" , 0 )
476+ c1 = Function (DG0 ).interpolate (conditional (xyz [direction ] < 0.318310 , 1 , 0 ))
477+ c2 = Function (DG0 ).interpolate (conditional (xyz [direction ] > 0.318310 , 1 , 0 ))
478+ mesh = RelabeledMesh (mesh , [c1 , c2 ], [1 , 2 ])
479+ family = "P"
480+ else :
481+ mesh = Mesh (join (cwd , ".." , "meshes" , "cube_hex.msh" ), distribution_parameters = distribution_parameters )
482+ xyz = SpatialCoordinate (mesh )
483+ DG0 = FunctionSpace (mesh , "DQ" , 0 )
484+ c1 = Function (DG0 ).interpolate (conditional (xyz [direction ] < 0.318310 , 1 , 0 ))
485+ c2 = Function (DG0 ).interpolate (conditional (xyz [direction ] > 0.318310 , 1 , 0 ))
486+ HDivTrace0 = FunctionSpace (mesh , "Q" , 2 )
487+ f1 = Function (HDivTrace0 ).interpolate (conditional (xyz [0 ] < .001 , 1 , 0 ))
488+ f2 = Function (HDivTrace0 ).interpolate (conditional (xyz [0 ] > .999 , 1 , 0 ))
489+ f3 = Function (HDivTrace0 ).interpolate (conditional (xyz [1 ] < .001 , 1 , 0 ))
490+ f4 = Function (HDivTrace0 ).interpolate (conditional (xyz [1 ] < .999 , 1 , 0 ))
491+ f5 = Function (HDivTrace0 ).interpolate (conditional (xyz [2 ] < .001 , 1 , 0 ))
492+ f6 = Function (HDivTrace0 ).interpolate (conditional (xyz [2 ] < .999 , 1 , 0 ))
493+ mesh = RelabeledMesh (mesh , [c1 , c2 , f1 , f2 , f3 , f4 , f5 , f6 ], [1 , 2 , 1 , 2 , 3 , 4 , 5 , 6 ])
494+ family = "Q"
495+ mesh1 = Submesh (mesh , dim , 1 )
496+ x1 , y1 , z1 = SpatialCoordinate (mesh1 )
497+ mesh2 = Submesh (mesh , dim , 2 )
498+ x2 , y2 , z2 = SpatialCoordinate (mesh2 )
499+ label_interf = 7 # max + 1
500+ mesh12 = Submesh (mesh2 , dim - 1 , label_interf )
501+ dx1 = Measure ("dx" , mesh1 )
502+ dx2 = Measure ("dx" , mesh2 )
503+ dx12 = Measure ("dx" , mesh12 )
504+ dx12_ds1 = Measure ("dx" , mesh12 , intersect_measures = (Measure ("ds" , mesh1 ),))
505+ ds1_dx12 = Measure ("ds" , mesh1 , intersect_measures = (Measure ("dx" , mesh12 ),))
506+ ds2_dx12 = Measure ("ds" , mesh2 , intersect_measures = (Measure ("dx" , mesh12 ),))
507+ # Check sanity.
508+ vol1 = assemble (Constant (1 ) * dx1 )
509+ vol2 = assemble (Constant (1 ) * dx2 )
510+ assert abs (vol1 + vol2 - 1. ) < 1.e-14
511+ # Solve Poisson problem.
512+ V1 = FunctionSpace (mesh1 , family , 3 )
513+ V12 = FunctionSpace (mesh12 , family , 5 )
514+ V2 = FunctionSpace (mesh2 , family , 4 )
515+ V = V1 * V12 * V2
516+ u = TrialFunction (V )
517+ v = TestFunction (V )
518+ u1 , u12 , u2 = split (u )
519+ v1 , v12 , v2 = split (v )
520+ g1 = cos (2 * pi * x1 ) * cos (2 * pi * y1 ) * cos (2 * pi * z1 )
521+ g2 = cos (2 * pi * x2 ) * cos (2 * pi * y2 ) * cos (2 * pi * z2 )
522+ f1 = 12 * pi ** 2 * g1
523+ f2 = 12 * pi ** 2 * g2
524+ n1 = FacetNormal (mesh1 )
525+ a = (
526+ inner (grad (u1 ), grad (v1 )) * dx1 - inner (u12 , v1 ) * ds1_dx12 (label_interf ) +
527+ inner (u12 , v12 ) * dx12 +
528+ inner (grad (u2 ), grad (v2 )) * dx2 + inner (u12 , v2 ) * ds2_dx12 (label_interf )
529+ )
530+ L = (
531+ inner (f1 , v1 ) * dx1 +
532+ inner (dot (grad (g1 ), n1 ), v12 ) * dx12_ds1 +
533+ inner (f2 , v2 ) * dx2
534+ )
535+ sol = Function (V )
536+ bc1 = DirichletBC (V .sub (0 ), g1 , (2 * direction + 1 ,))
537+ bc2 = DirichletBC (V .sub (2 ), g2 , (2 * direction + 2 ,))
538+ solve (a == L , sol , bcs = [bc1 , bc2 ])
539+ sol1 , sol12 , sol2 = split (sol )
540+ error1 = assemble (inner (sol1 - g1 , sol1 - g1 ) * dx1 )
541+ error2 = assemble (inner (sol2 - g2 , sol2 - g2 ) * dx2 )
542+ assert sqrt (error1 ) < 4.e-4
543+ assert sqrt (error2 ) < 4.e-5
0 commit comments