FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecmw_vis_mesh_extent.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 
7 
8 #include <stdlib.h>
9 #include "hecmw_malloc.h"
10 
11 int calc_extent(struct hecmwST_local_mesh *mesh, double *extent) {
12  int nodeID;
13  int i;
14  long long j;
15 
16  double x_min, x_max, y_min, y_max, z_min, z_max;
17  double x, y, z;
18 
19  for (i = 0; i < mesh->n_elem; i++) {
20  nodeID = mesh->elem_node_item[mesh->elem_node_index[i]] - 1;
21  x_min = x_max = mesh->node[nodeID * 3];
22  y_min = y_max = mesh->node[nodeID * 3 + 1];
23  z_min = z_max = mesh->node[nodeID * 3 + 2];
24  for (j = mesh->elem_node_index[i] + 1; j < mesh->elem_node_index[i + 1];
25  j++) {
26  nodeID = mesh->elem_node_item[j] - 1;
27  x = mesh->node[nodeID * 3];
28  y = mesh->node[nodeID * 3 + 1];
29  z = mesh->node[nodeID * 3 + 2];
30  if (x_min > x) x_min = x;
31  if (x_max < x) x_max = x;
32  if (y_min > y) y_min = y;
33  if (y_max < y) y_max = y;
34  if (z_min > z) z_min = z;
35  if (z_max < z) z_max = z;
36  }
37  extent[i * 6] = x_min;
38  extent[i * 6 + 1] = x_max;
39  extent[i * 6 + 2] = y_min;
40  extent[i * 6 + 3] = y_max;
41  extent[i * 6 + 4] = z_min;
42  extent[i * 6 + 5] = z_max;
43  }
44 
45  return 1;
46 }
47 
48 int calc_voxel_level(int n_voxel, struct hecmwST_local_mesh *mesh,
49  double *voxel_dxyz, double *voxel_orig_xyz, double *extent,
50  int *level, HECMW_Comm VIS_COMM) {
51  int i, j;
52  int flag;
53  double *extent_xyz;
54  double *result_xyz;
55  int pesize;
56  int rank;
57 
58  extent_xyz = (double *)HECMW_calloc(n_voxel * 3, sizeof(double));
59  result_xyz = (double *)HECMW_calloc(n_voxel * 3, sizeof(double));
60 
61  for (i = 0; i < n_voxel * 3; i++) {
62  extent_xyz[i] = voxel_dxyz[i];
63  }
64 
65  HECMW_Comm_rank(VIS_COMM, &rank);
66  HECMW_Comm_size(VIS_COMM, &pesize);
67  for (i = 0; i < mesh->n_elem; i++) {
68  if (mesh->elem_type[i] < 400) {
69  for (j = 0; j < n_voxel; j++) {
70  flag = 1;
71  if ((extent[i * 6 + 1] < voxel_orig_xyz[0]) ||
72  (voxel_orig_xyz[0] + voxel_dxyz[0] < extent[i * 6])) {
73  flag = 0;
74  } else if ((extent[i * 6 + 3] < voxel_orig_xyz[1]) ||
75  (voxel_orig_xyz[1] + voxel_dxyz[1] < extent[i * 6 + 2])) {
76  flag = 0;
77  } else if ((extent[i * 6 + 5] < voxel_orig_xyz[2]) ||
78  (voxel_orig_xyz[2] + voxel_dxyz[2] < extent[i * 6 + 4])) {
79  flag = 0;
80  }
81  if (flag) {
82  if (extent_xyz[j * 3] > (extent[i * 6 + 1] - extent[i * 6]))
83  extent_xyz[j * 3] = extent[i * 6 + 1] - extent[i * 6];
84  if (extent_xyz[j * 3 + 1] > (extent[i * 6 + 3] - extent[i * 6 + 2]))
85  extent_xyz[j * 3 + 1] = extent[i * 6 + 3] - extent[i * 6 + 2];
86  if (extent_xyz[j * 3 + 2] > (extent[i * 6 + 5] - extent[i * 6 + 4]))
87  extent_xyz[j * 3 + 2] = extent[i * 6 + 5] - extent[i * 6 + 4];
88  }
89  }
90  }
91  }
92  /* for (i = 0; i < n_voxel; i++) {
93 fprintf(stderr, "Extent %d: %lf %lf %lf\n",
94  i, extent_x[i], extent_y[i], extent_z[i]);
95 }
96  */
97  HECMW_Barrier(VIS_COMM);
98  if (pesize > 1) {
99  HECMW_Allreduce(extent_xyz, result_xyz, n_voxel * 3, HECMW_DOUBLE,
100  HECMW_MIN, VIS_COMM);
101 
102  } else {
103  for (i = 0; i < n_voxel; i++) {
104  result_xyz[i] = extent_xyz[i];
105  }
106  }
107  HECMW_Barrier(VIS_COMM);
108  /*
109 for (i = 0; i < vox->n_voxel; i++) {
110 if (result_x[i] != vox->info[i].dx) {
111 vox->info[i].level[0]
112  = (int)(log(vox->info[i].dx / result_x[i])/log(2.0));
113 } else vox->info[i].level[0] = 0;
114 if (result_y[i] != vox->info[i].dy) {
115 vox->info[i].level[1]
116  = (int)(log(vox->info[i].dy / result_y[i])/log(2.0));
117 } else vox->info[i].level[1] = 0;
118 if (result_z[i] != vox->info[i].dz) {
119 vox->info[i].level[2]
120  = (int)(log(vox->info[i].dz / result_z[i])/log(2.0));
121 } else vox->info[i].level[2] = 0;
122 }
123  */
124  for (i = 0; i < n_voxel; i++) {
125  if (result_xyz[i * 3] != voxel_dxyz[i * 3]) {
126  level[i * 3] = (int)(voxel_dxyz[i * 3] / result_xyz[i * 3]);
127  } else
128  level[i * 3] = 0;
129  if (result_xyz[i * 3 + 1] != voxel_dxyz[i * 3 + 1]) {
130  level[i * 3 + 1] = (int)(voxel_dxyz[i * 3 + 1] / result_xyz[i * 3 + 1]);
131  } else
132  level[i * 3 + 1] = 0;
133  if (result_xyz[i * 3 + 2] != voxel_dxyz[i * 3 + 2]) {
134  level[i * 3 + 2] = (int)(voxel_dxyz[i * 3 + 2] / result_xyz[i * 3 + 2]);
135  } else
136  level[i * 3 + 2] = 0;
137  }
138 
139  HECMW_free(extent_xyz);
140  HECMW_free(result_xyz);
141 
142  return 1;
143 }
int HECMW_Comm_rank(HECMW_Comm comm, int *rank)
Definition: hecmw_comm.c:18
int HECMW_Comm_size(HECMW_Comm comm, int *size)
Definition: hecmw_comm.c:37
int HECMW_Allreduce(void *sendbuf, void *recvbuf, int count, HECMW_Datatype datatype, HECMW_Op op, HECMW_Comm comm)
Definition: hecmw_comm.c:404
int HECMW_Barrier(HECMW_Comm comm)
Definition: hecmw_comm.c:95
#define HECMW_DOUBLE
Definition: hecmw_config.h:50
MPI_Comm HECMW_Comm
Definition: hecmw_config.h:30
#define HECMW_MIN
Definition: hecmw_config.h:56
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
#define HECMW_calloc(nmemb, size)
Definition: hecmw_malloc.h:21
#define HECMW_free(ptr)
Definition: hecmw_malloc.h:24
int calc_voxel_level(int n_voxel, struct hecmwST_local_mesh *mesh, double *voxel_dxyz, double *voxel_orig_xyz, double *extent, int *level, HECMW_Comm VIS_COMM)
int calc_extent(struct hecmwST_local_mesh *mesh, double *extent)
double * voxel_dxyz
double * extent
double * voxel_orig_xyz
int * level
long long * elem_node_index
Definition: hecmw_struct.h:195