FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecmw_visual_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 <errno.h>
9 #include "hecmw_struct.h"
10 #include "hecmw_result.h"
11 #include "hecmw_util.h"
12 #include "hecmw_dist_copy_f2c.h"
13 #include "hecmw_result_copy_f2c.h"
14 #include "hecmw_dist_free.h"
15 #include "hecmw_visualizer.h"
16 #include "hecmw_lib_fc.h"
17 
18 static struct hecmwST_local_mesh *mesh;
19 static struct hecmwST_result_data *result;
20 
21 /*----------------------------------------------------------------------------*/
22 static int alloc_local_mesh(void) {
23  mesh = HECMW_malloc(sizeof(*mesh));
24  if (mesh == NULL) {
25  HECMW_set_error(errno, "");
26  return -1;
27  }
28 
29  mesh->section = HECMW_malloc(sizeof(*mesh->section));
30  if (mesh->section == NULL) {
31  HECMW_set_error(errno, "");
32  return -1;
33  }
34 
35  mesh->material = HECMW_malloc(sizeof(*mesh->material));
36  if (mesh->material == NULL) {
37  HECMW_set_error(errno, "");
38  return -1;
39  }
40 
41  mesh->mpc = HECMW_malloc(sizeof(*mesh->mpc));
42  if (mesh->mpc == NULL) {
43  HECMW_set_error(errno, "");
44  return -1;
45  }
46 
47  mesh->amp = HECMW_malloc(sizeof(*mesh->amp));
48  if (mesh->amp == NULL) {
49  HECMW_set_error(errno, "");
50  return -1;
51  }
52 
53  mesh->node_group = HECMW_malloc(sizeof(*mesh->node_group));
54  if (mesh->node_group == NULL) {
55  HECMW_set_error(errno, "");
56  return -1;
57  }
58 
59  mesh->elem_group = HECMW_malloc(sizeof(*mesh->elem_group));
60  if (mesh->elem_group == NULL) {
61  HECMW_set_error(errno, "");
62  return -1;
63  }
64 
65  mesh->surf_group = HECMW_malloc(sizeof(*mesh->surf_group));
66  if (mesh->surf_group == NULL) {
67  HECMW_set_error(errno, "");
68  return -1;
69  }
70 
71  mesh->contact_pair = HECMW_malloc(sizeof(*mesh->contact_pair));
72  if (mesh->contact_pair == NULL) {
73  HECMW_set_error(errno, "");
74  return -1;
75  }
76 
77  return 0;
78 }
79 
80 /*----------------------------------------------------------------------------*/
81 static int alloc_result(void) {
82  result = HECMW_malloc(sizeof(*result));
83  if (result == NULL) {
84  HECMW_set_error(errno, "");
85  return -1;
86  }
87  return 0;
88 }
89 
90 /*----------------------------------------------------------------------------*/
91 void hecmw_visualize_if(int *step, int *err) {
92  *err = 1;
93  if (HECMW_visualize(mesh, result, *step)) return;
94  *err = 0;
95 }
96 
97 void hecmw_visualize_if_(int *step, int *err) {
98  hecmw_visualize_if(step, err);
99 }
100 
101 void hecmw_visualize_if__(int *step, int *err) {
102  hecmw_visualize_if(step, err);
103 }
104 
105 void HECMW_VISUALIZE_IF(int *step, int *err) {
106  hecmw_visualize_if(step, err);
107 }
108 
109 /*----------------------------------------------------------------------------*/
110 void hecmw_visualize_by_addfname_if(int *step, char *addfname, int *err,
111  int len) {
112  char addfname_str[HECMW_NAME_LEN + 1];
113  *err = 1;
114  if (HECMW_strcpy_f2c_r(addfname, len, addfname_str, sizeof(addfname_str)) ==
115  NULL)
116  return;
117  if (HECMW_visualize_by_addfname(mesh, result, *step, addfname_str)) return;
118  *err = 0;
119 }
120 
121 void hecmw_visualize_by_addfname_if_(int *step, char *addfname, int *err,
122  int len) {
123  hecmw_visualize_by_addfname_if(step, addfname, err, len);
124 }
125 
126 void hecmw_visualize_by_addfname_if__(int *step, char *addfname, int *err,
127  int len) {
128  hecmw_visualize_by_addfname_if(step, addfname, err, len);
129 }
130 
131 void HECMW_VISUALIZE_BY_ADDFNAME_IF(int *step, char *addfname, int *err,
132  int len) {
133  hecmw_visualize_by_addfname_if(step, addfname, err, len);
134 }
135 
136 /*----------------------------------------------------------------------------*/
137 void hecmw_visualize_init_if(int *nnode, int *nelem, int *err) {
138  *err = 1;
139 
140  if (alloc_local_mesh()) return;
141 
142  if (alloc_result()) return;
143 
144  if (HECMW_dist_copy_f2c_init(mesh)) return;
145 
146  if (HECMW_result_copy_f2c_init(result, *nnode, *nelem)) return;
147 
148  *err = 0;
149 }
150 
151 void hecmw_visualize_init_if_(int *nnode, int *nelem, int *err) {
152  hecmw_visualize_init_if(nnode, nelem, err);
153 }
154 
155 void hecmw_visualize_init_if__(int *nnode, int *nelem, int *err) {
156  hecmw_visualize_init_if(nnode, nelem, err);
157 }
158 
159 void HECMW_VISUALIZE_INIT_IF(int *nnode, int *nelem, int *err) {
160  hecmw_visualize_init_if(nnode, nelem, err);
161 }
162 
163 /*----------------------------------------------------------------------------*/
165  *err = 0;
166 
167  if (HECMW_dist_copy_f2c_finalize()) return;
168 
169  if (HECMW_result_copy_f2c_finalize()) return;
170 
171  HECMW_dist_free(mesh);
172  mesh = NULL;
173 
174  HECMW_result_free(result);
175  result = NULL;
176 
177  *err = 0;
178 }
179 
182 }
183 
186 }
187 
189 
190 /*----------------------------------------------------------------------------*/
191 void hecmw_init_for_visual_if(int *err) {
192  *err = 1;
193  if (HECMW_visualize_init()) return;
194  *err = 0;
195 }
196 
198 
200 
202 
203 /*----------------------------------------------------------------------------*/
205  *err = 1;
206  if (HECMW_visualize_finalize()) return;
207  *err = 0;
208 }
209 
212 }
213 
216 }
217 
220 }
#define HECMW_NAME_LEN
Definition: hecmw_config.h:72
int HECMW_dist_copy_f2c_init(struct hecmwST_local_mesh *local_mesh)
int HECMW_dist_copy_f2c_finalize(void)
void HECMW_dist_free(struct hecmwST_local_mesh *mesh)
int HECMW_set_error(int errorno, const char *fmt,...)
Definition: hecmw_error.c:37
#define NULL
char * HECMW_strcpy_f2c_r(const char *fstr, int flen, char *buf, int bufsize)
Definition: hecmw_lib_fc.c:45
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
void HECMW_result_free(struct hecmwST_result_data *result)
Definition: hecmw_result.c:21
int HECMW_result_copy_f2c_init(struct hecmwST_result_data *result_data, int n_node, int n_elem)
int HECMW_result_copy_f2c_finalize(void)
void hecmw_finalize_for_visual_if__(int *err)
void hecmw_visualize_finalize_if__(int *err)
void hecmw_init_for_visual_if_(int *err)
void hecmw_finalize_for_visual_if(int *err)
void hecmw_init_for_visual_if(int *err)
void hecmw_visualize_init_if(int *nnode, int *nelem, int *err)
void hecmw_visualize_if_(int *step, int *err)
void hecmw_visualize_init_if_(int *nnode, int *nelem, int *err)
void hecmw_visualize_if__(int *step, int *err)
void hecmw_finalize_for_visual_if_(int *err)
void hecmw_init_for_visual_if__(int *err)
void HECMW_VISUALIZE_BY_ADDFNAME_IF(int *step, char *addfname, int *err, int len)
void HECMW_VISUALIZE_FINALIZE_IF(int *err)
void hecmw_visualize_finalize_if(int *err)
void hecmw_visualize_finalize_if_(int *err)
void hecmw_visualize_by_addfname_if(int *step, char *addfname, int *err, int len)
void hecmw_visualize_by_addfname_if__(int *step, char *addfname, int *err, int len)
void HECMW_VISUALIZE_INIT_IF(int *nnode, int *nelem, int *err)
void HECMW_VISUALIZE_IF(int *step, int *err)
void HECMW_INIT_FOR_VISUAL_IF(int *err)
void HECMW_FINALIZE_FOR_VISUAL_IF(int *err)
void hecmw_visualize_init_if__(int *nnode, int *nelem, int *err)
void hecmw_visualize_by_addfname_if_(int *step, char *addfname, int *err, int len)
void hecmw_visualize_if(int *step, int *err)
int HECMW_visualize(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int timestep)
int HECMW_visualize_init(void)
int HECMW_visualize_finalize(void)
int HECMW_visualize_by_addfname(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int timestep, char *addfname)
struct hecmwST_section * section
Definition: hecmw_struct.h:245
struct hecmwST_amplitude * amp
Definition: hecmw_struct.h:248
struct hecmwST_material * material
Definition: hecmw_struct.h:246
struct hecmwST_mpc * mpc
Definition: hecmw_struct.h:247
struct hecmwST_node_grp * node_group
Definition: hecmw_struct.h:249
struct hecmwST_contact_pair * contact_pair
Definition: hecmw_struct.h:252
struct hecmwST_surf_grp * surf_group
Definition: hecmw_struct.h:251
struct hecmwST_elem_grp * elem_group
Definition: hecmw_struct.h:250