FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecmw_couple_mapped_point.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_etype.h"
17 
18 #include "hecmw_couple_define.h"
19 #include "hecmw_couple_struct.h"
21 
22 /*================================================================================================*/
23 
25  struct hecmw_couple_mapped_point *p = NULL;
26 
28  sizeof(struct hecmw_couple_mapped_point));
29  if (p == NULL) {
30  HECMW_set_error(errno, "");
31  return NULL;
32  }
33  p->n = 0;
35  p->item = NULL;
36  p->id = NULL;
37  p->coord = NULL;
38 
39  return p;
40 }
41 
43  struct hecmw_couple_mapped_point *p) {
44  if (p == NULL) return;
45 
46  HECMW_free(p->item);
47  HECMW_free(p->id);
48  HECMW_free(p->coord);
49  HECMW_free(p);
50  p = NULL;
51 }
52 
53 /*================================================================================================*/
54 
55 static struct hecmw_couple_mapped_point *set_mapped_point_by_node(
56  const struct hecmwST_local_mesh *mesh_dst,
57  const struct hecmw_couple_boundary *boundary_dst) {
58  struct hecmw_couple_mapped_point *mapped_point = NULL;
59  int node, i;
60 
61  mapped_point = HECMW_couple_alloc_mapped_point();
62  if (mapped_point == NULL) return NULL;
63 
64  mapped_point->n = boundary_dst->node->n;
65  mapped_point->type = HECMW_COUPLE_NODE_GROUP;
66 
67  mapped_point->item = (int *)HECMW_malloc(sizeof(int) * mapped_point->n);
68  if (mapped_point->item == NULL) {
69  HECMW_set_error(errno, "");
70  goto error;
71  }
72  mapped_point->id = (int *)HECMW_malloc(sizeof(int) * mapped_point->n);
73  if (mapped_point->item == NULL) {
74  HECMW_set_error(errno, "");
75  goto error;
76  }
77  mapped_point->coord =
78  (double *)HECMW_malloc(sizeof(double) * mapped_point->n * 3);
79  if (mapped_point->coord == NULL) {
80  HECMW_set_error(errno, "");
81  goto error;
82  }
83 
84  for (i = 0; i < boundary_dst->node->n; i++) {
85  node = boundary_dst->node->item[i];
86  mapped_point->item[i] = node;
87  mapped_point->id[i] = i;
88  mapped_point->coord[3 * i] = mesh_dst->node[3 * (node - 1)];
89  mapped_point->coord[3 * i + 1] = mesh_dst->node[3 * (node - 1) + 1];
90  mapped_point->coord[3 * i + 2] = mesh_dst->node[3 * (node - 1) + 2];
91  }
92 
93  return mapped_point;
94 
95 error:
96  HECMW_couple_free_mapped_point(mapped_point);
97  return NULL;
98 }
99 
100 static struct hecmw_couple_mapped_point *set_mapped_point_by_elem(
101  const struct hecmwST_local_mesh *mesh_dst,
102  const struct hecmw_couple_boundary *boundary_dst) {
103  struct hecmw_couple_mapped_point *mapped_point = NULL;
104  double coord_x_sum, coord_y_sum, coord_z_sum;
105  int elem, node, max_node, i;
106  long long j;
107 
108  mapped_point = HECMW_couple_alloc_mapped_point();
109  if (mapped_point == NULL) return NULL;
110 
111  mapped_point->n = boundary_dst->elem->n;
112  mapped_point->type = HECMW_COUPLE_ELEMENT_GROUP;
113 
114  mapped_point->item = (int *)HECMW_malloc(sizeof(int) * mapped_point->n);
115  if (mapped_point->item == NULL) {
116  HECMW_set_error(errno, "");
117  goto error;
118  }
119  mapped_point->id = (int *)HECMW_malloc(sizeof(int) * mapped_point->n);
120  if (mapped_point->id == NULL) {
121  HECMW_set_error(errno, "");
122  goto error;
123  }
124  mapped_point->coord =
125  (double *)HECMW_malloc(sizeof(double) * mapped_point->n);
126  if (mapped_point->coord == NULL) {
127  HECMW_set_error(errno, "");
128  goto error;
129  }
130 
131  for (i = 0; i < mapped_point->n; i++) {
132  coord_x_sum = coord_y_sum = coord_z_sum = 0.0;
133  elem = boundary_dst->elem->item[i];
134  max_node = HECMW_get_max_node(mesh_dst->elem_type[elem - 1]);
135  for (j = mesh_dst->elem_node_index[elem - 1];
136  j < mesh_dst->elem_node_index[elem]; j++) {
137  node = mesh_dst->elem_node_item[j];
138  coord_x_sum += mesh_dst->node[3 * (node - 1)];
139  coord_y_sum += mesh_dst->node[3 * (node - 1) + 1];
140  coord_z_sum += mesh_dst->node[3 * (node - 1) + 2];
141  }
142  mapped_point->item[i] = elem;
143  mapped_point->id[i] = i;
144  mapped_point->coord[3 * i] = coord_x_sum / max_node;
145  mapped_point->coord[3 * i + 1] = coord_x_sum / max_node;
146  mapped_point->coord[3 * i + 2] = coord_x_sum / max_node;
147  }
148 
149  return mapped_point;
150 
151 error:
152  HECMW_couple_free_mapped_point(mapped_point);
153  return NULL;
154 }
155 
156 static struct hecmw_couple_mapped_point *set_mapped_point_by_surf(
157  const struct hecmwST_local_mesh *mesh_dst,
158  const struct hecmw_couple_boundary *boundary_dst) {
159  struct hecmw_couple_mapped_point *mapped_point = NULL;
160 
161  /*@@@ NOT implementing @@@*/
162  goto error;
163 
164  return mapped_point;
165 
166 error:
167  HECMW_couple_free_mapped_point(mapped_point);
168  return NULL;
169 }
170 
172  const char *boundary_id, const struct hecmwST_local_mesh *mesh_dst,
173  const struct hecmw_couple_boundary *boundary_dst) {
174  struct hecmw_couple_mapped_point *mapped_point = NULL;
175  int map_type;
176 
177  if (mesh_dst == NULL) {
179  "Invalid NULL pointer is found (mesh_dst)");
180  return NULL;
181  }
182  if (boundary_dst == NULL) {
184  "Invalid NULL pointer is found (boundary_dst)");
185  return NULL;
186  }
187 
189 
190  if (map_type == HECMW_COUPLE_MAP_NODE_TO_SURF) {
191  if ((mapped_point = set_mapped_point_by_node(mesh_dst, boundary_dst)) ==
192  NULL)
193  goto error;
194  } else {
196  goto error;
197  }
198 
199  return mapped_point;
200 
201 error:
202  HECMW_couple_free_mapped_point(mapped_point);
203  return NULL;
204 }
#define HECMW_COUPLE_ELEMENT_GROUP
#define HECMWCPL_E_INVALID_MAPTYPE
#define HECMW_COUPLE_NODE_GROUP
#define HECMW_COUPLE_MAP_UNDEF
#define HECMW_COUPLE_MAP_NODE_TO_SURF
#define HECMWCPL_E_INVALID_ARG
struct hecmw_couple_mapped_point * HECMW_couple_alloc_mapped_point(void)
struct hecmw_couple_mapped_point * HECMW_couple_set_mapped_point(const char *boundary_id, const struct hecmwST_local_mesh *mesh_dst, const struct hecmw_couple_boundary *boundary_dst)
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
int HECMW_get_max_node(int etype)
Definition: hecmw_etype.c:413
#define NULL
#define HECMW_free(ptr)
Definition: hecmw_malloc.h:24
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
struct hecmw_couple_boundary_item * elem
struct hecmw_couple_boundary_item * node
long long * elem_node_index
Definition: hecmw_struct.h:195