FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecmw_couple_inter_iftable.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 <string.h>
9 #include <assert.h>
10 #include <errno.h>
11 
12 #include "hecmw_struct.h"
13 #include "hecmw_msgno.h"
14 #include "hecmw_common_define.h"
15 #include "hecmw_error.h"
16 #include "hecmw_comm.h"
17 
18 #include "hecmw_couple_comm.h"
19 #include "hecmw_couple_define.h"
20 #include "hecmw_couple_struct.h"
21 #include "hecmw_couple_judge.h"
27 
28 #define MAX_NODE_SIZE 20
29 
30 #define INFINITE (1.0E+37)
31 
32 #define EPS (1.0E-06)
33 
35  int n_node;
36 
37  double *coord;
38 };
39 
40 struct map_info {
41  int n;
42 
43  int *id;
44 
45  int *n_positive;
46 
47  double *dot_product;
48 
49  double *distance;
50 };
51 
52 struct link_list {
53  int item;
54  struct link_list *next;
55 };
56 
57 struct import_info {
58  int n;
59  struct link_list *list;
60 };
61 
63  int *index;
64  int *id;
65 };
66 
67 struct mapping_info {
68  int n;
69  int *index;
70  int *pe;
71  int *id;
72 };
73 
74 struct link_list_map {
75  int id;
76  int item;
78 };
79 
80 /*================================================================================================*/
81 
82 static void free_link_list(struct link_list *r) {
83  struct link_list *p, *q;
84 
85  p = r;
86  while (p) {
87  q = p->next;
88  HECMW_free(p);
89  p = q;
90  }
91  r = NULL;
92 }
93 
94 static void free_link_list_map(struct link_list_map *r) {
95  struct link_list_map *p, *q;
96 
97  p = r;
98  while (p) {
99  q = p->next;
100  HECMW_free(p);
101  p = q;
102  }
103  r = NULL;
104 }
105 
106 static struct map_info *alloc_struct_map_info(void) {
107  struct map_info *p = NULL;
108 
109  p = (struct map_info *)HECMW_malloc(sizeof(struct map_info));
110  if (p == NULL) {
111  HECMW_set_error(errno, "");
112  return NULL;
113  }
114 
115  p->n = 0;
116  p->id = NULL;
117  p->n_positive = NULL;
118  p->dot_product = NULL;
119  p->distance = NULL;
120 
121  return p;
122 }
123 
124 static void free_struct_map_info(struct map_info *p) {
125  if (p == NULL) return;
126 
127  HECMW_free(p->id);
130  HECMW_free(p->distance);
131  HECMW_free(p);
132  p = NULL;
133 }
134 
136  struct hecmw_couple_inter_iftable *p) {
137  if (p == NULL) return;
138 
145  HECMW_free(p);
146  p = NULL;
147 }
148 
150  void) {
151  struct hecmw_couple_inter_iftable *p = NULL;
152  int size;
153 
154  size = sizeof(struct hecmw_couple_inter_iftable);
155  p = (struct hecmw_couple_inter_iftable *)HECMW_malloc(size);
156  if (p == NULL) {
157  HECMW_set_error(errno, "");
158  return NULL;
159  }
160 
161  p->n_neighbor_pe_import = 0;
163  p->import_index = NULL;
164  p->import_item = NULL;
165  p->n_neighbor_pe_export = 0;
167  p->export_index = NULL;
168  p->export_item = NULL;
169 
170  return p;
171 }
172 
174  const struct hecmw_couple_inter_iftable *p, FILE *fp) {
175  int i, j;
176 
177  fprintf(fp, "*** Interface Table for Inter-communication\n");
178 
179  fprintf(fp, "number of neighbor processes for import: %d\n",
181  fprintf(fp, "neighbor processes for import:\n");
182  for (i = 0; i < p->n_neighbor_pe_import; i++) {
183  fprintf(fp, "%d%c", p->neighbor_pe_import[i], (i + 1) % 10 ? ' ' : '\n');
184  }
185  if (i % 10) fprintf(fp, "\n");
186 
187  fprintf(fp, "number of neighbor processes for export: %d\n",
189  fprintf(fp, "neighbor processes for export:\n");
190  for (i = 0; i < p->n_neighbor_pe_export; i++) {
191  fprintf(fp, "%d%c", p->neighbor_pe_export[i], (i + 1) % 10 ? ' ' : '\n');
192  }
193  if (i % 10) fprintf(fp, "\n");
194 
195  fprintf(fp, "import index:\n");
196  for (i = 0; i < p->n_neighbor_pe_import; i++) {
197  fprintf(fp, "%d%c", p->import_index[i], (i + 1) % 10 ? ' ' : '\n');
198  }
199  if (i % 10) fprintf(fp, "\n");
200 
201  fprintf(fp, "import item:\n");
202  for (i = 0; i < p->n_neighbor_pe_import; i++) {
203  for (j = p->import_index[i]; j < p->import_index[i + 1]; j++) {
204  fprintf(fp, "%d%c", p->import_item[j], (j + 1) % 10 ? ' ' : '\n');
205  }
206  }
207  if (j % 10) fprintf(fp, "\n");
208 
209  fprintf(fp, "export index:\n");
210  for (i = 0; i < p->n_neighbor_pe_export; i++) {
211  fprintf(fp, "%d%c", p->export_index[i], (i + 1) % 10 ? ' ' : '\n');
212  }
213  if (i % 10) fprintf(fp, "\n");
214 
215  fprintf(fp, "export item:\n");
216  for (i = 0; i < p->n_neighbor_pe_export; i++) {
217  for (j = p->export_index[i]; j < p->export_index[i + 1]; j++) {
218  fprintf(fp, "%d%c", p->export_item[j], (j + 1) % 10 ? ' ' : '\n');
219  }
220  }
221  if (j % 10) fprintf(fp, "\n");
222 }
223 
224 /*================================================================================================*/
225 
226 static int bcast_mapped_point_d2s_n(
227  const struct hecmw_couple_mapped_point *mapped_point,
228  const struct hecmw_couple_comm *comm_src,
229  const struct hecmw_couple_comm *comm_dst,
230  const struct hecmw_couple_comm *intercomm,
231  struct hecmw_couple_mapped_point **all_mapped_point) {
232  int n_pe_send = 0, n_pe_recv = 0, *pe_send = NULL, *pe_recv = NULL;
233  int sendbuf_size = 0, *recvbuf_index = NULL, *sendbuf = NULL, *recvbuf = NULL;
234  int rtc, i;
235 
236  /*
237  * send buffer (destination unit)
238  */
239  if (comm_dst->is_member) {
240  /* number of communication processes */
241  n_pe_send = comm_src->psize;
242 
243  /* communication processes */
244  pe_send = (int *)HECMW_malloc(sizeof(int) * n_pe_send);
245  if (pe_send == NULL) {
246  HECMW_set_error(errno, "");
247  goto error;
248  }
249  for (i = 0; i < n_pe_send; i++) {
250  pe_send[i] = comm_src->ranks[i];
251  }
252 
253  /* size of send buffer */
254  sendbuf_size = 1;
255 
256  /* send buffer */
257  sendbuf = (int *)HECMW_malloc(sizeof(int) * (sendbuf_size + 1));
258  if (sendbuf == NULL) {
259  HECMW_set_error(errno, "");
260  goto error;
261  }
262  sendbuf[0] = mapped_point->n;
263  }
264 
265  /*
266  * receive buffer (source unit)
267  */
268  if (comm_src->is_member) {
269  /* number of communication processes */
270  n_pe_recv = comm_dst->psize;
271 
272  /* communication processes */
273  pe_recv = (int *)HECMW_malloc(sizeof(int) * n_pe_recv);
274  if (pe_recv == NULL) {
275  HECMW_set_error(errno, "");
276  goto error;
277  }
278  for (i = 0; i < n_pe_recv; i++) {
279  pe_recv[i] = comm_dst->ranks[i];
280  }
281 
282  /* size of receive buffer */
283  recvbuf_index = (int *)HECMW_calloc(n_pe_recv + 1, sizeof(int));
284  if (recvbuf_index == NULL) {
285  HECMW_set_error(errno, "");
286  goto error;
287  }
288  for (i = 0; i < n_pe_recv; i++) {
289  recvbuf_index[i + 1] = recvbuf_index[i] + 1;
290  }
291 
292  /* receive buffer */
293  recvbuf = (int *)HECMW_calloc(recvbuf_index[n_pe_recv] + 1, sizeof(int));
294  if (recvbuf == NULL) {
295  HECMW_set_error(errno, "");
296  goto error;
297  }
298  }
299 
300  /*
301  * broadcasting
302  */
303  rtc = HECMW_couple_bcast(n_pe_send, pe_send, sendbuf_size, sendbuf, n_pe_recv,
304  pe_recv, recvbuf_index, recvbuf, HECMW_INT,
305  intercomm->comm);
306  if (rtc != 0) goto error;
307 
308  if (comm_src->is_member) {
309  for (i = 0; i < comm_dst->psize; i++) {
310  all_mapped_point[i]->n = recvbuf[i];
311  }
312  }
313 
314  HECMW_free(sendbuf);
315  HECMW_free(pe_send);
316  HECMW_free(recvbuf_index);
317  HECMW_free(recvbuf);
318  HECMW_free(pe_recv);
319  return 0;
320 
321 error:
322  HECMW_free(sendbuf);
323  HECMW_free(pe_send);
324  HECMW_free(recvbuf_index);
325  HECMW_free(recvbuf);
326  HECMW_free(pe_recv);
327  return -1;
328 }
329 
330 static int bcast_mapped_point_d2s_coord(
331  const struct hecmw_couple_mapped_point *mapped_point,
332  const struct hecmw_couple_comm *comm_src,
333  const struct hecmw_couple_comm *comm_dst,
334  const struct hecmw_couple_comm *intercomm,
335  struct hecmw_couple_mapped_point **all_mapped_point) {
336  int n_pe_send = 0, n_pe_recv = 0, *pe_send = NULL, *pe_recv = NULL;
337  int sendbuf_size = 0, *recvbuf_index = NULL;
338  double *sendbuf = NULL, *recvbuf = NULL;
339  int node, size, rtc, i, j;
340 
341  /*
342  * send buffer (destination unit)
343  */
344  if (comm_dst->is_member) {
345  /* number of communication processes */
346  n_pe_send = comm_src->psize;
347 
348  /* communication processes */
349  pe_send = (int *)HECMW_malloc(sizeof(int) * n_pe_send);
350  if (pe_send == NULL) {
351  HECMW_set_error(errno, "");
352  goto error;
353  }
354  for (i = 0; i < n_pe_send; i++) {
355  pe_send[i] = comm_src->ranks[i];
356  }
357 
358  /* size of send buffer */
359  sendbuf_size = mapped_point->n * 3;
360 
361  /* send buffer */
362  sendbuf = (double *)HECMW_malloc(sizeof(double) * (sendbuf_size + 1));
363  if (sendbuf == NULL) {
364  HECMW_set_error(errno, "");
365  goto error;
366  }
367  for (i = 0; i < mapped_point->n * 3; i++) {
368  sendbuf[i] = mapped_point->coord[i];
369  }
370  }
371 
372  /*
373  * receive buffer (source unit)
374  */
375  if (comm_src->is_member) {
376  /* number of communication processes */
377  n_pe_recv = comm_dst->psize;
378 
379  /* communication processes */
380  pe_recv = (int *)HECMW_malloc(sizeof(int) * n_pe_recv);
381  if (pe_recv == NULL) {
382  HECMW_set_error(errno, "");
383  goto error;
384  }
385  for (i = 0; i < n_pe_recv; i++) {
386  pe_recv[i] = comm_dst->ranks[i];
387  }
388 
389  /* size of receive buffer */
390  recvbuf_index = (int *)HECMW_calloc(n_pe_recv + 1, sizeof(int));
391  if (recvbuf_index == NULL) {
392  HECMW_set_error(errno, "");
393  goto error;
394  }
395  for (i = 0; i < n_pe_recv; i++) {
396  recvbuf_index[i + 1] = recvbuf_index[i] + all_mapped_point[i]->n * 3;
397  }
398 
399  /* receive buffer */
400  recvbuf =
401  (double *)HECMW_malloc(sizeof(double) * (recvbuf_index[n_pe_recv] + 1));
402  if (recvbuf == NULL) {
403  HECMW_set_error(errno, "");
404  goto error;
405  }
406  }
407 
408  /* broadcast */
409  rtc = HECMW_couple_bcast(n_pe_send, pe_send, sendbuf_size, sendbuf, n_pe_recv,
410  pe_recv, recvbuf_index, recvbuf, HECMW_DOUBLE,
411  intercomm->comm);
412  if (rtc != 0) goto error;
413 
414  /* coordinates */
415  if (comm_src->is_member) {
416  for (i = 0; i < comm_dst->psize; i++) {
417  size = recvbuf_index[i + 1] - recvbuf_index[i];
418  HECMW_assert(size == all_mapped_point[i]->n * 3);
419  if (size == 0) continue;
420 
421  all_mapped_point[i]->coord =
422  (double *)HECMW_malloc(sizeof(double) * size);
423  if (all_mapped_point[i]->coord == NULL) {
424  HECMW_set_error(errno, "");
425  goto error;
426  }
427 
428  for (j = recvbuf_index[i]; j < recvbuf_index[i + 1]; j++) {
429  all_mapped_point[i]->coord[j - recvbuf_index[i]] = recvbuf[j];
430  }
431  }
432  }
433 
434  HECMW_free(sendbuf);
435  HECMW_free(pe_send);
436  HECMW_free(recvbuf_index);
437  HECMW_free(recvbuf);
438  HECMW_free(pe_recv);
439  return 0;
440 
441 error:
442  HECMW_free(sendbuf);
443  HECMW_free(pe_send);
444  HECMW_free(recvbuf_index);
445  HECMW_free(recvbuf);
446  HECMW_free(pe_recv);
447 
448  return -1;
449 }
450 
451 static int bcast_mapped_point_d2s(
452  const struct hecmw_couple_mapped_point *mapped_point,
453  const struct hecmw_couple_comm *comm_src,
454  const struct hecmw_couple_comm *comm_dst,
455  const struct hecmw_couple_comm *intercomm,
456  struct hecmw_couple_mapped_point **all_mapped_point) {
457  int rtc, i;
458 
459  if (comm_src->is_member) {
460  for (i = 0; i < comm_dst->psize; i++) {
461  all_mapped_point[i] = HECMW_couple_alloc_mapped_point();
462  if (all_mapped_point[i] == NULL) goto error;
463  }
464  }
465 
466  if (bcast_mapped_point_d2s_n(mapped_point, comm_src, comm_dst, intercomm,
467  all_mapped_point))
468  goto error;
469  if (bcast_mapped_point_d2s_coord(mapped_point, comm_src, comm_dst, intercomm,
470  all_mapped_point))
471  goto error;
472 
473  return 0;
474 
475 error:
476  if (all_mapped_point) {
477  for (i = 0; i < comm_dst->psize; i++) {
478  HECMW_couple_free_mapped_point(all_mapped_point[i]);
479  all_mapped_point[i] = NULL;
480  }
481  }
482  return -1;
483 }
484 
485 /*================================================================================================*/
486 
487 static int bcast_bbox_d2s(const struct hecmw_couple_bounding_box *bbox_dst,
488  const struct hecmw_couple_comm *comm_src,
489  const struct hecmw_couple_comm *comm_dst,
490  const struct hecmw_couple_comm *intercomm,
491  struct hecmw_couple_box *all_dst_bbox) {
492  int n_pe_send = 0, n_pe_recv = 0, *pe_send = NULL, *pe_recv = NULL;
493  int sendbuf_size = 0, *recvbuf_index = NULL;
494  double *sendbuf = NULL, *recvbuf = NULL;
495  int rtc, i;
496  int N_BOUNDING_BOX_MEMBER = 6;
497 
498  /*
499  * send buffer (destination unit)
500  */
501  if (comm_dst->is_member) {
502  /* number of neighboring processes */
503  n_pe_send = comm_src->psize;
504 
505  /* neighboring processes */
506  pe_send = (int *)HECMW_malloc(sizeof(int) * n_pe_send);
507  if (pe_send == NULL) {
508  HECMW_set_error(errno, "");
509  goto error;
510  }
511  for (i = 0; i < n_pe_send; i++) {
512  pe_send[i] = comm_src->ranks[i];
513  }
514 
515  /* size of send buffer */
516  sendbuf_size = N_BOUNDING_BOX_MEMBER;
517 
518  /* send buffer */
519  sendbuf = (double *)HECMW_malloc(sizeof(double) * (sendbuf_size + 1));
520  if (sendbuf == NULL) {
521  HECMW_set_error(errno, "");
522  goto error;
523  }
524 
525  sendbuf[0] = bbox_dst->enlarged->min_x;
526  sendbuf[1] = bbox_dst->enlarged->min_y;
527  sendbuf[2] = bbox_dst->enlarged->min_z;
528  sendbuf[3] = bbox_dst->enlarged->max_x;
529  sendbuf[4] = bbox_dst->enlarged->max_y;
530  sendbuf[5] = bbox_dst->enlarged->max_z;
531  }
532 
533  /*
534  * receive buffer (source unit)
535  */
536  if (comm_src->is_member) {
537  /* number of communication processes */
538  n_pe_recv = comm_dst->psize;
539 
540  /* communication processes */
541  pe_recv = (int *)HECMW_malloc(sizeof(int) * n_pe_recv);
542  if (pe_recv == NULL) {
543  HECMW_set_error(errno, "");
544  goto error;
545  }
546  for (i = 0; i < n_pe_recv; i++) {
547  pe_recv[i] = comm_dst->ranks[i];
548  }
549 
550  /* size of receive buffer */
551  recvbuf_index = (int *)HECMW_calloc(n_pe_recv + 1, sizeof(int));
552  if (recvbuf_index == NULL) {
553  HECMW_set_error(errno, "");
554  goto error;
555  }
556  for (i = 0; i < n_pe_recv; i++) {
557  recvbuf_index[i + 1] = recvbuf_index[i] + N_BOUNDING_BOX_MEMBER;
558  }
559 
560  /* receive buffer */
561  recvbuf =
562  (double *)HECMW_malloc(sizeof(double) * (recvbuf_index[n_pe_recv] + 1));
563  if (recvbuf == NULL) {
564  HECMW_set_error(errno, "");
565  goto error;
566  }
567  }
568 
569  /*
570  * send and receive
571  */
572  rtc = HECMW_couple_bcast(n_pe_send, pe_send, sendbuf_size, sendbuf, n_pe_recv,
573  pe_recv, recvbuf_index, recvbuf, HECMW_DOUBLE,
574  intercomm->comm);
575  if (rtc != 0) goto error;
576 
577  /*
578  * set received items
579  */
580  if (comm_src->is_member) {
581  for (i = 0; i < comm_dst->psize; i++) {
582  HECMW_assert(recvbuf_index[i + 1] - recvbuf_index[i] ==
583  N_BOUNDING_BOX_MEMBER);
584 
585  all_dst_bbox[i].min_x = recvbuf[recvbuf_index[i]];
586  all_dst_bbox[i].min_y = recvbuf[recvbuf_index[i] + 1];
587  all_dst_bbox[i].min_z = recvbuf[recvbuf_index[i] + 2];
588  all_dst_bbox[i].max_x = recvbuf[recvbuf_index[i] + 3];
589  all_dst_bbox[i].max_y = recvbuf[recvbuf_index[i] + 4];
590  all_dst_bbox[i].max_z = recvbuf[recvbuf_index[i] + 5];
591  }
592  }
593 
594  HECMW_free(sendbuf);
595  HECMW_free(pe_send);
596  HECMW_free(recvbuf_index);
597  HECMW_free(recvbuf);
598  HECMW_free(pe_recv);
599  return 0;
600 
601 error:
602  HECMW_free(sendbuf);
603  HECMW_free(pe_send);
604  HECMW_free(recvbuf_index);
605  HECMW_free(recvbuf);
606  HECMW_free(pe_recv);
607  return -1;
608 }
609 
610 /*------------------------------------------------------------------------------------------------*/
611 
612 static int check_bbox_within_bbox(const struct hecmw_couple_box *box_src,
613  const struct hecmw_couple_box *box_dst) {
614  if (box_dst->min_x <= box_src->max_x && box_dst->max_x >= box_src->min_x &&
615  box_dst->min_y <= box_src->max_y && box_dst->max_y >= box_src->min_y &&
616  box_dst->min_z <= box_src->max_z && box_dst->max_z >= box_src->min_z) {
617  return 1;
618  }
619 
620  return 0;
621 }
622 
623 static int check_node_within_bbox(
624  const struct hecmw_couple_box *box_src,
625  const struct hecmw_couple_mapped_point *mapped_point, int *is_candidate) {
626  double coord_x, coord_y, coord_z;
627  int n, i;
628 
629  for (n = 0, i = 0; i < mapped_point->n; i++) {
630  coord_x = mapped_point->coord[3 * i];
631  coord_y = mapped_point->coord[3 * i + 1];
632  coord_z = mapped_point->coord[3 * i + 2];
633 
634  if (coord_x >= box_src->min_x && coord_x <= box_src->max_x &&
635  coord_y >= box_src->min_y && coord_y <= box_src->max_y &&
636  coord_z >= box_src->min_z && coord_z <= box_src->max_z) {
637  is_candidate[i] = 1;
638  n++;
639  } else {
640  is_candidate[i] = 0;
641  }
642  }
643 
644  return (n != 0) ? 1 : 0;
645 }
646 
647 static int set_candidate_node(
648  const struct hecmw_couple_bounding_box *bbox_src,
649  const struct hecmw_couple_bounding_box *bbox_dst,
650  const struct hecmw_couple_comm *comm_src,
651  const struct hecmw_couple_comm *comm_dst,
652  const struct hecmw_couple_comm *intercomm,
653  struct hecmw_couple_mapped_point **all_mapped_point, int **is_candidate) {
654  struct hecmw_couple_box *all_dst_bbox = NULL;
655  int size, rtc, i;
656 
657  if (comm_src->is_member) {
658  size = sizeof(struct hecmw_couple_box) * comm_dst->psize;
659  all_dst_bbox = (struct hecmw_couple_box *)HECMW_malloc(size);
660  if (all_dst_bbox == NULL) {
661  HECMW_set_error(errno, "");
662  goto error;
663  }
664  for (i = 0; i < comm_dst->psize; i++) {
665  all_dst_bbox[i].min_x = 0.0;
666  all_dst_bbox[i].min_y = 0.0;
667  all_dst_bbox[i].min_z = 0.0;
668  all_dst_bbox[i].max_x = 0.0;
669  all_dst_bbox[i].max_y = 0.0;
670  all_dst_bbox[i].max_z = 0.0;
671  }
672  }
673 
674  /* broadcast bounding box information from destination unit to source unit */
675  if (bcast_bbox_d2s(bbox_dst, comm_src, comm_dst, intercomm, all_dst_bbox))
676  goto error;
677 
678  /* set candidate mapped nodes */
679  if (comm_src->is_member) {
680  for (i = 0; i < comm_dst->psize; i++) {
681  if (all_mapped_point[i]->n == 0) continue;
682 
683  is_candidate[i] =
684  (int *)HECMW_calloc(all_mapped_point[i]->n, sizeof(int));
685  if (is_candidate[i] == NULL) {
686  HECMW_set_error(errno, "");
687  goto error;
688  }
689 
690  if (check_bbox_within_bbox(bbox_src->enlarged, &all_dst_bbox[i])) {
691  check_node_within_bbox(bbox_src->enlarged, all_mapped_point[i],
692  is_candidate[i]);
693  }
694  }
695  }
696 
697  HECMW_free(all_dst_bbox);
698  return 0;
699 
700 error:
701  HECMW_free(all_dst_bbox);
702  if (is_candidate) {
703  for (i = 0; i < comm_dst->psize; i++) {
704  HECMW_free(is_candidate[i]);
705  is_candidate[i] = NULL;
706  }
707  }
708  return -1;
709 }
710 
711 /*================================================================================================*/
712 
713 static struct map_info_to_bgcell *map_node_to_bgcell(
714  const struct hecmwST_local_mesh *mesh_src,
715  const struct hecmw_couple_boundary *boundary_src,
716  const struct hecmw_couple_bounding_box *bbox_src,
717  const struct hecmw_couple_background_cell *bgcell_src) {
718  struct map_info_to_bgcell *map_to_bgcell = NULL;
719  struct link_list *bgcell_node_list = NULL, *p;
720  double coord_x, coord_y, coord_z;
721  int bgcell, node, ic, i, j, l, m, n;
722 
723  map_to_bgcell = (struct map_info_to_bgcell *)HECMW_malloc(
724  sizeof(struct map_info_to_bgcell));
725  if (map_to_bgcell == NULL) {
726  HECMW_set_error(errno, "");
727  goto error;
728  }
729  map_to_bgcell->index = NULL;
730  map_to_bgcell->id = NULL;
731 
732  if (bgcell_src->n == 0) return map_to_bgcell;
733 
734  /* linked list */
735  bgcell_node_list = (struct link_list *)HECMW_malloc(sizeof(struct link_list) *
736  bgcell_src->n);
737  if (bgcell_node_list == NULL) {
738  HECMW_set_error(errno, "");
739  goto error;
740  }
741  for (i = 0; i < bgcell_src->n; i++) {
742  bgcell_node_list[i].item = 0;
743  bgcell_node_list[i].next = NULL;
744  }
745 
746  for (ic = 0, i = 0; i < boundary_src->node->n; i++) {
747  node = boundary_src->node->item[i];
748  coord_x = mesh_src->node[3 * (node - 1)];
749  coord_y = mesh_src->node[3 * (node - 1) + 1];
750  coord_z = mesh_src->node[3 * (node - 1) + 2];
751 
752  l = (coord_x - bbox_src->enlarged->min_x) / bgcell_src->dx;
753  m = (coord_y - bbox_src->enlarged->min_y) / bgcell_src->dy;
754  n = (coord_z - bbox_src->enlarged->min_z) / bgcell_src->dz;
755 
756  if (l < 0) l = 0;
757  if (m < 0) m = 0;
758  if (n < 0) n = 0;
759  if (l >= bgcell_src->nx) l = bgcell_src->nx - 1;
760  if (m >= bgcell_src->ny) m = bgcell_src->ny - 1;
761  if (n >= bgcell_src->nz) n = bgcell_src->nz - 1;
762 
763  bgcell = bgcell_src->nx * bgcell_src->ny * n + bgcell_src->nx * m + l;
764 
765  p = (struct link_list *)HECMW_malloc(sizeof(struct link_list));
766  if (p == NULL) {
767  HECMW_set_error(errno, "");
768  goto error;
769  }
770  p->item = i;
771  p->next = bgcell_node_list[bgcell].next;
772  bgcell_node_list[bgcell].next = p;
773 
774  ic++;
775  }
776 
777  /* compressed 1-dimensional array */
778  map_to_bgcell->index = (int *)HECMW_calloc(bgcell_src->n + 1, sizeof(int));
779  if (map_to_bgcell->index == NULL) {
780  HECMW_set_error(errno, "");
781  goto error;
782  }
783  map_to_bgcell->id = (int *)HECMW_malloc(sizeof(int) * ic);
784  if (map_to_bgcell->id == NULL) {
785  HECMW_set_error(errno, "");
786  goto error;
787  }
788 
789  for (ic = 0, i = 0; i < bgcell_src->n; i++) {
790  p = bgcell_node_list[i].next;
791  while (p) {
792  map_to_bgcell->id[ic++] = p->item;
793  p = p->next;
794  }
795  map_to_bgcell->index[i + 1] = ic;
796  }
797 
798  /* free */
799  for (i = 0; i < bgcell_src->n; i++) {
800  free_link_list(bgcell_node_list[i].next);
801  }
802  HECMW_free(bgcell_node_list);
803 
804  return map_to_bgcell;
805 
806 error:
807  for (i = 0; i < bgcell_src->n; i++) {
808  free_link_list(bgcell_node_list[i].next);
809  }
810  HECMW_free(bgcell_node_list);
811  if (map_to_bgcell) {
812  HECMW_free(map_to_bgcell->index);
813  HECMW_free(map_to_bgcell->id);
814  }
815 
816  return NULL;
817 }
818 
819 static struct map_info_to_bgcell *map_elem_to_bgcell(
820  const struct hecmwST_local_mesh *mesh_src,
821  const struct hecmw_couple_boundary *boundary_src,
822  const struct hecmw_couple_bounding_box *bbox_src,
823  const struct hecmw_couple_background_cell *bgcell_src) {
824  struct map_info_to_bgcell *map_to_bgcell = NULL;
825  struct link_list *bgcell_elem_list = NULL, *p;
826  double coord_x, coord_y, coord_z, min_x, min_y, min_z, max_x, max_y, max_z;
827  int min_l, min_m, min_n, max_l, max_m, max_n;
828  int bgcell, elem, node, ic, i, l, m, n;
829  long long j;
830 
831  map_to_bgcell = (struct map_info_to_bgcell *)HECMW_malloc(
832  sizeof(struct map_info_to_bgcell));
833  if (map_to_bgcell == NULL) {
834  HECMW_set_error(errno, "");
835  goto error;
836  }
837  map_to_bgcell->index = NULL;
838  map_to_bgcell->id = NULL;
839 
840  if (bgcell_src->n == 0) return map_to_bgcell;
841 
842  /* linked list */
843  bgcell_elem_list = (struct link_list *)HECMW_malloc(sizeof(struct link_list) *
844  bgcell_src->n);
845  if (bgcell_elem_list == NULL) {
846  HECMW_set_error(errno, "");
847  goto error;
848  }
849  for (i = 0; i < bgcell_src->n; i++) {
850  bgcell_elem_list[i].item = 0;
851  bgcell_elem_list[i].next = NULL;
852  }
853 
854  for (ic = 0, i = 0; i < boundary_src->elem->n; i++) {
855  elem = boundary_src->elem->item[i];
856  min_x = min_y = min_z = +INFINITE;
857  max_x = max_y = max_z = -INFINITE;
858  for (j = mesh_src->elem_node_index[elem - 1];
859  j < mesh_src->elem_node_index[elem]; j++) {
860  node = mesh_src->elem_node_item[j];
861  coord_x = mesh_src->node[3 * (node - 1)];
862  coord_y = mesh_src->node[3 * (node - 1) + 1];
863  coord_z = mesh_src->node[3 * (node - 1) + 2];
864  if (coord_x < min_x) min_x = coord_x;
865  if (coord_y < min_y) min_y = coord_y;
866  if (coord_z < min_z) min_z = coord_z;
867  if (coord_x > max_x) max_x = coord_x;
868  if (coord_y > max_y) max_y = coord_y;
869  if (coord_z > max_z) max_z = coord_z;
870  }
871  min_x = min_x - (bbox_src->tolerance + EPS);
872  min_y = min_y - (bbox_src->tolerance + EPS);
873  min_z = min_z - (bbox_src->tolerance + EPS);
874  max_x = max_x + (bbox_src->tolerance + EPS);
875  max_y = max_y + (bbox_src->tolerance + EPS);
876  max_z = max_z + (bbox_src->tolerance + EPS);
877 
878  min_l = (min_x - bbox_src->enlarged->min_x) / bgcell_src->dx;
879  min_m = (min_y - bbox_src->enlarged->min_y) / bgcell_src->dy;
880  min_n = (min_z - bbox_src->enlarged->min_z) / bgcell_src->dz;
881  max_l = (max_x - bbox_src->enlarged->max_x) / bgcell_src->dx;
882  max_m = (max_y - bbox_src->enlarged->max_y) / bgcell_src->dy;
883  max_n = (max_z - bbox_src->enlarged->max_z) / bgcell_src->dz;
884 
885  if (min_l < 0) min_l = 0;
886  if (min_m < 0) min_m = 0;
887  if (min_n < 0) min_n = 0;
888  if (max_l < 0) max_l = 0;
889  if (max_m < 0) max_m = 0;
890  if (max_n < 0) max_n = 0;
891  if (min_l >= bgcell_src->nx) min_l = bgcell_src->nx - 1;
892  if (min_m >= bgcell_src->ny) min_m = bgcell_src->ny - 1;
893  if (min_n >= bgcell_src->nz) min_n = bgcell_src->nz - 1;
894  if (max_l >= bgcell_src->nx) max_l = bgcell_src->nx - 1;
895  if (max_m >= bgcell_src->ny) max_m = bgcell_src->ny - 1;
896  if (max_n >= bgcell_src->nz) max_n = bgcell_src->nz - 1;
897 
898  for (l = min_l; l <= max_l; l++) {
899  for (m = min_m; m <= max_m; m++) {
900  for (n = min_n; n <= max_n; n++) {
901  bgcell = bgcell_src->nx * bgcell_src->ny * n + bgcell_src->nx * m + l;
902 
903  p = (struct link_list *)HECMW_malloc(sizeof(struct link_list));
904  if (p == NULL) {
905  HECMW_set_error(errno, "");
906  goto error;
907  }
908  p->item = i;
909  p->next = bgcell_elem_list[bgcell].next;
910  bgcell_elem_list[bgcell].next = p;
911 
912  ic++;
913  }
914  }
915  }
916  }
917 
918  /* compressed 1-dimensional array */
919  map_to_bgcell->index = (int *)HECMW_calloc(bgcell_src->n + 1, sizeof(int));
920  if (map_to_bgcell->index == NULL) {
921  HECMW_set_error(errno, "");
922  goto error;
923  }
924  map_to_bgcell->id = (int *)HECMW_malloc(sizeof(int) * ic);
925  if (map_to_bgcell->id == NULL) {
926  HECMW_set_error(errno, "");
927  goto error;
928  }
929 
930  for (ic = 0, i = 0; i < bgcell_src->n; i++) {
931  p = bgcell_elem_list[i].next;
932  while (p) {
933  map_to_bgcell->id[ic++] = p->item;
934  p = p->next;
935  }
936  map_to_bgcell->index[i + 1] = ic;
937  }
938 
939  /* free */
940  for (i = 0; i < bgcell_src->n; i++) {
941  free_link_list(bgcell_elem_list[i].next);
942  }
943  HECMW_free(bgcell_elem_list);
944 
945  return map_to_bgcell;
946 
947 error:
948  for (i = 0; i < bgcell_src->n; i++) {
949  free_link_list(bgcell_elem_list[i].next);
950  }
951  HECMW_free(bgcell_elem_list);
952  if (map_to_bgcell) {
953  HECMW_free(map_to_bgcell->index);
954  HECMW_free(map_to_bgcell->id);
955  }
956  return NULL;
957 }
958 
959 static struct map_info_to_bgcell *map_surf_to_bgcell(
960  const struct hecmwST_local_mesh *mesh_src,
961  const struct hecmw_couple_boundary *boundary_src,
962  const struct hecmw_couple_bounding_box *bbox_src,
963  const struct hecmw_couple_background_cell *bgcell_src) {
964  struct map_info_to_bgcell *map_to_bgcell = NULL;
965  struct link_list *bgcell_surf_list = NULL, *p;
966  double coord_x, coord_y, coord_z, min_x, min_y, min_z, max_x, max_y, max_z;
967  int min_l, min_m, min_n, max_l, max_m, max_n;
968  int bgcell, elem, node, ic, i, l, m, n;
969  long long j;
970 
971  /* allocation */
972  map_to_bgcell = (struct map_info_to_bgcell *)HECMW_malloc(
973  sizeof(struct map_info_to_bgcell));
974  if (map_to_bgcell == NULL) {
975  HECMW_set_error(errno, "");
976  goto error;
977  }
978  map_to_bgcell->index = NULL;
979  map_to_bgcell->id = NULL;
980 
981  if (bgcell_src->n == 0) return map_to_bgcell;
982 
983  /* linked list */
984  bgcell_surf_list = (struct link_list *)HECMW_malloc(sizeof(struct link_list) *
985  bgcell_src->n);
986  if (bgcell_surf_list == NULL) {
987  HECMW_set_error(errno, "");
988  goto error;
989  }
990  for (i = 0; i < bgcell_src->n; i++) {
991  bgcell_surf_list[i].item = 0;
992  bgcell_surf_list[i].next = NULL;
993  }
994 
995  for (ic = 0, i = 0; i < boundary_src->surf->n; i++) {
996  elem = boundary_src->surf->item[2 * i];
997  min_x = min_y = min_z = +INFINITE;
998  max_x = max_y = max_z = -INFINITE;
999  for (j = mesh_src->elem_node_index[elem - 1];
1000  j < mesh_src->elem_node_index[elem]; j++) {
1001  node = mesh_src->elem_node_item[j];
1002  coord_x = mesh_src->node[3 * (node - 1)];
1003  coord_y = mesh_src->node[3 * (node - 1) + 1];
1004  coord_z = mesh_src->node[3 * (node - 1) + 2];
1005  if (coord_x < min_x) min_x = coord_x;
1006  if (coord_y < min_y) min_y = coord_y;
1007  if (coord_z < min_z) min_z = coord_z;
1008  if (coord_x > max_x) max_x = coord_x;
1009  if (coord_y > max_y) max_y = coord_y;
1010  if (coord_z > max_z) max_z = coord_z;
1011  }
1012  min_x = min_x - (bbox_src->tolerance + EPS);
1013  min_y = min_y - (bbox_src->tolerance + EPS);
1014  min_z = min_z - (bbox_src->tolerance + EPS);
1015  max_x = max_x + (bbox_src->tolerance + EPS);
1016  max_y = max_y + (bbox_src->tolerance + EPS);
1017  max_z = max_z + (bbox_src->tolerance + EPS);
1018 
1019  min_l = (min_x - bbox_src->enlarged->min_x) / bgcell_src->dx;
1020  min_m = (min_y - bbox_src->enlarged->min_y) / bgcell_src->dy;
1021  min_n = (min_z - bbox_src->enlarged->min_z) / bgcell_src->dz;
1022  max_l = (max_x - bbox_src->enlarged->min_x) / bgcell_src->dx;
1023  max_m = (max_y - bbox_src->enlarged->min_y) / bgcell_src->dy;
1024  max_n = (max_z - bbox_src->enlarged->min_z) / bgcell_src->dz;
1025 
1026  if (min_l < 0) min_l = 0;
1027  if (min_m < 0) min_m = 0;
1028  if (min_n < 0) min_n = 0;
1029  if (max_l < 0) max_l = 0;
1030  if (max_m < 0) max_m = 0;
1031  if (max_n < 0) max_n = 0;
1032  if (min_l >= bgcell_src->nx) min_l = bgcell_src->nx - 1;
1033  if (min_m >= bgcell_src->ny) min_m = bgcell_src->ny - 1;
1034  if (min_n >= bgcell_src->nz) min_n = bgcell_src->nz - 1;
1035  if (max_l >= bgcell_src->nx) max_l = bgcell_src->nx - 1;
1036  if (max_m >= bgcell_src->ny) max_m = bgcell_src->ny - 1;
1037  if (max_n >= bgcell_src->nz) max_n = bgcell_src->nz - 1;
1038 
1039  for (l = min_l; l <= max_l; l++) {
1040  for (m = min_m; m <= max_m; m++) {
1041  for (n = min_n; n <= max_n; n++) {
1042  bgcell = bgcell_src->nx * bgcell_src->ny * n + bgcell_src->nx * m + l;
1043  p = (struct link_list *)HECMW_malloc(sizeof(struct link_list));
1044  if (p == NULL) {
1045  HECMW_set_error(errno, "");
1046  goto error;
1047  }
1048  p->item = i;
1049  p->next = bgcell_surf_list[bgcell].next;
1050  bgcell_surf_list[bgcell].next = p;
1051 
1052  ic++;
1053  }
1054  }
1055  }
1056  }
1057 
1058  /* compressed 1-dimensional array */
1059  map_to_bgcell->index = (int *)HECMW_calloc(bgcell_src->n + 1, sizeof(int));
1060  if (map_to_bgcell->index == NULL) {
1061  HECMW_set_error(errno, "");
1062  goto error;
1063  }
1064  map_to_bgcell->id = (int *)HECMW_malloc(sizeof(int) * ic);
1065  if (map_to_bgcell->id == NULL) {
1066  HECMW_set_error(errno, "");
1067  goto error;
1068  }
1069 
1070  for (ic = 0, i = 0; i < bgcell_src->n; i++) {
1071  for (p = bgcell_surf_list[i].next; p; p = p->next) {
1072  map_to_bgcell->id[ic++] = p->item;
1073  }
1074  map_to_bgcell->index[i + 1] = ic;
1075  }
1076 
1077  /* free */
1078  for (i = 0; i < bgcell_src->n; i++) {
1079  free_link_list(bgcell_surf_list[i].next);
1080  }
1081  HECMW_free(bgcell_surf_list);
1082 
1083  return map_to_bgcell;
1084 
1085 error:
1086  for (i = 0; i < bgcell_src->n; i++) {
1087  free_link_list(bgcell_surf_list[i].next);
1088  }
1089  HECMW_free(bgcell_surf_list);
1090  if (map_to_bgcell) {
1091  HECMW_free(map_to_bgcell->index);
1092  HECMW_free(map_to_bgcell->id);
1093  }
1094  return NULL;
1095 }
1096 
1097 /*================================================================================================*/
1098 
1099 static int compare_mapping_info(int n_positive_old, double dot_product_old,
1100  double distance_old, int n_positive_new,
1101  double dot_product_new, double distance_new) {
1102  /*
1103  * 1st step: number of positive dot products
1104  */
1105  if (n_positive_old < 0) return 1; /* update */
1106  if (n_positive_new < n_positive_old) return 1; /* update */
1107  if (n_positive_new > n_positive_old) return 0; /* keep */
1108 
1109  /*
1110  * 2nd step: dot product (if number of positive dot products is positive)
1111  */
1112  /* n_positive_new = n_positive_old > 0 */
1113  /* if(n_positive_new > 0) { */
1114  if (dot_product_old > 0 && dot_product_new < 0) return 0; /* keep
1115  */
1116  if (dot_product_old < 0 && dot_product_new > 0) return 1; /* update */
1117  /* }*/
1118 
1119  /*
1120  * 3rd step: distance
1121  */
1122  if (distance_new < distance_old) return 1; /* update */
1123 
1124  return 0; /* keep */
1125 }
1126 
1127 static int map_point_to_surf(
1128  const struct hecmwST_local_mesh *mesh_src,
1129  const struct hecmw_couple_boundary *boundary_src,
1130  const struct hecmw_couple_bounding_box *bbox_src,
1131  const struct hecmw_couple_background_cell *bgcell_src,
1132  const struct hecmw_couple_mapped_point *mapped_point, int *is_candidate,
1133  const struct map_info_to_bgcell *map_to_bgcell, struct map_info *map_src) {
1134  double coord_x, coord_y, coord_z;
1135  int depth_x_before, depth_y_before, depth_z_before, depth_x_after,
1136  depth_y_after, depth_z_after;
1137  double dot_product, distance;
1138  int n_positive, elem, surf, bgcell, surf_id, nl, nm, nn, rtc, jstart, jfinal,
1139  i, j, l, m, n;
1140 
1141  map_src->n = mapped_point->n;
1142  if (map_src->n == 0) return 0;
1143 
1144  map_src->id = (int *)HECMW_malloc(sizeof(int) * map_src->n);
1145  if (map_src->id == NULL) {
1146  HECMW_set_error(errno, "");
1147  return -1;
1148  }
1149  map_src->n_positive = (int *)HECMW_malloc(sizeof(int) * map_src->n);
1150  if (map_src->n_positive == NULL) {
1151  HECMW_set_error(errno, "");
1152  return -1;
1153  }
1154  map_src->distance = (double *)HECMW_malloc(sizeof(double) * map_src->n);
1155  if (map_src->distance == NULL) {
1156  HECMW_set_error(errno, "");
1157  return -1;
1158  }
1159  map_src->dot_product = (double *)HECMW_malloc(sizeof(double) * map_src->n);
1160  if (map_src->dot_product == NULL) {
1161  HECMW_set_error(errno, "");
1162  return -1;
1163  }
1164  for (i = 0; i < map_src->n; i++) {
1165  map_src->id[i] = -1;
1166  map_src->n_positive[i] = -1;
1167  map_src->distance[i] = 0.0;
1168  map_src->dot_product[i] = 0.0;
1169  }
1170 
1171  for (i = 0; i < mapped_point->n; i++) {
1172  if (is_candidate[i] == 0) continue;
1173 
1174  coord_x = mapped_point->coord[3 * i];
1175  coord_y = mapped_point->coord[3 * i + 1];
1176  coord_z = mapped_point->coord[3 * i + 2];
1177 
1178  /* background cell which includes mapped node */
1179  nl = (coord_x - bbox_src->enlarged->min_x) / bgcell_src->dx;
1180  nm = (coord_y - bbox_src->enlarged->min_y) / bgcell_src->dy;
1181  nn = (coord_z - bbox_src->enlarged->min_z) / bgcell_src->dz;
1182  if (nl < 0) nl = 0;
1183  if (nm < 0) nm = 0;
1184  if (nn < 0) nn = 0;
1185  if (nl >= bgcell_src->nx) nl = bgcell_src->nx - 1;
1186  if (nm >= bgcell_src->ny) nm = bgcell_src->ny - 1;
1187  if (nn >= bgcell_src->nz) nn = bgcell_src->nz - 1;
1188 
1189  bgcell = bgcell_src->nx * bgcell_src->ny * nn + bgcell_src->nx * nm + nl;
1190 
1191  /* mapping */
1192  for (j = map_to_bgcell->index[bgcell]; j < map_to_bgcell->index[bgcell + 1];
1193  j++) {
1194  surf_id = map_to_bgcell->id[j];
1195  elem = boundary_src->surf->item[2 * surf_id];
1196  surf = boundary_src->surf->item[2 * surf_id + 1];
1197 
1198  if (mesh_src->elem_type[elem - 1] == HECMW_ETYPE_TET1) {
1199  n_positive =
1200  HECMW_couple_judge_tet1(mesh_src, elem, surf, coord_x, coord_y,
1201  coord_z, &dot_product, &distance);
1202  } else if (mesh_src->elem_type[elem - 1] == HECMW_ETYPE_HEX1) {
1203  n_positive =
1204  HECMW_couple_judge_hex1(mesh_src, elem, surf, coord_x, coord_y,
1205  coord_z, &dot_product, &distance);
1206  } else {
1208  return -1;
1209  }
1210 
1211  if (n_positive >= 0) {
1212  rtc = compare_mapping_info(
1213  map_src->n_positive[i], map_src->dot_product[i],
1214  map_src->distance[i], n_positive, dot_product, distance);
1215  if (rtc == 1) {
1216  map_src->n_positive[i] = n_positive;
1217  map_src->dot_product[i] = dot_product;
1218  map_src->distance[i] = distance;
1219  map_src->id[i] = surf_id;
1220  }
1221  }
1222  }
1223  }
1224 
1225  return 0;
1226 }
1227 
1228 static int mapping_in_src(const struct hecmwST_local_mesh *mesh_src,
1229  const struct hecmw_couple_boundary *boundary_src,
1230  const struct hecmw_couple_bounding_box *bbox_src,
1231  const struct hecmw_couple_background_cell *bgcell_src,
1232  const struct hecmw_couple_comm *comm_dst,
1233  struct hecmw_couple_mapped_point **all_mapped_point,
1234  int **is_candidate, struct map_info **map_src) {
1235  struct map_info_to_bgcell *map_to_bgcell = NULL;
1236  int map_type, i;
1237 
1238  /* mapping boundary surface to background cell */
1239  map_to_bgcell = (struct map_info_to_bgcell *)HECMW_malloc(
1240  sizeof(struct map_info_to_bgcell));
1241  if (map_to_bgcell == NULL) {
1242  HECMW_set_error(errno, "");
1243  goto error;
1244  }
1245  map_to_bgcell->index = NULL;
1246  map_to_bgcell->id = NULL;
1247 
1248  /* mapping boundary nodes on destination side to boundary surface on source
1249  * side */
1250  map_type = HECMW_COUPLE_MAP_SURF_TO_SURF; /*@@*/
1251 
1252  if (map_type == HECMW_COUPLE_MAP_SURF_TO_SURF) {
1253  map_to_bgcell =
1254  map_surf_to_bgcell(mesh_src, boundary_src, bbox_src, bgcell_src);
1255  if (map_to_bgcell == NULL) goto error;
1256 
1257  for (i = 0; i < comm_dst->psize; i++) {
1258  if (map_point_to_surf(mesh_src, boundary_src, bbox_src, bgcell_src,
1259  all_mapped_point[i], is_candidate[i], map_to_bgcell,
1260  map_src[i]))
1261  goto error;
1262  }
1263 
1264  } else {
1266  goto error;
1267  }
1268 
1269  if (map_to_bgcell) {
1270  HECMW_free(map_to_bgcell->index);
1271  HECMW_free(map_to_bgcell->id);
1272  HECMW_free(map_to_bgcell);
1273  }
1274  return 0;
1275 
1276 error:
1277  if (map_to_bgcell) {
1278  HECMW_free(map_to_bgcell->index);
1279  HECMW_free(map_to_bgcell->id);
1280  HECMW_free(map_to_bgcell);
1281  }
1282  if (map_src) {
1283  for (i = 0; i < comm_dst->psize; i++) {
1284  free_struct_map_info(map_src[i]);
1285  }
1286  HECMW_free(map_src);
1287  }
1288  return -1;
1289 }
1290 
1291 /*================================================================================================*/
1292 
1293 static int gather_id_s2d(struct map_info **map_src,
1294  const struct hecmw_couple_comm *comm_src,
1295  const struct hecmw_couple_comm *comm_dst,
1296  const struct hecmw_couple_comm *intercomm,
1297  struct map_info **map_dst) {
1298  int n_send_pe = 0, n_recv_pe = 0, *send_pe = NULL, *recv_pe = NULL;
1299  int *sendbuf_index = NULL, *recvbuf_index = NULL, *sendbuf = NULL,
1300  *recvbuf = NULL;
1301  int rtc, i, j;
1302 
1303  /*
1304  * send buffer (source unit)
1305  */
1306  if (comm_src->is_member) {
1307  /* number of communication processes */
1308  n_send_pe = comm_dst->psize;
1309 
1310  /* communication processes */
1311  send_pe = (int *)HECMW_malloc(sizeof(int) * n_send_pe);
1312  if (send_pe == NULL) {
1313  HECMW_set_error(errno, "");
1314  goto error;
1315  }
1316  for (i = 0; i < n_send_pe; i++) {
1317  send_pe[i] = comm_dst->ranks[i];
1318  }
1319 
1320  /* size of send buffer */
1321  sendbuf_index = (int *)HECMW_calloc(n_send_pe + 1, sizeof(int));
1322  if (sendbuf_index == NULL) {
1323  HECMW_set_error(errno, "");
1324  goto error;
1325  }
1326  for (i = 0; i < n_send_pe; i++) {
1327  sendbuf_index[i + 1] = sendbuf_index[i] + map_src[i]->n;
1328  }
1329 
1330  /* send buffer */
1331  sendbuf = (int *)HECMW_malloc(sizeof(int) * (sendbuf_index[n_send_pe] + 1));
1332  if (sendbuf == NULL) {
1333  HECMW_set_error(errno, "");
1334  goto error;
1335  }
1336  for (i = 0; i < comm_dst->psize; i++) {
1337  for (j = 0; j < map_src[i]->n; j++) {
1338  sendbuf[sendbuf_index[i] + j] = map_src[i]->id[j];
1339  }
1340  }
1341  }
1342 
1343  /*
1344  * receive buffer (destination unit)
1345  */
1346  if (comm_dst->is_member) {
1347  /* number of communication processes */
1348  n_recv_pe = comm_src->psize;
1349 
1350  /* communication processes */
1351  recv_pe = (int *)HECMW_malloc(sizeof(int) * n_recv_pe);
1352  if (recv_pe == NULL) {
1353  HECMW_set_error(errno, "");
1354  goto error;
1355  }
1356  for (i = 0; i < n_recv_pe; i++) {
1357  recv_pe[i] = comm_src->ranks[i];
1358  }
1359 
1360  /* size of receive buffer */
1361  recvbuf_index = (int *)HECMW_calloc(n_recv_pe + 1, sizeof(int));
1362  if (recvbuf_index == NULL) {
1363  HECMW_set_error(errno, "");
1364  goto error;
1365  }
1366  for (i = 0; i < n_recv_pe; i++) {
1367  recvbuf_index[i + 1] = recvbuf_index[i] + map_dst[i]->n;
1368  }
1369 
1370  /* receive buffer */
1371  recvbuf = (int *)HECMW_malloc(sizeof(int) * (recvbuf_index[n_recv_pe] + 1));
1372  if (recvbuf == NULL) {
1373  HECMW_set_error(errno, "");
1374  goto error;
1375  }
1376  }
1377 
1378  /*
1379  * send and receive
1380  */
1381  rtc = HECMW_couple_inter_send_recv(n_send_pe, send_pe, sendbuf_index, sendbuf,
1382  n_recv_pe, recv_pe, recvbuf_index, recvbuf,
1383  HECMW_INT, intercomm->comm);
1384  if (rtc != 0) goto error;
1385 
1386  /*
1387  * store received data
1388  */
1389  if (comm_dst->is_member) {
1390  for (i = 0; i < n_recv_pe; i++) {
1391  map_dst[i]->id = (int *)HECMW_calloc(map_dst[i]->n, sizeof(int));
1392  if (map_dst[i]->id == NULL) {
1393  HECMW_set_error(errno, "");
1394  goto error;
1395  }
1396  for (j = 0; j < map_dst[i]->n; j++) {
1397  map_dst[i]->id[j] = recvbuf[recvbuf_index[i] + j];
1398  }
1399  }
1400  }
1401 
1402  HECMW_free(send_pe);
1403  HECMW_free(sendbuf_index);
1404  HECMW_free(sendbuf);
1405  HECMW_free(recv_pe);
1406  HECMW_free(recvbuf_index);
1407  HECMW_free(recvbuf);
1408  return 0;
1409 
1410 error:
1411  HECMW_free(send_pe);
1412  HECMW_free(sendbuf_index);
1413  HECMW_free(sendbuf);
1414  HECMW_free(recv_pe);
1415  HECMW_free(recvbuf_index);
1416  HECMW_free(recvbuf);
1417  return -1;
1418 }
1419 
1420 static int gather_n_positive_s2d(struct map_info **map_src,
1421  const struct hecmw_couple_comm *comm_src,
1422  const struct hecmw_couple_comm *comm_dst,
1423  const struct hecmw_couple_comm *intercomm,
1424  struct map_info **map_dst) {
1425  int n_send_pe = 0, n_recv_pe = 0, *send_pe = NULL, *recv_pe = NULL;
1426  int *sendbuf_index = NULL, *recvbuf_index = NULL, *sendbuf = NULL,
1427  *recvbuf = NULL;
1428  int rtc, i, j;
1429 
1430  /*
1431  * send buffer (source unit)
1432  */
1433  if (comm_src->is_member) {
1434  /* number of communication processes */
1435  n_send_pe = comm_dst->psize;
1436 
1437  /* communication processes */
1438  send_pe = (int *)HECMW_malloc(sizeof(int) * n_send_pe);
1439  if (send_pe == NULL) {
1440  HECMW_set_error(errno, "");
1441  goto error;
1442  }
1443  for (i = 0; i < n_send_pe; i++) {
1444  send_pe[i] = comm_dst->ranks[i];
1445  }
1446 
1447  /* size of send buffer */
1448  sendbuf_index = (int *)HECMW_calloc(n_send_pe + 1, sizeof(int));
1449  if (sendbuf_index == NULL) {
1450  HECMW_set_error(errno, "");
1451  goto error;
1452  }
1453  for (i = 0; i < n_send_pe; i++) {
1454  sendbuf_index[i + 1] = sendbuf_index[i] + map_src[i]->n;
1455  }
1456 
1457  /* send buffer */
1458  sendbuf = (int *)HECMW_malloc(sizeof(int) * (sendbuf_index[n_send_pe] + 1));
1459  if (sendbuf == NULL) {
1460  HECMW_set_error(errno, "");
1461  goto error;
1462  }
1463  for (i = 0; i < comm_dst->psize; i++) {
1464  for (j = 0; j < map_src[i]->n; j++) {
1465  sendbuf[sendbuf_index[i] + j] = map_src[i]->n_positive[j];
1466  }
1467  }
1468  }
1469 
1470  /*
1471  * receive buffer (destination unit)
1472  */
1473  if (comm_dst->is_member) {
1474  /* number of communication processes */
1475  n_recv_pe = comm_src->psize;
1476 
1477  /* communication processes */
1478  recv_pe = (int *)HECMW_malloc(sizeof(int) * n_recv_pe);
1479  if (recv_pe == NULL) {
1480  HECMW_set_error(errno, "");
1481  goto error;
1482  }
1483  for (i = 0; i < n_recv_pe; i++) {
1484  recv_pe[i] = comm_src->ranks[i];
1485  }
1486 
1487  /* size of receive buffer */
1488  recvbuf_index = (int *)HECMW_calloc(n_recv_pe + 1, sizeof(int));
1489  if (recvbuf_index == NULL) {
1490  HECMW_set_error(errno, "");
1491  goto error;
1492  }
1493  for (i = 0; i < n_recv_pe; i++) {
1494  recvbuf_index[i + 1] = recvbuf_index[i] + map_dst[i]->n;
1495  }
1496 
1497  /* receive buffer */
1498  recvbuf = (int *)HECMW_malloc(sizeof(int) * (recvbuf_index[n_recv_pe] + 1));
1499  if (recvbuf == NULL) {
1500  HECMW_set_error(errno, "");
1501  goto error;
1502  }
1503  }
1504 
1505  /*
1506  * send and receive
1507  */
1508  rtc = HECMW_couple_inter_send_recv(n_send_pe, send_pe, sendbuf_index, sendbuf,
1509  n_recv_pe, recv_pe, recvbuf_index, recvbuf,
1510  HECMW_INT, intercomm->comm);
1511  if (rtc != 0) goto error;
1512 
1513  /*
1514  * store received data
1515  */
1516  if (comm_dst->is_member) {
1517  for (i = 0; i < n_recv_pe; i++) {
1518  map_dst[i]->n_positive = (int *)HECMW_calloc(map_dst[i]->n, sizeof(int));
1519  if (map_dst[i]->n_positive == NULL) {
1520  HECMW_set_error(errno, "");
1521  goto error;
1522  }
1523  for (j = 0; j < map_dst[i]->n; j++) {
1524  map_dst[i]->n_positive[j] = recvbuf[recvbuf_index[i] + j];
1525  }
1526  }
1527  }
1528 
1529  HECMW_free(send_pe);
1530  HECMW_free(sendbuf_index);
1531  HECMW_free(sendbuf);
1532  HECMW_free(recv_pe);
1533  HECMW_free(recvbuf_index);
1534  HECMW_free(recvbuf);
1535  return 0;
1536 
1537 error:
1538  HECMW_free(send_pe);
1539  HECMW_free(sendbuf_index);
1540  HECMW_free(sendbuf);
1541  HECMW_free(recv_pe);
1542  HECMW_free(recvbuf_index);
1543  HECMW_free(recvbuf);
1544  return -1;
1545 }
1546 
1547 static int gather_dot_product_s2d(struct map_info **map_src,
1548  const struct hecmw_couple_comm *comm_src,
1549  const struct hecmw_couple_comm *comm_dst,
1550  const struct hecmw_couple_comm *intercomm,
1551  struct map_info **map_dst) {
1552  int n_send_pe = 0, n_recv_pe = 0, *send_pe = NULL, *recv_pe = NULL;
1553  int *sendbuf_index = NULL, *recvbuf_index = NULL;
1554  double *sendbuf = NULL, *recvbuf = NULL;
1555  int rtc, i, j;
1556 
1557  /*
1558  * send buffer (source unit)
1559  */
1560  if (comm_src->is_member) {
1561  /* number of communication processes */
1562  n_send_pe = comm_dst->psize;
1563 
1564  /* communication processes */
1565  send_pe = (int *)HECMW_malloc(sizeof(int) * n_send_pe);
1566  if (send_pe == NULL) {
1567  HECMW_set_error(errno, "");
1568  goto error;
1569  }
1570  for (i = 0; i < n_send_pe; i++) {
1571  send_pe[i] = comm_dst->ranks[i];
1572  }
1573 
1574  /* index of send buffer */
1575  sendbuf_index = (int *)HECMW_calloc(n_send_pe + 1, sizeof(int));
1576  if (sendbuf_index == NULL) {
1577  HECMW_set_error(errno, "");
1578  goto error;
1579  }
1580  for (i = 0; i < n_send_pe; i++) {
1581  sendbuf_index[i + 1] = sendbuf_index[i] + map_src[i]->n;
1582  }
1583 
1584  /* send buffer */
1585  sendbuf =
1586  (double *)HECMW_malloc(sizeof(double) * (sendbuf_index[n_send_pe] + 1));
1587  if (sendbuf == NULL) {
1588  HECMW_set_error(errno, "");
1589  goto error;
1590  }
1591  for (i = 0; i < comm_dst->psize; i++) {
1592  for (j = 0; j < map_src[i]->n; j++) {
1593  sendbuf[sendbuf_index[i] + j] = map_src[i]->dot_product[j];
1594  }
1595  }
1596  }
1597 
1598  /*
1599  * receive buffer (destination unit)
1600  */
1601  if (comm_dst->is_member) {
1602  /* number of communication processes */
1603  n_recv_pe = comm_src->psize;
1604 
1605  /* communication processes */
1606  recv_pe = (int *)HECMW_malloc(sizeof(int) * n_recv_pe);
1607  if (recv_pe == NULL) {
1608  HECMW_set_error(errno, "");
1609  goto error;
1610  }
1611  for (i = 0; i < n_recv_pe; i++) {
1612  recv_pe[i] = comm_src->ranks[i];
1613  }
1614 
1615  /* index of receive buffer */
1616  recvbuf_index = (int *)HECMW_calloc(n_recv_pe + 1, sizeof(int));
1617  if (recvbuf_index == NULL) {
1618  HECMW_set_error(errno, "");
1619  goto error;
1620  }
1621  for (i = 0; i < n_recv_pe; i++) {
1622  recvbuf_index[i + 1] = recvbuf_index[i] + map_dst[i]->n;
1623  }
1624 
1625  /* receive buffer */
1626  recvbuf =
1627  (double *)HECMW_malloc(sizeof(double) * recvbuf_index[n_recv_pe] + 1);
1628  if (recvbuf == NULL) {
1629  HECMW_set_error(errno, "");
1630  goto error;
1631  }
1632  }
1633 
1634  /*
1635  * send and receive
1636  */
1637  rtc = HECMW_couple_inter_send_recv(n_send_pe, send_pe, sendbuf_index, sendbuf,
1638  n_recv_pe, recv_pe, recvbuf_index, recvbuf,
1639  HECMW_DOUBLE, intercomm->comm);
1640  if (rtc != 0) goto error;
1641 
1642  /*
1643  * store received data
1644  */
1645  if (comm_dst->is_member) {
1646  for (i = 0; i < n_recv_pe; i++) {
1647  map_dst[i]->dot_product =
1648  (double *)HECMW_malloc(sizeof(double) * map_dst[i]->n);
1649  if (map_dst[i]->dot_product == NULL) {
1650  HECMW_set_error(errno, "");
1651  goto error;
1652  }
1653  for (j = 0; j < map_dst[i]->n; j++) {
1654  map_dst[i]->dot_product[j] = recvbuf[recvbuf_index[i] + j];
1655  }
1656  }
1657  }
1658 
1659  HECMW_free(send_pe);
1660  HECMW_free(sendbuf_index);
1661  HECMW_free(sendbuf);
1662  HECMW_free(recv_pe);
1663  HECMW_free(recvbuf_index);
1664  HECMW_free(recvbuf);
1665  return 0;
1666 
1667 error:
1668  HECMW_free(send_pe);
1669  HECMW_free(sendbuf_index);
1670  HECMW_free(sendbuf);
1671  HECMW_free(recv_pe);
1672  HECMW_free(recvbuf_index);
1673  HECMW_free(recvbuf);
1674  return -1;
1675 }
1676 
1677 static int gather_distance_s2d(struct map_info **map_src,
1678  const struct hecmw_couple_comm *comm_src,
1679  const struct hecmw_couple_comm *comm_dst,
1680  const struct hecmw_couple_comm *intercomm,
1681  struct map_info **map_dst) {
1682  int n_send_pe = 0, n_recv_pe = 0, *send_pe = NULL, *recv_pe = NULL;
1683  int *sendbuf_index = NULL, *recvbuf_index = NULL;
1684  double *sendbuf = NULL, *recvbuf = NULL;
1685  int rtc, i, j;
1686 
1687  /*
1688  * send buffer (source unit)
1689  */
1690  if (comm_src->is_member) {
1691  /* number of communication processes */
1692  n_send_pe = comm_dst->psize;
1693 
1694  /* communication processes */
1695  send_pe = (int *)HECMW_malloc(sizeof(int) * n_send_pe);
1696  if (send_pe == NULL) {
1697  HECMW_set_error(errno, "");
1698  goto error;
1699  }
1700  for (i = 0; i < n_send_pe; i++) {
1701  send_pe[i] = comm_dst->ranks[i];
1702  }
1703 
1704  /* index of send buffer */
1705  sendbuf_index = (int *)HECMW_calloc(n_send_pe + 1, sizeof(int));
1706  if (sendbuf_index == NULL) {
1707  HECMW_set_error(errno, "");
1708  goto error;
1709  }
1710  for (i = 0; i < n_send_pe; i++) {
1711  sendbuf_index[i + 1] = sendbuf_index[i] + map_src[i]->n;
1712  }
1713 
1714  /* send buffer */
1715  sendbuf =
1716  (double *)HECMW_malloc(sizeof(double) * (sendbuf_index[n_send_pe] + 1));
1717  if (sendbuf == NULL) {
1718  HECMW_set_error(errno, "");
1719  goto error;
1720  }
1721  for (i = 0; i < comm_dst->psize; i++) {
1722  for (j = 0; j < map_src[i]->n; j++) {
1723  sendbuf[sendbuf_index[i] + j] = map_src[i]->distance[j];
1724  }
1725  }
1726  }
1727 
1728  /* receive buffer */
1729  if (comm_dst->is_member) {
1730  /* number of communication processes */
1731  n_recv_pe = comm_src->psize;
1732 
1733  /* communication processes */
1734  recv_pe = (int *)HECMW_malloc(sizeof(int) * n_recv_pe);
1735  if (recv_pe == NULL) {
1736  HECMW_set_error(errno, "");
1737  goto error;
1738  }
1739  for (i = 0; i < n_recv_pe; i++) {
1740  recv_pe[i] = comm_src->ranks[i];
1741  }
1742 
1743  /* index of receive buffer */
1744  recvbuf_index = (int *)HECMW_calloc(n_recv_pe + 1, sizeof(int));
1745  if (recvbuf_index == NULL) {
1746  HECMW_set_error(errno, "");
1747  goto error;
1748  }
1749  for (i = 0; i < n_recv_pe; i++) {
1750  recvbuf_index[i + 1] = recvbuf_index[i] + map_dst[i]->n;
1751  }
1752 
1753  /* receive buffer */
1754  recvbuf =
1755  (double *)HECMW_malloc(sizeof(double) * (recvbuf_index[n_recv_pe] + 1));
1756  if (recvbuf == NULL) {
1757  HECMW_set_error(errno, "");
1758  goto error;
1759  }
1760  }
1761 
1762  /*
1763  * send and receive
1764  */
1765  rtc = HECMW_couple_inter_send_recv(n_send_pe, send_pe, sendbuf_index, sendbuf,
1766  n_recv_pe, recv_pe, recvbuf_index, recvbuf,
1767  HECMW_DOUBLE, intercomm->comm);
1768  if (rtc != 0) goto error;
1769 
1770  /*
1771  * store received data
1772  */
1773  if (comm_dst->is_member) {
1774  for (i = 0; i < n_recv_pe; i++) {
1775  map_dst[i]->distance =
1776  (double *)HECMW_malloc(sizeof(double) * map_dst[i]->n);
1777  if (map_dst[i]->distance == NULL) {
1778  HECMW_set_error(errno, "");
1779  goto error;
1780  }
1781  for (j = 0; j < map_dst[i]->n; j++) {
1782  map_dst[i]->distance[j] = recvbuf[recvbuf_index[i] + j];
1783  }
1784  }
1785  }
1786 
1787  HECMW_free(send_pe);
1788  HECMW_free(sendbuf_index);
1789  HECMW_free(sendbuf);
1790  HECMW_free(recv_pe);
1791  HECMW_free(recvbuf_index);
1792  HECMW_free(recvbuf);
1793  return 0;
1794 
1795 error:
1796  HECMW_free(send_pe);
1797  HECMW_free(sendbuf_index);
1798  HECMW_free(sendbuf);
1799  HECMW_free(recv_pe);
1800  HECMW_free(recvbuf_index);
1801  HECMW_free(recvbuf);
1802  return -1;
1803 }
1804 
1805 /*------------------------------------------------------------------------------------------------*/
1806 
1807 static int gather_map_data_s2d(
1808  const struct hecmw_couple_mapped_point *mapped_point,
1809  struct map_info **map_src, const struct hecmw_couple_comm *comm_src,
1810  const struct hecmw_couple_comm *comm_dst,
1811  const struct hecmw_couple_comm *intercomm, struct map_info **map_dst) {
1812  int map_type, rtc, i;
1813 
1814  if (comm_dst->is_member) {
1815  for (i = 0; i < comm_src->psize; i++) {
1816  map_dst[i] = alloc_struct_map_info();
1817  if (map_dst[i] == NULL) goto error;
1818 
1819  map_dst[i]->n = mapped_point->n;
1820  }
1821  }
1822 
1823  /*@@@ map_type = HECMW_couple_get_map_type(boundary_id); @@@*/
1824  map_type = HECMW_COUPLE_MAP_NODE_TO_SURF;
1825 
1826  if (map_type == HECMW_COUPLE_MAP_NODE_TO_SURF) {
1827  if (gather_id_s2d(map_src, comm_src, comm_dst, intercomm, map_dst))
1828  goto error;
1829  if (gather_n_positive_s2d(map_src, comm_src, comm_dst, intercomm, map_dst))
1830  goto error;
1831  if (gather_dot_product_s2d(map_src, comm_src, comm_dst, intercomm, map_dst))
1832  goto error;
1833  if (gather_distance_s2d(map_src, comm_src, comm_dst, intercomm, map_dst))
1834  goto error;
1835 
1836  } else {
1838  goto error;
1839  }
1840 
1841  return 0;
1842 
1843 error:
1844  if (map_dst) {
1845  for (i = 0; i < comm_src->psize; i++) {
1846  free_struct_map_info(map_dst[i]);
1847  map_dst[i] = NULL;
1848  }
1849  }
1850  return -1;
1851 }
1852 
1853 /*================================================================================================*/
1854 
1855 static struct link_list_map *set_mapping_surf(
1856  const struct hecmw_couple_mapped_point *mapped_point,
1857  const struct hecmw_couple_comm *comm_src, struct map_info **map_dst) {
1858  struct link_list_map *mapping_data_list = NULL, *p;
1859  double _dot_product, _distance;
1860  int _n_positive, _item, pe_index, index, size, rtc, n, i, j;
1861 
1862  size = sizeof(struct link_list_map) * comm_src->psize;
1863  mapping_data_list = (struct link_list_map *)HECMW_malloc(size);
1864  if (mapping_data_list == NULL) {
1865  HECMW_set_error(errno, "");
1866  goto error;
1867  }
1868  for (i = 0; i < comm_src->psize; i++) {
1869  mapping_data_list[i].next = NULL;
1870  mapping_data_list[i].id = -1;
1871  mapping_data_list[i].item = -1;
1872  }
1873 
1874  for (n = 0, i = 0; i < mapped_point->n; i++) {
1875  _n_positive = -1;
1876 
1877  for (j = 0; j < comm_src->psize; j++) {
1878  if (map_dst[j]->n_positive[i] >= 0) {
1879  rtc = compare_mapping_info(
1880  _n_positive, _dot_product, _distance, map_dst[j]->n_positive[i],
1881  map_dst[j]->dot_product[i], map_dst[j]->distance[i]);
1882  if (rtc == 1) {
1883  pe_index = j;
1884  _item = map_dst[j]->id[i];
1885  _n_positive = map_dst[j]->n_positive[i];
1886  _dot_product = map_dst[j]->dot_product[i];
1887  _distance = map_dst[j]->distance[i];
1888  }
1889  }
1890  }
1891 
1892  if (_n_positive >= 0) {
1893  p = (struct link_list_map *)HECMW_malloc(sizeof(struct link_list_map));
1894  if (p == NULL) {
1895  HECMW_set_error(errno, "");
1896  goto error;
1897  }
1898  p->next = mapping_data_list[pe_index].next;
1899  p->id = mapped_point->id[n++];
1900  p->item = _item;
1901  mapping_data_list[pe_index].next = p;
1902  }
1903  }
1904 
1905  return mapping_data_list;
1906 
1907 error:
1908  if (mapping_data_list) {
1909  for (i = 0; i < comm_src->psize; i++) {
1910  free_link_list_map(mapping_data_list[i].next);
1911  }
1912  HECMW_free(mapping_data_list);
1913  }
1914 
1915  return NULL;
1916 }
1917 
1918 /*================================================================================================*/
1919 
1920 static int set_n_neighbor_pe_import(
1921  struct hecmw_couple_inter_iftable *inter_tbl,
1922  const struct hecmw_couple_comm *comm_src,
1923  struct link_list_map *mapping_data_list) {
1924  int n, i;
1925 
1926  for (n = 0, i = 0; i < comm_src->psize; i++) {
1927  if (mapping_data_list[i].next) n++;
1928  }
1929  inter_tbl->n_neighbor_pe_import = n;
1930 
1931  return 0;
1932 }
1933 
1934 static int set_neighbor_pe_import(struct hecmw_couple_inter_iftable *inter_tbl,
1935  const struct hecmw_couple_comm *comm_src,
1936  struct link_list_map *mapping_data_list) {
1937  int size, n, i;
1938 
1939  if (inter_tbl->n_neighbor_pe_import == 0) return 0;
1940 
1941  size = sizeof(int) * inter_tbl->n_neighbor_pe_import;
1942  inter_tbl->neighbor_pe_import = (int *)HECMW_malloc(size);
1943  if (inter_tbl->neighbor_pe_import == NULL) {
1944  HECMW_set_error(errno, "");
1945  return -1;
1946  }
1947  for (n = 0, i = 0; i < comm_src->psize; i++) {
1948  if (mapping_data_list[i].next) {
1949  inter_tbl->neighbor_pe_import[n++] = comm_src->ranks[i];
1950  }
1951  }
1952  HECMW_assert(n == inter_tbl->n_neighbor_pe_import);
1953 
1954  return 0;
1955 }
1956 
1957 static int set_import_index(struct hecmw_couple_inter_iftable *inter_tbl,
1958  const struct hecmw_couple_comm *comm_src,
1959  struct link_list_map *mapping_data_list) {
1960  struct link_list_map *p;
1961  int nmemb, m, n, i;
1962 
1963  nmemb = inter_tbl->n_neighbor_pe_import + 1;
1964  inter_tbl->import_index = (int *)HECMW_calloc(nmemb, sizeof(int));
1965  if (inter_tbl->import_index == NULL) {
1966  HECMW_set_error(errno, "");
1967  return -1;
1968  }
1969 
1970  for (m = 0, n = 0, i = 0; i < comm_src->psize; i++) {
1971  if (mapping_data_list[i].next) {
1972  for (p = mapping_data_list[i].next; p; p = p->next) {
1973  n++;
1974  }
1975  inter_tbl->import_index[++m] = n;
1976  }
1977  }
1978  HECMW_assert(m == inter_tbl->n_neighbor_pe_import);
1979 
1980  return 0;
1981 }
1982 
1983 static int set_import_item(struct hecmw_couple_inter_iftable *inter_tbl,
1984  const struct hecmw_couple_comm *comm_src,
1985  struct link_list_map *mapping_data_list) {
1986  struct link_list_map *p;
1987  int size, n, i;
1988 
1989  size = sizeof(int) * inter_tbl->import_index[inter_tbl->n_neighbor_pe_import];
1990  inter_tbl->import_item = (int *)HECMW_malloc(size);
1991  if (inter_tbl->import_item == NULL) {
1992  HECMW_set_error(errno, "");
1993  return -1;
1994  }
1995 
1996  for (n = 0, i = 0; i < comm_src->psize; i++) {
1997  if (mapping_data_list[i].next) {
1998  for (p = mapping_data_list[i].next; p; p = p->next) {
1999  inter_tbl->import_item[n++] = p->id;
2000  }
2001  HECMW_assert(n == inter_tbl->import_index[i + 1]);
2002  }
2003  }
2004 
2005  return 0;
2006 }
2007 
2008 /*------------------------------------------------------------------------------------------------*/
2009 
2010 static int *set_export_data(struct hecmw_couple_inter_iftable *inter_tbl,
2011  const struct hecmw_couple_comm *comm_src,
2012  struct link_list_map *mapping_data_list) {
2013  struct link_list_map *p;
2014  int *export_data = NULL;
2015  int size, n, i;
2016 
2017  size = sizeof(int) * inter_tbl->import_index[inter_tbl->n_neighbor_pe_import];
2018  export_data = (int *)HECMW_malloc(size);
2019  if (export_data == NULL) {
2020  HECMW_set_error(errno, "");
2021  return NULL;
2022  }
2023 
2024  for (n = 0, i = 0; i < comm_src->psize; i++) {
2025  if (mapping_data_list[i].next) {
2026  for (p = mapping_data_list[i].next; p; p = p->next) {
2027  export_data[n++] = p->item;
2028  }
2029  HECMW_assert(n == inter_tbl->import_index[i + 1]);
2030  }
2031  }
2032 
2033  return export_data;
2034 }
2035 
2036 static int set_neighbor_info_import(
2037  struct hecmw_couple_inter_iftable *inter_tbl,
2038  struct link_list_map *mapping_data_list,
2039  const struct hecmw_couple_comm *comm_src) {
2040  int i;
2041 
2042  /* number of neighboring domains */
2043  if (set_n_neighbor_pe_import(inter_tbl, comm_src, mapping_data_list))
2044  return -1;
2045 
2046  /* neighboring domain */
2047  if (set_neighbor_pe_import(inter_tbl, comm_src, mapping_data_list)) return -1;
2048 
2049  /* index for import node */
2050  if (set_import_index(inter_tbl, comm_src, mapping_data_list)) return -1;
2051 
2052  /* import node */
2053  if (set_import_item(inter_tbl, comm_src, mapping_data_list)) return -1;
2054 
2055  return 0;
2056 }
2057 
2058 /*------------------------------------------------------------------------------------------------*/
2059 
2060 static int set_neighbor_pe_export(
2061  struct hecmw_couple_inter_iftable *inter_tbl,
2062  const struct hecmw_couple_comm *comm_src,
2063  const struct hecmw_couple_comm *comm_dst,
2064  const struct hecmw_couple_comm *intercomm,
2065  const struct link_list_map *mapping_data_list) {
2066  int n_send_pe = 0, n_recv_pe = 0;
2067  int *send_pe = NULL, *recv_pe = NULL;
2068  int *sendbuf_index = NULL, *recvbuf_index = NULL, *sendbuf = NULL,
2069  *recvbuf = NULL;
2070  int size, rtc, n, i;
2071 
2072  /*
2073  * send buffer (destination unit)
2074  */
2075  if (comm_dst->is_member) {
2076  /* number of communication processes */
2077  n_send_pe = comm_src->psize;
2078 
2079  /* communication processes */
2080  send_pe = (int *)HECMW_malloc(sizeof(int) * n_send_pe);
2081  if (send_pe == NULL) {
2082  HECMW_set_error(errno, "");
2083  goto error;
2084  }
2085  for (i = 0; i < comm_src->psize; i++) {
2086  send_pe[i] = comm_src->ranks[i];
2087  }
2088 
2089  /* index of send buffer */
2090  sendbuf_index = (int *)HECMW_calloc(n_send_pe + 1, sizeof(int));
2091  if (sendbuf_index == NULL) {
2092  HECMW_set_error(errno, "");
2093  goto error;
2094  }
2095  for (i = 0; i < n_send_pe; i++) {
2096  sendbuf_index[i + 1] = sendbuf_index[i] + 1;
2097  }
2098 
2099  /* send buffer */
2100  sendbuf = (int *)HECMW_malloc(sizeof(int) * (sendbuf_index[n_send_pe] + 1));
2101  if (sendbuf == NULL) {
2102  HECMW_set_error(errno, "");
2103  goto error;
2104  }
2105  for (i = 0; i < n_send_pe; i++) {
2106  if (mapping_data_list[i].next) {
2107  sendbuf[i] = 1;
2108  } else {
2109  sendbuf[i] = 0;
2110  }
2111  }
2112  }
2113 
2114  /*
2115  * receive buffer (source unit)
2116  */
2117  if (comm_src->is_member) {
2118  /* number of communication processes */
2119  n_recv_pe = comm_dst->psize;
2120 
2121  /* communication processes */
2122  recv_pe = (int *)HECMW_malloc(sizeof(int) * n_recv_pe);
2123  if (recv_pe == NULL) {
2124  HECMW_set_error(errno, "");
2125  goto error;
2126  }
2127  for (i = 0; i < comm_dst->psize; i++) {
2128  recv_pe[i] = comm_dst->ranks[i];
2129  }
2130 
2131  /* index of receive buffer */
2132  recvbuf_index = (int *)HECMW_calloc(n_recv_pe + 1, sizeof(int));
2133  if (recvbuf_index == NULL) {
2134  HECMW_set_error(errno, "");
2135  goto error;
2136  }
2137  for (i = 0; i < n_recv_pe; i++) {
2138  recvbuf_index[i + 1] = recvbuf_index[i] + 1;
2139  }
2140 
2141  /* receive buffer */
2142  recvbuf = (int *)HECMW_malloc(sizeof(int) * (recvbuf_index[n_recv_pe] + 1));
2143  if (recvbuf == NULL) {
2144  HECMW_set_error(errno, "");
2145  goto error;
2146  }
2147  }
2148 
2149  /* send and receive */
2150  rtc = HECMW_couple_inter_send_recv(n_send_pe, send_pe, sendbuf_index, sendbuf,
2151  n_recv_pe, recv_pe, recvbuf_index, recvbuf,
2152  HECMW_INT, intercomm->comm);
2153  if (rtc != 0) goto error;
2154 
2155  /*
2156  * set neighbor process for inter-communication (source unit)
2157  */
2158  if (comm_src->is_member) {
2159  for (n = 0, i = 0; i < comm_dst->psize; i++) {
2160  if (recvbuf[i] > 0) n++;
2161  }
2162  inter_tbl->n_neighbor_pe_export = n;
2163 
2164  if (inter_tbl->n_neighbor_pe_export != 0) {
2165  size = sizeof(int) * inter_tbl->n_neighbor_pe_export;
2166  inter_tbl->neighbor_pe_export = (int *)HECMW_malloc(size);
2167  if (inter_tbl->neighbor_pe_export == NULL) {
2168  HECMW_set_error(errno, "");
2169  goto error;
2170  }
2171  for (n = 0, i = 0; i < comm_dst->psize; i++) {
2172  if (recvbuf[i] > 0) {
2173  inter_tbl->neighbor_pe_export[n++] = comm_dst->ranks[i];
2174  }
2175  }
2176  HECMW_assert(n == inter_tbl->n_neighbor_pe_export);
2177  }
2178  }
2179 
2180  HECMW_free(send_pe);
2181  HECMW_free(sendbuf_index);
2182  HECMW_free(sendbuf);
2183  HECMW_free(recv_pe);
2184  HECMW_free(recvbuf_index);
2185  HECMW_free(recvbuf);
2186  return 0;
2187 
2188 error:
2189  HECMW_free(send_pe);
2190  HECMW_free(sendbuf_index);
2191  HECMW_free(sendbuf);
2192  HECMW_free(recv_pe);
2193  HECMW_free(recvbuf_index);
2194  HECMW_free(recvbuf);
2195  return -1;
2196 }
2197 
2198 static int set_export_index(struct hecmw_couple_inter_iftable *inter_tbl,
2199  const struct hecmw_couple_comm *comm_src,
2200  const struct hecmw_couple_comm *comm_dst,
2201  const struct hecmw_couple_comm *intercomm) {
2202  int *sendbuf_index = NULL, *recvbuf_index = NULL, *sendbuf = NULL,
2203  *recvbuf = NULL;
2204  int size, rtc, i;
2205 
2206  /*
2207  * send buffer (destination unit)
2208  */
2209  if (comm_dst->is_member) {
2210  /* index of send buffer */
2211  sendbuf_index =
2212  (int *)HECMW_calloc(inter_tbl->n_neighbor_pe_import + 1, sizeof(int));
2213  if (sendbuf_index == NULL) {
2214  HECMW_set_error(errno, "");
2215  goto error;
2216  }
2217  for (i = 0; i < inter_tbl->n_neighbor_pe_import; i++) {
2218  sendbuf_index[i + 1] = sendbuf_index[i] + 1;
2219  }
2220 
2221  /* send buffer */
2222  sendbuf = (int *)HECMW_malloc(sizeof(int) *
2223  (inter_tbl->n_neighbor_pe_import + 1));
2224  if (sendbuf == NULL) {
2225  HECMW_set_error(errno, "");
2226  goto error;
2227  }
2228  for (i = 0; i < inter_tbl->n_neighbor_pe_import; i++) {
2229  sendbuf[i] = inter_tbl->import_index[i + 1] - inter_tbl->import_index[i];
2230  }
2231  }
2232 
2233  /*
2234  * receive buffer (source unit)
2235  */
2236  if (comm_src->is_member) {
2237  /* index of receive buffer */
2238  recvbuf_index =
2239  (int *)HECMW_calloc(inter_tbl->n_neighbor_pe_export + 1, sizeof(int));
2240  if (recvbuf_index == NULL) {
2241  HECMW_set_error(errno, "");
2242  goto error;
2243  }
2244  for (i = 0; i < inter_tbl->n_neighbor_pe_export; i++) {
2245  recvbuf_index[i + 1] = recvbuf_index[i] + 1;
2246  }
2247 
2248  /* receive buffer */
2249  recvbuf = (int *)HECMW_malloc(sizeof(int) *
2250  (inter_tbl->n_neighbor_pe_export + 1));
2251  if (recvbuf == NULL) {
2252  HECMW_set_error(errno, "");
2253  goto error;
2254  }
2255  }
2256 
2257  if (inter_tbl->n_neighbor_pe_import == 0 &&
2258  inter_tbl->n_neighbor_pe_export == 0)
2259  return HECMW_SUCCESS;
2260 
2261  /*
2262  * send and receive
2263  */
2265  inter_tbl->n_neighbor_pe_import, inter_tbl->neighbor_pe_import,
2266  sendbuf_index, sendbuf, inter_tbl->n_neighbor_pe_export,
2267  inter_tbl->neighbor_pe_export, recvbuf_index, recvbuf, HECMW_INT,
2268  intercomm->comm);
2269  if (rtc != 0) goto error;
2270 
2271  /*
2272  * set index of export node for inter-communication (source unit)
2273  */
2274  if (comm_src->is_member) {
2275  inter_tbl->export_index = NULL;
2276  if (inter_tbl->n_neighbor_pe_export != 0) {
2277  size = inter_tbl->n_neighbor_pe_export + 1;
2278  inter_tbl->export_index = (int *)HECMW_calloc(size, sizeof(int));
2279  if (inter_tbl->export_index == NULL) {
2280  HECMW_set_error(errno, "");
2281  goto error;
2282  }
2283  for (i = 0; i < inter_tbl->n_neighbor_pe_export; i++) {
2284  inter_tbl->export_index[i + 1] =
2285  inter_tbl->export_index[i] + recvbuf[i];
2286  }
2287  }
2288  }
2289 
2290  HECMW_free(sendbuf_index);
2291  HECMW_free(sendbuf);
2292  HECMW_free(recvbuf_index);
2293  HECMW_free(recvbuf);
2294  return 0;
2295 
2296 error:
2297  HECMW_free(sendbuf_index);
2298  HECMW_free(sendbuf);
2299  HECMW_free(recvbuf_index);
2300  HECMW_free(recvbuf);
2301  return -1;
2302 }
2303 
2304 static int set_export_item(struct hecmw_couple_inter_iftable *inter_tbl,
2305  const struct hecmw_couple_comm *comm_src,
2306  const struct hecmw_couple_comm *comm_dst,
2307  const struct hecmw_couple_comm *intercomm,
2308  int *export_data) {
2309  int size, rtc, i;
2310 
2311  if (inter_tbl->n_neighbor_pe_import == 0 &&
2312  inter_tbl->n_neighbor_pe_export == 0)
2313  return 0;
2314 
2315  /*
2316  * receive buffer (source unit)
2317  */
2318  if (comm_src->is_member) {
2319  /* receive buffer */
2320  size = sizeof(int) *
2321  (inter_tbl->export_index[inter_tbl->n_neighbor_pe_export] + 1);
2322  inter_tbl->export_item = (int *)HECMW_malloc(size);
2323  if (inter_tbl->export_item == NULL) {
2324  HECMW_set_error(errno, "");
2325  goto error;
2326  }
2327  }
2328 
2329  /*
2330  * send and receive
2331  */
2333  inter_tbl->n_neighbor_pe_import, inter_tbl->neighbor_pe_import,
2334  inter_tbl->import_index, export_data, inter_tbl->n_neighbor_pe_export,
2335  inter_tbl->neighbor_pe_export, inter_tbl->export_index,
2336  inter_tbl->export_item, HECMW_INT, intercomm->comm);
2337  if (rtc != 0) goto error;
2338 
2339  return 0;
2340 
2341 error:
2342  return -1;
2343 }
2344 
2345 static struct hecmw_couple_inter_iftable *set_inter_iftable(
2346  const struct hecmw_couple_comm *comm_src,
2347  const struct hecmw_couple_comm *comm_dst,
2348  const struct hecmw_couple_comm *intercomm, struct map_info **map_dst,
2349  const struct hecmw_couple_mapped_point *mapped_point) {
2350  struct hecmw_couple_inter_iftable *inter_tbl = NULL;
2351  struct link_list_map *mapping_data_list = NULL;
2352  int *export_data = NULL;
2353  int rtc;
2354 
2355  /* allocation */
2356  inter_tbl = HECMW_couple_alloc_inter_iftable();
2357  if (inter_tbl == NULL) goto error;
2358 
2359  /* import side */
2360  if (comm_dst->is_member) {
2361  mapping_data_list = set_mapping_surf(mapped_point, comm_src, map_dst);
2362  if (mapping_data_list == NULL) goto error;
2363 
2364  rtc = set_neighbor_info_import(inter_tbl, mapping_data_list, comm_src);
2365  if (rtc != HECMW_SUCCESS) goto error;
2366 
2367  export_data = set_export_data(inter_tbl, comm_src, mapping_data_list);
2368  if (export_data == NULL) goto error;
2369  }
2370 
2371  /* export side */
2372  rtc = set_neighbor_pe_export(inter_tbl, comm_src, comm_dst, intercomm,
2373  mapping_data_list);
2374  if (rtc != HECMW_SUCCESS) goto error;
2375 
2376  rtc = set_export_index(inter_tbl, comm_src, comm_dst, intercomm);
2377  if (rtc != HECMW_SUCCESS) goto error;
2378 
2379  rtc = set_export_item(inter_tbl, comm_src, comm_dst, intercomm, export_data);
2380  if (rtc != HECMW_SUCCESS) goto error;
2381 
2382  /* finalization */
2383  HECMW_free(export_data);
2384  return inter_tbl;
2385 
2386 error:
2387  HECMW_free(export_data);
2388  return NULL;
2389 }
2390 
2391 /*================================================================================================*/
2392 
2394  const struct hecmwST_local_mesh *mesh_src,
2395  const struct hecmwST_local_mesh *mesh_dst,
2396  const struct hecmw_couple_comm *comm_src,
2397  const struct hecmw_couple_comm *comm_dst,
2398  const struct hecmw_couple_comm *intercomm,
2399  const struct hecmw_couple_boundary *boundary_src,
2400  const struct hecmw_couple_bounding_box *bbox_src,
2401  const struct hecmw_couple_bounding_box *bbox_dst,
2402  const struct hecmw_couple_background_cell *bgcell_src,
2403  const struct hecmw_couple_mapped_point *mapped_point) {
2404  struct hecmw_couple_inter_iftable *inter_tbl = NULL;
2405  struct hecmw_couple_mapped_point **all_mapped_point = NULL;
2406  struct map_info **map_src = NULL, **map_dst = NULL;
2407  int **is_candidate = NULL;
2408  int size, rtc, i;
2409 
2410  if (comm_src->is_member) {
2411  size = sizeof(struct hecmw_couple_mapped_point *) * comm_dst->psize;
2412  all_mapped_point = (struct hecmw_couple_mapped_point **)HECMW_malloc(size);
2413  if (all_mapped_point == NULL) {
2414  HECMW_set_error(errno, "");
2415  goto error;
2416  }
2417  for (i = 0; i < comm_dst->psize; i++) {
2418  all_mapped_point[i] = NULL;
2419  }
2420 
2421  is_candidate = (int **)HECMW_malloc(sizeof(int *) * comm_dst->psize);
2422  if (is_candidate == NULL) {
2423  HECMW_set_error(errno, "");
2424  goto error;
2425  }
2426  for (i = 0; i < comm_dst->psize; i++) {
2427  is_candidate[i] = NULL;
2428  }
2429  }
2430 
2431  rtc = bcast_mapped_point_d2s(mapped_point, comm_src, comm_dst, intercomm,
2432  all_mapped_point);
2433  if (rtc != HECMW_SUCCESS) goto error;
2434 
2435  rtc = set_candidate_node(bbox_src, bbox_dst, comm_src, comm_dst, intercomm,
2436  all_mapped_point, is_candidate);
2437  if (rtc != HECMW_SUCCESS) goto error;
2438 
2439  /* */
2440  if (comm_src->is_member) {
2441  map_src = (struct map_info **)HECMW_malloc(sizeof(struct map_info *) *
2442  comm_dst->psize);
2443  if (map_src == NULL) {
2444  HECMW_set_error(errno, "");
2445  goto error;
2446  }
2447  for (i = 0; i < comm_dst->psize; i++) {
2448  map_src[i] = NULL;
2449  }
2450  for (i = 0; i < comm_dst->psize; i++) {
2451  map_src[i] = alloc_struct_map_info();
2452  if (map_src[i] == NULL) goto error;
2453  }
2454  }
2455 
2456  /* mapping on source unit */
2457  if (comm_src->is_member) {
2458  rtc = mapping_in_src(mesh_src, boundary_src, bbox_src, bgcell_src, comm_dst,
2459  all_mapped_point, is_candidate, map_src);
2460  if (rtc != HECMW_SUCCESS) goto error;
2461  }
2462 
2463  if (all_mapped_point) {
2464  for (i = 0; i < comm_dst->psize; i++) {
2465  HECMW_couple_free_mapped_point(all_mapped_point[i]);
2466  }
2467  HECMW_free(all_mapped_point);
2468  }
2469  if (is_candidate) {
2470  for (i = 0; i < comm_dst->psize; i++) {
2471  HECMW_free(is_candidate[i]);
2472  }
2473  HECMW_free(is_candidate);
2474  }
2475 
2476  /* mapping on destination unit */
2477  if (comm_dst->is_member) {
2478  map_dst = (struct map_info **)HECMW_malloc(sizeof(struct map_info *) *
2479  comm_dst->psize);
2480  if (map_dst == NULL) {
2481  HECMW_set_error(errno, "");
2482  goto error;
2483  }
2484  for (i = 0; i < comm_src->psize; i++) {
2485  map_dst[i] = NULL;
2486  }
2487  }
2488 
2489  rtc = gather_map_data_s2d(mapped_point, map_src, comm_src, comm_dst,
2490  intercomm, map_dst);
2491  if (rtc != HECMW_SUCCESS) goto error;
2492 
2493  /* construct interface table for inter-communicate */
2494  inter_tbl =
2495  set_inter_iftable(comm_src, comm_dst, intercomm, map_dst, mapped_point);
2496  if (inter_tbl == NULL) goto error;
2497 
2498  return inter_tbl;
2499 
2500 error:
2501  if (all_mapped_point) {
2502  for (i = 0; i < comm_dst->psize; i++) {
2503  HECMW_couple_free_mapped_point(all_mapped_point[i]);
2504  }
2505  HECMW_free(all_mapped_point);
2506  }
2507  if (is_candidate) {
2508  for (i = 0; i < comm_dst->psize; i++) {
2509  HECMW_free(is_candidate[i]);
2510  }
2511  HECMW_free(is_candidate);
2512  }
2513  return NULL;
2514 }
if(!(yy_init))
Definition: hecmw_ablex.c:1823
#define HECMW_ETYPE_HEX1
#define HECMW_ETYPE_TET1
#define HECMW_INT
Definition: hecmw_config.h:48
#define HECMW_DOUBLE
Definition: hecmw_config.h:50
#define HECMW_SUCCESS
Definition: hecmw_config.h:66
int HECMW_couple_bcast(int n_neighbor_pe_send, int *neighbor_pe_send, int sendbuf_size, void *sendbuf, int n_neighbor_pe_recv, int *neighbor_pe_recv, int *recvbuf_index, void *recvbuf, HECMW_Datatype datatype, HECMW_Comm comm)
int HECMW_couple_inter_send_recv(int n_neighbor_pe_send, int *neighbor_pe_send, int *sendbuf_index, void *sendbuf, int n_neighbor_pe_recv, int *neighbor_pe_recv, int *recvbuf_index, void *recvbuf, HECMW_Datatype datatype, HECMW_Comm comm)
#define HECMWCPL_E_INVALID_MAPTYPE
#define HECMW_COUPLE_MAP_SURF_TO_SURF
#define HECMWCPL_E_NONSUPPORT_ETYPE
#define HECMW_COUPLE_MAP_NODE_TO_SURF
void HECMW_couple_free_inter_iftable(struct hecmw_couple_inter_iftable *p)
#define EPS
#define INFINITE
struct hecmw_couple_inter_iftable * HECMW_couple_alloc_inter_iftable(void)
struct hecmw_couple_inter_iftable * HECMW_couple_set_map_data(const struct hecmwST_local_mesh *mesh_src, const struct hecmwST_local_mesh *mesh_dst, const struct hecmw_couple_comm *comm_src, const struct hecmw_couple_comm *comm_dst, const struct hecmw_couple_comm *intercomm, const struct hecmw_couple_boundary *boundary_src, const struct hecmw_couple_bounding_box *bbox_src, const struct hecmw_couple_bounding_box *bbox_dst, const struct hecmw_couple_background_cell *bgcell_src, const struct hecmw_couple_mapped_point *mapped_point)
void HECMW_couple_print_inter_iftable(const struct hecmw_couple_inter_iftable *p, FILE *fp)
int HECMW_couple_judge_hex1(const struct hecmwST_local_mesh *local_mesh, int elem, int surf_id, double coord_px, double coord_py, double coord_pz, double *dot_product, double *distance)
int HECMW_couple_judge_tet1(const struct hecmwST_local_mesh *local_mesh, int elem, int surf_id, double coord_px, double coord_py, double coord_pz, double *dot_product, double *distance)
struct hecmw_couple_mapped_point * HECMW_couple_alloc_mapped_point(void)
void HECMW_couple_free_mapped_point(struct hecmw_couple_mapped_point *p)
int HECMW_set_error(int errorno, const char *fmt,...)
Definition: hecmw_error.c:37
#define NULL
#define HECMW_calloc(nmemb, size)
Definition: hecmw_malloc.h:21
#define HECMW_free(ptr)
Definition: hecmw_malloc.h:24
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
#define HECMW_assert(cond)
Definition: hecmw_util.h:40
struct hecmw_couple_boundary_item * elem
struct hecmw_couple_boundary_item * node
struct hecmw_couple_boundary_item * surf
struct hecmw_couple_box * enlarged
long long * elem_node_index
Definition: hecmw_struct.h:195
struct link_list * list