| 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 | *
|
|---|
| 17 | *****************************************************************************/
|
|---|
| 18 |
|
|---|
| 19 | #include "headers.h"
|
|---|
| 20 |
|
|---|
| 21 | /*--------------------------------------------------------------------------
|
|---|
| 22 | *--------------------------------------------------------------------------*/
|
|---|
| 23 |
|
|---|
| 24 | int
|
|---|
| 25 | hypre_BoxMapEntrySetInfo( hypre_BoxMapEntry *entry,
|
|---|
| 26 | void *info )
|
|---|
| 27 | {
|
|---|
| 28 | int ierr = 0;
|
|---|
| 29 |
|
|---|
| 30 | hypre_BoxMapEntryInfo(entry) = info;
|
|---|
| 31 |
|
|---|
| 32 | return ierr;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | /*--------------------------------------------------------------------------
|
|---|
| 36 | *--------------------------------------------------------------------------*/
|
|---|
| 37 |
|
|---|
| 38 | int
|
|---|
| 39 | hypre_BoxMapEntryGetInfo( hypre_BoxMapEntry *entry,
|
|---|
| 40 | void **info_ptr )
|
|---|
| 41 | {
|
|---|
| 42 | int ierr = 0;
|
|---|
| 43 |
|
|---|
| 44 | *info_ptr = hypre_BoxMapEntryInfo(entry);
|
|---|
| 45 |
|
|---|
| 46 | return ierr;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | /*--------------------------------------------------------------------------
|
|---|
| 50 | *--------------------------------------------------------------------------*/
|
|---|
| 51 |
|
|---|
| 52 | int
|
|---|
| 53 | hypre_BoxMapEntryGetExtents( hypre_BoxMapEntry *entry,
|
|---|
| 54 | hypre_Index imin,
|
|---|
| 55 | hypre_Index imax )
|
|---|
| 56 | {
|
|---|
| 57 | int ierr = 0;
|
|---|
| 58 | hypre_IndexRef entry_imin = hypre_BoxMapEntryIMin(entry);
|
|---|
| 59 | hypre_IndexRef entry_imax = hypre_BoxMapEntryIMax(entry);
|
|---|
| 60 | int d;
|
|---|
| 61 |
|
|---|
| 62 | for (d = 0; d < 3; d++)
|
|---|
| 63 | {
|
|---|
| 64 | hypre_IndexD(imin, d) = hypre_IndexD(entry_imin, d);
|
|---|
| 65 | hypre_IndexD(imax, d) = hypre_IndexD(entry_imax, d);
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | return ierr;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | /*--------------------------------------------------------------------------
|
|---|
| 72 | *--------------------------------------------------------------------------*/
|
|---|
| 73 |
|
|---|
| 74 | int
|
|---|
| 75 | hypre_BoxMapCreate( int max_nentries,
|
|---|
| 76 | hypre_Index global_imin,
|
|---|
| 77 | hypre_Index global_imax,
|
|---|
| 78 | int nprocs,
|
|---|
| 79 | hypre_BoxMap **map_ptr )
|
|---|
| 80 | {
|
|---|
| 81 | int ierr = 0;
|
|---|
| 82 |
|
|---|
| 83 | hypre_BoxMap *map;
|
|---|
| 84 | hypre_IndexRef global_imin_ref;
|
|---|
| 85 | hypre_IndexRef global_imax_ref;
|
|---|
| 86 | int d,i;
|
|---|
| 87 |
|
|---|
| 88 | map = hypre_CTAlloc(hypre_BoxMap, 1);
|
|---|
| 89 | hypre_BoxMapMaxNEntries(map) = max_nentries;
|
|---|
| 90 | global_imin_ref = hypre_BoxMapGlobalIMin(map);
|
|---|
| 91 | global_imax_ref = hypre_BoxMapGlobalIMax(map);
|
|---|
| 92 | for (d = 0; d < 3; d++)
|
|---|
| 93 | {
|
|---|
| 94 | hypre_IndexD(global_imin_ref, d) = hypre_IndexD(global_imin, d);
|
|---|
| 95 | hypre_IndexD(global_imax_ref, d) = hypre_IndexD(global_imax, d);
|
|---|
| 96 | hypre_BoxMapIndexesD(map, d) = NULL;
|
|---|
| 97 | }
|
|---|
| 98 | hypre_BoxMapNEntries(map) = 0;
|
|---|
| 99 | hypre_BoxMapEntries(map) = hypre_CTAlloc(hypre_BoxMapEntry, max_nentries);
|
|---|
| 100 | hypre_BoxMapTable(map) = NULL;
|
|---|
| 101 | hypre_BoxMapBoxProcTable(map) = NULL;
|
|---|
| 102 | hypre_BoxMapBoxProcOffset(map)= hypre_CTAlloc(int, nprocs);
|
|---|
| 103 |
|
|---|
| 104 | /* GEC1002 we choose a default that will give zero everywhere..*/
|
|---|
| 105 |
|
|---|
| 106 | for (i = 0; i < 6; i++)
|
|---|
| 107 | {
|
|---|
| 108 | hypre_BoxMapNumGhost(map)[i] = 0;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | *map_ptr = map;
|
|---|
| 112 |
|
|---|
| 113 | return ierr;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | /*--------------------------------------------------------------------------
|
|---|
| 117 | *--------------------------------------------------------------------------*/
|
|---|
| 118 |
|
|---|
| 119 | int
|
|---|
| 120 | hypre_BoxMapIncSize( hypre_BoxMap *map,
|
|---|
| 121 | int inc_nentries )
|
|---|
| 122 | {
|
|---|
| 123 | int ierr = 0;
|
|---|
| 124 |
|
|---|
| 125 | int max_nentries = hypre_BoxMapMaxNEntries(map);
|
|---|
| 126 | hypre_BoxMapEntry *entries = hypre_BoxMapEntries(map);
|
|---|
| 127 |
|
|---|
| 128 | max_nentries += inc_nentries;
|
|---|
| 129 | entries = hypre_TReAlloc(entries, hypre_BoxMapEntry, max_nentries);
|
|---|
| 130 |
|
|---|
| 131 | hypre_BoxMapMaxNEntries(map) = max_nentries;
|
|---|
| 132 | hypre_BoxMapEntries(map) = entries;
|
|---|
| 133 |
|
|---|
| 134 | return ierr;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | /*--------------------------------------------------------------------------
|
|---|
| 138 | *--------------------------------------------------------------------------*/
|
|---|
| 139 |
|
|---|
| 140 | int
|
|---|
| 141 | hypre_BoxMapAddEntry( hypre_BoxMap *map,
|
|---|
| 142 | hypre_Index imin,
|
|---|
| 143 | hypre_Index imax,
|
|---|
| 144 | void *info )
|
|---|
| 145 | {
|
|---|
| 146 | int ierr = 0;
|
|---|
| 147 |
|
|---|
| 148 | int nentries = hypre_BoxMapNEntries(map);
|
|---|
| 149 | hypre_BoxMapEntry *entries = hypre_BoxMapEntries(map);
|
|---|
| 150 | hypre_BoxMapEntry *entry;
|
|---|
| 151 | hypre_IndexRef entry_imin;
|
|---|
| 152 | hypre_IndexRef entry_imax;
|
|---|
| 153 | int d;
|
|---|
| 154 | /* GEC0902 added num_ghost variable. extract location */
|
|---|
| 155 | int *num_ghost = hypre_BoxMapNumGhost(map);
|
|---|
| 156 |
|
|---|
| 157 | entry = &entries[nentries];
|
|---|
| 158 | entry_imin = hypre_BoxMapEntryIMin(entry);
|
|---|
| 159 | entry_imax = hypre_BoxMapEntryIMax(entry);
|
|---|
| 160 | for (d = 0; d < 3; d++)
|
|---|
| 161 | {
|
|---|
| 162 | hypre_IndexD(entry_imin, d) = hypre_IndexD(imin, d);
|
|---|
| 163 | hypre_IndexD(entry_imax, d) = hypre_IndexD(imax, d);
|
|---|
| 164 | }
|
|---|
| 165 | hypre_BoxMapEntryInfo(entry) = info;
|
|---|
| 166 | hypre_BoxMapNEntries(map) = nentries + 1;
|
|---|
| 167 |
|
|---|
| 168 | /* GEC0902 for ghost sizes: inherit and inject the numghost from map into mapentry*/
|
|---|
| 169 |
|
|---|
| 170 | for (d = 0; d < 6; d++)
|
|---|
| 171 | {
|
|---|
| 172 | hypre_BoxMapEntryNumGhost(entry)[d] = num_ghost[d];
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | hypre_BoxMapEntryNext(entry)= NULL;
|
|---|
| 176 |
|
|---|
| 177 | return ierr;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | /*--------------------------------------------------------------------------
|
|---|
| 181 | *--------------------------------------------------------------------------*/
|
|---|
| 182 |
|
|---|
| 183 | int
|
|---|
| 184 | hypre_BoxMapAssemble( hypre_BoxMap *map, MPI_Comm comm )
|
|---|
| 185 | {
|
|---|
| 186 | int ierr = 0;
|
|---|
| 187 |
|
|---|
| 188 | int nentries = hypre_BoxMapNEntries(map);
|
|---|
| 189 | hypre_BoxMapEntry *entries = hypre_BoxMapEntries(map);
|
|---|
| 190 |
|
|---|
| 191 | hypre_BoxMapEntry **table;
|
|---|
| 192 | int *indexes[3];
|
|---|
| 193 | int size[3];
|
|---|
| 194 |
|
|---|
| 195 | hypre_BoxMapEntry *entry;
|
|---|
| 196 | hypre_IndexRef entry_imin;
|
|---|
| 197 | hypre_IndexRef entry_imax;
|
|---|
| 198 |
|
|---|
| 199 | int imin[3];
|
|---|
| 200 | int imax[3];
|
|---|
| 201 | int iminmax[2];
|
|---|
| 202 | int index_not_there;
|
|---|
| 203 | int b, d, i, j, k, l;
|
|---|
| 204 |
|
|---|
| 205 | int myproc, proc;
|
|---|
| 206 | int *proc_entries, *nproc_entries, pcnt, npcnt;
|
|---|
| 207 |
|
|---|
| 208 | MPI_Comm_rank(comm, &myproc);
|
|---|
| 209 |
|
|---|
| 210 | /*------------------------------------------------------
|
|---|
| 211 | * BoxProcTable is a ptr to entries since they have been
|
|---|
| 212 | * in the desired order: proc followed by local box.
|
|---|
| 213 | *------------------------------------------------------*/
|
|---|
| 214 | hypre_BoxMapBoxProcTable(map)= entries;
|
|---|
| 215 |
|
|---|
| 216 | /*------------------------------------------------------
|
|---|
| 217 | * Set up the indexes array and record the processor's
|
|---|
| 218 | * entries. This will be used in ordering the link list
|
|---|
| 219 | * of BoxMapEntry- ones on this processor listed first.
|
|---|
| 220 | *------------------------------------------------------*/
|
|---|
| 221 | for (d = 0; d < 3; d++)
|
|---|
| 222 | {
|
|---|
| 223 | indexes[d] = hypre_CTAlloc(int, 2*nentries);
|
|---|
| 224 | size[d] = 0;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | proc_entries = hypre_CTAlloc(int, nentries);
|
|---|
| 228 | nproc_entries= hypre_CTAlloc(int, nentries);
|
|---|
| 229 | pcnt = 0;
|
|---|
| 230 | npcnt= 0;
|
|---|
| 231 | for (b = 0; b < nentries; b++)
|
|---|
| 232 | {
|
|---|
| 233 | entry = &entries[b];
|
|---|
| 234 | entry_imin = hypre_BoxMapEntryIMin(entry);
|
|---|
| 235 | entry_imax = hypre_BoxMapEntryIMax(entry);
|
|---|
| 236 |
|
|---|
| 237 | hypre_SStructMapEntryGetProcess(entry, &proc);
|
|---|
| 238 | if (proc != myproc)
|
|---|
| 239 | {
|
|---|
| 240 | nproc_entries[npcnt++]= b;
|
|---|
| 241 | }
|
|---|
| 242 | else
|
|---|
| 243 | {
|
|---|
| 244 | proc_entries[pcnt++]= b;
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | for (d = 0; d < 3; d++)
|
|---|
| 248 | {
|
|---|
| 249 | iminmax[0] = hypre_IndexD(entry_imin, d);
|
|---|
| 250 | iminmax[1] = hypre_IndexD(entry_imax, d) + 1;
|
|---|
| 251 |
|
|---|
| 252 | for (i = 0; i < 2; i++)
|
|---|
| 253 | {
|
|---|
| 254 | /* find the new index position in the indexes array */
|
|---|
| 255 | index_not_there = 1;
|
|---|
| 256 | for (j = 0; j < size[d]; j++)
|
|---|
| 257 | {
|
|---|
| 258 | if (iminmax[i] <= indexes[d][j])
|
|---|
| 259 | {
|
|---|
| 260 | if (iminmax[i] == indexes[d][j])
|
|---|
| 261 | {
|
|---|
| 262 | index_not_there = 0;
|
|---|
| 263 | }
|
|---|
| 264 | break;
|
|---|
| 265 | }
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | /* if the index is already there, don't add it again */
|
|---|
| 269 | if (index_not_there)
|
|---|
| 270 | {
|
|---|
| 271 | for (k = size[d]; k > j; k--)
|
|---|
| 272 | {
|
|---|
| 273 | indexes[d][k] = indexes[d][k-1];
|
|---|
| 274 | }
|
|---|
| 275 | indexes[d][j] = iminmax[i];
|
|---|
| 276 | size[d]++;
|
|---|
| 277 | }
|
|---|
| 278 | }
|
|---|
| 279 | }
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | for (d = 0; d < 3; d++)
|
|---|
| 283 | {
|
|---|
| 284 | size[d]--;
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | /*------------------------------------------------------
|
|---|
| 288 | * Set up the table.
|
|---|
| 289 | *------------------------------------------------------*/
|
|---|
| 290 |
|
|---|
| 291 | table = hypre_CTAlloc(hypre_BoxMapEntry *, (size[0] * size[1] * size[2]));
|
|---|
| 292 |
|
|---|
| 293 | for (l= 0; l< npcnt; l++)
|
|---|
| 294 | {
|
|---|
| 295 | b= nproc_entries[l];
|
|---|
| 296 | entry = &entries[b];
|
|---|
| 297 | entry_imin = hypre_BoxMapEntryIMin(entry);
|
|---|
| 298 | entry_imax = hypre_BoxMapEntryIMax(entry);
|
|---|
| 299 |
|
|---|
| 300 | /* find the indexes corresponding to the current box */
|
|---|
| 301 | for (d = 0; d < 3; d++)
|
|---|
| 302 | {
|
|---|
| 303 | j = 0;
|
|---|
| 304 |
|
|---|
| 305 | while (hypre_IndexD(entry_imin, d) != indexes[d][j])
|
|---|
| 306 | {
|
|---|
| 307 | j++;
|
|---|
| 308 | }
|
|---|
| 309 | hypre_IndexD(imin, d) = j;
|
|---|
| 310 |
|
|---|
| 311 | while (hypre_IndexD(entry_imax, d) + 1 != indexes[d][j])
|
|---|
| 312 | {
|
|---|
| 313 | j++;
|
|---|
| 314 | }
|
|---|
| 315 | hypre_IndexD(imax, d) = j;
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | /* set up map table */
|
|---|
| 319 | for (k = imin[2]; k < imax[2]; k++)
|
|---|
| 320 | {
|
|---|
| 321 | for (j = imin[1]; j < imax[1]; j++)
|
|---|
| 322 | {
|
|---|
| 323 | for (i = imin[0]; i < imax[0]; i++)
|
|---|
| 324 | {
|
|---|
| 325 | if (!(table[((k) * size[1] + j) * size[0] + i]))
|
|---|
| 326 | {
|
|---|
| 327 | table[((k) * size[1] + j) * size[0] + i] = entry;
|
|---|
| 328 | }
|
|---|
| 329 | else /* link list for BoxMapEntry- overlapping */
|
|---|
| 330 | {
|
|---|
| 331 | hypre_BoxMapEntryNext(entry)= table[((k) * size[1] + j) * size[0] + i];
|
|---|
| 332 | table[((k) * size[1] + j) * size[0] + i]= entry;
|
|---|
| 333 | }
|
|---|
| 334 | }
|
|---|
| 335 | }
|
|---|
| 336 | }
|
|---|
| 337 | }
|
|---|
| 338 |
|
|---|
| 339 | for (l= 0; l< pcnt; l++)
|
|---|
| 340 | {
|
|---|
| 341 | b= proc_entries[l];
|
|---|
| 342 | entry = &entries[b];
|
|---|
| 343 | entry_imin = hypre_BoxMapEntryIMin(entry);
|
|---|
| 344 | entry_imax = hypre_BoxMapEntryIMax(entry);
|
|---|
| 345 |
|
|---|
| 346 | /* find the indexes corresponding to the current box */
|
|---|
| 347 | for (d = 0; d < 3; d++)
|
|---|
| 348 | {
|
|---|
| 349 | j = 0;
|
|---|
| 350 |
|
|---|
| 351 | while (hypre_IndexD(entry_imin, d) != indexes[d][j])
|
|---|
| 352 | {
|
|---|
| 353 | j++;
|
|---|
| 354 | }
|
|---|
| 355 | hypre_IndexD(imin, d) = j;
|
|---|
| 356 |
|
|---|
| 357 | while (hypre_IndexD(entry_imax, d) + 1 != indexes[d][j])
|
|---|
| 358 | {
|
|---|
| 359 | j++;
|
|---|
| 360 | }
|
|---|
| 361 | hypre_IndexD(imax, d) = j;
|
|---|
| 362 | }
|
|---|
| 363 |
|
|---|
| 364 | /* set up map table */
|
|---|
| 365 | for (k = imin[2]; k < imax[2]; k++)
|
|---|
| 366 | {
|
|---|
| 367 | for (j = imin[1]; j < imax[1]; j++)
|
|---|
| 368 | {
|
|---|
| 369 | for (i = imin[0]; i < imax[0]; i++)
|
|---|
| 370 | {
|
|---|
| 371 | if (!(table[((k) * size[1] + j) * size[0] + i]))
|
|---|
| 372 | {
|
|---|
| 373 | table[((k) * size[1] + j) * size[0] + i] = entry;
|
|---|
| 374 | }
|
|---|
| 375 | else /* link list for BoxMapEntry- overlapping */
|
|---|
| 376 | {
|
|---|
| 377 | hypre_BoxMapEntryNext(entry)= table[((k) * size[1] + j) * size[0] + i];
|
|---|
| 378 | table[((k) * size[1] + j) * size[0] + i]= entry;
|
|---|
| 379 | }
|
|---|
| 380 | }
|
|---|
| 381 | }
|
|---|
| 382 | }
|
|---|
| 383 | }
|
|---|
| 384 | hypre_TFree(proc_entries);
|
|---|
| 385 | hypre_TFree(nproc_entries);
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 | /*------------------------------------------------------
|
|---|
| 389 | * Set up the map
|
|---|
| 390 | *------------------------------------------------------*/
|
|---|
| 391 |
|
|---|
| 392 | hypre_TFree(hypre_BoxMapTable(map));
|
|---|
| 393 | hypre_BoxMapTable(map) = table;
|
|---|
| 394 | for (d = 0; d < 3; d++)
|
|---|
| 395 | {
|
|---|
| 396 | hypre_TFree(hypre_BoxMapIndexesD(map, d));
|
|---|
| 397 | hypre_BoxMapIndexesD(map, d) = indexes[d];
|
|---|
| 398 | hypre_BoxMapSizeD(map, d) = size[d];
|
|---|
| 399 | hypre_BoxMapLastIndexD(map, d) = 0;
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | return ierr;
|
|---|
| 403 | }
|
|---|
| 404 |
|
|---|
| 405 | /*--------------------------------------------------------------------------
|
|---|
| 406 | * hypre_BoxMapDestroy
|
|---|
| 407 | *--------------------------------------------------------------------------*/
|
|---|
| 408 |
|
|---|
| 409 | int
|
|---|
| 410 | hypre_BoxMapDestroy( hypre_BoxMap *map )
|
|---|
| 411 | {
|
|---|
| 412 | int ierr = 0;
|
|---|
| 413 | int d;
|
|---|
| 414 |
|
|---|
| 415 | if (map)
|
|---|
| 416 | {
|
|---|
| 417 | hypre_TFree(hypre_BoxMapEntries(map));
|
|---|
| 418 | hypre_TFree(hypre_BoxMapTable(map));
|
|---|
| 419 | hypre_TFree(hypre_BoxMapBoxProcOffset(map));
|
|---|
| 420 |
|
|---|
| 421 | for (d = 0; d < 3; d++)
|
|---|
| 422 | {
|
|---|
| 423 | hypre_TFree(hypre_BoxMapIndexesD(map, d));
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | hypre_TFree(map);
|
|---|
| 427 | }
|
|---|
| 428 |
|
|---|
| 429 | return ierr;
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | /*--------------------------------------------------------------------------
|
|---|
| 433 | * This routine return a NULL 'entry_ptr' if an entry is not found
|
|---|
| 434 | *--------------------------------------------------------------------------*/
|
|---|
| 435 |
|
|---|
| 436 | int
|
|---|
| 437 | hypre_BoxMapFindEntry( hypre_BoxMap *map,
|
|---|
| 438 | hypre_Index index,
|
|---|
| 439 | hypre_BoxMapEntry **entry_ptr )
|
|---|
| 440 | {
|
|---|
| 441 | int ierr = 0;
|
|---|
| 442 |
|
|---|
| 443 | int index_d;
|
|---|
| 444 | int map_index[3] = {0, 0, 0};
|
|---|
| 445 | int *map_indexes_d;
|
|---|
| 446 | int map_index_d;
|
|---|
| 447 | int map_size_d;
|
|---|
| 448 | int d;
|
|---|
| 449 |
|
|---|
| 450 | for (d = 0; d < 3; d++)
|
|---|
| 451 | {
|
|---|
| 452 | map_indexes_d = hypre_BoxMapIndexesD(map, d);
|
|---|
| 453 | map_size_d = hypre_BoxMapSizeD(map, d);
|
|---|
| 454 |
|
|---|
| 455 | /* Find location of index[d] in map */
|
|---|
| 456 | index_d = hypre_IndexD(index, d);
|
|---|
| 457 |
|
|---|
| 458 | /* Start looking in place indicated by last_index stored in map */
|
|---|
| 459 | map_index_d = hypre_BoxMapLastIndexD(map, d);
|
|---|
| 460 |
|
|---|
| 461 | /* Loop downward if target index is less than current location */
|
|---|
| 462 | while ( (map_index_d >= 0 ) &&
|
|---|
| 463 | (index_d < map_indexes_d[map_index_d]) )
|
|---|
| 464 | {
|
|---|
| 465 | map_index_d --;
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | /* Loop upward if target index is greater than current location */
|
|---|
| 469 | while ( (map_index_d <= (map_size_d-1)) &&
|
|---|
| 470 | (index_d >= map_indexes_d[map_index_d+1]) )
|
|---|
| 471 | {
|
|---|
| 472 | map_index_d ++;
|
|---|
| 473 | }
|
|---|
| 474 |
|
|---|
| 475 | if( ( map_index_d < 0 ) || ( map_index_d > (map_size_d-1) ) )
|
|---|
| 476 | {
|
|---|
| 477 | *entry_ptr = NULL;
|
|---|
| 478 | return ierr;
|
|---|
| 479 | }
|
|---|
| 480 | else
|
|---|
| 481 | {
|
|---|
| 482 | map_index[d] = map_index_d;
|
|---|
| 483 | }
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | /* If code reaches this point, then the entry was successfully found */
|
|---|
| 487 | *entry_ptr = hypre_BoxMapTableEntry(map,
|
|---|
| 488 | map_index[0],
|
|---|
| 489 | map_index[1],
|
|---|
| 490 | map_index[2]);
|
|---|
| 491 |
|
|---|
| 492 | /* Reset the last index in the map */
|
|---|
| 493 | for (d = 0; d < 3; d++)
|
|---|
| 494 | {
|
|---|
| 495 | hypre_BoxMapLastIndexD(map, d) = map_index[d];
|
|---|
| 496 | }
|
|---|
| 497 |
|
|---|
| 498 | return ierr;
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| 501 | int
|
|---|
| 502 | hypre_BoxMapFindBoxProcEntry( hypre_BoxMap *map,
|
|---|
| 503 | int box,
|
|---|
| 504 | int proc,
|
|---|
| 505 | hypre_BoxMapEntry **entry_ptr )
|
|---|
| 506 | {
|
|---|
| 507 | int ierr = 0;
|
|---|
| 508 |
|
|---|
| 509 | *entry_ptr= &hypre_BoxMapBoxProcTableEntry(map, box, proc);
|
|---|
| 510 |
|
|---|
| 511 | return ierr;
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 | /*--------------------------------------------------------------------------
|
|---|
| 515 | * This routine returns NULL for 'entries' if none are found
|
|---|
| 516 | * Although the entries_ptr can be a link list of BoxMapEntries, the linked
|
|---|
| 517 | * BoxMapEntries will be included in another entry in entries_ptr.
|
|---|
| 518 | *--------------------------------------------------------------------------*/
|
|---|
| 519 |
|
|---|
| 520 | int
|
|---|
| 521 | hypre_BoxMapIntersect( hypre_BoxMap *map,
|
|---|
| 522 | hypre_Index ilower,
|
|---|
| 523 | hypre_Index iupper,
|
|---|
| 524 | hypre_BoxMapEntry ***entries_ptr,
|
|---|
| 525 | int *nentries_ptr )
|
|---|
| 526 | {
|
|---|
| 527 | int ierr = 0;
|
|---|
| 528 |
|
|---|
| 529 | hypre_BoxMapEntry **entries, **all_entries;
|
|---|
| 530 | hypre_BoxMapEntry *entry;
|
|---|
| 531 | int nentries;
|
|---|
| 532 |
|
|---|
| 533 | int index_d;
|
|---|
| 534 | int map_ilower[3] = {0, 0, 0};
|
|---|
| 535 | int map_iupper[3] = {0, 0, 0};
|
|---|
| 536 | int *map_indexes_d;
|
|---|
| 537 | int map_index_d;
|
|---|
| 538 | int map_size_d;
|
|---|
| 539 | int d, i, j, k;
|
|---|
| 540 |
|
|---|
| 541 | hypre_SStructMapInfo *info;
|
|---|
| 542 | int *ii, *jj, *kk;
|
|---|
| 543 | int cnt;
|
|---|
| 544 | HYPRE_BigInt *offsets;
|
|---|
| 545 | int *unsort;
|
|---|
| 546 |
|
|---|
| 547 | for (d = 0; d < 3; d++)
|
|---|
| 548 | {
|
|---|
| 549 | map_indexes_d = hypre_BoxMapIndexesD(map, d);
|
|---|
| 550 | map_size_d = hypre_BoxMapSizeD(map, d);
|
|---|
| 551 |
|
|---|
| 552 | /*------------------------------------------
|
|---|
| 553 | * Find location of ilower[d] in map
|
|---|
| 554 | *------------------------------------------*/
|
|---|
| 555 |
|
|---|
| 556 | index_d = hypre_IndexD(ilower, d);
|
|---|
| 557 |
|
|---|
| 558 | /* Start looking in place indicated by last_index stored in map */
|
|---|
| 559 | map_index_d = hypre_BoxMapLastIndexD(map, d);
|
|---|
| 560 |
|
|---|
| 561 | /* Loop downward if target index is less than current location */
|
|---|
| 562 | while ( (map_index_d >= 0 ) &&
|
|---|
| 563 | (index_d < map_indexes_d[map_index_d]) )
|
|---|
| 564 | {
|
|---|
| 565 | map_index_d --;
|
|---|
| 566 | }
|
|---|
| 567 |
|
|---|
| 568 | /* Loop upward if target index is greater than current location */
|
|---|
| 569 | while ( (map_index_d <= (map_size_d-1)) &&
|
|---|
| 570 | (index_d >= map_indexes_d[map_index_d+1]) )
|
|---|
| 571 | {
|
|---|
| 572 | map_index_d ++;
|
|---|
| 573 | }
|
|---|
| 574 |
|
|---|
| 575 | if( map_index_d > (map_size_d-1) )
|
|---|
| 576 | {
|
|---|
| 577 | *entries_ptr = NULL;
|
|---|
| 578 | *nentries_ptr = 0;
|
|---|
| 579 | return ierr;
|
|---|
| 580 | }
|
|---|
| 581 | else
|
|---|
| 582 | {
|
|---|
| 583 | map_ilower[d] = hypre_max(map_index_d, 0);
|
|---|
| 584 | }
|
|---|
| 585 |
|
|---|
| 586 | /*------------------------------------------
|
|---|
| 587 | * Find location of iupper[d] in map
|
|---|
| 588 | *------------------------------------------*/
|
|---|
| 589 |
|
|---|
| 590 | index_d = hypre_IndexD(iupper, d);
|
|---|
| 591 |
|
|---|
| 592 | /* Loop upward if target index is greater than current location */
|
|---|
| 593 | while ( (map_index_d <= (map_size_d-1)) &&
|
|---|
| 594 | (index_d >= map_indexes_d[map_index_d+1]) )
|
|---|
| 595 | {
|
|---|
| 596 | map_index_d ++;
|
|---|
| 597 | }
|
|---|
| 598 |
|
|---|
| 599 | if( map_index_d < 0 )
|
|---|
| 600 | {
|
|---|
| 601 | *entries_ptr = NULL;
|
|---|
| 602 | *nentries_ptr = 0;
|
|---|
| 603 | return ierr;
|
|---|
| 604 | }
|
|---|
| 605 | else
|
|---|
| 606 | {
|
|---|
| 607 | map_iupper[d] = hypre_min(map_index_d, (map_size_d-1)) + 1;
|
|---|
| 608 | }
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | /*-----------------------------------------------------------------
|
|---|
| 612 | * If code reaches this point, then set up the entries array and
|
|---|
| 613 | * eliminate duplicates. To eliminate duplicates, we need to
|
|---|
| 614 | * compare the BoxMapEntry link lists. We accomplish this using
|
|---|
| 615 | * the unique offsets (qsort and eliminate duplicate offsets).
|
|---|
| 616 | *-----------------------------------------------------------------*/
|
|---|
| 617 |
|
|---|
| 618 | nentries = ((map_iupper[0] - map_ilower[0]) *
|
|---|
| 619 | (map_iupper[1] - map_ilower[1]) *
|
|---|
| 620 | (map_iupper[2] - map_ilower[2]));
|
|---|
| 621 |
|
|---|
| 622 | ii= hypre_CTAlloc(int, nentries);
|
|---|
| 623 | jj= hypre_CTAlloc(int, nentries);
|
|---|
| 624 | kk= hypre_CTAlloc(int, nentries);
|
|---|
| 625 |
|
|---|
| 626 | nentries = 0;
|
|---|
| 627 | cnt= 0;
|
|---|
| 628 | for (k = map_ilower[2]; k < map_iupper[2]; k++)
|
|---|
| 629 | {
|
|---|
| 630 | for (j = map_ilower[1]; j < map_iupper[1]; j++)
|
|---|
| 631 | {
|
|---|
| 632 | for (i = map_ilower[0]; i < map_iupper[0]; i++)
|
|---|
| 633 | {
|
|---|
| 634 | /* the next 3 `if' statements eliminate duplicates */
|
|---|
| 635 | if (k > map_ilower[2])
|
|---|
| 636 | {
|
|---|
| 637 | if ( hypre_BoxMapTableEntry(map, i, j, k) ==
|
|---|
| 638 | hypre_BoxMapTableEntry(map, i, j, (k-1)) )
|
|---|
| 639 | {
|
|---|
| 640 | continue;
|
|---|
| 641 | }
|
|---|
| 642 | }
|
|---|
| 643 | if (j > map_ilower[1])
|
|---|
| 644 | {
|
|---|
| 645 | if ( hypre_BoxMapTableEntry(map, i, j, k) ==
|
|---|
| 646 | hypre_BoxMapTableEntry(map, i, (j-1), k) )
|
|---|
| 647 | {
|
|---|
| 648 | continue;
|
|---|
| 649 | }
|
|---|
| 650 | }
|
|---|
| 651 | if (i > map_ilower[0])
|
|---|
| 652 | {
|
|---|
| 653 | if ( hypre_BoxMapTableEntry(map, i, j, k) ==
|
|---|
| 654 | hypre_BoxMapTableEntry(map, (i-1), j, k) )
|
|---|
| 655 | {
|
|---|
| 656 | continue;
|
|---|
| 657 | }
|
|---|
| 658 | }
|
|---|
| 659 |
|
|---|
| 660 | entry= hypre_BoxMapTableEntry(map, i, j, k);
|
|---|
| 661 | /* Record the indices for non-empty entries and count all MapEntries. */
|
|---|
| 662 | if (entry != NULL)
|
|---|
| 663 | {
|
|---|
| 664 | ii[nentries]= i;
|
|---|
| 665 | jj[nentries]= j;
|
|---|
| 666 | kk[nentries++]= k;
|
|---|
| 667 |
|
|---|
| 668 | while (entry)
|
|---|
| 669 | {
|
|---|
| 670 | cnt++;
|
|---|
| 671 | entry= hypre_BoxMapEntryNext(entry);
|
|---|
| 672 | }
|
|---|
| 673 | }
|
|---|
| 674 |
|
|---|
| 675 | }
|
|---|
| 676 | }
|
|---|
| 677 | }
|
|---|
| 678 |
|
|---|
| 679 | /* no link lists of BoxMapEntries. Just point to the unique BoxMapEntries */
|
|---|
| 680 | if (nentries == cnt)
|
|---|
| 681 | {
|
|---|
| 682 | entries= hypre_CTAlloc(hypre_BoxMapEntry *, nentries);
|
|---|
| 683 | for (i= 0; i< nentries; i++)
|
|---|
| 684 | {
|
|---|
| 685 | entries[i]= hypre_BoxMapTableEntry(map, ii[i], jj[i], kk[i]);
|
|---|
| 686 | }
|
|---|
| 687 | }
|
|---|
| 688 |
|
|---|
| 689 | /* link lists of BoxMapEntries. Sorting needed to eliminate duplicates. */
|
|---|
| 690 | else
|
|---|
| 691 | {
|
|---|
| 692 | unsort = hypre_CTAlloc(int, cnt);
|
|---|
| 693 | offsets = hypre_CTAlloc(HYPRE_BigInt, cnt);
|
|---|
| 694 | all_entries= hypre_CTAlloc(hypre_BoxMapEntry *, cnt);
|
|---|
| 695 |
|
|---|
| 696 | cnt= 0;
|
|---|
| 697 | for (i= 0; i< nentries; i++)
|
|---|
| 698 | {
|
|---|
| 699 | entry= hypre_BoxMapTableEntry(map, ii[i], jj[i], kk[i]);
|
|---|
| 700 |
|
|---|
| 701 | while (entry)
|
|---|
| 702 | {
|
|---|
| 703 | all_entries[cnt]= entry;
|
|---|
| 704 | unsort[cnt] = cnt;
|
|---|
| 705 | /* RDF: This sstruct-specific info stuff should not be here! */
|
|---|
| 706 | info = (hypre_SStructMapInfo *) hypre_BoxMapEntryInfo(entry);
|
|---|
| 707 | offsets[cnt++] = hypre_SStructMapInfoOffset(info);
|
|---|
| 708 |
|
|---|
| 709 | entry= hypre_BoxMapEntryNext(entry);
|
|---|
| 710 | }
|
|---|
| 711 | }
|
|---|
| 712 |
|
|---|
| 713 | hypre_BigQsortbi(offsets, unsort, 0, cnt-1);
|
|---|
| 714 |
|
|---|
| 715 | /* count the unique MapEntries */
|
|---|
| 716 | nentries= 1;
|
|---|
| 717 | for (i= 1; i< cnt; i++)
|
|---|
| 718 | {
|
|---|
| 719 | if (offsets[i] != offsets[i-1])
|
|---|
| 720 | {
|
|---|
| 721 | nentries++;
|
|---|
| 722 | }
|
|---|
| 723 | }
|
|---|
| 724 |
|
|---|
| 725 | entries= hypre_CTAlloc(hypre_BoxMapEntry *, nentries);
|
|---|
| 726 |
|
|---|
| 727 | /* extract the unique MapEntries */
|
|---|
| 728 | entries[0]= all_entries[unsort[0]];
|
|---|
| 729 | nentries= 1;
|
|---|
| 730 | for (i= 1; i< cnt; i++)
|
|---|
| 731 | {
|
|---|
| 732 | if (offsets[i] != offsets[i-1])
|
|---|
| 733 | {
|
|---|
| 734 | entries[nentries++]= all_entries[unsort[i]];
|
|---|
| 735 | }
|
|---|
| 736 | }
|
|---|
| 737 |
|
|---|
| 738 | hypre_TFree(unsort);
|
|---|
| 739 | hypre_TFree(offsets);
|
|---|
| 740 | hypre_TFree(all_entries);
|
|---|
| 741 | }
|
|---|
| 742 |
|
|---|
| 743 | hypre_TFree(ii);
|
|---|
| 744 | hypre_TFree(jj);
|
|---|
| 745 | hypre_TFree(kk);
|
|---|
| 746 |
|
|---|
| 747 | /* Reset the last index in the map */
|
|---|
| 748 | for (d = 0; d < 3; d++)
|
|---|
| 749 | {
|
|---|
| 750 | hypre_BoxMapLastIndexD(map, d) = map_ilower[d];
|
|---|
| 751 | }
|
|---|
| 752 |
|
|---|
| 753 | *entries_ptr = entries;
|
|---|
| 754 | *nentries_ptr = nentries;
|
|---|
| 755 |
|
|---|
| 756 | return ierr;
|
|---|
| 757 | }
|
|---|
| 758 |
|
|---|
| 759 |
|
|---|
| 760 | /*------------------------------------------------------------------------------
|
|---|
| 761 | *GEC0902 hypre_BoxMapSetNumGhost
|
|---|
| 762 | *
|
|---|
| 763 | * the purpose is to set num ghost in the boxmap. It is identical
|
|---|
| 764 | * to the function that is used in the structure vector entity. Take
|
|---|
| 765 | * the entity map and use the macro to inject the num_ghost
|
|---|
| 766 | *-----------------------------------------------------------------------------*/
|
|---|
| 767 |
|
|---|
| 768 | int
|
|---|
| 769 | hypre_BoxMapSetNumGhost( hypre_BoxMap *map, int *num_ghost )
|
|---|
| 770 | {
|
|---|
| 771 | int ierr = 0;
|
|---|
| 772 | int i;
|
|---|
| 773 |
|
|---|
| 774 | for (i = 0; i < 6; i++)
|
|---|
| 775 | {
|
|---|
| 776 | hypre_BoxMapNumGhost(map)[i] = num_ghost[i];
|
|---|
| 777 | }
|
|---|
| 778 | return ierr;
|
|---|
| 779 | }
|
|---|