1 /*****************************************************************************
2 * Copyright (c) 2019 FrontISTR Commons
3 * This software is released under the MIT License, see LICENSE.txt
4 *****************************************************************************/
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <errno.h>
9 #include "hecmw_util.h"
10 #include "hecmw_heclex.h"
11 #include "hecmw_io_hec.h"
12 #include "hecmw_io_mesh.h"
13 #include "hecmw_io_struct.h"
14 #include "hecmw_struct.h"
15 #include "hecmw_config.h"
16 #include "hecmw_system.h"
17 #include "hecmw_dist.h"
18 #include "hecmw_dist_print.h"
19 #include "hecmw_dist_free.h"
20 #include "hecmw_common.h"
21 #include "hecmw_reorder.h"
22 #include "hecmw_map_int.h"
23 #include "hecmw_set_int.h"
24 #include "hecmw_hash.h"
25
26 #define HECMW_FLAG_VERSION 5
27
28 static int global_node_ID_max = -1;
29 static int global_elem_ID_max = -1;
30
31 /* temporaly data structures */
32 static struct hecmw_io_header *_head;
33 static struct hecmw_io_initial *_init;
34 static struct hecmw_io_amplitude *_amp;
35 static struct hecmw_map_int *_node;
36 static struct hecmw_map_int *_elem;
37 static struct hecmw_io_egrp *_egrp;
38 static struct hecmw_io_ngrp *_ngrp;
39 static struct hecmw_io_sgrp *_sgrp;
40 static struct hecmw_io_mpc *_mpc;
41 static struct hecmw_io_material *_mat;
42 static struct hecmw_io_section *_sect;
43 static struct hecmw_system_param *_system;
44 static struct hecmw_io_zero *_zero;
45 static struct hecmw_io_contact *_contact;
46
47 static char grid_filename[HECMW_FILENAME_LEN + 1] = "Unknown";
48
49 /*----------------------------------------------------------------------------*/
50
do_logging(int loglv,int msgno,const char * fmt,va_list ap)51 static void do_logging(int loglv, int msgno, const char *fmt, va_list ap) {
52 if (loglv == HECMW_LOG_ERROR) {
53 HECMW_set_verror(msgno, fmt, ap);
54 } else {
55 HECMW_print_vmsg(loglv, msgno, fmt, ap);
56 }
57 }
58
set_err(int msgno,const char * fmt,...)59 static void set_err(int msgno, const char *fmt, ...) {
60 va_list ap;
61
62 va_start(ap, fmt);
63 do_logging(HECMW_LOG_ERROR, msgno, fmt, ap);
64 va_end(ap);
65 }
66
set_warn(int msgno,const char * fmt,...)67 static void set_warn(int msgno, const char *fmt, ...) {
68 va_list ap;
69
70 va_start(ap, fmt);
71 do_logging(HECMW_LOG_WARN, msgno, fmt, ap);
72 va_end(ap);
73 }
74
75 /*----------------------------------------------------------------------------*/
76
get_gid2lid_node(int gid)77 static int get_gid2lid_node(int gid) {
78 size_t clocal;
79 int ret;
80 HECMW_assert(_node);
81 ret = HECMW_map_int_key2local(_node, gid, &clocal);
82 HECMW_assert(ret == HECMW_SUCCESS);
83 return clocal + 1;
84 }
85
get_gid2lid_elem(int gid)86 static int get_gid2lid_elem(int gid) {
87 size_t clocal;
88 int ret;
89 HECMW_assert(_elem);
90 ret = HECMW_map_int_key2local(_elem, gid, &clocal);
91 HECMW_assert(ret == HECMW_SUCCESS);
92 return clocal + 1;
93 }
94
95 /*----------------------------------------------------------------------------*/
96
make_surf_key(int elem_id,int surf_id)97 static int make_surf_key(int elem_id, int surf_id) {
98 /* return elem_id*10 + surf_id - 1; */
99 if (surf_id < 4) {
100 return elem_id * 3 + surf_id - 1;
101 } else {
102 return -(elem_id * 3 + surf_id - 4);
103 }
104 }
105
decode_surf_key(int key,int * elem_id,int * surf_id)106 static void decode_surf_key(int key, int *elem_id, int *surf_id) {
107 /* *elem_id = key/10; */
108 /* *surf_id = key%10 + 1; */
109 if (key > 0) {
110 *elem_id = key / 3;
111 *surf_id = key % 3 + 1;
112 } else {
113 *elem_id = (-key) / 3;
114 *surf_id = (-key) % 3 + 4;
115 }
116 }
117
clear(void)118 static int clear(void) {
119 if (HECMW_io_free_all()) return -1;
120
121 strcpy(grid_filename, "Unkown");
122
123 _head = NULL;
124 _init = NULL;
125 _amp = NULL;
126 _node = NULL;
127 _elem = NULL;
128 _egrp = NULL;
129 _ngrp = NULL;
130 _sgrp = NULL;
131 _mpc = NULL;
132 _mat = NULL;
133 _sect = NULL;
134 _system = NULL;
135 _zero = NULL;
136 _contact = NULL;
137
138 return 0;
139 }
140
141 /*------------------------------------------------------------------------------
142 print functions
143 */
144
print_header(FILE * fp)145 static void print_header(FILE *fp) {
146 HECMW_assert(fp);
147
148 fprintf(fp, "HEADER:\n");
149 fprintf(fp, "%s\n", _head ? _head->header : "none");
150 fprintf(fp, "END of HEADER\n");
151 }
152
print_amp(FILE * fp)153 static void print_amp(FILE *fp) {
154 struct hecmw_io_amplitude *p;
155
156 HECMW_assert(fp);
157
158 fprintf(fp, "AMPLITUDE:\n");
159 for (p = _amp; p; p = p->next) {
160 struct hecmw_io_amplitude_item *item;
161 fprintf(fp, "NAME: %s, DEFINITION: %d, TIME: %d, VALUE: %d\n", p->name,
162 p->type_def, p->type_time, p->type_val);
163 for (item = p->item; item; item = item->next) {
164 fprintf(fp, "VAL: %E, T: %E\n", item->val, item->table);
165 }
166 }
167 fprintf(fp, "END of AMPLITUDE\n");
168 }
169
print_init(FILE * fp)170 static void print_init(FILE *fp) {
171 struct hecmw_io_initial *p;
172
173 HECMW_assert(fp);
174
175 fprintf(fp, "INITIAL CONDITION:\n");
176 for (p = _init; p; p = p->next) {
177 fprintf(fp, "TYPE: %d, NODE: %d, NGRP: %s, VAL: %E\n", p->type, p->node,
178 (*p->ngrp != '\0') ? p->ngrp : "none", p->val);
179 }
180 fprintf(fp, "END of INITIAL CONDITION\n");
181 }
182
print_node(FILE * fp)183 static void print_node(FILE *fp) {
184 int seq, id;
185 struct hecmw_io_node *p;
186
187 HECMW_assert(fp);
188 HECMW_assert(_node);
189
190 fprintf(fp, "NODE:\n");
191
192 seq = 1;
193 HECMW_map_int_iter_init(_node);
194 while (HECMW_map_int_iter_next(_node, &id, (void **)&p))
195 fprintf(fp, "Node %d: ID=%d: %E %E %E\n", seq++, id, p->x, p->y, p->z);
196
197 fprintf(fp, "END of NODE\n");
198 }
199
print_elem(FILE * fp)200 static void print_elem(FILE *fp) {
201 int seq, n, id, j;
202 struct hecmw_io_element *p;
203
204 HECMW_assert(fp);
205 HECMW_assert(_elem);
206
207 fprintf(fp, "ELEMENT:\n");
208
209 seq = 1;
210 HECMW_map_int_iter_init(_elem);
211 while (HECMW_map_int_iter_next(_elem, &id, (void **)&p)) {
212 fprintf(fp, "Element %d: ID=%d: TYPE=%d: ", seq++, id, p->type);
213 n = HECMW_get_max_node(p->type);
214 for (j = 0; j < n; j++) {
215 fprintf(fp, "%d ", p->node[j]);
216 }
217 fprintf(fp, ": MATITEM: ");
218 if (p->nmatitem == 0) {
219 fprintf(fp, "none");
220 } else {
221 for (j = 0; j < p->nmatitem; j++) {
222 fprintf(fp, "%E ", p->matitem[j]);
223 }
224 }
225 fprintf(fp, "\n");
226 }
227
228 fprintf(fp, "END of ELEMENT\n");
229 }
230
print_ngrp(FILE * fp)231 static void print_ngrp(FILE *fp) {
232 int i;
233 const int NITEM = 10;
234 struct hecmw_io_ngrp *p;
235
236 HECMW_assert(fp);
237
238 fprintf(fp, "NGROUP:\n");
239 for (p = _ngrp; p; p = p->next) {
240 int id;
241 fprintf(fp, "NAME=%s:\n", p->name);
242 HECMW_set_int_iter_init(p->node);
243 for (i = 0; HECMW_set_int_iter_next(p->node, &id); i++) {
244 fprintf(fp, "%d %c", id, (i + 1) % NITEM ? ' ' : '\n');
245 }
246 if (i % NITEM) {
247 fprintf(fp, "\n");
248 }
249 }
250 fprintf(fp, "END of NGROUP\n");
251 }
252
print_egrp(FILE * fp)253 static void print_egrp(FILE *fp) {
254 int i;
255 const int NITEM = 10;
256 struct hecmw_io_egrp *p;
257
258 HECMW_assert(fp);
259
260 fprintf(fp, "EGROUP:\n");
261 for (p = _egrp; p; p = p->next) {
262 int id;
263 fprintf(fp, "NAME=%s:\n", p->name);
264 HECMW_set_int_iter_init(p->elem);
265 for (i = 0; HECMW_set_int_iter_next(p->elem, &id); i++) {
266 fprintf(fp, "%d %c", id, (i + 1) % NITEM ? ' ' : '\n');
267 }
268 if (i % NITEM) {
269 fprintf(fp, "\n");
270 }
271 }
272 fprintf(fp, "END of EGROUP\n");
273 }
274
print_sgrp(FILE * fp)275 static void print_sgrp(FILE *fp) {
276 int i;
277 const int NITEM = 10;
278 struct hecmw_io_sgrp *p;
279
280 HECMW_assert(fp);
281
282 fprintf(fp, "SGROUP:\n");
283 for (p = _sgrp; p; p = p->next) {
284 int id, eid, sid;
285 fprintf(fp, "NAME=%s:\n", p->name);
286 HECMW_set_int_iter_init(p->item);
287 for (i = 0; HECMW_set_int_iter_next(p->item, &id); i++) {
288 decode_surf_key(id, &eid, &sid);
289 fprintf(fp, "%d %d %c", eid, sid, (i + 1) % NITEM ? ' ' : '\n');
290 }
291 if (i % NITEM) {
292 fprintf(fp, "\n");
293 }
294 }
295 fprintf(fp, "END of SGROUP\n");
296 }
297
print_sect(FILE * fp)298 static void print_sect(FILE *fp) {
299 struct hecmw_io_section *p;
300
301 HECMW_assert(fp);
302
303 fprintf(fp, "SECTION:\n");
304 for (p = _sect; p; p = p->next) {
305 fprintf(fp, "EGRP: %s, MATERIAL: %s, COMPOSITE: %d, SECOPT: %d\n", p->egrp,
306 p->material, p->composite, p->secopt);
307 if (p->type == HECMW_SECT_TYPE_SOLID) {
308 fprintf(fp, "TYPE: SOLID, THICKNESS: %E\n", p->sect.solid.thickness);
309 } else if (p->type == HECMW_SECT_TYPE_SHELL) {
310 fprintf(fp, "TYPE: SHELL, THICKNESS: %E, INTEGPOINTS: %d\n",
311 p->sect.shell.thickness, p->sect.shell.integpoints);
312 } else if (p->type == HECMW_SECT_TYPE_BEAM) {
313 fprintf(fp, "TYPE: BEAM, Reference vector: %E %E %E, Iyy: %E\n",
314 p->sect.beam.vxyz[0], p->sect.beam.vxyz[1], p->sect.beam.vxyz[2],
315 p->sect.beam.Iyy);
316 } else if (p->type == HECMW_SECT_TYPE_INTERFACE) {
317 fprintf(fp,
318 "TYPE: INTERFACE, THICKNESS: %E, "
319 "GAPCON: %E, GAPRAD1: %E, GAPRAD2: %E\n",
320 p->sect.interface.thickness, p->sect.interface.gapcon,
321 p->sect.interface.gaprad1, p->sect.interface.gaprad2);
322 }
323 }
324 fprintf(fp, "END of SECTION\n");
325 }
326
print_mat(FILE * fp)327 static void print_mat(FILE *fp) {
328 int i, j;
329 struct hecmw_io_material *p;
330
331 HECMW_assert(fp);
332
333 fprintf(fp, "MATERIAL:\n");
334 for (p = _mat; p; p = p->next) {
335 fprintf(fp, "NAME: %s\n", p->name);
336 for (i = 0; i < p->nitem; i++) {
337 struct hecmw_io_matitem *item = &p->item[i];
338 struct hecmw_io_matsubitem *p;
339 fprintf(fp, "ITEM=%d, SUBITEM=%d:\n", item->item, item->nval);
340 for (p = item->subitem; p; p = p->next) {
341 fprintf(fp, "VAL: ");
342 for (j = 0; j < item->nval; j++) {
343 fprintf(fp, "%E ", p->val[j]);
344 }
345 fprintf(fp, "TEMP: %E\n", p->temp);
346 }
347 }
348 }
349 fprintf(fp, "END of MATERIAL\n");
350 }
351
print_mpc(FILE * fp)352 static void print_mpc(FILE *fp) {
353 int i;
354 struct hecmw_io_mpc *p;
355
356 HECMW_assert(fp);
357
358 fprintf(fp, "EQUATION:\n");
359 for (p = _mpc; p; p = p->next) {
360 fprintf(fp, "NEQ: %d\n", p->neq);
361 for (i = 0; i < p->neq; i++) {
362 struct hecmw_io_mpcitem *item = &p->item[i];
363 fprintf(fp, "ngrp: %s, nod: %d, DOF: %d, A: %E\n",
364 (item->node == -1) ? item->ngrp : "(none)", item->node, item->dof,
365 item->a);
366 }
367 }
368 fprintf(fp, "END of EQUATION\n");
369 }
370
print_system(FILE * fp)371 static void print_system(FILE *fp) {
372 struct hecmw_system_param param;
373
374 HECMW_assert(fp);
375
376 if (_system) {
377 param = *_system;
378 } else {
379 memset(¶m, 0, sizeof(param));
380 }
381
382 fprintf(fp, "SYSTEM:\n");
383 fprintf(fp, "%E %E %E\n", param.xa, param.ya, param.za);
384 fprintf(fp, "%E %E %E\n", param.xb, param.yb, param.zb);
385 fprintf(fp, "%E %E %E\n", param.xc, param.yc, param.zc);
386 fprintf(fp, "END of SYSTEM\n");
387 }
388
print_zero(FILE * fp)389 static void print_zero(FILE *fp) {
390 HECMW_assert(fp);
391
392 fprintf(fp, "ZERO:\n");
393 fprintf(fp, "%E\n", _zero ? _zero->zero : 0.0);
394 fprintf(fp, "END of ZERO\n");
395 }
396
print_contact(FILE * fp)397 static void print_contact(FILE *fp) {
398 int i;
399 struct hecmw_io_contact *p;
400
401 HECMW_assert(fp);
402
403 fprintf(fp, "CONTACT PAIR:\n");
404 for (p = _contact; p; p = p->next) {
405 fprintf(fp, "NAME=%s, ", p->name);
406 if (p->type == HECMW_CONTACT_TYPE_NODE_SURF) {
407 fprintf(fp, "TYPE=NODE-SURF, ");
408 } else if (p->type == HECMW_CONTACT_TYPE_SURF_SURF) {
409 fprintf(fp, "TYPE=SURF-SURF, ");
410 }
411 fprintf(fp, "SLAVE_GRP=%s, MASTER_GRP=%s\n", p->slave_grp, p->master_grp);
412 }
413 fprintf(fp, "END of CONTACT PAIR\n");
414 }
415
HECMW_io_print_all(FILE * fp)416 void HECMW_io_print_all(FILE *fp) {
417 HECMW_assert(fp);
418
419 print_header(fp);
420 fprintf(fp, "\n");
421 print_zero(fp);
422 fprintf(fp, "\n");
423 print_init(fp);
424 fprintf(fp, "\n");
425 print_amp(fp);
426 fprintf(fp, "\n");
427 print_system(fp);
428 fprintf(fp, "\n");
429 print_node(fp);
430 fprintf(fp, "\n");
431 print_elem(fp);
432 fprintf(fp, "\n");
433 print_ngrp(fp);
434 fprintf(fp, "\n");
435 print_egrp(fp);
436 fprintf(fp, "\n");
437 print_sgrp(fp);
438 fprintf(fp, "\n");
439 print_sect(fp);
440 fprintf(fp, "\n");
441 print_mat(fp);
442 fprintf(fp, "\n");
443 print_mpc(fp);
444 fprintf(fp, "\n");
445 print_contact(fp);
446 fprintf(fp, "\n");
447 }
448
449 /*------------------------------------------------------------------------------
450 free
451 */
452
free_header(struct hecmw_io_header * header)453 static int free_header(struct hecmw_io_header *header) {
454 if (header == NULL) return 0;
455
456 HECMW_free(header);
457 return 0;
458 }
459
free_zero(struct hecmw_io_zero * zero)460 static int free_zero(struct hecmw_io_zero *zero) {
461 if (zero == NULL) return 0;
462
463 HECMW_free(zero);
464 return 0;
465 }
466
free_node(struct hecmw_map_int * node)467 static int free_node(struct hecmw_map_int *node) {
468 if (node == NULL) return 0;
469
470 HECMW_map_int_finalize(node);
471 HECMW_free(node);
472 return 0;
473 }
474
free_elem(struct hecmw_map_int * elem)475 static int free_elem(struct hecmw_map_int *elem) {
476 if (elem == NULL) return 0;
477
478 HECMW_map_int_finalize(elem);
479 HECMW_free(elem);
480 return 0;
481 }
482
free_ngrp(struct hecmw_io_ngrp * ngrp)483 static int free_ngrp(struct hecmw_io_ngrp *ngrp) {
484 struct hecmw_io_ngrp *p, *q;
485
486 for (p = ngrp; p; p = q) {
487 q = p->next;
488 HECMW_set_int_finalize(p->node);
489 HECMW_free(p->node);
490 HECMW_free(p);
491 }
492 return 0;
493 }
494
free_egrp(struct hecmw_io_egrp * egrp)495 static int free_egrp(struct hecmw_io_egrp *egrp) {
496 struct hecmw_io_egrp *p, *q;
497
498 for (p = egrp; p; p = q) {
499 q = p->next;
500 HECMW_set_int_finalize(p->elem);
501 HECMW_free(p->elem);
502 HECMW_free(p);
503 }
504 return 0;
505 }
506
free_sgrp(struct hecmw_io_sgrp * sgrp)507 static int free_sgrp(struct hecmw_io_sgrp *sgrp) {
508 struct hecmw_io_sgrp *p, *q;
509
510 for (p = sgrp; p; p = q) {
511 q = p->next;
512 HECMW_set_int_finalize(p->item);
513 HECMW_free(p->item);
514 HECMW_free(p);
515 }
516 return 0;
517 }
518
free_mpc(struct hecmw_io_mpc * mpc)519 static int free_mpc(struct hecmw_io_mpc *mpc) {
520 struct hecmw_io_mpc *p, *q;
521
522 for (p = mpc; p; p = q) {
523 q = p->next;
524 HECMW_free(p->item);
525 HECMW_free(p);
526 }
527 return 0;
528 }
529
free_amp(struct hecmw_io_amplitude * amp)530 static int free_amp(struct hecmw_io_amplitude *amp) {
531 struct hecmw_io_amplitude *p, *q;
532 struct hecmw_io_amplitude_item *pp, *qq;
533
534 for (p = amp; p; p = q) {
535 q = p->next;
536 for (pp = p->item; pp; pp = qq) {
537 qq = pp->next;
538 HECMW_free(pp);
539 }
540 HECMW_free(p);
541 }
542 return 0;
543 }
544
free_init(struct hecmw_io_initial * init)545 static int free_init(struct hecmw_io_initial *init) {
546 struct hecmw_io_initial *p, *q;
547
548 for (p = init; p; p = q) {
549 q = p->next;
550 HECMW_free(p);
551 }
552 return 0;
553 }
554
free_material(struct hecmw_io_material * mat)555 static int free_material(struct hecmw_io_material *mat) {
556 int i;
557 struct hecmw_io_material *p, *q;
558 struct hecmw_io_matsubitem *pp, *qq;
559
560 for (p = mat; p; p = q) {
561 q = p->next;
562 for (i = 0; i < p->nitem; i++) {
563 for (pp = p->item[i].subitem; pp; pp = qq) {
564 qq = pp->next;
565 HECMW_free(pp->val);
566 HECMW_free(pp);
567 }
568 }
569 HECMW_free(p->item);
570 HECMW_free(p);
571 }
572 return 0;
573 }
574
free_sect(struct hecmw_io_section * sect)575 static int free_sect(struct hecmw_io_section *sect) {
576 struct hecmw_io_section *p, *q;
577
578 for (p = sect; p; p = q) {
579 q = p->next;
580 HECMW_free(p);
581 }
582 return 0;
583 }
584
free_system(struct hecmw_system_param * system)585 static int free_system(struct hecmw_system_param *system) {
586 if (system == NULL) return 0;
587
588 HECMW_free(system);
589 return 0;
590 }
591
free_contact(struct hecmw_io_contact * contact)592 static int free_contact(struct hecmw_io_contact *contact) {
593 struct hecmw_io_contact *p, *q;
594
595 for (p = contact; p; p = q) {
596 q = p->next;
597 HECMW_free(p);
598 }
599 return 0;
600 }
601
HECMW_io_free_all(void)602 int HECMW_io_free_all(void) {
603 if (free_header(_head)) return -1;
604 if (free_zero(_zero)) return -1;
605 if (free_node(_node)) return -1;
606 if (free_elem(_elem)) return -1;
607 if (free_ngrp(_ngrp)) return -1;
608 if (free_egrp(_egrp)) return -1;
609 if (free_sgrp(_sgrp)) return -1;
610 if (free_mpc(_mpc)) return -1;
611 if (free_amp(_amp)) return -1;
612 if (free_init(_init)) return -1;
613 if (free_material(_mat)) return -1;
614 if (free_sect(_sect)) return -1;
615 if (free_system(_system)) return -1;
616 if (free_contact(_contact)) return -1;
617 return 0;
618 }
619
620 /*----------------------------------------------------------------------------*/
621
HECMW_io_set_gridfile(char * gridfile)622 int HECMW_io_set_gridfile(char *gridfile) {
623 if (gridfile == NULL) gridfile = "";
624
625 strcpy(grid_filename, gridfile);
626 return 0;
627 }
628
HECMW_io_add_amp(const char * name,int definition,int time,int value,double val,double t)629 struct hecmw_io_amplitude *HECMW_io_add_amp(const char *name, int definition,
630 int time, int value, double val,
631 double t) {
632 static struct hecmw_io_amplitude *prev_amp = NULL;
633 struct hecmw_io_amplitude *p;
634 struct hecmw_io_amplitude_item *item;
635
636 if (name == NULL) {
637 set_err(HECMW_ALL_E0101, "HECMW_io_add_amp(): name");
638 return NULL;
639 }
640 if (strlen(name) > HECMW_NAME_LEN) {
641 set_err(HECMW_ALL_E0101, "HECMW_io_add_amp(): name too long");
642 return NULL;
643 }
644
645 if (prev_amp != NULL && strcmp(prev_amp->name, name) == 0) {
646 p = prev_amp;
647 } else {
648 p = HECMW_malloc(sizeof(*p));
649 if (p == NULL) {
650 set_err(errno, "");
651 return NULL;
652 }
653 strcpy(p->name, name);
654 p->next = NULL;
655 p->item = NULL;
656 p->last = NULL;
657
658 if (prev_amp == NULL) {
659 _amp = p;
660 } else {
661 prev_amp->next = p;
662 }
663 prev_amp = p;
664 }
665 p->type_def = definition;
666 p->type_time = time;
667 p->type_val = value;
668
669 item = HECMW_malloc(sizeof(*item));
670 if (item == NULL) {
671 set_err(errno, "");
672 return NULL;
673 }
674 item->next = NULL;
675 item->val = val;
676 item->table = t;
677
678 if (p->last == NULL) {
679 p->item = item;
680 p->last = item;
681 } else {
682 p->last->next = item;
683 p->last = item;
684 }
685
686 return p;
687 }
688
HECMW_io_get_initial(int node)689 struct hecmw_io_initial *HECMW_io_get_initial(int node) {
690 struct hecmw_io_initial *p;
691
692 for (p = _init; p; p = p->next) {
693 if (p->node == node) return p;
694 }
695 return NULL;
696 }
697
HECMW_io_add_initial(int type,int node,const char * ngrp,double val)698 struct hecmw_io_initial *HECMW_io_add_initial(int type, int node,
699 const char *ngrp, double val) {
700 static struct hecmw_io_initial *prev_init = NULL;
701 struct hecmw_io_initial *p;
702
703 if (ngrp == NULL && node <= 0) {
704 set_err(HECMW_ALL_E0101, "HECMW_io_add_initial(): ngrp,node");
705 return NULL;
706 }
707
708 p = HECMW_malloc(sizeof(*p));
709 if (p == NULL) {
710 set_err(errno, "");
711 return NULL;
712 }
713
714 if (ngrp) {
715 strcpy(p->ngrp, ngrp);
716 }
717 p->type = type;
718 p->node = ngrp ? -1 : node;
719 p->val = val;
720 p->next = NULL;
721
722 if (prev_init == NULL) {
723 _init = p;
724 } else {
725 prev_init->next = p;
726 }
727 prev_init = p;
728
729 return p;
730 }
731
HECMW_io_get_elem(int id)732 struct hecmw_io_element *HECMW_io_get_elem(int id) {
733 HECMW_assert(_elem);
734
735 return (struct hecmw_io_element *)HECMW_map_int_get(_elem, id);
736 }
737
HECMW_io_get_n_elem(void)738 int HECMW_io_get_n_elem(void) {
739 HECMW_assert(_elem);
740
741 return HECMW_map_int_nval(_elem);
742 }
743
HECMW_io_get_elem_max_id(void)744 int HECMW_io_get_elem_max_id(void) {
745 int id, max = 0;
746 struct hecmw_io_element *val;
747
748 HECMW_assert(_elem);
749
750 HECMW_map_int_iter_init(_elem);
751 while (HECMW_map_int_iter_next(_elem, &id, (void **)&val)) {
752 if (id > max) {
753 max = id;
754 }
755 }
756 return max;
757 }
758
free_io_elem(void * io_elem)759 static void free_io_elem(void *io_elem) {
760 struct hecmw_io_element *p;
761 p = (struct hecmw_io_element *)io_elem;
762 HECMW_free(p->node);
763 HECMW_free(p->matitem);
764 HECMW_free(p);
765 }
766
HECMW_io_add_elem(int id,int type,int * node,int nmatitem,double * matitem)767 struct hecmw_io_element *HECMW_io_add_elem(int id, int type, int *node,
768 int nmatitem, double *matitem) {
769 int nnode;
770 int *new_node;
771 double *new_matitem;
772 struct hecmw_io_element *new_elem;
773
774 if (node == NULL) {
775 set_err(HECMW_ALL_E0101, "HECMW_io_add_elem(): node");
776 return NULL;
777 }
778 if (nmatitem < 0) {
779 set_err(HECMW_ALL_E0101, "HECMW_io_add_elem(): nmatitem");
780 return NULL;
781 }
782
783 /* get # of connectivity */
784 nnode = HECMW_get_max_node(type);
785 HECMW_assert(nnode > 0);
786 HECMW_assert(nnode <= HECMW_MAX_NODE_MAX);
787
788 new_node = HECMW_malloc(sizeof(*new_node) * nnode);
789 if (new_node == NULL) {
790 set_err(errno, "");
791 return NULL;
792 }
793 memcpy(new_node, node, sizeof(*new_node) * nnode);
794
795 /* material */
796 new_matitem = NULL;
797 if (nmatitem > 0) {
798 new_matitem = HECMW_malloc(sizeof(*new_matitem) * nmatitem);
799 if (new_matitem == NULL) {
800 set_err(errno, "");
801 return NULL;
802 }
803 memcpy(new_matitem, matitem, sizeof(*new_matitem) * nmatitem);
804 }
805
806 new_elem = HECMW_malloc(sizeof(*new_elem));
807 if (new_elem == NULL) {
808 set_err(errno, "");
809 return NULL;
810 }
811 new_elem->type = type;
812 new_elem->node = new_node;
813 new_elem->nmatitem = nmatitem;
814 new_elem->matitem = new_matitem;
815 new_elem->mpc_matid = -1;
816 new_elem->mpc_sectid = -1;
817
818 if (_elem == NULL) {
819 _elem = (struct hecmw_map_int *)HECMW_malloc(sizeof(struct hecmw_map_int));
820 if (_elem == NULL) {
821 set_err(errno, "");
822 return NULL;
823 }
824 if (HECMW_map_int_init(_elem, free_io_elem)) {
825 set_err(errno, "");
826 return NULL;
827 }
828 }
829
830 if (HECMW_map_int_add(_elem, id, new_elem)) {
831 set_err(errno, "");
832 return NULL;
833 }
834
835 if (id > global_elem_ID_max) {
836 global_elem_ID_max = id;
837 }
838
839 return new_elem;
840 }
841
HECMW_io_get_egrp(const char * name)842 struct hecmw_io_egrp *HECMW_io_get_egrp(const char *name) {
843 extern hecmw_hash_p *hash_eg;
844
845 return (struct hecmw_io_egrp *)hecmw_hash_p_get(hash_eg, name);
846 }
847
HECMW_io_get_elem_in_egrp(const char * name)848 struct hecmw_io_id_array *HECMW_io_get_elem_in_egrp(const char *name) {
849 int nval, i, eid;
850 struct hecmw_io_egrp *egrp;
851 struct hecmw_io_id_array *id = NULL;
852
853 egrp = HECMW_io_get_egrp(name);
854 if (egrp == NULL) goto error;
855
856 nval = HECMW_set_int_nval(_egrp->elem);
857 HECMW_assert(nval > 0);
858
859 id = HECMW_malloc(sizeof(*id));
860 if (id == NULL) {
861 set_err(errno, "");
862 goto error;
863 }
864
865 id->id = HECMW_malloc(sizeof(*id->id) * nval);
866 if (id->id == NULL) {
867 set_err(errno, "");
868 goto error;
869 }
870
871 id->n = nval;
872
873 HECMW_set_int_iter_init(_egrp->elem);
874 for (i = 0; HECMW_set_int_iter_next(_egrp->elem, &eid); i++) {
875 id->id[i] = eid;
876 }
877
878 HECMW_assert(i == nval);
879
880 return id;
881
882 error:
883 if (id) {
884 if (id->id) HECMW_free(id->id);
885 HECMW_free(id);
886 }
887 return NULL;
888 }
889
HECMW_io_add_egrp(const char * name,int nelem,int * elem)890 int HECMW_io_add_egrp(const char *name, int nelem, int *elem) {
891 int i;
892 static struct hecmw_io_egrp *cp = NULL;
893 struct hecmw_io_egrp *p;
894 extern hecmw_hash_p *hash_eg;
895
896 if (name == NULL) {
897 set_err(HECMW_ALL_E0101, "HECMW_io_add_egrp(): name");
898 return -1;
899 }
900 if (elem == NULL) {
901 set_err(HECMW_ALL_E0101, "HECMW_io_add_egrp(): elem");
902 return -1;
903 }
904 if (nelem <= 0) {
905 set_err(HECMW_ALL_E0101, "HECMW_io_add_egrp(): nelem");
906 return -1;
907 }
908
909 /** for(p=_egrp; p; p=p->next) {
910 if(strcmp(p->name, name) == 0) break;
911 q = p;
912 }**/
913
914 p = (struct hecmw_io_egrp *)hecmw_hash_p_get(hash_eg, name);
915 if (p == NULL) {
916 p = HECMW_malloc(sizeof(struct hecmw_io_egrp));
917 if (p == NULL) {
918 set_err(errno, "");
919 return -1;
920 }
921 strcpy(p->name, name);
922 p->elem =
923 (struct hecmw_set_int *)HECMW_malloc(sizeof(struct hecmw_set_int));
924 if (p->elem == NULL) {
925 set_err(errno, "");
926 return -1;
927 }
928 if (HECMW_set_int_init(p->elem)) {
929 set_err(errno, "");
930 return -1;
931 }
932 p->next = NULL;
933
934 if (cp != NULL) {
935 cp->next = p;
936 } else {
937 _egrp = p;
938 }
939 cp = p;
940 }
941
942 for (i = 0; i < nelem; i++) {
943 if (HECMW_set_int_add(p->elem, elem[i])) {
944 set_err(errno, "");
945 return -1;
946 }
947 }
948
949 if (HECMW_set_int_is_empty(p->elem)) {
950 /* new group && ignored all */
951 HECMW_assert(nelem == 0);
952 HECMW_set_int_finalize(p->elem);
953 HECMW_free(p->elem);
954 HECMW_free(p);
955 return 0;
956 }
957
958 if (hecmw_hash_p_put(hash_eg, name, (void *)p) == 0) {
959 printf("HECMW HASH TABEL PUT ERROR\n");
960 return -1;
961 }
962
963 /* if(cp != NULL) { */
964 /* cp->next = p; */
965 /* } else if (strcmp(cp->name, name) != 0) { */
966 /* _egrp = p; */
967 /* } */
968 /* cp = p; */
969
970 return nelem;
971 }
972
HECMW_io_get_node(int id)973 struct hecmw_io_node *HECMW_io_get_node(int id) {
974 HECMW_assert(_node);
975
976 return (struct hecmw_io_node *)HECMW_map_int_get(_node, id);
977 }
978
HECMW_io_get_n_node(void)979 int HECMW_io_get_n_node(void) {
980 HECMW_assert(_node);
981
982 return HECMW_map_int_nval(_node);
983 }
984
free_io_node(void * io_node)985 static void free_io_node(void *io_node) {
986 struct hecmw_io_node *p;
987 p = (struct hecmw_io_node *)io_node;
988 /* nothing to do on members */
989 HECMW_free(p);
990 }
991
HECMW_io_add_node(int id,double x,double y,double z)992 struct hecmw_io_node *HECMW_io_add_node(int id, double x, double y, double z) {
993 struct hecmw_io_node *new_node;
994
995 new_node = HECMW_malloc(sizeof(*new_node));
996 if (new_node == NULL) {
997 set_err(errno, "");
998 return NULL;
999 }
1000 new_node->x = x;
1001 new_node->y = y;
1002 new_node->z = z;
1003
1004 if (_node == NULL) {
1005 _node = (struct hecmw_map_int *)HECMW_malloc(sizeof(struct hecmw_map_int));
1006 if (_node == NULL) {
1007 set_err(errno, "");
1008 return NULL;
1009 }
1010 if (HECMW_map_int_init(_node, free_io_node)) {
1011 set_err(errno, "");
1012 return NULL;
1013 }
1014 }
1015
1016 if (HECMW_map_int_add(_node, id, new_node)) {
1017 set_err(errno, "");
1018 return NULL;
1019 }
1020
1021 if (id > global_node_ID_max) {
1022 global_node_ID_max = id;
1023 }
1024
1025 return new_node;
1026 }
1027
HECMW_io_get_nnode_in_ngrp(const char * name)1028 int HECMW_io_get_nnode_in_ngrp(const char *name) {
1029 struct hecmw_io_ngrp *p;
1030
1031 if (name == NULL) {
1032 set_err(HECMW_ALL_E0101, "HECMW_io_get_nnode_in_ngrp(): name");
1033 return -1;
1034 }
1035
1036 for (p = _ngrp; p; p = p->next) {
1037 if (strcmp(p->name, name) == 0) break;
1038 }
1039 if (p == NULL) return 0;
1040
1041 return HECMW_set_int_nval(p->node);
1042 }
1043
1044 /*
1045 int
1046 HECMW_io_remove_node(int id)
1047 {
1048 return HECMW_map_int_del(_node, id);
1049 }
1050 */
1051
HECMW_io_get_ngrp(const char * name)1052 struct hecmw_io_ngrp *HECMW_io_get_ngrp(const char *name) {
1053 /* struct hecmw_io_ngrp *p; */
1054 extern hecmw_hash_p *hash_ng;
1055
1056 if (name == NULL) {
1057 set_err(HECMW_ALL_E0101, "HECMW_io_get_ngrp(): name");
1058 return NULL;
1059 }
1060
1061 /* for(p=_ngrp; p; p=p->next) { */
1062 /* if(strcmp(p->name, name) == 0) break; */
1063 /* } */
1064 /* return p; */
1065
1066 return (struct hecmw_io_ngrp *)hecmw_hash_p_get(hash_ng, name);
1067 }
1068
HECMW_io_get_node_in_ngrp(const char * name)1069 struct hecmw_io_id_array *HECMW_io_get_node_in_ngrp(const char *name) {
1070 int n, i, nid;
1071 struct hecmw_io_ngrp *ngrp;
1072 struct hecmw_io_id_array *id;
1073
1074 if (name == NULL) {
1075 set_err(HECMW_ALL_E0101, "HECMW_io_get_node_in_ngrp(): name");
1076 return NULL;
1077 }
1078
1079 ngrp = HECMW_io_get_ngrp(name);
1080 if (ngrp == NULL) return NULL;
1081
1082 id = HECMW_malloc(sizeof(*id));
1083 if (id == NULL) {
1084 set_err(errno, "");
1085 return NULL;
1086 }
1087
1088 n = HECMW_set_int_nval(ngrp->node);
1089 HECMW_assert(n > 0);
1090
1091 id->id = HECMW_malloc(sizeof(*id->id) * n);
1092 if (id->id == NULL) {
1093 set_err(errno, "");
1094 return NULL;
1095 }
1096
1097 id->n = n;
1098 HECMW_set_int_iter_init(ngrp->node);
1099 for (i = 0; HECMW_set_int_iter_next(ngrp->node, &nid); i++) {
1100 id->id[i] = nid;
1101 }
1102
1103 HECMW_assert(i == n);
1104
1105 return id;
1106 }
1107
HECMW_io_add_ngrp(const char * name,int nnode,int * node)1108 int HECMW_io_add_ngrp(const char *name, int nnode, int *node) {
1109 int i;
1110 static struct hecmw_io_ngrp *prev_ngrp = NULL;
1111 struct hecmw_io_ngrp *p;
1112 extern hecmw_hash_p *hash_ng;
1113
1114 if (name == NULL) {
1115 set_err(HECMW_ALL_E0101, "HECMW_io_add_ngrp(): name");
1116 return -1;
1117 }
1118 if (node == NULL) {
1119 set_err(HECMW_ALL_E0101, "HECMW_io_add_ngrp(): node");
1120 return -1;
1121 }
1122 if (nnode <= 0) {
1123 set_err(HECMW_ALL_E0101, "HECMW_io_add_ngrp(): nnode");
1124 return -1;
1125 }
1126
1127 p = (struct hecmw_io_ngrp *)hecmw_hash_p_get(hash_ng, name);
1128
1129 /* if(prev_ngrp != NULL && strcmp(prev_ngrp->name, name) == 0) { */
1130 /* p = prev_ngrp; */
1131 /* } else { */
1132 if (p == NULL) {
1133 p = HECMW_malloc(sizeof(*p));
1134 if (p == NULL) {
1135 set_err(errno, "");
1136 return -1;
1137 }
1138 strcpy(p->name, name);
1139 p->node =
1140 (struct hecmw_set_int *)HECMW_malloc(sizeof(struct hecmw_set_int));
1141 if (p->node == NULL) {
1142 set_err(errno, "");
1143 return -1;
1144 }
1145 if (HECMW_set_int_init(p->node)) {
1146 set_err(errno, "");
1147 return -1;
1148 }
1149 p->next = NULL;
1150
1151 if (prev_ngrp == NULL) {
1152 _ngrp = p;
1153 } else {
1154 prev_ngrp->next = p;
1155 }
1156 prev_ngrp = p;
1157 }
1158
1159 for (i = 0; i < nnode; i++) {
1160 if (HECMW_set_int_add(p->node, node[i])) {
1161 set_err(errno, "");
1162 return -1;
1163 }
1164 }
1165
1166 if (HECMW_set_int_is_empty(p->node)) {
1167 /* new group && ignored all */
1168 HECMW_set_int_finalize(p->node);
1169 HECMW_free(p->node);
1170 HECMW_free(p);
1171 return 0;
1172 }
1173
1174 if (hecmw_hash_p_put(hash_ng, name, (void *)p) == 0) {
1175 printf("HECMW HASH TABEL PUT ERROR\n");
1176 return -1;
1177 }
1178
1179 /* if(prev_ngrp == NULL) { */
1180 /* _ngrp = p; */
1181 /* } else if(strcmp(prev_ngrp->name, name) != 0) { */
1182 /* prev_ngrp->next = p; */
1183 /* } */
1184 /* prev_ngrp = p; */
1185
1186 return nnode;
1187 }
1188
HECMW_io_remove_node_in_ngrp(int node)1189 static int HECMW_io_remove_node_in_ngrp(int node) {
1190 struct hecmw_io_ngrp *p, *q, *next;
1191
1192 q = NULL;
1193 for (p = _ngrp; p; p = next) {
1194 HECMW_set_int_del(p->node, node);
1195 if (HECMW_set_int_is_empty(p->node)) {
1196 /* no node in this group */
1197 if (q == NULL) {
1198 _ngrp = p->next;
1199 } else {
1200 q->next = p->next;
1201 }
1202 next = p->next;
1203 HECMW_set_int_finalize(p->node);
1204 HECMW_free(p->node);
1205 HECMW_free(p);
1206 } else {
1207 q = p;
1208 next = p->next;
1209 }
1210 }
1211 return 0;
1212 }
1213
HECMW_io_get_sgrp(const char * name)1214 static struct hecmw_io_sgrp *HECMW_io_get_sgrp(const char *name) {
1215 /* struct hecmw_io_sgrp *p; */
1216 extern hecmw_hash_p *hash_sg;
1217
1218 if (name == NULL) {
1219 set_err(HECMW_ALL_E0101, "HECMW_io_get_sgrp(): name");
1220 return NULL;
1221 }
1222
1223 /* for(p=_sgrp; p; p=p->next) { */
1224 /* if(strcmp(p->name, name) == 0) break; */
1225 /* } */
1226 /* return p; */
1227
1228 return (struct hecmw_io_sgrp *)hecmw_hash_p_get(hash_sg, name);
1229 }
1230
HECMW_io_add_sgrp(const char * name,int n_item,int * elem,int * surf)1231 int HECMW_io_add_sgrp(const char *name, int n_item, int *elem, int *surf) {
1232 int i;
1233 static struct hecmw_io_sgrp *prev_sgrp = NULL;
1234 struct hecmw_io_sgrp *p;
1235 extern hecmw_hash_p *hash_sg;
1236
1237 if (name == NULL) {
1238 set_err(HECMW_ALL_E0101, "HECMW_add_sgrp(): name");
1239 return -1;
1240 }
1241 if (elem == NULL) {
1242 set_err(HECMW_ALL_E0101, "HECMW_add_sgrp(): elem");
1243 return -1;
1244 }
1245 if (surf == NULL) {
1246 set_err(HECMW_ALL_E0101, "HECMW_add_sgrp(): surf");
1247 return -1;
1248 }
1249 if (n_item <= 0) {
1250 set_err(HECMW_ALL_E0101, "HECMW_add_sgrp(): n_item");
1251 return -1;
1252 }
1253
1254 p = (struct hecmw_io_sgrp *)hecmw_hash_p_get(hash_sg, name);
1255 if (p == NULL) {
1256 /* if(prev_sgrp != NULL && strcmp(prev_sgrp->name, name) == 0) { */
1257 /* p = prev_sgrp; */
1258 /* } else { */
1259 p = HECMW_malloc(sizeof(*p));
1260 if (p == NULL) {
1261 set_err(errno, "");
1262 return -1;
1263 }
1264 strcpy(p->name, name);
1265 p->item =
1266 (struct hecmw_set_int *)HECMW_malloc(sizeof(struct hecmw_set_int));
1267 if (p->item == NULL) {
1268 set_err(errno, "");
1269 return -1;
1270 }
1271 if (HECMW_set_int_init(p->item)) {
1272 set_err(errno, "");
1273 return -1;
1274 }
1275 p->next = NULL;
1276
1277 if (prev_sgrp == NULL) {
1278 _sgrp = p;
1279 } else {
1280 prev_sgrp->next = p;
1281 }
1282 prev_sgrp = p;
1283 }
1284
1285 for (i = 0; i < n_item; i++) {
1286 if (HECMW_set_int_add(p->item, make_surf_key(elem[i], surf[i]))) {
1287 set_err(errno, "");
1288 return -1;
1289 }
1290 }
1291
1292 if (HECMW_set_int_is_empty(p->item)) {
1293 /* new group && ignored all */
1294 HECMW_set_int_finalize(p->item);
1295 HECMW_free(p->item);
1296 HECMW_free(p);
1297 return 0;
1298 }
1299
1300 if (hecmw_hash_p_put(hash_sg, name, (void *)p) == 0) {
1301 printf("HECMW HASH TABEL PUT ERROR\n");
1302 return -1;
1303 }
1304
1305 /* if(prev_sgrp == NULL) { */
1306 /* _sgrp = p; */
1307 /* } else if(strcmp(prev_sgrp->name, name) != 0) { */
1308 /* prev_sgrp->next = p; */
1309 /* } */
1310 /* prev_sgrp = p; */
1311
1312 return n_item;
1313 }
1314
HECMW_io_add_mpc(int neq,const struct hecmw_io_mpcitem * mpcitem,double cnst)1315 struct hecmw_io_mpc *HECMW_io_add_mpc(int neq,
1316 const struct hecmw_io_mpcitem *mpcitem,
1317 double cnst) {
1318 int i;
1319 static struct hecmw_io_mpc *prev_mpc = NULL;
1320 struct hecmw_io_mpc *p;
1321 struct hecmw_io_mpcitem *item;
1322
1323 if (neq <= 0) {
1324 set_err(HECMW_ALL_E0101, "HECMW_add_mpc(): neq");
1325 return NULL;
1326 }
1327 if (mpcitem == NULL) {
1328 set_err(HECMW_ALL_E0101, "HECMW_add_mpc(): mpcitem");
1329 return NULL;
1330 }
1331
1332 p = HECMW_malloc(sizeof(*p));
1333 if (p == NULL) {
1334 set_err(errno, "");
1335 return NULL;
1336 }
1337
1338 item = HECMW_malloc(sizeof(*item) * neq);
1339 if (item == NULL) {
1340 set_err(errno, "");
1341 return NULL;
1342 }
1343
1344 for (i = 0; i < neq; i++) {
1345 const struct hecmw_io_mpcitem *src = &mpcitem[i];
1346 struct hecmw_io_mpcitem *dst = &item[i];
1347 HECMW_assert((src->node == -1) ? (strlen(src->ngrp) > 0) : 1);
1348 HECMW_assert((src->node != -1) ? (src->node > 0) : 1);
1349 HECMW_assert(!HECMW_io_check_mpc_dof(src->dof));
1350 strcpy(dst->ngrp, src->ngrp);
1351 dst->node = src->node;
1352 dst->dof = src->dof;
1353 dst->a = src->a;
1354 }
1355
1356 p->neq = neq;
1357 p->cnst = cnst;
1358 p->item = item;
1359 p->next = NULL;
1360
1361 if (prev_mpc == NULL) {
1362 _mpc = p;
1363 } else {
1364 prev_mpc->next = p;
1365 }
1366 prev_mpc = p;
1367
1368 return p;
1369 }
1370
HECMW_io_add_sect(struct hecmw_io_section * sect)1371 struct hecmw_io_section *HECMW_io_add_sect(struct hecmw_io_section *sect) {
1372 static struct hecmw_io_section *prev_sect = NULL;
1373 struct hecmw_io_section *p;
1374
1375 if (sect == NULL) {
1376 set_err(HECMW_ALL_E0101, "HECMW_io_add_sect(): sect");
1377 return NULL;
1378 }
1379
1380 p = HECMW_malloc(sizeof(*p));
1381 if (p == NULL) {
1382 set_err(errno, "");
1383 return NULL;
1384 }
1385
1386 *p = *sect;
1387 p->next = NULL;
1388
1389 if (prev_sect == NULL) {
1390 _sect = p;
1391 } else {
1392 prev_sect->next = p;
1393 }
1394 prev_sect = p;
1395
1396 return p;
1397 }
1398
HECMW_io_get_mat(const char * name)1399 struct hecmw_io_material *HECMW_io_get_mat(const char *name) {
1400 struct hecmw_io_material *p;
1401 extern hecmw_hash_p *hash_mat;
1402
1403 if (name == NULL) {
1404 set_err(HECMW_ALL_E0101, "HECMW_io_get_mat(): name");
1405 return NULL;
1406 }
1407
1408 p = (struct hecmw_io_material *)hecmw_hash_p_get(hash_mat, name);
1409
1410 /* for(p=_mat; p; p=p->next) {
1411 if(strcmp(p->name, name) == 0) break;
1412 }*/
1413
1414 return p;
1415 }
1416
HECMW_io_add_mat(const char * name,struct hecmw_io_material * mat)1417 struct hecmw_io_material *HECMW_io_add_mat(const char *name,
1418 struct hecmw_io_material *mat) {
1419 static struct hecmw_io_material *prev_mat = NULL;
1420 struct hecmw_io_material *p;
1421 extern hecmw_hash_p *hash_mat;
1422
1423 if (mat == NULL) {
1424 set_err(HECMW_ALL_E0101, "HECMW_io_add_mat(): mat");
1425 return NULL;
1426 }
1427
1428 p = (struct hecmw_io_material *)hecmw_hash_p_get(hash_mat, name);
1429 if (p == NULL) {
1430 if (hecmw_hash_p_put(hash_mat, name, (void *)mat) == 0) {
1431 printf("HECMW HASH TABEL PUT ERROR\n");
1432 return NULL;
1433 } else {
1434 if (prev_mat == NULL) {
1435 _mat = mat;
1436 } else {
1437 prev_mat->next = mat;
1438 }
1439 prev_mat = mat;
1440 }
1441 }
1442
1443 return mat;
1444 }
1445
HECMW_io_set_header(struct hecmw_io_header * header)1446 void HECMW_io_set_header(struct hecmw_io_header *header) {
1447 if (header == NULL) {
1448 set_err(HECMW_ALL_E0101, "HECMW_io_set_header(): header");
1449 return;
1450 }
1451
1452 if (_head) {
1453 HECMW_free(_head);
1454 set_warn(HECMW_IO_W1010, "");
1455 }
1456 _head = header;
1457 }
1458
HECMW_io_get_system(void)1459 struct hecmw_system_param *HECMW_io_get_system(void) {
1460 return _system;
1461 }
1462
HECMW_io_set_system(struct hecmw_system_param * system)1463 void HECMW_io_set_system(struct hecmw_system_param *system) {
1464 HECMW_free(_system);
1465 _system = system; /* allow NULL */
1466 }
1467
HECMW_io_set_zero(struct hecmw_io_zero * zero)1468 void HECMW_io_set_zero(struct hecmw_io_zero *zero) {
1469 if (_zero) {
1470 HECMW_free(_zero);
1471 set_warn(HECMW_IO_W1011, "");
1472 }
1473 _zero = zero;
1474 }
1475
HECMW_io_add_contact(const char * name,int type,const char * slave_grp,const char * master_grp)1476 struct hecmw_io_contact *HECMW_io_add_contact(const char *name, int type,
1477 const char *slave_grp,
1478 const char *master_grp) {
1479 static struct hecmw_io_contact *prev_contact = NULL;
1480 struct hecmw_io_contact *p;
1481
1482 if (slave_grp == NULL) {
1483 set_err(HECMW_ALL_E0101, "HECMW_io_add_contact(): slave_grp");
1484 return NULL;
1485 }
1486 if (master_grp == NULL) {
1487 set_err(HECMW_ALL_E0101, "HECMW_io_add_contact(): master_grp");
1488 return NULL;
1489 }
1490
1491 p = (struct hecmw_io_contact *)HECMW_malloc(sizeof(*p));
1492 if (p == NULL) {
1493 set_err(HECMW_ALL_E0101, "HECMW_io_add_contact(): contact");
1494 return NULL;
1495 }
1496
1497 strcpy(p->name, name);
1498 p->type = type;
1499 strcpy(p->slave_grp, slave_grp);
1500 strcpy(p->slave_orisgrp, slave_grp);
1501 strcpy(p->master_grp, master_grp);
1502 p->next = NULL;
1503
1504 if (prev_contact == NULL) {
1505 _contact = p;
1506 } else {
1507 prev_contact->next = p;
1508 }
1509 prev_contact = p;
1510
1511 return p;
1512 }
1513
1514 /*------------------------------------------------------------------------------
1515 convert to hecmwST_local_mesh
1516 */
1517
setup_flags(struct hecmwST_local_mesh * mesh)1518 static int setup_flags(struct hecmwST_local_mesh *mesh) {
1519 HECMW_assert(mesh);
1520
1521 mesh->hecmw_flag_adapt = 0;
1522 mesh->hecmw_flag_initcon = 0;
1523 mesh->hecmw_flag_parttype = HECMW_FLAG_PARTTYPE_UNKNOWN;
1524 mesh->hecmw_flag_partdepth = 1;
1525 mesh->hecmw_flag_version = HECMW_FLAG_VERSION;
1526 mesh->hecmw_flag_partcontact = HECMW_FLAG_PARTCONTACT_UNKNOWN;
1527
1528 return 0;
1529 }
1530
setup_gridfile(struct hecmwST_local_mesh * mesh)1531 static int setup_gridfile(struct hecmwST_local_mesh *mesh) {
1532 HECMW_assert(mesh);
1533
1534 strcpy(mesh->gridfile, grid_filename);
1535
1536 return 0;
1537 }
1538
setup_files(struct hecmwST_local_mesh * mesh)1539 static int setup_files(struct hecmwST_local_mesh *mesh) {
1540 HECMW_assert(mesh);
1541
1542 mesh->hecmw_n_file = 0;
1543 mesh->files = NULL;
1544
1545 return 0;
1546 }
1547
setup_header(struct hecmwST_local_mesh * mesh)1548 static int setup_header(struct hecmwST_local_mesh *mesh) {
1549 char *p;
1550
1551 HECMW_assert(mesh);
1552
1553 p = _head ? _head->header : "";
1554 strcpy(mesh->header, p);
1555
1556 return 0;
1557 }
1558
setup_zero(struct hecmwST_local_mesh * mesh)1559 static int setup_zero(struct hecmwST_local_mesh *mesh) {
1560 HECMW_assert(mesh);
1561
1562 mesh->zero_temp = 0.0; /* default value */
1563 if (_zero) {
1564 mesh->zero_temp = _zero->zero;
1565 }
1566
1567 return 0;
1568 }
1569
setup_init(struct hecmwST_local_mesh * mesh)1570 static int setup_init(struct hecmwST_local_mesh *mesh) {
1571 int i, n;
1572 size_t size;
1573 struct hecmw_io_initial *p;
1574
1575 HECMW_assert(mesh);
1576 HECMW_assert(mesh->n_node > 0);
1577
1578 /* initialize */
1579 mesh->node_init_val_index = NULL;
1580 mesh->node_init_val_item = NULL;
1581
1582 n = 0;
1583 for (p = _init; p; p = p->next) {
1584 n++;
1585 }
1586 HECMW_log(HECMW_LOG_DEBUG, "setup_init: n = %d", n);
1587
1588 if (n == 0) {
1589 mesh->hecmw_flag_initcon = 0;
1590 return 0;
1591 }
1592 mesh->hecmw_flag_initcon = 1;
1593
1594 /* allocate index initialized with 0 */
1595 mesh->node_init_val_index =
1596 HECMW_calloc(mesh->n_node + 1, sizeof(*mesh->node_init_val_index));
1597 if (mesh->node_init_val_index == NULL) {
1598 set_err(errno, "");
1599 return -1;
1600 }
1601
1602 /* set index to 1 where initial condition is specified */
1603 for (p = _init; p; p = p->next) {
1604 int lid = get_gid2lid_node(p->node);
1605 mesh->node_init_val_index[lid] = 1;
1606 }
1607
1608 /* integrate index */
1609 for (i = 0; i < mesh->n_node; i++) {
1610 mesh->node_init_val_index[i + 1] += mesh->node_init_val_index[i];
1611 }
1612
1613 /* allocate item */
1614 size = sizeof(*mesh->node_init_val_item) * n;
1615 mesh->node_init_val_item = HECMW_malloc(size);
1616 if (mesh->node_init_val_item == NULL) {
1617 set_err(errno, "");
1618 return -1;
1619 }
1620
1621 /* put values into correct places */
1622 for (p = _init; p; p = p->next) {
1623 int lid = get_gid2lid_node(p->node);
1624 int index = mesh->node_init_val_index[lid] - 1;
1625 mesh->node_init_val_item[index] = p->val;
1626 }
1627
1628 return 0;
1629 }
1630
setup_node(struct hecmwST_local_mesh * mesh)1631 static int setup_node(struct hecmwST_local_mesh *mesh) {
1632 int i, id;
1633 size_t size;
1634 struct hecmw_io_node *p;
1635
1636 HECMW_assert(mesh);
1637
1638 /* initiallize */
1639 mesh->n_node = 0;
1640 mesh->nn_internal = 0;
1641 mesh->node_internal_list = NULL;
1642 mesh->node_ID = NULL;
1643 mesh->global_node_ID = NULL;
1644 mesh->node = NULL;
1645 mesh->n_dof = 0;
1646 mesh->n_dof_grp = 0;
1647 mesh->n_dof_tot = 0;
1648 mesh->node_dof_index = NULL;
1649 mesh->node_dof_item = NULL;
1650 mesh->node_val_index = NULL;
1651 mesh->node_val_item = NULL;
1652
1653 /* n_node */
1654 mesh->n_node = HECMW_io_get_n_node();
1655 if (mesh->n_node == 0) {
1656 return 0;
1657 }
1658
1659 /* n_node_gross */
1660 mesh->n_node_gross = mesh->n_node;
1661
1662 /* nn_middle */
1663 mesh->nn_middle = mesh->n_node;
1664
1665 /* nn_internal */
1666 mesh->nn_internal = mesh->n_node;
1667
1668 /* node_internal_list */
1669 size = sizeof(*mesh->node_internal_list) * mesh->nn_internal;
1670 mesh->node_internal_list = HECMW_malloc(size);
1671 if (mesh->node_internal_list == NULL) {
1672 set_err(errno, "");
1673 return -1;
1674 }
1675 /* node_ID */
1676 size = sizeof(*mesh->node_ID) * mesh->n_node * 2;
1677 mesh->node_ID = HECMW_malloc(size);
1678 if (mesh->node_ID == NULL) {
1679 set_err(errno, "");
1680 return -1;
1681 }
1682
1683 /* global_node_ID */
1684 size = sizeof(*mesh->global_node_ID) * mesh->n_node;
1685 mesh->global_node_ID = HECMW_malloc(size);
1686 if (mesh->global_node_ID == NULL) {
1687 set_err(errno, "");
1688 return -1;
1689 }
1690
1691 /* node */
1692 size = sizeof(*mesh->node) * mesh->n_node * 3;
1693 mesh->node = HECMW_malloc(size);
1694 if (mesh->node == NULL) {
1695 set_err(errno, "");
1696 return -1;
1697 }
1698
1699 /* set node_internal_list, node_ID, global_node_ID, node */
1700 HECMW_map_int_iter_init(_node);
1701 for (i = 0; HECMW_map_int_iter_next(_node, &id, (void **)&p); i++) {
1702 mesh->node_internal_list[i] = i + 1;
1703 mesh->node_ID[2 * i] = i + 1;
1704 mesh->node_ID[2 * i + 1] = 0;
1705 mesh->global_node_ID[i] = id;
1706 mesh->node[3 * i] = p->x;
1707 mesh->node[3 * i + 1] = p->y;
1708 mesh->node[3 * i + 2] = p->z;
1709 }
1710
1711 HECMW_assert(i == mesh->n_node);
1712
1713 return 0;
1714 }
1715
setup_elem(struct hecmwST_local_mesh * mesh)1716 static int setup_elem(struct hecmwST_local_mesh *mesh) {
1717 int i, j, n, id;
1718 size_t size, ncon;
1719 struct hecmw_io_element *p;
1720
1721 HECMW_assert(mesh);
1722
1723 /* initialize */
1724 mesh->n_elem = 0;
1725 mesh->ne_internal = 0;
1726 mesh->elem_internal_list = NULL;
1727 mesh->elem_ID = NULL;
1728 mesh->global_elem_ID = NULL;
1729 mesh->elem_node_index = NULL;
1730 mesh->elem_node_item = NULL;
1731 mesh->elem_type = NULL;
1732 mesh->n_elem_type = 0;
1733 mesh->elem_type_index = NULL;
1734 mesh->elem_type_item = NULL;
1735 mesh->section_ID = NULL;
1736 mesh->n_elem_mat_ID = 0;
1737 mesh->elem_mat_ID_index = NULL;
1738 mesh->elem_mat_ID_item = NULL;
1739 mesh->elem_mat_int_index = NULL;
1740 mesh->elem_mat_int_val = NULL;
1741 mesh->elem_val_index = NULL;
1742 mesh->elem_val_item = NULL;
1743
1744 /* n_elem */
1745 mesh->n_elem = HECMW_io_get_n_elem();
1746 HECMW_assert(mesh->n_elem > 0);
1747
1748 /* n_elem_gross */
1749 mesh->n_elem_gross = mesh->n_elem;
1750
1751 /* ne_internal */
1752 mesh->ne_internal = mesh->n_elem;
1753
1754 /* elem_internal_list */
1755 size = sizeof(*mesh->elem_internal_list) * mesh->ne_internal;
1756 mesh->elem_internal_list = HECMW_malloc(size);
1757 if (mesh->elem_internal_list == NULL) {
1758 set_err(errno, "");
1759 return -1;
1760 }
1761
1762 /* elem_ID */
1763 size = sizeof(*mesh->elem_ID) * mesh->n_elem * 2;
1764 mesh->elem_ID = HECMW_malloc(size);
1765 if (mesh->elem_ID == NULL) {
1766 set_err(errno, "");
1767 return -1;
1768 }
1769
1770 /* global_elem_ID */
1771 size = sizeof(*mesh->global_elem_ID) * mesh->n_elem;
1772 mesh->global_elem_ID = HECMW_malloc(size);
1773 if (mesh->global_elem_ID == NULL) {
1774 set_err(errno, "");
1775 return -1;
1776 }
1777
1778 /* elem_type */
1779 size = sizeof(*mesh->elem_type) * mesh->n_elem;
1780 mesh->elem_type = HECMW_malloc(size);
1781 if (mesh->elem_type == NULL) {
1782 set_err(errno, "");
1783 return -1;
1784 }
1785
1786 /* elem_node_index */
1787 size = sizeof(*mesh->elem_node_index) * (mesh->n_elem + 1);
1788 mesh->elem_node_index = HECMW_malloc(size);
1789 if (mesh->elem_node_index == NULL) {
1790 set_err(errno, "");
1791 return -1;
1792 }
1793
1794 /* count total # of connectivity and set elem_node_index */
1795 ncon = 0;
1796 mesh->elem_node_index[0] = 0;
1797
1798 HECMW_map_int_iter_init(_elem);
1799 for (i = 0; HECMW_map_int_iter_next(_elem, &id, (void **)&p); i++) {
1800 n = HECMW_get_max_node(p->type);
1801
1802 HECMW_assert(n > 0);
1803 ncon += n;
1804 HECMW_assert(i + 1 <= mesh->n_elem);
1805 mesh->elem_node_index[i + 1] = mesh->elem_node_index[i] + n;
1806 HECMW_assert(mesh->elem_node_index[i + 1] <= ncon);
1807 }
1808
1809 HECMW_assert(i == mesh->n_elem);
1810 HECMW_assert(mesh->elem_node_index[mesh->n_elem] == ncon);
1811
1812 /* elem_node_item */
1813 size = sizeof(*mesh->elem_node_item) * ncon;
1814 mesh->elem_node_item = HECMW_malloc(size);
1815 if (mesh->elem_node_item == NULL) {
1816 set_err(errno, "");
1817 return -1;
1818 }
1819
1820 /* set elem_ID, global_elem_ID, elem_internal_list, elem_type */
1821 HECMW_map_int_iter_init(_elem);
1822 for (i = 0; HECMW_map_int_iter_next(_elem, &id, (void **)&p); i++) {
1823 int start;
1824
1825 /* connectivity */
1826 n = mesh->elem_node_index[i + 1] - mesh->elem_node_index[i];
1827 start = mesh->elem_node_index[i];
1828 for (j = 0; j < n; j++) {
1829 HECMW_assert(start + j <= mesh->elem_node_index[mesh->n_elem]);
1830 mesh->elem_node_item[start + j] = get_gid2lid_node(p->node[j]);
1831 }
1832
1833 mesh->elem_ID[2 * i] = i + 1;
1834 mesh->elem_ID[2 * i + 1] = 0;
1835 mesh->global_elem_ID[i] = id;
1836 mesh->elem_internal_list[i] = i + 1;
1837 mesh->elem_type[i] = p->type;
1838 }
1839
1840 HECMW_assert(i == mesh->n_elem);
1841
1842 return 0;
1843 }
1844
setup_ngrp(struct hecmwST_local_mesh * mesh)1845 static int setup_ngrp(struct hecmwST_local_mesh *mesh) {
1846 int i, j, nngrp, nnode;
1847 size_t size;
1848 struct hecmwST_node_grp *ngrp;
1849 struct hecmw_io_ngrp *p;
1850
1851 HECMW_assert(mesh);
1852
1853 ngrp = HECMW_malloc(sizeof(*ngrp));
1854 if (ngrp == NULL) {
1855 set_err(errno, "");
1856 return -1;
1857 }
1858
1859 /* initialize */
1860 ngrp->n_grp = 0;
1861 ngrp->n_bc = 0;
1862 ngrp->grp_name = NULL;
1863 ngrp->grp_index = NULL;
1864 ngrp->grp_item = NULL;
1865 ngrp->bc_grp_ID = NULL;
1866 ngrp->bc_grp_type = NULL;
1867 ngrp->bc_grp_index = NULL;
1868 ngrp->bc_grp_dof = NULL;
1869 ngrp->bc_grp_val = NULL;
1870
1871 nngrp = nnode = 0;
1872 for (p = _ngrp; p; p = p->next) {
1873 nnode += HECMW_set_int_nval(p->node);
1874 nngrp++;
1875 }
1876 ngrp->n_grp = nngrp;
1877
1878 if (ngrp->n_grp <= 0) {
1879 mesh->node_group = ngrp;
1880 return 0;
1881 }
1882
1883 /* grp_name */
1884 size = sizeof(*ngrp->grp_name) * ngrp->n_grp;
1885 ngrp->grp_name = HECMW_malloc(size);
1886 if (ngrp->grp_name == NULL) {
1887 set_err(errno, "");
1888 return -1;
1889 }
1890
1891 /* grp_index */
1892 size = sizeof(*ngrp->grp_index) * (ngrp->n_grp + 1);
1893 ngrp->grp_index = HECMW_malloc(size);
1894 if (ngrp->grp_index == NULL) {
1895 set_err(errno, "");
1896 return -1;
1897 }
1898
1899 /* grp_item */
1900 size = sizeof(*ngrp->grp_item) * nnode;
1901 ngrp->grp_item = HECMW_malloc(size);
1902 if (ngrp->grp_item == NULL) {
1903 set_err(errno, "");
1904 return -1;
1905 }
1906
1907 /* set */
1908 ngrp->grp_index[0] = 0;
1909 for (i = 0, p = _ngrp; p; p = p->next, i++) {
1910 int start = ngrp->grp_index[i], nid;
1911
1912 HECMW_set_int_iter_init(p->node);
1913 for (j = 0; HECMW_set_int_iter_next(p->node, &nid); j++) {
1914 HECMW_assert(start + j < nnode);
1915
1916 ngrp->grp_item[start + j] = get_gid2lid_node(nid);
1917
1918 HECMW_assert(ngrp->grp_item[start + j] > 0);
1919 }
1920
1921 ngrp->grp_index[i + 1] = ngrp->grp_index[i] + j;
1922 ngrp->grp_name[i] = HECMW_strdup(p->name);
1923 if (ngrp->grp_name[i] == NULL) {
1924 set_err(errno, "");
1925 return -1;
1926 }
1927 }
1928
1929 HECMW_assert(ngrp->grp_index[ngrp->n_grp] == nnode);
1930
1931 mesh->node_group = ngrp;
1932
1933 return 0;
1934 }
1935
setup_egrp(struct hecmwST_local_mesh * mesh)1936 static int setup_egrp(struct hecmwST_local_mesh *mesh) {
1937 int i, j, negrp, nelem;
1938 size_t size;
1939 struct hecmwST_elem_grp *egrp;
1940 struct hecmw_io_egrp *p;
1941
1942 HECMW_assert(mesh);
1943
1944 egrp = HECMW_malloc(sizeof(*egrp));
1945 if (egrp == NULL) {
1946 set_err(errno, "");
1947 return -1;
1948 }
1949
1950 /* initialize */
1951 egrp->n_grp = 0;
1952 egrp->n_bc = 0;
1953 egrp->grp_name = NULL;
1954 egrp->grp_index = NULL;
1955 egrp->grp_item = NULL;
1956 egrp->bc_grp_ID = NULL;
1957 egrp->bc_grp_type = NULL;
1958 egrp->bc_grp_index = NULL;
1959 egrp->bc_grp_val = NULL;
1960
1961 negrp = nelem = 0;
1962 for (p = _egrp; p; p = p->next) {
1963 nelem += HECMW_set_int_nval(p->elem);
1964 negrp++;
1965 }
1966 egrp->n_grp = negrp;
1967
1968 if (egrp->n_grp <= 0) {
1969 mesh->elem_group = egrp;
1970 return 0;
1971 }
1972
1973 /* grp_name */
1974 size = sizeof(*egrp->grp_name) * egrp->n_grp;
1975 egrp->grp_name = HECMW_malloc(size);
1976 if (egrp->grp_name == NULL) {
1977 set_err(errno, "");
1978 return -1;
1979 }
1980
1981 /* grp_index */
1982 size = sizeof(*egrp->grp_index) * (egrp->n_grp + 1);
1983 egrp->grp_index = HECMW_malloc(size);
1984 if (egrp->grp_index == NULL) {
1985 set_err(errno, "");
1986 return -1;
1987 }
1988
1989 /* grp_item */
1990 size = sizeof(*egrp->grp_item) * nelem;
1991 egrp->grp_item = HECMW_malloc(size);
1992 if (egrp->grp_item == NULL) {
1993 set_err(errno, "");
1994 return -1;
1995 }
1996
1997 /* set */
1998 egrp->grp_index[0] = 0;
1999 for (i = 0, p = _egrp; p; p = p->next, i++) {
2000 int eid;
2001
2002 HECMW_set_int_iter_init(p->elem);
2003 for (j = 0; HECMW_set_int_iter_next(p->elem, &eid); j++) {
2004 int start = egrp->grp_index[i];
2005
2006 HECMW_assert(start + j < nelem);
2007
2008 egrp->grp_item[start + j] = get_gid2lid_elem(eid);
2009
2010 HECMW_assert(egrp->grp_item[start + j] > 0);
2011 }
2012
2013 egrp->grp_index[i + 1] = egrp->grp_index[i] + j;
2014 egrp->grp_name[i] = HECMW_strdup(p->name);
2015
2016 if (egrp->grp_name[i] == NULL) {
2017 set_err(errno, "");
2018 return -1;
2019 }
2020 }
2021
2022 HECMW_assert(egrp->grp_index[egrp->n_grp] == nelem);
2023
2024 mesh->elem_group = egrp;
2025
2026 return 0;
2027 }
2028
setup_sgrp(struct hecmwST_local_mesh * mesh)2029 static int setup_sgrp(struct hecmwST_local_mesh *mesh) {
2030 int i, j, nsgrp, nelem;
2031 size_t size;
2032 struct hecmwST_surf_grp *sgrp;
2033 struct hecmw_io_sgrp *p;
2034
2035 HECMW_assert(mesh);
2036
2037 sgrp = HECMW_malloc(sizeof(*sgrp));
2038 if (sgrp == NULL) {
2039 set_err(errno, "");
2040 return -1;
2041 }
2042
2043 /* initialize */
2044 sgrp->n_grp = 0;
2045 sgrp->n_bc = 0;
2046 sgrp->grp_name = NULL;
2047 sgrp->grp_index = NULL;
2048 sgrp->grp_item = NULL;
2049 sgrp->bc_grp_ID = NULL;
2050 sgrp->bc_grp_type = NULL;
2051 sgrp->bc_grp_index = NULL;
2052 sgrp->bc_grp_val = NULL;
2053
2054 nsgrp = nelem = 0;
2055 for (p = _sgrp; p; p = p->next) {
2056 nelem += HECMW_set_int_nval(p->item);
2057 nsgrp++;
2058 }
2059 sgrp->n_grp = nsgrp;
2060
2061 if (sgrp->n_grp <= 0) {
2062 mesh->surf_group = sgrp;
2063 return 0;
2064 }
2065
2066 /* grp_name */
2067 size = sizeof(*sgrp->grp_name) * sgrp->n_grp;
2068 sgrp->grp_name = HECMW_malloc(size);
2069 if (sgrp->grp_name == NULL) {
2070 set_err(errno, "");
2071 return -1;
2072 }
2073
2074 /* grp_index */
2075 size = sizeof(*sgrp->grp_index) * (sgrp->n_grp + 1);
2076 sgrp->grp_index = HECMW_malloc(size);
2077 if (sgrp->grp_index == NULL) {
2078 set_err(errno, "");
2079 return -1;
2080 }
2081
2082 /* grp_item */
2083 size = sizeof(*sgrp->grp_item) * nelem * 2;
2084 sgrp->grp_item = HECMW_malloc(size);
2085 if (sgrp->grp_item == NULL) {
2086 set_err(errno, "");
2087 return -1;
2088 }
2089
2090 /* set */
2091 sgrp->grp_index[0] = 0;
2092 for (i = 0, p = _sgrp; p; p = p->next, i++) {
2093 int start = sgrp->grp_index[i] * 2, id;
2094
2095 HECMW_set_int_iter_init(p->item);
2096 for (j = 0; HECMW_set_int_iter_next(p->item, &id); j++) {
2097 int eid, sid;
2098
2099 decode_surf_key(id, &eid, &sid);
2100
2101 sgrp->grp_item[start + j * 2] = get_gid2lid_elem(eid);
2102 sgrp->grp_item[start + j * 2 + 1] = sid;
2103 }
2104
2105 sgrp->grp_index[i + 1] = sgrp->grp_index[i] + j;
2106 sgrp->grp_name[i] = HECMW_strdup(p->name);
2107
2108 if (sgrp->grp_name[i] == NULL) {
2109 set_err(errno, "");
2110 return -1;
2111 }
2112 }
2113
2114 HECMW_assert(sgrp->grp_index[sgrp->n_grp] == nelem);
2115
2116 mesh->surf_group = sgrp;
2117
2118 return 0;
2119 }
2120
setup_mpc(struct hecmwST_local_mesh * mesh)2121 static int setup_mpc(struct hecmwST_local_mesh *mesh) {
2122 int i, j, nmpc, nneq, start;
2123 size_t size;
2124 struct hecmwST_mpc *mpc;
2125 struct hecmw_io_mpc *p;
2126
2127 HECMW_assert(mesh);
2128
2129 mpc = HECMW_malloc(sizeof(*mpc));
2130 if (mpc == NULL) {
2131 set_err(errno, "");
2132 goto error;
2133 }
2134
2135 mpc->n_mpc = 0;
2136 mpc->mpc_index = NULL;
2137 mpc->mpc_item = NULL;
2138 mpc->mpc_dof = NULL;
2139 mpc->mpc_val = NULL;
2140 mpc->mpc_const = NULL;
2141
2142 if (_mpc == NULL) {
2143 mesh->mpc = mpc;
2144 return 0;
2145 }
2146
2147 /* count total # of mpc, neq */
2148 nmpc = 0;
2149 nneq = 0;
2150 for (p = _mpc; p; p = p->next) {
2151 nmpc++;
2152 nneq += p->neq;
2153 }
2154 HECMW_assert(nmpc > 0);
2155 HECMW_assert(nneq > 0);
2156 mpc->n_mpc = nmpc;
2157
2158 /* mpc_index */
2159 size = sizeof(*mpc->mpc_index) * (mpc->n_mpc + 1);
2160 mpc->mpc_index = HECMW_malloc(size);
2161 if (mpc->mpc_index == NULL) {
2162 set_err(errno, "");
2163 goto error;
2164 }
2165
2166 /* mpc_item */
2167 size = sizeof(*mpc->mpc_item) * nneq;
2168 mpc->mpc_item = HECMW_malloc(size);
2169 if (mpc->mpc_item == NULL) {
2170 set_err(errno, "");
2171 goto error;
2172 }
2173
2174 /* mpc_dof */
2175 size = sizeof(*mpc->mpc_dof) * nneq;
2176 mpc->mpc_dof = HECMW_malloc(size);
2177 if (mpc->mpc_dof == NULL) {
2178 set_err(errno, "");
2179 goto error;
2180 }
2181
2182 /* mpc_val */
2183 size = sizeof(*mpc->mpc_val) * nneq;
2184 mpc->mpc_val = HECMW_malloc(size);
2185 if (mpc->mpc_val == NULL) {
2186 set_err(errno, "");
2187 goto error;
2188 }
2189
2190 /* mpc_const */
2191 size = sizeof(*mpc->mpc_const) * nmpc;
2192 mpc->mpc_const = HECMW_malloc(size);
2193 if (mpc->mpc_const == NULL) {
2194 set_err(errno, "");
2195 goto error;
2196 }
2197
2198 /* set */
2199 i = 0;
2200 mpc->mpc_index[0] = 0;
2201 for (p = _mpc; p; p = p->next) {
2202 HECMW_assert(i + 1 <= mpc->n_mpc);
2203 mpc->mpc_index[i + 1] = mpc->mpc_index[i] + p->neq;
2204 HECMW_assert(mpc->mpc_index[i + 1] <= nneq);
2205 start = mpc->mpc_index[i];
2206 for (j = 0; j < p->neq; j++) {
2207 HECMW_assert(start + j < nneq);
2208 mpc->mpc_item[start + j] = get_gid2lid_node(p->item[j].node);
2209 HECMW_assert(mpc->mpc_item[start + j]);
2210 mpc->mpc_dof[start + j] = p->item[j].dof;
2211 mpc->mpc_val[start + j] = p->item[j].a;
2212 }
2213 mpc->mpc_const[i] = p->cnst;
2214 i++;
2215 }
2216 HECMW_assert(i == mpc->n_mpc);
2217 HECMW_assert(mpc->mpc_index[mpc->n_mpc] == nneq);
2218
2219 mesh->mpc = mpc;
2220
2221 return 0;
2222 error:
2223 if (mpc) {
2224 HECMW_free(mpc->mpc_index);
2225 HECMW_free(mpc->mpc_item);
2226 HECMW_free(mpc->mpc_dof);
2227 HECMW_free(mpc->mpc_val);
2228 HECMW_free(mpc->mpc_const);
2229 HECMW_free(mpc);
2230 }
2231 return -1;
2232 }
2233
setup_amp(struct hecmwST_local_mesh * mesh)2234 static int setup_amp(struct hecmwST_local_mesh *mesh) {
2235 int i, j, namp, nitem, start;
2236 size_t size;
2237 struct hecmwST_amplitude *amp;
2238 struct hecmw_io_amplitude *p;
2239
2240 HECMW_assert(mesh);
2241
2242 amp = HECMW_malloc(sizeof(*amp));
2243 if (amp == NULL) {
2244 set_err(errno, "");
2245 return -1;
2246 }
2247
2248 amp->n_amp = 0;
2249 amp->amp_name = NULL;
2250 amp->amp_type_definition = NULL;
2251 amp->amp_type_time = NULL;
2252 amp->amp_type_value = NULL;
2253 amp->amp_index = NULL;
2254 amp->amp_val = NULL;
2255 amp->amp_table = NULL;
2256
2257 if (_amp == NULL) {
2258 mesh->amp = amp;
2259 return 0;
2260 }
2261
2262 /* count total # of amplitude,item */
2263 namp = 0;
2264 nitem = 0;
2265 for (p = _amp; p; p = p->next) {
2266 struct hecmw_io_amplitude_item *item;
2267 for (item = p->item; item; item = item->next) {
2268 nitem++;
2269 }
2270 namp++;
2271 }
2272 HECMW_assert(namp > 0);
2273 HECMW_assert(nitem > 0);
2274 amp->n_amp = namp;
2275
2276 /* amp_name */
2277 size = sizeof(*amp->amp_name) * amp->n_amp;
2278 amp->amp_name = HECMW_malloc(size);
2279 if (amp->amp_name == NULL) {
2280 set_err(errno, "");
2281 return -1;
2282 }
2283
2284 /* amp_type_definition */
2285 size = sizeof(*amp->amp_type_definition) * amp->n_amp;
2286 amp->amp_type_definition = HECMW_malloc(size);
2287 if (amp->amp_type_definition == NULL) {
2288 set_err(errno, "");
2289 return -1;
2290 }
2291
2292 /* amp_type_time */
2293 size = sizeof(*amp->amp_type_time) * amp->n_amp;
2294 amp->amp_type_time = HECMW_malloc(size);
2295 if (amp->amp_type_time == NULL) {
2296 set_err(errno, "");
2297 return -1;
2298 }
2299
2300 /* amp_type_val */
2301 size = sizeof(*amp->amp_type_value) * amp->n_amp;
2302 amp->amp_type_value = HECMW_malloc(size);
2303 if (amp->amp_type_value == NULL) {
2304 set_err(errno, "");
2305 return -1;
2306 }
2307
2308 /* amp_index */
2309 size = sizeof(*amp->amp_index) * (amp->n_amp + 1);
2310 amp->amp_index = HECMW_malloc(size);
2311 if (amp->amp_index == NULL) {
2312 set_err(errno, "");
2313 return -1;
2314 }
2315
2316 /* amp_val */
2317 size = sizeof(*amp->amp_val) * nitem;
2318 amp->amp_val = HECMW_malloc(size);
2319 if (amp->amp_val == NULL) {
2320 set_err(errno, "");
2321 return -1;
2322 }
2323
2324 /* amp_table */
2325 size = sizeof(*amp->amp_table) * nitem;
2326 amp->amp_table = HECMW_malloc(size);
2327 if (amp->amp_table == NULL) {
2328 set_err(errno, "");
2329 return -1;
2330 }
2331
2332 /* set */
2333 i = 0;
2334 amp->amp_index[0] = 0;
2335 for (p = _amp; p; p = p->next) {
2336 struct hecmw_io_amplitude_item *item;
2337 int n = 0;
2338 for (item = p->item; item; item = item->next) {
2339 n++;
2340 }
2341 HECMW_assert(i + 1 <= namp);
2342 amp->amp_index[i + 1] = amp->amp_index[i] + n;
2343 HECMW_assert(amp->amp_index[i + 1] <= nitem);
2344 start = amp->amp_index[i];
2345 for (item = p->item, j = 0; item; item = item->next, j++) {
2346 amp->amp_val[start + j] = item->val;
2347 amp->amp_table[start + j] = item->table;
2348 }
2349 HECMW_assert(strlen(p->name) < HECMW_NAME_LEN);
2350 amp->amp_name[i] = HECMW_strdup(p->name);
2351 if (amp->amp_name[i] == NULL) {
2352 set_err(errno, "");
2353 return -1;
2354 }
2355 amp->amp_type_definition[i] = p->type_def;
2356 amp->amp_type_time[i] = p->type_time;
2357 amp->amp_type_value[i] = p->type_val;
2358 i++;
2359 }
2360 HECMW_assert(i == amp->n_amp);
2361 HECMW_assert(amp->amp_index[amp->n_amp] == nitem);
2362
2363 mesh->amp = amp;
2364
2365 return 0;
2366 }
2367
setup_adapt(struct hecmwST_local_mesh * mesh)2368 static int setup_adapt(struct hecmwST_local_mesh *mesh) {
2369 HECMW_assert(mesh);
2370
2371 /* clear */
2372 mesh->coarse_grid_level = 0;
2373 mesh->n_adapt = 0;
2374 mesh->when_i_was_refined_node = NULL;
2375 mesh->when_i_was_refined_elem = NULL;
2376 mesh->adapt_parent_type = NULL;
2377 mesh->adapt_type = NULL;
2378 mesh->adapt_level = NULL;
2379 mesh->adapt_parent = NULL;
2380 mesh->adapt_children_index = NULL;
2381 mesh->adapt_children_item = NULL;
2382
2383 return 0;
2384 }
2385
setup_refine(struct hecmwST_local_mesh * mesh)2386 static int setup_refine(struct hecmwST_local_mesh *mesh) {
2387 HECMW_assert(mesh);
2388
2389 /* clear */
2390 mesh->n_refine = 0;
2391 mesh->node_old2new = NULL;
2392 mesh->node_new2old = NULL;
2393 mesh->elem_old2new = NULL;
2394 mesh->elem_new2old = NULL;
2395 mesh->n_node_refine_hist = NULL;
2396
2397 return 0;
2398 }
2399
setup_pe(struct hecmwST_local_mesh * mesh)2400 static int setup_pe(struct hecmwST_local_mesh *mesh) {
2401 HECMW_assert(mesh);
2402
2403 mesh->PETOT = HECMW_comm_get_size();
2404 mesh->my_rank = HECMW_comm_get_rank();
2405 mesh->HECMW_COMM = HECMW_comm_get_comm();
2406 mesh->PEsmpTOT = 1;
2407 mesh->n_subdomain = 1;
2408 mesh->errnof = 0;
2409 mesh->n_neighbor_pe = 0;
2410 mesh->neighbor_pe = NULL;
2411 mesh->import_index = NULL;
2412 mesh->import_item = NULL;
2413 mesh->export_index = NULL;
2414 mesh->export_item = NULL;
2415 mesh->shared_index = NULL;
2416 mesh->shared_item = NULL;
2417
2418 if (mesh->my_rank == 0) {
2419 mesh->zero = 1;
2420 } else {
2421 mesh->zero = 0;
2422 }
2423
2424 return 0;
2425 }
2426
setup_elem_check_sectid(struct hecmwST_local_mesh * mesh)2427 static int setup_elem_check_sectid(struct hecmwST_local_mesh *mesh) {
2428 int i;
2429
2430 HECMW_assert(mesh);
2431
2432 for (i = 0; i < mesh->n_elem; i++) {
2433 if (mesh->section_ID[i] == -1) {
2434 set_err(HECMW_IO_E1012, "Element %d", mesh->global_elem_ID[i]);
2435 return -1;
2436 }
2437 }
2438 return 0;
2439 }
2440
setup_sect_set_sectid(struct hecmwST_local_mesh * mesh,const char * egrp_name,int sectid)2441 static int setup_sect_set_sectid(struct hecmwST_local_mesh *mesh,
2442 const char *egrp_name, int sectid) {
2443 int i, eid, egid, start, end;
2444 struct hecmwST_elem_grp *egrp;
2445
2446 HECMW_assert(mesh);
2447 HECMW_assert(mesh->elem_group);
2448 HECMW_assert(egrp_name);
2449
2450 egid = HECMW_dist_get_egrp_id(mesh->elem_group, egrp_name);
2451 HECMW_assert(egid > 0);
2452
2453 egrp = mesh->elem_group;
2454
2455 start = egrp->grp_index[egid - 1];
2456 end = egrp->grp_index[egid] - 1;
2457
2458 HECMW_assert(mesh->section_ID);
2459 for (i = start; i <= end; i++) {
2460 eid = egrp->grp_item[i];
2461 if (mesh->section_ID[eid - 1] != -1) {
2462 set_err(HECMW_IO_E1012, "Element %d has already had section %d",
2463 mesh->global_elem_ID[eid - 1], mesh->section_ID[eid - 1]);
2464 return -1;
2465 }
2466 mesh->section_ID[eid - 1] = sectid;
2467 }
2468 return 0;
2469 }
2470
setup_sect(struct hecmwST_local_mesh * mesh)2471 static int setup_sect(struct hecmwST_local_mesh *mesh) {
2472 int i, nsect, nint, nreal, nmat;
2473 size_t size;
2474 struct hecmwST_section *sect;
2475 struct hecmw_io_section *p;
2476
2477 HECMW_assert(mesh);
2478
2479 /* mesh->section */
2480 size = sizeof(*sect);
2481 sect = HECMW_malloc(size);
2482 if (sect == NULL) {
2483 set_err(errno, "");
2484 return -1;
2485 }
2486
2487 /* section_ID */
2488 size = sizeof(*mesh->section_ID) * mesh->n_elem;
2489 mesh->section_ID = HECMW_malloc(size);
2490 if (mesh->section_ID == NULL) {
2491 set_err(errno, "");
2492 return -1;
2493 }
2494 memset(mesh->section_ID, -1, size); /* initialize */
2495
2496 nsect = nint = nreal = nmat = 0;
2497 for (p = _sect; p; p = p->next) {
2498 nsect++;
2499 if (p->type == HECMW_SECT_TYPE_SOLID) {
2500 nreal++; /* thickness */
2501 } else if (p->type == HECMW_SECT_TYPE_SHELL) {
2502 nreal++; /* thickness */
2503 nint++; /* integpoints */
2504 } else if (p->type == HECMW_SECT_TYPE_BEAM) {
2505 nreal += 7; /* vxyz3, Iyy, Izz, Jx */
2506 } else if (p->type == HECMW_SECT_TYPE_INTERFACE) {
2507 nreal += 4; /* thickness, gapcon, gaprad1, gaprad2 */
2508 } else {
2509 return -1;
2510 }
2511 /*
2512 if(p->composite > 0) {
2513 nmat += composite;
2514 } else {
2515 nmat++;
2516 }
2517 */
2518 nmat++;
2519 }
2520 sect->n_sect = nsect;
2521
2522 sect->sect_type = NULL;
2523 sect->sect_opt = NULL;
2524 sect->sect_mat_ID_index = NULL;
2525 sect->sect_mat_ID_item = NULL;
2526 sect->sect_I_index = NULL;
2527 sect->sect_I_item = NULL;
2528 sect->sect_R_index = NULL;
2529 sect->sect_R_item = NULL;
2530
2531 if (sect->n_sect <= 0) {
2532 mesh->section = sect;
2533 return 0;
2534 }
2535
2536 /* sect_type */
2537 size = sizeof(*sect->sect_type) * sect->n_sect;
2538 sect->sect_type = HECMW_malloc(size);
2539 if (sect->sect_type == NULL) {
2540 set_err(errno, "");
2541 return -1;
2542 }
2543
2544 /* sect_opt */
2545 size = sizeof(*sect->sect_opt) * sect->n_sect;
2546 sect->sect_opt = HECMW_malloc(size);
2547 if (sect->sect_opt == NULL) {
2548 set_err(errno, "");
2549 return -1;
2550 }
2551
2552 /* sect_mat_ID_index */
2553 size = sizeof(*sect->sect_mat_ID_index) * (sect->n_sect + 1);
2554 sect->sect_mat_ID_index = HECMW_malloc(size);
2555 if (sect->sect_mat_ID_index == NULL) {
2556 set_err(errno, "");
2557 return -1;
2558 }
2559
2560 /* sect_mat_ID_item */
2561 HECMW_assert(nmat > 0);
2562 size = sizeof(*sect->sect_mat_ID_item) * nmat;
2563 sect->sect_mat_ID_item = HECMW_malloc(size);
2564 if (sect->sect_mat_ID_item == NULL) {
2565 set_err(errno, "");
2566 return -1;
2567 }
2568
2569 /* sect_I_index */
2570 size = sizeof(*sect->sect_I_index) * (sect->n_sect + 1);
2571 sect->sect_I_index = HECMW_malloc(size);
2572 if (sect->sect_I_index == NULL) {
2573 set_err(errno, "");
2574 return -1;
2575 }
2576
2577 /* sect_I_item */
2578 sect->sect_I_item = NULL;
2579 if (nint > 0) {
2580 size = sizeof(*sect->sect_I_item) * nint;
2581 sect->sect_I_item = HECMW_malloc(size);
2582 if (sect->sect_I_item == NULL) {
2583 set_err(errno, "");
2584 return -1;
2585 }
2586 }
2587
2588 /* sect_R_index */
2589 size = sizeof(*sect->sect_R_index) * (sect->n_sect + 1);
2590 sect->sect_R_index = HECMW_malloc(size);
2591 if (sect->sect_R_index == NULL) {
2592 set_err(errno, "");
2593 return -1;
2594 }
2595
2596 /* sect_R_item */
2597 sect->sect_R_item = NULL;
2598 if (nreal > 0) {
2599 size = sizeof(*sect->sect_R_item) * nreal;
2600 sect->sect_R_item = HECMW_malloc(size);
2601 if (sect->sect_R_item == NULL) {
2602 set_err(errno, "");
2603 return -1;
2604 }
2605 }
2606
2607 /* set */
2608 sect->sect_I_index[0] = 0;
2609 sect->sect_R_index[0] = 0;
2610 sect->sect_mat_ID_index[0] = 0;
2611 for (i = 0, p = _sect; p; p = p->next, i++) {
2612 int iidx = sect->sect_I_index[i];
2613 int ridx = sect->sect_R_index[i];
2614 int midx;
2615 if (p->type == HECMW_SECT_TYPE_SOLID) {
2616 sect->sect_I_index[i + 1] = sect->sect_I_index[i] + 0;
2617 sect->sect_R_index[i + 1] = sect->sect_R_index[i] + 1;
2618 HECMW_assert(ridx <= nreal);
2619 sect->sect_R_item[ridx] = p->sect.solid.thickness;
2620 } else if (p->type == HECMW_SECT_TYPE_SHELL) {
2621 sect->sect_I_index[i + 1] = sect->sect_I_index[i] + 1;
2622 sect->sect_R_index[i + 1] = sect->sect_R_index[i] + 1;
2623 HECMW_assert(iidx <= nint);
2624 HECMW_assert(ridx <= nreal);
2625 sect->sect_I_item[iidx] = p->sect.shell.integpoints;
2626 sect->sect_R_item[ridx] = p->sect.shell.thickness;
2627 } else if (p->type == HECMW_SECT_TYPE_BEAM) {
2628 sect->sect_I_index[i + 1] = sect->sect_I_index[i] + 0;
2629 sect->sect_R_index[i + 1] = sect->sect_R_index[i] + 7;
2630 HECMW_assert(ridx + 6 <= nreal);
2631 sect->sect_R_item[ridx] = p->sect.beam.vxyz[0];
2632 sect->sect_R_item[ridx + 1] = p->sect.beam.vxyz[1];
2633 sect->sect_R_item[ridx + 2] = p->sect.beam.vxyz[2];
2634 sect->sect_R_item[ridx + 3] = p->sect.beam.area;
2635 sect->sect_R_item[ridx + 4] = p->sect.beam.Iyy;
2636 sect->sect_R_item[ridx + 5] = p->sect.beam.Izz;
2637 sect->sect_R_item[ridx + 6] = p->sect.beam.Jx;
2638 } else if (p->type == HECMW_SECT_TYPE_INTERFACE) {
2639 sect->sect_I_index[i + 1] = sect->sect_I_index[i] + 0;
2640 sect->sect_R_index[i + 1] = sect->sect_R_index[i] + 4;
2641 HECMW_assert(ridx + 3 <= nreal);
2642 sect->sect_R_item[ridx] = p->sect.interface.thickness;
2643 sect->sect_R_item[ridx + 1] = p->sect.interface.gapcon;
2644 sect->sect_R_item[ridx + 2] = p->sect.interface.gaprad1;
2645 sect->sect_R_item[ridx + 3] = p->sect.interface.gaprad2;
2646 } else {
2647 return -1;
2648 }
2649 sect->sect_type[i] = p->type;
2650 sect->sect_opt[i] = p->secopt;
2651 sect->sect_mat_ID_index[i + 1] = sect->sect_mat_ID_index[i] + 1;
2652 midx = sect->sect_mat_ID_index[i];
2653 /* must be called setup_mat() before */
2654 HECMW_assert(mesh->material);
2655 sect->sect_mat_ID_item[midx] =
2656 HECMW_dist_get_mat_id(mesh->material, p->material);
2657 HECMW_assert(sect->sect_mat_ID_item[midx] > 0);
2658
2659 /* set mesh->section_id */
2660 /* depends on setup_egrp() */
2661 if (setup_sect_set_sectid(mesh, p->egrp, i + 1)) return -1;
2662 }
2663
2664 mesh->section = sect;
2665
2666 return 0;
2667 }
2668
setup_mpc_sectid(struct hecmwST_local_mesh * mesh)2669 static int setup_mpc_sectid(struct hecmwST_local_mesh *mesh) {
2670 int i;
2671 struct hecmw_io_element *elem;
2672
2673 HECMW_assert(mesh);
2674
2675 for (i = 0; i < mesh->n_elem; i++) {
2676 /* depends on setup_elem() */
2677 if (mesh->elem_type[i] < 900) continue;
2678 if (mesh->elem_type[i] >= 1000) continue;
2679 elem = HECMW_io_get_elem(mesh->global_elem_ID[i]);
2680 HECMW_assert(elem);
2681 HECMW_assert(elem->mpc_sectid != -1);
2682 mesh->section_ID[i] = elem->mpc_sectid;
2683 }
2684 return 0;
2685 }
2686
setup_mpc_reorder(struct hecmwST_local_mesh * mesh)2687 static int setup_mpc_reorder(struct hecmwST_local_mesh *mesh) {
2688 if (HECMW_reorder(mesh)) {
2689 return -1;
2690 }
2691 return 0;
2692 }
2693
setup_mat(struct hecmwST_local_mesh * mesh)2694 static int setup_mat(struct hecmwST_local_mesh *mesh) {
2695 int i, j, k, l, nmat, nmatitem, nmatsubitem, nmattable;
2696 size_t size;
2697 struct hecmwST_material *mat;
2698 struct hecmw_io_material *p;
2699
2700 HECMW_assert(mesh);
2701
2702 /* mesh->material */
2703 size = sizeof(*mat);
2704 mat = HECMW_malloc(size);
2705 if (mat == NULL) {
2706 set_err(errno, "");
2707 return -1;
2708 }
2709
2710 /* n_mat, n_mat_item, n_mat_subitem, n_mat_table */
2711 nmat = nmatitem = nmatsubitem = nmattable = 0;
2712 for (p = _mat; p; p = p->next) {
2713 nmat++;
2714 nmatitem += p->nitem;
2715 for (i = 0; i < p->nitem; i++) {
2716 struct hecmw_io_matsubitem *msi = p->item[i].subitem;
2717 nmatsubitem += p->item[i].nval;
2718 for (msi = p->item[i].subitem; msi; msi = msi->next) {
2719 nmattable += p->item[i].nval;
2720 }
2721 }
2722 }
2723 mat->n_mat = nmat;
2724 mat->n_mat_item = nmatitem;
2725 mat->n_mat_subitem = nmatsubitem;
2726 mat->n_mat_table = nmattable;
2727
2728 mat->mat_name = NULL;
2729 mat->mat_item_index = NULL;
2730 mat->mat_subitem_index = NULL;
2731 mat->mat_table_index = NULL;
2732 mat->mat_val = NULL;
2733 mat->mat_temp = NULL;
2734
2735 if (mat->n_mat <= 0) {
2736 mesh->material = mat;
2737 return 0;
2738 }
2739
2740 /* mat_name */
2741 size = sizeof(*mat->mat_name) * mat->n_mat;
2742 mat->mat_name = HECMW_malloc(size);
2743 if (mat->mat_name == NULL) {
2744 set_err(errno, "");
2745 return -1;
2746 }
2747
2748 /* mat_item_index */
2749 size = sizeof(*mat->mat_item_index) * (mat->n_mat + 1);
2750 mat->mat_item_index = HECMW_malloc(size);
2751 if (mat->mat_item_index == NULL) {
2752 set_err(errno, "");
2753 return -1;
2754 }
2755
2756 /* mat_subitem_index */
2757 size = sizeof(*mat->mat_subitem_index) * (mat->n_mat_item + 1);
2758 mat->mat_subitem_index = HECMW_malloc(size);
2759 if (mat->mat_subitem_index == NULL) {
2760 set_err(errno, "");
2761 return -1;
2762 }
2763
2764 /* mat_table_index */
2765 size = sizeof(*mat->mat_table_index) * (mat->n_mat_subitem + 1);
2766 mat->mat_table_index = HECMW_malloc(size);
2767 if (mat->mat_table_index == NULL) {
2768 set_err(errno, "");
2769 return -1;
2770 }
2771
2772 /* mat_val */
2773 size = sizeof(*mat->mat_val) * nmattable;
2774 mat->mat_val = HECMW_malloc(size);
2775 if (mat->mat_val == NULL) {
2776 set_err(errno, "");
2777 return -1;
2778 }
2779
2780 /* mat_temp */
2781 size = sizeof(*mat->mat_temp) * nmattable;
2782 mat->mat_temp = HECMW_malloc(size);
2783 if (mat->mat_temp == NULL) {
2784 set_err(errno, "");
2785 return -1;
2786 }
2787
2788 /* set */
2789 mat->mat_item_index[0] = 0;
2790 mat->mat_subitem_index[0] = 0;
2791 mat->mat_table_index[0] = 0;
2792 for (i = 0, p = _mat; p; p = p->next, i++) {
2793 HECMW_assert(i + 1 <= mat->n_mat);
2794 mat->mat_item_index[i + 1] = mat->mat_item_index[i] + p->nitem;
2795 mat->mat_name[i] = HECMW_strdup(p->name);
2796 if (mat->mat_name[i] == NULL) {
2797 set_err(errno, "");
2798 return -1;
2799 }
2800 for (j = 0; j < p->nitem; j++) {
2801 int ntable = 0;
2802 struct hecmw_io_matitem *item = &p->item[j];
2803 struct hecmw_io_matsubitem *subitem = item->subitem;
2804 int idx = mat->mat_item_index[i] + j;
2805 HECMW_assert(idx + 1 <= mat->n_mat_item);
2806 mat->mat_subitem_index[idx + 1] =
2807 mat->mat_subitem_index[idx] + item->nval;
2808 for (subitem = item->subitem; subitem; subitem = subitem->next) {
2809 ntable++;
2810 }
2811 for (k = 0; k < item->nval; k++) {
2812 HECMW_assert(mat->mat_item_index[i] + j <= mat->n_mat_item);
2813 idx = mat->mat_subitem_index[mat->mat_item_index[i] + j] + k;
2814 HECMW_assert(idx + 1 <= mat->n_mat_subitem);
2815 mat->mat_table_index[idx + 1] = mat->mat_table_index[idx] + ntable;
2816 }
2817 for (k = 0, subitem = item->subitem; subitem;
2818 subitem = subitem->next, k++) {
2819 for (l = 0; l < item->nval; l++) {
2820 int imat = mat->mat_item_index[i];
2821 int ismat = mat->mat_subitem_index[imat + j];
2822 int itable = mat->mat_table_index[ismat + l];
2823 idx = itable + k;
2824 HECMW_assert(idx < mat->n_mat_table);
2825 mat->mat_val[idx] = subitem->val[l];
2826 mat->mat_temp[idx] = subitem->temp;
2827 }
2828 }
2829 }
2830 }
2831
2832 HECMW_assert(mat->mat_item_index[mat->n_mat] == mat->n_mat_item);
2833 HECMW_assert(mat->mat_subitem_index[mat->n_mat_item] == mat->n_mat_subitem);
2834 HECMW_assert(mat->mat_table_index[mat->n_mat_subitem] == mat->n_mat_table);
2835
2836 mesh->material = mat;
2837
2838 return 0;
2839 }
2840
setup_elem_mat(struct hecmwST_local_mesh * mesh)2841 static int setup_elem_mat(struct hecmwST_local_mesh *mesh) {
2842 int i, j, n, id, idx, *start, sectid, nmat, *matid;
2843 struct mat_table {
2844 int n;
2845 int *matid;
2846 } * mat;
2847
2848 HECMW_assert(mesh);
2849
2850 mat = HECMW_malloc(sizeof(*mat) * mesh->n_elem);
2851 if (mat == NULL) {
2852 set_err(errno, "");
2853 return -1;
2854 }
2855
2856 for (i = 0; i < mesh->n_elem; i++) {
2857 mat[i].n = 0;
2858 }
2859
2860 nmat = 0;
2861 for (i = 0; i < mesh->n_elem; i++) {
2862 struct hecmw_io_element *elem = HECMW_io_get_elem(mesh->global_elem_ID[i]);
2863 HECMW_assert(elem);
2864 if (mesh->elem_type[i] >= 900 && mesh->elem_type[i] < 1000) {
2865 n = 1;
2866 HECMW_assert(elem->mpc_matid != -1);
2867 start = &elem->mpc_matid;
2868 } else if (mesh->elem_type[i] >= 1000 && mesh->elem_type[i] < 1100) {
2869 n = 1;
2870 HECMW_assert(elem->mpc_matid != -1);
2871 start = &elem->mpc_matid;
2872 } else {
2873 if (elem->nmatitem > 0) {
2874 HECMW_assert(mesh->material);
2875 n = 1;
2876 id = HECMW_dist_get_mat_id(mesh->material, elem->matname);
2877 HECMW_assert(id > 0);
2878 start = &id;
2879 } else {
2880 HECMW_assert(mesh->section);
2881 sectid = mesh->section_ID[i];
2882 HECMW_assert(sectid > 0);
2883 idx = mesh->section->sect_mat_ID_index[sectid - 1];
2884 n = mesh->section->sect_mat_ID_index[sectid] - idx;
2885 HECMW_assert(n > 0);
2886 start = &mesh->section->sect_mat_ID_item[idx];
2887 }
2888 }
2889 matid = HECMW_malloc(sizeof(matid) * n);
2890 if (matid == NULL) {
2891 set_err(errno, "");
2892 return -1;
2893 }
2894 for (j = 0; j < n; j++) {
2895 matid[j] = start[j];
2896 }
2897 mat[i].matid = matid;
2898 mat[i].n = n;
2899 nmat += n;
2900 }
2901
2902 mesh->n_elem_mat_ID = nmat;
2903 if (mesh->n_elem_mat_ID > 0) {
2904 size_t size;
2905 size = sizeof(*mesh->elem_mat_ID_index) * (mesh->n_elem + 1);
2906 mesh->elem_mat_ID_index = HECMW_malloc(size);
2907 if (mesh->elem_mat_ID_index == NULL) {
2908 set_err(errno, "");
2909 return -1;
2910 }
2911
2912 size = sizeof(*mesh->elem_mat_ID_item) * nmat;
2913 mesh->elem_mat_ID_item = HECMW_malloc(size);
2914 if (mesh->elem_mat_ID_item == NULL) {
2915 set_err(errno, "");
2916 return -1;
2917 }
2918
2919 mesh->elem_mat_ID_index[0] = 0;
2920 for (i = 0; i < mesh->n_elem; i++) {
2921 mesh->elem_mat_ID_index[i + 1] = mesh->elem_mat_ID_index[i] + mat[i].n;
2922 for (j = 0; j < mat[i].n; j++) {
2923 int sidx = mesh->elem_mat_ID_index[i];
2924 mesh->elem_mat_ID_item[sidx + j] = mat[i].matid[j];
2925 }
2926 }
2927 }
2928
2929 for (i = 0; i < mesh->n_elem; i++) {
2930 HECMW_free(mat[i].matid);
2931 }
2932 HECMW_free(mat);
2933
2934 return 0;
2935 }
2936
setup_contact(struct hecmwST_local_mesh * mesh)2937 static int setup_contact(struct hecmwST_local_mesh *mesh) {
2938 int i, npair, slave_gid, master_gid, orislave_sgid;
2939 size_t size;
2940 struct hecmwST_contact_pair *cpair;
2941 struct hecmw_io_contact *p;
2942 orislave_sgid = 0;
2943 slave_gid = 0;
2944
2945 HECMW_assert(mesh);
2946
2947 cpair = HECMW_malloc(sizeof(*cpair));
2948 if (cpair == NULL) {
2949 set_err(errno, "");
2950 goto error;
2951 }
2952
2953 cpair->n_pair = 0;
2954 cpair->type = NULL;
2955 cpair->name = NULL;
2956 cpair->slave_grp_id = NULL;
2957 cpair->slave_orisgrp_id = NULL;
2958 cpair->master_grp_id = NULL;
2959
2960 if (_contact == NULL) {
2961 mesh->contact_pair = cpair;
2962 return 0;
2963 }
2964
2965 /* count total # of contact pairs */
2966 npair = 0;
2967 for (p = _contact; p; p = p->next) {
2968 npair++;
2969 }
2970 HECMW_assert(npair > 0);
2971 cpair->n_pair = npair;
2972
2973 /* name */
2974 size = sizeof(*cpair->name) * (cpair->n_pair);
2975 cpair->name = HECMW_malloc(size);
2976 if (cpair->name == NULL) {
2977 set_err(errno, "");
2978 return -1;
2979 }
2980
2981 /* type */
2982 size = sizeof(*cpair->type) * (cpair->n_pair);
2983 cpair->type = HECMW_malloc(size);
2984 if (cpair->type == NULL) {
2985 set_err(errno, "");
2986 goto error;
2987 }
2988
2989 /* slave_grp_id */
2990 size = sizeof(*cpair->slave_grp_id) * (cpair->n_pair);
2991 cpair->slave_grp_id = HECMW_malloc(size);
2992 if (cpair->slave_grp_id == NULL) {
2993 set_err(errno, "");
2994 goto error;
2995 }
2996
2997 /* slave_orisgrp_id */
2998 size = sizeof(*cpair->slave_orisgrp_id) * (cpair->n_pair);
2999 cpair->slave_orisgrp_id = HECMW_malloc(size);
3000 if (cpair->slave_orisgrp_id == NULL) {
3001 set_err(errno, "");
3002 goto error;
3003 }
3004
3005 /* master_grp_id */
3006 size = sizeof(*cpair->master_grp_id) * (cpair->n_pair);
3007 cpair->master_grp_id = HECMW_malloc(size);
3008 if (cpair->master_grp_id == NULL) {
3009 set_err(errno, "");
3010 goto error;
3011 }
3012
3013 /* set */
3014 for (p = _contact, i = 0; p; p = p->next, i++) {
3015 HECMW_assert(i + 1 <= cpair->n_pair);
3016
3017 HECMW_assert(strlen(p->name) < HECMW_NAME_LEN);
3018 cpair->name[i] = HECMW_strdup(p->name);
3019 if (cpair->name[i] == NULL) {
3020 set_err(errno, "");
3021 return -1;
3022 }
3023
3024 cpair->type[i] = p->type;
3025
3026 if (p->type == HECMW_CONTACT_TYPE_NODE_SURF) {
3027 slave_gid = HECMW_dist_get_ngrp_id(mesh->node_group, p->slave_grp);
3028 orislave_sgid = -1;
3029 } else if (p->type == HECMW_CONTACT_TYPE_SURF_SURF) {
3030 slave_gid = HECMW_dist_get_sgrp_id(mesh->surf_group, p->slave_grp);
3031 orislave_sgid = HECMW_dist_get_sgrp_id(mesh->surf_group, p->slave_orisgrp);
3032 } else {
3033 HECMW_assert(0);
3034 }
3035 HECMW_assert(slave_gid > 0);
3036
3037 cpair->slave_grp_id[i] = slave_gid;
3038 cpair->slave_orisgrp_id[i] = orislave_sgid;
3039
3040 master_gid = HECMW_dist_get_sgrp_id(mesh->surf_group, p->master_grp);
3041 HECMW_assert(master_gid > 0);
3042
3043 cpair->master_grp_id[i] = master_gid;
3044 }
3045 HECMW_assert(i == cpair->n_pair);
3046
3047 mesh->contact_pair = cpair;
3048
3049 return 0;
3050
3051 error:
3052 return -1;
3053 }
3054
setup_contact_sectid(struct hecmwST_local_mesh * mesh)3055 static int setup_contact_sectid(struct hecmwST_local_mesh *mesh) {
3056 int i;
3057 struct hecmw_io_element *elem;
3058
3059 HECMW_assert(mesh);
3060
3061 for (i = 0; i < mesh->n_elem; i++) {
3062 /* depends on setup_elem() */
3063 if (mesh->elem_type[i] < 1000) continue;
3064 if (mesh->elem_type[i] >= 1100) continue;
3065 elem = HECMW_io_get_elem(mesh->global_elem_ID[i]);
3066 HECMW_assert(elem);
3067 HECMW_assert(elem->mpc_sectid != -1);
3068 mesh->section_ID[i] = elem->mpc_sectid;
3069 }
3070 return 0;
3071 }
3072
3073 /*----------------------------------------------------------------------------*/
3074
post_remove_unused_node(void)3075 static int post_remove_unused_node(void) {
3076 int id;
3077
3078 HECMW_assert(_node);
3079
3080 /* used nodes have been marked in post_elem_check_node_existence() */
3081
3082 HECMW_map_int_iter_init(_node);
3083 while (HECMW_map_int_iter_next_unmarked(_node, &id, NULL)) {
3084 /* remove from NODE GROUP */
3085 if (HECMW_io_remove_node_in_ngrp(id) < 0) {
3086 return -1;
3087 }
3088 }
3089
3090 HECMW_map_int_del_unmarked(_node);
3091
3092 return 0;
3093 }
3094
post_node(void)3095 static int post_node(void) {
3096 int n_dup;
3097
3098 if (_node == NULL || HECMW_map_int_nval(_node) == 0) {
3099 set_err(HECMW_IO_E1014, "");
3100 return -1;
3101 }
3102
3103 n_dup = HECMW_map_int_check_dup(_node);
3104 if (n_dup > 0) {
3105 set_warn(HECMW_IO_W1004, "%d node(s) updated", n_dup);
3106 }
3107
3108 return 0;
3109 }
3110
post_elem_check_node_existence(void)3111 static int post_elem_check_node_existence(void) {
3112 int i, j, ncon, id;
3113 struct hecmw_io_element *p;
3114
3115 HECMW_assert(global_node_ID_max > 0);
3116
3117 if (HECMW_map_int_mark_init(_node)) {
3118 return -1;
3119 }
3120
3121 HECMW_map_int_iter_init(_elem);
3122 for (i = 0; HECMW_map_int_iter_next(_elem, &id, (void **)&p); i++) {
3123 ncon = HECMW_get_max_node(p->type);
3124
3125 HECMW_assert(ncon > 0);
3126
3127 for (j = 0; j < ncon; j++) {
3128 HECMW_assert(p->node[j] > 0);
3129 HECMW_assert(p->node[j] <= global_node_ID_max);
3130
3131 if (HECMW_map_int_mark(_node, p->node[j])) {
3132 set_err(HECMW_IO_E1027, "Node %d does not exist", p->node[j]);
3133 return -1;
3134 }
3135 }
3136 }
3137
3138 return 0;
3139 }
3140
post_elem_make_matname(int id,char * buf,int bufsize)3141 static char *post_elem_make_matname(int id, char *buf, int bufsize) {
3142 const char *matname = "HECMW-MAT";
3143
3144 HECMW_assert(buf);
3145 HECMW_assert(bufsize > 0);
3146
3147 sprintf(buf, "%s%d", matname, id);
3148
3149 return buf;
3150 }
3151
post_elem_make_mat(void)3152 static int post_elem_make_mat(void) {
3153 int i, j, id;
3154 char name[HECMW_NAME_LEN + 1];
3155 struct hecmw_io_element *p;
3156 struct hecmw_io_material *mat;
3157 struct hecmw_io_matitem *matitem;
3158 struct hecmw_io_matsubitem *matsubitem;
3159
3160 HECMW_map_int_iter_init(_elem);
3161 for (i = 0; HECMW_map_int_iter_next(_elem, &id, (void **)&p); i++) {
3162 if (p->nmatitem <= 0) continue;
3163
3164 mat = HECMW_malloc(sizeof(*mat));
3165 if (mat == NULL) {
3166 set_err(errno, "");
3167 return -1;
3168 }
3169
3170 matitem = HECMW_malloc(sizeof(*matitem));
3171 if (matitem == NULL) {
3172 set_err(errno, "");
3173 return -1;
3174 }
3175
3176 matsubitem = HECMW_malloc(sizeof(*matsubitem));
3177 if (matsubitem == NULL) {
3178 set_err(errno, "");
3179 return -1;
3180 }
3181
3182 matsubitem->val = HECMW_malloc(sizeof(*matsubitem->val) * p->nmatitem);
3183 if (matsubitem->val == NULL) {
3184 set_err(errno, "");
3185 return -1;
3186 }
3187
3188 for (j = 0; j < p->nmatitem; j++) {
3189 matsubitem->val[j] = p->matitem[j];
3190 }
3191 matsubitem->temp = 0.0;
3192 matsubitem->next = NULL;
3193
3194 matitem->item = 1;
3195 matitem->nval = p->nmatitem;
3196 matitem->subitem = matsubitem;
3197
3198 mat->nitem = 1;
3199 mat->item = matitem;
3200 post_elem_make_matname(id, name, sizeof(name));
3201 strcpy(p->matname, name);
3202 strcpy(mat->name, name);
3203 mat->next = NULL;
3204
3205 if (HECMW_io_add_mat(name, mat) == NULL) return -1;
3206 }
3207 return 0;
3208 }
3209
post_elem(void)3210 static int post_elem(void) {
3211 int n_dup;
3212
3213 if (_elem == NULL) {
3214 set_err(HECMW_IO_E1015, "");
3215 return -1;
3216 }
3217
3218 n_dup = HECMW_map_int_check_dup(_elem);
3219 if (n_dup > 0) {
3220 set_warn(HECMW_IO_W1001, "%d element(s) updated", n_dup);
3221 }
3222
3223 if (post_elem_check_node_existence()) return -1;
3224
3225 if (post_elem_make_mat()) return -1;
3226
3227 return 0;
3228 }
3229
post_ngrp(void)3230 static int post_ngrp(void) {
3231 struct hecmw_io_ngrp *p;
3232
3233 for (p = _ngrp; p; p = p->next) {
3234 int n_dup, id, i;
3235
3236 n_dup = HECMW_set_int_check_dup(p->node);
3237 if (n_dup > 0) set_warn(HECMW_IO_W1006, "%d node(s) in %s", n_dup, p->name);
3238
3239 HECMW_set_int_iter_init(p->node);
3240 for (i = 0; HECMW_set_int_iter_next(p->node, &id); i++) {
3241 if (HECMW_io_get_node(id) == NULL) {
3242 set_warn(HECMW_IO_W1005, "Node %d doesn't exist", id);
3243 HECMW_set_int_del(p->node, id);
3244 }
3245 }
3246 }
3247 return 0;
3248 }
3249
post_egrp(void)3250 static int post_egrp(void) {
3251 struct hecmw_io_egrp *p;
3252
3253 for (p = _egrp; p; p = p->next) {
3254 int n_dup, id, i;
3255
3256 n_dup = HECMW_set_int_check_dup(p->elem);
3257 if (n_dup > 0)
3258 set_warn(HECMW_IO_W1003, "%d element(s) in %s", n_dup, p->name);
3259
3260 HECMW_set_int_iter_init(p->elem);
3261 for (i = 0; HECMW_set_int_iter_next(p->elem, &id); i++) {
3262 if (HECMW_io_get_elem(id) == NULL) {
3263 set_warn(HECMW_IO_W1002, "Element %d doesn't exist", id);
3264 HECMW_set_int_del(p->elem, id);
3265 }
3266 }
3267 }
3268 return 0;
3269 }
3270
post_sgrp(void)3271 static int post_sgrp(void) {
3272 struct hecmw_io_sgrp *p;
3273
3274 for (p = _sgrp; p; p = p->next) {
3275 int n_dup, id, i;
3276
3277 n_dup = HECMW_set_int_check_dup(p->item);
3278 if (n_dup > 0)
3279 set_warn(HECMW_IO_W1009, "%d surface(s) in %s", n_dup, p->name);
3280
3281 HECMW_set_int_iter_init(p->item);
3282 for (i = 0; HECMW_set_int_iter_next(p->item, &id); i++) {
3283 int eid, sid;
3284 struct hecmw_io_element *element;
3285
3286 decode_surf_key(id, &eid, &sid);
3287
3288 /* check element */
3289 element = HECMW_io_get_elem(eid);
3290 if (element == NULL) {
3291 set_warn(HECMW_IO_W1007, "Element %d doesn't exist", eid);
3292 HECMW_set_int_del(p->item, id);
3293 continue;
3294 }
3295
3296 /* check surface */
3297 if (HECMW_get_max_surf(element->type) < sid) {
3298 set_warn(HECMW_IO_W1008, "Element %d, surface %d", eid, sid);
3299 HECMW_set_int_del(p->item, id);
3300 }
3301 }
3302 }
3303 return 0;
3304 }
3305
post_initial_check_node_exists(void)3306 static int post_initial_check_node_exists(void) {
3307 int ignore;
3308 struct hecmw_io_initial *p, *prev, *next;
3309
3310 if (_init == NULL) return 0;
3311
3312 /* check node existence */
3313 prev = NULL;
3314 for (p = _init; p; p = next) {
3315 next = p->next;
3316 if (p->node == -1) {
3317 if (prev) {
3318 prev->next = p;
3319 }
3320 prev = p;
3321 continue;
3322 }
3323
3324 ignore = 0;
3325 if (HECMW_io_get_node(p->node) == NULL) {
3326 set_warn(HECMW_IO_W1016, "Node %d does not eixist", p->node);
3327 ignore = 1;
3328 }
3329 if (ignore) {
3330 HECMW_free(p);
3331 if (prev == NULL) {
3332 _init = next;
3333 } else {
3334 prev->next = next;
3335 }
3336 } else {
3337 if (prev == NULL) {
3338 _init = p;
3339 } else {
3340 prev->next = p;
3341 }
3342 prev = p;
3343 }
3344 }
3345 return 0;
3346 }
3347
post_initial_ngrp_to_node(void)3348 static int post_initial_ngrp_to_node(void) {
3349 int i, nnode, ignore, *node;
3350 struct hecmw_io_initial *p, *prev, *next, *new_init;
3351 struct hecmw_io_id_array *id;
3352
3353 if (_init == NULL) return 0;
3354
3355 /* change ngrp to node */
3356 prev = NULL;
3357 for (p = _init; p; p = next) {
3358 next = p->next;
3359 if (p->node != -1) {
3360 if (prev) {
3361 prev->next = p;
3362 }
3363 prev = p;
3364 continue;
3365 }
3366
3367 /* check existence */
3368 ignore = 0;
3369 if (HECMW_io_get_ngrp(p->ngrp) == NULL) {
3370 set_warn(HECMW_IO_W1017, "Node group %s does not eixist", p->ngrp);
3371 ignore = 1;
3372 }
3373 if (ignore) {
3374 HECMW_free(p);
3375 if (prev == NULL) {
3376 _init = next;
3377 } else {
3378 prev->next = next;
3379 }
3380 continue;
3381 }
3382
3383 /* check # of node in node group */
3384 ignore = 0;
3385 nnode = HECMW_io_get_nnode_in_ngrp(p->ngrp);
3386 HECMW_assert(nnode > 0);
3387
3388 /* replace by node */
3389 id = HECMW_io_get_node_in_ngrp(p->ngrp);
3390 HECMW_assert(id);
3391 HECMW_assert(id->n == nnode);
3392 node = id->id;
3393 HECMW_free(id);
3394
3395 for (i = 0; i < nnode; i++) {
3396 new_init = HECMW_malloc(sizeof(*new_init));
3397 if (new_init == NULL) {
3398 set_err(errno, "");
3399 return -1;
3400 }
3401 memcpy(new_init, p, sizeof(*new_init));
3402 new_init->next = NULL;
3403 new_init->node = node[i];
3404
3405 if (prev == NULL) {
3406 _init = new_init;
3407 } else {
3408 prev->next = new_init;
3409 }
3410 prev = new_init;
3411 }
3412
3413 HECMW_free(node);
3414 HECMW_free(p);
3415 }
3416 return 0;
3417 }
3418
post_initial_check_dup(void)3419 static int post_initial_check_dup(void) {
3420 struct hecmw_io_initial *p;
3421 struct hecmw_set_int set;
3422 int ndup;
3423
3424 if (_init == NULL) return 0;
3425
3426 HECMW_set_int_init(&set);
3427
3428 /* check duplication */
3429 for (p = _init; p; p = p->next) {
3430 HECMW_set_int_add(&set, p->node);
3431 }
3432 ndup = HECMW_set_int_check_dup(&set);
3433
3434 HECMW_set_int_finalize(&set);
3435
3436 if (ndup > 0) {
3437 set_err(HECMW_IO_E1018, "Some nodes are initialized more than once");
3438 return -1;
3439 }
3440 return 0;
3441 }
3442
post_initial(void)3443 static int post_initial(void) {
3444 if (_init == NULL) return 0;
3445
3446 if (post_initial_check_node_exists()) return -1;
3447 HECMW_log(HECMW_LOG_DEBUG, "post_initial_check_node_exists done");
3448 if (post_initial_ngrp_to_node()) return -1;
3449 HECMW_log(HECMW_LOG_DEBUG, "post_initial_ngrp_to_node done");
3450 if (post_initial_check_dup()) return -1;
3451 HECMW_log(HECMW_LOG_DEBUG, "post_initial_check_dup done");
3452
3453 return 0;
3454 }
3455
post_equation_check_node_exists(void)3456 static int post_equation_check_node_exists(void) {
3457 int i, ignore;
3458 struct hecmw_io_mpc *p, *prev, *next;
3459
3460 if (_mpc == NULL) return 0;
3461
3462 /* check node existence */
3463 prev = NULL;
3464 for (p = _mpc; p; p = next) {
3465 next = p->next;
3466 if (p->item[0].node == -1) {
3467 if (prev) {
3468 prev->next = p;
3469 }
3470 prev = p;
3471 continue;
3472 }
3473
3474 ignore = 0;
3475 HECMW_assert(p->neq >= 2);
3476 for (i = 0; i < p->neq; i++) {
3477 struct hecmw_io_mpcitem *item = &p->item[i];
3478 if (HECMW_io_get_node(item->node) == NULL) {
3479 set_warn(HECMW_IO_W1019, "Node %d not found", item->node);
3480 ignore = 1;
3481 break;
3482 }
3483 }
3484 if (ignore) {
3485 HECMW_free(p->item);
3486 HECMW_free(p);
3487 if (prev == NULL) {
3488 _mpc = next;
3489 } else {
3490 prev->next = next;
3491 }
3492 continue;
3493 }
3494 }
3495 return 0;
3496 }
3497
post_equation_ngrp_to_node(void)3498 static int post_equation_ngrp_to_node(void) {
3499 int i, j, ignore, **node;
3500 struct hecmw_io_mpc *p, *prev, *next, *new_mpc;
3501
3502 if (_mpc == NULL) return 0;
3503
3504 /* change ngrp to node */
3505 prev = NULL;
3506 for (p = _mpc; p; p = next) {
3507 int nnode;
3508 next = p->next;
3509 if (p->item[0].node != -1) {
3510 if (prev) {
3511 prev->next = p;
3512 }
3513 prev = p;
3514 continue;
3515 }
3516
3517 /* check existence */
3518 ignore = 0;
3519 HECMW_assert(p->neq >= 2);
3520 for (i = 0; i < p->neq; i++) {
3521 struct hecmw_io_mpcitem *item = &p->item[i];
3522 HECMW_assert(item->node == -1);
3523 if (HECMW_io_get_ngrp(item->ngrp) == NULL) {
3524 set_warn(HECMW_IO_W1020, "Node group %s not found", item->ngrp);
3525 ignore = 1;
3526 break;
3527 }
3528 }
3529 if (ignore) {
3530 HECMW_free(p->item);
3531 HECMW_free(p);
3532 if (prev == NULL) {
3533 _mpc = next;
3534 } else {
3535 prev->next = next;
3536 }
3537 continue;
3538 }
3539
3540 /* check # of node in node group */
3541 ignore = 0;
3542 nnode = HECMW_io_get_nnode_in_ngrp(p->item[0].ngrp);
3543 HECMW_assert(nnode > 0);
3544 for (i = 1; i < p->neq; i++) {
3545 struct hecmw_io_mpcitem *item = &p->item[i];
3546 int n = HECMW_io_get_nnode_in_ngrp(item->ngrp);
3547 if (n != nnode) {
3548 set_err(HECMW_IO_E1021, "%d node%s in %s, %d node%s in %s", nnode,
3549 (nnode != 0) ? "s" : "", p->item[0].ngrp, n,
3550 (n != 0) ? "s" : "", p->item[i].ngrp);
3551 return -1;
3552 }
3553 }
3554
3555 /* replace by node */
3556 node = HECMW_malloc(sizeof(node) * p->neq);
3557 if (node == NULL) {
3558 set_err(errno, "");
3559 return -1;
3560 }
3561
3562 for (i = 0; i < p->neq; i++) {
3563 struct hecmw_io_id_array *id = HECMW_io_get_node_in_ngrp(p->item[i].ngrp);
3564 HECMW_assert(id);
3565 HECMW_assert(id->n == nnode);
3566 node[i] = id->id;
3567 HECMW_free(id);
3568 }
3569
3570 for (i = 0; i < nnode; i++) {
3571 new_mpc = HECMW_malloc(sizeof(*new_mpc));
3572 if (new_mpc == NULL) {
3573 set_err(errno, "");
3574 return -1;
3575 }
3576 memcpy(new_mpc, p, sizeof(*new_mpc));
3577 new_mpc->next = NULL;
3578 new_mpc->item = NULL;
3579
3580 new_mpc->item = HECMW_malloc(sizeof(*new_mpc->item) * (p->neq));
3581 if (new_mpc == NULL) {
3582 set_err(errno, "");
3583 return -1;
3584 }
3585
3586 for (j = 0; j < new_mpc->neq; j++) {
3587 struct hecmw_io_mpcitem *item = &new_mpc->item[j];
3588 item->node = node[j][i];
3589 item->dof = p->item[j].dof;
3590 item->a = p->item[j].a;
3591 }
3592
3593 if (prev == NULL) {
3594 _mpc = new_mpc;
3595 } else {
3596 prev->next = new_mpc;
3597 }
3598 prev = new_mpc;
3599 }
3600
3601 for (i = 0; i < p->neq; i++) {
3602 HECMW_free(node[i]);
3603 }
3604 HECMW_free(node);
3605
3606 HECMW_free(p->item);
3607 HECMW_free(p);
3608 }
3609 return 0;
3610 }
3611
3612 /*
3613 * must be node(not allow ngrp)
3614 */
post_equation_check_dup(void)3615 static int post_equation_check_dup(void) {
3616 int i;
3617 struct hecmw_io_mpc *p, *q;
3618
3619 if (_mpc == NULL) return 0;
3620
3621 /* check duplication */
3622 for (p = _mpc; p; p = p->next) {
3623 int nod = p->item[0].node;
3624 int dof = p->item[0].dof;
3625 for (q = _mpc; q; q = q->next) {
3626 HECMW_assert(q->neq >= 2);
3627 for (i = 1; i < q->neq; i++) {
3628 HECMW_assert(q->item[i].node != -1);
3629 if (q->item[i].node == nod && q->item[i].dof == dof) {
3630 set_err(HECMW_IO_E1022, "Node:%d and DOF:%d", nod, dof);
3631 return -1;
3632 }
3633 }
3634 }
3635 }
3636 return 0;
3637 }
3638
post_equation_add_elem(void)3639 static int post_equation_add_elem(void) {
3640 int i, j, mpc_id, elem_id, dof1, dof2, type;
3641 int node[2];
3642 struct hecmw_io_mpc *p;
3643 struct hecmw_io_element *elem;
3644
3645 if (_mpc == NULL) return 0;
3646
3647 /* max element ID */
3648 elem_id = HECMW_io_get_elem_max_id();
3649 elem_id++;
3650
3651 /* add element */
3652 for (p = _mpc, mpc_id = 1; p; p = p->next, mpc_id++) {
3653 HECMW_assert(p->neq >= 2);
3654 for (j = 0; j < p->neq - 1; j++) {
3655 dof1 = p->item[j].dof;
3656 for (i = j + 1; i < p->neq; i++) {
3657 dof2 = p->item[i].dof;
3658 /* make element type */
3659 type = 900 + dof1 * 10 + dof2;
3660 HECMW_assert(HECMW_get_max_node(type) == 2);
3661
3662 /* set node */
3663 node[0] = p->item[j].node;
3664 node[1] = p->item[i].node;
3665
3666 /* add */
3667 elem = HECMW_io_add_elem(elem_id, type, node, 0, NULL);
3668 if (elem == NULL) {
3669 return -1;
3670 }
3671
3672 elem->mpc_matid = (j + 1) * 10 + (i + 1);
3673 elem->mpc_sectid = mpc_id;
3674
3675 if (HECMW_io_add_egrp("ALL", 1, &elem_id) < 0) {
3676 return -1;
3677 }
3678 elem_id++;
3679 }
3680 }
3681 }
3682 return 0;
3683 }
3684
post_equation(void)3685 static int post_equation(void) {
3686 if (_mpc == NULL) return 0;
3687
3688 if (post_equation_check_node_exists()) return -1;
3689 if (post_equation_ngrp_to_node()) return -1;
3690 /* Delete because performance grow worse at large number of equations
3691 if(post_equation_check_dup()) return -1;
3692 */
3693 if (post_equation_add_elem()) return -1;
3694
3695 return 0;
3696 }
3697
post_section_check_exists(void)3698 static int post_section_check_exists(void) {
3699 if (_sect == NULL) {
3700 set_err(HECMW_IO_E1023, "");
3701 return -1;
3702 }
3703 return 0;
3704 }
3705
post_section_check_egrp(void)3706 static int post_section_check_egrp(void) {
3707 int i, eid;
3708 struct hecmw_io_section *p;
3709
3710 for (p = _sect; p; p = p->next) {
3711 struct hecmw_io_egrp *egrp = HECMW_io_get_egrp(p->egrp);
3712
3713 if (egrp == NULL) {
3714 set_err(HECMW_IO_E1024, "Element gorup %s not found", p->egrp);
3715 goto error;
3716 }
3717
3718 HECMW_set_int_iter_init(egrp->elem);
3719 for (i = 0; HECMW_set_int_iter_next(egrp->elem, &eid); i++) {
3720 struct hecmw_io_element *elem = HECMW_io_get_elem(eid);
3721
3722 HECMW_assert(elem);
3723
3724 if (HECMW_is_etype_link(elem->type)) continue;
3725
3726 switch (p->type) {
3727 case HECMW_SECT_TYPE_SHELL:
3728 if (!HECMW_is_etype_shell(elem->type)) {
3729 set_err(HECMW_IO_E1026, "Only shell element allowed in EGRP %s",
3730 p->egrp);
3731 goto error;
3732 }
3733 break;
3734 case HECMW_SECT_TYPE_SOLID:
3735 if (!HECMW_is_etype_solid(elem->type)) {
3736 set_err(HECMW_IO_E1026, "Only solid element allowed in EGRP %s",
3737 p->egrp);
3738 goto error;
3739 }
3740 break;
3741 case HECMW_SECT_TYPE_BEAM:
3742 if (!HECMW_is_etype_beam(elem->type)) {
3743 set_err(HECMW_IO_E1026, "Only beam element allowed in EGRP %s",
3744 p->egrp);
3745 goto error;
3746 }
3747 break;
3748 case HECMW_SECT_TYPE_INTERFACE:
3749 if (!HECMW_is_etype_interface(elem->type)) {
3750 set_err(HECMW_IO_E1026, "Only interface element allowed in EGRP %s",
3751 p->egrp);
3752 goto error;
3753 }
3754 break;
3755 default:
3756 HECMW_assert(0);
3757 }
3758 }
3759 }
3760 return 0;
3761 error:
3762 return -1;
3763 }
3764
post_section_check_mat_exists(void)3765 static int post_section_check_mat_exists(void) {
3766 int found;
3767 struct hecmw_io_section *p;
3768 struct hecmw_io_material *mat;
3769 extern hecmw_hash_p *hash_mat;
3770
3771 for (p = _sect; p; p = p->next) {
3772 found = 0;
3773 /* for(mat=_mat; mat; mat=mat->next) {
3774 if(strcmp(p->material, mat->name) == 0) {
3775 found = 1;
3776 break;
3777 }
3778 }*/
3779 if ((struct hecmw_io_material *)hecmw_hash_p_get(hash_mat, p->material) !=
3780 NULL) {
3781 found = 1;
3782 }
3783 if (p->type != HECMW_SECT_TYPE_INTERFACE && !found) {
3784 set_err(HECMW_IO_E1025, "MATERIAL %s not found", p->material);
3785 return -1;
3786 }
3787 }
3788 return 0;
3789 }
3790
post_section(void)3791 static int post_section(void) {
3792 if (post_section_check_exists()) return -1;
3793 if (post_section_check_egrp()) return -1;
3794 if (post_section_check_mat_exists()) return -1;
3795
3796 return 0;
3797 }
3798
post_contact_check_grp(void)3799 static int post_contact_check_grp(void) {
3800 int i;
3801 struct hecmw_io_contact *p;
3802
3803 for (p = _contact; p; p = p->next) {
3804 struct hecmw_io_ngrp *ngrp;
3805 struct hecmw_io_sgrp *sgrp;
3806
3807 if (p->type == HECMW_CONTACT_TYPE_NODE_SURF) {
3808 ngrp = HECMW_io_get_ngrp(p->slave_grp);
3809 if (ngrp == NULL) {
3810 set_err(HECMW_IO_E1029, "Node gorup %s not found", p->slave_grp);
3811 goto error;
3812 }
3813 } else if (p->type == HECMW_CONTACT_TYPE_SURF_SURF) {
3814 sgrp = HECMW_io_get_sgrp(p->slave_grp);
3815 if (sgrp == NULL) {
3816 set_err(HECMW_IO_E1028, "Surface gorup %s not found", p->slave_grp);
3817 goto error;
3818 }
3819 } else {
3820 fprintf(stderr, "ERROR: CONTACT_PAIR: TYPE=%d\n", p->type);
3821 HECMW_assert(0);
3822 }
3823
3824 sgrp = HECMW_io_get_sgrp(p->master_grp);
3825 if (sgrp == NULL) {
3826 set_err(HECMW_IO_E1028, "Surface gorup %s not found", p->master_grp);
3827 goto error;
3828 }
3829 }
3830 return 0;
3831 error:
3832 return -1;
3833 }
3834
post_contact_convert_sgroup(void)3835 static int post_contact_convert_sgroup(void)
3836 {
3837 struct hecmw_io_contact *p;
3838 int elem_id, contact_id;
3839
3840 elem_id = HECMW_io_get_elem_max_id();
3841 elem_id++;
3842
3843 for (p = _contact, contact_id = 1; p; p = p->next, contact_id++) {
3844 struct hecmw_io_sgrp *sgrp;
3845 int n_item, i, id, ret;
3846 int *elem, *surf;
3847 char new_sgrp_name[HECMW_NAME_LEN+1];
3848
3849 if (p->type != HECMW_CONTACT_TYPE_SURF_SURF) continue;
3850
3851 sgrp = HECMW_io_get_sgrp(p->slave_grp);
3852 HECMW_assert(sgrp);
3853
3854 n_item = HECMW_set_int_nval(sgrp->item);
3855 if (n_item == 0) continue;
3856
3857 elem = (int *) malloc(sizeof(int) * n_item);
3858 surf = (int *) malloc(sizeof(int) * n_item);
3859 if (!elem || !surf) {
3860 set_err(errno, "");
3861 return -1;
3862 }
3863
3864 HECMW_set_int_iter_init(sgrp->item);
3865 for (i = 0; HECMW_set_int_iter_next(sgrp->item, &id); i++) {
3866 int eid, sid, etype, surf_etype, surf_nnode, j;
3867 struct hecmw_io_element *element, *ptelem;
3868 const int *surf_nodes;
3869 int nodes[8];
3870
3871 decode_surf_key(id, &eid, &sid);
3872
3873 element = HECMW_io_get_elem(eid);
3874 HECMW_assert(element);
3875 etype = element->type;
3876
3877 /* extract surface */
3878 surf_nodes = HECMW_get_surf_nodes(etype, sid, &surf_etype);
3879 HECMW_assert( HECMW_is_etype_patch(surf_etype) );
3880
3881 surf_nnode = HECMW_get_max_node(surf_etype);
3882
3883 for (j = 0; j < surf_nnode; j++) {
3884 nodes[j] = element->node[surf_nodes[j] - 1];
3885 }
3886
3887 /* add surface patch elem */
3888 ptelem = HECMW_io_add_elem(elem_id, surf_etype, nodes, 0, NULL);
3889 if (ptelem == NULL) {
3890 return -1;
3891 }
3892
3893 ptelem->mpc_matid = surf_etype % 100;
3894 ptelem->mpc_sectid = contact_id;
3895
3896 elem[i] = elem_id;
3897 surf[i] = 1;
3898
3899 elem_id++;
3900 }
3901
3902 /* add newly added patch elems to egrp "ALL" */
3903 if (HECMW_io_add_egrp("ALL", n_item, elem) < 0)
3904 return -1;
3905
3906 /* generate name for new sgrp with patch elems */
3907 ret = snprintf(new_sgrp_name, sizeof(new_sgrp_name), "_PT_%s", sgrp->name);
3908 if (ret >= sizeof(new_sgrp_name)) {
3909 set_err(HECMW_IO_E0001, "Surface group name: %s", sgrp->name);
3910 return -1;
3911 } else if (HECMW_io_get_sgrp(new_sgrp_name) != NULL) {
3912 set_err(HECMW_IO_E0003, "Surface group name: %s", new_sgrp_name);
3913 return -1;
3914 }
3915
3916 /* add sgrp with patch elems */
3917 if (HECMW_io_add_sgrp(new_sgrp_name, n_item, elem, surf) < 0)
3918 return -1;
3919
3920 free(elem);
3921 free(surf);
3922
3923 /* replace slave group by newly added sgrp with patch elems */
3924 strcpy(p->slave_grp, new_sgrp_name);
3925 }
3926 return 0;
3927 }
3928
post_contact(void)3929 static int post_contact(void) {
3930 if (post_contact_check_grp()) return -1;
3931 if (post_contact_convert_sgroup()) return -1;
3932
3933 return 0;
3934 }
3935
3936 /*----------------------------------------------------------------------------*/
3937
HECMW_io_check_mpc_dof(int dof)3938 int HECMW_io_check_mpc_dof(int dof) {
3939 if (dof < 1 || dof > 6) return -1;
3940 return 0;
3941 }
3942
HECMW_io_is_reserved_name(const char * name)3943 int HECMW_io_is_reserved_name(const char *name) {
3944 if (name == NULL) return 0;
3945 if (strncmp("HECMW", name, 5) == 0) return 1;
3946 return 0;
3947 }
3948
HECMW_io_get_version(void)3949 int HECMW_io_get_version(void) { return HECMW_FLAG_VERSION; }
3950
HECMW_hash_init(void)3951 int HECMW_hash_init(void) {
3952 extern hecmw_hash_p *hash_ng;
3953 extern hecmw_hash_p *hash_eg;
3954 extern hecmw_hash_p *hash_sg;
3955 extern hecmw_hash_p *hash_mat;
3956
3957 hash_ng = hecmw_hash_p_new(1);
3958 if (hash_ng == NULL) return 1;
3959 hash_eg = hecmw_hash_p_new(2);
3960 if (hash_eg == NULL) return 1;
3961 hash_sg = hecmw_hash_p_new(3);
3962 if (hash_sg == NULL) return 1;
3963 hash_mat = hecmw_hash_p_new(4);
3964 if (hash_mat == NULL) return 1;
3965
3966 return 0;
3967 }
3968
HECMW_hash_finalize(void)3969 int HECMW_hash_finalize(void) {
3970 extern hecmw_hash_p *hash_ng;
3971 extern hecmw_hash_p *hash_eg;
3972 extern hecmw_hash_p *hash_sg;
3973 extern hecmw_hash_p *hash_mat;
3974
3975 hecmw_hash_p_delete(hash_ng);
3976 hecmw_hash_p_delete(hash_eg);
3977 hecmw_hash_p_delete(hash_sg);
3978 hecmw_hash_p_delete(hash_mat);
3979
3980 return 0;
3981 }
3982
HECMW_io_init(void)3983 int HECMW_io_init(void) {
3984 HECMW_log(HECMW_LOG_DEBUG, "Initializing IO process...");
3985
3986 if (HECMW_hash_init()) {
3987 printf("ERROE:HECMW_HASHTABLE INIT \n");
3988 return -1;
3989 }
3990 if (clear()) {
3991 return -1;
3992 }
3993
3994 return 0;
3995 }
3996
HECMW_io_finalize(void)3997 int HECMW_io_finalize(void) {
3998 HECMW_log(HECMW_LOG_DEBUG, "Finalizing IO process...");
3999
4000 if (HECMW_hash_finalize()) {
4001 printf("ERROE:HECMW_HASHTABLE FINALIZE \n");
4002 return -1;
4003 }
4004 if (clear()) {
4005 return -1;
4006 }
4007
4008 return 0;
4009 }
4010
HECMW_io_pre_process(void)4011 int HECMW_io_pre_process(void) { return 0; }
4012
HECMW_io_post_process(void)4013 int HECMW_io_post_process(void) {
4014 HECMW_log(HECMW_LOG_DEBUG, "Running post process...");
4015
4016 if (post_node()) goto error;
4017 HECMW_log(HECMW_LOG_DEBUG, "post_node done");
4018 if (post_elem()) goto error;
4019 HECMW_log(HECMW_LOG_DEBUG, "post_elem done");
4020 if (post_ngrp()) goto error;
4021 HECMW_log(HECMW_LOG_DEBUG, "post_ngrp done");
4022 if (post_egrp()) goto error;
4023 HECMW_log(HECMW_LOG_DEBUG, "post_egrp done");
4024 if (post_sgrp()) goto error;
4025 HECMW_log(HECMW_LOG_DEBUG, "post_sgrp done");
4026 if (post_remove_unused_node()) goto error;
4027 HECMW_log(HECMW_LOG_DEBUG, "post_remove_unused_node done");
4028 if (post_initial()) goto error;
4029 HECMW_log(HECMW_LOG_DEBUG, "post_initial done");
4030 if (post_equation()) goto error;
4031 HECMW_log(HECMW_LOG_DEBUG, "post_equation done");
4032 if (post_section()) goto error;
4033 HECMW_log(HECMW_LOG_DEBUG, "post_section done");
4034 if (post_contact()) goto error;
4035 HECMW_log(HECMW_LOG_DEBUG, "post_contact done");
4036 return 0;
4037 error:
4038 return -1;
4039 }
4040
HECMW_io_make_local_mesh(void)4041 struct hecmwST_local_mesh *HECMW_io_make_local_mesh(void) {
4042 struct hecmwST_local_mesh *mesh;
4043
4044 HECMW_log(HECMW_LOG_DEBUG, "Creating hecmwST_local_mesh...");
4045
4046 mesh = HECMW_calloc(1, sizeof(*mesh));
4047 if (mesh == NULL) {
4048 set_err(errno, "");
4049 goto error;
4050 }
4051
4052 if (setup_flags(mesh)) goto error;
4053 HECMW_log(HECMW_LOG_DEBUG, "setup_flags done");
4054 if (setup_gridfile(mesh)) goto error;
4055 HECMW_log(HECMW_LOG_DEBUG, "setup_gridfile done");
4056 if (setup_files(mesh)) goto error;
4057 HECMW_log(HECMW_LOG_DEBUG, "setup_files done");
4058 if (setup_header(mesh)) goto error;
4059 HECMW_log(HECMW_LOG_DEBUG, "setup_header done");
4060 if (setup_zero(mesh)) goto error;
4061 HECMW_log(HECMW_LOG_DEBUG, "setup_zero done");
4062 if (setup_node(mesh)) goto error;
4063 HECMW_log(HECMW_LOG_DEBUG, "setup_node done");
4064 if (setup_init(mesh)) goto error;
4065 HECMW_log(HECMW_LOG_DEBUG, "setup_init done");
4066 if (setup_elem(mesh)) goto error;
4067 HECMW_log(HECMW_LOG_DEBUG, "setup_elem done");
4068 if (setup_ngrp(mesh)) goto error;
4069 HECMW_log(HECMW_LOG_DEBUG, "setup_ngrp done");
4070 if (setup_egrp(mesh)) goto error;
4071 HECMW_log(HECMW_LOG_DEBUG, "setup_egrp done");
4072 if (setup_sgrp(mesh)) goto error;
4073 HECMW_log(HECMW_LOG_DEBUG, "setup_sgrp done");
4074 if (setup_pe(mesh)) goto error;
4075 HECMW_log(HECMW_LOG_DEBUG, "setup_pe done");
4076 if (setup_adapt(mesh)) goto error;
4077 HECMW_log(HECMW_LOG_DEBUG, "setup_adapt done");
4078 if (setup_refine(mesh)) goto error;
4079 HECMW_log(HECMW_LOG_DEBUG, "setup_refine done");
4080 if (setup_mpc(mesh)) goto error;
4081 HECMW_log(HECMW_LOG_DEBUG, "setup_mpc done");
4082 if (setup_amp(mesh)) goto error;
4083 HECMW_log(HECMW_LOG_DEBUG, "setup_amp done");
4084 if (setup_mat(mesh)) goto error;
4085 HECMW_log(HECMW_LOG_DEBUG, "setup_mat done");
4086 if (setup_sect(mesh)) goto error;
4087 HECMW_log(HECMW_LOG_DEBUG, "setup_sect done");
4088 if (setup_mpc_sectid(mesh)) goto error;
4089 HECMW_log(HECMW_LOG_DEBUG, "setup_mpc_sectid done");
4090 if (setup_contact_sectid(mesh)) goto error;
4091 HECMW_log(HECMW_LOG_DEBUG, "setup_contact_sectid done");
4092 if (setup_elem_check_sectid(mesh)) goto error;
4093 HECMW_log(HECMW_LOG_DEBUG, "setup_elem_check_sectid done");
4094 if (setup_elem_mat(mesh)) goto error;
4095 HECMW_log(HECMW_LOG_DEBUG, "setup_elem_mat done");
4096 if (setup_mpc_reorder(mesh)) goto error;
4097 HECMW_log(HECMW_LOG_DEBUG, "setup_mpc_reorder done");
4098 if (setup_contact(mesh)) goto error;
4099 HECMW_log(HECMW_LOG_DEBUG, "setup_contact done");
4100 return mesh;
4101 error:
4102 return NULL;
4103 }
4104