@@ -129,23 +129,19 @@ def __init__(self,
129129 self .u_exact = as_mixed (exact_solution ) if isinstance (exact_solution , (tuple , list )) else exact_solution
130130 self .goal_exact = exact_goal
131131
132- # Set up an AdaptiveMeshHierarchy
132+ # Set up an AdaptiveMeshHierarchy for every mesh of the problem
133133 V = problem .u .function_space ()
134134 meshes = set (V .mesh ())
135135 meshes .add (V .mesh ())
136- hierarchy = {}
137136 for mesh in meshes :
138137 mh , level = get_level (mesh )
139138 if mh is None :
140139 amh = AdaptiveMeshHierarchy (mesh )
141140 else :
142- meshes = list (mh )
143- amh = AdaptiveMeshHierarchy (meshes [0 ])
144- for m in meshes [1 :level + 1 ]:
141+ amh = AdaptiveMeshHierarchy (mh [0 ])
142+ for m in mh [1 :level + 1 ]:
145143 amh .add_mesh (m )
146- hierarchy [mesh ] = amh
147144
148- self .amh = hierarchy [V .mesh ()]
149145 self .atm = AdaptiveTransferManager ()
150146 self .base_levels = len (amh )
151147
@@ -455,25 +451,26 @@ def set_adaptive_cell_markers(self, eta_cell):
455451
456452 def set_uniform_cell_markers (self ):
457453 """Uniform marking for comparison tests"""
458- mesh = self .amh [- 1 ]
454+ V = self .problem .u .function_space ()
455+ mesh = V .mesh ().unique ()
459456 markers_space = FunctionSpace (mesh , "DG" , 0 )
460457 markers = Function (markers_space )
461458 markers .assign (1 )
462459 return markers
463460
464461 def refine_problem (self , markers ):
465- """Rediscretise the problem on the finest mesh"""
466- domain_markers = {m .function_space ().mesh (): m for m in markers .subfunctions }
467- hierarchy = {}
468- for mesh in domain_markers :
462+ """Adaptively refine the mesh and rediscretise the problem on the refined mesh"""
463+ for marker in markers .subfunctions :
464+ mesh = marker .function_space ().mesh ()
465+ new_mesh = mesh .refine_marked_elements (marker )
466+ amh , _ = get_level (mesh )
467+ amh .add_mesh (new_mesh )
468+ # Reconstruct MeshSequence with the refined meshes
469+ mesh = self .problem .u .function_space ().mesh ()
470+ if len (mesh ) > 1 :
471+ new_mesh = type (mesh )([get_level (m )[0 ][- 1 ] for m in mesh ])
469472 amh , _ = get_level (mesh )
470- new_mesh = mesh .refine_marked_elements (domain_markers [mesh ])
471473 amh .add_mesh (new_mesh )
472- hierarchy [mesh ] = amh
473-
474- if self .amh not in hierarchy .values ():
475- mesh = self .amh [- 1 ]
476- self .amh .add_mesh (type (mesh )([hierarchy [m ][- 1 ] for m in mesh ]))
477474
478475 coef_map = {}
479476 self .problem = refine (self .problem , refine , coefficient_mapping = coef_map )
@@ -512,7 +509,8 @@ def step(self, it=None):
512509
513510 """
514511 if it is None :
515- it = len (self .amh ) - 1
512+ V = self .problem .u .function_space ()
513+ _ , it = get_level (V .mesh ())
516514 self .print (f"---------------------------- [MESH LEVEL { it } ] ----------------------------" )
517515 # SOLVE
518516 u_err = self .solve_primal ()
0 commit comments