FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
hecmw_couple_bounding_box.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_msgno.h"
13 #include "hecmw_struct.h"
14 #include "hecmw_error.h"
15 
16 #include "hecmw_couple_define.h"
17 #include "hecmw_couple_struct.h"
18 #include "hecmw_couple_control.h"
21 
22 #define INFINITE (1.0E+37)
23 
24 /*================================================================================================*/
25 
27  struct hecmw_couple_bounding_box *bbox) {
28  if (bbox == NULL) return;
29 
30  HECMW_free(bbox->just);
31  HECMW_free(bbox->enlarged);
32  HECMW_free(bbox);
33  bbox = NULL;
34 }
35 
36 static struct hecmw_couple_bounding_box *alloc_struct_bbox(void) {
37  struct hecmw_couple_bounding_box *bbox = NULL;
38  int size;
39 
40  size = sizeof(struct hecmw_couple_bounding_box);
41  bbox = (struct hecmw_couple_bounding_box *)HECMW_malloc(size);
42  if (bbox == NULL) {
43  HECMW_set_error(errno, "");
44  return NULL;
45  }
46  bbox->just = NULL;
47  bbox->enlarged = NULL;
48 
49  bbox->just =
50  (struct hecmw_couple_box *)HECMW_malloc(sizeof(struct hecmw_couple_box));
51  if (bbox->just == NULL) {
52  HECMW_set_error(errno, "");
53  goto error;
54  }
55  bbox->enlarged =
56  (struct hecmw_couple_box *)HECMW_malloc(sizeof(struct hecmw_couple_box));
57  if (bbox->enlarged == NULL) {
58  HECMW_set_error(errno, "");
59  goto error;
60  }
61 
62  bbox->coef = 0.0;
63  bbox->tolerance = 0.0;
64 
65  bbox->just->min_x = 0.0;
66  bbox->just->min_y = 0.0;
67  bbox->just->min_z = 0.0;
68  bbox->just->max_x = 0.0;
69  bbox->just->max_y = 0.0;
70  bbox->just->max_z = 0.0;
71 
72  bbox->enlarged->min_x = 0.0;
73  bbox->enlarged->min_y = 0.0;
74  bbox->enlarged->min_z = 0.0;
75  bbox->enlarged->max_x = 0.0;
76  bbox->enlarged->max_y = 0.0;
77  bbox->enlarged->max_z = 0.0;
78 
79  return bbox;
80 
81 error:
83  return NULL;
84 }
85 
86 /*================================================================================================*/
87 
89  const char *boundary_id, const struct hecmwST_local_mesh *mesh,
90  const struct hecmw_couple_boundary *boundary) {
91  struct hecmw_couple_bounding_box *bbox = NULL;
92  double length_x, length_y, length_z, coord_x, coord_y, coord_z, half_coef;
93  double min_x, min_y, min_z, max_x, max_y, max_z;
94  int elem, node, i, j;
95 
96  if (boundary_id == NULL) {
98  "HECMW_couple_set_bounding_box(): 'boundary_id' is NULL");
99  return NULL;
100  }
101  if (mesh == NULL) {
103  "HECMW_couple_set_bounding_box(): 'mesh' is NULL");
104  return NULL;
105  }
106  if (boundary == NULL) {
108  "HECMW_couple_set_bounding_box(): 'boundary' is NULL");
109  return NULL;
110  }
111 
112  /* allocation & initialization */
113  if ((bbox = alloc_struct_bbox()) == NULL) return NULL;
114 
115  HECMW_couple_ctrl_get_tolerance(boundary_id, &bbox->tolerance);
116  if (bbox->tolerance < 0.0) goto error;
117  HECMW_couple_ctrl_get_bbcoef(boundary_id, &bbox->coef);
118  if (bbox->coef < 0.0) goto error;
119 
120  if (boundary->node->n == 0) return bbox;
121 
122  min_x = min_y = min_z = +INFINITE;
123  max_x = max_y = max_z = -INFINITE;
124 
125  if (boundary->geom_type == HECMW_COUPLE_NODE_GROUP) { /* node group */
127  "In current version, node group is not supported");
128  goto error;
129 
130  /*
131  for(i=0; i<boundary->node->n; i++) {
132  node = boundary->node->item[i];
133  coord_x = mesh->node[3*(node-1) ];
134  coord_y = mesh->node[3*(node-1)+1];
135  coord_z = mesh->node[3*(node-1)+2];
136 
137  if(coord_x < min_x) min_x = coord_x;
138  if(coord_y < min_y) min_y = coord_y;
139  if(coord_z < min_z) min_z = coord_z;
140  if(coord_x > max_x) max_x = coord_x;
141  if(coord_y > max_y) max_y = coord_y;
142  if(coord_z > max_z) max_z = coord_z;
143  }
144  */
145 
146  } else if (boundary->geom_type ==
147  HECMW_COUPLE_ELEMENT_GROUP) { /* element group */
149  "In current version, element group is not supported");
150  goto error;
151 
152  /*
153  for(i=0; i<boundary->node->n; i++) {
154  node = boundary->node->item[i];
155  coord_x = mesh->node[3*(node-1) ];
156  coord_y = mesh->node[3*(node-1)+1];
157  coord_z = mesh->node[3*(node-1)+2];
158 
159  if(coord_x < min_x) min_x = coord_x;
160  if(coord_y < min_y) min_y = coord_y;
161  if(coord_z < min_z) min_z = coord_z;
162  if(coord_x > max_x) max_x = coord_x;
163  if(coord_y > max_y) max_y = coord_y;
164  if(coord_z > max_z) max_z = coord_z;
165  }
166  */
167 
168  } else if (boundary->geom_type ==
169  HECMW_COUPLE_SURFACE_GROUP) { /* surface group */
170  for (i = 0; i < boundary->surf->n; i++) {
171  elem = boundary->surf->item[2 * i];
172  for (j = mesh->elem_node_index[elem - 1]; j < mesh->elem_node_index[elem];
173  j++) {
174  node = mesh->elem_node_item[j];
175  coord_x = mesh->node[3 * (node - 1)];
176  coord_y = mesh->node[3 * (node - 1) + 1];
177  coord_z = mesh->node[3 * (node - 1) + 2];
178 
179  if (coord_x < min_x) min_x = coord_x;
180  if (coord_y < min_y) min_y = coord_y;
181  if (coord_z < min_z) min_z = coord_z;
182  if (coord_x > max_x) max_x = coord_x;
183  if (coord_y > max_y) max_y = coord_y;
184  if (coord_z > max_z) max_z = coord_z;
185  }
186  }
187 
188  } else { /* error */
190  goto error;
191  }
192 
193  /* just size bounding box */
194  bbox->just->min_x = min_x;
195  bbox->just->min_y = min_y;
196  bbox->just->min_z = min_z;
197  bbox->just->max_x = max_x;
198  bbox->just->max_y = max_y;
199  bbox->just->max_z = max_z;
200 
201  /* enlarged size bounding box */
202  half_coef = (bbox->coef - 1.0) * 0.5;
203  length_x = bbox->just->max_x - bbox->just->min_x;
204  length_y = bbox->just->max_y - bbox->just->min_y;
205  length_z = bbox->just->max_z - bbox->just->min_z;
206 
207  if (length_x > half_coef) {
208  bbox->enlarged->min_x = min_x - length_x * half_coef;
209  bbox->enlarged->max_x = max_x + length_x * half_coef;
210  } else {
211  bbox->enlarged->min_x = min_x - half_coef;
212  bbox->enlarged->max_x = max_x + half_coef;
213  }
214  if (length_y > half_coef) {
215  bbox->enlarged->min_y = min_y - length_y * half_coef;
216  bbox->enlarged->max_y = max_y + length_y * half_coef;
217  } else {
218  bbox->enlarged->min_y = min_y - half_coef;
219  bbox->enlarged->max_y = max_y + half_coef;
220  }
221  if (length_z > half_coef) {
222  bbox->enlarged->min_z = min_z - length_z * half_coef;
223  bbox->enlarged->max_z = max_z + length_z * half_coef;
224  } else {
225  bbox->enlarged->min_z = min_z - half_coef;
226  bbox->enlarged->max_z = max_z + half_coef;
227  }
228 
229  return bbox;
230 
231 error:
233  return NULL;
234 }
hecmw_couple_boundary::surf
struct hecmw_couple_boundary_item * surf
Definition: hecmw_couple_boundary_info.h:23
hecmw_couple_boundary::geom_type
int geom_type
Definition: hecmw_couple_boundary_info.h:19
hecmw_couple_bounding_box.h
hecmw_couple_bounding_box::coef
double coef
Definition: hecmw_couple_bounding_box.h:23
HECMW_couple_ctrl_get_tolerance
int HECMW_couple_ctrl_get_tolerance(const char *boundary_id, double *tolerance)
Definition: hecmw_couple_control.c:1834
hecmw_couple_box::max_x
double max_x
Definition: hecmw_couple_bounding_box.h:19
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
hecmw_couple_box::max_y
double max_y
Definition: hecmw_couple_bounding_box.h:20
mesh
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
HECMW_couple_free_bounding_box
void HECMW_couple_free_bounding_box(struct hecmw_couple_bounding_box *bbox)
Definition: hecmw_couple_bounding_box.c:26
hecmwST_local_mesh
Definition: hecmw_struct.h:139
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_bounding_box::enlarged
struct hecmw_couple_box * enlarged
Definition: hecmw_couple_bounding_box.h:25
hecmw_couple_box::min_z
double min_z
Definition: hecmw_couple_bounding_box.h:18
INFINITE
#define INFINITE
Definition: hecmw_couple_bounding_box.c:22
HECMW_COUPLE_ELEMENT_GROUP
#define HECMW_COUPLE_ELEMENT_GROUP
Definition: hecmw_couple_define.h:37
hecmw_couple_box::min_y
double min_y
Definition: hecmw_couple_bounding_box.h:17
hecmw_struct.h
hecmwST_local_mesh::node
double * node
Definition: hecmw_struct.h:170
hecmw_couple_control.h
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_COUPLE_SURFACE_GROUP
#define HECMW_COUPLE_SURFACE_GROUP
Definition: hecmw_couple_define.h:39
hecmw_couple_bounding_box::just
struct hecmw_couple_box * just
Definition: hecmw_couple_bounding_box.h:24
HECMWCPL_E_INVALID_GEOMTYPE
#define HECMWCPL_E_INVALID_GEOMTYPE
Definition: hecmw_couple_define.h:167
hecmw_couple_struct.h
hecmw_couple_boundary_info.h
HECMW_couple_set_bounding_box
struct hecmw_couple_bounding_box * HECMW_couple_set_bounding_box(const char *boundary_id, const struct hecmwST_local_mesh *mesh, const struct hecmw_couple_boundary *boundary)
Definition: hecmw_couple_bounding_box.c:88
hecmw_couple_box::min_x
double min_x
Definition: hecmw_couple_bounding_box.h:16
hecmw_couple_bounding_box
Definition: hecmw_couple_bounding_box.h:21
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
HECMWCPL_E_NONSUPPORT_GEOMTYPE
#define HECMWCPL_E_NONSUPPORT_GEOMTYPE
Definition: hecmw_couple_define.h:179
hecmw_couple_box
Definition: hecmw_couple_bounding_box.h:12
hecmw_couple_box::max_z
double max_z
Definition: hecmw_couple_bounding_box.h:21
hecmw_couple_boundary_item::item
int * item
Definition: hecmw_couple_boundary_info.h:18
hecmw_couple_define.h
HECMW_couple_ctrl_get_bbcoef
int HECMW_couple_ctrl_get_bbcoef(const char *boundary_id, double *bbcoef)
Definition: hecmw_couple_control.c:1854
hecmw_couple_bounding_box::tolerance
double tolerance
Definition: hecmw_couple_bounding_box.h:22