FrontISTR  5.7.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, j;
106 
107  mapped_point = HECMW_couple_alloc_mapped_point();
108  if (mapped_point == NULL) return NULL;
109 
110  mapped_point->n = boundary_dst->elem->n;
111  mapped_point->type = HECMW_COUPLE_ELEMENT_GROUP;
112 
113  mapped_point->item = (int *)HECMW_malloc(sizeof(int) * mapped_point->n);
114  if (mapped_point->item == NULL) {
115  HECMW_set_error(errno, "");
116  goto error;
117  }
118  mapped_point->id = (int *)HECMW_malloc(sizeof(int) * mapped_point->n);
119  if (mapped_point->id == NULL) {
120  HECMW_set_error(errno, "");
121  goto error;
122  }
123  mapped_point->coord =
124  (double *)HECMW_malloc(sizeof(double) * mapped_point->n);
125  if (mapped_point->coord == NULL) {
126  HECMW_set_error(errno, "");
127  goto error;
128  }
129 
130  for (i = 0; i < mapped_point->n; i++) {
131  coord_x_sum = coord_y_sum = coord_z_sum = 0.0;
132  elem = boundary_dst->elem->item[i];
133  max_node = HECMW_get_max_node(mesh_dst->elem_type[elem - 1]);
134  for (j = mesh_dst->elem_node_index[elem - 1];
135  j < mesh_dst->elem_node_index[elem]; j++) {
136  node = mesh_dst->elem_node_item[j];
137  coord_x_sum += mesh_dst->node[3 * (node - 1)];
138  coord_y_sum += mesh_dst->node[3 * (node - 1) + 1];
139  coord_z_sum += mesh_dst->node[3 * (node - 1) + 2];
140  }
141  mapped_point->item[i] = elem;
142  mapped_point->id[i] = i;
143  mapped_point->coord[3 * i] = coord_x_sum / max_node;
144  mapped_point->coord[3 * i + 1] = coord_x_sum / max_node;
145  mapped_point->coord[3 * i + 2] = coord_x_sum / max_node;
146  }
147 
148  return mapped_point;
149 
150 error:
151  HECMW_couple_free_mapped_point(mapped_point);
152  return NULL;
153 }
154 
155 static struct hecmw_couple_mapped_point *set_mapped_point_by_surf(
156  const struct hecmwST_local_mesh *mesh_dst,
157  const struct hecmw_couple_boundary *boundary_dst) {
158  struct hecmw_couple_mapped_point *mapped_point = NULL;
159 
160  /*@@@ NOT implementing @@@*/
161  goto error;
162 
163  return mapped_point;
164 
165 error:
166  HECMW_couple_free_mapped_point(mapped_point);
167  return NULL;
168 }
169 
171  const char *boundary_id, const struct hecmwST_local_mesh *mesh_dst,
172  const struct hecmw_couple_boundary *boundary_dst) {
173  struct hecmw_couple_mapped_point *mapped_point = NULL;
174  int map_type;
175 
176  if (mesh_dst == NULL) {
178  "Invalid NULL pointer is found (mesh_dst)");
179  return NULL;
180  }
181  if (boundary_dst == NULL) {
183  "Invalid NULL pointer is found (boundary_dst)");
184  return NULL;
185  }
186 
188 
189  if (map_type == HECMW_COUPLE_MAP_NODE_TO_SURF) {
190  if ((mapped_point = set_mapped_point_by_node(mesh_dst, boundary_dst)) ==
191  NULL)
192  goto error;
193  } else {
195  goto error;
196  }
197 
198  return mapped_point;
199 
200 error:
201  HECMW_couple_free_mapped_point(mapped_point);
202  return NULL;
203 }
hecmw_etype.h
hecmw_couple_mapped_point.h
hecmw_couple_mapped_point::id
int * id
Definition: hecmw_couple_mapped_point.h:19
HECMW_couple_alloc_mapped_point
struct hecmw_couple_mapped_point * HECMW_couple_alloc_mapped_point(void)
Definition: hecmw_couple_mapped_point.c:24
hecmwST_local_mesh::elem_node_item
int * elem_node_item
Definition: hecmw_struct.h:196
HECMW_malloc
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
hecmwST_local_mesh
Definition: hecmw_struct.h:139
hecmwST_local_mesh::elem_type
int * elem_type
Definition: hecmw_struct.h:191
hecmw_couple_mapped_point::n
int n
Definition: hecmw_couple_mapped_point.h:16
hecmw_couple_boundary_item::n
int n
Definition: hecmw_couple_boundary_info.h:17
hecmw_couple_boundary
Definition: hecmw_couple_boundary_info.h:18
hecmw_error.h
HECMW_COUPLE_ELEMENT_GROUP
#define HECMW_COUPLE_ELEMENT_GROUP
Definition: hecmw_couple_define.h:37
hecmw_struct.h
hecmwST_local_mesh::node
double * node
Definition: hecmw_struct.h:170
hecmw_msgno.h
HECMW_COUPLE_NODE_GROUP
#define HECMW_COUPLE_NODE_GROUP
Definition: hecmw_couple_define.h:35
hecmwST_local_mesh::elem_node_index
int * elem_node_index
Definition: hecmw_struct.h:195
HECMW_get_max_node
int HECMW_get_max_node(int etype)
Definition: hecmw_etype.c:413
hecmw_couple_boundary::elem
struct hecmw_couple_boundary_item * elem
Definition: hecmw_couple_boundary_info.h:22
hecmw_couple_mapped_point::coord
double * coord
Definition: hecmw_couple_mapped_point.h:20
hecmw_couple_struct.h
HECMW_COUPLE_MAP_NODE_TO_SURF
#define HECMW_COUPLE_MAP_NODE_TO_SURF
Definition: hecmw_couple_define.h:67
HECMW_COUPLE_MAP_UNDEF
#define HECMW_COUPLE_MAP_UNDEF
Definition: hecmw_couple_define.h:61
hecmw_common_define.h
hecmw_couple_mapped_point
Definition: hecmw_couple_mapped_point.h:12
HECMW_couple_set_mapped_point
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)
Definition: hecmw_couple_mapped_point.c:170
HECMWCPL_E_INVALID_MAPTYPE
#define HECMWCPL_E_INVALID_MAPTYPE
Definition: hecmw_couple_define.h:173
HECMW_couple_free_mapped_point
void HECMW_couple_free_mapped_point(struct hecmw_couple_mapped_point *p)
Definition: hecmw_couple_mapped_point.c:42
hecmw_couple_mapped_point::item
int * item
Definition: hecmw_couple_mapped_point.h:18
hecmw_couple_boundary::node
struct hecmw_couple_boundary_item * node
Definition: hecmw_couple_boundary_info.h:21
HECMW_set_error
int HECMW_set_error(int errorno, const char *fmt,...)
Definition: hecmw_error.c:37
NULL
#define NULL
Definition: hecmw_io_nastran.c:30
HECMWCPL_E_INVALID_ARG
#define HECMWCPL_E_INVALID_ARG
Definition: hecmw_couple_define.h:91
HECMW_free
#define HECMW_free(ptr)
Definition: hecmw_malloc.h:24
hecmw_couple_boundary_item::item
int * item
Definition: hecmw_couple_boundary_info.h:18
hecmw_couple_define.h
hecmw_couple_mapped_point::type
int type
Definition: hecmw_couple_mapped_point.h:17