FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
hecmw_couple_startup.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 #include "hecmw_malloc.h"
16 
17 #include "hecmw_couple_define.h"
18 #include "hecmw_couple_struct.h"
19 #include "hecmw_couple_control.h"
21 #include "hecmw_couple_info.h"
22 #include "hecmw_couple_init.h"
23 #include "hecmw_couple_startup.h"
24 
25 /*================================================================================================*/
26 
28  struct hecmw_couple_value *couple_value) {
29  if (couple_value == NULL) return;
30 
31  HECMW_free(couple_value->item);
32  HECMW_free(couple_value->value);
33  HECMW_free(couple_value);
34  couple_value = NULL;
35 }
36 
38  struct hecmw_couple_value *p = NULL;
39 
40  p = (struct hecmw_couple_value *)HECMW_malloc(
41  sizeof(struct hecmw_couple_value));
42  if (p == NULL) {
43  HECMW_set_error(errno, "");
44  return NULL;
45  }
46 
47  p->n = 0;
48  p->n_dof = 0;
50  p->item = NULL;
51  p->value = NULL;
52 
53  return p;
54 }
55 
57  const struct hecmw_couple_value *couple_value, FILE *fp) {
58  int i, j;
59 
60  if (couple_value == NULL || fp == NULL) return;
61 
62  fprintf(fp, "*** Value of coupling area\n");
63 
64  fprintf(fp, "number of item: %d\n", couple_value->n);
65 
66  if (couple_value->item_type == HECMW_COUPLE_NODE_GROUP) {
67  fprintf(fp, "item type: NODE GROUP\n");
68  } else if (couple_value->item_type == HECMW_COUPLE_ELEMENT_GROUP) {
69  fprintf(fp, "item type: ELEMENT GROUP\n");
70  } else if (couple_value->item_type == HECMW_COUPLE_SURFACE_GROUP) {
71  fprintf(fp, "item type: SURFACE GROUP\n");
72  } else {
73  fprintf(fp, "item type: UNKNOWN\n");
74  }
75 
76  fprintf(fp, "number of DOF: %d\n", couple_value->n_dof);
77 
78  fprintf(fp, "ID & value:\n");
79  for (i = 0; i < couple_value->n; i++) {
80  if (couple_value->item_type == HECMW_COUPLE_SURFACE_GROUP) {
81  fprintf(fp, " %d %d", couple_value->item[2 * i],
82  couple_value->item[2 * i + 1]);
83  } else {
84  fprintf(fp, " %d", couple_value->item[i]);
85  }
86 
87  for (j = 0; j < couple_value->n_dof; j++) {
88  fprintf(fp, " %lE", couple_value->value[i * couple_value->n_dof + j]);
89  }
90  fprintf(fp, "\n");
91  }
92 }
93 
94 /*------------------------------------------------------------------------------------------------*/
95 
97  const char *boundary_id) {
98  struct hecmw_couple_value *couple_value = NULL;
99  struct hecmw_couple_info *couple_info = NULL;
100  struct hecmw_couple_boundary *boundary = NULL;
101  int i;
102 
103  if (boundary_id == NULL) {
105  "HECMW_couple_startup(): 'boundary_id' is NULL");
106  return NULL;
107  }
108 
109  if ((couple_value = HECMW_couple_alloc_couple_value()) == NULL) goto error;
110  if ((couple_info = HECMW_couple_get_info(boundary_id)) == NULL) goto error;
111 
112  if (couple_info->comm_src->is_member) {
113  boundary = couple_info->boundary_src;
114 
115  couple_value->n_dof = 0;
116  couple_value->item_type = boundary->data_type;
117 
118  /* node group */
119  if (boundary->data_type == HECMW_COUPLE_NODE_GROUP) {
120  couple_value->n = boundary->node->n;
121 
122  if (couple_value->n > 0) {
123  couple_value->item = (int *)HECMW_malloc(sizeof(int) * couple_value->n);
124  if (couple_value->item == NULL) {
125  HECMW_set_error(errno, "");
126  goto error;
127  }
128  for (i = 0; i < couple_value->n; i++) {
129  couple_value->item[i] = boundary->node->item[i];
130  }
131  }
132 
133  /* element group */
134  } else if (boundary->data_type == HECMW_COUPLE_ELEMENT_GROUP) {
135  couple_value->n = boundary->elem->n;
136 
137  if (couple_value->n > 0) {
138  couple_value->item = (int *)HECMW_malloc(sizeof(int) * couple_value->n);
139  if (couple_value->item == NULL) {
140  HECMW_set_error(errno, "");
141  goto error;
142  }
143  for (i = 0; i < couple_value->n; i++) {
144  couple_value->item[i] = boundary->elem->item[i];
145  }
146  }
147 
148  /* surface group */
149  } else if (boundary->data_type == HECMW_COUPLE_SURFACE_GROUP) {
150  couple_value->n = boundary->surf->n;
151 
152  if (couple_value->n > 0) {
153  couple_value->item =
154  (int *)HECMW_malloc(sizeof(int) * couple_value->n * 2);
155  if (couple_value->item == NULL) {
156  HECMW_set_error(errno, "");
157  goto error;
158  }
159  for (i = 0; i < couple_value->n; i++) {
160  couple_value->item[2 * i] = boundary->surf->item[2 * i];
161  couple_value->item[2 * i + 1] = boundary->surf->item[2 * i + 1];
162  }
163  }
164 
165  /* invalid group type */
166  } else {
168  goto error;
169  }
170  }
171 
172  return couple_value;
173 
174 error:
175  HECMW_couple_free_couple_value(couple_value);
176  return NULL;
177 }
178 
179 /*------------------------------------------------------------------------------------------------*/
180 
181 extern void HECMW_couple_cleanup(struct hecmw_couple_value *couple_value) {
182  HECMW_couple_free_couple_value(couple_value);
183 }
hecmw_couple_boundary::surf
struct hecmw_couple_boundary_item * surf
Definition: hecmw_couple_boundary_info.h:23
hecmw_malloc.h
hecmw_couple_boundary::data_type
int data_type
Definition: hecmw_couple_boundary_info.h:20
hecmw_couple_init.h
hecmw_couple_info::boundary_src
struct hecmw_couple_boundary * boundary_src
Definition: hecmw_couple_init.h:26
HECMW_malloc
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
HECMW_couple_print_couple_value
void HECMW_couple_print_couple_value(const struct hecmw_couple_value *couple_value, FILE *fp)
Definition: hecmw_couple_startup.c:56
hecmw_couple_value::n
int n
Definition: hecmw_couple_startup.h:13
hecmw_couple_value::value
double * value
Definition: hecmw_couple_startup.h:17
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_couple_value::item_type
int item_type
Definition: hecmw_couple_startup.h:14
hecmw_struct.h
HECMW_couple_alloc_couple_value
struct hecmw_couple_value * HECMW_couple_alloc_couple_value(void)
Definition: hecmw_couple_startup.c:37
hecmw_couple_control.h
hecmw_msgno.h
hecmw_couple_comm::is_member
int is_member
Definition: hecmw_couple_struct.h:23
HECMW_couple_get_info
struct hecmw_couple_info * HECMW_couple_get_info(const char *boundary_id)
Definition: hecmw_couple_init.c:204
HECMW_COUPLE_NODE_GROUP
#define HECMW_COUPLE_NODE_GROUP
Definition: hecmw_couple_define.h:35
HECMW_COUPLE_SURFACE_GROUP
#define HECMW_COUPLE_SURFACE_GROUP
Definition: hecmw_couple_define.h:39
hecmw_couple_startup.h
hecmw_couple_value::n_dof
int n_dof
Definition: hecmw_couple_startup.h:15
hecmw_couple_info
Definition: hecmw_couple_init.h:17
HECMW_COUPLE_GROUP_UNDEF
#define HECMW_COUPLE_GROUP_UNDEF
Definition: hecmw_couple_define.h:33
hecmw_couple_boundary::elem
struct hecmw_couple_boundary_item * elem
Definition: hecmw_couple_boundary_info.h:22
hecmw_couple_struct.h
hecmw_couple_boundary_info.h
hecmw_couple_value::item
int * item
Definition: hecmw_couple_startup.h:16
hecmw_couple_info.h
hecmw_couple_value
Definition: hecmw_couple_startup.h:9
hecmw_couple_boundary::node
struct hecmw_couple_boundary_item * node
Definition: hecmw_couple_boundary_info.h:21
hecmw_couple_info::comm_src
struct hecmw_couple_comm * comm_src
Definition: hecmw_couple_init.h:23
HECMW_set_error
int HECMW_set_error(int errorno, const char *fmt,...)
Definition: hecmw_error.c:37
HECMW_couple_free_couple_value
void HECMW_couple_free_couple_value(struct hecmw_couple_value *couple_value)
Definition: hecmw_couple_startup.c:27
HECMW_couple_startup
struct hecmw_couple_value * HECMW_couple_startup(const char *boundary_id)
Definition: hecmw_couple_startup.c:96
NULL
#define NULL
Definition: hecmw_io_nastran.c:30
HECMWCPL_E_INVALID_ARG
#define HECMWCPL_E_INVALID_ARG
Definition: hecmw_couple_define.h:91
HECMWCPL_E_INVALID_GRPTYPE
#define HECMWCPL_E_INVALID_GRPTYPE
Definition: hecmw_couple_define.h:165
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_cleanup
void HECMW_couple_cleanup(struct hecmw_couple_value *couple_value)
Definition: hecmw_couple_startup.c:181