FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecmw_visualizer.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 "hecmw_visualizer.h"
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "hecmw_vis_mem_util.h"
11 #include "hecmw_vis_read_control.h"
12 #include "hecmw_vis_surface_main.h"
13 #include "hecmw_vis_pvr_main.h"
14 #include "hecmw_malloc.h"
15 
18 
21 }
22 
24  FILE *contfp;
25  int pesize, mynode;
26  char *contfile, buf[HECMW_FILENAME_LEN];
27 
28  HECMW_Comm_size(VIS_COMM, &pesize);
29  HECMW_Comm_rank(VIS_COMM, &mynode);
30 
31  if ((contfp = fopen("hecmw_vis.ini", "r")) == NULL) {
32  contfile = HECMW_ctrl_get_control_file("vis_ctrl");
33  if ((contfp = fopen(contfile, "r")) == NULL)
34  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0011: Cannot open control file");
35  }
36 
37  psf = (PSF_link *)HECMW_malloc(sizeof(PSF_link));
38  if (psf == NULL) HECMW_vis_memory_exit("psf");
39  psf->next_psf = NULL;
40  psf->num_of_psf = 0;
41  pvr = (PVR_link *)HECMW_malloc(sizeof(PVR_link));
42  if (pvr == NULL) HECMW_vis_memory_exit("pvr");
43  pvr->next_pvr = NULL;
44  pvr->num_of_pvr = 0;
45 
46  HECMW_vis_read_control(contfp, pesize, mynode, psf, pvr);
47  fclose(contfp);
48 
49  return 0;
50 }
51 
52 /* Internal: perform PSF/PVR rendering with given outfile/buf1 base names */
53 static int visualize_render(struct hecmwST_local_mesh *mesh,
54  struct hecmwST_result_data *data, int timestep,
55  const char *outfile, const char *buf1) {
56  int ii;
57  char outfile1[HECMW_FILENAME_LEN];
58  char body[HECMW_FILENAME_LEN];
59  PSF_link *tp1;
60  PVR_link *tv1;
61  int visual_id, init_flag;
63  struct surface_module *sf;
64  Parameter_vr *vr;
65  int stat_para_sf[NUM_CONTROL_PSF], stat_para_vr[NUM_CONTROL_PVR];
66  HECMW_Comm VIS_COMM;
67  int pesize, mynode;
68 
69  HECMW_Comm_dup(mesh->HECMW_COMM, &VIS_COMM);
70  HECMW_Comm_size(VIS_COMM, &pesize);
71  HECMW_Comm_rank(VIS_COMM, &mynode);
72 
73  if (HECMW_ctrl_is_subdir()) {
74  if (HECMW_ctrl_make_subdir((char *)outfile)) {
76  "ERROR: HEC-MW-VIS-E0009: Cannot open output directory");
77  }
78  }
79  if (psf->num_of_psf > 0) {
80  init_flag = 1;
81  tp1 = psf->next_psf;
82  for (visual_id = 0; visual_id < psf->num_of_psf; visual_id++) {
83  if (mynode == 0)
84  fprintf(stderr, " Start visualize PSF %d at timestep %d\n",
85  visual_id + 1, timestep);
86  sf = tp1->sf;
87  sr = tp1->sr;
88  for (ii = 0; ii < NUM_CONTROL_PSF; ii++)
89  stat_para_sf[ii] = tp1->stat_para[ii];
90  tp1 = tp1->next_psf;
91  if (psf->num_of_psf > 1) {
92  if (timestep >= 1000) {
93  snprintf(outfile1, sizeof(outfile1), "%s_psf%d.%d", outfile, visual_id + 1, timestep);
94  snprintf(body, sizeof(body), "%s_psf%d.%d", buf1, visual_id + 1, timestep);
95  } else if ((timestep >= 100) && (timestep <= 999)) {
96  snprintf(outfile1, sizeof(outfile1), "%s_psf%d.0%d", outfile, visual_id + 1, timestep);
97  snprintf(body, sizeof(body), "%s_psf%d.0%d", buf1, visual_id + 1, timestep);
98  } else if ((timestep >= 10) && (timestep <= 99)) {
99  snprintf(outfile1, sizeof(outfile1), "%s_psf%d.00%d", outfile, visual_id + 1, timestep);
100  snprintf(body, sizeof(body), "%s_psf%d.00%d", buf1, visual_id + 1, timestep);
101  } else if (timestep <= 9) {
102  snprintf(outfile1, sizeof(outfile1), "%s_psf%d.000%d", outfile, visual_id + 1, timestep);
103  snprintf(body, sizeof(body), "%s_psf%d.000%d", buf1, visual_id + 1, timestep);
104  }
105  } else {
106  if (timestep >= 1000) {
107  snprintf(outfile1, sizeof(outfile1), "%s_psf.%d", outfile, timestep);
108  snprintf(body, sizeof(body), "%s_psf.%d", buf1, timestep);
109  } else if ((timestep >= 100) && (timestep <= 999)) {
110  snprintf(outfile1, sizeof(outfile1), "%s_psf.0%d", outfile, timestep);
111  snprintf(body, sizeof(body), "%s_psf.0%d", buf1, timestep);
112  } else if ((timestep >= 10) && (timestep <= 99)) {
113  snprintf(outfile1, sizeof(outfile1), "%s_psf.00%d", outfile, timestep);
114  snprintf(body, sizeof(body), "%s_psf.00%d", buf1, timestep);
115  } else if (timestep <= 9) {
116  snprintf(outfile1, sizeof(outfile1), "%s_psf.000%d", outfile, timestep);
117  snprintf(body, sizeof(body), "%s_psf.000%d", buf1, timestep);
118  }
119  }
120  HECMW_vis_psf_rendering(mesh, data, &timestep, sf, sr, stat_para_sf,
121  outfile1, body, VIS_COMM);
122  init_flag = 0;
123  }
124  }
125  if (pvr->num_of_pvr > 0) {
126  tv1 = pvr->next_pvr;
127  init_flag = 1;
128  for (visual_id = 0; visual_id < pvr->num_of_pvr; visual_id++) {
129  if (mynode == 0)
130  fprintf(stderr, " Start visualize PVR %d at timestep %d\n",
131  visual_id + 1, timestep);
132  vr = tv1->vr;
133  for (ii = 0; ii < NUM_CONTROL_PVR; ii++)
134  stat_para_vr[ii] = tv1->stat_para[ii];
135  tv1 = tv1->next_pvr;
136  if (pvr->num_of_pvr > 1) {
137  if (timestep >= 1000)
138  snprintf(outfile1, sizeof(outfile1), "%s_pvr%d.%d", outfile, visual_id + 1, timestep);
139  else if ((timestep >= 100) && (timestep <= 999))
140  snprintf(outfile1, sizeof(outfile1), "%s_pvr%d.0%d", outfile, visual_id + 1, timestep);
141  else if ((timestep >= 10) && (timestep <= 99))
142  snprintf(outfile1, sizeof(outfile1), "%s_pvr%d.00%d", outfile, visual_id + 1,
143  timestep);
144  else if (timestep <= 9)
145  snprintf(outfile1, sizeof(outfile1), "%s_pvr%d.000%d", outfile, visual_id + 1,
146  timestep);
147  } else {
148  if (timestep >= 1000)
149  snprintf(outfile1, sizeof(outfile1), "%s_pvr.%d", outfile, timestep);
150  else if ((timestep >= 100) && (timestep <= 999))
151  snprintf(outfile1, sizeof(outfile1), "%s_pvr.0%d", outfile, timestep);
152  else if ((timestep >= 10) && (timestep <= 99))
153  snprintf(outfile1, sizeof(outfile1), "%s_pvr.00%d", outfile, timestep);
154  else if (timestep <= 9)
155  snprintf(outfile1, sizeof(outfile1), "%s_pvr.000%d", outfile, timestep);
156  }
157  HECMW_vis_pvr_rendering(mesh, data, &timestep, &init_flag,
158  pvr->num_of_pvr, vr, stat_para_vr, outfile1,
159  VIS_COMM);
160  init_flag = 0;
161  }
162  }
163  HECMW_Comm_free(&VIS_COMM);
164 
165  return 0;
166 }
167 
169  struct hecmwST_result_data *data, int timestep ) {
170  char *outfile, *buf1;
171  int fg_text, ret;
172 
173  outfile = HECMW_ctrl_get_result_fileheader("vis_out", timestep, &fg_text);
174  buf1 = HECMW_ctrl_get_result_filebody("vis_out");
175 
176  ret = visualize_render(mesh, data, timestep, outfile, buf1);
177 
178  HECMW_free(buf1);
179  HECMW_free(outfile);
180 
181  return ret;
182 }
183 
185  struct hecmwST_result_data *data, int timestep,
186  char *addfname) {
187  char *outfile_raw, *buf1_raw;
188  char outfile[HECMW_FILENAME_LEN], buf1[HECMW_FILENAME_LEN];
189  int fg_text, ret;
190 
191  outfile_raw = HECMW_ctrl_get_result_fileheader("vis_out", timestep, &fg_text);
192  buf1_raw = HECMW_ctrl_get_result_filebody("vis_out");
193 
194  /* Insert addfname suffix */
195  snprintf(outfile, HECMW_FILENAME_LEN, "%s%s", outfile_raw, addfname);
196  snprintf(buf1, HECMW_FILENAME_LEN, "%s%s", buf1_raw, addfname);
197  HECMW_free(outfile_raw);
198  HECMW_free(buf1_raw);
199 
200  ret = visualize_render(mesh, data, timestep, outfile, buf1);
201 
202  return ret;
203 }
204 
206  PSF_link *tp1, *tp2;
207  PVR_link *tv1, *tv2;
208  int i;
209 
210  if (psf->num_of_psf > 0) {
211  tp1 = psf->next_psf;
212  for (i = 0; i < psf->num_of_psf; i++) {
213  tp2 = tp1;
214  tp1 = tp1->next_psf;
215  HECMW_free(tp2->sf);
216  if (tp2->sr->light_point) HECMW_free(tp2->sr->light_point);
217  HECMW_free(tp2->sr);
218  HECMW_free(tp2);
219  }
220  }
221  HECMW_free(psf);
222  if (pvr->num_of_pvr > 0) {
223  tv1 = pvr->next_pvr;
224  for (i = 0; i < pvr->num_of_pvr; i++) {
225  tv2 = tv1;
226  tv1 = tv1->next_pvr;
227  HECMW_free(tv2->vr);
228  HECMW_free(tv2);
229  }
230  }
231  HECMW_free(pvr);
232 
233  return 0;
234 }
if(!(yy_init))
Definition: hecmw_ablex.c:1823
int HECMW_Comm_rank(HECMW_Comm comm, int *rank)
Definition: hecmw_comm.c:18
HECMW_Comm HECMW_comm_get_comm(void)
Definition: hecmw_comm.c:751
int HECMW_Comm_size(HECMW_Comm comm, int *size)
Definition: hecmw_comm.c:37
int HECMW_Comm_free(HECMW_Comm *comm)
Definition: hecmw_comm.c:75
int HECMW_Comm_dup(HECMW_Comm comm, HECMW_Comm *new_comm)
Definition: hecmw_comm.c:56
#define HECMW_FILENAME_LEN
Definition: hecmw_config.h:74
MPI_Comm HECMW_Comm
Definition: hecmw_config.h:30
char * HECMW_ctrl_get_result_filebody(char *name_ID)
char * HECMW_ctrl_get_control_file(char *name_ID)
int HECMW_ctrl_is_subdir(void)
char * HECMW_ctrl_get_result_fileheader(char *name_ID, int istep, int *fg_text)
int HECMW_ctrl_make_subdir(char *filename)
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
#define NULL
#define HECMW_free(ptr)
Definition: hecmw_malloc.h:24
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
#define NUM_CONTROL_PSF
void HECMW_vis_print_exit(char *var)
void HECMW_vis_memory_exit(char *var)
void HECMW_vis_pvr_rendering(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int *timestep, int *init_flag, int num_of_pvr, Parameter_vr *vr, int stat_para[NUM_CONTROL_PVR], char *outfile, HECMW_Comm VIS_COMM)
#define NUM_CONTROL_PVR
void HECMW_vis_read_control(FILE *fp, int pesize, int mynode, PSF_link *psf, PVR_link *pvr)
void HECMW_vis_psf_rendering(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int *timestep, struct surface_module *sf, Parameter_rendering *sr, int stat_para[NUM_CONTROL_PSF], char *outfile1, char *body, HECMW_Comm VIS_COMM)
int HECMW_visualize_init_by_comm(HECMW_Comm VIS_COMM)
int HECMW_visualize(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int timestep)
PVR_link * pvr
int HECMW_visualize_init(void)
PSF_link * psf
int HECMW_visualize_finalize(void)
int HECMW_visualize_by_addfname(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int timestep, char *addfname)
CNFData data
HECMW_Comm HECMW_COMM
Definition: hecmw_struct.h:209