| [2aa6644] | 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 | * Projection routines.
|
|---|
| 17 | *
|
|---|
| 18 | *****************************************************************************/
|
|---|
| 19 |
|
|---|
| 20 | #include "headers.h"
|
|---|
| 21 |
|
|---|
| 22 | /*--------------------------------------------------------------------------
|
|---|
| 23 | * hypre_ProjectBox:
|
|---|
| 24 | * Projects a box onto a strided index space that contains the
|
|---|
| 25 | * index `index' and has stride `stride'.
|
|---|
| 26 | *
|
|---|
| 27 | * Note: An "empty" projection is represented by a box with volume 0.
|
|---|
| 28 | *--------------------------------------------------------------------------*/
|
|---|
| 29 |
|
|---|
| 30 | int
|
|---|
| 31 | hypre_ProjectBox( hypre_Box *box,
|
|---|
| 32 | hypre_Index index,
|
|---|
| 33 | hypre_Index stride )
|
|---|
| 34 | {
|
|---|
| 35 | int i, s, d, hl, hu, kl, ku;
|
|---|
| 36 | int ierr = 0;
|
|---|
| 37 |
|
|---|
| 38 | /*------------------------------------------------------
|
|---|
| 39 | * project in all 3 dimensions
|
|---|
| 40 | *------------------------------------------------------*/
|
|---|
| 41 |
|
|---|
| 42 | for (d = 0; d < 3; d++)
|
|---|
| 43 | {
|
|---|
| 44 |
|
|---|
| 45 | i = hypre_IndexD(index, d);
|
|---|
| 46 | s = hypre_IndexD(stride, d);
|
|---|
| 47 |
|
|---|
| 48 | hl = hypre_BoxIMinD(box, d) - i;
|
|---|
| 49 | hu = hypre_BoxIMaxD(box, d) - i;
|
|---|
| 50 |
|
|---|
| 51 | if ( hl <= 0 )
|
|---|
| 52 | kl = (int) (hl / s);
|
|---|
| 53 | else
|
|---|
| 54 | kl = (int) ((hl + (s-1)) / s);
|
|---|
| 55 |
|
|---|
| 56 | if ( hu >= 0 )
|
|---|
| 57 | ku = (int) (hu / s);
|
|---|
| 58 | else
|
|---|
| 59 | ku = (int) ((hu - (s-1)) / s);
|
|---|
| 60 |
|
|---|
| 61 | hypre_BoxIMinD(box, d) = i + kl * s;
|
|---|
| 62 | hypre_BoxIMaxD(box, d) = i + ku * s;
|
|---|
| 63 |
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | return ierr;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | /*--------------------------------------------------------------------------
|
|---|
| 70 | * hypre_ProjectBoxArray:
|
|---|
| 71 | *
|
|---|
| 72 | * Note: The dimensions of the modified box array are not changed.
|
|---|
| 73 | * So, it is possible to have boxes with volume 0.
|
|---|
| 74 | *--------------------------------------------------------------------------*/
|
|---|
| 75 |
|
|---|
| 76 | int
|
|---|
| 77 | hypre_ProjectBoxArray( hypre_BoxArray *box_array,
|
|---|
| 78 | hypre_Index index,
|
|---|
| 79 | hypre_Index stride )
|
|---|
| 80 | {
|
|---|
| 81 | hypre_Box *box;
|
|---|
| 82 | int i;
|
|---|
| 83 | int ierr = 0;
|
|---|
| 84 |
|
|---|
| 85 | hypre_ForBoxI(i, box_array)
|
|---|
| 86 | {
|
|---|
| 87 | box = hypre_BoxArrayBox(box_array, i);
|
|---|
| 88 | hypre_ProjectBox(box, index, stride);
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | return ierr;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | /*--------------------------------------------------------------------------
|
|---|
| 95 | * hypre_ProjectBoxArrayArray:
|
|---|
| 96 | *
|
|---|
| 97 | * Note: The dimensions of the modified box array-array are not changed.
|
|---|
| 98 | * So, it is possible to have boxes with volume 0.
|
|---|
| 99 | *--------------------------------------------------------------------------*/
|
|---|
| 100 |
|
|---|
| 101 | int
|
|---|
| 102 | hypre_ProjectBoxArrayArray( hypre_BoxArrayArray *box_array_array,
|
|---|
| 103 | hypre_Index index,
|
|---|
| 104 | hypre_Index stride )
|
|---|
| 105 | {
|
|---|
| 106 | hypre_BoxArray *box_array;
|
|---|
| 107 | hypre_Box *box;
|
|---|
| 108 | int i, j;
|
|---|
| 109 | int ierr = 0;
|
|---|
| 110 |
|
|---|
| 111 | hypre_ForBoxArrayI(i, box_array_array)
|
|---|
| 112 | {
|
|---|
| 113 | box_array = hypre_BoxArrayArrayBoxArray(box_array_array, i);
|
|---|
| 114 | hypre_ForBoxI(j, box_array)
|
|---|
| 115 | {
|
|---|
| 116 | box = hypre_BoxArrayBox(box_array, j);
|
|---|
| 117 | hypre_ProjectBox(box, index, stride);
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | return ierr;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|