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