FrontISTR 5.2.0
Large-scale structural analysis program with finit element method
Loading...
Searching...
No Matches
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
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
55static 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
95error:
97 return NULL;
98}
99
100static 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
150error:
151 HECMW_couple_free_mapped_point(mapped_point);
152 return NULL;
153}
154
155static 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
165error:
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
200error:
201 HECMW_couple_free_mapped_point(mapped_point);
202 return NULL;
203}
#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
void HECMW_couple_free_mapped_point(struct hecmw_couple_mapped_point *p)
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)
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:409
#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