| 1 | /*BHEADER**********************************************************************
|
|---|
| 2 | * Copyright (c) 2008, Lawrence Livermore National Security, LLC.
|
|---|
| 3 | * Produced at the Lawrence Livermore National Laboratory.
|
|---|
| 4 | * This file is part of HYPRE. See file COPYRIGHT for details.
|
|---|
| 5 | *
|
|---|
| 6 | * HYPRE is free software; you can redistribute it and/or modify it under the
|
|---|
| 7 | * terms of the GNU Lesser General Public License (as published by the Free
|
|---|
| 8 | * Software Foundation) version 2.1 dated February 1999.
|
|---|
| 9 | *
|
|---|
| 10 | * $Revision: 2.4 $
|
|---|
| 11 | ***********************************************************************EHEADER*/
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | /******************************************************************************
|
|---|
| 15 | *
|
|---|
| 16 | * Member functions for hypre_Box class:
|
|---|
| 17 | * Box algebra functions.
|
|---|
| 18 | *
|
|---|
| 19 | *****************************************************************************/
|
|---|
| 20 |
|
|---|
| 21 | #include "headers.h"
|
|---|
| 22 |
|
|---|
| 23 | /*--------------------------------------------------------------------------
|
|---|
| 24 | * Intersect box1 and box2.
|
|---|
| 25 | * If the boxes do not intersect, the result is a box with zero volume.
|
|---|
| 26 | *--------------------------------------------------------------------------*/
|
|---|
| 27 |
|
|---|
| 28 | int
|
|---|
| 29 | hypre_IntersectBoxes( hypre_Box *box1,
|
|---|
| 30 | hypre_Box *box2,
|
|---|
| 31 | hypre_Box *ibox )
|
|---|
| 32 | {
|
|---|
| 33 | int ierr = 0;
|
|---|
| 34 | int d;
|
|---|
| 35 |
|
|---|
| 36 | /* find x, y, and z bounds */
|
|---|
| 37 | for (d = 0; d < 3; d++)
|
|---|
| 38 | {
|
|---|
| 39 | hypre_BoxIMinD(ibox, d) =
|
|---|
| 40 | hypre_max(hypre_BoxIMinD(box1, d), hypre_BoxIMinD(box2, d));
|
|---|
| 41 | hypre_BoxIMaxD(ibox, d) =
|
|---|
| 42 | hypre_min(hypre_BoxIMaxD(box1, d), hypre_BoxIMaxD(box2, d));
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | return ierr;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | /*--------------------------------------------------------------------------
|
|---|
| 49 | * Compute (box1 - box2) and append result to box_array.
|
|---|
| 50 | *--------------------------------------------------------------------------*/
|
|---|
| 51 |
|
|---|
| 52 | int
|
|---|
| 53 | hypre_SubtractBoxes( hypre_Box *box1,
|
|---|
| 54 | hypre_Box *box2,
|
|---|
| 55 | hypre_BoxArray *box_array )
|
|---|
| 56 | {
|
|---|
| 57 | int ierr = 0;
|
|---|
| 58 |
|
|---|
| 59 | hypre_Box *box;
|
|---|
| 60 | hypre_Box *rembox;
|
|---|
| 61 | int d, size;
|
|---|
| 62 |
|
|---|
| 63 | /*------------------------------------------------------
|
|---|
| 64 | * Set the box array size to the maximum possible,
|
|---|
| 65 | * plus one, to have space for the remainder box.
|
|---|
| 66 | *------------------------------------------------------*/
|
|---|
| 67 |
|
|---|
| 68 | size = hypre_BoxArraySize(box_array);
|
|---|
| 69 | hypre_BoxArraySetSize(box_array, (size + 7));
|
|---|
| 70 |
|
|---|
| 71 | /*------------------------------------------------------
|
|---|
| 72 | * Subtract the boxes by cutting box1 in x, y, then z
|
|---|
| 73 | *------------------------------------------------------*/
|
|---|
| 74 |
|
|---|
| 75 | rembox = hypre_BoxArrayBox(box_array, (size + 6));
|
|---|
| 76 | hypre_CopyBox(box1, rembox);
|
|---|
| 77 |
|
|---|
| 78 | for (d = 0; d < 3; d++)
|
|---|
| 79 | {
|
|---|
| 80 | /* if the boxes do not intersect, the subtraction is trivial */
|
|---|
| 81 | if ( (hypre_BoxIMinD(box2, d) > hypre_BoxIMaxD(rembox, d)) ||
|
|---|
| 82 | (hypre_BoxIMaxD(box2, d) < hypre_BoxIMinD(rembox, d)) )
|
|---|
| 83 | {
|
|---|
| 84 | size = hypre_BoxArraySize(box_array) - 7;
|
|---|
| 85 | hypre_CopyBox(box1, hypre_BoxArrayBox(box_array, size));
|
|---|
| 86 | size++;
|
|---|
| 87 | break;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | /* update the box array */
|
|---|
| 91 | else
|
|---|
| 92 | {
|
|---|
| 93 | if ( hypre_BoxIMinD(box2, d) > hypre_BoxIMinD(rembox, d) )
|
|---|
| 94 | {
|
|---|
| 95 | box = hypre_BoxArrayBox(box_array, size);
|
|---|
| 96 | hypre_CopyBox(rembox, box);
|
|---|
| 97 | hypre_BoxIMaxD(box, d) = hypre_BoxIMinD(box2, d) - 1;
|
|---|
| 98 | hypre_BoxIMinD(rembox, d) = hypre_BoxIMinD(box2, d);
|
|---|
| 99 | if ( hypre_BoxVolume(box)>0 ) size++;
|
|---|
| 100 | }
|
|---|
| 101 | if ( hypre_BoxIMaxD(box2, d) < hypre_BoxIMaxD(rembox, d) )
|
|---|
| 102 | {
|
|---|
| 103 | box = hypre_BoxArrayBox(box_array, size);
|
|---|
| 104 | hypre_CopyBox(rembox, box);
|
|---|
| 105 | hypre_BoxIMinD(box, d) = hypre_BoxIMaxD(box2, d) + 1;
|
|---|
| 106 | hypre_BoxIMaxD(rembox, d) = hypre_BoxIMaxD(box2, d);
|
|---|
| 107 | if ( hypre_BoxVolume(box)>0 ) size++;
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | }
|
|---|
| 111 | hypre_BoxArraySetSize(box_array, size);
|
|---|
| 112 |
|
|---|
| 113 | return ierr;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | /*--------------------------------------------------------------------------
|
|---|
| 117 | * Compute (box_array1 - box_array2) and replace box_array1 with result.
|
|---|
| 118 | *--------------------------------------------------------------------------*/
|
|---|
| 119 |
|
|---|
| 120 | int
|
|---|
| 121 | hypre_SubtractBoxArrays( hypre_BoxArray *box_array1,
|
|---|
| 122 | hypre_BoxArray *box_array2,
|
|---|
| 123 | hypre_BoxArray *tmp_box_array )
|
|---|
| 124 | {
|
|---|
| 125 | int ierr = 0;
|
|---|
| 126 |
|
|---|
| 127 | hypre_BoxArray *diff_boxes = box_array1;
|
|---|
| 128 | hypre_BoxArray *new_diff_boxes = tmp_box_array;
|
|---|
| 129 | hypre_BoxArray box_array;
|
|---|
| 130 | hypre_Box *box1;
|
|---|
| 131 | hypre_Box *box2;
|
|---|
| 132 | int i, k;
|
|---|
| 133 |
|
|---|
| 134 | hypre_ForBoxI(i, box_array2)
|
|---|
| 135 | {
|
|---|
| 136 | box2 = hypre_BoxArrayBox(box_array2, i);
|
|---|
| 137 |
|
|---|
| 138 | /* compute new_diff_boxes = (diff_boxes - box2) */
|
|---|
| 139 | hypre_BoxArraySetSize(new_diff_boxes, 0);
|
|---|
| 140 | hypre_ForBoxI(k, diff_boxes)
|
|---|
| 141 | {
|
|---|
| 142 | box1 = hypre_BoxArrayBox(diff_boxes, k);
|
|---|
| 143 | hypre_SubtractBoxes(box1, box2, new_diff_boxes);
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | /* swap internals of diff_boxes and new_diff_boxes */
|
|---|
| 147 | box_array = *new_diff_boxes;
|
|---|
| 148 | *new_diff_boxes = *diff_boxes;
|
|---|
| 149 | *diff_boxes = box_array;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | return ierr;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | /*--------------------------------------------------------------------------
|
|---|
| 156 | * Compute (box_array1 - box_array2) (excluding boxa and boxb from box_array2)
|
|---|
| 157 | * and replace box_array1 with result.
|
|---|
| 158 | *--------------------------------------------------------------------------*/
|
|---|
| 159 |
|
|---|
| 160 | int
|
|---|
| 161 | hypre_SubtractBoxArraysExceptBoxes( hypre_BoxArray *box_array1,
|
|---|
| 162 | hypre_BoxArray *box_array2,
|
|---|
| 163 | hypre_BoxArray *tmp_box_array,
|
|---|
| 164 | hypre_Box *boxa, hypre_Box *boxb )
|
|---|
| 165 | {
|
|---|
| 166 | int ierr = 0;
|
|---|
| 167 |
|
|---|
| 168 | hypre_BoxArray *diff_boxes = box_array1;
|
|---|
| 169 | hypre_BoxArray *new_diff_boxes = tmp_box_array;
|
|---|
| 170 | hypre_BoxArray box_array;
|
|---|
| 171 | hypre_Box *box1;
|
|---|
| 172 | hypre_Box *box2;
|
|---|
| 173 | int i, k;
|
|---|
| 174 |
|
|---|
| 175 | hypre_ForBoxI(i, box_array2)
|
|---|
| 176 | {
|
|---|
| 177 | box2 = hypre_BoxArrayBox(box_array2, i);
|
|---|
| 178 |
|
|---|
| 179 | if ( (! hypre_BoxEqualP(boxa,box2)) && (! hypre_BoxEqualP(boxb,box2)) )
|
|---|
| 180 | {
|
|---|
| 181 | /* compute new_diff_boxes = (diff_boxes - box2) */
|
|---|
| 182 | hypre_BoxArraySetSize(new_diff_boxes, 0);
|
|---|
| 183 | hypre_ForBoxI(k, diff_boxes)
|
|---|
| 184 | {
|
|---|
| 185 | box1 = hypre_BoxArrayBox(diff_boxes, k);
|
|---|
| 186 | hypre_SubtractBoxes(box1, box2, new_diff_boxes);
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | /* swap internals of diff_boxes and new_diff_boxes */
|
|---|
| 190 | box_array = *new_diff_boxes;
|
|---|
| 191 | *new_diff_boxes = *diff_boxes;
|
|---|
| 192 | *diff_boxes = box_array;
|
|---|
| 193 | }
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | return ierr;
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | /*--------------------------------------------------------------------------
|
|---|
| 200 | * Compute the union of all boxes.
|
|---|
| 201 | *
|
|---|
| 202 | * To compute the union, we first construct a logically rectangular,
|
|---|
| 203 | * variably spaced, 3D grid called block. Each cell (i,j,k) of block
|
|---|
| 204 | * corresponds to a box with extents given by
|
|---|
| 205 | *
|
|---|
| 206 | * iminx = block_index[0][i]
|
|---|
| 207 | * iminy = block_index[1][j]
|
|---|
| 208 | * iminz = block_index[2][k]
|
|---|
| 209 | * imaxx = block_index[0][i+1] - 1
|
|---|
| 210 | * imaxy = block_index[1][j+1] - 1
|
|---|
| 211 | * imaxz = block_index[2][k+1] - 1
|
|---|
| 212 | *
|
|---|
| 213 | * The size of block is given by
|
|---|
| 214 | *
|
|---|
| 215 | * sizex = block_sz[0]
|
|---|
| 216 | * sizey = block_sz[1]
|
|---|
| 217 | * sizez = block_sz[2]
|
|---|
| 218 | *
|
|---|
| 219 | * We initially set all cells of block that are part of the union to
|
|---|
| 220 | *
|
|---|
| 221 | * factor[2] + factor[1] + factor[0]
|
|---|
| 222 | *
|
|---|
| 223 | * where
|
|---|
| 224 | *
|
|---|
| 225 | * factor[0] = 1;
|
|---|
| 226 | * factor[1] = (block_sz[0] + 1);
|
|---|
| 227 | * factor[2] = (block_sz[1] + 1) * factor[1];
|
|---|
| 228 | *
|
|---|
| 229 | * The cells of block are then "joined" in x first, then y, then z.
|
|---|
| 230 | * The result is that each nonzero entry of block corresponds to a
|
|---|
| 231 | * box in the union with extents defined by factoring the entry, then
|
|---|
| 232 | * indexing into the block_index array.
|
|---|
| 233 | *
|
|---|
| 234 | * Note: Special care has to be taken for boxes of size 0.
|
|---|
| 235 | *
|
|---|
| 236 | *--------------------------------------------------------------------------*/
|
|---|
| 237 |
|
|---|
| 238 | int
|
|---|
| 239 | hypre_UnionBoxes( hypre_BoxArray *boxes )
|
|---|
| 240 | {
|
|---|
| 241 | int ierr = 0;
|
|---|
| 242 |
|
|---|
| 243 | hypre_Box *box;
|
|---|
| 244 |
|
|---|
| 245 | int *block_index[3];
|
|---|
| 246 | int block_sz[3], block_volume;
|
|---|
| 247 | int *block;
|
|---|
| 248 | int index;
|
|---|
| 249 | int size;
|
|---|
| 250 | int factor[3];
|
|---|
| 251 |
|
|---|
| 252 | int iminmax[2], imin[3], imax[3];
|
|---|
| 253 | int ii[3], dd[3];
|
|---|
| 254 | int join;
|
|---|
| 255 | int i_tmp0, i_tmp1;
|
|---|
| 256 | int ioff, joff, koff;
|
|---|
| 257 | int bi, d, i, j, k;
|
|---|
| 258 |
|
|---|
| 259 | int index_not_there;
|
|---|
| 260 |
|
|---|
| 261 | /*------------------------------------------------------
|
|---|
| 262 | * If the size of boxes is less than 2, return
|
|---|
| 263 | *------------------------------------------------------*/
|
|---|
| 264 |
|
|---|
| 265 | if (hypre_BoxArraySize(boxes) < 2)
|
|---|
| 266 | {
|
|---|
| 267 | return ierr;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | /*------------------------------------------------------
|
|---|
| 271 | * Set up the block_index array
|
|---|
| 272 | *------------------------------------------------------*/
|
|---|
| 273 |
|
|---|
| 274 | i_tmp0 = 2 * hypre_BoxArraySize(boxes);
|
|---|
| 275 | block_index[0] = hypre_TAlloc(int, 3 * i_tmp0);
|
|---|
| 276 | block_sz[0] = 0;
|
|---|
| 277 | for (d = 1; d < 3; d++)
|
|---|
| 278 | {
|
|---|
| 279 | block_index[d] = block_index[d-1] + i_tmp0;
|
|---|
| 280 | block_sz[d] = 0;
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | hypre_ForBoxI(bi, boxes)
|
|---|
| 284 | {
|
|---|
| 285 | box = hypre_BoxArrayBox(boxes, bi);
|
|---|
| 286 |
|
|---|
| 287 | for (d = 0; d < 3; d++)
|
|---|
| 288 | {
|
|---|
| 289 | iminmax[0] = hypre_BoxIMinD(box, d);
|
|---|
| 290 | iminmax[1] = hypre_BoxIMaxD(box, d) + 1;
|
|---|
| 291 |
|
|---|
| 292 | for (i = 0; i < 2; i++)
|
|---|
| 293 | {
|
|---|
| 294 | /* find the new index position in the block_index array */
|
|---|
| 295 | index_not_there = 1;
|
|---|
| 296 | for (j = 0; j < block_sz[d]; j++)
|
|---|
| 297 | {
|
|---|
| 298 | if (iminmax[i] <= block_index[d][j])
|
|---|
| 299 | {
|
|---|
| 300 | if (iminmax[i] == block_index[d][j])
|
|---|
| 301 | index_not_there = 0;
|
|---|
| 302 | break;
|
|---|
| 303 | }
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 | /* if the index is already there, don't add it again */
|
|---|
| 307 | if (index_not_there)
|
|---|
| 308 | {
|
|---|
| 309 | for (k = block_sz[d]; k > j; k--)
|
|---|
| 310 | block_index[d][k] = block_index[d][k-1];
|
|---|
| 311 | block_index[d][j] = iminmax[i];
|
|---|
| 312 | block_sz[d]++;
|
|---|
| 313 | }
|
|---|
| 314 | }
|
|---|
| 315 | }
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | for (d = 0; d < 3; d++)
|
|---|
| 319 | block_sz[d]--;
|
|---|
| 320 | block_volume = block_sz[0] * block_sz[1] * block_sz[2];
|
|---|
| 321 |
|
|---|
| 322 | /*------------------------------------------------------
|
|---|
| 323 | * Set factor values
|
|---|
| 324 | *------------------------------------------------------*/
|
|---|
| 325 |
|
|---|
| 326 | factor[0] = 1;
|
|---|
| 327 | factor[1] = (block_sz[0] + 1);
|
|---|
| 328 | factor[2] = (block_sz[1] + 1) * factor[1];
|
|---|
| 329 |
|
|---|
| 330 | /*------------------------------------------------------
|
|---|
| 331 | * Set up the block array
|
|---|
| 332 | *------------------------------------------------------*/
|
|---|
| 333 |
|
|---|
| 334 | block = hypre_CTAlloc(int, block_volume);
|
|---|
| 335 |
|
|---|
| 336 | hypre_ForBoxI(bi, boxes)
|
|---|
| 337 | {
|
|---|
| 338 | box = hypre_BoxArrayBox(boxes, bi);
|
|---|
| 339 |
|
|---|
| 340 | /* find the block_index indices corresponding to the current box */
|
|---|
| 341 | for (d = 0; d < 3; d++)
|
|---|
| 342 | {
|
|---|
| 343 | j = 0;
|
|---|
| 344 |
|
|---|
| 345 | while (hypre_BoxIMinD(box, d) != block_index[d][j])
|
|---|
| 346 | j++;
|
|---|
| 347 | imin[d] = j;
|
|---|
| 348 |
|
|---|
| 349 | while (hypre_BoxIMaxD(box, d) + 1 != block_index[d][j])
|
|---|
| 350 | j++;
|
|---|
| 351 | imax[d] = j;
|
|---|
| 352 | }
|
|---|
| 353 |
|
|---|
| 354 | /* note: boxes of size zero will not be added to block */
|
|---|
| 355 | for (k = imin[2]; k < imax[2]; k++)
|
|---|
| 356 | {
|
|---|
| 357 | for (j = imin[1]; j < imax[1]; j++)
|
|---|
| 358 | {
|
|---|
| 359 | for (i = imin[0]; i < imax[0]; i++)
|
|---|
| 360 | {
|
|---|
| 361 | index = ((k) * block_sz[1] + j) * block_sz[0] + i;
|
|---|
| 362 |
|
|---|
| 363 | block[index] = factor[2] + factor[1] + factor[0];
|
|---|
| 364 | }
|
|---|
| 365 | }
|
|---|
| 366 | }
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | /*------------------------------------------------------
|
|---|
| 370 | * Join block array in x, then y, then z
|
|---|
| 371 | *
|
|---|
| 372 | * Notes:
|
|---|
| 373 | * - ii[0], ii[1], and ii[2] correspond to indices
|
|---|
| 374 | * in x, y, and z respectively.
|
|---|
| 375 | * - dd specifies the order in which to loop over
|
|---|
| 376 | * the three dimensions.
|
|---|
| 377 | *------------------------------------------------------*/
|
|---|
| 378 |
|
|---|
| 379 | for (d = 0; d < 3; d++)
|
|---|
| 380 | {
|
|---|
| 381 | switch(d)
|
|---|
| 382 | {
|
|---|
| 383 | case 0: /* join in x */
|
|---|
| 384 | dd[0] = 0;
|
|---|
| 385 | dd[1] = 1;
|
|---|
| 386 | dd[2] = 2;
|
|---|
| 387 | break;
|
|---|
| 388 |
|
|---|
| 389 | case 1: /* join in y */
|
|---|
| 390 | dd[0] = 1;
|
|---|
| 391 | dd[1] = 0;
|
|---|
| 392 | dd[2] = 2;
|
|---|
| 393 | break;
|
|---|
| 394 |
|
|---|
| 395 | case 2: /* join in z */
|
|---|
| 396 | dd[0] = 2;
|
|---|
| 397 | dd[1] = 1;
|
|---|
| 398 | dd[2] = 0;
|
|---|
| 399 | break;
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | for (ii[dd[2]] = 0; ii[dd[2]] < block_sz[dd[2]]; ii[dd[2]]++)
|
|---|
| 403 | {
|
|---|
| 404 | for (ii[dd[1]] = 0; ii[dd[1]] < block_sz[dd[1]]; ii[dd[1]]++)
|
|---|
| 405 | {
|
|---|
| 406 | join = 0;
|
|---|
| 407 | for (ii[dd[0]] = 0; ii[dd[0]] < block_sz[dd[0]]; ii[dd[0]]++)
|
|---|
| 408 | {
|
|---|
| 409 | index = ((ii[2]) * block_sz[1] + ii[1]) * block_sz[0] + ii[0];
|
|---|
| 410 |
|
|---|
| 411 | if ((join) && (block[index] == i_tmp1))
|
|---|
| 412 | {
|
|---|
| 413 | block[index] = 0;
|
|---|
| 414 | block[i_tmp0] += factor[dd[0]];
|
|---|
| 415 | }
|
|---|
| 416 | else
|
|---|
| 417 | {
|
|---|
| 418 | if (block[index])
|
|---|
| 419 | {
|
|---|
| 420 | i_tmp0 = index;
|
|---|
| 421 | i_tmp1 = block[index];
|
|---|
| 422 | join = 1;
|
|---|
| 423 | }
|
|---|
| 424 | else
|
|---|
| 425 | join = 0;
|
|---|
| 426 | }
|
|---|
| 427 | }
|
|---|
| 428 | }
|
|---|
| 429 | }
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | /*------------------------------------------------------
|
|---|
| 433 | * Set up the boxes BoxArray
|
|---|
| 434 | *------------------------------------------------------*/
|
|---|
| 435 |
|
|---|
| 436 | size = 0;
|
|---|
| 437 | for (index = 0; index < block_volume; index++)
|
|---|
| 438 | {
|
|---|
| 439 | if (block[index])
|
|---|
| 440 | size++;
|
|---|
| 441 | }
|
|---|
| 442 | hypre_BoxArraySetSize(boxes, size);
|
|---|
| 443 |
|
|---|
| 444 | index = 0;
|
|---|
| 445 | size = 0;
|
|---|
| 446 | for (k = 0; k < block_sz[2]; k++)
|
|---|
| 447 | {
|
|---|
| 448 | for (j = 0; j < block_sz[1]; j++)
|
|---|
| 449 | {
|
|---|
| 450 | for (i = 0; i < block_sz[0]; i++)
|
|---|
| 451 | {
|
|---|
| 452 | if (block[index])
|
|---|
| 453 | {
|
|---|
| 454 | ioff = (block[index] % factor[1]) ;
|
|---|
| 455 | joff = (block[index] % factor[2]) / factor[1];
|
|---|
| 456 | koff = (block[index] ) / factor[2];
|
|---|
| 457 |
|
|---|
| 458 | box = hypre_BoxArrayBox(boxes, size);
|
|---|
| 459 | hypre_BoxIMinD(box, 0) = block_index[0][i];
|
|---|
| 460 | hypre_BoxIMinD(box, 1) = block_index[1][j];
|
|---|
| 461 | hypre_BoxIMinD(box, 2) = block_index[2][k];
|
|---|
| 462 | hypre_BoxIMaxD(box, 0) = block_index[0][i + ioff] - 1;
|
|---|
| 463 | hypre_BoxIMaxD(box, 1) = block_index[1][j + joff] - 1;
|
|---|
| 464 | hypre_BoxIMaxD(box, 2) = block_index[2][k + koff] - 1;
|
|---|
| 465 |
|
|---|
| 466 | size++;
|
|---|
| 467 | }
|
|---|
| 468 |
|
|---|
| 469 | index++;
|
|---|
| 470 | }
|
|---|
| 471 | }
|
|---|
| 472 | }
|
|---|
| 473 |
|
|---|
| 474 | /*---------------------------------------------------------
|
|---|
| 475 | * Clean up and return
|
|---|
| 476 | *---------------------------------------------------------*/
|
|---|
| 477 |
|
|---|
| 478 | hypre_TFree(block_index[0]);
|
|---|
| 479 | hypre_TFree(block);
|
|---|
| 480 |
|
|---|
| 481 | return ierr;
|
|---|
| 482 | }
|
|---|
| 483 |
|
|---|
| 484 | /*--------------------------------------------------------------------------
|
|---|
| 485 | * Compute the union of all boxes such that the min. no. of boxes is
|
|---|
| 486 | * generated. Accomplished by making six calls to hypre_UnionBoxes and then
|
|---|
| 487 | * taking the union that has the least no. of boxes. The six calls union in
|
|---|
| 488 | * the order xzy, yzx, yxz, zxy, zyx, xyz
|
|---|
| 489 | *--------------------------------------------------------------------------*/
|
|---|
| 490 | int
|
|---|
| 491 | hypre_MinUnionBoxes( hypre_BoxArray *boxes )
|
|---|
| 492 | {
|
|---|
| 493 | int ierr = 0;
|
|---|
| 494 |
|
|---|
| 495 | hypre_BoxArrayArray *rotated_array;
|
|---|
| 496 | hypre_BoxArray *rotated_boxes;
|
|---|
| 497 | hypre_Box *box, *rotated_box;
|
|---|
| 498 | hypre_Index lower, upper;
|
|---|
| 499 |
|
|---|
| 500 | int i, j, size, min_size, array;
|
|---|
| 501 |
|
|---|
| 502 | size= hypre_BoxArraySize(boxes);
|
|---|
| 503 | rotated_box= hypre_CTAlloc(hypre_Box, 1);
|
|---|
| 504 | rotated_array= hypre_BoxArrayArrayCreate(5);
|
|---|
| 505 |
|
|---|
| 506 | for (i= 0; i< 5; i++)
|
|---|
| 507 | {
|
|---|
| 508 | rotated_boxes= hypre_BoxArrayArrayBoxArray(rotated_array, i);
|
|---|
| 509 | switch(i)
|
|---|
| 510 | {
|
|---|
| 511 | case 0:
|
|---|
| 512 | for (j= 0; j< size; j++)
|
|---|
| 513 | {
|
|---|
| 514 | box= hypre_BoxArrayBox(boxes, j);
|
|---|
| 515 | hypre_SetIndex(lower, hypre_BoxIMin(box)[0], hypre_BoxIMin(box)[2],
|
|---|
| 516 | hypre_BoxIMin(box)[1]);
|
|---|
| 517 | hypre_SetIndex(upper, hypre_BoxIMax(box)[0], hypre_BoxIMax(box)[2],
|
|---|
| 518 | hypre_BoxIMax(box)[1]);
|
|---|
| 519 | hypre_BoxSetExtents(rotated_box, lower, upper);
|
|---|
| 520 | hypre_AppendBox(rotated_box, rotated_boxes);
|
|---|
| 521 | }
|
|---|
| 522 | hypre_UnionBoxes(rotated_boxes);
|
|---|
| 523 | break;
|
|---|
| 524 |
|
|---|
| 525 | case 1:
|
|---|
| 526 | for (j= 0; j< size; j++)
|
|---|
| 527 | {
|
|---|
| 528 | box= hypre_BoxArrayBox(boxes, j);
|
|---|
| 529 | hypre_SetIndex(lower, hypre_BoxIMin(box)[1], hypre_BoxIMin(box)[2],
|
|---|
| 530 | hypre_BoxIMin(box)[0]);
|
|---|
| 531 | hypre_SetIndex(upper, hypre_BoxIMax(box)[1], hypre_BoxIMax(box)[2],
|
|---|
| 532 | hypre_BoxIMax(box)[0]);
|
|---|
| 533 | hypre_BoxSetExtents(rotated_box, lower, upper);
|
|---|
| 534 | hypre_AppendBox(rotated_box, rotated_boxes);
|
|---|
| 535 | }
|
|---|
| 536 | hypre_UnionBoxes(rotated_boxes);
|
|---|
| 537 | break;
|
|---|
| 538 |
|
|---|
| 539 | case 2:
|
|---|
| 540 | for (j= 0; j< size; j++)
|
|---|
| 541 | {
|
|---|
| 542 | box= hypre_BoxArrayBox(boxes, j);
|
|---|
| 543 | hypre_SetIndex(lower, hypre_BoxIMin(box)[1], hypre_BoxIMin(box)[0],
|
|---|
| 544 | hypre_BoxIMin(box)[2]);
|
|---|
| 545 | hypre_SetIndex(upper, hypre_BoxIMax(box)[1], hypre_BoxIMax(box)[0],
|
|---|
| 546 | hypre_BoxIMax(box)[2]);
|
|---|
| 547 | hypre_BoxSetExtents(rotated_box, lower, upper);
|
|---|
| 548 | hypre_AppendBox(rotated_box, rotated_boxes);
|
|---|
| 549 | }
|
|---|
| 550 | hypre_UnionBoxes(rotated_boxes);
|
|---|
| 551 | break;
|
|---|
| 552 |
|
|---|
| 553 | case 3:
|
|---|
| 554 | for (j= 0; j< size; j++)
|
|---|
| 555 | {
|
|---|
| 556 | box= hypre_BoxArrayBox(boxes, j);
|
|---|
| 557 | hypre_SetIndex(lower, hypre_BoxIMin(box)[2], hypre_BoxIMin(box)[0],
|
|---|
| 558 | hypre_BoxIMin(box)[1]);
|
|---|
| 559 | hypre_SetIndex(upper, hypre_BoxIMax(box)[2], hypre_BoxIMax(box)[0],
|
|---|
| 560 | hypre_BoxIMax(box)[1]);
|
|---|
| 561 | hypre_BoxSetExtents(rotated_box, lower, upper);
|
|---|
| 562 | hypre_AppendBox(rotated_box, rotated_boxes);
|
|---|
| 563 | }
|
|---|
| 564 | hypre_UnionBoxes(rotated_boxes);
|
|---|
| 565 | break;
|
|---|
| 566 |
|
|---|
| 567 | case 4:
|
|---|
| 568 | for (j= 0; j< size; j++)
|
|---|
| 569 | {
|
|---|
| 570 | box= hypre_BoxArrayBox(boxes, j);
|
|---|
| 571 | hypre_SetIndex(lower, hypre_BoxIMin(box)[2], hypre_BoxIMin(box)[1],
|
|---|
| 572 | hypre_BoxIMin(box)[0]);
|
|---|
| 573 | hypre_SetIndex(upper, hypre_BoxIMax(box)[2], hypre_BoxIMax(box)[1],
|
|---|
| 574 | hypre_BoxIMax(box)[0]);
|
|---|
| 575 | hypre_BoxSetExtents(rotated_box, lower, upper);
|
|---|
| 576 | hypre_AppendBox(rotated_box, rotated_boxes);
|
|---|
| 577 | }
|
|---|
| 578 | hypre_UnionBoxes(rotated_boxes);
|
|---|
| 579 | break;
|
|---|
| 580 |
|
|---|
| 581 | } /*switch(i) */
|
|---|
| 582 | } /* for (i= 0; i< 5; i++) */
|
|---|
| 583 | hypre_TFree(rotated_box);
|
|---|
| 584 |
|
|---|
| 585 | hypre_UnionBoxes(boxes);
|
|---|
| 586 |
|
|---|
| 587 | array= 5;
|
|---|
| 588 | min_size= hypre_BoxArraySize(boxes);
|
|---|
| 589 |
|
|---|
| 590 | for (i= 0; i< 5; i++)
|
|---|
| 591 | {
|
|---|
| 592 | rotated_boxes= hypre_BoxArrayArrayBoxArray(rotated_array, i);
|
|---|
| 593 | if (hypre_BoxArraySize(rotated_boxes) < min_size)
|
|---|
| 594 | {
|
|---|
| 595 | min_size= hypre_BoxArraySize(rotated_boxes);
|
|---|
| 596 | array= i;
|
|---|
| 597 | }
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 | /* copy the box_array with the minimum number of boxes to boxes */
|
|---|
| 601 | if (array != 5)
|
|---|
| 602 | {
|
|---|
| 603 | rotated_boxes= hypre_BoxArrayArrayBoxArray(rotated_array, array);
|
|---|
| 604 | hypre_BoxArraySize(boxes)= min_size;
|
|---|
| 605 |
|
|---|
| 606 | switch(array)
|
|---|
| 607 | {
|
|---|
| 608 | case 0:
|
|---|
| 609 | for (j= 0; j< min_size; j++)
|
|---|
| 610 | {
|
|---|
| 611 | rotated_box= hypre_BoxArrayBox(rotated_boxes, j);
|
|---|
| 612 | hypre_SetIndex(lower, hypre_BoxIMin(rotated_box)[0], hypre_BoxIMin(rotated_box)[2],
|
|---|
| 613 | hypre_BoxIMin(rotated_box)[1]);
|
|---|
| 614 | hypre_SetIndex(upper, hypre_BoxIMax(rotated_box)[0], hypre_BoxIMax(rotated_box)[2],
|
|---|
| 615 | hypre_BoxIMax(rotated_box)[1]);
|
|---|
| 616 |
|
|---|
| 617 | hypre_BoxSetExtents( hypre_BoxArrayBox(boxes, j), lower, upper);
|
|---|
| 618 | }
|
|---|
| 619 | break;
|
|---|
| 620 |
|
|---|
| 621 | case 1:
|
|---|
| 622 | for (j= 0; j< min_size; j++)
|
|---|
| 623 | {
|
|---|
| 624 | rotated_box= hypre_BoxArrayBox(rotated_boxes, j);
|
|---|
| 625 | hypre_SetIndex(lower, hypre_BoxIMin(rotated_box)[2], hypre_BoxIMin(rotated_box)[0],
|
|---|
| 626 | hypre_BoxIMin(rotated_box)[1]);
|
|---|
| 627 | hypre_SetIndex(upper, hypre_BoxIMax(rotated_box)[2], hypre_BoxIMax(rotated_box)[0],
|
|---|
| 628 | hypre_BoxIMax(rotated_box)[1]);
|
|---|
| 629 |
|
|---|
| 630 | hypre_BoxSetExtents( hypre_BoxArrayBox(boxes, j), lower, upper);
|
|---|
| 631 | }
|
|---|
| 632 | break;
|
|---|
| 633 |
|
|---|
| 634 | case 2:
|
|---|
| 635 | for (j= 0; j< min_size; j++)
|
|---|
| 636 | {
|
|---|
| 637 | rotated_box= hypre_BoxArrayBox(rotated_boxes, j);
|
|---|
| 638 | hypre_SetIndex(lower, hypre_BoxIMin(rotated_box)[1], hypre_BoxIMin(rotated_box)[0],
|
|---|
| 639 | hypre_BoxIMin(rotated_box)[2]);
|
|---|
| 640 | hypre_SetIndex(upper, hypre_BoxIMax(rotated_box)[1], hypre_BoxIMax(rotated_box)[0],
|
|---|
| 641 | hypre_BoxIMax(rotated_box)[2]);
|
|---|
| 642 |
|
|---|
| 643 | hypre_BoxSetExtents( hypre_BoxArrayBox(boxes, j), lower, upper);
|
|---|
| 644 | }
|
|---|
| 645 | break;
|
|---|
| 646 |
|
|---|
| 647 | case 3:
|
|---|
| 648 | for (j= 0; j< min_size; j++)
|
|---|
| 649 | {
|
|---|
| 650 | rotated_box= hypre_BoxArrayBox(rotated_boxes, j);
|
|---|
| 651 | hypre_SetIndex(lower, hypre_BoxIMin(rotated_box)[1], hypre_BoxIMin(rotated_box)[2],
|
|---|
| 652 | hypre_BoxIMin(rotated_box)[0]);
|
|---|
| 653 | hypre_SetIndex(upper, hypre_BoxIMax(rotated_box)[1], hypre_BoxIMax(rotated_box)[2],
|
|---|
| 654 | hypre_BoxIMax(rotated_box)[0]);
|
|---|
| 655 |
|
|---|
| 656 | hypre_BoxSetExtents( hypre_BoxArrayBox(boxes, j), lower, upper);
|
|---|
| 657 | }
|
|---|
| 658 | break;
|
|---|
| 659 |
|
|---|
| 660 | case 4:
|
|---|
| 661 | for (j= 0; j< min_size; j++)
|
|---|
| 662 | {
|
|---|
| 663 | rotated_box= hypre_BoxArrayBox(rotated_boxes, j);
|
|---|
| 664 | hypre_SetIndex(lower, hypre_BoxIMin(rotated_box)[2], hypre_BoxIMin(rotated_box)[1],
|
|---|
| 665 | hypre_BoxIMin(rotated_box)[0]);
|
|---|
| 666 | hypre_SetIndex(upper, hypre_BoxIMax(rotated_box)[2], hypre_BoxIMax(rotated_box)[1],
|
|---|
| 667 | hypre_BoxIMax(rotated_box)[0]);
|
|---|
| 668 |
|
|---|
| 669 | hypre_BoxSetExtents( hypre_BoxArrayBox(boxes, j), lower, upper);
|
|---|
| 670 | }
|
|---|
| 671 | break;
|
|---|
| 672 |
|
|---|
| 673 | } /* switch(array) */
|
|---|
| 674 | } /* if (array != 5) */
|
|---|
| 675 |
|
|---|
| 676 | hypre_BoxArrayArrayDestroy(rotated_array);
|
|---|
| 677 |
|
|---|
| 678 | return ierr;
|
|---|
| 679 | }
|
|---|
| 680 |
|
|---|