| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "params.h" // for MAXSETS |
| 10 |
#include "smalloc.h" // for smalloc, sfree |
| 11 |
|
| 12 |
void sorts3d( |
| 13 |
/* Sort the lists needed to find the splitter. */ |
| 14 |
double *vals[8][MAXSETS], /* lists of values to sort */ |
| 15 |
int *indices[8][MAXSETS], /* indices of sorted lists */ |
| 16 |
int nvtxs /* number of vertices */ |
| 17 |
) |
| 18 |
{ |
| 19 |
int *space; /* space for mergesort routine */ |
| 20 |
int nsets = 8; /* number of sets */ |
| 21 |
int nlists = 13; /* number of directions to sort */ |
| 22 |
int *temp[13]; /* place holders for indices */ |
| 23 |
int i, j; /* loop counter */ |
| 24 |
|
| 25 |
void ch_mergesort(double *vals, int nvals, int *indices, int *space); |
| 26 |
|
| 27 |
space = smalloc(nvtxs * sizeof(int)); |
| 28 |
|
| 29 |
for (i = 0; i < nlists; i++) { |
| 30 |
temp[i] = smalloc(nvtxs * sizeof(int)); |
| 31 |
} |
| 32 |
|
| 33 |
ch_mergesort(vals[0][1], nvtxs, temp[0], space); |
| 34 |
ch_mergesort(vals[0][2], nvtxs, temp[1], space); |
| 35 |
ch_mergesort(vals[0][4], nvtxs, temp[2], space); |
| 36 |
ch_mergesort(vals[0][3], nvtxs, temp[3], space); |
| 37 |
ch_mergesort(vals[1][2], nvtxs, temp[4], space); |
| 38 |
ch_mergesort(vals[0][5], nvtxs, temp[5], space); |
| 39 |
ch_mergesort(vals[1][4], nvtxs, temp[6], space); |
| 40 |
ch_mergesort(vals[0][6], nvtxs, temp[7], space); |
| 41 |
ch_mergesort(vals[2][4], nvtxs, temp[8], space); |
| 42 |
ch_mergesort(vals[0][7], nvtxs, temp[9], space); |
| 43 |
ch_mergesort(vals[1][6], nvtxs, temp[10], space); |
| 44 |
ch_mergesort(vals[2][5], nvtxs, temp[11], space); |
| 45 |
ch_mergesort(vals[3][4], nvtxs, temp[12], space); |
| 46 |
|
| 47 |
sfree(space); |
| 48 |
|
| 49 |
indices[0][1] = indices[2][3] = indices[4][5] = indices[6][7] = temp[0]; |
| 50 |
indices[0][2] = indices[1][3] = indices[4][6] = indices[5][7] = temp[1]; |
| 51 |
indices[0][4] = indices[1][5] = indices[2][6] = indices[3][7] = temp[2]; |
| 52 |
indices[0][3] = indices[4][7] = temp[3]; |
| 53 |
indices[1][2] = indices[5][6] = temp[4]; |
| 54 |
indices[0][5] = indices[2][7] = temp[5]; |
| 55 |
indices[1][4] = indices[3][6] = temp[6]; |
| 56 |
indices[0][6] = indices[1][7] = temp[7]; |
| 57 |
indices[2][4] = indices[3][5] = temp[8]; |
| 58 |
indices[0][7] = temp[9]; |
| 59 |
indices[1][6] = temp[10]; |
| 60 |
indices[2][5] = temp[11]; |
| 61 |
indices[3][4] = temp[12]; |
| 62 |
|
| 63 |
for (i = 0; i < nsets; i++) { |
| 64 |
for (j = i + 1; j < nsets; j++) { |
| 65 |
indices[j][i] = indices[i][j]; |
| 66 |
} |
| 67 |
} |
| 68 |
} |