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