source: CIVL/examples/mpi-omp/AMG2013/sstruct_mv/sstruct_grid.c@ 7d77e64

main test-branch
Last change on this file since 7d77e64 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 43.9 KB
Line 
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 * Member functions for hypre_SStructGrid class.
18 *
19 *****************************************************************************/
20
21#include "headers.h"
22
23/*==========================================================================
24 * SStructVariable routines
25 *==========================================================================*/
26
27/*--------------------------------------------------------------------------
28 * hypre_SStructVariableGetOffset
29 *--------------------------------------------------------------------------*/
30
31int
32hypre_SStructVariableGetOffset( HYPRE_SStructVariable vartype,
33 int ndim,
34 hypre_Index varoffset )
35{
36 int ierr = 0;
37 int d;
38
39 switch(vartype)
40 {
41 case HYPRE_SSTRUCT_VARIABLE_CELL:
42 hypre_SetIndex(varoffset, 0, 0, 0);
43 break;
44 case HYPRE_SSTRUCT_VARIABLE_NODE:
45 hypre_SetIndex(varoffset, 1, 1, 1);
46 break;
47 case HYPRE_SSTRUCT_VARIABLE_XFACE:
48 hypre_SetIndex(varoffset, 1, 0, 0);
49 break;
50 case HYPRE_SSTRUCT_VARIABLE_YFACE:
51 hypre_SetIndex(varoffset, 0, 1, 0);
52 break;
53 case HYPRE_SSTRUCT_VARIABLE_ZFACE:
54 hypre_SetIndex(varoffset, 0, 0, 1);
55 break;
56 case HYPRE_SSTRUCT_VARIABLE_XEDGE:
57 hypre_SetIndex(varoffset, 0, 1, 1);
58 break;
59 case HYPRE_SSTRUCT_VARIABLE_YEDGE:
60 hypre_SetIndex(varoffset, 1, 0, 1);
61 break;
62 case HYPRE_SSTRUCT_VARIABLE_ZEDGE:
63 hypre_SetIndex(varoffset, 1, 1, 0);
64 break;
65 case HYPRE_SSTRUCT_VARIABLE_UNDEFINED:
66 break;
67 }
68 for (d = ndim; d < 3; d++)
69 {
70 hypre_IndexD(varoffset, d) = 0;
71 }
72
73 return ierr;
74}
75
76/*==========================================================================
77 * SStructPGrid routines
78 *==========================================================================*/
79
80/*--------------------------------------------------------------------------
81 * hypre_SStructPGridCreate
82 *--------------------------------------------------------------------------*/
83
84int
85hypre_SStructPGridCreate( MPI_Comm comm,
86 int ndim,
87 hypre_SStructPGrid **pgrid_ptr )
88{
89 int ierr = 0;
90
91 hypre_SStructPGrid *pgrid;
92 hypre_StructGrid *sgrid;
93 int t;
94
95 pgrid = hypre_TAlloc(hypre_SStructPGrid, 1);
96
97 hypre_SStructPGridComm(pgrid) = comm;
98 hypre_SStructPGridNDim(pgrid) = ndim;
99 hypre_SStructPGridNVars(pgrid) = 0;
100 hypre_SStructPGridCellSGridDone(pgrid) = 0;
101 hypre_SStructPGridVarTypes(pgrid) = NULL;
102
103 for (t = 0; t < 8; t++)
104 {
105 hypre_SStructPGridVTSGrid(pgrid, t) = NULL;
106 hypre_SStructPGridVTIBoxArray(pgrid, t) = NULL;
107 }
108 HYPRE_StructGridCreate(comm, ndim, &sgrid);
109 hypre_SStructPGridCellSGrid(pgrid) = sgrid;
110
111 hypre_SStructPGridPNeighbors(pgrid) = hypre_BoxArrayCreate(0);
112
113 hypre_SStructPGridLocalSize(pgrid) = 0;
114 hypre_SStructPGridGlobalSize(pgrid) = 0;
115
116 /* GEC0902 ghost addition to the grid */
117 hypre_SStructPGridGhlocalSize(pgrid) = 0;
118
119 hypre_ClearIndex(hypre_SStructPGridPeriodic(pgrid));
120
121 *pgrid_ptr = pgrid;
122
123 return ierr;
124}
125
126/*--------------------------------------------------------------------------
127 * hypre_SStructPGridDestroy
128 *--------------------------------------------------------------------------*/
129
130int
131hypre_SStructPGridDestroy( hypre_SStructPGrid *pgrid )
132{
133 int ierr = 0;
134
135 hypre_StructGrid **sgrids;
136 hypre_BoxArray **iboxarrays;
137 int t;
138
139 if (pgrid)
140 {
141 sgrids = hypre_SStructPGridSGrids(pgrid);
142 iboxarrays = hypre_SStructPGridIBoxArrays(pgrid);
143 hypre_TFree(hypre_SStructPGridVarTypes(pgrid));
144 for (t = 0; t < 8; t++)
145 {
146 HYPRE_StructGridDestroy(sgrids[t]);
147 hypre_BoxArrayDestroy(iboxarrays[t]);
148 }
149 hypre_BoxArrayDestroy(hypre_SStructPGridPNeighbors(pgrid));
150 hypre_TFree(pgrid);
151 }
152
153 return ierr;
154}
155
156/*--------------------------------------------------------------------------
157 * hypre_SStructPGridSetExtents
158 *--------------------------------------------------------------------------*/
159
160int
161hypre_SStructPGridSetExtents( hypre_SStructPGrid *pgrid,
162 hypre_Index ilower,
163 hypre_Index iupper )
164{
165 hypre_StructGrid *sgrid = hypre_SStructPGridCellSGrid(pgrid);
166
167 return ( HYPRE_StructGridSetExtents(sgrid, ilower, iupper) );
168}
169
170/*--------------------------------------------------------------------------
171 * hypre_SStructPGridSetCellSGrid
172 *--------------------------------------------------------------------------*/
173
174int
175hypre_SStructPGridSetCellSGrid( hypre_SStructPGrid *pgrid,
176 hypre_StructGrid *cell_sgrid )
177{
178 int ierr = 0;
179
180 hypre_SStructPGridCellSGrid(pgrid) = cell_sgrid;
181 hypre_SStructPGridCellSGridDone(pgrid) = 1;
182
183 return ierr;
184}
185
186/*--------------------------------------------------------------------------
187 * hypre_SStructPGridSetVariables
188 *--------------------------------------------------------------------------*/
189
190int hypre_SStructPGridSetVariables( hypre_SStructPGrid *pgrid,
191 int nvars,
192 HYPRE_SStructVariable *vartypes )
193{
194 int ierr = 0;
195
196 hypre_SStructVariable *new_vartypes;
197 int i;
198
199 hypre_TFree(hypre_SStructPGridVarTypes(pgrid));
200
201 new_vartypes = hypre_TAlloc(hypre_SStructVariable, nvars);
202 for (i = 0; i < nvars; i++)
203 {
204 new_vartypes[i] = vartypes[i];
205 }
206
207 hypre_SStructPGridNVars(pgrid) = nvars;
208 hypre_SStructPGridVarTypes(pgrid) = new_vartypes;
209
210 return ierr;
211}
212
213/*--------------------------------------------------------------------------
214 * hypre_SStructPGridSetVariable
215 * Like hypre_SStructPGridSetVariables, but do one variable at a time.
216 * Nevertheless, you still must provide nvars, for memory allocation.
217 *--------------------------------------------------------------------------*/
218
219int hypre_SStructPGridSetVariable( hypre_SStructPGrid *pgrid,
220 int var,
221 int nvars,
222 HYPRE_SStructVariable vartype )
223{
224 int ierr = 0;
225
226 hypre_SStructVariable *vartypes;
227
228 if ( hypre_SStructPGridVarTypes(pgrid) == NULL )
229 {
230 vartypes = hypre_TAlloc(hypre_SStructVariable, nvars);
231 hypre_SStructPGridNVars(pgrid) = nvars;
232 hypre_SStructPGridVarTypes(pgrid) = vartypes;
233 }
234 else
235 {
236 vartypes = hypre_SStructPGridVarTypes(pgrid);
237 }
238
239 vartypes[var] = vartype;
240
241 return ierr;
242}
243
244/*--------------------------------------------------------------------------
245 * hypre_SStructPGridSetPNeighbor
246 *--------------------------------------------------------------------------*/
247
248int
249hypre_SStructPGridSetPNeighbor( hypre_SStructPGrid *pgrid,
250 hypre_Box *pneighbor_box )
251{
252 int ierr = 0;
253
254 hypre_AppendBox(pneighbor_box, hypre_SStructPGridPNeighbors(pgrid));
255
256 return ierr;
257}
258
259/*--------------------------------------------------------------------------
260 * hypre_SStructPGridAssemble
261 *--------------------------------------------------------------------------*/
262
263int
264hypre_SStructPGridAssemble( hypre_SStructPGrid *pgrid )
265{
266 int ierr = 0;
267
268 MPI_Comm comm = hypre_SStructPGridComm(pgrid);
269 int ndim = hypre_SStructPGridNDim(pgrid);
270 int nvars = hypre_SStructPGridNVars(pgrid);
271 HYPRE_SStructVariable *vartypes = hypre_SStructPGridVarTypes(pgrid);
272 hypre_StructGrid **sgrids = hypre_SStructPGridSGrids(pgrid);
273 hypre_BoxArray **iboxarrays = hypre_SStructPGridIBoxArrays(pgrid);
274 hypre_BoxArray *pneighbors = hypre_SStructPGridPNeighbors(pgrid);
275 hypre_IndexRef periodic = hypre_SStructPGridPeriodic(pgrid);
276
277 hypre_StructGrid *cell_sgrid;
278 hypre_IndexRef cell_imax;
279 hypre_StructGrid *sgrid;
280 hypre_BoxArray *iboxarray;
281 hypre_BoxNeighbors *hood;
282 hypre_BoxArray *hood_boxes;
283 int hood_first_local;
284 int hood_num_local;
285 hypre_BoxArray *nbor_boxes;
286 hypre_BoxArray *diff_boxes;
287 hypre_BoxArray *tmp_boxes;
288 hypre_BoxArray *boxes;
289 hypre_Box *box;
290 hypre_Index varoffset;
291 int pneighbors_size;
292 int nbor_boxes_size;
293
294 int t, var, i, j, d;
295
296 /*-------------------------------------------------------------
297 * set up the uniquely distributed sgrids for each vartype
298 *-------------------------------------------------------------*/
299
300 cell_sgrid = hypre_SStructPGridCellSGrid(pgrid);
301 HYPRE_StructGridSetPeriodic(cell_sgrid, periodic);
302 if (!hypre_SStructPGridCellSGridDone(pgrid))
303 HYPRE_StructGridAssemble(cell_sgrid);
304
305 /* this is used to truncate boxes when periodicity is on */
306 cell_imax = hypre_BoxIMax(hypre_StructGridBoundingBox(cell_sgrid));
307
308 hood = hypre_StructGridNeighbors(cell_sgrid);
309 hood_boxes = hypre_BoxNeighborsBoxes(hood);
310 hood_first_local = hypre_BoxNeighborsFirstLocal(hood);
311 hood_num_local = hypre_BoxNeighborsNumLocal(hood);
312
313 pneighbors_size = hypre_BoxArraySize(pneighbors);
314 nbor_boxes_size = pneighbors_size + hood_first_local + hood_num_local;
315
316 nbor_boxes = hypre_BoxArrayCreate(nbor_boxes_size);
317 diff_boxes = hypre_BoxArrayCreate(0);
318 tmp_boxes = hypre_BoxArrayCreate(0);
319
320 for (var = 0; var < nvars; var++)
321 {
322 t = vartypes[var];
323
324 if ((t > 0) && (sgrids[t] == NULL))
325 {
326 HYPRE_StructGridCreate(comm, ndim, &sgrid);
327 boxes = hypre_BoxArrayCreate(0);
328 hypre_SStructVariableGetOffset((hypre_SStructVariable) t,
329 ndim, varoffset);
330
331 /* create nbor_boxes for this variable type */
332 for (i = 0; i < pneighbors_size; i++)
333 {
334 hypre_CopyBox(hypre_BoxArrayBox(pneighbors, i),
335 hypre_BoxArrayBox(nbor_boxes, i));
336 }
337 for (i = 0; i < (hood_first_local + hood_num_local); i++)
338 {
339 hypre_CopyBox(hypre_BoxArrayBox(hood_boxes, i),
340 hypre_BoxArrayBox(nbor_boxes, pneighbors_size + i));
341 }
342 for (i = 0; i < nbor_boxes_size; i++)
343 {
344 box = hypre_BoxArrayBox(nbor_boxes, i);
345 hypre_BoxIMinX(box) -= hypre_IndexX(varoffset);
346 hypre_BoxIMinY(box) -= hypre_IndexY(varoffset);
347 hypre_BoxIMinZ(box) -= hypre_IndexZ(varoffset);
348 }
349
350 /* boxes = (local boxes - neighbors with smaller ID - pneighbors) */
351 for (i = 0; i < hood_num_local; i++)
352 {
353 j = pneighbors_size + hood_first_local + i;
354 hypre_BoxArraySetSize(diff_boxes, 1);
355 hypre_CopyBox(hypre_BoxArrayBox(nbor_boxes, j),
356 hypre_BoxArrayBox(diff_boxes, 0));
357 hypre_BoxArraySetSize(nbor_boxes, j);
358
359 hypre_SubtractBoxArrays(diff_boxes, nbor_boxes, tmp_boxes);
360 hypre_AppendBoxArray(diff_boxes, boxes);
361 }
362
363 /* truncate if necessary when periodic */
364 for (d = 0; d < 3; d++)
365 {
366 if (hypre_IndexD(periodic, d) && hypre_IndexD(varoffset, d))
367 {
368 hypre_ForBoxI(i, boxes)
369 {
370 box = hypre_BoxArrayBox(boxes, i);
371 if (hypre_BoxIMaxD(box, d) == hypre_IndexD(cell_imax, d))
372 {
373 hypre_BoxIMaxD(box, d) --;
374 }
375 }
376 }
377 }
378 HYPRE_StructGridSetPeriodic(sgrid, periodic);
379
380 hypre_StructGridSetBoxes(sgrid, boxes);
381 HYPRE_StructGridAssemble(sgrid);
382
383 sgrids[t] = sgrid;
384 }
385 }
386
387 hypre_BoxArrayDestroy(nbor_boxes);
388 hypre_BoxArrayDestroy(diff_boxes);
389 hypre_BoxArrayDestroy(tmp_boxes);
390
391 /*-------------------------------------------------------------
392 * compute iboxarrays
393 *-------------------------------------------------------------*/
394
395 for (t = 0; t < 8; t++)
396 {
397 sgrid = sgrids[t];
398 if (sgrid != NULL)
399 {
400 iboxarray = hypre_BoxArrayDuplicate(hypre_StructGridBoxes(sgrid));
401
402 hypre_SStructVariableGetOffset((hypre_SStructVariable) t,
403 ndim, varoffset);
404 hypre_ForBoxI(i, iboxarray)
405 {
406 /* grow the boxes */
407 box = hypre_BoxArrayBox(iboxarray, i);
408 hypre_BoxIMinX(box) -= hypre_IndexX(varoffset);
409 hypre_BoxIMinY(box) -= hypre_IndexY(varoffset);
410 hypre_BoxIMinZ(box) -= hypre_IndexZ(varoffset);
411 hypre_BoxIMaxX(box) += hypre_IndexX(varoffset);
412 hypre_BoxIMaxY(box) += hypre_IndexY(varoffset);
413 hypre_BoxIMaxZ(box) += hypre_IndexZ(varoffset);
414 }
415
416 iboxarrays[t] = iboxarray;
417 }
418 }
419
420 /*-------------------------------------------------------------
421 * set up the size info
422 * GEC0902 addition of the local ghost size for pgrid.At first pgridghlocalsize=0
423 *-------------------------------------------------------------*/
424
425 for (var = 0; var < nvars; var++)
426 {
427 sgrid = hypre_SStructPGridSGrid(pgrid, var);
428 hypre_SStructPGridLocalSize(pgrid) += hypre_StructGridLocalSize(sgrid);
429 hypre_SStructPGridGlobalSize(pgrid) += hypre_StructGridGlobalSize(sgrid);
430 hypre_SStructPGridGhlocalSize(pgrid) += hypre_StructGridGhlocalSize(sgrid);
431
432 }
433
434 return ierr;
435}
436
437/*==========================================================================
438 * SStructGrid routines
439 *==========================================================================*/
440
441/*--------------------------------------------------------------------------
442 * hypre_SStructGridRef
443 *--------------------------------------------------------------------------*/
444
445int
446hypre_SStructGridRef( hypre_SStructGrid *grid,
447 hypre_SStructGrid **grid_ref)
448{
449 hypre_SStructGridRefCount(grid) ++;
450 *grid_ref = grid;
451
452 return 0;
453}
454
455/*--------------------------------------------------------------------------
456 *--------------------------------------------------------------------------*/
457
458int
459hypre_SStructGridAssembleMaps( hypre_SStructGrid *grid )
460{
461 int ierr = 0;
462
463 MPI_Comm comm = hypre_SStructGridComm(grid);
464 int nparts = hypre_SStructGridNParts(grid);
465 int local_size = hypre_SStructGridLocalSize(grid);
466 hypre_BoxMap ***maps;
467 hypre_SStructMapInfo ***info;
468 hypre_SStructPGrid *pgrid;
469 int nvars;
470 hypre_StructGrid *sgrid;
471 hypre_Box *bounding_box;
472
473 HYPRE_BigInt *offsets;
474 hypre_SStructMapInfo *entry_info;
475 hypre_BoxArray *boxes;
476 hypre_Box *box;
477
478 int *procs;
479 int *local_boxnums;
480 int *boxproc_offset;
481 int first_local;
482
483 int nprocs, myproc;
484 int proc, part, var, b;
485
486 /* GEC0902 variable for ghost calculation */
487 hypre_Box *ghostbox;
488 int * num_ghost;
489 HYPRE_BigInt *ghoffsets;
490 int ghlocal_size = hypre_SStructGridGhlocalSize(grid);
491 HYPRE_BigInt tmp_big_int;
492
493 /*------------------------------------------------------
494 * Build map info for grid boxes
495 *------------------------------------------------------*/
496
497 MPI_Comm_size(comm, &nprocs);
498 MPI_Comm_rank(comm, &myproc);
499
500 offsets = hypre_TAlloc(HYPRE_BigInt, nprocs + 1);
501 offsets[0] = 0;
502
503 tmp_big_int = (HYPRE_BigInt) local_size;
504 MPI_Allgather(&tmp_big_int, 1, MPI_HYPRE_BIG_INT, &offsets[1], 1, MPI_HYPRE_BIG_INT, comm);
505
506 /* GEC0902 calculate a ghost piece for each mapentry using the ghlocalsize of the grid.
507 * Gather each ghlocalsize in each of the processors in comm */
508
509 ghoffsets = hypre_TAlloc(HYPRE_BigInt, nprocs +1);
510 ghoffsets[0] = 0;
511
512 tmp_big_int = (HYPRE_BigInt) ghlocal_size;
513
514 MPI_Allgather(&tmp_big_int, 1, MPI_HYPRE_BIG_INT, &ghoffsets[1], 1, MPI_HYPRE_BIG_INT, comm);
515
516
517 for (proc = 1; proc < (nprocs + 1); proc++)
518 {
519
520 offsets[proc] += offsets[proc-1];
521 ghoffsets[proc] += ghoffsets[proc-1];
522
523 }
524
525 hypre_SStructGridStartRank(grid) = offsets[myproc];
526
527 hypre_SStructGridGhstartRank(grid) = ghoffsets[myproc];
528
529 maps = hypre_TAlloc(hypre_BoxMap **, nparts);
530 info = hypre_TAlloc(hypre_SStructMapInfo **, nparts);
531 for (part = 0; part < nparts; part++)
532 {
533 pgrid = hypre_SStructGridPGrid(grid, part);
534 nvars = hypre_SStructPGridNVars(pgrid);
535
536 maps[part] = hypre_TAlloc(hypre_BoxMap *, nvars);
537 info[part] = hypre_TAlloc(hypre_SStructMapInfo *, nvars);
538 for (var = 0; var < nvars; var++)
539 {
540 sgrid = hypre_SStructPGridSGrid(pgrid, var);
541
542 /* NOTE: With neighborhood info from user, don't need all gather */
543 hypre_GatherAllBoxes(comm, hypre_StructGridBoxes(sgrid),
544 &boxes, &procs, &first_local);
545 bounding_box = hypre_StructGridBoundingBox(sgrid);
546
547 /* get the local box numbers for all the boxes*/
548 hypre_ComputeBoxnums(boxes, procs, &local_boxnums);
549
550 hypre_BoxMapCreate(hypre_BoxArraySize(boxes),
551 hypre_BoxIMin(bounding_box),
552 hypre_BoxIMax(bounding_box),
553 nprocs,
554 &maps[part][var]);
555
556 info[part][var] = hypre_TAlloc(hypre_SStructMapInfo,
557 hypre_BoxArraySize(boxes));
558
559 /* GEC0902 adding the ghost in the boxmap using a new function and sgrid info
560 * each sgrid has num_ghost, we just inject the ghost into the boxmap */
561
562 num_ghost = hypre_StructGridNumGhost(sgrid);
563 hypre_BoxMapSetNumGhost(maps[part][var], num_ghost);
564
565 ghostbox = hypre_BoxCreate();
566
567 boxproc_offset= hypre_BoxMapBoxProcOffset(maps[part][var]);
568 proc= -1;
569 for (b = 0; b < hypre_BoxArraySize(boxes); b++)
570 {
571 box = hypre_BoxArrayBox(boxes, b);
572 if (proc != procs[b])
573 {
574 proc= procs[b];
575 boxproc_offset[proc]= b; /* record the proc box offset */
576 }
577
578 entry_info = &info[part][var][b];
579 hypre_SStructMapInfoType(entry_info) =
580 hypre_SSTRUCT_MAP_INFO_DEFAULT;
581 hypre_SStructMapInfoProc(entry_info) = proc;
582 hypre_SStructMapInfoOffset(entry_info) = offsets[proc];
583 hypre_SStructMapInfoBox(entry_info) = local_boxnums[b];
584
585 /* GEC0902 ghoffsets added to entry_info */
586
587 hypre_SStructMapInfoGhoffset(entry_info) = ghoffsets[proc];
588
589 hypre_BoxMapAddEntry(maps[part][var],
590 hypre_BoxIMin(box),
591 hypre_BoxIMax(box),
592 entry_info);
593
594 offsets[proc] += (HYPRE_BigInt)hypre_BoxVolume(box);
595
596 /* GEC0902 expanding box to compute expanded volume for ghost calculation */
597
598 /* ghostbox = hypre_BoxCreate(); */
599 hypre_CopyBox(box, ghostbox);
600 hypre_BoxExpand(ghostbox,num_ghost);
601
602 ghoffsets[proc] += (HYPRE_BigInt)hypre_BoxVolume(ghostbox);
603 /* hypre_BoxDestroy(ghostbox); */
604 }
605
606 hypre_BoxDestroy(ghostbox);
607 hypre_BoxArrayDestroy(boxes);
608 hypre_TFree(procs);
609 hypre_TFree(local_boxnums);
610
611 hypre_BoxMapAssemble(maps[part][var], comm);
612 }
613 }
614 hypre_TFree(offsets);
615 hypre_TFree(ghoffsets);
616 hypre_SStructGridMaps(grid) = maps;
617 hypre_SStructGridInfo(grid) = info;
618
619 return ierr;
620}
621
622/*--------------------------------------------------------------------------
623 *--------------------------------------------------------------------------*/
624
625int
626hypre_SStructGridAssembleNBorMaps( hypre_SStructGrid *grid )
627{
628 int ierr = 0;
629
630 MPI_Comm comm = hypre_SStructGridComm(grid);
631 int nparts = hypre_SStructGridNParts(grid);
632 int **nvneighbors = hypre_SStructGridNVNeighbors(grid);
633 hypre_SStructNeighbor ***vneighbors = hypre_SStructGridVNeighbors(grid);
634 hypre_SStructNeighbor *vneighbor;
635 hypre_BoxMap ***maps = hypre_SStructGridMaps(grid);
636 hypre_SStructNMapInfo ***ninfo;
637 hypre_SStructPGrid *pgrid;
638 int nvars;
639
640 hypre_SStructNMapInfo *entry_ninfo;
641
642 hypre_BoxMapEntry *map_entry;
643 hypre_Box *nbor_box;
644 hypre_Box *box;
645 int nbor_part;
646 int nbor_boxnum;
647 hypre_Index nbor_ilower;
648 HYPRE_BigInt nbor_offset;
649 int nbor_proc;
650 hypre_Index c;
651 int *d, *stride;
652
653 int part, var, b;
654
655 /* GEC1002 additional ghost box */
656
657 hypre_Box *ghostbox ;
658 HYPRE_BigInt nbor_ghoffset;
659 int *ghstride;
660 int *num_ghost;
661
662 /*------------------------------------------------------
663 * Add neighbor boxes to maps and re-assemble
664 *------------------------------------------------------*/
665
666 box = hypre_BoxCreate();
667
668 /* GEC1002 creating a ghostbox for strides calculation */
669
670 ghostbox = hypre_BoxCreate();
671
672 ninfo = hypre_TAlloc(hypre_SStructNMapInfo **, nparts);
673 for (part = 0; part < nparts; part++)
674 {
675 pgrid = hypre_SStructGridPGrid(grid, part);
676 nvars = hypre_SStructPGridNVars(pgrid);
677 ninfo[part] = hypre_TAlloc(hypre_SStructNMapInfo *, nvars);
678
679 for (var = 0; var < nvars; var++)
680 {
681 ninfo[part][var] = hypre_TAlloc(hypre_SStructNMapInfo,
682 nvneighbors[part][var]);
683
684 for (b = 0; b < nvneighbors[part][var]; b++)
685 {
686 vneighbor = &vneighbors[part][var][b];
687 nbor_box = hypre_SStructNeighborBox(vneighbor);
688 nbor_part = hypre_SStructNeighborPart(vneighbor);
689 hypre_CopyIndex(hypre_SStructNeighborILower(vneighbor),
690 nbor_ilower);
691 /*
692 * Note that this assumes that the entire neighbor box
693 * actually lives on the global grid. This was insured by
694 * intersecting the neighbor boxes with the global grid.
695 * We also assume that each neighbour box intersects
696 * with only one box on the neighbouring processor. This
697 * should be the case since we only have one map_entry.
698 */
699 hypre_SStructGridFindMapEntry(grid, nbor_part, nbor_ilower, var,
700 &map_entry);
701
702 hypre_BoxMapEntryGetExtents(map_entry,
703 hypre_BoxIMin(box),
704 hypre_BoxIMax(box));
705 hypre_SStructMapEntryGetProcess(map_entry, &nbor_proc);
706 hypre_SStructMapEntryGetBox(map_entry, &nbor_boxnum);
707
708 /* GEC1002 using the globalcsrank for inclusion in the nmapinfo */
709 hypre_SStructMapEntryGetGlobalCSRank(map_entry, nbor_ilower,
710 &nbor_offset);
711 /* GEC1002 using the ghglobalrank for inclusion in the nmapinfo */
712 hypre_SStructMapEntryGetGlobalGhrank(map_entry, nbor_ilower,
713 &nbor_ghoffset);
714
715 num_ghost = hypre_BoxMapEntryNumGhost(map_entry);
716
717 entry_ninfo = &ninfo[part][var][b];
718 hypre_SStructMapInfoType(entry_ninfo) =
719 hypre_SSTRUCT_MAP_INFO_NEIGHBOR;
720 hypre_SStructMapInfoProc(entry_ninfo) = nbor_proc;
721 hypre_SStructMapInfoBox(entry_ninfo)= nbor_boxnum;
722 hypre_SStructMapInfoOffset(entry_ninfo) = nbor_offset;
723 /* GEC1002 inclusion of ghoffset for the ninfo */
724 hypre_SStructMapInfoGhoffset(entry_ninfo) = nbor_ghoffset;
725
726 hypre_SStructNMapInfoPart(entry_ninfo) = nbor_part;
727 hypre_CopyIndex(nbor_ilower,
728 hypre_SStructNMapInfoILower(entry_ninfo));
729 hypre_CopyIndex(hypre_SStructNeighborCoord(vneighbor),
730 hypre_SStructNMapInfoCoord(entry_ninfo));
731 hypre_CopyIndex(hypre_SStructNeighborDir(vneighbor),
732 hypre_SStructNMapInfoDir(entry_ninfo));
733
734 /*------------------------------------------------------
735 * This computes strides in the local index-space,
736 * so they may be negative.
737 *------------------------------------------------------*/
738
739 /* want `c' to map from neighbor index-space back */
740 d = hypre_SStructNMapInfoCoord(entry_ninfo);
741 c[d[0]] = 0;
742 c[d[1]] = 1;
743 c[d[2]] = 2;
744 d = hypre_SStructNMapInfoDir(entry_ninfo);
745
746 stride = hypre_SStructNMapInfoStride(entry_ninfo);
747 stride[c[0]] = 1;
748 stride[c[1]] = hypre_BoxSizeD(box, 0);
749 stride[c[2]] = hypre_BoxSizeD(box, 1) * stride[c[1]];
750 stride[c[0]] *= d[0];
751 stride[c[1]] *= d[1];
752 stride[c[2]] *= d[2];
753
754 /* GEC1002 expanding the ghostbox to compute the strides based on ghosts vector */
755
756 hypre_CopyBox(box, ghostbox);
757 hypre_BoxExpand(ghostbox,num_ghost);
758 ghstride = hypre_SStructNMapInfoGhstride(entry_ninfo);
759 ghstride[c[0]] = 1;
760 ghstride[c[1]] = hypre_BoxSizeD(ghostbox, 0);
761 ghstride[c[2]] = hypre_BoxSizeD(ghostbox, 1) * ghstride[c[1]];
762 ghstride[c[0]] *= d[0];
763 ghstride[c[1]] *= d[1];
764 ghstride[c[2]] *= d[2];
765 }
766 }
767
768 /* NOTE: It is important not to change the map in the above
769 * loop because it is needed in the 'FindMapEntry' call */
770 for (var = 0; var < nvars; var++)
771 {
772 hypre_BoxMapIncSize(maps[part][var], nvneighbors[part][var]);
773
774 for (b = 0; b < nvneighbors[part][var]; b++)
775 {
776 vneighbor = &vneighbors[part][var][b];
777 nbor_box = hypre_SStructNeighborBox(vneighbor);
778 hypre_BoxMapAddEntry(maps[part][var],
779 hypre_BoxIMin(nbor_box),
780 hypre_BoxIMax(nbor_box),
781 &ninfo[part][var][b]);
782 }
783
784 hypre_BoxMapAssemble(maps[part][var], comm);
785 }
786 }
787
788
789 hypre_SStructGridNInfo(grid) = ninfo;
790
791 hypre_BoxDestroy(box);
792
793 hypre_BoxDestroy(ghostbox);
794
795 return ierr;
796}
797
798/*--------------------------------------------------------------------------
799 * This routine returns a NULL 'entry_ptr' if an entry is not found
800 *--------------------------------------------------------------------------*/
801
802int
803hypre_SStructGridFindMapEntry( hypre_SStructGrid *grid,
804 int part,
805 hypre_Index index,
806 int var,
807 hypre_BoxMapEntry **entry_ptr )
808{
809 int ierr = 0;
810
811 hypre_BoxMapFindEntry(hypre_SStructGridMap(grid, part, var),
812 index, entry_ptr);
813
814 return ierr;
815}
816
817int
818hypre_SStructGridBoxProcFindMapEntry( hypre_SStructGrid *grid,
819 int part,
820 int var,
821 int box,
822 int proc,
823 hypre_BoxMapEntry **entry_ptr )
824{
825 int ierr = 0;
826
827 hypre_BoxMapFindBoxProcEntry(hypre_SStructGridMap(grid, part, var),
828 box, proc, entry_ptr);
829
830 return ierr;
831}
832
833/*--------------------------------------------------------------------------
834 *--------------------------------------------------------------------------*/
835
836int
837hypre_SStructMapEntryGetCSRstrides( hypre_BoxMapEntry *entry,
838 hypre_Index strides )
839{
840 int ierr = 0;
841 hypre_SStructMapInfo *entry_info;
842
843 hypre_BoxMapEntryGetInfo(entry, (void **) &entry_info);
844
845 if (hypre_SStructMapInfoType(entry_info) == hypre_SSTRUCT_MAP_INFO_DEFAULT)
846 {
847 hypre_Index imin;
848 hypre_Index imax;
849
850 hypre_BoxMapEntryGetExtents(entry, imin, imax);
851
852 strides[0] = 1;
853 strides[1] = hypre_IndexD(imax, 0) - hypre_IndexD(imin, 0) + 1;
854 strides[2] = hypre_IndexD(imax, 1) - hypre_IndexD(imin, 1) + 1;
855 strides[2] *= strides[1];
856 }
857 else
858 {
859 hypre_SStructNMapInfo *entry_ninfo;
860
861 entry_ninfo = (hypre_SStructNMapInfo *) entry_info;
862 hypre_CopyIndex(hypre_SStructNMapInfoStride(entry_ninfo), strides);
863 }
864
865 return ierr;
866}
867
868/*--------------------------------------------------------------------------
869 * GEC1002 addition for a ghost stride calculation
870 * same function except that you modify imin, imax with the ghost and
871 * when the info is type nmapinfo you pull the ghoststrides.
872 *--------------------------------------------------------------------------*/
873
874int
875hypre_SStructMapEntryGetGhstrides( hypre_BoxMapEntry *entry,
876 hypre_Index strides )
877{
878 int ierr = 0;
879 hypre_SStructMapInfo *entry_info;
880 int *numghost;
881 int d ;
882
883 hypre_BoxMapEntryGetInfo(entry, (void **) &entry_info);
884
885 if (hypre_SStructMapInfoType(entry_info) == hypre_SSTRUCT_MAP_INFO_DEFAULT)
886 {
887 hypre_Index imin;
888 hypre_Index imax;
889
890 hypre_BoxMapEntryGetExtents(entry, imin, imax);
891
892 /* GEC1002 getting the ghost from the mapentry to modify imin, imax */
893
894 numghost = hypre_BoxMapEntryNumGhost(entry);
895
896 for (d = 0; d < 3; d++)
897 {
898 imax[d] += numghost[2*d+1];
899 imin[d] -= numghost[2*d];
900 }
901
902 /* GEC1002 imin, imax modified now and calculation identical. */
903
904 strides[0] = 1;
905 strides[1] = hypre_IndexD(imax, 0) - hypre_IndexD(imin, 0) + 1;
906 strides[2] = hypre_IndexD(imax, 1) - hypre_IndexD(imin, 1) + 1;
907 strides[2] *= strides[1];
908 }
909 else
910 {
911 hypre_SStructNMapInfo *entry_ninfo;
912 /* GEC1002 we now get the ghost strides using the macro */
913 entry_ninfo = (hypre_SStructNMapInfo *) entry_info;
914 hypre_CopyIndex(hypre_SStructNMapInfoGhstride(entry_ninfo), strides);
915 }
916
917 return ierr;
918}
919
920/*--------------------------------------------------------------------------
921 *--------------------------------------------------------------------------*/
922
923int
924hypre_SStructMapEntryGetGlobalCSRank( hypre_BoxMapEntry *entry,
925 hypre_Index index,
926 HYPRE_BigInt *rank_ptr )
927{
928 int ierr = 0;
929
930 hypre_SStructMapInfo *entry_info;
931 hypre_Index imin;
932 hypre_Index imax;
933 hypre_Index strides;
934 HYPRE_BigInt offset;
935
936 hypre_BoxMapEntryGetInfo(entry, (void **) &entry_info);
937 hypre_BoxMapEntryGetExtents(entry, imin, imax);
938 offset = hypre_SStructMapInfoOffset(entry_info);
939
940 hypre_SStructMapEntryGetCSRstrides(entry, strides);
941
942 *rank_ptr = offset + (HYPRE_BigInt)
943 ((hypre_IndexD(index, 2) - hypre_IndexD(imin, 2)) * strides[2] +
944 (hypre_IndexD(index, 1) - hypre_IndexD(imin, 1)) * strides[1] +
945 (hypre_IndexD(index, 0) - hypre_IndexD(imin, 0)) * strides[0]);
946
947 return ierr;
948}
949
950/*--------------------------------------------------------------------------
951 * GEC1002 a way to get the rank when you are in the presence of ghosts
952 * It could have been a function pointer but this is safer. It computes
953 * the ghost rank by using ghoffset, ghstrides and imin is modified
954 *--------------------------------------------------------------------------*/
955
956
957int
958hypre_SStructMapEntryGetGlobalGhrank( hypre_BoxMapEntry *entry,
959 hypre_Index index,
960 HYPRE_BigInt *rank_ptr )
961{
962 int ierr = 0;
963
964 hypre_SStructMapInfo *entry_info;
965 hypre_Index imin;
966 hypre_Index imax;
967 hypre_Index ghstrides;
968 HYPRE_BigInt ghoffset;
969 int *numghost = hypre_BoxMapEntryNumGhost(entry);
970 int d;
971 int info_type;
972
973
974 hypre_BoxMapEntryGetInfo(entry, (void **) &entry_info);
975 hypre_BoxMapEntryGetExtents(entry, imin, imax);
976 ghoffset = hypre_SStructMapInfoGhoffset(entry_info);
977 info_type = hypre_SStructMapInfoType(entry_info);
978
979
980 hypre_SStructMapEntryGetGhstrides(entry, ghstrides);
981
982 /* GEC shifting the imin according to the ghosts when you have a default info
983 * When you have a neighbor info, you do not need to shift the imin since
984 * the ghoffset for neighbor info has factored in the ghost presence during
985 * the neighbor info assemble phase */
986
987 if (info_type == hypre_SSTRUCT_MAP_INFO_DEFAULT)
988 {
989 for (d = 0; d < 3; d++)
990 {
991 imin[d] -= numghost[2*d];
992 }
993 }
994
995 *rank_ptr = ghoffset + (HYPRE_BigInt)
996 ((hypre_IndexD(index, 2) - hypre_IndexD(imin, 2)) * ghstrides[2] +
997 (hypre_IndexD(index, 1) - hypre_IndexD(imin, 1)) * ghstrides[1] +
998 (hypre_IndexD(index, 0) - hypre_IndexD(imin, 0)) * ghstrides[0]);
999
1000 return ierr;
1001}
1002
1003/*--------------------------------------------------------------------------
1004 *--------------------------------------------------------------------------*/
1005
1006int
1007hypre_SStructMapEntryGetProcess( hypre_BoxMapEntry *entry,
1008 int *proc_ptr )
1009{
1010 int ierr = 0;
1011
1012 hypre_SStructMapInfo *entry_info;
1013
1014 hypre_BoxMapEntryGetInfo(entry, (void **) &entry_info);
1015 *proc_ptr = hypre_SStructMapInfoProc(entry_info);
1016
1017 return ierr;
1018}
1019
1020int
1021hypre_SStructMapEntryGetBox( hypre_BoxMapEntry *entry,
1022 int *box_ptr )
1023{
1024 int ierr = 0;
1025
1026 hypre_SStructMapInfo *entry_info;
1027
1028 hypre_BoxMapEntryGetInfo(entry, (void **) &entry_info);
1029 *box_ptr = hypre_SStructMapInfoBox(entry_info);
1030
1031 return ierr;
1032}
1033
1034/*--------------------------------------------------------------------------
1035 * Mapping Notes:
1036 *
1037 * coord maps Box index-space to NBorBox index-space. That is,
1038 * `coord[d]' is the dimension in the NBorBox index-space, and
1039 * `d' is the dimension in the Box index-space.
1040 *
1041 * dir works on the NBorBox index-space. That is, `dir[coord[d]]' is
1042 * the direction (positive or negative) of dimension `coord[d]' in
1043 * the NBorBox index-space, relative to the positive direction of
1044 * dimension `d' in the Box index-space.
1045 *
1046 *--------------------------------------------------------------------------*/
1047
1048int
1049hypre_SStructBoxToNBorBox( hypre_Box *box,
1050 hypre_Index index,
1051 hypre_Index nbor_index,
1052 hypre_Index coord,
1053 hypre_Index dir )
1054{
1055 int ierr = 0;
1056
1057 int *imin = hypre_BoxIMin(box);
1058 int *imax = hypre_BoxIMax(box);
1059 int nbor_imin[3];
1060 int nbor_imax[3];
1061
1062 int d, nd;
1063
1064 for (d = 0; d < 3; d++)
1065 {
1066 nd = coord[d];
1067 nbor_imin[nd] = nbor_index[nd] + (imin[d] - index[d]) * dir[nd];
1068 nbor_imax[nd] = nbor_index[nd] + (imax[d] - index[d]) * dir[nd];
1069 }
1070
1071 for (d = 0; d < 3; d++)
1072 {
1073 imin[d] = hypre_min(nbor_imin[d], nbor_imax[d]);
1074 imax[d] = hypre_max(nbor_imin[d], nbor_imax[d]);
1075 }
1076
1077 return ierr;
1078}
1079
1080/*--------------------------------------------------------------------------
1081 * See "Mapping Notes" in comment for `hypre_SStructBoxToNBorBox'.
1082 *--------------------------------------------------------------------------*/
1083
1084int
1085hypre_SStructNBorBoxToBox( hypre_Box *nbor_box,
1086 hypre_Index index,
1087 hypre_Index nbor_index,
1088 hypre_Index coord,
1089 hypre_Index dir )
1090{
1091 int ierr = 0;
1092
1093 int *nbor_imin = hypre_BoxIMin(nbor_box);
1094 int *nbor_imax = hypre_BoxIMax(nbor_box);
1095 int imin[3];
1096 int imax[3];
1097
1098 int d, nd;
1099
1100 for (d = 0; d < 3; d++)
1101 {
1102 nd = coord[d];
1103 imin[d] = index[d] + (nbor_imin[nd] - nbor_index[nd]) * dir[nd];
1104 imax[d] = index[d] + (nbor_imax[nd] - nbor_index[nd]) * dir[nd];
1105 }
1106
1107 for (d = 0; d < 3; d++)
1108 {
1109 nbor_imin[d] = hypre_min(imin[d], imax[d]);
1110 nbor_imax[d] = hypre_max(imin[d], imax[d]);
1111 }
1112
1113 return ierr;
1114}
1115
1116
1117
1118
1119/*--------------------------------------------------------------------------
1120 * GEC0902 a function that will set the ghost in each of the sgrids
1121 *
1122 *--------------------------------------------------------------------------*/
1123int
1124hypre_SStructGridSetNumGhost( hypre_SStructGrid *grid, int *num_ghost )
1125{
1126 int ierr = 0;
1127
1128 int nparts = hypre_SStructGridNParts(grid);
1129 int nvars ;
1130 int part ;
1131 int var ;
1132 hypre_SStructPGrid *pgrid;
1133 hypre_StructGrid *sgrid;
1134
1135 for (part = 0; part < nparts; part++)
1136 {
1137
1138 pgrid = hypre_SStructGridPGrid(grid, part);
1139 nvars = hypre_SStructPGridNVars(pgrid);
1140
1141 for ( var = 0; var < nvars; var++)
1142 {
1143 sgrid = hypre_SStructPGridSGrid(pgrid, var);
1144 hypre_StructGridSetNumGhost(sgrid, num_ghost);
1145 }
1146
1147 }
1148 return ierr;
1149}
1150
1151/*--------------------------------------------------------------------------
1152 * GEC1002 a function that will select the right way to calculate the rank
1153 * depending on the matrix type. It is an extension to the usual GetGlobalRank
1154 *
1155 *--------------------------------------------------------------------------*/
1156int
1157hypre_SStructMapEntryGetGlobalRank(hypre_BoxMapEntry *entry,
1158 hypre_Index index,
1159 HYPRE_BigInt *rank_ptr,
1160 int type)
1161{
1162 int ierr = 0;
1163
1164 if (type == HYPRE_PARCSR)
1165 {
1166 hypre_SStructMapEntryGetGlobalCSRank(entry,index,rank_ptr);
1167 }
1168 if (type == HYPRE_SSTRUCT || type == HYPRE_STRUCT)
1169 {
1170 hypre_SStructMapEntryGetGlobalGhrank(entry,index,rank_ptr);
1171 }
1172
1173 return ierr;
1174}
1175
1176
1177/*--------------------------------------------------------------------------
1178 * GEC1002 a function that will select the right way to calculate the strides
1179 * depending on the matrix type. It is an extension to the usual strides
1180 *
1181 *--------------------------------------------------------------------------*/
1182int
1183hypre_SStructMapEntryGetStrides(hypre_BoxMapEntry *entry,
1184 hypre_Index strides,
1185 int type)
1186{
1187 int ierr = 0;
1188
1189 if (type == HYPRE_PARCSR)
1190 {
1191 hypre_SStructMapEntryGetCSRstrides(entry,strides);
1192 }
1193 if (type == HYPRE_SSTRUCT || type == HYPRE_STRUCT)
1194 {
1195 hypre_SStructMapEntryGetGhstrides(entry,strides);
1196 }
1197
1198 return ierr;
1199}
1200
1201/*--------------------------------------------------------------------------
1202 * A function to determine the local variable box numbers that underlie
1203 * a cellbox with local box number boxnum. Only returns local box numbers
1204 * of myproc.
1205 *--------------------------------------------------------------------------*/
1206int
1207hypre_SStructBoxNumMap(hypre_SStructGrid *grid,
1208 int part,
1209 int boxnum,
1210 int **num_varboxes_ptr,
1211 int ***map_ptr)
1212{
1213 int ierr = 0;
1214
1215 hypre_SStructPGrid *pgrid = hypre_SStructGridPGrid(grid, part);
1216 hypre_StructGrid *cellgrid= hypre_SStructPGridCellSGrid(pgrid);
1217 hypre_StructGrid *vargrid;
1218 hypre_BoxArray *boxes;
1219 hypre_Box *cellbox, vbox, *box, intersect_box;
1220 HYPRE_SStructVariable *vartypes= hypre_SStructPGridVarTypes(pgrid);
1221
1222 int ndim = hypre_SStructGridNDim(grid);
1223 int nvars = hypre_SStructPGridNVars(pgrid);
1224 hypre_Index varoffset;
1225
1226 int *num_boxes;
1227 int **var_boxnums;
1228 int *temp;
1229
1230 int i, j, k, var;
1231
1232 cellbox= hypre_StructGridBox(cellgrid, boxnum);
1233
1234 /* ptrs to store var_box map info */
1235 num_boxes = hypre_CTAlloc(int, nvars);
1236 var_boxnums= hypre_TAlloc(int *, nvars);
1237
1238 /* intersect the cellbox with the var_boxes */
1239 for (var= 0; var< nvars; var++)
1240 {
1241 vargrid= hypre_SStructPGridSGrid(pgrid, var);
1242 boxes = hypre_StructGridBoxes(vargrid);
1243 temp = hypre_CTAlloc(int, hypre_BoxArraySize(boxes));
1244
1245 /* map cellbox to a variable box */
1246 hypre_CopyBox(cellbox, &vbox);
1247
1248 i= vartypes[var];
1249 hypre_SStructVariableGetOffset((hypre_SStructVariable) i,
1250 ndim, varoffset);
1251 hypre_SubtractIndex(hypre_BoxIMin(&vbox), varoffset,
1252 hypre_BoxIMin(&vbox));
1253
1254 /* loop over boxes to see if they intersect with vbox */
1255 hypre_ForBoxI(i, boxes)
1256 {
1257 box= hypre_BoxArrayBox(boxes, i);
1258 hypre_IntersectBoxes(&vbox, box, &intersect_box);
1259 if (hypre_BoxVolume(&intersect_box))
1260 {
1261 temp[i]++;
1262 num_boxes[var]++;
1263 }
1264 }
1265
1266 /* record local var box numbers */
1267 if (num_boxes[var])
1268 {
1269 var_boxnums[var]= hypre_TAlloc(int, num_boxes[var]);
1270 }
1271 else
1272 {
1273 var_boxnums[var]= NULL;
1274 }
1275
1276 j= 0;
1277 k= hypre_BoxArraySize(boxes);
1278 for (i= 0; i< k; i++)
1279 {
1280 if (temp[i])
1281 {
1282 var_boxnums[var][j]= i;
1283 j++;
1284 }
1285 }
1286 hypre_TFree(temp);
1287
1288 } /* for (var= 0; var< nvars; var++) */
1289
1290 *num_varboxes_ptr= num_boxes;
1291 *map_ptr= var_boxnums;
1292
1293 return ierr;
1294}
1295
1296/*--------------------------------------------------------------------------
1297 * A function to extract all the local var box numbers underlying the
1298 * cellgrid boxes.
1299 *--------------------------------------------------------------------------*/
1300int
1301hypre_SStructCellGridBoxNumMap(hypre_SStructGrid *grid,
1302 int part,
1303 int ***num_varboxes_ptr,
1304 int ****map_ptr)
1305{
1306 int ierr = 0;
1307
1308 hypre_SStructPGrid *pgrid = hypre_SStructGridPGrid(grid, part);
1309 hypre_StructGrid *cellgrid = hypre_SStructPGridCellSGrid(pgrid);
1310 hypre_BoxArray *cellboxes= hypre_StructGridBoxes(cellgrid);
1311
1312 int **num_boxes;
1313 int ***var_boxnums;
1314
1315 int i, ncellboxes;
1316
1317 ncellboxes = hypre_BoxArraySize(cellboxes);
1318
1319 num_boxes = hypre_TAlloc(int *, ncellboxes);
1320 var_boxnums= hypre_TAlloc(int **, ncellboxes);
1321
1322 hypre_ForBoxI(i, cellboxes)
1323 {
1324 hypre_SStructBoxNumMap(grid,
1325 part,
1326 i,
1327 &num_boxes[i],
1328 &var_boxnums[i]);
1329 }
1330
1331 *num_varboxes_ptr= num_boxes;
1332 *map_ptr= var_boxnums;
1333
1334 return ierr;
1335}
Note: See TracBrowser for help on using the repository browser.