FrontISTR 5.2.0
Large-scale structural analysis program with finit element method
Loading...
Searching...
No Matches
hecmw_io_dist.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 <ctype.h>
10#include "hecmw_struct.h"
11#include "hecmw_util.h"
12#include "hecmw_dist_alloc.h"
13#include "hecmw_io_dist.h"
14
15#define FSCANF_RTC_TOO_SHORT (-10001)
16#define FSCNAF_RTC_EOF (-10002)
17
18#define COLS_INT_DEF 10
19#define COLS_DOUBLE_DEF 5
20#define COLS_TWO 2
21#define COLS_THREE 3
22
23#define FILE_MAGIC "!HECMW-DMD-ASCII"
24#define FILE_MAGIC_LEN (sizeof(FILE_MAGIC) - 1)
25#define HEADER_STRING "!HECMW-DMD-ASCII version="
26
27/* */
28/* get data */
29/* */
30
31/*----------------------------------------------------------------------------*/
32/* integer */
33/*----------------------------------------------------------------------------*/
34static int get_int(int *i, FILE *fp) {
35 int rtc;
36
37 rtc = fscanf(fp, "%d", i);
38 if (rtc < 1) {
40 return -1;
41 } else if (rtc == EOF) {
43 return -1;
44 } else {
45 return 0;
46 }
47}
48
49/*----------------------------------------------------------------------------*/
50/* double */
51/*----------------------------------------------------------------------------*/
52static int get_double(double *d, FILE *fp) {
53 int rtc;
54
55 rtc = fscanf(fp, "%lf", d);
56 if (rtc < 1) {
58 return -1;
59 } else if (rtc == EOF) {
61 return -1;
62 } else {
63 return 0;
64 }
65}
66
67/*----------------------------------------------------------------------------*/
68/* string */
69/*----------------------------------------------------------------------------*/
70static int get_string(char *s, int max, FILE *fp) {
71 int c, len;
72
73 while ((c = fgetc(fp)) != EOF && isspace(c))
74 ; /* skip */
75 if (c == EOF) {
77 return -1;
78 }
79 if (ungetc(c, fp) == EOF) {
81 return -1;
82 }
83 if (fgets(s, max, fp) == NULL) {
85 return -1;
86 }
87 len = strlen(s);
88 if (len == max - 1 && s[max - 2] != '\n') {
89 HECMW_set_error(HECMW_IO_E5004, "line too long");
90 return -1;
91 }
92 while (len > 0 && isspace(s[len - 1])) {
93 len--;
94 }
95 s[len] = '\0';
96
97 return strlen(s);
98}
99
100/*----------------------------------------------------------------------------*/
101/* HECMW_Comm */
102/*----------------------------------------------------------------------------*/
103static int get_comm(HECMW_Comm *i, FILE *fp) {
104 int rtc;
105
106 rtc = fscanf(fp, "%d", (int *)i);
107 if (rtc < 1) {
109 return -1;
110 } else if (rtc == EOF) {
112 return -1;
113 } else {
114 return 0;
115 }
116}
117
118/*----------------------------------------------------------------------------*/
119/* array ( int ) */
120/*----------------------------------------------------------------------------*/
121static int get_int_ary(int *ary, int n, FILE *fp) {
122 int rtc, i;
123
124 for (i = 0; i < n; i++) {
125 rtc = fscanf(fp, "%d", &ary[i]);
126 if (rtc < 1) {
128 return -1;
129 } else if (rtc == EOF) {
131 return -1;
132 }
133 }
134
135 return 0;
136}
137
138/*----------------------------------------------------------------------------*/
139/* array ( double ) */
140/*----------------------------------------------------------------------------*/
141static int get_double_ary(double *ary, int n, FILE *fp) {
142 int rtc, i;
143
144 for (i = 0; i < n; i++) {
145 rtc = fscanf(fp, "%lf", &ary[i]);
146 if (rtc < 1) {
148 return -1;
149 } else if (rtc == EOF) {
151 return -1;
152 }
153 }
154
155 return 0;
156}
157
158/*----------------------------------------------------------------------------*/
159/* array ( string ) */
160/*----------------------------------------------------------------------------*/
161static int get_string_ary(char **ary, int n, FILE *fp) {
162#define LINEBUF_SIZE 8096
163 int i;
164 char linebuf[LINEBUF_SIZE];
165
166 for (i = 0; i < n; i++) {
167 if (get_string(linebuf, sizeof(linebuf), fp) < 0) {
168 return -1;
169 }
170 if ((ary[i] = (char *)HECMW_strdup(linebuf)) == NULL) {
171 HECMW_set_error(errno, "");
172 return -1;
173 }
174 }
175
176 return 0;
177}
178
179/*============================================================================*/
180/* */
181/* check file type */
182/* */
183/*============================================================================*/
184static int is_hecmw_dist_file(FILE *fp) {
185 char filetype[FILE_MAGIC_LEN];
186
187 if (fread(filetype, FILE_MAGIC_LEN, 1, fp) != 1) {
189 return 0;
190 }
191 if (memcmp(filetype, FILE_MAGIC, FILE_MAGIC_LEN)) {
192 HECMW_set_error(HECMW_IO_E5005, "Not a HECMW-DIST ASCII file");
193 return 0;
194 }
195 return 1;
196}
197
198/*============================================================================*/
199/* */
200/* rewind FILE pointer */
201/* */
202/*============================================================================*/
203static int rewind_fp(FILE *fp) {
204 if (fseek(fp, 0L, SEEK_SET)) {
206 return -1;
207 }
208 return 0;
209}
210
211/*============================================================================*/
212/* */
213/* get header */
214/* */
215/*============================================================================*/
216static int get_header(FILE *fp) {
217 char header[HECMW_HEADER_LEN + 1];
218 int ver;
219
220 if (fgets(header, sizeof(header), fp) == NULL) {
222 return -1;
223 }
224 if (strlen(header) == sizeof(header) - 1 &&
225 header[strlen(header) - 2] != '\n') {
226 HECMW_set_error(HECMW_IO_E5004, "line too long");
227 return -1;
228 }
229 if (strncmp(header, HEADER_STRING, strlen(HEADER_STRING)) != 0) {
230 HECMW_set_error(HECMW_IO_E5005, "Not a HECMW-DIST file");
231 return -1;
232 }
233 if (sscanf(header + strlen(HEADER_STRING), "%d", &ver) != 1) {
234 HECMW_set_error(HECMW_IO_E5006, "Invalid version");
235 return -1;
236 }
237 return 0;
238}
239
240/*============================================================================*/
241/* */
242/* get global information */
243/* */
244/*============================================================================*/
245static int get_global_info(struct hecmwST_local_mesh *mesh, FILE *fp) {
246 int flag_header;
247
248 /* hecmw_flag_adapt */
249 if (get_int(&mesh->hecmw_flag_adapt, fp)) {
250 return -1;
251 }
252
253 /* hecmw_flag_initcon */
254 if (get_int(&mesh->hecmw_flag_initcon, fp)) {
255 return -1;
256 }
257
258 /* hecmw_flag_parttype */
259 if (get_int(&mesh->hecmw_flag_parttype, fp)) {
260 return -1;
261 }
262
263 /* hecmw_flag_partdepth */
264 if (get_int(&mesh->hecmw_flag_partdepth, fp)) {
265 return -1;
266 }
267
268 /* hecmw_flag_version */
269 if (get_int(&mesh->hecmw_flag_version, fp)) {
270 return -1;
271 }
272
273 /* hecmw_flag_partcontact */
274 if (mesh->hecmw_flag_version >= 4) {
275 if (get_int(&mesh->hecmw_flag_partcontact, fp)) {
276 return -1;
277 }
278 } else {
280 }
281
282 /* gridfile */
283 if (get_string(mesh->gridfile, sizeof(mesh->gridfile), fp) < 0) {
284 return -1;
285 }
286
287 /* hecmw_n_file */
288 if (get_int(&mesh->hecmw_n_file, fp)) {
289 return -1;
290 }
291
292 /* files */
293 if (mesh->hecmw_n_file > 0) {
294 if ((mesh->files = (char **)HECMW_calloc(mesh->hecmw_n_file,
295 sizeof(char *))) == NULL) {
296 HECMW_set_error(errno, "");
297 return -1;
298 }
299 if (get_string_ary(mesh->files, mesh->hecmw_n_file, fp)) {
300 return -1;
301 }
302 } else {
303 mesh->files = NULL;
304 }
305
306 /* flag for header */
307 if (get_int(&flag_header, fp)) {
308 return -1;
309 }
310
311 if (flag_header == 1) {
312 /* header */
313 if (get_string(mesh->header, sizeof(mesh->header), fp) < 0) {
314 return -1;
315 }
316 }
317
318 /* zero_temp */
319 if (get_double(&mesh->zero_temp, fp)) {
320 return -1;
321 }
322
323 return 0;
324}
325
326/*============================================================================*/
327/* */
328/* get node information */
329/* */
330/*============================================================================*/
331static int get_node_info(struct hecmwST_local_mesh *mesh, FILE *fp) {
332 /* n_node*/
333 if (get_int(&mesh->n_node, fp)) {
334 return -1;
335 }
336
337 if (mesh->hecmw_flag_version >= 2) {
338 /* n_node_gross*/
339 if (get_int(&mesh->n_node_gross, fp)) {
340 return -1;
341 }
342 } else {
344 }
345
346 if (mesh->hecmw_flag_version >= 4) {
347 /* nn_middle*/
348 if (get_int(&mesh->nn_middle, fp)) {
349 return -1;
350 }
351 } else {
353 }
354
355 /* nn_internal */
356 if (get_int(&mesh->nn_internal, fp)) {
357 return -1;
358 }
359
360 /* node_internal_list */
363 mesh->nn_internal > 0) {
365 (int *)HECMW_malloc(sizeof(double) * mesh->nn_internal);
366 if (mesh->node_internal_list == NULL) {
367 HECMW_set_error(errno, "");
368 return -1;
369 }
370 if (get_int_ary(mesh->node_internal_list, mesh->nn_internal, fp)) {
371 return -1;
372 }
373 }
374
375 if (mesh->n_node_gross > 0) {
376 /* node_ID */
377 mesh->node_ID = (int *)HECMW_malloc(sizeof(int) * mesh->n_node_gross * 2);
378 if (mesh->node_ID == NULL) {
379 HECMW_set_error(errno, "");
380 return -1;
381 }
382 if (get_int_ary(mesh->node_ID, mesh->n_node_gross * 2, fp)) {
383 return -1;
384 }
385
386 /* global_node_ID */
388 (int *)HECMW_malloc(sizeof(int) * mesh->n_node_gross);
389 if (mesh->global_node_ID == NULL) {
390 HECMW_set_error(errno, "");
391 return -1;
392 }
393 if (get_int_ary(mesh->global_node_ID, mesh->n_node_gross, fp)) {
394 return -1;
395 }
396
397 /* node */
398 mesh->node =
399 (double *)HECMW_malloc(sizeof(double) * mesh->n_node_gross * 3);
400 if (mesh->node == NULL) {
401 HECMW_set_error(errno, "");
402 return -1;
403 }
404 if (get_double_ary(mesh->node, mesh->n_node_gross * 3, fp)) {
405 return -1;
406 }
407 }
408
409 /* n_dof */
410 if (get_int(&mesh->n_dof, fp)) {
411 return -1;
412 }
413
414 /* n_dof_grp */
415 if (get_int(&mesh->n_dof_grp, fp)) {
416 return -1;
417 }
418
419 if (mesh->n_dof_grp > 0) {
420 /* node_dof_index */
422 (int *)HECMW_malloc(sizeof(int) * (mesh->n_dof_grp + 1));
423 if (mesh->node_dof_index == NULL) {
424 HECMW_set_error(errno, "");
425 return -1;
426 }
427 if (get_int_ary(mesh->node_dof_index, mesh->n_dof_grp + 1, fp)) {
428 return -1;
429 }
430
431 /* node_dof_item */
432 mesh->node_dof_item = (int *)HECMW_malloc(sizeof(int) * mesh->n_dof_grp);
433 if (mesh->node_dof_item == NULL) {
434 HECMW_set_error(errno, "");
435 return -1;
436 }
437 if (get_int_ary(mesh->node_dof_item, mesh->n_dof_grp, fp)) {
438 return -1;
439 }
440 }
441
443 /* node_init_val_index */
445 (int *)HECMW_malloc(sizeof(int) * (mesh->n_node_gross + 1));
446 if (mesh->node_init_val_index == NULL) {
447 HECMW_set_error(errno, "");
448 return -1;
449 }
450 if (get_int_ary(mesh->node_init_val_index, mesh->n_node_gross + 1, fp)) {
451 return -1;
452 }
453
454 /* node_init_val_item */
457 } else {
459 sizeof(double) * mesh->node_init_val_index[mesh->n_node_gross]);
460 if (mesh->node_init_val_item == NULL) {
461 HECMW_set_error(errno, "");
462 return -1;
463 }
464 if (get_double_ary(mesh->node_init_val_item,
466 return -1;
467 }
468 }
469 }
470
471 return 0;
472}
473
474/*============================================================================*/
475/* */
476/* get element information */
477/* */
478/*============================================================================*/
479static int get_elem_info(struct hecmwST_local_mesh *mesh, FILE *fp) {
480 /* n_elem */
481 if (get_int(&mesh->n_elem, fp)) {
482 return -1;
483 }
484
485 if (mesh->hecmw_flag_version >= 2) {
486 /* n_elem_gross */
487 if (get_int(&mesh->n_elem_gross, fp)) {
488 return -1;
489 }
490 } else {
492 }
493
494 /* ne_internal */
495 if (get_int(&mesh->ne_internal, fp)) {
496 return -1;
497 }
498
499 /* elem_internal_list */
502 mesh->ne_internal > 0) {
504 (int *)HECMW_malloc(sizeof(int) * mesh->ne_internal);
505 if (mesh->elem_internal_list == NULL) {
506 HECMW_set_error(errno, "");
507 return -1;
508 }
509 if (get_int_ary(mesh->elem_internal_list, mesh->ne_internal, fp)) {
510 return -1;
511 }
512 }
513
514 if (mesh->n_elem_gross > 0) {
515 /* elem_ID */
516 if ((mesh->elem_ID = (int *)HECMW_malloc(sizeof(int) * mesh->n_elem_gross *
517 2)) == NULL) {
518 HECMW_set_error(errno, "");
519 return -1;
520 }
521 if (get_int_ary(mesh->elem_ID, mesh->n_elem_gross * 2, fp)) {
522 return -1;
523 }
524
525 /* global_elem_ID */
526 if ((mesh->global_elem_ID =
527 (int *)HECMW_malloc(sizeof(int) * mesh->n_elem_gross)) == NULL) {
528 HECMW_set_error(errno, "");
529 return -1;
530 }
531 if (get_int_ary(mesh->global_elem_ID, mesh->n_elem_gross, fp)) {
532 return -1;
533 }
534
535 /* elem_type */
536 if ((mesh->elem_type =
537 (int *)HECMW_malloc(sizeof(int) * mesh->n_elem_gross)) == NULL) {
538 HECMW_set_error(errno, "");
539 return -1;
540 }
541 if (get_int_ary(mesh->elem_type, mesh->n_elem_gross, fp)) {
542 return -1;
543 }
544 }
545
546 /* n_elem_type */
547 if (get_int(&mesh->n_elem_type, fp)) {
548 return -1;
549 }
550
551 if (mesh->n_elem_type > 0) {
552 /* elem_type_index */
553 if ((mesh->elem_type_index = (int *)HECMW_malloc(
554 sizeof(int) * (mesh->n_elem_type + 1))) == NULL) {
555 HECMW_set_error(errno, "");
556 return -1;
557 }
558 if (get_int_ary(mesh->elem_type_index, mesh->n_elem_type + 1, fp)) {
559 return -1;
560 }
561
562 /* elem_type_item */
563 if ((mesh->elem_type_item =
564 (int *)HECMW_malloc(sizeof(int) * mesh->n_elem_type)) == NULL) {
565 HECMW_set_error(errno, "");
566 return -1;
567 }
568 if (get_int_ary(mesh->elem_type_item, mesh->n_elem_type, fp)) {
569 return -1;
570 }
571 }
572
573 if (mesh->n_elem_gross > 0) {
574 /* elem_node_index */
575 if ((mesh->elem_node_index = (int *)HECMW_malloc(
576 sizeof(int) * (mesh->n_elem_gross + 1))) == NULL) {
577 HECMW_set_error(errno, "");
578 return -1;
579 }
580 if (get_int_ary(mesh->elem_node_index, mesh->n_elem_gross + 1, fp)) {
581 return -1;
582 }
583
584 /* elem_node_item */
585 if ((mesh->elem_node_item = (int *)HECMW_malloc(
586 sizeof(int) * mesh->elem_node_index[mesh->n_elem_gross])) ==
587 NULL) {
588 HECMW_set_error(errno, "");
589 return -1;
590 }
591 if (get_int_ary(mesh->elem_node_item,
593 return -1;
594 }
595
596 /* section_ID */
597 if ((mesh->section_ID =
598 (int *)HECMW_malloc(sizeof(int) * mesh->n_elem_gross)) == NULL) {
599 HECMW_set_error(errno, "");
600 return -1;
601 }
602 if (get_int_ary(mesh->section_ID, mesh->n_elem_gross, fp)) {
603 return -1;
604 }
605
606 /* elem_mat_ID_index */
607 if ((mesh->elem_mat_ID_index = (int *)HECMW_malloc(
608 sizeof(int) * (mesh->n_elem_gross + 1))) == NULL) {
609 HECMW_set_error(errno, "");
610 return -1;
611 }
612 if (get_int_ary(mesh->elem_mat_ID_index, mesh->n_elem_gross + 1, fp)) {
613 return -1;
614 }
615
616 /* elem_mat_ID_item */
617 if ((mesh->elem_mat_ID_item = (int *)HECMW_malloc(
618 sizeof(int) * mesh->elem_mat_ID_index[mesh->n_elem_gross])) ==
619 NULL) {
620 HECMW_set_error(errno, "");
621 return -1;
622 }
623 if (get_int_ary(mesh->elem_mat_ID_item,
625 return -1;
626 }
627 }
628
629 /* n_elem_mat_ID */
630 if (get_int(&mesh->n_elem_mat_ID, fp)) {
631 return -1;
632 }
633
634 /* elem_mat_int_index */
635 /* elem_mat_int_item */
636
637 /* elem_val_index */
638 /* elem_val_item */
639
640 return 0;
641}
642
643/*============================================================================*/
644/* */
645/* get domain information & communication table */
646/* */
647/*============================================================================*/
648static int get_comm_info(struct hecmwST_local_mesh *mesh, FILE *fp) {
649 /* zero */
650 if (get_int(&mesh->zero, fp)) {
651 return -1;
652 }
653
654 /* HECMW_COMM */
655 if (get_comm(&mesh->HECMW_COMM, fp)) {
656 return -1;
657 }
658
659 /* PETOT */
660 if (get_int(&mesh->PETOT, fp)) {
661 return -1;
662 }
663
664 /* PEsmpTOT */
665 if (get_int(&mesh->PEsmpTOT, fp)) {
666 return -1;
667 }
668
669 /* my_rank */
670 if (get_int(&mesh->my_rank, fp)) {
671 return -1;
672 }
673
674 /* errnof */
675 if (get_int(&mesh->errnof, fp)) {
676 return -1;
677 }
678
679 /* n_subdomain */
680 if (get_int(&mesh->n_subdomain, fp)) {
681 return -1;
682 }
683
684 /* n_neighbor_pe */
685 if (get_int(&mesh->n_neighbor_pe, fp)) {
686 return -1;
687 }
688
689 if (mesh->n_neighbor_pe == 0) {
694
695 mesh->import_index = HECMW_malloc(sizeof(int));
696 if (mesh->import_index == NULL) {
697 HECMW_set_error(errno, "");
698 return -1;
699 }
700 mesh->import_index[0] = 0;
701
702 mesh->export_index = HECMW_malloc(sizeof(int));
703 if (mesh->export_index == NULL) {
704 HECMW_set_error(errno, "");
705 return -1;
706 }
707 mesh->export_index[0] = 0;
708
709 mesh->shared_index = HECMW_malloc(sizeof(int));
710 if (mesh->shared_index == NULL) {
711 HECMW_set_error(errno, "");
712 return -1;
713 }
714 mesh->shared_index[0] = 0;
715
716 return 0;
717 }
718
719 /* neighbor_pe */
720 if ((mesh->neighbor_pe =
721 (int *)HECMW_malloc(sizeof(int) * mesh->n_neighbor_pe)) == NULL) {
722 HECMW_set_error(errno, "");
723 return -1;
724 }
725 if (get_int_ary(mesh->neighbor_pe, mesh->n_neighbor_pe, fp)) {
726 return -1;
727 }
728
729 /* import_index */
730 if ((mesh->import_index = (int *)HECMW_malloc(
731 sizeof(int) * (mesh->n_neighbor_pe + 1))) == NULL) {
732 HECMW_set_error(errno, "");
733 return -1;
734 }
735 if (get_int_ary(mesh->import_index, mesh->n_neighbor_pe + 1, fp)) {
736 return -1;
737 }
738
739 /* import_item */
740 if ((mesh->import_item = (int *)HECMW_malloc(
741 sizeof(int) * mesh->import_index[mesh->n_neighbor_pe])) == NULL) {
742 HECMW_set_error(errno, "");
743 return -1;
744 }
745 if (get_int_ary(mesh->import_item, mesh->import_index[mesh->n_neighbor_pe],
746 fp)) {
747 return -1;
748 }
749
750 /* export_index */
751 if ((mesh->export_index = (int *)HECMW_malloc(
752 sizeof(int) * (mesh->n_neighbor_pe + 1))) == NULL) {
753 HECMW_set_error(errno, "");
754 return -1;
755 }
756 if (get_int_ary(mesh->export_index, mesh->n_neighbor_pe + 1, fp)) {
757 return -1;
758 }
759
760 /* export_item */
761 if ((mesh->export_item = (int *)HECMW_malloc(
762 sizeof(int) * mesh->export_index[mesh->n_neighbor_pe])) == NULL) {
763 HECMW_set_error(errno, "");
764 return -1;
765 }
766 if (get_int_ary(mesh->export_item, mesh->export_index[mesh->n_neighbor_pe],
767 fp)) {
768 return -1;
769 }
770
771 /* shared_index */
772 if ((mesh->shared_index = (int *)HECMW_malloc(
773 sizeof(int) * (mesh->n_neighbor_pe + 1))) == NULL) {
774 HECMW_set_error(errno, "");
775 return -1;
776 }
777 if (get_int_ary(mesh->shared_index, mesh->n_neighbor_pe + 1, fp)) {
778 return -1;
779 }
780
781 /* shared_item */
782 if ((mesh->shared_item = (int *)HECMW_malloc(
783 sizeof(int) * mesh->shared_index[mesh->n_neighbor_pe])) == NULL) {
784 HECMW_set_error(errno, "");
785 return -1;
786 }
787 if (get_int_ary(mesh->shared_item, mesh->shared_index[mesh->n_neighbor_pe],
788 fp)) {
789 return -1;
790 }
791
792 return 0;
793}
794
795/*============================================================================*/
796/* */
797/* get adaptation information */
798/* */
799/*============================================================================*/
800static int get_adapt_info(struct hecmwST_local_mesh *mesh, FILE *fp) {
801 if (mesh->hecmw_flag_adapt == 0) {
803 mesh->n_adapt = 0;
812 return 0;
813 }
814
815 /* coarse_grid_level */
816 if (get_int(&mesh->coarse_grid_level, fp)) {
817 return -1;
818 }
819
820 /* n_adapt */
821 if (get_int(&mesh->n_adapt, fp)) {
822 return -1;
823 }
824
825 if (mesh->n_node_gross > 0) {
826 /* when_i_was_refined_node */
828 (int *)HECMW_malloc(sizeof(int) * mesh->n_node_gross)) == NULL) {
829 HECMW_set_error(errno, "");
830 return -1;
831 }
832 if (get_int_ary(mesh->when_i_was_refined_node, mesh->n_node_gross, fp)) {
833 return -1;
834 }
835 }
836
837 if (mesh->n_elem_gross <= 0) return 0;
838
839 /* when_i_was_refined_elem */
841 (int *)HECMW_malloc(sizeof(int) * mesh->n_elem_gross)) == NULL) {
842 HECMW_set_error(errno, "");
843 return -1;
844 }
845 if (get_int_ary(mesh->when_i_was_refined_elem, mesh->n_elem_gross, fp)) {
846 return -1;
847 }
848
849 /* adapt_parent_type */
850 if ((mesh->adapt_parent_type =
851 (int *)HECMW_malloc(sizeof(int) * mesh->n_elem_gross)) == NULL) {
852 HECMW_set_error(errno, "");
853 return -1;
854 }
855 if (get_int_ary(mesh->adapt_parent_type, mesh->n_elem_gross, fp)) {
856 return -1;
857 }
858
859 /* adapt_type */
860 if ((mesh->adapt_type =
861 (int *)HECMW_malloc(sizeof(int) * mesh->n_elem_gross)) == NULL) {
862 HECMW_set_error(errno, "");
863 return -1;
864 }
865 if (get_int_ary(mesh->adapt_type, mesh->n_elem_gross, fp)) {
866 return -1;
867 }
868
869 /* adapt_level */
870 if ((mesh->adapt_level =
871 (int *)HECMW_malloc(sizeof(int) * mesh->n_elem_gross)) == NULL) {
872 HECMW_set_error(errno, "");
873 return -1;
874 }
875 if (get_int_ary(mesh->adapt_level, mesh->n_elem_gross, fp)) {
876 return -1;
877 }
878
879 /* adapt_parent */
880 if ((mesh->adapt_parent =
881 (int *)HECMW_malloc(sizeof(int) * mesh->n_elem_gross * 2)) == NULL) {
882 HECMW_set_error(errno, "");
883 return -1;
884 }
885 if (get_int_ary(mesh->adapt_parent, 2 * mesh->n_elem_gross, fp)) {
886 return -1;
887 }
888
889 /* adapt_children_index */
891 sizeof(int) * (mesh->n_elem_gross + 1))) == NULL) {
892 HECMW_set_error(errno, "");
893 return -1;
894 }
895 if (get_int_ary(mesh->adapt_children_index, mesh->n_elem_gross + 1, fp)) {
896 return -1;
897 }
898
899 /* adapt_children_item */
901 sizeof(int) * mesh->adapt_children_index[mesh->n_elem_gross] * 2)) ==
902 NULL) {
903 HECMW_set_error(errno, "");
904 return -1;
905 }
906 if (get_int_ary(mesh->adapt_children_item,
908 return -1;
909 }
910
911 return 0;
912}
913
914/*============================================================================*/
915/* */
916/* get section information */
917/* */
918/*============================================================================*/
919static int get_section_info(struct hecmwST_section *sect, FILE *fp) {
920 /* n_sect */
921 if (get_int(&sect->n_sect, fp)) {
922 return -1;
923 }
924
925 if (sect->n_sect == 0) {
926 sect->sect_type = NULL;
927 sect->sect_opt = NULL;
928 sect->sect_mat_ID_index = NULL;
929 sect->sect_mat_ID_item = NULL;
930 sect->sect_I_index = NULL;
931 sect->sect_I_item = NULL;
932 sect->sect_R_index = NULL;
933 sect->sect_R_item = NULL;
934 return 0;
935 }
936
937 /* sect_type */
938 if ((sect->sect_type = (int *)HECMW_malloc(sizeof(int) * sect->n_sect)) ==
939 NULL) {
940 HECMW_set_error(errno, "");
941 return -1;
942 }
943 if (get_int_ary(sect->sect_type, sect->n_sect, fp)) {
944 return -1;
945 }
946
947 /* sect_opt */
948 if ((sect->sect_opt = (int *)HECMW_malloc(sizeof(int) * sect->n_sect)) ==
949 NULL) {
950 HECMW_set_error(errno, "");
951 return -1;
952 }
953 if (get_int_ary(sect->sect_opt, sect->n_sect, fp)) {
954 return -1;
955 }
956
957 /* sect_mat_ID_index */
958 if ((sect->sect_mat_ID_index =
959 (int *)HECMW_malloc(sizeof(int) * (sect->n_sect + 1))) == NULL) {
960 HECMW_set_error(errno, "");
961 return -1;
962 }
963 if (get_int_ary(sect->sect_mat_ID_index, sect->n_sect + 1, fp)) {
964 return -1;
965 }
966
967 /* sect_mat_ID_item */
968 if (sect->sect_mat_ID_index[sect->n_sect] > 0) {
969 if ((sect->sect_mat_ID_item = (int *)HECMW_malloc(
970 sizeof(int) * sect->sect_mat_ID_index[sect->n_sect])) == NULL) {
971 HECMW_set_error(errno, "");
972 return -1;
973 }
974 if (get_int_ary(sect->sect_mat_ID_item,
975 sect->sect_mat_ID_index[sect->n_sect], fp)) {
976 return -1;
977 }
978 }
979
980 /* sect_I_index */
981 if ((sect->sect_I_index =
982 (int *)HECMW_malloc(sizeof(int) * (sect->n_sect + 1))) == NULL) {
983 HECMW_set_error(errno, "");
984 return -1;
985 }
986 if (get_int_ary(sect->sect_I_index, sect->n_sect + 1, fp)) {
987 return -1;
988 }
989
990 /* sect_I_item */
991 if (sect->sect_I_index[sect->n_sect] > 0) {
992 if ((sect->sect_I_item = (int *)HECMW_malloc(
993 sizeof(int) * sect->sect_I_index[sect->n_sect])) == NULL) {
994 HECMW_set_error(errno, "");
995 return -1;
996 }
997 if (get_int_ary(sect->sect_I_item, sect->sect_I_index[sect->n_sect], fp)) {
998 return -1;
999 }
1000 }
1001
1002 /* sect_R_index */
1003 if ((sect->sect_R_index =
1004 (int *)HECMW_malloc(sizeof(int) * (sect->n_sect + 1))) == NULL) {
1005 HECMW_set_error(errno, "");
1006 return -1;
1007 }
1008 if (get_int_ary(sect->sect_R_index, sect->n_sect + 1, fp)) {
1009 return -1;
1010 }
1011
1012 /* sect_R_item */
1013 if (sect->sect_R_index[sect->n_sect] > 0) {
1014 if ((sect->sect_R_item = (double *)HECMW_malloc(
1015 sizeof(double) * sect->sect_R_index[sect->n_sect])) == NULL) {
1016 HECMW_set_error(errno, "");
1017 return -1;
1018 }
1019 if (get_double_ary(sect->sect_R_item, sect->sect_R_index[sect->n_sect],
1020 fp)) {
1021 return -1;
1022 }
1023 }
1024
1025 return 0;
1026}
1027
1028/*============================================================================*/
1029/* */
1030/* get material information */
1031/* */
1032/*============================================================================*/
1033static int get_material_info(struct hecmwST_material *mat, FILE *fp) {
1034 /* n_mat */
1035 if (get_int(&mat->n_mat, fp)) {
1036 return -1;
1037 }
1038
1039 if (mat->n_mat == 0) {
1040 mat->n_mat_item = 0;
1041 mat->n_mat_subitem = 0;
1042 mat->n_mat_table = 0;
1043 mat->mat_name = NULL;
1044 mat->mat_item_index = NULL;
1045 mat->mat_subitem_index = NULL;
1046 mat->mat_table_index = NULL;
1047 mat->mat_val = NULL;
1048 mat->mat_temp = NULL;
1049 return 0;
1050 }
1051
1052 /* n_mat_item */
1053 if (get_int(&mat->n_mat_item, fp)) {
1054 return -1;
1055 }
1056
1057 /* n_mat_subitem */
1058 if (get_int(&mat->n_mat_subitem, fp)) {
1059 return -1;
1060 }
1061
1062 /* n_mat_table */
1063 if (get_int(&mat->n_mat_table, fp)) {
1064 return -1;
1065 }
1066
1067 /* mat_name */
1068 if ((mat->mat_name = (char **)HECMW_malloc(sizeof(char *) * mat->n_mat)) ==
1069 NULL) {
1070 HECMW_set_error(errno, "");
1071 return -1;
1072 }
1073 if (get_string_ary(mat->mat_name, mat->n_mat, fp)) {
1074 return -1;
1075 }
1076
1077 /* mat_item_index */
1078 if ((mat->mat_item_index =
1079 (int *)HECMW_malloc(sizeof(int) * (mat->n_mat + 1))) == NULL) {
1080 HECMW_set_error(errno, "");
1081 return -1;
1082 }
1083 if (get_int_ary(mat->mat_item_index, mat->n_mat + 1, fp)) {
1084 return -1;
1085 }
1086
1087 /* mat_subitem_index */
1088 if ((mat->mat_subitem_index =
1089 (int *)HECMW_malloc(sizeof(int) * (mat->n_mat_item + 1))) == NULL) {
1090 HECMW_set_error(errno, "");
1091 return -1;
1092 }
1093 if (get_int_ary(mat->mat_subitem_index, mat->n_mat_item + 1, fp)) {
1094 return -1;
1095 }
1096
1097 /* mat_table_index */
1098 if ((mat->mat_table_index = (int *)HECMW_malloc(
1099 sizeof(int) * (mat->n_mat_subitem + 1))) == NULL) {
1100 HECMW_set_error(errno, "");
1101 return -1;
1102 }
1103 if (get_int_ary(mat->mat_table_index, mat->n_mat_subitem + 1, fp)) {
1104 return -1;
1105 }
1106
1107 /* mat_val */
1108 if ((mat->mat_val =
1109 (double *)HECMW_malloc(sizeof(double) * mat->n_mat_table)) == NULL) {
1110 HECMW_set_error(errno, "");
1111 return -1;
1112 }
1113 if (get_double_ary(mat->mat_val, mat->n_mat_table, fp)) {
1114 return -1;
1115 }
1116
1117 /* mat_temp */
1118 if ((mat->mat_temp =
1119 (double *)HECMW_malloc(sizeof(double) * mat->n_mat_table)) == NULL) {
1120 HECMW_set_error(errno, "");
1121 return -1;
1122 }
1123 if (get_double_ary(mat->mat_temp, mat->n_mat_table, fp)) {
1124 return -1;
1125 }
1126
1127 return 0;
1128}
1129
1130/*============================================================================*/
1131/* */
1132/* get MPC group information */
1133/* */
1134/*============================================================================*/
1135static int get_mpc_info(struct hecmwST_mpc *mpc, FILE *fp,
1136 int hecmw_flag_version) {
1137 /* n_mpc */
1138 if (get_int(&mpc->n_mpc, fp)) {
1139 return -1;
1140 }
1141
1142 if (mpc->n_mpc == 0) {
1143 mpc->mpc_item = NULL;
1144 mpc->mpc_dof = NULL;
1145 mpc->mpc_val = NULL;
1146 mpc->mpc_index = HECMW_malloc(sizeof(int));
1147 if (mpc->mpc_index == NULL) {
1148 HECMW_set_error(errno, "");
1149 return -1;
1150 }
1151 mpc->mpc_index[0] = 0;
1152 return 0;
1153 }
1154
1155 /* mpc_index */
1156 if ((mpc->mpc_index = (int *)HECMW_malloc(sizeof(int) * (mpc->n_mpc + 1))) ==
1157 NULL) {
1158 HECMW_set_error(errno, "");
1159 return -1;
1160 }
1161 if (get_int_ary(mpc->mpc_index, mpc->n_mpc + 1, fp)) {
1162 return -1;
1163 }
1164
1165 /* mpc_item */
1166 if ((mpc->mpc_item = (int *)HECMW_malloc(
1167 sizeof(int) * mpc->mpc_index[mpc->n_mpc])) == NULL) {
1168 HECMW_set_error(errno, "");
1169 return -1;
1170 }
1171 if (get_int_ary(mpc->mpc_item, mpc->mpc_index[mpc->n_mpc], fp)) {
1172 return -1;
1173 }
1174
1175 /* mpc_dof */
1176 if ((mpc->mpc_dof = (int *)HECMW_malloc(
1177 sizeof(int) * mpc->mpc_index[mpc->n_mpc])) == NULL) {
1178 HECMW_set_error(errno, "");
1179 return -1;
1180 }
1181 if (get_int_ary(mpc->mpc_dof, mpc->mpc_index[mpc->n_mpc], fp)) {
1182 return -1;
1183 }
1184
1185 /* mpc_val */
1186 if ((mpc->mpc_val = (double *)HECMW_malloc(
1187 sizeof(double) * mpc->mpc_index[mpc->n_mpc])) == NULL) {
1188 HECMW_set_error(errno, "");
1189 return -1;
1190 }
1191 if (get_double_ary(mpc->mpc_val, mpc->mpc_index[mpc->n_mpc], fp)) {
1192 return -1;
1193 }
1194
1195 /* mpc_const */
1196 if ((mpc->mpc_const = (double *)HECMW_calloc(mpc->n_mpc, sizeof(double))) ==
1197 NULL) {
1198 HECMW_set_error(errno, "");
1199 return -1;
1200 }
1201 if (hecmw_flag_version >= 3) {
1202 if (get_double_ary(mpc->mpc_const, mpc->n_mpc, fp)) {
1203 return -1;
1204 }
1205 }
1206
1207 return 0;
1208}
1209
1210/*============================================================================*/
1211/* */
1212/* get amplitude information */
1213/* */
1214/*============================================================================*/
1215static int get_amp_info(struct hecmwST_amplitude *amp, FILE *fp) {
1216 /* n_amp */
1217 if (get_int(&amp->n_amp, fp)) {
1218 return -1;
1219 }
1220
1221 if (amp->n_amp == 0) {
1222 amp->amp_name = NULL;
1224 amp->amp_type_time = NULL;
1225 amp->amp_type_value = NULL;
1226 amp->amp_val = NULL;
1227 amp->amp_table = NULL;
1228 amp->amp_index = HECMW_malloc(sizeof(int));
1229 if (amp->amp_index == NULL) {
1230 HECMW_set_error(errno, "");
1231 return -1;
1232 }
1233 amp->amp_index[0] = 0;
1234 return 0;
1235 }
1236
1237 /* amp_name */
1238 if ((amp->amp_name = (char **)HECMW_malloc(sizeof(char *) * amp->n_amp)) ==
1239 NULL) {
1240 HECMW_set_error(errno, "");
1241 return -1;
1242 }
1243 if (get_string_ary(amp->amp_name, amp->n_amp, fp)) {
1244 return -1;
1245 }
1246
1247 /* amp_type_definition */
1248 if ((amp->amp_type_definition =
1249 (int *)HECMW_malloc(sizeof(int) * amp->n_amp)) == NULL) {
1250 HECMW_set_error(errno, "");
1251 return -1;
1252 }
1253 if (get_int_ary(amp->amp_type_definition, amp->n_amp, fp)) {
1254 return -1;
1255 }
1256
1257 /* amp_type_time */
1258 if ((amp->amp_type_time = (int *)HECMW_malloc(sizeof(int) * amp->n_amp)) ==
1259 NULL) {
1260 HECMW_set_error(errno, "");
1261 return -1;
1262 }
1263 if (get_int_ary(amp->amp_type_time, amp->n_amp, fp)) {
1264 return -1;
1265 }
1266
1267 /* amp_type_value */
1268 if ((amp->amp_type_value = (int *)HECMW_malloc(sizeof(int) * amp->n_amp)) ==
1269 NULL) {
1270 HECMW_set_error(errno, "");
1271 return -1;
1272 }
1273 if (get_int_ary(amp->amp_type_value, amp->n_amp, fp)) {
1274 return -1;
1275 }
1276
1277 /* amp_index */
1278 if ((amp->amp_index = (int *)HECMW_malloc(sizeof(int) * (amp->n_amp + 1))) ==
1279 NULL) {
1280 HECMW_set_error(errno, "");
1281 return -1;
1282 }
1283 if (get_int_ary(amp->amp_index, amp->n_amp + 1, fp)) {
1284 return -1;
1285 }
1286
1287 /* amp_val */
1288 if ((amp->amp_val = (double *)HECMW_malloc(
1289 sizeof(double) * amp->amp_index[amp->n_amp])) == NULL) {
1290 HECMW_set_error(errno, "");
1291 return -1;
1292 }
1293 if (get_double_ary(amp->amp_val, amp->amp_index[amp->n_amp], fp)) {
1294 return -1;
1295 }
1296
1297 /* amp_table */
1298 if ((amp->amp_table = (double *)HECMW_malloc(
1299 sizeof(double) * amp->amp_index[amp->n_amp])) == NULL) {
1300 HECMW_set_error(errno, "");
1301 return -1;
1302 }
1303 if (get_double_ary(amp->amp_table, amp->amp_index[amp->n_amp], fp)) {
1304 return -1;
1305 }
1306
1307 return 0;
1308}
1309
1310/*============================================================================*/
1311/* */
1312/* get node group information */
1313/* */
1314/*============================================================================*/
1315static int get_node_group_info(struct hecmwST_node_grp *grp, FILE *fp) {
1316 /* n_grp */
1317 if (get_int(&grp->n_grp, fp)) {
1318 return -1;
1319 }
1320
1321 if (grp->n_grp == 0) {
1322 grp->grp_name = NULL;
1323 grp->grp_item = NULL;
1324 grp->grp_index = HECMW_malloc(sizeof(int));
1325 if (grp->grp_index == NULL) {
1326 HECMW_set_error(errno, "");
1327 return -1;
1328 }
1329 grp->grp_index[0] = 0;
1330 return 0;
1331 }
1332
1333 /* grp_name */
1334 if ((grp->grp_name = (char **)HECMW_malloc(sizeof(char *) * grp->n_grp)) ==
1335 NULL) {
1336 HECMW_set_error(errno, "");
1337 return -1;
1338 }
1339 if (get_string_ary(grp->grp_name, grp->n_grp, fp)) {
1340 return -1;
1341 }
1342
1343 /* grp_index */
1344 if ((grp->grp_index = (int *)HECMW_malloc(sizeof(int) * (grp->n_grp + 1))) ==
1345 NULL) {
1346 HECMW_set_error(errno, "");
1347 return -1;
1348 }
1349 if (get_int_ary(grp->grp_index, grp->n_grp + 1, fp)) {
1350 return -1;
1351 }
1352
1353 /* grp_item */
1354 if (grp->grp_index[grp->n_grp] > 0) {
1355 if ((grp->grp_item = (int *)HECMW_malloc(
1356 sizeof(int) * grp->grp_index[grp->n_grp])) == NULL) {
1357 HECMW_set_error(errno, "");
1358 return -1;
1359 }
1360 if (get_int_ary(grp->grp_item, grp->grp_index[grp->n_grp], fp)) {
1361 return -1;
1362 }
1363 } else {
1364 grp->grp_item = NULL;
1365 }
1366
1367 return 0;
1368}
1369
1370/*============================================================================*/
1371/* */
1372/* get element group information */
1373/* */
1374/*============================================================================*/
1375static int get_elem_group_info(struct hecmwST_elem_grp *grp, FILE *fp) {
1376 /* n_grp */
1377 if (get_int(&grp->n_grp, fp)) {
1378 return -1;
1379 }
1380
1381 if (grp->n_grp == 0) {
1382 grp->grp_name = NULL;
1383 grp->grp_item = NULL;
1384 grp->grp_index = HECMW_malloc(sizeof(int));
1385 if (grp->grp_index == NULL) {
1386 HECMW_set_error(errno, "");
1387 return -1;
1388 }
1389 grp->grp_index[0] = 0;
1390 return 0;
1391 }
1392
1393 /* grp_name */
1394 if ((grp->grp_name = (char **)HECMW_malloc(sizeof(char *) * grp->n_grp)) ==
1395 NULL) {
1396 HECMW_set_error(errno, "");
1397 return -1;
1398 }
1399 if (get_string_ary(grp->grp_name, grp->n_grp, fp)) {
1400 return -1;
1401 }
1402
1403 /* grp_index */
1404 if ((grp->grp_index = (int *)HECMW_malloc(sizeof(int) * (grp->n_grp + 1))) ==
1405 NULL) {
1406 HECMW_set_error(errno, "");
1407 return -1;
1408 }
1409 if (get_int_ary(grp->grp_index, grp->n_grp + 1, fp)) {
1410 return -1;
1411 }
1412
1413 /* grp_item */
1414 if (grp->grp_index[grp->n_grp] > 0) {
1415 if ((grp->grp_item = (int *)HECMW_malloc(
1416 sizeof(int) * grp->grp_index[grp->n_grp])) == NULL) {
1417 HECMW_set_error(errno, "");
1418 return -1;
1419 }
1420 if (get_int_ary(grp->grp_item, grp->grp_index[grp->n_grp], fp)) {
1421 return -1;
1422 }
1423 } else {
1424 grp->grp_item = NULL;
1425 }
1426
1427 return 0;
1428}
1429
1430/*============================================================================*/
1431/* */
1432/* get surface group information */
1433/* */
1434/*============================================================================*/
1435static int get_surf_group_info(struct hecmwST_surf_grp *grp, FILE *fp) {
1436 /* n_grp */
1437 if (get_int(&grp->n_grp, fp)) {
1438 return -1;
1439 }
1440
1441 if (grp->n_grp == 0) {
1442 grp->grp_name = NULL;
1443 grp->grp_item = NULL;
1444 grp->grp_index = HECMW_malloc(sizeof(int));
1445 if (grp->grp_index == NULL) {
1446 HECMW_set_error(errno, "");
1447 return -1;
1448 }
1449 grp->grp_index[0] = 0;
1450 return 0;
1451 }
1452
1453 /* grp_name */
1454 if ((grp->grp_name = (char **)HECMW_malloc(sizeof(char *) * grp->n_grp)) ==
1455 NULL) {
1456 HECMW_set_error(errno, "");
1457 return -1;
1458 }
1459 if (get_string_ary(grp->grp_name, grp->n_grp, fp)) {
1460 return -1;
1461 }
1462
1463 /* grp_index */
1464 if ((grp->grp_index = (int *)HECMW_malloc(sizeof(int) * (grp->n_grp + 1))) ==
1465 NULL) {
1466 HECMW_set_error(errno, "");
1467 return -1;
1468 }
1469 if (get_int_ary(grp->grp_index, grp->n_grp + 1, fp)) {
1470 return -1;
1471 }
1472
1473 /* grp_item */
1474 if (grp->grp_index[grp->n_grp] > 0) {
1475 if ((grp->grp_item = (int *)HECMW_malloc(
1476 sizeof(int) * grp->grp_index[grp->n_grp] * 2)) == NULL) {
1477 HECMW_set_error(errno, "");
1478 return -1;
1479 }
1480 if (get_int_ary(grp->grp_item, grp->grp_index[grp->n_grp] * 2, fp)) {
1481 return -1;
1482 }
1483 } else {
1484 grp->grp_item = NULL;
1485 }
1486
1487 return 0;
1488}
1489
1490/*============================================================================*/
1491/* */
1492/* get contact information */
1493/* */
1494/*============================================================================*/
1495static int get_contact_info(struct hecmwST_contact_pair *cpair, FILE *fp,
1496 int hecmw_flag_version) {
1497 if (hecmw_flag_version < 3) {
1498 cpair->n_pair = 0;
1499 cpair->type = NULL;
1500 cpair->slave_grp_id = NULL;
1501 cpair->slave_orisgrp_id = NULL;
1502 cpair->master_grp_id = NULL;
1503 return 0;
1504 }
1505
1506 /* n_pair */
1507 if (get_int(&cpair->n_pair, fp)) {
1508 return -1;
1509 }
1510
1511 if (cpair->n_pair == 0) {
1512 cpair->name = NULL;
1513 cpair->type = NULL;
1514 cpair->slave_grp_id = NULL;
1515 cpair->slave_orisgrp_id = NULL;
1516 cpair->master_grp_id = NULL;
1517 return 0;
1518 }
1519
1520 /* name */
1521 if ((cpair->name = (char **)HECMW_malloc(sizeof(char *) * cpair->n_pair)) ==
1522 NULL) {
1523 HECMW_set_error(errno, "");
1524 return -1;
1525 }
1526 if (get_string_ary(cpair->name, cpair->n_pair, fp)) {
1527 return -1;
1528 }
1529
1530 /* type */
1531 if ((cpair->type = (int *)HECMW_malloc(sizeof(int) * (cpair->n_pair))) ==
1532 NULL) {
1533 HECMW_set_error(errno, "");
1534 return -1;
1535 }
1536 if (get_int_ary(cpair->type, cpair->n_pair, fp)) {
1537 return -1;
1538 }
1539
1540 /* slave_grp_id */
1541 if ((cpair->slave_grp_id =
1542 (int *)HECMW_malloc(sizeof(int) * (cpair->n_pair))) == NULL) {
1543 HECMW_set_error(errno, "");
1544 return -1;
1545 }
1546 if (get_int_ary(cpair->slave_grp_id, cpair->n_pair, fp)) {
1547 return -1;
1548 }
1549
1550 /* slave_orisgrp_id */
1551 if ((cpair->slave_orisgrp_id =
1552 (int *)HECMW_malloc(sizeof(int) * (cpair->n_pair))) == NULL) {
1553 HECMW_set_error(errno, "");
1554 return -1;
1555 }
1556 if (hecmw_flag_version >= 5) {
1557 if (get_int_ary(cpair->slave_orisgrp_id, cpair->n_pair, fp)) {
1558 return -1;
1559 }
1560 }
1561
1562 /* master_grp_id */
1563 if ((cpair->master_grp_id =
1564 (int *)HECMW_malloc(sizeof(int) * (cpair->n_pair))) == NULL) {
1565 HECMW_set_error(errno, "");
1566 return -1;
1567 }
1568 if (get_int_ary(cpair->master_grp_id, cpair->n_pair, fp)) {
1569 return -1;
1570 }
1571
1572 return 0;
1573}
1574
1575/*============================================================================*/
1576/* */
1577/* get refinement information */
1578/* */
1579/*============================================================================*/
1580static int get_refine_info(struct hecmwST_local_mesh *mesh, FILE *fp) {
1581 if (mesh->hecmw_flag_version < 2) {
1582 mesh->n_refine = 0;
1585 return 0;
1586 }
1587
1588 /* number of refinement performed */
1589 if (get_int(&mesh->n_refine, fp)) {
1590 return -1;
1591 }
1592 if (mesh->n_refine == 0 || mesh->n_subdomain == 1) {
1595 return 0;
1596 }
1597
1599 /* node_old2new */
1600 if ((mesh->node_old2new =
1601 (int *)HECMW_malloc(sizeof(int) * mesh->n_node_gross)) == NULL) {
1602 HECMW_set_error(errno, "");
1603 return -1;
1604 }
1605 if (get_int_ary(mesh->node_old2new, mesh->n_node_gross, fp)) {
1606 return -1;
1607 }
1608
1609 /* node_new2old */
1610 if ((mesh->node_new2old =
1611 (int *)HECMW_malloc(sizeof(int) * mesh->n_node_gross)) == NULL) {
1612 HECMW_set_error(errno, "");
1613 return -1;
1614 }
1615 if (get_int_ary(mesh->node_new2old, mesh->n_node_gross, fp)) {
1616 return -1;
1617 }
1618 }
1619
1620 if (mesh->n_elem_gross > mesh->n_elem) {
1621 /* elem_old2new */
1622 if ((mesh->elem_old2new =
1623 (int *)HECMW_malloc(sizeof(int) * mesh->n_elem_gross)) == NULL) {
1624 HECMW_set_error(errno, "");
1625 return -1;
1626 }
1627 if (get_int_ary(mesh->elem_old2new, mesh->n_elem_gross, fp)) {
1628 return -1;
1629 }
1630
1631 /* elem_new2old */
1632 if ((mesh->elem_new2old =
1633 (int *)HECMW_malloc(sizeof(int) * mesh->n_elem_gross)) == NULL) {
1634 HECMW_set_error(errno, "");
1635 return -1;
1636 }
1637 if (get_int_ary(mesh->elem_new2old, mesh->n_elem_gross, fp)) {
1638 return -1;
1639 }
1640 }
1641
1642 return 0;
1643}
1644
1645static void set_comm(struct hecmwST_local_mesh *mesh) {
1648 mesh->PEsmpTOT = 1;
1650 if (mesh->my_rank == 0) {
1651 mesh->zero = 1;
1652 } else {
1653 mesh->zero = 0;
1654 }
1655}
1656
1657/*============================================================================*/
1658/* */
1659/* get HEC-MW distributed mesh format data */
1660/* */
1661/*============================================================================*/
1662extern struct hecmwST_local_mesh *HECMW_get_dist_mesh(char *fname) {
1663 FILE *fp;
1664 struct hecmwST_local_mesh *mesh;
1665
1666 HECMW_log(HECMW_LOG_DEBUG, "Start to read HECW-DIST file");
1667
1668 /* allocation */
1669 if ((mesh = HECMW_dist_alloc()) == NULL) {
1670 return NULL;
1671 }
1672
1673 /* file open */
1674 if ((fp = fopen(fname, "r")) == NULL) {
1675 HECMW_set_error(HECMW_IO_E5001, "File: %s, %s", fname, HECMW_strmsg(errno));
1676 return NULL;
1677 }
1678
1679 /* check file type */
1680 if (!is_hecmw_dist_file(fp)) {
1681 return NULL;
1682 }
1683
1684 /* rewind */
1685 if (rewind_fp(fp)) {
1686 return NULL;
1687 }
1688
1689 /* get data */
1690 if (get_header(fp)) {
1691 return NULL;
1692 }
1693
1694 if (get_global_info(mesh, fp)) {
1695 return NULL;
1696 }
1697
1698 if (get_node_info(mesh, fp)) {
1699 return NULL;
1700 }
1701
1702 if (get_elem_info(mesh, fp)) {
1703 return NULL;
1704 }
1705
1706 if (get_comm_info(mesh, fp)) {
1707 return NULL;
1708 }
1709
1710 if (get_adapt_info(mesh, fp)) {
1711 return NULL;
1712 }
1713
1714 if (get_section_info(mesh->section, fp)) {
1715 return NULL;
1716 }
1717
1718 if (get_material_info(mesh->material, fp)) {
1719 return NULL;
1720 }
1721
1722 if (get_mpc_info(mesh->mpc, fp, mesh->hecmw_flag_version)) {
1723 return NULL;
1724 }
1725
1726 if (get_amp_info(mesh->amp, fp)) {
1727 return NULL;
1728 }
1729
1730 if (get_node_group_info(mesh->node_group, fp)) {
1731 return NULL;
1732 }
1733
1734 if (get_elem_group_info(mesh->elem_group, fp)) {
1735 return NULL;
1736 }
1737
1738 if (get_surf_group_info(mesh->surf_group, fp)) {
1739 return NULL;
1740 }
1741
1742 if (get_refine_info(mesh, fp)) {
1743 return NULL;
1744 }
1745
1746 if (get_contact_info(mesh->contact_pair, fp, mesh->hecmw_flag_version)) {
1747 return NULL;
1748 }
1749
1750 /* close file */
1751 if (fclose(fp)) {
1753 return NULL;
1754 }
1755
1756 set_comm(mesh);
1757
1758 if (mesh->hecmw_flag_version < 4) {
1760 }
1761
1762 return mesh;
1763}
1764
1765/* */
1766/* print data */
1767/* */
1768
1769/*----------------------------------------------------------------------------*/
1770/* print int */
1771/*----------------------------------------------------------------------------*/
1772static int print_int(int item, FILE *fp) {
1773 int rtc;
1774
1775 rtc = fprintf(fp, "%d\n", item);
1776 if (rtc < 0) {
1778 return -1;
1779 }
1780
1781 return 0;
1782}
1783
1784/*----------------------------------------------------------------------------*/
1785/* print double */
1786/*----------------------------------------------------------------------------*/
1787static int print_double(double item, FILE *fp) {
1788 int rtc;
1789
1790 rtc = fprintf(fp, "%.16E\n", item);
1791 if (rtc < 0) {
1793 return -1;
1794 }
1795
1796 return 0;
1797}
1798
1799/*----------------------------------------------------------------------------*/
1800/* print string */
1801/*----------------------------------------------------------------------------*/
1802static int print_string(const char *item, FILE *fp) {
1803 int rtc;
1804
1805 rtc = fprintf(fp, "%s\n", item);
1806 if (rtc < 0) {
1808 return -1;
1809 }
1810
1811 return 0;
1812}
1813
1814/*----------------------------------------------------------------------------*/
1815/* print HECMW_Comm */
1816/*----------------------------------------------------------------------------*/
1817static int print_comm(HECMW_Comm item, FILE *fp) {
1818 int rtc;
1819
1820 /* rtc = fprintf( fp, "%d\n", (int)item ); */
1821 rtc = fprintf(fp, "%d\n", 0);
1822 if (rtc < 0) {
1824 return -1;
1825 }
1826
1827 return 0;
1828}
1829
1830/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1831/* print int (array) */
1832/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1833static int print_int_ary(const int *ary, int n, int cols, FILE *fp) {
1834 int rtc, i;
1835
1836 if (n <= 0) return 0;
1837
1838 for (i = 0; i < n; i++) {
1839 rtc = fprintf(fp, "%d%c", ary[i], (i + 1) % cols ? ' ' : '\n');
1840 if (rtc < 0) {
1842 return -1;
1843 }
1844 }
1845 if (n % cols) {
1846 rtc = fprintf(fp, "\n");
1847 if (rtc < 0) {
1849 return -1;
1850 }
1851 }
1852
1853 return 0;
1854}
1855
1856/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1857/* print double (array) */
1858/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1859static int print_double_ary(const double *ary, int n, int cols, FILE *fp) {
1860 int rtc, i;
1861
1862 if (n <= 0) return 0;
1863
1864 for (i = 0; i < n; i++) {
1865 rtc = fprintf(fp, "%.16E%c", ary[i], (i + 1) % cols ? ' ' : '\n');
1866 if (rtc < 0) {
1868 return -1;
1869 }
1870 }
1871 if (n % cols) {
1872 rtc = fprintf(fp, "\n");
1873 if (rtc < 0) {
1875 return -1;
1876 }
1877 }
1878
1879 return 0;
1880}
1881
1882/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1883/* print string (array) */
1884/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1885static int print_string_ary(char **ary, int n, FILE *fp) {
1886 int rtc, i;
1887
1888 for (i = 0; i < n; i++) {
1889 rtc = fprintf(fp, "%s\n", ary[i]);
1890 if (rtc < 0) {
1892 return -1;
1893 }
1894 }
1895
1896 return 0;
1897}
1898
1899/*----------------------------------------------------------------------------*/
1900/* print header */
1901/*----------------------------------------------------------------------------*/
1902static int print_header(const struct hecmwST_local_mesh *mesh, FILE *fp) {
1903 int rtc;
1904 char header[HECMW_HEADER_LEN + 1];
1905
1906 strcpy(header, HEADER_STRING);
1907 rtc = sprintf(header + strlen(header), "%d", mesh->hecmw_flag_version);
1908 if (rtc < 0) {
1910 return -1;
1911 }
1912
1913 if (print_string(header, fp)) {
1914 return -1;
1915 } else {
1916 return 0;
1917 }
1918}
1919
1920/*----------------------------------------------------------------------------*/
1921/* print global information */
1922/*----------------------------------------------------------------------------*/
1923static int print_global_info(const struct hecmwST_local_mesh *mesh, FILE *fp) {
1924 int flag_header;
1925
1926 /* hecmw_flag_adapt */
1927 if (print_int(mesh->hecmw_flag_adapt, fp)) {
1928 return -1;
1929 }
1930
1931 /* hecmw_flag_initcon */
1932 if (print_int(mesh->hecmw_flag_initcon, fp)) {
1933 return -1;
1934 }
1935
1936 /* hecmw_flag_parttype */
1937 if (print_int(mesh->hecmw_flag_parttype, fp)) {
1938 return -1;
1939 }
1940
1941 /* hecmw_flag_partdepth */
1942 if (print_int(mesh->hecmw_flag_partdepth, fp)) {
1943 return -1;
1944 }
1945
1946 /* hecmw_flag_version */
1947 if (print_int(mesh->hecmw_flag_version, fp)) {
1948 return -1;
1949 }
1950
1951 /* hecmw_flag_partcontact */
1952 if (print_int(mesh->hecmw_flag_partcontact, fp)) {
1953 return -1;
1954 }
1955
1956 /* gridfile */
1957 if (print_string(mesh->gridfile, fp)) {
1958 return -1;
1959 }
1960
1961 /* hecmw_n_files */
1962 if (print_int(mesh->hecmw_n_file, fp)) {
1963 return -1;
1964 }
1965
1966 /* files */
1967 if (mesh->hecmw_n_file > 0) {
1968 if (print_string_ary(mesh->files, mesh->hecmw_n_file, fp)) {
1969 return -1;
1970 }
1971 }
1972
1973 if (strlen(mesh->header) > 0) {
1974 /* flag for header */
1975 flag_header = 1;
1976 if (print_int(flag_header, fp)) {
1977 return -1;
1978 }
1979
1980 /* header */
1981 if (print_string(mesh->header, fp)) {
1982 return -1;
1983 }
1984 } else {
1985 /* flag for header */
1986 flag_header = 0;
1987 if (print_int(flag_header, fp)) {
1988 return -1;
1989 }
1990 }
1991
1992 /* zero_temp */
1993 if (print_double(mesh->zero_temp, fp)) {
1994 return -1;
1995 }
1996
1997 return 0;
1998}
1999
2000/*============================================================================*/
2001/* */
2002/* print node information */
2003/* */
2004/*============================================================================*/
2005static int print_node_info(const struct hecmwST_local_mesh *mesh, FILE *fp) {
2006 /* n_node */
2007 if (print_int(mesh->n_node, fp)) {
2008 return -1;
2009 }
2010
2011 /* n_node_gross */
2012 if (print_int(mesh->n_node_gross, fp)) {
2013 return -1;
2014 }
2015
2016 /* nn_middle */
2017 if (print_int(mesh->nn_middle, fp)) {
2018 return -1;
2019 }
2020
2021 /* nn_internal */
2022 if (print_int(mesh->nn_internal, fp)) {
2023 return -1;
2024 }
2025
2026 /* node_internal_list */
2029 if (print_int_ary(mesh->node_internal_list, mesh->nn_internal, COLS_INT_DEF,
2030 fp)) {
2031 return -1;
2032 }
2033 }
2034
2035 /* node_ID */
2036 if (print_int_ary(mesh->node_ID, 2 * mesh->n_node_gross, COLS_TWO, fp)) {
2037 return -1;
2038 }
2039
2040 /* global_node_ID */
2041 if (print_int_ary(mesh->global_node_ID, mesh->n_node_gross, COLS_INT_DEF,
2042 fp)) {
2043 return -1;
2044 }
2045
2046 /* node */
2047 if (print_double_ary(mesh->node, 3 * mesh->n_node_gross, COLS_THREE, fp)) {
2048 return -1;
2049 }
2050
2051 /* n_dof */
2052 if (print_int(mesh->n_dof, fp)) {
2053 return -1;
2054 }
2055
2056 /* n_dof_grp */
2057 if (print_int(mesh->n_dof_grp, fp)) {
2058 return -1;
2059 }
2060
2061 /* node_dof_index */
2062 if (print_int_ary(mesh->node_dof_index, mesh->n_dof_grp + 1, COLS_INT_DEF,
2063 fp)) {
2064 return -1;
2065 }
2066
2067 /* node_dof_item */
2068 if (print_int_ary(mesh->node_dof_item, mesh->n_dof_grp, COLS_INT_DEF, fp)) {
2069 return -1;
2070 }
2071
2072 if (mesh->hecmw_flag_initcon) {
2073 /* node_init_val_index */
2074 if (print_int_ary(mesh->node_init_val_index, mesh->n_node_gross + 1,
2075 COLS_INT_DEF, fp)) {
2076 return -1;
2077 }
2078
2079 /* node_init_val_item */
2080 if (print_double_ary(mesh->node_init_val_item,
2082 COLS_DOUBLE_DEF, fp)) {
2083 return -1;
2084 }
2085 }
2086
2087 /* node_val_index */
2088 /* node_val_item */
2089
2090 return 0;
2091}
2092
2093/*============================================================================*/
2094/* */
2095/* print element information */
2096/* */
2097/*============================================================================*/
2098static int print_elem_info(const struct hecmwST_local_mesh *mesh, FILE *fp) {
2099 /* n_elem */
2100 if (print_int(mesh->n_elem, fp)) {
2101 return -1;
2102 }
2103
2104 /* n_elem_gross */
2105 if (print_int(mesh->n_elem_gross, fp)) {
2106 return -1;
2107 }
2108
2109 /* ne_internal */
2110 if (print_int(mesh->ne_internal, fp)) {
2111 return -1;
2112 }
2113
2114 /* elem_internal_list */
2117 if (print_int_ary(mesh->elem_internal_list, mesh->ne_internal, COLS_INT_DEF,
2118 fp)) {
2119 return -1;
2120 }
2121 }
2122
2123 /* elem_ID */
2124 if (print_int_ary(mesh->elem_ID, 2 * mesh->n_elem_gross, COLS_TWO, fp)) {
2125 return -1;
2126 }
2127
2128 /* global_elem_ID */
2129 if (print_int_ary(mesh->global_elem_ID, mesh->n_elem_gross, COLS_INT_DEF,
2130 fp)) {
2131 return -1;
2132 }
2133
2134 /* elem_type */
2135 if (print_int_ary(mesh->elem_type, mesh->n_elem_gross, COLS_INT_DEF, fp)) {
2136 return -1;
2137 }
2138
2139 /* n_elem_type */
2140 if (print_int(mesh->n_elem_type, fp)) {
2141 return -1;
2142 }
2143
2144 /* elem_type_index */
2145 if (print_int_ary(mesh->elem_type_index, mesh->n_elem_type + 1, COLS_INT_DEF,
2146 fp)) {
2147 return -1;
2148 }
2149
2150 /* elem_type_item */
2151 if (print_int_ary(mesh->elem_type_item, mesh->n_elem_type, COLS_INT_DEF,
2152 fp)) {
2153 return -1;
2154 }
2155
2156 /* elem_node_index */
2157 if (print_int_ary(mesh->elem_node_index, mesh->n_elem_gross + 1, COLS_INT_DEF,
2158 fp)) {
2159 return -1;
2160 }
2161
2162 /* elem_node_item */
2163 if (print_int_ary(mesh->elem_node_item,
2165 fp)) {
2166 return -1;
2167 }
2168
2169 /* section_ID */
2170 if (print_int_ary(mesh->section_ID, mesh->n_elem_gross, COLS_INT_DEF, fp)) {
2171 return -1;
2172 }
2173
2174 /* elem_mat_ID_index */
2175 if (print_int_ary(mesh->elem_mat_ID_index, mesh->n_elem_gross + 1,
2176 COLS_INT_DEF, fp)) {
2177 return -1;
2178 }
2179
2180 /* elem_mat_ID_item */
2181 if (print_int_ary(mesh->elem_mat_ID_item,
2183 fp)) {
2184 return -1;
2185 }
2186
2187 /* n_elem_mat_ID */
2188 if (print_int(mesh->n_elem_mat_ID, fp)) {
2189 return -1;
2190 }
2191
2192 /* elem_mat_int_index */
2193 /* elem_mat_int_item */
2194
2195 /* elem_val_index */
2196 /* elem_val_item */
2197
2198 return 0;
2199}
2200
2201/*============================================================================*/
2202/* */
2203/* print domain information & communication tables */
2204/* */
2205/*============================================================================*/
2206static int print_comm_info(const struct hecmwST_local_mesh *mesh, FILE *fp) {
2207 /* zero */
2208 if (print_int(mesh->zero, fp)) {
2209 return -1;
2210 }
2211
2212 /* HECMW_COMM */
2213 if (print_comm(mesh->HECMW_COMM, fp)) {
2214 return -1;
2215 }
2216
2217 /* PETOT */
2218 if (print_int(mesh->PETOT, fp)) {
2219 return -1;
2220 }
2221
2222 /* PEsmpTOT */
2223 if (print_int(mesh->PEsmpTOT, fp)) {
2224 return -1;
2225 }
2226
2227 /* my_rank */
2228 if (print_int(mesh->my_rank, fp)) {
2229 return -1;
2230 }
2231
2232 /* errnof */
2233 if (print_int(mesh->errnof, fp)) {
2234 return -1;
2235 }
2236
2237 /* n_subdomain */
2238 if (print_int(mesh->n_subdomain, fp)) {
2239 return -1;
2240 }
2241
2242 /* n_neighbor_pd */
2243 if (print_int(mesh->n_neighbor_pe, fp)) {
2244 return -1;
2245 }
2246
2247 if (mesh->n_neighbor_pe == 0) return 0;
2248
2249 /* neighbor_pe */
2250 if (print_int_ary(mesh->neighbor_pe, mesh->n_neighbor_pe, COLS_INT_DEF, fp)) {
2251 return -1;
2252 }
2253
2254 /* import_index */
2255 if (print_int_ary(mesh->import_index, mesh->n_neighbor_pe + 1, COLS_INT_DEF,
2256 fp)) {
2257 return -1;
2258 }
2259
2260 /* import_item */
2261 if (print_int_ary(mesh->import_item, mesh->import_index[mesh->n_neighbor_pe],
2262 COLS_INT_DEF, fp)) {
2263 return -1;
2264 }
2265
2266 /* export_index */
2267 if (print_int_ary(mesh->export_index, mesh->n_neighbor_pe + 1, COLS_INT_DEF,
2268 fp)) {
2269 return -1;
2270 }
2271
2272 /* export_item */
2273 if (print_int_ary(mesh->export_item, mesh->export_index[mesh->n_neighbor_pe],
2274 COLS_INT_DEF, fp)) {
2275 return -1;
2276 }
2277
2278 /* shared_index */
2279 if (print_int_ary(mesh->shared_index, mesh->n_neighbor_pe + 1, COLS_INT_DEF,
2280 fp)) {
2281 return -1;
2282 }
2283
2284 /* shared_item */
2285 if (print_int_ary(mesh->shared_item, mesh->shared_index[mesh->n_neighbor_pe],
2286 COLS_INT_DEF, fp)) {
2287 return -1;
2288 }
2289
2290 return 0;
2291}
2292
2293/*============================================================================*/
2294/* */
2295/* print adaptation information */
2296/* */
2297/*============================================================================*/
2298static int print_adapt_info(const struct hecmwST_local_mesh *mesh, FILE *fp) {
2299 if (mesh->hecmw_flag_adapt == 0) return 0;
2300
2301 /* coarse_grid_level */
2302 if (print_int(mesh->coarse_grid_level, fp)) {
2303 return -1;
2304 }
2305
2306 /* n_adapt */
2307 if (print_int(mesh->n_adapt, fp)) {
2308 return -1;
2309 }
2310
2311 /* when_i_was_refined_node */
2312 if (print_int_ary(mesh->when_i_was_refined_node, mesh->n_node_gross,
2313 COLS_INT_DEF, fp)) {
2314 return -1;
2315 }
2316
2317 /* when_i_was_refined_elem */
2318 if (print_int_ary(mesh->when_i_was_refined_elem, mesh->n_elem_gross,
2319 COLS_INT_DEF, fp)) {
2320 return -1;
2321 }
2322
2323 /* adapt_parent_type */
2324 if (print_int_ary(mesh->adapt_parent_type, mesh->n_elem_gross, COLS_INT_DEF,
2325 fp)) {
2326 return -1;
2327 }
2328
2329 /* adapt_type */
2330 if (print_int_ary(mesh->adapt_type, mesh->n_elem_gross, COLS_INT_DEF, fp)) {
2331 return -1;
2332 }
2333
2334 /* adapt_level */
2335 if (print_int_ary(mesh->adapt_level, mesh->n_elem_gross, COLS_INT_DEF, fp)) {
2336 return -1;
2337 }
2338
2339 /* adapt_parent */
2340 if (print_int_ary(mesh->adapt_parent, 2 * mesh->n_elem_gross, COLS_TWO, fp)) {
2341 return -1;
2342 }
2343
2344 /* adapt_children_index */
2345 if (print_int_ary(mesh->adapt_children_index, mesh->n_elem_gross + 1,
2346 COLS_INT_DEF, fp)) {
2347 return -1;
2348 }
2349
2350 /* adapt_children_item */
2351 if (print_int_ary(mesh->adapt_children_item,
2353 COLS_TWO, fp)) {
2354 return -1;
2355 }
2356
2357 return 0;
2358}
2359
2360/*============================================================================*/
2361/* */
2362/* print section information */
2363/* */
2364/*============================================================================*/
2365static int print_section_info(const struct hecmwST_section *sect, FILE *fp) {
2366 /* n_sect */
2367 if (print_int(sect->n_sect, fp)) {
2368 return -1;
2369 }
2370
2371 if (sect->n_sect == 0) return 0;
2372
2373 /* sect_type */
2374 if (print_int_ary(sect->sect_type, sect->n_sect, COLS_INT_DEF, fp)) {
2375 return -1;
2376 }
2377
2378 /* sect_opt */
2379 if (print_int_ary(sect->sect_opt, sect->n_sect, COLS_INT_DEF, fp)) {
2380 return -1;
2381 }
2382
2383 /* sect_mat_ID_index */
2384 if (print_int_ary(sect->sect_mat_ID_index, sect->n_sect + 1, COLS_INT_DEF,
2385 fp)) {
2386 return -1;
2387 }
2388
2389 /* sect_mat_ID_item */
2390 if (print_int_ary(sect->sect_mat_ID_item,
2391 sect->sect_mat_ID_index[sect->n_sect], COLS_INT_DEF, fp)) {
2392 return -1;
2393 }
2394
2395 /* sect_I_index */
2396 if (print_int_ary(sect->sect_I_index, sect->n_sect + 1, COLS_INT_DEF, fp)) {
2397 return -1;
2398 }
2399
2400 /* sect_I_item */
2401 if (print_int_ary(sect->sect_I_item, sect->sect_I_index[sect->n_sect],
2402 COLS_INT_DEF, fp)) {
2403 return -1;
2404 }
2405
2406 /* sect_R_index */
2407 if (print_int_ary(sect->sect_R_index, sect->n_sect + 1, COLS_INT_DEF, fp)) {
2408 return -1;
2409 }
2410
2411 /* sect_R_item */
2412 if (print_double_ary(sect->sect_R_item, sect->sect_R_index[sect->n_sect],
2413 COLS_DOUBLE_DEF, fp)) {
2414 return -1;
2415 }
2416
2417 return 0;
2418}
2419
2420/*============================================================================*/
2421/* */
2422/* print material information */
2423/* */
2424/*============================================================================*/
2425static int print_material_info(struct hecmwST_material *mat, FILE *fp) {
2426 /* n_mat */
2427 if (print_int(mat->n_mat, fp)) {
2428 return -1;
2429 }
2430
2431 if (mat->n_mat == 0) return 0;
2432
2433 /* n_mat_item */
2434 if (print_int(mat->n_mat_item, fp)) {
2435 return -1;
2436 }
2437
2438 /* n_mat_subitem */
2439 if (print_int(mat->n_mat_subitem, fp)) {
2440 return -1;
2441 }
2442
2443 /* n_mat_table */
2444 if (print_int(mat->n_mat_table, fp)) {
2445 return -1;
2446 }
2447
2448 /* mat_name */
2449 if (print_string_ary(mat->mat_name, mat->n_mat, fp)) {
2450 return -1;
2451 }
2452
2453 /* mat_item_index */
2454 if (print_int_ary(mat->mat_item_index, mat->n_mat + 1, COLS_INT_DEF, fp)) {
2455 return -1;
2456 }
2457
2458 /* mat_subitem_index */
2459 if (print_int_ary(mat->mat_subitem_index, mat->n_mat_item + 1, COLS_INT_DEF,
2460 fp)) {
2461 return -1;
2462 }
2463
2464 /* mat_table_index */
2465 if (print_int_ary(mat->mat_table_index, mat->n_mat_subitem + 1, COLS_INT_DEF,
2466 fp)) {
2467 return -1;
2468 }
2469
2470 /* mat_val */
2471 if (print_double_ary(mat->mat_val, mat->n_mat_table, COLS_DOUBLE_DEF, fp)) {
2472 return -1;
2473 }
2474
2475 /* mat_temp */
2476 if (print_double_ary(mat->mat_temp, mat->n_mat_table, COLS_DOUBLE_DEF, fp)) {
2477 return -1;
2478 }
2479
2480 return 0;
2481}
2482
2483/*============================================================================*/
2484/* */
2485/* print MPC group information */
2486/* */
2487/*============================================================================*/
2488static int print_mpc_info(const struct hecmwST_mpc *mpc, FILE *fp) {
2489 /* n_mpc */
2490 if (print_int(mpc->n_mpc, fp)) {
2491 return -1;
2492 }
2493
2494 if (mpc->n_mpc == 0) return 0;
2495
2496 /* mpc_index */
2497 if (print_int_ary(mpc->mpc_index, mpc->n_mpc + 1, COLS_INT_DEF, fp)) {
2498 return -1;
2499 }
2500
2501 /* mpc_item */
2502 if (print_int_ary(mpc->mpc_item, mpc->mpc_index[mpc->n_mpc], COLS_INT_DEF,
2503 fp)) {
2504 return -1;
2505 }
2506
2507 /* mpc_dof */
2508 if (print_int_ary(mpc->mpc_dof, mpc->mpc_index[mpc->n_mpc], COLS_INT_DEF,
2509 fp)) {
2510 return -1;
2511 }
2512
2513 /* mpc_val */
2514 if (print_double_ary(mpc->mpc_val, mpc->mpc_index[mpc->n_mpc],
2515 COLS_DOUBLE_DEF, fp)) {
2516 return -1;
2517 }
2518
2519 /* mpc_const */
2520 if (print_double_ary(mpc->mpc_const, mpc->n_mpc, COLS_DOUBLE_DEF, fp)) {
2521 return -1;
2522 }
2523
2524 return 0;
2525}
2526
2527/*============================================================================*/
2528/* */
2529/* print amplitude information */
2530/* */
2531/*============================================================================*/
2532static int print_amp_info(const struct hecmwST_amplitude *amp, FILE *fp) {
2533 /* n_amp */
2534 if (print_int(amp->n_amp, fp)) {
2535 return -1;
2536 }
2537
2538 if (amp->n_amp == 0) return 0;
2539
2540 /* amp_name */
2541 if (print_string_ary(amp->amp_name, amp->n_amp, fp)) {
2542 return -1;
2543 }
2544
2545 /* amp_type_definition */
2546 if (print_int_ary(amp->amp_type_definition, amp->n_amp, COLS_INT_DEF, fp)) {
2547 return -1;
2548 }
2549
2550 /* amp_type_time */
2551 if (print_int_ary(amp->amp_type_time, amp->n_amp, COLS_INT_DEF, fp)) {
2552 return -1;
2553 }
2554
2555 /* amp_type_value */
2556 if (print_int_ary(amp->amp_type_value, amp->n_amp, COLS_INT_DEF, fp)) {
2557 return -1;
2558 }
2559
2560 /* amp_index */
2561 if (print_int_ary(amp->amp_index, amp->n_amp + 1, COLS_INT_DEF, fp)) {
2562 return -1;
2563 }
2564
2565 /* amp_val */
2566 if (print_double_ary(amp->amp_val, amp->amp_index[amp->n_amp],
2567 COLS_DOUBLE_DEF, fp)) {
2568 return -1;
2569 }
2570
2571 /* amp_table */
2572 if (print_double_ary(amp->amp_table, amp->amp_index[amp->n_amp],
2573 COLS_DOUBLE_DEF, fp)) {
2574 return -1;
2575 }
2576
2577 return 0;
2578}
2579
2580/*============================================================================*/
2581/* */
2582/* print node group information */
2583/* */
2584/*============================================================================*/
2585static int print_node_grp_info(const struct hecmwST_node_grp *grp, FILE *fp) {
2586 /* n_grp */
2587 if (print_int(grp->n_grp, fp)) {
2588 return -1;
2589 }
2590
2591 if (grp->n_grp == 0) return 0;
2592
2593 /* grp_name */
2594 if (print_string_ary(grp->grp_name, grp->n_grp, fp)) {
2595 return -1;
2596 }
2597
2598 /* grp_index */
2599 if (print_int_ary(grp->grp_index, grp->n_grp + 1, COLS_INT_DEF, fp)) {
2600 return -1;
2601 }
2602
2603 /* grp_item */
2604 if (print_int_ary(grp->grp_item, grp->grp_index[grp->n_grp], COLS_INT_DEF,
2605 fp)) {
2606 return -1;
2607 }
2608
2609 return 0;
2610}
2611
2612/*============================================================================*/
2613/* */
2614/* print element group information */
2615/* */
2616/*============================================================================*/
2617static int print_elem_grp_info(const struct hecmwST_elem_grp *grp, FILE *fp) {
2618 /* n_grp */
2619 if (print_int(grp->n_grp, fp)) {
2620 return -1;
2621 }
2622
2623 if (grp->n_grp == 0) return 0;
2624
2625 /* grp_name */
2626 if (print_string_ary(grp->grp_name, grp->n_grp, fp)) {
2627 return -1;
2628 }
2629
2630 /* grp_index */
2631 if (print_int_ary(grp->grp_index, grp->n_grp + 1, COLS_INT_DEF, fp)) {
2632 return -1;
2633 }
2634
2635 /* grp_item */
2636 if (print_int_ary(grp->grp_item, grp->grp_index[grp->n_grp], COLS_INT_DEF,
2637 fp)) {
2638 return -1;
2639 }
2640
2641 return 0;
2642}
2643
2644/*============================================================================*/
2645/* */
2646/* print surface group information */
2647/* */
2648/*============================================================================*/
2649static int print_surf_grp_info(const struct hecmwST_surf_grp *grp, FILE *fp) {
2650 /* n_grp */
2651 if (print_int(grp->n_grp, fp)) {
2652 return -1;
2653 }
2654
2655 if (grp->n_grp == 0) return 0;
2656
2657 /* grp_name */
2658 if (print_string_ary(grp->grp_name, grp->n_grp, fp)) {
2659 return -1;
2660 }
2661
2662 /* grp_index */
2663 if (print_int_ary(grp->grp_index, grp->n_grp + 1, COLS_INT_DEF, fp)) {
2664 return -1;
2665 }
2666
2667 /* grp_item */
2668 if (print_int_ary(grp->grp_item, grp->grp_index[grp->n_grp] * 2, COLS_TWO,
2669 fp)) {
2670 return -1;
2671 }
2672
2673 return 0;
2674}
2675
2676/*============================================================================*/
2677/* */
2678/* print refinement information */
2679/* */
2680/*============================================================================*/
2681static int print_refine_info(const struct hecmwST_local_mesh *mesh, FILE *fp) {
2682 /* number of refinement performed */
2683 if (print_int(mesh->n_refine, fp)) {
2684 return -1;
2685 }
2686
2687 if (mesh->n_refine == 0 || mesh->n_subdomain == 1) return 0;
2688
2690 /* node_old2new */
2691 if (print_int_ary(mesh->node_old2new, mesh->n_node_gross, COLS_INT_DEF,
2692 fp)) {
2693 return -1;
2694 }
2695
2696 /* node_new2old */
2697 if (print_int_ary(mesh->node_new2old, mesh->n_node_gross, COLS_INT_DEF,
2698 fp)) {
2699 return -1;
2700 }
2701 }
2702
2703 if (mesh->n_elem_gross > mesh->n_elem) {
2704 /* elem_old2new */
2705 if (print_int_ary(mesh->elem_old2new, mesh->n_elem_gross, COLS_INT_DEF,
2706 fp)) {
2707 return -1;
2708 }
2709
2710 /* elem_new2old */
2711 if (print_int_ary(mesh->elem_new2old, mesh->n_elem_gross, COLS_INT_DEF,
2712 fp)) {
2713 return -1;
2714 }
2715 }
2716
2717 return 0;
2718}
2719
2720/*============================================================================*/
2721/* */
2722/* print contact information */
2723/* */
2724/*============================================================================*/
2725static int print_contact_info(const struct hecmwST_contact_pair *cpair,
2726 FILE *fp) {
2727 /* n_pair */
2728 if (print_int(cpair->n_pair, fp)) {
2729 return -1;
2730 }
2731
2732 if (cpair->n_pair == 0) return 0;
2733
2734 /* name */
2735 if (print_string_ary(cpair->name, cpair->n_pair, fp)) {
2736 return -1;
2737 }
2738
2739 /* type */
2740 if (print_int_ary(cpair->type, cpair->n_pair, COLS_INT_DEF, fp)) {
2741 return -1;
2742 }
2743
2744 /* slave_grp_id */
2745 if (print_int_ary(cpair->slave_grp_id, cpair->n_pair, COLS_INT_DEF, fp)) {
2746 return -1;
2747 }
2748
2749 /* slave_orisgrp_id */
2750 if (print_int_ary(cpair->slave_orisgrp_id, cpair->n_pair, COLS_INT_DEF, fp)) {
2751 return -1;
2752 }
2753
2754 /* master_grp_id */
2755 if (print_int_ary(cpair->master_grp_id, cpair->n_pair, COLS_INT_DEF, fp)) {
2756 return -1;
2757 }
2758
2759 return 0;
2760}
2761
2762/*============================================================================*/
2763/* */
2764/* print HEC-MW distributed mesh format data */
2765/* */
2766/*============================================================================*/
2767extern int HECMW_put_dist_mesh(const struct hecmwST_local_mesh *mesh,
2768 char *fname) {
2769 FILE *fp;
2770
2771 if (mesh == NULL) return 0;
2772 if (fname == NULL) {
2773 HECMW_set_error(HECMW_IO_E5001, "Filename is NULL)");
2774 return -1;
2775 }
2776
2777 if (HECMW_ctrl_is_subdir()) {
2778 if (HECMW_ctrl_make_subdir(fname)) return 0;
2779 }
2780
2781 /* open file */
2782 if ((fp = fopen(fname, "w")) == NULL) {
2783 HECMW_set_error(HECMW_IO_E5001, "File: %s, %s", fname, strerror(errno));
2784 return -1;
2785 }
2786
2787 /* header */
2788 if (print_header(mesh, fp)) {
2789 return -1;
2790 }
2791
2792 /* global info. */
2793 if (print_global_info(mesh, fp)) {
2794 return -1;
2795 }
2796
2797 /* node info. */
2798 if (print_node_info(mesh, fp)) {
2799 return -1;
2800 }
2801
2802 /* element info. */
2803 if (print_elem_info(mesh, fp)) {
2804 return -1;
2805 }
2806
2807 /* domain info & communication table */
2808 if (print_comm_info(mesh, fp)) {
2809 return -1;
2810 }
2811
2812 /* adaptation info. */
2813 if (print_adapt_info(mesh, fp)) {
2814 return -1;
2815 }
2816
2817 /* section info. */
2818 if (print_section_info(mesh->section, fp)) {
2819 return -1;
2820 }
2821
2822 /* material info. */
2823 if (print_material_info(mesh->material, fp)) {
2824 return -1;
2825 }
2826
2827 /* MPC group info. */
2828 if (print_mpc_info(mesh->mpc, fp)) {
2829 return -1;
2830 }
2831
2832 /* amplitude info. */
2833 if (print_amp_info(mesh->amp, fp)) {
2834 return -1;
2835 }
2836
2837 /* node group info. */
2838 if (print_node_grp_info(mesh->node_group, fp)) {
2839 return -1;
2840 }
2841
2842 /* element group info. */
2843 if (print_elem_grp_info(mesh->elem_group, fp)) {
2844 return -1;
2845 }
2846
2847 /* surface group info */
2848 if (print_surf_grp_info(mesh->surf_group, fp)) {
2849 return -1;
2850 }
2851
2852 /* refinement info. */
2853 if (print_refine_info(mesh, fp)) {
2854 return -1;
2855 }
2856
2857 /* contact info */
2858 if (print_contact_info(mesh->contact_pair, fp)) {
2859 return -1;
2860 }
2861
2862 /* close file */
2863 if (fclose(fp)) {
2865 return -1;
2866 }
2867
2868 return 0;
2869}
HECMW_Comm HECMW_comm_get_comm(void)
Definition: hecmw_comm.c:699
int HECMW_comm_get_rank(void)
Definition: hecmw_comm.c:707
int HECMW_comm_get_size(void)
Definition: hecmw_comm.c:703
MPI_Comm HECMW_Comm
Definition: hecmw_config.h:30
#define HECMW_HEADER_LEN
Definition: hecmw_config.h:68
int HECMW_ctrl_is_subdir(void)
int HECMW_ctrl_make_subdir(char *filename)
struct hecmwST_local_mesh * HECMW_dist_alloc()
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
int HECMW_set_error(int errorno, const char *fmt,...)
Definition: hecmw_error.c:37
#define LINEBUF_SIZE
struct hecmwST_local_mesh * HECMW_get_dist_mesh(char *fname)
#define HEADER_STRING
Definition: hecmw_io_dist.c:25
#define COLS_THREE
Definition: hecmw_io_dist.c:21
#define COLS_DOUBLE_DEF
Definition: hecmw_io_dist.c:19
#define COLS_TWO
Definition: hecmw_io_dist.c:20
#define COLS_INT_DEF
Definition: hecmw_io_dist.c:18
#define FILE_MAGIC_LEN
Definition: hecmw_io_dist.c:24
int HECMW_put_dist_mesh(const struct hecmwST_local_mesh *mesh, char *fname)
#define FILE_MAGIC
Definition: hecmw_io_dist.c:23
#define NULL
int HECMW_log(int loglv, const char *fmt,...)
Definition: hecmw_log.c:260
#define HECMW_LOG_DEBUG
Definition: hecmw_log.h:21
#define HECMW_calloc(nmemb, size)
Definition: hecmw_malloc.h:21
#define HECMW_strdup(s)
Definition: hecmw_malloc.h:23
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
char * HECMW_strmsg(int msgno)
Definition: hecmw_msg.c:31
#define HECMW_IO_E5005
Definition: hecmw_msgno.h:166
#define HECMW_IO_E5001
Definition: hecmw_msgno.h:162
#define HECMW_IO_E5002
Definition: hecmw_msgno.h:163
#define HECMW_IO_E5003
Definition: hecmw_msgno.h:164
#define HECMW_IO_E5006
Definition: hecmw_msgno.h:167
#define HECMW_IO_E5004
Definition: hecmw_msgno.h:165
#define HECMW_FLAG_PARTTYPE_UNKNOWN
Definition: hecmw_struct.h:142
#define HECMW_FLAG_PARTCONTACT_UNKNOWN
Definition: hecmw_struct.h:148
#define HECMW_FLAG_PARTTYPE_NODEBASED
Definition: hecmw_struct.h:143
#define HECMW_FLAG_PARTTYPE_ELEMBASED
Definition: hecmw_struct.h:144
int * amp_type_definition
Definition: hecmw_struct.h:61
double * amp_table
Definition: hecmw_struct.h:72
struct hecmwST_section * section
Definition: hecmw_struct.h:244
struct hecmwST_amplitude * amp
Definition: hecmw_struct.h:247
struct hecmwST_material * material
Definition: hecmw_struct.h:245
struct hecmwST_mpc * mpc
Definition: hecmw_struct.h:246
struct hecmwST_node_grp * node_group
Definition: hecmw_struct.h:248
double * node_init_val_item
Definition: hecmw_struct.h:180
struct hecmwST_contact_pair * contact_pair
Definition: hecmw_struct.h:251
struct hecmwST_surf_grp * surf_group
Definition: hecmw_struct.h:250
char gridfile[HECMW_FILENAME_LEN+1]
Definition: hecmw_struct.h:153
char header[HECMW_HEADER_LEN+1]
Definition: hecmw_struct.h:156
HECMW_Comm HECMW_COMM
Definition: hecmw_struct.h:208
struct hecmwST_elem_grp * elem_group
Definition: hecmw_struct.h:249
int * when_i_was_refined_node
Definition: hecmw_struct.h:226
int * when_i_was_refined_elem
Definition: hecmw_struct.h:227
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 * sect_R_item
Definition: hecmw_struct.h:32
int * sect_mat_ID_index
Definition: hecmw_struct.h:27
int * sect_mat_ID_item
Definition: hecmw_struct.h:28