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