FrontISTR  5.7.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 
53  struct hecmwST_result_data *data, int timestep ) {
54  int ii;
55  char *outfile, *buf1, outfile1[HECMW_FILENAME_LEN];
56  char body[HECMW_FILENAME_LEN];
57  PSF_link *tp1;
58  PVR_link *tv1;
59  int visual_id, init_flag, fg_text;
61  struct surface_module *sf;
62  Parameter_vr *vr;
63  int stat_para_sf[NUM_CONTROL_PSF], stat_para_vr[NUM_CONTROL_PVR];
64  HECMW_Comm VIS_COMM;
65  int pesize, mynode;
66 
67  HECMW_Comm_dup(mesh->HECMW_COMM, &VIS_COMM);
68  HECMW_Comm_size(VIS_COMM, &pesize);
69  HECMW_Comm_rank(VIS_COMM, &mynode);
70 
71  outfile = HECMW_ctrl_get_result_fileheader("vis_out", timestep, &fg_text);
72  buf1 = HECMW_ctrl_get_result_filebody("vis_out");
73 
74  if (HECMW_ctrl_is_subdir()) {
75  if (HECMW_ctrl_make_subdir(outfile)) {
77  "ERROR: HEC-MW-VIS-E0009: Cannot open output directory");
78  }
79  }
80  if (psf->num_of_psf > 0) {
81  init_flag = 1;
82  tp1 = psf->next_psf;
83  for (visual_id = 0; visual_id < psf->num_of_psf; visual_id++) {
84  if (mynode == 0)
85  fprintf(stderr, " Start visualize PSF %d at timestep %d\n",
86  visual_id + 1, timestep);
87  sf = tp1->sf;
88  sr = tp1->sr;
89  for (ii = 0; ii < NUM_CONTROL_PSF; ii++)
90  stat_para_sf[ii] = tp1->stat_para[ii];
91  tp1 = tp1->next_psf;
92  if (psf->num_of_psf > 1) {
93  if (timestep >= 1000) {
94  sprintf(outfile1, "%s_psf%d.%d", outfile, visual_id + 1, timestep);
95  sprintf(body, "%s_psf%d.%d", buf1, visual_id + 1, timestep);
96  } else if ((timestep >= 100) && (timestep <= 999)) {
97  sprintf(outfile1, "%s_psf%d.0%d", outfile, visual_id + 1, timestep);
98  sprintf(body, "%s_psf%d.0%d", buf1, visual_id + 1, timestep);
99  } else if ((timestep >= 10) && (timestep <= 99)) {
100  sprintf(outfile1, "%s_psf%d.00%d", outfile, visual_id + 1, timestep);
101  sprintf(body, "%s_psf%d.00%d", buf1, visual_id + 1, timestep);
102  } else if (timestep <= 9) {
103  sprintf(outfile1, "%s_psf%d.000%d", outfile, visual_id + 1, timestep);
104  sprintf(body, "%s_psf%d.000%d", buf1, visual_id + 1, timestep);
105  }
106  } else {
107  if (timestep >= 1000) {
108  sprintf(outfile1, "%s_psf.%d", outfile, timestep);
109  sprintf(body, "%s_psf.%d", buf1, timestep);
110  } else if ((timestep >= 100) && (timestep <= 999)) {
111  sprintf(outfile1, "%s_psf.0%d", outfile, timestep);
112  sprintf(body, "%s_psf.0%d", buf1, timestep);
113  } else if ((timestep >= 10) && (timestep <= 99)) {
114  sprintf(outfile1, "%s_psf.00%d", outfile, timestep);
115  sprintf(body, "%s_psf.00%d", buf1, timestep);
116  } else if (timestep <= 9) {
117  sprintf(outfile1, "%s_psf.000%d", outfile, timestep);
118  sprintf(body, "%s_psf.000%d", buf1, timestep);
119  }
120  }
121  HECMW_vis_psf_rendering(mesh, data, &timestep, sf, sr, stat_para_sf,
122  outfile1, body, VIS_COMM);
123  init_flag = 0;
124  }
125  }
126  if (pvr->num_of_pvr > 0) {
127  tv1 = pvr->next_pvr;
128  init_flag = 1;
129  for (visual_id = 0; visual_id < pvr->num_of_pvr; visual_id++) {
130  if (mynode == 0)
131  fprintf(stderr, " Start visualize PVR %d at timestep %d\n",
132  visual_id + 1, timestep);
133  vr = tv1->vr;
134  for (ii = 0; ii < NUM_CONTROL_PVR; ii++)
135  stat_para_vr[ii] = tv1->stat_para[ii];
136  tv1 = tv1->next_pvr;
137  if (pvr->num_of_pvr > 1) {
138  if (timestep >= 1000)
139  sprintf(outfile1, "%s_pvr%d.%d", outfile, visual_id + 1, timestep);
140  else if ((timestep >= 100) && (timestep <= 999))
141  sprintf(outfile1, "%s_pvr%d.0%d", outfile, visual_id + 1, timestep);
142  else if ((timestep >= 10) && (timestep <= 99))
143  sprintf(outfile1, "%s_pvr%d.00%d", outfile, visual_id + 1,
144  timestep);
145  else if (timestep <= 9)
146  sprintf(outfile1, "%s_pvr%d.000%d", outfile, visual_id + 1,
147  timestep);
148  } else {
149  if (timestep >= 1000)
150  sprintf(outfile1, "%s_pvr.%d", outfile, timestep);
151  else if ((timestep >= 100) && (timestep <= 999))
152  sprintf(outfile1, "%s_pvr.0%d", outfile, timestep);
153  else if ((timestep >= 10) && (timestep <= 99))
154  sprintf(outfile1, "%s_pvr.00%d", outfile, timestep);
155  else if (timestep <= 9)
156  sprintf(outfile1, "%s_pvr.000%d", outfile, timestep);
157  }
158  HECMW_vis_pvr_rendering(mesh, data, &timestep, &init_flag,
159  pvr->num_of_pvr, vr, stat_para_vr, outfile1,
160  VIS_COMM);
161  init_flag = 0;
162  }
163  }
164  HECMW_free(buf1);
165  HECMW_free(outfile);
166  HECMW_Comm_free(&VIS_COMM);
167 
168  return 0;
169 }
170 
172  PSF_link *tp1, *tp2;
173  PVR_link *tv1, *tv2;
174  int i;
175 
176  if (psf->num_of_psf > 0) {
177  tp1 = psf->next_psf;
178  for (i = 0; i < psf->num_of_psf; i++) {
179  tp2 = tp1;
180  tp1 = tp1->next_psf;
181  HECMW_free(tp2->sf);
182  if (tp2->sr->light_point) HECMW_free(tp2->sr->light_point);
183  HECMW_free(tp2->sr);
184  HECMW_free(tp2);
185  }
186  }
187  HECMW_free(psf);
188  if (pvr->num_of_pvr > 0) {
189  tv1 = pvr->next_pvr;
190  for (i = 0; i < pvr->num_of_pvr; i++) {
191  tv2 = tv1;
192  tv1 = tv1->next_pvr;
193  HECMW_free(tv2->vr);
194  HECMW_free(tv2);
195  }
196  }
197  HECMW_free(pvr);
198 
199  return 0;
200 }
hecmw_malloc.h
hecmwST_result_data
Definition: hecmw_result.h:11
if
if(!(yy_init))
Definition: hecmw_ablex.c:1823
hecmw_vis_mem_util.h
HECMW_ctrl_get_control_file
char * HECMW_ctrl_get_control_file(char *name_ID)
Definition: hecmw_control.c:2428
HECMW_visualize_finalize
int HECMW_visualize_finalize(void)
Definition: hecmw_visualizer.c:171
HECMW_vis_psf_rendering
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)
Definition: hecmw_vis_surface_main.c:33
HECMW_malloc
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
mesh
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
HECMW_comm_get_comm
HECMW_Comm HECMW_comm_get_comm(void)
Definition: hecmw_comm.c:699
_vr_parameter_struct
Definition: hecmw_vis_ray_trace.h:56
hecmw_vis_read_control.h
hecmwST_local_mesh
Definition: hecmw_struct.h:139
pvr
PVR_link * pvr
Definition: hecmw_visualizer.c:17
HECMW_vis_print_exit
void HECMW_vis_print_exit(char *var)
Definition: hecmw_vis_mem_util.c:21
hecmw_visualizer.h
HECMW_Comm_free
int HECMW_Comm_free(HECMW_Comm *comm)
Definition: hecmw_comm.c:75
HECMW_Comm_dup
int HECMW_Comm_dup(HECMW_Comm comm, HECMW_Comm *new_comm)
Definition: hecmw_comm.c:56
hecmw_vis_surface_main.h
HECMW_ctrl_make_subdir
int HECMW_ctrl_make_subdir(char *filename)
Definition: hecmw_control.c:2447
psf
PSF_link * psf
Definition: hecmw_visualizer.c:16
HECMW_vis_memory_exit
void HECMW_vis_memory_exit(char *var)
Definition: hecmw_vis_mem_util.c:12
NUM_CONTROL_PSF
#define NUM_CONTROL_PSF
Definition: hecmw_vis_SF_geom.h:65
HECMW_ctrl_get_result_filebody
char * HECMW_ctrl_get_result_filebody(char *name_ID)
Definition: hecmw_control.c:2337
HECMW_vis_read_control
void HECMW_vis_read_control(FILE *fp, int pesize, int mynode, PSF_link *psf, PVR_link *pvr)
Definition: hecmw_vis_read_control.c:461
hecmw_vis_pvr_main.h
_rendering_parameter_struct
Definition: hecmw_vis_psf_rendering.h:18
NUM_CONTROL_PVR
#define NUM_CONTROL_PVR
Definition: hecmw_vis_ray_trace.h:53
surface_module
Definition: hecmw_vis_SF_geom.h:88
data
CNFData data
Definition: neu_reporter.cpp:18
_rendering_parameter_struct::light_point
double * light_point
Definition: hecmw_vis_psf_rendering.h:29
HECMW_Comm
MPI_Comm HECMW_Comm
Definition: hecmw_config.h:30
HECMW_vis_pvr_rendering
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)
Definition: hecmw_vis_pvr_main.c:29
HECMW_Comm_rank
int HECMW_Comm_rank(HECMW_Comm comm, int *rank)
Definition: hecmw_comm.c:18
HECMW_Comm_size
int HECMW_Comm_size(HECMW_Comm comm, int *size)
Definition: hecmw_comm.c:37
HECMW_visualize
int HECMW_visualize(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int timestep)
Definition: hecmw_visualizer.c:52
NULL
#define NULL
Definition: hecmw_io_nastran.c:30
HECMW_free
#define HECMW_free(ptr)
Definition: hecmw_malloc.h:24
HECMW_FILENAME_LEN
#define HECMW_FILENAME_LEN
Definition: hecmw_config.h:72
HECMW_visualize_init
int HECMW_visualize_init(void)
Definition: hecmw_visualizer.c:19
HECMW_visualize_init_by_comm
int HECMW_visualize_init_by_comm(HECMW_Comm VIS_COMM)
Definition: hecmw_visualizer.c:23
HECMW_ctrl_is_subdir
int HECMW_ctrl_is_subdir(void)
Definition: hecmw_control.c:2500
hecmwST_local_mesh::HECMW_COMM
HECMW_Comm HECMW_COMM
Definition: hecmw_struct.h:209
HECMW_ctrl_get_result_fileheader
char * HECMW_ctrl_get_result_fileheader(char *name_ID, int istep, int *fg_text)
Definition: hecmw_control.c:2321