FrontISTR  5.2.0
Large-scale structural analysis program with finit element method
fstr_rmerge.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 
6 /*
7  * FSTR result 出力ファイルを1つのファイルに統合する。
8  * 計算に用いたコントロールファイル、メッシュデータが必要
9  */
10 
11 #include "fstr_rmerge_util.h"
12 
13 FILE* log_fp;
14 int nrank = 0;
15 int strid = 0;
16 int endid = -1;
17 int intid = 1;
18 
19 void error_stop(void) {
20  char* msg;
21  HECMW_get_error(&msg);
22  fputs(msg, stderr);
23  exit(-1);
24 }
25 
26 void help(void) {
27  printf(" HECMW Result File Merger\n");
28  printf("usage) rmerge [options] out_fileheader\n");
29  printf("[option]\n");
30  printf(" -h : help\n");
31  printf(" -o [type] : output file type (binary/text)\n");
32  printf(" -n [rank] : number of ranks (default:%d)\n", nrank);
33  printf(" -s [step] : start step number (default:%d)\n", strid);
34  printf(" -e [step] : end step number (default:%d)\n", endid);
35  printf(" -i [step] : interval step number (default:%d)\n", intid);
36 }
37 
38 void set_fname(int argc, char** argv, char* out_fheader, int* binary) {
39  int i;
40  char* fheader = NULL;
41 
42  *binary = 0;
43  for (i = 1; i < argc; i++) {
44  if (!strcmp(argv[i], "-h")) {
45  help();
46  exit(-1);
47  } else if (!strcmp(argv[i], "-o")) {
48  if (argc == i + 1) {
49  fprintf(stderr, "Error : paramter required after %s\n", argv[i]);
50  exit(-1);
51  }
52  i++;
53  if (!strcmp(argv[i], "binary")) {
54  *binary = 1;
55  } else if (!strcmp(argv[i], "text")) {
56  *binary = 0;
57  } else {
58  fprintf(stderr, "Error : text or binary is required after -o\n");
59  exit(-1);
60  }
61  } else if (strcmp(argv[i], "-n") == 0) {
62  if (argc == i + 1) {
63  fprintf(stderr, "Error : paramter required after %s\n", argv[i]);
64  exit(-1);
65  }
66  i++;
67  if (sscanf(argv[i], "%d", &nrank) != 1) {
68  fprintf(stderr,
69  "Error : parameter %s cannot be converted to number of ranks\n",
70  argv[i]);
71  exit(-1);
72  }
73  } else if (strcmp(argv[i], "-s") == 0) {
74  if (argc == i + 1) {
75  fprintf(stderr, "Error : paramter required after %s\n", argv[i]);
76  exit(-1);
77  }
78  i++;
79  if (sscanf(argv[i], "%d", &strid) != 1) {
80  fprintf(
81  stderr,
82  "Error : parameter %s cannot be converted to start step number\n",
83  argv[i]);
84  exit(-1);
85  }
86  } else if (strcmp(argv[i], "-e") == 0) {
87  if (argc == i + 1) {
88  fprintf(stderr, "Error : paramter required after %s\n", argv[i]);
89  exit(-1);
90  }
91  i++;
92  if (sscanf(argv[i], "%d", &endid) != 1) {
93  fprintf(stderr,
94  "Error : parameter %s cannot be converted to end step number\n",
95  argv[i]);
96  exit(-1);
97  }
98  } else if (strcmp(argv[i], "-i") == 0) {
99  if (argc == i + 1) {
100  fprintf(stderr, "Error : paramter required after %s\n", argv[i]);
101  exit(-1);
102  }
103  i++;
104  if (sscanf(argv[i], "%d", &intid) != 1) {
105  fprintf(stderr,
106  "Error : parameter %s cannot be converted to interval step "
107  "number\n",
108  argv[i]);
109  exit(-1);
110  }
111  } else {
112  fheader = argv[i];
113  }
114  }
115 
116  if (!fheader) {
117  help();
118  exit(-1);
119  } else {
120  strcpy(out_fheader, fheader);
121  }
122 }
123 
124 int main(int argc, char** argv) {
125  int area_n, step_n, binary, refine, fg_text;
126  int step, rcode;
127  char out_fheader[HECMW_HEADER_LEN + 1];
128  char out_fname[HECMW_FILENAME_LEN + 1];
129  struct hecmwST_local_mesh** mesh;
130  struct hecmwST_local_mesh* glmesh;
131  struct hecmwST_result_data* data;
132  fstr_res_info** res;
133  fstr_glt* glt;
134  char header[HECMW_HEADER_LEN + 1];
135  char comment[HECMW_MSG_LEN + 1];
136  char* fileheader;
137  char dirname[HECMW_HEADER_LEN + 1];
138  char buff[HECMW_HEADER_LEN + 1];
139  char *ptoken, *ntoken;
140 
141  log_fp = stderr;
142 
143  if (HECMW_init(&argc, &argv)) error_stop();
144 
145  set_fname(argc, argv, out_fheader, &binary);
146  fprintf(log_fp, "out file name header is %s\n", out_fheader);
147 
148  mesh = fstr_get_all_local_mesh("fstrMSH", &area_n, &refine);
149  if (!mesh) error_stop();
150 
151  fprintf(log_fp, "table creating .. \n");
152  glt = fstr_create_glt(mesh, area_n);
153  if (!glt) {
154  fprintf(stderr, "ERROR : Cannot create global_local table.\n");
155  fstr_free_mesh(mesh, area_n);
156  exit(-1);
157  }
158 
159  glmesh = fstr_create_glmesh(glt);
160  if (!glmesh) {
161  fprintf(stderr, "ERROR : Cannot create global table.\n");
162  fstr_free_mesh(mesh, area_n);
163  fstr_free_glt(glt);
164  exit(-1);
165  }
166 
167  fstr_free_mesh(mesh, area_n);
168 
169  step_n = fstr_get_step_n("fstrRES");
170 
171  for (step = strid; step <= step_n; step++) {
172  if ((step % intid) != 0 && step != step_n) continue;
173 
174  fprintf(log_fp, "step:%d .. reading .. ", step);
175  res = fstr_get_all_result("fstrRES", step, area_n, refine);
176  if (!res) {
177  fstr_free_result(res, area_n);
178  continue;
179  }
180  fprintf(log_fp, "end\n");
181 
182  fprintf(log_fp, "step:%d .. combining .. ", step);
183  data = fstr_all_result(glt, res, refine);
184  if (!data) {
185  fprintf(stderr, "ERROR : Cannot combine result structure.\n");
186  fstr_free_glt(glt);
187  fstr_free_glmesh(glmesh);
188  fstr_free_result(res, area_n);
189  exit(-1);
190  }
191  fprintf(log_fp, "end\n");
192 
193  if (nrank == 0) {
194  if ((fileheader = HECMW_ctrl_get_result_fileheader("fstrRES", step,
195  &fg_text)) == NULL)
196  return 0;
197  } else {
198  if ((fileheader = HECMW_ctrl_get_result_fileheader_sub(
199  "fstrRES", step, nrank, 0, &fg_text)) == NULL)
200  return 0;
201  }
202  strcpy(buff, fileheader);
203  strcpy(dirname, "");
204  ptoken = strtok(buff, "/");
205  ntoken = strtok(NULL, "/");
206  while (ntoken) {
207  strcat(dirname, ptoken);
208  strcat(dirname, "/");
209  ptoken = ntoken;
210  ntoken = strtok(NULL, "/");
211  }
212  sprintf(out_fname, "%s%s.%d", dirname, out_fheader, step);
213  fprintf(log_fp, "output to %s .. ", out_fname);
214  HECMW_result_get_header(header);
215  HECMW_result_get_comment(comment);
216  HECMW_result_init(glmesh, step, header, comment);
217  if (binary) {
218  rcode = HECMW_result_write_bin_ST_by_fname(out_fname, data, glt->node_n,
219  glt->elem_n, header, comment);
220  } else {
221  rcode = HECMW_result_write_txt_ST_by_fname(out_fname, data, glt->node_n,
222  glt->elem_n, header, comment);
223  }
224  if (rcode) {
225  fprintf(stderr, "ERROR : Cannot open/write file %s\n", out_fname);
226  fstr_free_glt(glt);
227  fstr_free_glmesh(glmesh);
228  fstr_free_result(res, area_n);
230  exit(-1);
231  }
232  fprintf(log_fp, "end\n");
233 
234  fstr_free_result(res, area_n);
236  }
237 
238  fstr_free_glt(glt);
239  fstr_free_glmesh(glmesh);
240 
241  HECMW_finalize();
242 
243  exit(0);
244 }
void help(void)
Definition: fstr_rmerge.c:26
int main(int argc, char **argv)
Definition: fstr_rmerge.c:124
int endid
Definition: fstr_rmerge.c:16
int intid
Definition: fstr_rmerge.c:17
void set_fname(int argc, char **argv, char *out_fheader, int *binary)
Definition: fstr_rmerge.c:38
FILE * log_fp
並列計算された結果を読込み処理するためのユーティリティ
Definition: fstr_rmerge.c:13
int nrank
Definition: fstr_rmerge.c:14
int strid
Definition: fstr_rmerge.c:15
void error_stop(void)
Definition: fstr_rmerge.c:19
struct hecmwST_local_mesh * fstr_create_glmesh(fstr_glt *glt)
単一領域メッシュの作成
struct hecmwST_local_mesh ** fstr_get_all_local_mesh(char *name_ID, int *area_number, int *refine)
全分散メッシュの読込み
int fstr_get_step_n(char *name_ID)
ステップ数を調べる(ファイルの存在を調べる)
void fstr_free_glmesh(struct hecmwST_local_mesh *mesh)
単一領域メッシュの削除
fstr_glt * fstr_create_glt(struct hecmwST_local_mesh **mesh, int area_n)
テーブル fstr_glt の作成
void fstr_free_glt(fstr_glt *glt)
fstr_glt の削除
struct hecmwST_result_data * fstr_all_result(fstr_glt *glt, fstr_res_info **res, int refine)
ステップの全領域データの結合
void fstr_free_result(fstr_res_info **res, int area_n)
fstr_res_info の削除
fstr_res_info ** fstr_get_all_result(char *name_ID, int step, int area_n, int refine)
ステップの全領域データの読み込み
void fstr_free_mesh(struct hecmwST_local_mesh **mesh, int area_n)
メッシュの削除
#define HECMW_FILENAME_LEN
Definition: hecmw_config.h:72
#define HECMW_MSG_LEN
Definition: hecmw_config.h:74
#define HECMW_HEADER_LEN
Definition: hecmw_config.h:68
char * HECMW_ctrl_get_result_fileheader_sub(char *name_ID, int istep, int n_rank, int i_rank, int *fg_text)
char * HECMW_ctrl_get_result_fileheader(char *name_ID, int istep, int *fg_text)
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
int HECMW_get_error(char **errmsg)
Definition: hecmw_error.c:49
int HECMW_finalize(void)
Definition: hecmw_finalize.c:9
int HECMW_init(int *argc, char ***argv)
Definition: hecmw_init.c:24
#define NULL
int HECMW_result_init(struct hecmwST_local_mesh *hecMESH, int i_step, char *header, char *comment)
Definition: hecmw_result.c:60
void HECMW_result_free(struct hecmwST_result_data *result)
Definition: hecmw_result.c:25
char * HECMW_result_get_comment(char *buff)
Definition: hecmw_result.c:212
char * HECMW_result_get_header(char *buff)
Definition: hecmw_result.c:207
int HECMW_result_write_bin_ST_by_fname(char *filename, struct hecmwST_result_data *result, int n_node, int n_elem, char *header, char *comment)
int HECMW_result_write_txt_ST_by_fname(char *filename, struct hecmwST_result_data *result, int n_node, int n_elem, char *header, char *comment)
CNFData data
グローバル・ローカル対応表
分散で計算された結果を読込み処理するためのユーティリティ