def execute_refinement_strategy(self, problem_params, mesh, e_distr, md_distr, maj_distr, error_k, majorant_k, i_eff_maj_k, error_d_k, majorant_d_k, h_max_k, h_min_k, t_T, k, nt, project_path, results_folder, init_data_info): if problem_params['refinement_tag'] == "adaptive": # Define the distribution (error or majorant) upon which the refinement is based if problem_params['refinement_criteria_tag'] == 'error': distr = e_distr elif problem_params['refinement_criteria_tag'] == 'majorant': distr = md_distr #if self.dim == 2: distr = md_distr #elif self.dim == 3: distr = md_distr refinement_tag = problem_params[ 'refinement_criteria_tag'] + '-' + problem_params[ 'marking_tag'] + '-marking' # Define the marking algorithm if problem_params['marking_tag'] == 'average': marking = estimates.averaged_marking(mesh, distr) #refinement_tag = problem_params['refinement_criteria_tag'] + '-' + problem_params[ # 'marking_tag'] + '-marking' #refinement_tag = refinement_tag + '-marking' elif problem_params['marking_tag'] == 'predefined': marking = estimates.predefined_amount_of_elements_marking( mesh, distr, problem_params['percentage_value']) refinement_tag = refinement_tag + '-proc-%d' % ( problem_params['percentage_value'] * 100) elif problem_params['marking_tag'] == 'bulk': marking = estimates.bulk_marking( mesh, distr, problem_params['percentage_value']) refinement_tag = refinement_tag + '-bulk-%d' % ( problem_params['percentage_value'] * 100) elif problem_params['refinement_tag'] == "uniform": marking = CellFunction("bool", mesh) marking.set_all(True) refinement_tag = problem_params['refinement_tag'] if k % 1 == 0 and problem_params[ 'solving_strategy_tag'] == "with-refinement": results_path = project_path + results_folder + 'e-maj-distr-hist-' + refinement_tag + init_data_info postprocess.plot_histogram(mesh, e_distr, distr, results_path) postprocess.save_distr_to_mat_file(e_distr, distr, results_path) mesh = refine(mesh, marking) postprocess.document_results_with_refinement( problem_params, mesh, e_distr, md_distr, error_k, majorant_k, i_eff_maj_k, error_d_k, majorant_d_k, h_max_k, h_min_k, t_T, k, nt, refinement_tag, project_path, results_folder, init_data_info, dim) return mesh
def execute_refinement_strategy(self, problem_params, mesh, e_distr, md_distr, project_path, results_folder, init_data_info): # error_k, majorant_k, i_eff_maj_k, error_d_k, majorant_d_k, h_max_k, h_min_k, t_T, k, nt, # Define the refinement strategy if problem_params['refinement_tag'] == "adaptive": # Define the distribution (error or majorant) upon which the refinement is basedy^ if problem_params['refinement_criteria_tag'] == 'error': distr = e_distr elif problem_params['refinement_criteria_tag'] == 'majorant': distr = md_distr if problem_params['marking_tag'] == 'average': marking = estimates.averaged_marking(mesh, distr) refinement_tag = problem_params[ 'refinement_criteria_tag'] + '-' + problem_params[ 'marking_tag'] + '-marking' elif problem_params['marking_tag'] == 'predefined': marking = estimates.predefined_amount_of_elements_marking( mesh, distr, problem_params['percentage_value']) refinement_tag = problem_params[ 'refinement_criteria_tag'] + '-' + problem_params[ 'marking_tag'] + '-marking' + '-proc-%d' % ( problem_params['percentage_value'] * 100) elif problem_params['marking_tag'] == 'bulk': marking = estimates.bulk_marking( mesh, distr, problem_params['percentage_value']) refinement_tag = problem_params[ 'refinement_criteria_tag'] + '-' + problem_params[ 'marking_tag'] + '-marking' + '-bulk-%d' % ( problem_params['percentage_value'] * 100) print("% ----------------") print("% Refine the mesh ") print("% ----------------") # Refine mesh based on the marking criteria mesh = refine(mesh, marking) print('mesh parameters: num_cells = %d, num_vertices = %d' % (mesh.num_cells(), mesh.num_vertices())) # Define the name of the mat-file mat_file_tag = project_path + results_folder + 'results-on-mesh-based-' + refinement_tag + init_data_info elif problem_params['refinement_tag'] == "uniform": cell_markers = CellFunction("bool", mesh) cell_markers.set_all(True) mesh = refine(mesh, cell_markers) refinement_tag = problem_params['refinement_tag'] # Define the name of the matfile mat_file_tag = project_path + results_folder + 'results-on-mesh-uniform' + init_data_info return mesh, mat_file_tag
def bulk_marking(mesh, distr, theta): marking = CellFunction("bool", mesh) distr_0 = sorted(distr, reverse=True)[int(len(distr) * theta)] for cell in cells(mesh): marking[cell] = distr[cell.index()] > distr_0 return marking
def get_2d_slice_of_3d_function_on_Oz(mesh, u, T, dim, v_degree): # create a boundary mesh bmesh = BoundaryMesh(mesh, "exterior") cell_func = CellFunction('size_t', bmesh, 0) coordinates = bmesh.coordinates() z_indeces = postprocess.allocate_array(dim) for cell in cells(bmesh): indx = 0 for vertex in vertices(cell): z_indeces[indx] = coordinates[vertex.index()][dim - 1] indx += 1 #print "Vertex index with coordinates", vertex.index(), coordinates[vertex.index()][dim-1] if (dim == 3 and near(z_indeces[0], T) and near(z_indeces[1], T) and near(z_indeces[2], T)) or (dim == 2 and near( z_indeces[0], T) and near(z_indeces[1], T)): #print "right cell", cell.index() cell_func[cell] = 1 submesh = SubMesh(bmesh, cell_func, 1) # create a FunctionSpace on the submesh- Vs = FunctionSpace(submesh, "Lagrange", v_degree) us = interpolate(u, Vs) return us, submesh
def averaged_marking(mesh, distr): cells_num = mesh.num_cells() marking = CellFunction("bool", mesh) distr_aver = sum(distr) / cells_num for c in cells(mesh): marking[c] = distr[c.index()] >= distr_aver return marking
def predefined_amount_of_elements_marking(mesh, distr, theta): cells_num = mesh.num_cells() marking = CellFunction("bool", mesh) marking.set_all(False) i_cut = int(math.floor(theta * cells_num)) index_sorted = sorted(range(len(distr)), key=lambda k: distr[k], reverse=True) cells_indices_to_refine = index_sorted[0:i_cut] for cell in cells(mesh): if cell.index() in cells_indices_to_refine: marking[cell] = True return marking