예제 #1
0
def Surrogate_Model():
    rbf_type = 'lin_a'
    list_w_stress = []
    list_w_dSum = []
    # list_y_name = []
    stds = ''
    cycle_index = len(list_stress)
    for i in range(cycle_index):
        stress_real = list_stress[i]
        dSum_real = list_disp_sum[i]
        rbfnet_stress = RBF(rbf_type)
        rbfnet_dSum = RBF(rbf_type)
        w_stress = rbfnet_stress.fit(fd, stress_real)
        w_disp = rbfnet_dSum.fit(fd, dSum_real)
        stds = str(rbfnet_stress.std)
        list_w_stress.append(w_stress)
        list_w_dSum.append(w_disp)
        print("\r" + rbfnet_stress.__class__.__name__ + "程序当前已完成:" + str(round(i / cycle_index * 10000) / 100) + '%',
              end="")

    stepAndMin = path_switch[4:-2] + '_others'
    ele = path_switch[4:-2] + '_ele'
    dSum_w = path_switch[4:-2] + '_dSum_w'
    stress_w = path_switch[4:-2] + '_stress_w'
    coord = path_switch[4:-2] + '_coord'
    x_train = ','.join(map(lambda x: ','.join(map(str, x)), fd.tolist()))

    pathisExists = os.path.exists(path_four_write)
    if not pathisExists:
        os.makedirs(path_four_write)  # 不存在创建目录
        pf.printf('文件夹[' + path_four_write + ']创建成功,正在写入文件...')
    # 步数和最小值,方差,输入值
    text_Create(path_four_write, stepAndMin,
                d_step + ',' + d_min + ',' + s_step + ',' + s_min + '\n' + stds + '\n' + x_train)
    # 索引文件
    text_Create(path_four_write, ele, ','.join(map(str, list_ele_data)))
    # 坐标文件
    text_Create(path_four_write, coord, ','.join(list_coord_results))
    # 总位移文件
    text_Create(path_four_write, dSum_w, '\n'.join(list_w_dSum) + '\n' + rbf_type)
    # 应力文件
    text_Create(path_four_write, stress_w, '\n'.join(list_w_stress) + '\n' + rbf_type)
예제 #2
0
    def allDisplacement_To_Str_Beam188(self):
        isExisted = os.path.exists(self.path_displacement)
        if not isExisted:
            pf.printf(self.path_displacement)
            pf.printf('上面列出的路径不存在,请设置正确路径!')
            return
        else:
            pf.printf('目录[' + self.path_displacement + ']存在,正在读取...')
        """
             2020.12.19 从其他程序移植两个功能:
             1、自动删除"file0.page", "file1.page"
             2、对中间加了横杠的文件进行排序
        """
        files = os.listdir(self.path_displacement)  # 获取当前文档下的文件
        abandon_files = ["file0.page", "file1.page"]
        for file in files:
            file_name = os.path.basename(file)
            if file_name in abandon_files:
                os.remove(self.path_displacement + file_name)
        files = os.listdir(self.path_displacement)  # 获取当前文档下的文件
        # files_cut = sorted(files[0:-1], key=lambda x: int(x[:-4]))
        # files_cut = sorted(files[0:-1], key=lambda x: int(x[:-4]))
        # 先按照文件名的第二个数字排列
        files_cut_sorted_1 = sorted(files[0:-1], key=lambda x: int(x[:-4].split('_')[1]))
        # 再按照文件名的第一个数字排列
        files_cut_sorted_2 = sorted(files_cut_sorted_1, key=lambda x: int(x[:-4].split('_')[0]))
        float_Dcolor_step, float_Dcolor_min = colord.color_Step(files_cut_sorted_2, self.path_displacement,
                                                                'd')  # 获取step

        i_processing = 1  # 遍历到第i个文件
        str_displacementXYZ_allFile = ''  # 不带初始坐标信息
        str_Dcolor_allFile = ''
        str_displacementSum_allFile = ''
        for file in files_cut_sorted_2:  # 遍历文件夹
            list_sort = []  # 存放加上位移后的所有坐标值的list
            list_Dcolor = []
            if not os.path.isdir(file):  # 判断是否是文件夹,不是文件夹才打开
                filename = os.path.basename(file)  # 返回文件名
                fullpath_input = self.path_displacement + filename  # 得到文件夹中每个文件的完整路径
                infile = open(fullpath_input, 'rt')  # 以文本形式读取文件
                for line in infile:
                    list_everyline = line.split()
                    list_sort.extend(
                        [list_everyline[1].strip(), list_everyline[2].strip(), list_everyline[3].strip()])
                    list_Dcolor.append(list_everyline[4].strip())  # 将位移之和的值传入数组
                infile.close()
            list_Dcolor_result = map(colord.define_Color, map(float, list_Dcolor),
                                     itertools.repeat(float_Dcolor_min),
                                     itertools.repeat(float_Dcolor_step))
            str_Dcolor_allFile += ','.join(map(str, list_Dcolor_result)) + '\n'

            str_displacementSum_allFile += ','.join(list_Dcolor) + '\n'
            str_displacementXYZ_allFile += ','.join(list_sort) + '\n'  # 以逗号为分隔符来组成字符串,并在最后添加换行符,以换行符区分每个文件的信息
            print("\r位移信息读取程序当前已完成:" + str(round(i_processing / len(files_cut_sorted_2) * 100)) + '%', end="")
            i_processing += 1
        str_Dcolor_allFile += str(float_Dcolor_step * 21 / 9)
        # print(str_coords_allFile.rstrip('\n'))
        return str_displacementXYZ_allFile.rstrip('\n'), str_displacementSum_allFile.rstrip(
            '\n'), str_Dcolor_allFile, float_Dcolor_step, float_Dcolor_min
예제 #3
0
 def __allEle_To_List(self):
     list_result = []
     if self.path_ele is not None:
         isExisted = os.path.exists(self.path_ele)
         if not isExisted:
             pf.printf(self.path_ele)
             pf.printf('上面列出的路径不存在,请设置正确路径!')
             return
         else:
             pf.printf('文件[' +
                       self.path_ele[len(self.path_ele) -
                                     self.path_ele[::-1].index('\\'):] +
                       ']存在,正在读取...')
         eleFile = open(self.path_ele, "rt")
         index_ele = 0
         for every_line in eleFile:
             list_everyline = every_line.split()
             list_cut = list_everyline[1:]
             list_temp = list(map(int, list_cut))
             if (int(list_everyline[0]) - index_ele) != 1:
                 break
             list_result.extend(self.sort_Node_Index(list_temp))
             index_ele += 1
         eleFile.close()
         pf.printf('文件[' + self.path_ele[len(self.path_ele) -
                                         self.path_ele[::-1].index('\\'):] +
                   ']读取完成!')
     if self.data_list is not None:
         for every_component in self.data_list:
             index_ele = 0
             list_component = []
             # print(every_component)
             for every_line in every_component:
                 # if len(every_line) == 0:
                 #     print(every_line)
                 # if index_ele == 0:
                 #     print(every_line)
                 # print(every_line)
                 list_temp = every_line[1:]
                 list_component.extend(self.sort_Node_Index(list_temp))
                 # index_ele += 1
             list_result.append(list_component)
             # print(len(list_component)/12)
     return list_result
예제 #4
0
    def read_stress(self, path, mode="h"):

        """
        :param path: 多个static structural数据路径
        :return:
        """
        isExisted = os.path.exists(path)
        if not isExisted:
            pf.printf(path)
            pf.printf('上面列出的路径不存在,请设置正确路径!')
            return
        else:
            pf.printf('目录[' + path + ']存在,正在读取...')
        files = os.listdir(path)  # 获取当前文档下的文件
        abandon_files = ["file0.page", "file1.page"]
        for file in files:
            file_name = os.path.basename(file)
            if file_name in abandon_files:
                os.remove(path + file_name)
        files = os.listdir(path)  # 获取当前文档下的文件
        # 先按照文件名的第二个数字排列
        files_cut_sorted_1 = sorted(files, key=lambda x: int(x[:-4].split('_')[1]))
        # 再按照文件名的第一个数字排列
        files_cut_sorted_2 = sorted(files_cut_sorted_1, key=lambda x: int(x[:-4].split('_')[0]))

        list_stress = []
        for file in files_cut_sorted_2:
            file_content = open(path + os.path.basename(file), 'rt')
            if mode == 'h':
                first_line = file_content.read()
                each_point_stress = first_line.split()
                list_stress.append(list(map(float, each_point_stress)))
            elif mode == 'v':
                list_everyfile = []
                for line in file_content:
                    list_everyline = line.split()
                    list_everyfile.append(float(list_everyline[1]))
                list_stress.append(list_everyfile)
            else:
                pass
            file_content.close()
        return list_stress
예제 #5
0
 def __allEle_To_List(self):
     TETRAHEDRON_LINEAR = '3D4_L'
     TETRAHEDRON_PROGRAM_CONTROL = '3D4_P'
     HEXAHEDRON = '3D6'
     TETRAHEDRAL_SHEET = '2D4'
     """
     2020.12.13 增加BEAM188的解析
     """
     BEAM_188 = 'BEAM_188'
     isExisted = os.path.exists(self.path_ele)
     if not isExisted:
         pf.printf(self.path_ele)
         pf.printf('上面列出的路径不存在,请设置正确路径!')
         return
     else:
         pf.printf('文件[' + self.path_ele[len(self.path_ele) - self.path_ele[::-1].index('\\'):] + ']存在,正在读取...')
     eleFile = open(self.path_ele, "rt")
     list_result = []
     index_ele = 0
     for everyline in eleFile:
         list_everyline = everyline.split()
         list_cut = list_everyline[1:]
         list_temp = list(map(int, list_cut))
         # if list_everyline[0] == '1':
         #     print(list_temp)
         if len(list_temp) == 8:
             if TETRAHEDRON_LINEAR in self.geometry_type:
                 """ 
                 2020.12.12
                 有时候单元序号是不连续的,但是单元类型是相同的。
                 【变保真的会议论文中,桁架的单元序号出现了不连续209179直接跳到了209276】,
                 但都是solid185单元。
                 其实在apdl导出时,程序通常仅保留单个类型的单元,所以下面这一句判断可以不加,但也要看情况
                 【查明原因】:因为有solid186单元没有导出,导致序号不连续。
                 """
                 # if (int(list_everyline[0]) - index_ele) != 1:
                 #     break
                 # 1332  2391  1389  1389  1372  1372  1372  1372
                 # 1594  1999  1617  1617  1616  1616  1616  1616
                 # 所有的ele【前4位】排列为【四面体】的画图形式,得到这些值并存在list_result中
                 list_result.extend([list_temp[0] - 1, list_temp[2] - 1, list_temp[1] - 1,  # outter
                                     list_temp[1] - 1, list_temp[2] - 1, list_temp[4] - 1,  # outter
                                     list_temp[0] - 1, list_temp[4] - 1, list_temp[2] - 1,  # outter
                                     list_temp[0] - 1, list_temp[1] - 1, list_temp[4] - 1])  # outter
             elif TETRAHEDRON_PROGRAM_CONTROL in self.geometry_type:
                 # if (int(list_everyline[0]) - index_ele) != 1:
                 #     break
                 # 190     919    1105     747
                 # 88239   88800   88850   89126
                 # 所有的ele【前4位】排列为【四面体】的画图形式,得到这些值并存在list_result中
                 list_result.extend([list_temp[0] - 1, list_temp[2] - 1, list_temp[1] - 1,
                                     list_temp[1] - 1, list_temp[2] - 1, list_temp[3] - 1,
                                     list_temp[0] - 1, list_temp[3] - 1, list_temp[2] - 1,
                                     list_temp[0] - 1, list_temp[1] - 1, list_temp[3] - 1])
             elif HEXAHEDRON in self.geometry_type:
                 # 所有的ele【前8位】排列为【六面体】的画图形式,得到这些值并存在list_result中
                 list_result.extend(
                     [list_temp[0] - 1, list_temp[1] - 1, list_temp[2] - 1,
                      list_temp[0] - 1, list_temp[2] - 1, list_temp[3] - 1,
                      list_temp[4] - 1, list_temp[5] - 1, list_temp[6] - 1,
                      list_temp[4] - 1, list_temp[6] - 1, list_temp[7] - 1,
                      list_temp[0] - 1, list_temp[3] - 1, list_temp[7] - 1,
                      list_temp[0] - 1, list_temp[4] - 1, list_temp[7] - 1,
                      list_temp[1] - 1, list_temp[5] - 1, list_temp[6] - 1,
                      list_temp[1] - 1, list_temp[2] - 1, list_temp[6] - 1,
                      list_temp[0] - 1, list_temp[4] - 1, list_temp[5] - 1,
                      list_temp[0] - 1, list_temp[1] - 1, list_temp[5] - 1,
                      list_temp[2] - 1, list_temp[6] - 1, list_temp[7] - 1,
                      list_temp[2] - 1, list_temp[6] - 1, list_temp[7] - 1])
         elif len(list_temp) == 4:
             if TETRAHEDRAL_SHEET in self.geometry_type:
                 list_result.extend([list_temp[0] - 1, list_temp[1] - 1,
                                     list_temp[2] - 1, list_temp[2] - 1,
                                     list_temp[0] - 1, list_temp[3] - 1])
         elif len(list_temp) == 3:
             if BEAM_188 in self.geometry_type:
                 list_result.extend([list_temp[0] - 1, list_temp[1] - 1])
         index_ele += 1
     eleFile.close()
     pf.printf('文件[' + self.path_ele[len(self.path_ele) - self.path_ele[::-1].index('\\'):] + ']读取完成!')
     return list_result
예제 #6
0
    def surface_Stress_Scolor(self):
        isExisted = os.path.exists(self.path_stress)
        if not isExisted:
            pf.printf(self.path_stress)
            pf.printf('上面列出的路径不存在,请设置正确路径!')
            return
        else:
            pf.printf('目录[' + self.path_stress + ']存在,正在读取...')
        """
        2020.12.19 从其他程序移植两个功能:
        1、自动删除"file0.page", "file1.page"
        2、对中间加了横杠的文件进行排序
        """
        files = os.listdir(self.path_stress)  # 获取当前文档下的文件
        abandon_files = ["file0.page", "file1.page"]
        for file in files:
            file_name = os.path.basename(file)
            if file_name in abandon_files:
                os.remove(self.path_stress + file_name)
        files_stress = os.listdir(self.path_stress)  # 获取当前文档下的文件
        # files_stress.sort(key=lambda x: int(x[:-4]))
        # 先按照文件名的第二个数字排列
        files_cut_sorted_1 = sorted(files_stress,
                                    key=lambda x: int(x[:-4].split('_')[1]))
        # 再按照文件名的第一个数字排列
        files_cut_sorted_2 = sorted(files_cut_sorted_1,
                                    key=lambda x: int(x[:-4].split('_')[0]))
        float_Scolor_step, float_Scolor_min = colord.color_Step(
            files_cut_sorted_2, self.path_stress, 's')  # 获取step

        set_surface_ele = self.ed.set_SurfaceEle()

        i_processing = 0
        str_Scolor_allFile = ''
        str_stress_allFile = ''
        for file in files_cut_sorted_2:  # 遍历文件夹
            list_Scolor = []
            if not os.path.isdir(file):  # 判断是否是文件夹,不是文件夹才打开
                filename = os.path.basename(file)  # 返回文件名
                fullpath = self.path_stress + filename  # 得到文件夹中每个文件的完整路径
                infile = open(fullpath, 'rt')  # 以文本形式读取文件
                for line in infile:
                    list_everyline = line.split()
                    line_index = int(list_everyline[0])
                    if line_index in set_surface_ele:
                        list_Scolor.append(list_everyline[1].strip()
                                           )  # 将每一行以制表符分开后加入到list_Scolor序列中

                infile.close()
            list_Scolor_result = map(colord.define_Color,
                                     map(float, list_Scolor),
                                     itertools.repeat(float_Scolor_min),
                                     itertools.repeat(float_Scolor_step))

            i_processing += 1
            print("\r应力信息读取程序当前已完成:" +
                  str(round(i_processing / len(files_cut_sorted_2) * 100)) +
                  '%',
                  end="")
            str_Scolor_allFile += ','.join(
                map(str, list_Scolor_result
                    )) + '\n'  # 以逗号为分隔符来组成字符串,并在最后添加换行符,以换行符区分每个文件的信息
            str_stress_allFile += ','.join(list_Scolor) + '\n'

        str_Scolor_allFile += str(float_Scolor_step * 21 / 9)
        return str_stress_allFile.rstrip('\n'), str_Scolor_allFile, str(
            float_Scolor_step) + ',' + str(float_Scolor_min)
예제 #7
0
    def dataSaveToTXT_RBF(self, v_fd, rbf_type='lin_a', which_part='truss'):
        """
        和上一版本的区别是,位移数据和坐标数据分开导出
        :param v_fd: 输入的训练自变量
        :param rbf_type: 使用的rbf类型
        :param which_part: 存储的数据是哪个零件的
        :return:
        """
        surfaced = SurfaceData(self.path_read, self.geometry_type)
        """以下为节点数据"""
        # 索引
        list_ele = surfaced.get_Ele_Data()
        # print(len(set(sorted(map(int, txt_ele.split(',')), key=lambda x: x))))
        list_coords = surfaced.get_Coord_Data()
        # 位移
        txt_displacement, txt_dopSum, d_step, d_min = surfaced.get_Displacement_DopSum_Dcolor_Bysorted(
        )
        # 应力
        txt_stress, s_step, s_min = surfaced.get_Stress_SStepandMin_Bysorted()
        # print(len(txt_coord.split('\n')[0].split(',')))
        stds = ''
        list_stress, len_data_stress = _getData(txt_stress, 'stressOrdSum')
        list_dopSum, len_data_dopSum = _getData(txt_dopSum, 'stressOrdSum')
        if len_data_stress != len_data_dopSum:
            print('displacement数据与stress数据数目不同!\n'
                  'displacemen数据个数:' + str(len_data_dopSum) +
                  '      stress数据个数:' + str(len_data_stress))
            return
        # list_w_1 = []
        # list_w_2 = []
        list_w_stress = []
        list_w_dSum = []
        # list_y_name = []
        cycle_index = len(list_stress)
        for i in range(cycle_index):
            # for i in range(1):
            stress_real = list_stress[i]
            dSum_real = list_dopSum[i]
            # rbfnet_1 = RBF(rbf_type)
            # rbfnet_2 = RBF(rbf_type)
            rbfnet_stress = RBF(rbf_type)
            rbfnet_dSum = RBF(rbf_type)
            # w_1 = rbfnet_1.fit(v_fd, real_1)
            # w_2 = rbfnet_2.fit(v_fd, real_2)
            w_stress = rbfnet_stress.fit(v_fd, stress_real)
            w_dSum = rbfnet_dSum.fit(v_fd, dSum_real)
            stds = str(rbfnet_stress.std)
            # list_w_1.append(w_1)
            # list_w_2.append(w_2)
            list_w_stress.append(','.join(map(str, w_stress)))
            list_w_dSum.append(','.join(map(str, w_dSum)))
            print("\r" + rbfnet_stress.__class__.__name__ + "程序当前已完成:" +
                  str(round(i / len(list_stress) * 10000) / 100) + '%',
                  end="")
            # x = np.array([0, 90, 180, 270, 360])
            # plt.plot(x, rbfnet_stress.predict(np.array([[0, 125],
            #                                             [90, 125],
            #                                             [180, 125],
            #                                             [270, 125],
            #                                             [360, 125],
            #                                             ])))
            # plt.show()

        w_1 = 'w_1'
        w_2 = 'w_2'

        stepAndMin = which_part + '_others'
        ele = which_part + '_ele'
        dSum_w = which_part + '_dSum_w'
        stress_w = which_part + '_stress_w'
        coord = which_part + '_coord'

        if v_fd.ndim == 1:
            x_train = ','.join(map(str, v_fd.tolist()))
        elif v_fd.ndim == 2:
            x_train = ','.join(
                map(lambda x: ','.join(map(str, x)), v_fd.tolist()))
        else:
            x_train = "null"
        pathisExists = os.path.exists(self.path_write)
        if not pathisExists:
            os.makedirs(self.path_write)  # 不存在创建目录
            pf.printf('文件夹[' + self.path_write + ']创建成功,正在写入文件...')
        # 步数和最小值,方差,输入值
        tfc.text_Create(
            self.path_write, stepAndMin,
            str(d_step) + ',' + str(d_min) + ',' + str(s_step) + ',' +
            str(s_min) + '\n' + stds + '\n' + x_train)
        # 索引文件
        tfc.text_Create(self.path_write, ele, ','.join(map(str, list_ele)))
        # 总位移文件
        tfc.text_Create(self.path_write, dSum_w,
                        '\n'.join(list_w_dSum) + '\n' + rbf_type)
        # 应力文件
        tfc.text_Create(self.path_write, stress_w,
                        '\n'.join(list_w_stress) + '\n' + rbf_type)
        # # 坐标文件【坐标一般需要变换一下,就不直接输出了】
        tfc.text_Create(self.path_write, coord, ','.join(map(str,
                                                             list_coords)))
예제 #8
0
    def dataSaveToJSON_RBF_Aerofoil(self,
                                    v_fd,
                                    rbf_type='lin_a',
                                    which_part='truss'):
        """
        因为机翼和小板都是对称的,所以训练集的响应值可以直接对称复制一下,与以前的训练方式略有不同
        :param v_fd: 输入的训练自变量
        :param rbf_type: 使用的rbf类型
        :param which_part: 存储的数据是哪个零件的
        :return:
        """
        surfaced = SurfaceData(self.path_read, self.geometry_type)
        """以下为节点数据"""
        # 索引
        list_ele = surfaced.get_Ele_Data()
        # print(len(set(sorted(map(int, list_ele.split(',')), key=lambda x: x))))
        list_coords = surfaced.get_Coord_Data()
        # 位移
        txt_displacement, txt_dopSum, d_step, d_min = surfaced.get_Displacement_DopSum_Dcolor_Bysorted(
        )
        # 应力
        txt_stress, s_step, s_min = surfaced.get_Stress_SStepandMin_Bysorted()
        # print(len(list_coords.split('\n')[0].split(',')))
        stds = None
        list_stress, len_data_stress = _getData(txt_stress, 'stressOrdSum')
        list_dopSum, len_data_dopSum = _getData(txt_dopSum, 'stressOrdSum')
        list_x, list_y, list_z = _getData(txt_displacement, 'coord')

        if len_data_stress != len_data_dopSum:
            print('displacement数据与stress数据数目不同!\n'
                  'displacemen数据个数:' + str(len_data_dopSum) +
                  '      stress数据个数:' + str(len_data_stress))
            return
        list_w_stress = []
        list_w_dSum = []
        list_w_y = []
        list_w_z = []
        cycle_index = len(list_stress)

        for i in range(cycle_index):
            coord_y_real = list_coords[i * 3 + 1]
            coord_z_real = list_coords[i * 3 + 2]
            stress_real = list_stress[i]
            stress_real.insert(0, 0)
            deformation_real = list_dopSum[i]
            deformation_real.insert(0, 0)

            y_real = list_y[i]
            y_real.insert(0, 0)
            # y_real = [y_real_child + coord_y_real for y_real_child in y_real]

            z_real = list_z[i]
            z_real.insert(0, 0)
            # z_real = [z_real_child + coord_z_real for z_real_child in z_real]

            rbf_stress = RBF(rbf_type)
            rbf_deformation = RBF(rbf_type)
            rbf_y = RBF(rbf_type)
            rbf_z = RBF(rbf_type)

            w_stress = rbf_stress.fit(v_fd, stress_real)
            w_dSum = rbf_deformation.fit(v_fd, deformation_real)
            w_y = rbf_y.fit(v_fd, y_real)
            w_z = rbf_z.fit(v_fd, z_real)

            if i == 0:
                stds = rbf_stress.std
            list_w_stress.append(w_stress)
            list_w_dSum.append(w_dSum)
            list_w_y.append(w_y)
            list_w_z.append(w_z)
            print("\r" + rbf_stress.__class__.__name__ + "程序当前已完成:" +
                  str(round(i / len(list_stress) * 10000) / 100) + '%',
                  end="")

        if v_fd.ndim == 1:
            x_train = v_fd.flatten().tolist()
        elif v_fd.ndim == 2:
            x_train = v_fd.flatten().tolist()
        else:
            x_train = None
        pathisExists = os.path.exists(self.path_write)
        if not pathisExists:
            os.makedirs(self.path_write)  # 不存在创建目录
            pf.printf('文件夹[' + self.path_write + ']创建成功,正在写入文件...')

        dict_rbf_model = {
            # 因为机翼是对称的,只储存了一份坐标
            "coordinates": list_coords,
            "elements_index": list_ele,
            "stress_w": list_w_stress,
            "stress_step": s_step,
            "stress_min": s_min,
            "deformation_w": list_w_dSum,
            "deformation_step": d_step,
            "deformation_min": d_min,
            "y_w": list_w_y,
            "z_w": list_w_z,
            "stds": stds,
            "x_train": x_train,
            "rbf_type": rbf_type,
        }
예제 #9
0
    def dataSaveToJSON_RBF(self, v_fd, rbf_type='lin_a', which_part='truss'):
        """

        :param v_fd: 输入的训练自变量
        :param rbf_type: 使用的rbf类型
        :param which_part: 存储的数据是哪个零件的
        :return:
        """
        surfaced = SurfaceData(self.path_read, self.geometry_type)
        """以下为节点数据"""
        # 索引
        list_ele = surfaced.get_Ele_Data()
        # print(len(set(sorted(map(int, list_ele.split(',')), key=lambda x: x))))
        list_coords = surfaced.get_Coord_Data()
        # 位移
        txt_displacement, txt_dopSum, d_step, d_min = surfaced.get_Displacement_DopSum_Dcolor_Bysorted(
        )
        # 应力
        txt_stress, s_step, s_min = surfaced.get_Stress_SStepandMin_Bysorted()
        # print(len(list_coords.split('\n')[0].split(',')))
        stds = None
        list_stress, len_data_stress = _getData(txt_stress, 'stressOrdSum')
        list_dopSum, len_data_dopSum = _getData(txt_dopSum, 'stressOrdSum')
        if len_data_stress != len_data_dopSum:
            print('displacement数据与stress数据数目不同!\n'
                  'displacemen数据个数:' + str(len_data_dopSum) +
                  '      stress数据个数:' + str(len_data_stress))
            return
        list_w_stress = []
        list_w_dSum = []
        cycle_index = len(list_stress)
        for i in range(cycle_index):
            stress_real = list_stress[i]
            deformation_real = list_dopSum[i]
            rbf_stress = RBF(rbf_type)
            rbf_deformation = RBF(rbf_type)
            w_stress = rbf_stress.fit(v_fd, stress_real)
            w_dSum = rbf_deformation.fit(v_fd, deformation_real)
            if i == 0:
                stds = rbf_stress.std
            list_w_stress.append(w_stress)
            list_w_dSum.append(w_dSum)
            print("\r" + rbf_stress.__class__.__name__ + "程序当前已完成:" +
                  str(round(i / len(list_stress) * 10000) / 100) + '%',
                  end="")
        if v_fd.ndim == 1:
            x_train = v_fd.flatten().tolist()
        elif v_fd.ndim == 2:
            x_train = v_fd.flatten().tolist()
        else:
            x_train = None
        pathisExists = os.path.exists(self.path_write)
        if not pathisExists:
            os.makedirs(self.path_write)  # 不存在创建目录
            pf.printf('文件夹[' + self.path_write + ']创建成功,正在写入文件...')

        dict_rbf_model = {
            "coordinates": list_coords,
            "elements_index": list_ele,
            "stress_w": list_w_stress,
            "stress_step": s_step,
            "stress_min": s_min,
            "deformation_w": list_w_dSum,
            "deformation_step": d_step,
            "deformation_min": d_min,
            "stds": stds,
            "x_train": x_train,
            "rbf_type": rbf_type,
        }
        # print(type(list_coords))
        # print(type(list_coords[0]))
        # print(type(list_ele))
        # print(type(list_ele[0]))
        # print(type(list_w_stress))
        # print(type(list_w_stress[0]))
        # print(type(s_step))
        # print(type(x_train))
        # print(type(rbf_type))
        # print(type(stds))

        json_rbf_model = json.dumps(dict_rbf_model)
        with open("C:/Users/laisir/Desktop/" + which_part + "_rbf.json",
                  "w") as f:
            json.dump(json_rbf_model, f)