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
Esempio n. 2
0
    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
Esempio n. 3
0
    def execute_refiniment_strategy(self, mesh, test_params, e_distr, m_distr):
        # Define the refinement strategy
        if test_params['refinement_tag'] == "adaptive":
            # Define the distribution (error or majorant) upon which the refinement is based
            if test_params['refinement_criteria_tag'] == 'error':
                distr = e_distr
            elif test_params['refinement_criteria_tag'] == 'majorant':
                distr = m_distr
                # distr = maj_distr
            # elif test_params['refinement_criteria_tag'] == 'e-dwr':
            #    distr = e_dwr_distr
            # elif test_params['refinement_criteria_tag'] == 'residual':
            #    distr = residual_distr

            # Run the marking procedure
            theta = 0.2  # percentage of the marked cells

            if test_params['marking_tag'] == 'average':
                marking = estimates.averaged_marking(mesh, distr)
            elif test_params['marking_tag'] == 'predefined':
                marking = estimates.predefined_amount_of_elements_marking(
                    mesh, distr, theta)
            elif test_params['marking_tag'] == 'bulk':
                marking = estimates.bulk_marking(mesh, distr, theta)

            # Refine mesh based on the marking criteria
            mesh = refine(mesh, marking)

        elif test_params['refinement_tag'] == "uniform":

            # Refinement for the comparison with theta < 1.0
            # cell_markers = CellFunction("bool", mesh)
            # cell_markers.set_all(True)
            # mesh = refine(mesh, cell_markers)

            mesh = refine(mesh)

        return mesh