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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MDOF Factory\n",
    "\n",
    "这个文件的主要功能就是测试各个 python 脚本,用来批量生成 MDOF 数据。包含几个步骤:\n",
    "\n",
    "1. 生成所需要的 BlgAttributes.txt 文件并复制到每个文件夹的 inputs 里面;\n",
    "2. 清空每个文件夹内的 Results 文件夹(或者以某种形式存起来,怕数据处理的时候出什么岔子);\n",
    "3. 运行批量运行 exe 文件的脚本 `Run_MDOF_Exe.py` ,等待 14 个 MDOF 文件夹内的 exe 脚本运行完毕;\n",
    "4. 读取买个文件夹的 Results 数据,将顶层结构加速度响应以及损伤等级保存到一个 hdf5 文件中;\n",
    "5. 重复以上四个步骤,直到所需要的情况训练完成。\n",
    "   \n",
    "SeT-4.0 版本所需要的建筑类型一共有 30 种情况,包含 1~10 层框架结构在 6,7,8 度抗震设防下的情况。使用的地震动是 knet 的 3474 条地震动(@Jie Zheng 整理的),使用 57 个调幅系数(@Jie Zheng 整理的)。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 生成 case.txt 文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "case.txt has been created with 30 cases.\n"
     ]
    }
   ],
   "source": [
    "# # 文件名\n",
    "# filename = 'case.txt'\n",
    "\n",
    "# # 打开文件以写入数据\n",
    "# with open(filename, 'w') as file:\n",
    "#     # 写入标题行,包含number作为序号\n",
    "#     file.write(\"number, Stories, height, IM, Site_CD\\n\")\n",
    "\n",
    "#     # 初始化序号\n",
    "#     number = 1\n",
    "\n",
    "#     # 生成案例\n",
    "#     for stories in range(1, 11):  # 1到10层,包含10层\n",
    "#         height = stories * 3  # 高度等于层数乘以3\n",
    "#         site_cd = 2  # 场地类别为2\n",
    "#         for im in range(6, 9):  # 抗震设防烈度为6,7,8\n",
    "#             # 写入案例数据,包括前面的序号\n",
    "#             file.write(f\"{number}, {stories}, {height}, {im}, {site_cd}\\n\")\n",
    "#             # 序号递增\n",
    "#             number += 1\n",
    "\n",
    "# # 打印文件创建完成的消息\n",
    "# print(f\"{filename} has been created with {number - 1} cases.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 生成所需要的 blgAttributes.txt 文件\n",
    "\n",
    "根据 case.txt 里面每一行的数据去更新 blgAttributes.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from Update_BlgAttributes_txt import update_blgattributes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Stories': '1', 'height': '3', 'IM': '7', 'Site_CD': '2'}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results = update_blgattributes(case_No=2)\n",
    "results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 复制 blgAttributes.txt 文件到每个文件夹的 inputs 里面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from Update_BlgAttributes_txt import update_blgattributes_txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "All BlgAttributes.txt files have been updated.\n"
     ]
    }
   ],
   "source": [
    "update_blgattributes_txt()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 清空之前的 Results 文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "from Delete_Results_Folder import delete_results_folder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "deleting results folder...\n"
     ]
    }
   ],
   "source": [
    "delete_results_folder()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 批量运行 exe 计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from Run_MDOF_Exe import run_exes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Running EXEs: 100%|██████████| 14/14 [00:00<00:00, 70.19exe/s]\n",
      "Waiting for EXEs to finish:   0%|          | 0/14 [00:00<?, ?exe/s]"
     ]
    }
   ],
   "source": [
    "run_exes()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 将 results 文件合并到 hdf5 文件中"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from Save_2_hdf5 import save"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Blg_F7_21m_IM7_SCD2.hdf5'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file_name = \"Blg_F\" + results[\"Stories\"] + \\\n",
    "            \"_\" + results[\"height\"] + \\\n",
    "            \"m_IM\" + results[\"IM\"] + \\\n",
    "            \"_SCD\" + results[\"Site_CD\"] + \\\n",
    "            \".hdf5\"\n",
    "\n",
    "file_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "save(file_name=file_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "killing exe files if existing...\n",
      "An error occurred while trying to terminate the process:\n",
      "ERROR: The process \"Flexural_Shear.exe\" not found.\n",
      "\n",
      "Case 1:\n",
      "Stories = 1\n",
      "height = 3\n",
      "IM = 6\n",
      "Site_CD = 2\n",
      "\n",
      "All BlgAttributes.txt files have been updated.\n",
      "Move blg.txt into each floder!\n",
      "deleting results folder...\n",
      "No 'j:\\SesimicTransformerData\\MDOF\\knet-250\\1-250\\Results' folder found in j:\\SesimicTransformerData\\MDOF\\knet-250\\1-250.\n"
     ]
    }
   ],
   "source": [
    "# \"\"\"\n",
    "# Author: Jason Jiang\n",
    "# Date: 2024.01.29\n",
    "\n",
    "# 用来批量进行 MDOF 计算、数据处理和数据保存。主要步骤如下:\n",
    "# 1. 生成所需要的 BlgAttributes.txt 文件并复制到每个文件夹的 inputs 里面;\n",
    "# 2. 清空每个文件夹内的 Results 文件夹(或者以某种形式存起来,怕数据处理的时候出什么岔子);\n",
    "# 3. 运行批量运行 exe 文件的脚本 `Run_MDOF_Exe.py` ,等待 14 个 MDOF 文件夹内的 exe 脚本运行完毕;\n",
    "# 4. 读取买个文件夹的 Results 数据,将顶层结构加速度响应以及损伤等级保存到一个 hdf5 文件中;\n",
    "# 5. 重复以上四个步骤,直到所需要的情况训练完成。\n",
    "\n",
    "# \"\"\"\n",
    "\n",
    "# from Update_BlgAttributes_txt import update_blgattributes, update_blgattributes_txt\n",
    "# from Delete_Results_Folder import delete_results_folder\n",
    "# from Run_MDOF_Exe import run_exes\n",
    "# from Save_2_hdf5 import save\n",
    "# from Kill_exe import kill_exe\n",
    "\n",
    "\n",
    "# # 一共有 30 种情况\n",
    "# for i in range(1, 2):\n",
    "\n",
    "#     print(\"killing exe files if existing...\")\n",
    "#     kill_exe()\n",
    "\n",
    "#     # 1. 生成 BlgAttributes.txt 文件,并复制到每个文件夹的 inputs 里面\n",
    "#     results = update_blgattributes(case_No=i)\n",
    "\n",
    "#     print(f\"Case {i}:\\n\"\n",
    "#         f\"Stories = {results['Stories']}\\n\"\n",
    "#         f\"height = {results['height']}\\n\"\n",
    "#         f\"IM = {results['IM']}\\n\"\n",
    "#         f\"Site_CD = {results['Site_CD']}\\n\")\n",
    "\n",
    "#     update_blgattributes_txt()\n",
    "#     print(\"Move blg.txt into each floder!\")\n",
    "\n",
    "#     # 2. 清空每个文件夹内的 Results 文件夹\n",
    "#     delete_results_folder()\n",
    "#     print(\"All Results folders have beed deleted.\")\n",
    "\n",
    "#     # 3. 运行批量运行 exe 文件的脚本 `Run_MDOF_Exe.py` ,等待 14 个 MDOF 文件夹内的 exe 脚本运行完毕\n",
    "#     print(\"running exe files\")\n",
    "#     run_exes()\n",
    "\n",
    "#     # 4. 保存数据到 hdf5 文件中\n",
    "#     file_name = \"Blg_F\" + results[\"Stories\"] + \\\n",
    "#                 \"_\" + results[\"height\"] + \\\n",
    "#                 \"m_IM\" + results[\"IM\"] + \\\n",
    "#                 \"_SCD\" + results[\"Site_CD\"] + \\\n",
    "#                 \".h5\"\n",
    "\n",
    "#     save(file_name=file_name)\n",
    "\n",
    "#     print(f\"Case {i} has been saved to {file_name}.\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import os\n",
    "# import re\n",
    "# import shutil\n",
    "\n",
    "# current_directory = os.getcwd()\n",
    "\n",
    "# # 定义你的.bat文件的原始路径\n",
    "# bat_file_path = os.path.join(current_directory, 'deleteResults.bat')\n",
    "\n",
    "# # 定义目标目录路径\n",
    "# target_directory_path = current_directory\n",
    "\n",
    "# # 正则表达式来匹配 number-number 格式的文件夹\n",
    "# folder_name_pattern = re.compile(r\"^\\d+-\\d+$\")\n",
    "\n",
    "# # 遍历目标目录中的所有项\n",
    "# for folder_name in os.listdir(target_directory_path):\n",
    "#     # 构建完整的文件夹路径\n",
    "#     folder_path = os.path.join(target_directory_path, folder_name)\n",
    "#     # 检查这是一个目录且符合我们的命名规则\n",
    "#     if os.path.isdir(folder_path) and folder_name_pattern.match(folder_name):\n",
    "#         # 构建目标.bat文件路径\n",
    "#         destination_bat_path = os.path.join(folder_path, os.path.basename(bat_file_path))\n",
    "#         # 复制.bat文件到目标文件夹\n",
    "#         shutil.copyfile(bat_file_path, destination_bat_path)\n",
    "#         print(f'复制到:{folder_path}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ml",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}