FrontISTR 5.2.0
Large-scale structural analysis program with finit element method
Loading...
Searching...
No Matches
neu2fstr.cpp
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#include <iostream>
7#include <stdio.h>
8#include <string.h>
9#include <time.h>
10
11#include "CConvMessage.h"
12#include "CNFData.h"
13#include "CFSTRData.h"
14#include "conv_neu2hec.h"
17#include "conv_neu2fstr_heat.h"
18
19#define VER "1.004"
20#define AUTHOR "The University of Tokyo, RSS21 Project"
21
22static int solution = sol_static;
23static bool fg_hecmw_ctrl = false;
24static bool fg_res_name = false;
25static bool fg_vis_name = false;
26static char date_time[256];
27static char neu_name[256];
28static char mesh_name[256];
29static char ctrl_name[256];
30static char hecmw_ctrl_name[256] = "hecmw_ctrl.dat";
31static char res_name[256]; // default: mesh_name + ".res"
32static char vis_name[256]; // default: mesh_name + ".vis"
33static bool fg_direct = false;
34
35static CNFData nfdata;
36static CFSTRData fstrdata;
37
38using namespace std;
39
40static void remove_cr(char *s) {
41 int n = strlen(s);
42
43 if (n == 0) return;
44
45 n--;
46
47 if (s[n] == '\r' || s[n] == '\n') s[n] = 0;
48}
49
50//-----------------------------------------------------------------------------
51
52void title() {
53 printf("NEU to FrontSTR Data Converter, Ver. %s \n", VER);
54 printf("Copyright (C) 2006 %s, All right reserved.\n", AUTHOR);
55}
56
57//-----------------------------------------------------------------------------
58
59void help() {
60 printf(
61 "[usage]\n"
62 " neu2fstr ([options]) [sSeEhH] [neu] [mesh] [ctrl]\n"
63 " [options]\n"
64 " -h : show help (this message)\n"
65 " -c : create HEC-MW control file (hecmw_ctrl.dat)\n"
66 " -r [name] : write result file name in hecmw_ctrl.dat "
67 "(default:[mesh].res)\n"
68 " -v [name] : write visual file name in hecmw_ctrl.dat "
69 "(default:[mesh].vis)\n"
70 " -d : set direct solver in FrontSTR control file\n"
71 " [sSeEhH] : command character s,S,e,E,h or H (specify only one "
72 "character)\n"
73 " s,S : generate for static analysis\n"
74 " e,E : generate for eigen analysis\n"
75 " CAUTION) Edit !EIGEN section in generated [ctrl]\n"
76 " h,H : generate for heat transfer analysis\n"
77 " [neu] : neutral file name\n"
78 " [mesh] : mesh file name\n"
79 " [ctrl] : FrontSTR control file name\n");
80 fflush(stdout);
81}
82
83//-----------------------------------------------------------------------------
84
85bool set_params(int argc, char **argv) {
86 int count = 0;
87#define CMP(x) (strcmp(argv[i], (x)) == 0)
88
89 for (int i = 1; i < argc; i++) {
90 if (CMP("-h")) {
91 return false;
92
93 } else if (CMP("-c")) {
94 fg_hecmw_ctrl = true;
95
96 } else if (CMP("-d")) {
97 fg_direct = true;
98
99 } else if (CMP("-v")) {
100 fg_vis_name = true;
101 i++;
102
103 if (i >= argc) {
104 fprintf(stderr, "##Error: Visual output file name is required\n");
105 return false;
106 }
107
108 strcpy(vis_name, argv[i]);
109
110 } else if (CMP("-r")) {
111 fg_res_name = true;
112 i++;
113
114 if (i >= argc) {
115 fprintf(stderr, "##Error: Result file name is required\n");
116 return false;
117 }
118
119 strcpy(res_name, argv[i]);
120
121 } else {
122 switch (count) {
123 case 0:
124 if (CMP("s") || CMP("S")) {
125 solution = sol_static;
126
127 } else if (CMP("e") || CMP("E")) {
128 solution = sol_eigen;
129
130 } else if (CMP("h") || CMP("H")) {
131 solution = sol_heat;
132
133 } else {
134 fprintf(stderr, "##Error: No such solution type %s\n", argv[i]);
135 return false;
136 }
137
138 case 1:
139 strcpy(neu_name, argv[i]);
140 break;
141
142 case 2:
143 strcpy(mesh_name, argv[i]);
144 break;
145
146 case 3:
147 strcpy(ctrl_name, argv[i]);
148 break;
149
150 default:
151 fprintf(stderr, "##Error: Too many arguments\n");
152 return false;
153 }
154
155 count++;
156 }
157 }
158
159#undef CMP
160
161 switch (count) {
162 case 0:
163 fprintf(stderr,
164 "##Error: one character, neu, mesh and ctrl file must be "
165 "specified\n");
166 return false;
167
168 case 1:
169 fprintf(stderr, "##Error: neu, mesh and ctrl file must be specified\n");
170 return false;
171
172 case 2:
173 fprintf(stderr, "##Error: mesh and ctrl file must be specified\n");
174 return false;
175
176 case 3:
177 fprintf(stderr, "##Error: ctrl file must be specified\n");
178 return false;
179 }
180
181 if (!fg_res_name) {
182 strcpy(res_name, mesh_name);
183 strcat(res_name, ".res");
184 }
185
186 if (!fg_vis_name) {
187 strcpy(vis_name, mesh_name);
188 strcat(vis_name, ".vis");
189 }
190
191 return true;
192}
193
194//-----------------------------------------------------------------------------
195
196void create_comment(char *s, bool fg_mesh) {
197 char ss[256];
198 s[0] = 0;
199 strcat(s, "###########################################################\n");
200
201 if (fg_mesh) {
202 sprintf(ss, " HEC-MW Mesh File Generated by neu2fstr ver.%s\n", VER);
203
204 } else {
205 sprintf(ss, " FrontSTR Control File Generated by neu2fstr ver.%s\n", VER);
206 }
207
208 strcat(s, ss);
209 sprintf(ss, " Date&Time: %s\n", date_time);
210 strcat(s, ss);
211 sprintf(ss, " Original : %s\n", neu_name);
212 strcat(s, ss);
213
214 if (fg_mesh) {
215 sprintf(ss, " Control : %s\n", ctrl_name);
216
217 } else {
218 sprintf(ss, " Mesh : %s\n", mesh_name);
219 }
220
221 strcat(s, ss);
222 strcat(s, "###########################################################\n");
223}
224
225//-----------------------------------------------------------------------------
226
228 FILE *fp = fopen(hecmw_ctrl_name, "w");
229
230 if (!fp) {
231 fprintf(stderr, "##Error: Cannot create hecmw_ctrl.dat file\n");
232 return false;
233 }
234
235 fprintf(fp, "###########################################################\n");
236 fprintf(fp, "# HEC-MW Control File Generated by neu2fstr ver.%s\n", VER);
237 fprintf(fp, "# Date&Time: %s\n", date_time);
238 fprintf(fp, "# Original : %s\n", neu_name);
239 fprintf(fp, "###########################################################\n");
240 fprintf(fp, "!MESH, NAME=fstrMSH,TYPE=HECMW-ENTIRE\n");
241 fprintf(fp, " %s\n", mesh_name);
242 fprintf(fp, "!CONTROL,NAME=fstrCNT\n");
243 fprintf(fp, " %s\n", ctrl_name);
244 fprintf(fp, "!RESULT,NAME=fstrRES,IO=OUT\n");
245 fprintf(fp, " %s\n", res_name);
246 fprintf(fp, "!RESULT,NAME=vis_out,IO=OUT\n");
247 fprintf(fp, " %s\n", vis_name);
248 fclose(fp);
249 return true;
250}
251
252//-----------------------------------------------------------------------------
253
254void set_solution(CFSTRData &fstrdata, int solution) {
256
257 switch (solution) {
258 case sol_static:
260 break;
261
262 case sol_eigen:
264 break;
265
266 case sol_heat:
268 break;
269
270 default:
271 assert(0);
272 }
273
274 fstrdata.DB.push_back(sol);
275}
276
277//-----------------------------------------------------------------------------
278
279void set_solver(CFSTRData &fstrdata, bool fg_direct = false) {
280 CFSTRDB_Solver *solver = new CFSTRDB_Solver();
281
282 if (fg_direct) {
283 strcpy(solver->method, "DIRECT");
284
285 } else {
286 strcpy(solver->method, "CG");
287 }
288
289 fstrdata.DB.push_back(solver);
290}
291
292//-----------------------------------------------------------------------------
293// main
294//-----------------------------------------------------------------------------
295
296int main(int argc, char **argv) {
297 time_t t;
298 time(&t);
299 strcpy(date_time, ctime(&t));
300 remove_cr(date_time);
301 title();
302
303 if (!set_params(argc, argv)) {
304 fflush(stderr);
305 help();
306 return -1;
307 }
308
309 cout << "loading neu file ... " << endl;
310
311 try {
312 nfdata.Load(neu_name);
313
314 } catch (CNFError e) {
315 fprintf(stderr, "NEU loading error : %s\n", e.Msg());
316 return -1;
317 }
318
319 try {
320 cout << "converting to HEC-MW mesh ... " << endl;
321 conv_neu2hec(nfdata, fstrdata, solution);
322 cout << "converting to FrontSTR control data " << endl;
323 conv_neu2fstr_static(nfdata, fstrdata);
324 conv_neu2fstr_dynamic(nfdata, fstrdata);
325 conv_neu2fstr_heat(nfdata, fstrdata);
326 set_solution(fstrdata, solution);
327 set_solver(fstrdata, fg_direct);
328
329 } catch (CConvMessage &e) {
330 fprintf(stderr, "Converting error : %s\n", e.Msg());
331 return -1;
332 }
333
334 char comment[256];
335 cout << "saving HEC-MW mesh file..." << endl;
336 create_comment(comment, true);
337
338 if (!fstrdata.SaveMesh(mesh_name, comment)) {
339 fprintf(stderr, "Cannot save mesh data\n");
340 return -1;
341 }
342
343 cout << "saving FrontSTR control file..." << endl;
344 create_comment(comment, false);
345
346 if (!fstrdata.SaveCtrl(ctrl_name, comment)) {
347 fprintf(stderr, "Cannot save control data\n");
348 return -1;
349 }
350
351 if (fg_hecmw_ctrl) {
352 cout << "creating hecmw_ctrl.dat file..." << endl;
353
354 if (!create_hecmw_ctrl()) return -1;
355 }
356
357 cout << "neu2fstr completed." << endl;
358 return 0;
359}
char method[30]
Definition: CFSTRDB.h:84
virtual bool SaveCtrl(const char *file_name, const char *comment="")
Definition: CFSTRData.cpp:44
virtual bool SaveMesh(const char *file_name, const char *comment="")
Definition: CFSTRData.cpp:21
std::vector< CHECDataBlock * > DB
Definition: CHECData.h:30
virtual void Load(const char *fname)
Definition: CNFData.cpp:66
virtual const char * Msg()
Definition: CNFMessage.cpp:21
bool conv_neu2fstr_dynamic(CNFData &neu, CHECData &hec)
void conv_neu2fstr_heat(CNFData &neu, CHECData &hec)
void conv_neu2fstr_static(CNFData &neu, CHECData &hec)
void conv_neu2hec(CNFData &neu, CHECData &hec, int sol)
@ sol_eigen
Definition: conv_neu2hec.h:18
@ sol_heat
Definition: conv_neu2hec.h:18
@ sol_static
Definition: conv_neu2hec.h:18
void title()
Definition: neu2fstr.cpp:52
#define AUTHOR
Definition: neu2fstr.cpp:20
bool set_params(int argc, char **argv)
Definition: neu2fstr.cpp:85
void help()
Definition: neu2fstr.cpp:59
#define VER
Definition: neu2fstr.cpp:19
#define CMP(x)
void set_solver(CFSTRData &fstrdata, bool fg_direct=false)
Definition: neu2fstr.cpp:279
bool create_hecmw_ctrl()
Definition: neu2fstr.cpp:227
void create_comment(char *s, bool fg_mesh)
Definition: neu2fstr.cpp:196
void set_solution(CFSTRData &fstrdata, int solution)
Definition: neu2fstr.cpp:254
int main()
Definition: varray_test.c:10