Esempio n. 1
0
    def Is_Convergence(self):
        '''
        # relative difference in a mean stress for the last 5 iterations must be < tolerance
        # i >= iterations_limit 
        '''
        global i, i_violated, difference_last, continue_iterations, check_tolerance, mass_goal_i
        if len(FI_mean) > 5:
            difference_last = []
            for last in range(1, 6):
                difference_last.append(
                    abs(FI_mean[i] - FI_mean[i - last]) / FI_mean[i])
            difference = max(difference_last)
            if check_tolerance is True:
                print(
                    "maximum relative difference in FI_mean for the last 5 iterations = {}"
                    .format(difference))
            if difference < tolerance:
                continue_iterations = False
            elif FI_mean[i] == FI_mean[i - 1] == FI_mean[i - 2]:
                continue_iterations = False
                print("FI_mean[i] == FI_mean[i-1] == FI_mean[i-2]")

        # start of the new iteration or finish of the iteration process
        if continue_iterations is False or i >= iterations_limit:
            # break
            return True
        else:
            # export the present mesh
            if save_iteration_results and np.mod(float(i - 1),
                                                 save_iteration_results) == 0:
                if "frd" in save_iteration_format:
                    beso_lib.export_frd(path_export + "/file" + str(), nodes,
                                        Elements, elm_states, number_of_states)
                if "inp" in save_iteration_format:
                    beso_lib.export_inp(path_export + "/file" + str(), nodes,
                                        Elements, elm_states, number_of_states)
        i += 1  # iteration number
        print("\n----------- new iteration number %d ----------" % i)

        # check for number of violated elements
        if sum(FI_violated[i -
                           1]) > sum(FI_violated[0]) + FI_violated_tolerance:
            mass_goal_i = mass[i - 1]  # use mass_new from previous iteration
            if i_violated == 0:
                i_violated = i
                check_tolerance = True
        elif mass[i -
                  1] <= mass_goal_ratio * mass_full:  # goal volume achieved
            if not i_violated:
                i_violated = i  # to start decaying
                check_tolerance = True
            try:
                mass_goal_i
            except NameError:
                msg = "ERROR: mass goal is lower than initial mass. Check mass_goal_ratio"
                beso_lib.write_to_log(file_name, msg + "\n")
        else:
            mass_goal_i = mass_goal_ratio * mass_full

        return False
Esempio n. 2
0
                                if elm_states[en] != elm_states_filtered[en]:
                                    mass[i] += volume_elm[en] * (
                                        domain_density[dn][elm_states_filtered[en]] - domain_density[dn][elm_states[en]])
                                    elm_states[en] = elm_states_filtered[en]
    print("mass = {}" .format(mass[i]))
    mass_excess = mass[i] - mass_not_filtered

    # export the present mesh
    beso_lib.append_vtk_states(file_name_resulting_states, i, en_all_vtk, elm_states)

    file_nameW2 = os.path.join(path, "file" + str(i).zfill(3))
    if save_iteration_results and np.mod(float(i), save_iteration_results) == 0:
        if "frd" in save_resulting_format:
            beso_lib.export_frd(file_nameW2, nodes, Elements, elm_states, number_of_states)
        if "inp" in save_resulting_format:
            beso_lib.export_inp(file_nameW2, nodes, Elements, elm_states, number_of_states)

    # check for oscillation state
    if elm_states_before_last == elm_states:  # oscillating state
        msg = "\nOSCILLATION: model turns back to " + str(i - 2) + "th iteration.\n"
        beso_lib.write_to_log(file_name, msg)
        print(msg)
        oscillations = True
        break
    elm_states_before_last = elm_states_last.copy()
    elm_states_last = elm_states.copy()

    # removing solver files
    if save_iteration_results and np.mod(float(i - 1), save_iteration_results) == 0:
        if "inp" not in save_solver_files:
            os.remove(file_nameW + ".inp")
Esempio n. 3
0
                                if elm_states[en] != elm_states_filtered[en]:
                                    mass[i] += volume_elm[en] * (
                                        domain_density[dn][elm_states_filtered[en]] - domain_density[dn][elm_states[en]])
                                    elm_states[en] = elm_states_filtered[en]
    print("mass = {}" .format(mass[i]))
    mass_excess = mass[i] - mass_not_filtered

    # export the present mesh
    beso_lib.append_vtk_states(file_name_resulting_states, i, en_all_vtk, elm_states)

    file_nameW2 = os.path.join(path, "file" + str(i).zfill(3))
    if save_iteration_results and np.mod(float(i), save_iteration_results) == 0:
        if "frd" in save_resulting_format:
            beso_lib.export_frd(file_nameW2, nodes, Elements, elm_states, number_of_states)
        if "inp" in save_resulting_format:
            beso_lib.export_inp(file_nameW2, nodes, Elements, elm_states, number_of_states)

    # check for oscillation state
    if elm_states_before_last == elm_states:  # oscillating state
        msg = "\nOSCILLATION: model turns back to " + str(i - 2) + "th iteration.\n"
        beso_lib.write_to_log(file_name, msg)
        print(msg)
        oscillations = True
        break
    elm_states_before_last = elm_states_last.copy()
    elm_states_last = elm_states.copy()

    # removing solver files
    if save_iteration_results and np.mod(float(i - 1), save_iteration_results) == 0:
        if "inp" not in save_solver_files:
            os.remove(file_nameW + ".inp")
Esempio n. 4
0
        elif FI_mean[i] == FI_mean[i - 1] == FI_mean[i - 2]:
            continue_iterations = False
            print("FI_mean[i] == FI_mean[i-1] == FI_mean[i-2]")

    # start of the new iteration or finish of the iteration process
    if continue_iterations is False or i >= iterations_limit:
        break
    else:
        # export the present mesh
        if save_iteration_results and np.mod(float(i - 1),
                                             save_iteration_results) == 0:
            if "frd" in save_iteration_format:
                beso_lib.export_frd(path_export + "file" + str(i), nodes,
                                    Elements, elm_states, number_of_states)
            if "inp" in save_iteration_format:
                beso_lib.export_inp(path_export + "file" + str(i), nodes,
                                    Elements, elm_states, number_of_states)
    i += 1  # iteration number
    print("\n----------- new iteration number %d ----------" % i)

    # check for number of violated elements
    if sum(FI_violated[i - 1]) > sum(FI_violated[0]) + FI_violated_tolerance:
        mass_goal_i = mass[i - 1]  # use mass_new from previous iteration
        if i_violated == 0:
            i_violated = i
            check_tolerance = True
    elif mass[i - 1] <= mass_goal_ratio * mass_full:  # goal volume achieved
        if not i_violated:
            i_violated = i  # to start decaying
            check_tolerance = True
        try:
            mass_goal_i