FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
hecmw_couple_init_if.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 <errno.h>
10 
11 #include "hecmw_struct.h"
12 #include "hecmw_dist_copy_f2c.h"
13 #include "hecmw_couple_define.h"
14 #include "hecmw_couple_init.h"
15 
16 static struct hecmwST_local_mesh *mesh_unit1 = NULL, *mesh_unit2 = NULL;
17 
18 /*================================================================================================*/
19 
20 static struct hecmwST_local_mesh *alloc_struct_local_mesh(void) {
21  struct hecmwST_local_mesh *mesh = NULL;
22 
24  sizeof(struct hecmwST_local_mesh));
25  if (mesh == NULL) {
26  HECMW_set_error(errno, "");
27  return NULL;
28  }
29  mesh->section = NULL;
30  mesh->material = NULL;
31  mesh->mpc = NULL;
32  mesh->amp = NULL;
33  mesh->node_group = NULL;
34  mesh->elem_group = NULL;
35  mesh->surf_group = NULL;
36 
37  mesh->section =
38  (struct hecmwST_section *)HECMW_malloc(sizeof(struct hecmwST_section));
39  if (mesh->section == NULL) {
40  HECMW_set_error(errno, "");
41  goto error;
42  }
43 
44  mesh->material =
45  (struct hecmwST_material *)HECMW_malloc(sizeof(struct hecmwST_material));
46  if (mesh->material == NULL) {
47  HECMW_set_error(errno, "");
48  goto error;
49  }
50 
51  mesh->mpc = (struct hecmwST_mpc *)HECMW_malloc(sizeof(struct hecmwST_mpc));
52  if (mesh->mpc == NULL) {
53  HECMW_set_error(errno, "");
54  goto error;
55  }
56 
58  sizeof(struct hecmwST_amplitude));
59  if (mesh->amp == NULL) {
60  HECMW_set_error(errno, "");
61  goto error;
62  }
63 
64  mesh->node_group =
65  (struct hecmwST_node_grp *)HECMW_malloc(sizeof(struct hecmwST_node_grp));
66  if (mesh->node_group == NULL) {
67  HECMW_set_error(errno, "");
68  goto error;
69  }
70 
71  mesh->elem_group =
72  (struct hecmwST_elem_grp *)HECMW_malloc(sizeof(struct hecmwST_elem_grp));
73  if (mesh->elem_group == NULL) {
74  HECMW_set_error(errno, "");
75  goto error;
76  }
77 
78  mesh->surf_group =
79  (struct hecmwST_surf_grp *)HECMW_malloc(sizeof(struct hecmwST_surf_grp));
80  if (mesh->surf_group == NULL) {
81  HECMW_set_error(errno, "");
82  goto error;
83  }
84 
85  return mesh;
86 
87 error:
88  HECMW_dist_free(mesh);
89  return NULL;
90 }
91 
92 /*================================================================================================*/
93 
94 extern void hecmw_couple_init_if(char *boundary_id, int *err, int len) {
95  char c_id[HECMW_NAME_LEN + 1];
96 
97  *err = 1;
98 
99  if (HECMW_strcpy_f2c_r(boundary_id, len, c_id, sizeof(c_id)) == NULL) return;
100  if (HECMW_couple_init(c_id, mesh_unit1, mesh_unit2) != HECMW_SUCCESS) return;
101 
102  *err = 0;
103 }
104 
105 extern void hecmw_couple_init_if_(char *boundary_id, int *err, int len) {
106  hecmw_couple_init_if(boundary_id, err, len);
107 }
108 
109 extern void hecmw_couple_init_if__(char *boundary_id, int *err, int len) {
110  hecmw_couple_init_if(boundary_id, err, len);
111 }
112 
113 extern void HECMW_COUPLE_INIT_IF(char *boundary_id, int *err, int len) {
114  hecmw_couple_init_if(boundary_id, err, len);
115 }
116 
117 /*------------------------------------------------------------------------------------------------*/
118 
119 extern void hecmw_couple_init_init_if(int *unit_specifier, int *err) {
120  *err = 1;
121 
122  if (*unit_specifier == HECMW_COUPLE_UNIT1) {
123  if ((mesh_unit1 = alloc_struct_local_mesh()) == NULL) return;
124  if (HECMW_dist_copy_f2c_init(mesh_unit1)) return;
125  } else if (*unit_specifier == HECMW_COUPLE_UNIT2) {
126  if ((mesh_unit2 = alloc_struct_local_mesh()) == NULL) return;
127  if (HECMW_dist_copy_f2c_init(mesh_unit2)) return;
128  } else {
129  return;
130  }
131 
132  *err = 0;
133 }
134 
135 extern void hecmw_couple_init_init_if_(int *unit_specifier, int *err) {
136  hecmw_couple_init_init_if(unit_specifier, err);
137 }
138 
139 extern void hecmw_couple_init_init_if__(int *unit_specifier, int *err) {
140  hecmw_couple_init_init_if(unit_specifier, err);
141 }
142 
143 extern void HECMW_COUPLE_INIT_INIT_IF(int *unit_specifier, int *err) {
144  hecmw_couple_init_init_if(unit_specifier, err);
145 }
146 
147 /*------------------------------------------------------------------------------------------------*/
148 
149 extern void hecmw_couple_init_final_if(int *err) {
150  *err = 1;
151 
152  if (HECMW_dist_copy_f2c_finalize()) return;
153  HECMW_dist_free(mesh_unit1);
154  HECMW_dist_free(mesh_unit2);
155 
156  mesh_unit1 = NULL;
157  mesh_unit2 = NULL;
158 
159  *err = 0;
160 }
161 
162 extern void hecmw_couple_init_final_if_(int *err) {
164 }
165 
166 extern void hecmw_couple_init_final_if__(int *err) {
168 }
169 
170 extern void HECMW_COUPLE_INIT_FINAL_IF(int *err) {
172 }
hecmwST_local_mesh::mpc
struct hecmwST_mpc * mpc
Definition: hecmw_struct.h:247
hecmwST_mpc
Definition: hecmw_struct.h:48
hecmw_couple_init_if_
void hecmw_couple_init_if_(char *boundary_id, int *err, int len)
Definition: hecmw_couple_init_if.c:105
HECMW_couple_init
int HECMW_couple_init(const char *boundary_id, struct hecmwST_local_mesh *mesh_unit1, struct hecmwST_local_mesh *mesh_unit2)
Definition: hecmw_couple_init.c:228
hecmw_couple_init.h
HECMW_dist_free
void HECMW_dist_free(struct hecmwST_local_mesh *mesh)
Definition: hecmw_dist_free.c:218
HECMW_malloc
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
hecmwST_local_mesh::elem_group
struct hecmwST_elem_grp * elem_group
Definition: hecmw_struct.h:250
mesh
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
hecmw_couple_init_final_if
void hecmw_couple_init_final_if(int *err)
Definition: hecmw_couple_init_if.c:149
hecmwST_local_mesh
Definition: hecmw_struct.h:139
HECMW_COUPLE_UNIT1
#define HECMW_COUPLE_UNIT1
Definition: hecmw_couple_define.h:23
HECMW_dist_copy_f2c_finalize
int HECMW_dist_copy_f2c_finalize(void)
Definition: hecmw_dist_copy_f2c.c:2033
hecmw_struct.h
hecmwST_amplitude
Definition: hecmw_struct.h:57
hecmwST_elem_grp
Definition: hecmw_struct.h:92
HECMW_COUPLE_INIT_FINAL_IF
void HECMW_COUPLE_INIT_FINAL_IF(int *err)
Definition: hecmw_couple_init_if.c:170
HECMW_COUPLE_INIT_INIT_IF
void HECMW_COUPLE_INIT_INIT_IF(int *unit_specifier, int *err)
Definition: hecmw_couple_init_if.c:143
HECMW_NAME_LEN
#define HECMW_NAME_LEN
Definition: hecmw_config.h:70
hecmwST_local_mesh::material
struct hecmwST_material * material
Definition: hecmw_struct.h:246
hecmwST_local_mesh::amp
struct hecmwST_amplitude * amp
Definition: hecmw_struct.h:248
hecmw_couple_init_if__
void hecmw_couple_init_if__(char *boundary_id, int *err, int len)
Definition: hecmw_couple_init_if.c:109
hecmwST_section
Definition: hecmw_struct.h:11
hecmw_couple_init_init_if__
void hecmw_couple_init_init_if__(int *unit_specifier, int *err)
Definition: hecmw_couple_init_if.c:139
hecmw_couple_init_init_if
void hecmw_couple_init_init_if(int *unit_specifier, int *err)
Definition: hecmw_couple_init_if.c:119
hecmw_dist_copy_f2c.h
hecmwST_node_grp
Definition: hecmw_struct.h:75
HECMW_SUCCESS
#define HECMW_SUCCESS
Definition: hecmw_config.h:64
HECMW_COUPLE_INIT_IF
void HECMW_COUPLE_INIT_IF(char *boundary_id, int *err, int len)
Definition: hecmw_couple_init_if.c:113
hecmwST_surf_grp
Definition: hecmw_struct.h:106
hecmw_couple_init_init_if_
void hecmw_couple_init_init_if_(int *unit_specifier, int *err)
Definition: hecmw_couple_init_if.c:135
HECMW_strcpy_f2c_r
char * HECMW_strcpy_f2c_r(const char *fstr, int flen, char *buf, int bufsize)
Definition: hecmw_lib_fc.c:45
HECMW_set_error
int HECMW_set_error(int errorno, const char *fmt,...)
Definition: hecmw_error.c:37
HECMW_dist_copy_f2c_init
int HECMW_dist_copy_f2c_init(struct hecmwST_local_mesh *local_mesh)
Definition: hecmw_dist_copy_f2c.c:2007
hecmw_couple_init_final_if__
void hecmw_couple_init_final_if__(int *err)
Definition: hecmw_couple_init_if.c:166
hecmwST_local_mesh::section
struct hecmwST_section * section
Definition: hecmw_struct.h:245
hecmw_couple_init_if
void hecmw_couple_init_if(char *boundary_id, int *err, int len)
Definition: hecmw_couple_init_if.c:94
NULL
#define NULL
Definition: hecmw_io_nastran.c:30
hecmwST_material
Definition: hecmw_struct.h:35
hecmw_couple_init_final_if_
void hecmw_couple_init_final_if_(int *err)
Definition: hecmw_couple_init_if.c:162
hecmwST_local_mesh::surf_group
struct hecmwST_surf_grp * surf_group
Definition: hecmw_struct.h:251
hecmwST_local_mesh::node_group
struct hecmwST_node_grp * node_group
Definition: hecmw_struct.h:249
hecmw_couple_define.h
HECMW_COUPLE_UNIT2
#define HECMW_COUPLE_UNIT2
Definition: hecmw_couple_define.h:25