| 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 | * Structured copy routine
|
|---|
| 17 | *
|
|---|
| 18 | *****************************************************************************/
|
|---|
| 19 |
|
|---|
| 20 | #include "headers.h"
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | /*--------------------------------------------------------------------------
|
|---|
| 24 | * hypre_StructCopy
|
|---|
| 25 | *--------------------------------------------------------------------------*/
|
|---|
| 26 |
|
|---|
| 27 | int
|
|---|
| 28 | hypre_StructCopy( hypre_StructVector *x,
|
|---|
| 29 | hypre_StructVector *y )
|
|---|
| 30 | {
|
|---|
| 31 | int ierr = 0;
|
|---|
| 32 |
|
|---|
| 33 | hypre_Box *x_data_box;
|
|---|
| 34 | hypre_Box *y_data_box;
|
|---|
| 35 |
|
|---|
| 36 | int xi;
|
|---|
| 37 | int yi;
|
|---|
| 38 |
|
|---|
| 39 | double *xp;
|
|---|
| 40 | double *yp;
|
|---|
| 41 |
|
|---|
| 42 | hypre_BoxArray *boxes;
|
|---|
| 43 | hypre_Box *box;
|
|---|
| 44 | hypre_Index loop_size;
|
|---|
| 45 | hypre_IndexRef start;
|
|---|
| 46 | hypre_Index unit_stride;
|
|---|
| 47 |
|
|---|
| 48 | int i;
|
|---|
| 49 | int loopi, loopj, loopk;
|
|---|
| 50 |
|
|---|
| 51 | hypre_SetIndex(unit_stride, 1, 1, 1);
|
|---|
| 52 |
|
|---|
| 53 | boxes = hypre_StructGridBoxes(hypre_StructVectorGrid(y));
|
|---|
| 54 | hypre_ForBoxI(i, boxes)
|
|---|
| 55 | {
|
|---|
| 56 | box = hypre_BoxArrayBox(boxes, i);
|
|---|
| 57 | start = hypre_BoxIMin(box);
|
|---|
| 58 |
|
|---|
| 59 | x_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(x), i);
|
|---|
| 60 | y_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(y), i);
|
|---|
| 61 |
|
|---|
| 62 | xp = hypre_StructVectorBoxData(x, i);
|
|---|
| 63 | yp = hypre_StructVectorBoxData(y, i);
|
|---|
| 64 |
|
|---|
| 65 | hypre_BoxGetSize(box, loop_size);
|
|---|
| 66 |
|
|---|
| 67 | hypre_BoxLoop2Begin(loop_size,
|
|---|
| 68 | x_data_box, start, unit_stride, xi,
|
|---|
| 69 | y_data_box, start, unit_stride, yi);
|
|---|
| 70 |
|
|---|
| 71 | hypre_BoxLoop2For(loopi, loopj, loopk, xi, yi)
|
|---|
| 72 | {
|
|---|
| 73 | yp[yi] = xp[xi];
|
|---|
| 74 | }
|
|---|
| 75 | hypre_BoxLoop2End(xi, yi);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | return ierr;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | /*--------------------------------------------------------------------------
|
|---|
| 82 | * hypre_StructPartialCopy: copy only the components on a subset of the grid.
|
|---|
| 83 | * A BoxArrayArray of boxes are needed- for each box of x, only an array
|
|---|
| 84 | * of subboxes (i.e., a boxarray for each box of x) are copied.
|
|---|
| 85 | *--------------------------------------------------------------------------*/
|
|---|
| 86 |
|
|---|
| 87 | int
|
|---|
| 88 | hypre_StructPartialCopy( hypre_StructVector *x,
|
|---|
| 89 | hypre_StructVector *y,
|
|---|
| 90 | hypre_BoxArrayArray *array_boxes )
|
|---|
| 91 | {
|
|---|
| 92 | int ierr = 0;
|
|---|
| 93 |
|
|---|
| 94 | hypre_Box *x_data_box;
|
|---|
| 95 | hypre_Box *y_data_box;
|
|---|
| 96 |
|
|---|
| 97 | int xi;
|
|---|
| 98 | int yi;
|
|---|
| 99 |
|
|---|
| 100 | double *xp;
|
|---|
| 101 | double *yp;
|
|---|
| 102 |
|
|---|
| 103 | hypre_BoxArray *boxes;
|
|---|
| 104 | hypre_Box *box;
|
|---|
| 105 | hypre_Index loop_size;
|
|---|
| 106 | hypre_IndexRef start;
|
|---|
| 107 | hypre_Index unit_stride;
|
|---|
| 108 |
|
|---|
| 109 | int i, j ;
|
|---|
| 110 | int loopi, loopj, loopk;
|
|---|
| 111 |
|
|---|
| 112 | hypre_SetIndex(unit_stride, 1, 1, 1);
|
|---|
| 113 |
|
|---|
| 114 | hypre_ForBoxArrayI(i, array_boxes)
|
|---|
| 115 | {
|
|---|
| 116 | boxes = hypre_BoxArrayArrayBoxArray(array_boxes, i);
|
|---|
| 117 |
|
|---|
| 118 | x_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(x), i);
|
|---|
| 119 | y_data_box = hypre_BoxArrayBox(hypre_StructVectorDataSpace(y), i);
|
|---|
| 120 |
|
|---|
| 121 | xp = hypre_StructVectorBoxData(x, i);
|
|---|
| 122 | yp = hypre_StructVectorBoxData(y, i);
|
|---|
| 123 |
|
|---|
| 124 | /* array of sub_boxes of box_i of the vector */
|
|---|
| 125 | hypre_ForBoxI(j, boxes)
|
|---|
| 126 | {
|
|---|
| 127 | box = hypre_BoxArrayBox(boxes, j);
|
|---|
| 128 |
|
|---|
| 129 | start = hypre_BoxIMin(box);
|
|---|
| 130 | hypre_BoxGetSize(box, loop_size);
|
|---|
| 131 |
|
|---|
| 132 | hypre_BoxLoop2Begin(loop_size,
|
|---|
| 133 | x_data_box, start, unit_stride, xi,
|
|---|
| 134 | y_data_box, start, unit_stride, yi);
|
|---|
| 135 |
|
|---|
| 136 | hypre_BoxLoop2For(loopi, loopj, loopk, xi, yi)
|
|---|
| 137 | {
|
|---|
| 138 | yp[yi] = xp[xi];
|
|---|
| 139 | }
|
|---|
| 140 | hypre_BoxLoop2End(xi, yi);
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | return ierr;
|
|---|
| 145 | }
|
|---|