def retrieve_node_set_from_imaginary_node_number(coil_data,
                                                  dict_planes_nodes,
                                                  imaginary_node):
     """
     Returns a list of sorted real node numbers belonging to the imaginary node
     :param coil_data: 4-column numpy array; 1st column: winding number, 2nd column: real node number,
     3rd column: imaginary node number, 4th column: length at the given imaginary node number
     :param dict_planes_nodes: dictionary of dictionaries with windings as the first key and plane as the second
     :param imaginary_node: imaginary node number as string
     :return: list of real node numbers
     """
     imaginary_1d_node_set = coil_data[:, 2]
     imaginary_1d_node_set = np.asfarray(imaginary_1d_node_set, float)
     coil_set = coil_data[(imaginary_1d_node_set[:] == imaginary_node)]
     nodes_set = []
     for i in range(len(coil_set[:, 0])):
         winding_number = coil_set[i, 0]
         if GeneralFunctions.check_if_string_is_float(coil_set[i, 1]):
             number = str(int(float(coil_set[i, 1])))
             plane_number = "plane" + number
         else:
             plane_number = "plane" + str(coil_set[i, 1])
         nodes_set.append(dict_planes_nodes[winding_number][plane_number])
     nodes_set = GeneralFunctions.flatten_list(nodes_set)
     nodes_set.sort()
     return nodes_set
Пример #2
0
 def __init__(self, factory):
     self.output_directory = factory.output_directory
     self.output_directory_quench_state = GeneralFunctions.create_folder_in_directory(
         self.output_directory, "quench_state_output")
     self.output_directory_resistive_voltage = GeneralFunctions.create_folder_in_directory(
         self.output_directory, "resistive_voltage_output")
     self.output_directory_temperature = GeneralFunctions.create_folder_in_directory(
         self.output_directory, "temperature_profile_output")
Пример #3
0
 def upload_quench_velocity_grid(self, factory):
     quench_velocity_map_array = np.loadtxt(
         self.quench_velocity_map_filename, delimiter=",", skiprows=1)
     GeneralFunctions.copy_file_to_directory(
         filename=factory.input_data.analysis_type.input.
         v_quench_map_filename,
         filename_directory=factory.input_directory,
         desired_filename_directory=factory.input_copy_directory)
     return quench_velocity_map_array[:, 1:]
Пример #4
0
 def extract_txt_data(self, magnetic_field_list):
     """
     Saves txt files with material properties arrays in Class directory
     :param magnetic_field_list: list of values of magnetic field strength as floats
     """
     for i in range(len(magnetic_field_list)):
         GeneralFunctions.save_array(
             self.output_directory, "Nb_Ti_cv_magnetic_field_{}.txt".format(
                 magnetic_field_list[i]), self.cv[i])
Пример #5
0
 def create_ic_temperature_profile(self):
     self.initial_temperature_profile = self.define_gaussian_temperature_distribution_array(
         self.geometry.coil_geometry,
         magnetic_field=self.input_data.temperature_settings.input.
         B_initially_quenched_winding)
     GeneralFunctions.save_array(self.plots.output_directory_temperature,
                                 "temperature_profile_0.txt",
                                 self.initial_temperature_profile)
     return self.initial_temperature_profile
Пример #6
0
 def input_file(self, filename, extension, directory):
     print(
         self.mapdl.executeCommandToString("/input,{},{},{}".format(
             filename, extension, directory)))
     end_process = GeneralFunctions.make_python_wait_until_ansys_finishes(
         filename='Process_Finished.txt', directory=self.directory)
     if end_process:
         GeneralFunctions.delete_file(filename='Process_Finished.txt',
                                      directory=self.directory)
         print("File uploaded... \n---------------")
    def __init__(self, factory):
        Geometry.__init__(self, factory)

        self.files_in_directory = GeneralFunctions.make_list_of_filenames_in_directory(
            directory=self.directory)
        list_windings_nodes = GeneralFunctions.find_files_with_given_word(
            list_files=self.files_in_directory,
            word="Nodes_winding_without_insul")
        self.dict_winding_nodes = self.load_files_with_windings_nodes(
            winding_files=list_windings_nodes,
            directory=self.directory,
            key_word="winding")
        self.file_node_position = Geometry.load_file_with_winding_nodes_position(
            directory=self.directory, filename="Node_Position.txt")
        self.center_plane_position = self.calculate_windings_lengths(
            position_array=self.file_node_position,
            winding_set=self.dict_winding_nodes)
        self.coil_data = Geometry.calculate_coil_length_data(
            windings_lengths=self.center_plane_position,
            number_of_windings=self.input_data.geometry_settings.type_input.
            n_windings)
        self.coil_length_1d = self.retrieve_1d_imaginary_coil(
            directory=self.output_directory_geometry, coil_data=self.coil_data)
        self.node_map_sorted = self.translate_domain_into_1d_cable(
            coil_data=self.coil_data, winding_set=self.dict_winding_nodes)
        self.dict_imaginary_nodes = Geometry.create_dict_with_imaginary_nodes(
            windings_lengths=self.center_plane_position,
            number_of_windings=self.input_data.geometry_settings.type_input.
            n_windings)
        self.im_nodes_per_winding = Geometry.number_of_im_nodes_per_winding(
            self.dict_imaginary_nodes)
        self.winding_node_dict = self.create_node_dict_for_each_winding()
        self.coil_geometry = self.coil_length_1d
        list_planes_nodes = GeneralFunctions.find_files_with_given_word(
            list_files=self.files_in_directory, word="Nodes_plane")
        self.dict_planes_nodes = self.load_files_with_windings_nodes(
            winding_files=list_planes_nodes,
            directory=self.directory,
            key_word="plane")

        if factory.input_data.geometry_settings.type_input.type_insulation_settings.insulation_analysis:
            list_windings_nodes_insul = GeneralFunctions.find_files_with_given_word(
                list_files=self.files_in_directory,
                word="Nodes_winding_with_insul")
            self.dict_winding_nodes_insul = self.load_files_with_windings_nodes(
                winding_files=list_windings_nodes_insul,
                directory=self.directory,
                key_word="winding")
            self.dict_windings_planes = self.create_dict_with_nodes_in_planes_in_each_winding(
                self.dict_planes_nodes, self.dict_winding_nodes_insul)
        else:
            self.dict_windings_planes = self.create_dict_with_nodes_in_planes_in_each_winding(
                self.dict_planes_nodes, self.dict_winding_nodes)
Пример #8
0
 def copy_ansys_analysis_files_to_output_results_directory(self):
     """
     Cuts the ANSYS files from the ANSYS initial directory and pastes them to the final output directory specified
     by the user
     """
     time.sleep(2)
     list_files = os.listdir(self.directory)
     for file in list_files:
         path = os.path.join(self.directory, file)
         if os.path.isfile(path):
             shutil.copy(path, self.output_directory)
             GeneralFunctions.delete_file(file, self.directory)
Пример #9
0
 def upload_differential_inductance(self):
     filename_directory = os.path.join(
         self.factory.input_file_directory, self.input_data.
         circuit_settings.transient_electric_analysis_input.L_diff_filename)
     diff_inductance_array = np.loadtxt(filename_directory,
                                        delimiter=",",
                                        skiprows=1)
     GeneralFunctions.copy_file_to_directory(
         filename=self.input_data.circuit_settings.
         transient_electric_analysis_input.L_diff_filename,
         filename_directory=self.factory.input_file_directory,
         desired_filename_directory=self.factory.input_copy_directory)
     return diff_inductance_array
Пример #10
0
 def create_analysis_output_directories(analysis_directory):
     """
     Creates the output_directory for the output files in the folder 'output'
     :param analysis_directory: analysis directory as string
     :return: output_directory for the output files as string
     """
     last_analysis_folder = AnalysisLauncher.count_number_of_analysis_output_folders_in_directory(
         analysis_directory)
     GeneralFunctions.create_folder_in_directory(
         directory=analysis_directory,
         foldername=str(last_analysis_folder + 1))
     path_final = os.path.join(analysis_directory,
                               str(last_analysis_folder + 1))
     return path_final
 def extract_txt_data(self, magnetic_field_list):
     """
     Saves txt files with material properties arrays in Class directory
     :param magnetic_field_list: list of values of magnetic field strength as floats
     """
     for i in range(len(magnetic_field_list)):
         GeneralFunctions.save_array(
             self.output_directory_materials,
             "Strand_eq_cv_magnetic_field_{}.txt".format(
                 magnetic_field_list[i]), self.strand_equivalent_cv[i])
         GeneralFunctions.save_array(
             self.output_directory_materials,
             "Strand_eq_diffusivity_magnetic_field_{}.txt".format(
                 magnetic_field_list[i]),
             self.strand_equivalent_diffusivity[i])
         GeneralFunctions.save_array(
             self.output_directory_materials,
             "Strand_eq_thermal_conductivity_magnetic_field_{}.txt".format(
                 magnetic_field_list[i]),
             self.strand_equivalent_thermal_conductivity[i])
         GeneralFunctions.save_array(
             self.output_directory_materials,
             "Strand_eq_resistivity_magnetic_field_{}.txt".format(
                 magnetic_field_list[i]),
             self.strand_equivalent_resistivity[i])
Пример #12
0
 def extract_txt_data(self):
     """
     Saves txt files with material properties arrays in Class directory
     """
     GeneralFunctions.save_array(self.output_directory, "winding_cv.txt", self.cv)
     GeneralFunctions.save_array(self.output_directory, "winding_k.txt", self.k)
     GeneralFunctions.save_array(self.output_directory, "winding_resistivity.txt", self.resistivity)
     GeneralFunctions.save_array(self.output_directory, "winding_diffusivity.txt", self.diffusivity)
Пример #13
0
 def __init__(self, factory):
     MagneticFieldMap.__init__(self, factory)
     winding_data = self.assign_magnetic_field_to_windings(current=self.input_data.circuit_settings.
                                                           electric_ansys_element_input.I_init)
     self.mag_dict = winding_data[0]
     self.mag_map_array = winding_data[1]
     MagneticFieldPlotting.plot_mag_field_in_windings(x_vector=self.mag_map_array[:, 0],
                                                      y_vector=self.mag_map_array[:, 1],
                                                      b_field_vector=self.mag_map_array[:, 2],
                                                      output_directory=self.output_directory_magnetic_field)
     self.im_short_mag_dict = self.simplify_the_magnetic_field_dictionary(self.mag_dict)
     print("CURRENT MAGNETIC FIELD MAP: {}".format(self.im_short_mag_dict))
     GeneralFunctions.copy_object_to_another_object(
         directory_to_copy=os.path.join(factory.input_directory, factory.
                                        input_data.magnetic_field_settings.input.B_map_foldername),
         directory_destination=os.path.join(factory.input_copy_directory, "magnetic_field"))
 def extract_joule_heating_density_profile(self,
                                           joule_heating_density_array):
     """
     Saves txt and png files with Joule heating initial profile
     :param joule_heating_density_array: numpy array;
     1st column temperature as float, 2nd column: joule heating density as float
     """
     GeneralFunctions.save_array(self.output_directory_materials,
                                 "joule_heating_density_profile.txt",
                                 joule_heating_density_array)
     MaterialPropertiesPlotter.plot_material_properties(
         directory=self.output_directory_materials,
         filename="joule_heating_density_profile.png",
         array=joule_heating_density_array,
         y_axis_name="Joule Heating Density, " +
         MaterialPropertiesUnits.power_density_unit)
Пример #15
0
 def calculate_energy_initially_deposited_inside_the_coil(
         self, temperature_init_distr, magnetic_field_value):
     energy_deposition = self.material_properties.calculate_energy(
         im_temp_profile=temperature_init_distr,
         im_coil_geom=self.geometry.coil_geometry,
         mag_field=magnetic_field_value,
         wire_diameter=self.input_data.geometry_settings.type_input.
         d_strand,
         ref_temperature=self.input_data.temperature_settings.input.T_bath)
     GeneralFunctions.write_line_to_file(
         self.plots.output_directory_temperature,
         "initial_energy_deposition_in_strand.txt",
         "Initial deposited energy equals: {} [J]".format(
             energy_deposition))
     print(self.initial_energy_deposition_to_string(energy_deposition))
     return energy_deposition
 def retrieve_1d_imaginary_coil(directory, coil_data):
     """
     Retrieves two last columns from coil_data numpy array
     :param directory: .txt file directory as string
     :param coil_data: 4-column numpy array; 1st column: winding number, 2nd column: real node number,
     3rd column: imaginary node number, 4th column: length at the given imaginary node number
     :return: Two-column numpy array without repetitions of its rows;
              1-ordered plane number along 1D coil length as float, 2-imaginary 1D coil length as float
     """
     coil_length_1d = coil_data[:, 2:4]
     coil_length_1d = Geometry.delete_repetitive_rows(coil_length_1d)
     coil_length_1d_sorted = coil_length_1d[coil_length_1d[:, 0].argsort()]
     GeneralFunctions.save_array(directory=directory,
                                 filename="im_coil_length.txt",
                                 array=coil_length_1d_sorted)
     return coil_length_1d_sorted
Пример #17
0
 def plot_resistive_voltage(self):
     if self.input_data.analysis_type.input.png_resistive_voltage_output:
         res_voltage_array = GeneralFunctions.load_file_python(
             directory=self.plots.output_directory_resistive_voltage,
             filename="resistance_voltage.txt")
         self.plots.plot_resistive_voltage(
             time_vector=res_voltage_array[:, 0],
             voltage_vector=res_voltage_array[:, 2],
             additional_description="ansys")
Пример #18
0
 def get_material_properties_class(factory):
     """
     Returns a Class which is the engine for material properties evaluation
     :param factory: Class with input data instances from analysis_engine
     :return: Class with material properties evaluation engine
     """
     output_directory_materials = GeneralFunctions.create_folder_in_directory(
         factory.output_directory, "material_properties")
     return MaterialProperties(factory, output_directory_materials)
    def check_quench_state_quench_velocity(self):
        if self.is_all_coil_quenched is False:
            temperature_profile = self.temperature_profile
            quench_fronts_new = self.q_det.detect_quench(
                self.quench_fronts,
                temperature_profile,
                magnetic_field_map=self.magnetic_map.im_short_mag_dict)
            self.quenched_windings_list_new = []
            self.quench_fronts_new = []

            for qf_new in quench_fronts_new:
                self.quench_fronts_new.append(
                    self.qf(x_down=qf_new[0],
                            x_up=qf_new[1],
                            label=self.quench_label,
                            factory=self.factory,
                            class_geometry=self.geometry))
                self.quenched_windings_list_new.extend(
                    list(
                        self.geometry.
                        retrieve_winding_numbers_and_quenched_nodes(
                            x_down_node=self.quench_fronts_new[-1].x_down_node,
                            x_up_node=self.quench_fronts_new[-1].x_up_node).
                        keys()))
                self.quench_label += 1

            for qf in self.quench_fronts:
                self.quenched_windings_list_new.extend(
                    list(
                        self.geometry.
                        retrieve_winding_numbers_and_quenched_nodes(
                            x_down_node=qf.x_down_node,
                            x_up_node=qf.x_up_node).keys()))
            self.quenched_windings_list_new = GeneralFunctions.remove_duplicate_strings_from_list(
                self.quenched_windings_list_new)
            self.quenched_windings_list_new.sort()

            self.check_if_new_winding_quenched()
            self.quenched_windings_list.extend(self.quenched_windings_list_new)
            self.quenched_windings_list = GeneralFunctions.remove_duplicate_strings_from_list(
                self.quenched_windings_list)
            self.quenched_windings_list.sort()
            self.quench_fronts.extend(self.quench_fronts_new)
Пример #20
0
 def create_first_lines_of_input_parameter_file_for_ansys(self, data):
     """
     :param data: Class object to create APDL commands .txt file
     Creates an input file with parameters used by ANSYS
     """
     data.write_text('/clear')
     data.write_text('/title,Quench_Analysis_' +
                     self.input_data.geometry_settings.dimensionality)
     data.write_text('/prep7')
     data.write_text('/nerr,999999999999')
     data.write_text('/graphics,power')
     data.write_text('/show,png')
     data.write_text('electric_analysis={}'.format(
         GeneralFunctions.change_boolean_into_integer(
             self.input_data.circuit_settings.electric_ansys_elements)))
     data.write_text('insulation_analysis =' + str(
         GeneralFunctions.change_boolean_into_integer(
             self.input_data.geometry_settings.type_input.
             type_insulation_settings.insulation_analysis)))
Пример #21
0
    def plot_quench_state_in_analysis(self):
        iteration = self.iteration[0]

        if self.is_all_coil_quenched is False:
            quench_state_array = self.geometry.create_quench_state_array(
                coil_length_array=self.geometry.coil_geometry,
                quench_fronts_list=self.quench_fronts)
            GeneralFunctions.save_array(
                directory=self.plots.output_directory_quench_state,
                filename="quench_state_{}.txt".format(self.iteration[0]),
                array=quench_state_array)

            self.is_all_coil_quenched = self.check_if_entire_coil_quenched(
                quench_state_array)

            if self.input_data.analysis_type.input.png_quench_state_output:
                quench_state_plot = self.plots.plot_and_save_quench_state(
                    quench_state_array, iteration=iteration)
                self.quench_state_plots.append(quench_state_plot)
Пример #22
0
 def plot_temperature(coil_length, directory, temperature_profile_1d, time_step, filename):
     """
     Plots temperature distribution
     :param coil_length: coil length numpy array; 1st column - node number, 2nd column position in [m]
     :param directory: analysis output_directory as string
     :param filename: filename as string
     :param time_step: time step as float
     """
     time_step = round(time_step, 4)
     length_node_temp_array = np.column_stack((coil_length, temperature_profile_1d[:, 1]))
     fig = plt.figure()
     ax = fig.add_subplot(111)
     ax.set_xlabel('x, m')
     ax.set_ylabel('T, K')
     plt.title("t = {} s".format(time_step))
     ax.plot(length_node_temp_array[:, 1], length_node_temp_array[:, 2])
     plt.grid(True)
     plt.show()
     if os.path.isfile(filename):
         GeneralFunctions.delete_file(directory=directory, filename=filename)
     return fig
 def load_1d_temperature(directory,
                         npoints,
                         filename="Temperature_Data.txt"):
     """
     Loads file with nodal temperature results
     :param directory: output_directory of the file as string
     :param npoints: number of nodes in geometry as integer
     :param filename: filename as string; default: "Temperature_Data.txt"
     """
     return GeneralFunctions.load_file_ansys(directory=directory,
                                             npoints=npoints,
                                             filename=filename)
 def create_initial_time_step_vector(time_step, total_time):
     """
     Returns at time vector for simulation with constant time step
     :param time_step: time step as float
     :param total_time: total simulation time as float
     :return: list of time steps
     """
     if type(time_step) != float or type(total_time) != float:
         raise TypeError("Time step and total time should be float numbers !!!")
     vector = []
     i = time_step
     time_step_digits = GeneralFunctions.check_number_of_digits_behind_comma(time_step)
     vector.append(0.0)
     while i <= total_time:
         vector.append(round(i, time_step_digits))
         i += time_step
         if i >= total_time:
             vector.append(total_time)
     vector = GeneralFunctions.remove_repetitive_values_from_list(vector)
     print(TimeStep.time_step_vector_to_string(vector))
     return vector
Пример #25
0
 def copy_input_json_file_to_output_directory(self):
     """
     Copies all input files used in the analysis to the output output_directory
     :return: directory with copied input files as string
     """
     os.chdir(self.output_directory)
     input_copy_directory = GeneralFunctions.create_folder_in_directory(
         directory=self.output_directory, foldername="input_copy")
     input_json_file_directory = os.path.join(self.input_directory,
                                              self.json_filename)
     shutil.copy(input_json_file_directory, input_copy_directory)
     return input_copy_directory
Пример #26
0
    def plot_temperature_profile(self):
        time_step = [self.time_step_vector[self.iteration[0]]][0]

        txt_temperature_filename = "temperature_profile_" + str(
            self.iteration[0]) + ".txt"
        temperaature_profile_array = self.geometry.create_temperature_profile_array(
            temperature_profile=self.temperature_profile,
            coil_length_array=self.geometry.coil_geometry)
        GeneralFunctions.save_array(
            directory=self.plots.output_directory_temperature,
            filename=txt_temperature_filename,
            array=temperaature_profile_array)

        if self.input_data.temperature_settings.input.png_temperature_output:
            temperature_plot = self.plots.plot_and_save_temperature(
                directory=self.directory,
                coil_length=self.geometry.coil_geometry,
                temperature_profile_1d=self.temperature_profile,
                iteration=self.iteration[0],
                time_step=time_step)
            self.quench_temperature_plots.append(temperature_plot)
Пример #27
0
    def create_ic_temperature_profile(self):
        self.initial_temperature_profile = np.zeros((len(self.geometry.coil_geometry[:, 0]), 2))
        self.initial_temperature_profile[:, 0] = self.geometry.coil_geometry[:, 0]
        self.initial_temperature_profile[:, 1] = self.input_data.temperature_settings.input.T_bath

        geometry_dimensions = InitialTemperatureUniform.find_start_and_end_length_of_coil(self.geometry.coil_geometry)
        ic_zone_dimensions = InitialTemperatureUniform.set_length_of_initial_ic_temperature_zone(
            zone_centre=self.input_data.analysis_settings.x_quench_init,
            zone_length=self.input_data.analysis_settings.L_quench_init,
            geometry_dimensions=geometry_dimensions)
        ic_zone_node_min = SearchNodes.search_init_node(position=ic_zone_dimensions[0],
                                                        coil_length=self.geometry.coil_geometry)
        ic_zone_node_max = SearchNodes.search_init_node(position=ic_zone_dimensions[1],
                                                        coil_length=self.geometry.coil_geometry)
        self.initial_temperature_profile[(ic_zone_node_min-1):ic_zone_node_max, 1] = \
            self.input_data.temperature_settings.input.T_max
        self.plots.plot_and_save_temperature(
            self.output_directory, self.geometry.coil_geometry,
            self.initial_temperature_profile, iteration=0, time_step=0.0)
        GeneralFunctions.save_array(self.plots.output_directory_temperature,
                        "temperature_profile_0.txt", self.initial_temperature_profile)
        return self.initial_temperature_profile
Пример #28
0
    def load_magnetic_maps_dependent_on_current(self, decimal_tolerance=10):
        filename_list = GeneralFunctions.make_list_of_filenames_in_directory(self.magnetic_field_map_directory)
        current_axis_number = GeneralFunctions.count_number_of_occurencies_of_substring_in_list(
            list_of_strings=filename_list, substring="magnetic_field_current_")
        magnet_nodal_pos = self.load_x_y_nodal_magnet_position()
        x_pos = magnet_nodal_pos[0]
        y_pos = magnet_nodal_pos[1]

        b_field_array = np.zeros((len(x_pos), len(y_pos), current_axis_number))
        current_list = []
        for filename in filename_list:
            if "magnetic_field_current_" in filename:
                path = os.path.join(self.magnetic_field_map_directory, filename)
                array = np.loadtxt(path, skiprows=9).round(decimal_tolerance)
                array_sorted = array[np.lexsort((array[:, 1], array[:, 0]))]
                b_field = array_sorted[:, 5]
                b_field_reshaped = b_field.reshape(len(x_pos), len(y_pos))
                current_value = float(filename.replace("magnetic_field_current_", " ").replace(".txt", " "))
                current_list.append(current_value)
                b_field_array[:, :, int(current_value)-1] = b_field_reshaped
        current_list.sort()
        current_array = np.asarray(current_list)
        return x_pos, y_pos, current_array, b_field_array
Пример #29
0
 def delete_old_ansys_analysis_files(self):
     """
     Deletes unnecessary files saved during previous analyses
     """
     GeneralFunctions.delete_file(directory=self.directory,
                                  filename='Variable_Input.inp')
     GeneralFunctions.delete_file(directory=self.directory,
                                  filename='File_Position.txt')
     GeneralFunctions.delete_file(directory=self.directory,
                                  filename='Process_Finished.txt')
 def load_temperature_and_map_onto_1d_cable(self,
                                            directory,
                                            npoints,
                                            filename="Temperature_Data.txt"
                                            ):
     """
     Loads temperature file with real nodes and maps it onto 1D cable length
     :param directory: full analysis output_directory as string
     :param npoints: number of nodes as integer in meshed ANSYS geometry
     :param filename: filename as string with temperature profile
     :returns: 2-column numpy array; 1-imaginary node number as float, 2-node temperature as float
     """
     temperature_profile = GeneralFunctions.load_file_ansys(
         directory=directory, npoints=npoints, filename=filename)
     coil_temperature_1d = self.map_temperature_into_1d_cable(
         temperature_profile=temperature_profile)
     return coil_temperature_1d