| 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 | * Functions to check for (physical) boundaries, adjacency, etc.
|
|---|
| 18 | * This is experimental code. Whatever functions I find useful will be
|
|---|
| 19 | * copied into some other file.
|
|---|
| 20 | *
|
|---|
| 21 | *****************************************************************************/
|
|---|
| 22 |
|
|---|
| 23 | #include "headers.h"
|
|---|
| 24 |
|
|---|
| 25 | /*--------------------------------------------------------------------------
|
|---|
| 26 | * Take away from the boxes in boxes1 whatever is adjacent to boxes in boxes2,
|
|---|
| 27 | * as well as the boxes themselves. But ignore "box" if it appears in boxes2.
|
|---|
| 28 | * The result is returned in boxes1. The last argument, thick, is the number
|
|---|
| 29 | * of layers around a box considered to be "adjacent", typically 1.
|
|---|
| 30 | *--------------------------------------------------------------------------*/
|
|---|
| 31 |
|
|---|
| 32 | int
|
|---|
| 33 | hypre_BoxArraySubtractAdjacentBoxArray( hypre_BoxArray *boxes1,
|
|---|
| 34 | hypre_BoxArray *boxes2,
|
|---|
| 35 | hypre_Box *box, int thick )
|
|---|
| 36 | {
|
|---|
| 37 | int ierr = 0;
|
|---|
| 38 | int i;
|
|---|
| 39 | int numexp[6];
|
|---|
| 40 | hypre_Box *box2e;
|
|---|
| 41 | hypre_Box *boxe = hypre_BoxDuplicate( box );
|
|---|
| 42 | hypre_BoxArray *boxes2e = hypre_BoxArrayDuplicate( boxes2 );
|
|---|
| 43 | hypre_BoxArray *tmp_box_array = hypre_BoxArrayCreate( 0 );
|
|---|
| 44 | for ( i=0; i<6; ++i ) numexp[i] = thick;
|
|---|
| 45 | hypre_ForBoxI(i, boxes2e)
|
|---|
| 46 | {
|
|---|
| 47 | box2e = hypre_BoxArrayBox(boxes2e, i);
|
|---|
| 48 | ierr += hypre_BoxExpand( box2e, numexp );
|
|---|
| 49 | }
|
|---|
| 50 | ierr += hypre_BoxExpand( boxe, numexp );
|
|---|
| 51 | ierr += hypre_SubtractBoxArraysExceptBoxes( boxes1, boxes2e, tmp_box_array, box, boxe );
|
|---|
| 52 |
|
|---|
| 53 | ierr += hypre_BoxArrayDestroy( boxes2e );
|
|---|
| 54 | ierr += hypre_BoxArrayDestroy( tmp_box_array );
|
|---|
| 55 | ierr += hypre_BoxDestroy( boxe );
|
|---|
| 56 |
|
|---|
| 57 | return ierr;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | /*--------------------------------------------------------------------------
|
|---|
| 61 | * Take away from the boxes in boxes1 whatever is adjacent to boxes in boxes2,
|
|---|
| 62 | * in the signed direction ds only (ds=0,1,2,3,4,5);
|
|---|
| 63 | * as well as the boxes themselves. But ignore "box" if it appears in boxes2.
|
|---|
| 64 | * The result is returned in boxes1. The last argument, thick, is the number
|
|---|
| 65 | * of layers around a box considered to be "adjacent", typically 1.
|
|---|
| 66 | *--------------------------------------------------------------------------*/
|
|---|
| 67 |
|
|---|
| 68 | int
|
|---|
| 69 | hypre_BoxArraySubtractAdjacentBoxArrayD( hypre_BoxArray *boxes1,
|
|---|
| 70 | hypre_BoxArray *boxes2,
|
|---|
| 71 | hypre_Box *box, int ds, int thick )
|
|---|
| 72 | {
|
|---|
| 73 | int ierr = 0;
|
|---|
| 74 | int i;
|
|---|
| 75 | int numexp[6];
|
|---|
| 76 | hypre_Box *box2e;
|
|---|
| 77 | hypre_Box *boxe = hypre_BoxDuplicate( box );
|
|---|
| 78 | hypre_BoxArray *boxes2e = hypre_BoxArrayDuplicate( boxes2 );
|
|---|
| 79 | hypre_BoxArray *tmp_box_array = hypre_BoxArrayCreate( 0 );
|
|---|
| 80 | for ( i=0; i<6; ++i ) numexp[i] = 0;
|
|---|
| 81 | numexp[ds] = thick;
|
|---|
| 82 | hypre_ForBoxI(i, boxes2e)
|
|---|
| 83 | {
|
|---|
| 84 | box2e = hypre_BoxArrayBox(boxes2e, i);
|
|---|
| 85 | ierr += hypre_BoxExpand( box2e, numexp );
|
|---|
| 86 | }
|
|---|
| 87 | ierr += hypre_BoxExpand( boxe, numexp );
|
|---|
| 88 | ierr += hypre_SubtractBoxArraysExceptBoxes( boxes1, boxes2e, tmp_box_array, box, boxe );
|
|---|
| 89 |
|
|---|
| 90 | ierr += hypre_BoxArrayDestroy( boxes2e );
|
|---|
| 91 | ierr += hypre_BoxArrayDestroy( tmp_box_array );
|
|---|
| 92 | ierr += hypre_BoxDestroy( boxe );
|
|---|
| 93 |
|
|---|
| 94 | return ierr;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | /*--------------------------------------------------------------------------
|
|---|
| 98 | * Find the parts of the given box which lie on a (physical) boundary, in
|
|---|
| 99 | * the supplied signed direction (ds=0,1,2,3,4,5; for unsigned directions
|
|---|
| 100 | * d=0,0,1,1,2,2). Boundary thickness is provided.
|
|---|
| 101 | * Stick them into the user-provided box array boundary (any input contents
|
|---|
| 102 | * of this box array may get changed).
|
|---|
| 103 | * The second input argument is a list of all neighbor boxes.
|
|---|
| 104 | *--------------------------------------------------------------------------*/
|
|---|
| 105 |
|
|---|
| 106 | int
|
|---|
| 107 | hypre_BoxBoundaryDNT( hypre_Box *box, hypre_BoxArray *neighbor_boxes,
|
|---|
| 108 | hypre_BoxArray *boundary, int ds, int thick )
|
|---|
| 109 | {
|
|---|
| 110 | int i;
|
|---|
| 111 | int numexp[6];
|
|---|
| 112 | int ierr = 0;
|
|---|
| 113 | hypre_Box *boxe = hypre_BoxDuplicate( box );
|
|---|
| 114 | for ( i=0; i<6; ++i ) numexp[i] = 0;
|
|---|
| 115 | numexp[ds] = -thick;
|
|---|
| 116 |
|
|---|
| 117 | ierr += hypre_BoxExpand( boxe, numexp ); /* shrink box away from boundary */
|
|---|
| 118 | ierr += hypre_SubtractBoxes( box, boxe, boundary );
|
|---|
| 119 |
|
|---|
| 120 | /* Now boundary contains the surface of the original box, in direction ds.
|
|---|
| 121 | Subtract out the neighbor boxes, and anything adjacent to a neighbor box
|
|---|
| 122 | in the opposite direction.
|
|---|
| 123 | Anything left will belong to the physical boundary. */
|
|---|
| 124 |
|
|---|
| 125 | switch(ds)
|
|---|
| 126 | {
|
|---|
| 127 | case 0:
|
|---|
| 128 | ds = 1;
|
|---|
| 129 | break;
|
|---|
| 130 | case 1:
|
|---|
| 131 | ds = 0;
|
|---|
| 132 | break;
|
|---|
| 133 | case 2:
|
|---|
| 134 | ds = 3;
|
|---|
| 135 | break;
|
|---|
| 136 | case 3:
|
|---|
| 137 | ds = 2;
|
|---|
| 138 | break;
|
|---|
| 139 | case 4:
|
|---|
| 140 | ds = 5;
|
|---|
| 141 | break;
|
|---|
| 142 | case 5:
|
|---|
| 143 | ds = 4;
|
|---|
| 144 | }
|
|---|
| 145 | ierr += hypre_BoxArraySubtractAdjacentBoxArrayD(
|
|---|
| 146 | boundary, neighbor_boxes, box, ds, thick );
|
|---|
| 147 |
|
|---|
| 148 | ierr += hypre_BoxDestroy( boxe );
|
|---|
| 149 |
|
|---|
| 150 | return ierr;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | /*--------------------------------------------------------------------------
|
|---|
| 154 | * Find the parts of the given box which lie on a (physical) boundary.
|
|---|
| 155 | * Stick them into the user-provided box array boundary (it is recommended that
|
|---|
| 156 | * this box array be empty on input).
|
|---|
| 157 | * The second input argument is a list of all neighbor boxes.
|
|---|
| 158 | * The last argument has 6 values to denote the boundary thickness in each direction.
|
|---|
| 159 | *--------------------------------------------------------------------------*/
|
|---|
| 160 |
|
|---|
| 161 | int
|
|---|
| 162 | hypre_BoxBoundaryNT( hypre_Box *box, hypre_BoxArray *neighbor_boxes,
|
|---|
| 163 | hypre_BoxArray *boundary, int* thickness )
|
|---|
| 164 | {
|
|---|
| 165 | int ds;
|
|---|
| 166 | int ierr = 0;
|
|---|
| 167 | hypre_BoxArray *boundary_d;
|
|---|
| 168 |
|
|---|
| 169 | /* We'll find the physical boundary in one direction at a time.
|
|---|
| 170 | This is so that we don't lose boundary points which are adjacent
|
|---|
| 171 | to boundary points of the neighbor boxes. */
|
|---|
| 172 | for ( ds=0; ds<6; ++ds )
|
|---|
| 173 | {
|
|---|
| 174 | boundary_d = hypre_BoxArrayCreate( 0 );
|
|---|
| 175 | ierr += hypre_BoxBoundaryDNT( box, neighbor_boxes, boundary_d,
|
|---|
| 176 | ds, thickness[ds] );
|
|---|
| 177 | ierr += hypre_AppendBoxArray( boundary_d, boundary );
|
|---|
| 178 | hypre_BoxArrayDestroy( boundary_d );
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | return ierr;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | /*--------------------------------------------------------------------------
|
|---|
| 185 | * Find the parts of the given box which lie on a (physical) boundary.
|
|---|
| 186 | * Stick them into the user-provided box array boundary (any input contents
|
|---|
| 187 | * of this box array may get changed).
|
|---|
| 188 | * The second input argument is the grid.
|
|---|
| 189 | * The boundary thickness is set to the ghost layer thickness, regardless
|
|---|
| 190 | * of whether the computed boundary will consist of ghost zones.
|
|---|
| 191 | *--------------------------------------------------------------------------*/
|
|---|
| 192 |
|
|---|
| 193 | int
|
|---|
| 194 | hypre_BoxBoundaryG( hypre_Box *box, hypre_StructGrid *g,
|
|---|
| 195 | hypre_BoxArray *boundary )
|
|---|
| 196 | {
|
|---|
| 197 | hypre_BoxNeighbors *neighbors = hypre_StructGridNeighbors(g);
|
|---|
| 198 | hypre_BoxArray *neighbor_boxes = hypre_BoxNeighborsBoxes( neighbors );
|
|---|
| 199 | /* neighbor_boxes are this processor's neighbors, not this box's
|
|---|
| 200 | neighbors. But it's likely to be cheaper to use them all in the
|
|---|
| 201 | next step than to try to shrink it to just this box's neighbors. */
|
|---|
| 202 | int * thickness = hypre_StructGridNumGhost(g);
|
|---|
| 203 | return hypre_BoxBoundaryNT( box, neighbor_boxes, boundary, thickness );
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | /*--------------------------------------------------------------------------
|
|---|
| 207 | * Find the parts of the given box which lie on a (physical) boundary, only
|
|---|
| 208 | * in the (unsigned) direction of d (d=0,1,2).
|
|---|
| 209 | * Stick them into the user-provided box arrays boundarym (for the minus direction)
|
|---|
| 210 | * and boundaryp (for the plus direction). (Any input contents of these box
|
|---|
| 211 | * arrays may get changed).
|
|---|
| 212 | * The second input argument is the grid the box is in (hypre_BoxBoundaryG).
|
|---|
| 213 | * The boundary thickness is set to 1.
|
|---|
| 214 | *--------------------------------------------------------------------------*/
|
|---|
| 215 |
|
|---|
| 216 | int
|
|---|
| 217 | hypre_BoxBoundaryDG( hypre_Box *box, hypre_StructGrid *g,
|
|---|
| 218 | hypre_BoxArray *boundarym, hypre_BoxArray *boundaryp,
|
|---|
| 219 | int d )
|
|---|
| 220 | {
|
|---|
| 221 | int ierr = 0;
|
|---|
| 222 | hypre_BoxNeighbors *neighbors = hypre_StructGridNeighbors(g);
|
|---|
| 223 | hypre_BoxArray *neighbor_boxes = hypre_BoxNeighborsBoxes( neighbors );
|
|---|
| 224 | int i;
|
|---|
| 225 | int thickness[6];
|
|---|
| 226 | for ( i=0; i<6; ++i ) thickness[i] = 1;
|
|---|
| 227 | /* neighbor_boxes are this processor's neighbors, not this box's
|
|---|
| 228 | neighbors. But it's likely to be cheaper to use them all in the
|
|---|
| 229 | next step than to try to shrink it to just this box's neighbors. */
|
|---|
| 230 | ierr += hypre_BoxBoundaryDNT( box, neighbor_boxes, boundarym, 2*d, thickness[2*d] );
|
|---|
| 231 | ierr += hypre_BoxBoundaryDNT( box, neighbor_boxes, boundaryp, 2*d+1, thickness[2*d] );
|
|---|
| 232 | return ierr;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|