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