| 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_SStructVector class.
|
|---|
| 18 | *
|
|---|
| 19 | *****************************************************************************/
|
|---|
| 20 |
|
|---|
| 21 | #include "headers.h"
|
|---|
| 22 |
|
|---|
| 23 | /*==========================================================================
|
|---|
| 24 | * SStructPVector routines
|
|---|
| 25 | *==========================================================================*/
|
|---|
| 26 |
|
|---|
| 27 | /*--------------------------------------------------------------------------
|
|---|
| 28 | * hypre_SStructVectorRef
|
|---|
| 29 | *--------------------------------------------------------------------------*/
|
|---|
| 30 |
|
|---|
| 31 | int
|
|---|
| 32 | hypre_SStructPVectorRef( hypre_SStructPVector *vector,
|
|---|
| 33 | hypre_SStructPVector **vector_ref )
|
|---|
| 34 | {
|
|---|
| 35 | hypre_SStructPVectorRefCount(vector) ++;
|
|---|
| 36 | *vector_ref = vector;
|
|---|
| 37 |
|
|---|
| 38 | return 0;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | /*--------------------------------------------------------------------------
|
|---|
| 42 | * hypre_SStructPVectorCreate
|
|---|
| 43 | *--------------------------------------------------------------------------*/
|
|---|
| 44 |
|
|---|
| 45 | int
|
|---|
| 46 | hypre_SStructPVectorCreate( MPI_Comm comm,
|
|---|
| 47 | hypre_SStructPGrid *pgrid,
|
|---|
| 48 | hypre_SStructPVector **pvector_ptr)
|
|---|
| 49 | {
|
|---|
| 50 | int ierr = 0;
|
|---|
| 51 |
|
|---|
| 52 | hypre_SStructPVector *pvector;
|
|---|
| 53 | int nvars;
|
|---|
| 54 | hypre_StructVector **svectors;
|
|---|
| 55 | hypre_CommPkg **comm_pkgs;
|
|---|
| 56 | hypre_StructGrid *sgrid;
|
|---|
| 57 | HYPRE_SStructVariable *vartypes= hypre_SStructPGridVarTypes(pgrid);
|
|---|
| 58 | int ndim = hypre_SStructPGridNDim(pgrid);
|
|---|
| 59 | hypre_Index varoffset;
|
|---|
| 60 | int var, d;
|
|---|
| 61 |
|
|---|
| 62 | pvector = hypre_TAlloc(hypre_SStructPVector, 1);
|
|---|
| 63 |
|
|---|
| 64 | hypre_SStructPVectorComm(pvector) = comm;
|
|---|
| 65 | hypre_SStructPVectorPGrid(pvector) = pgrid;
|
|---|
| 66 | nvars = hypre_SStructPGridNVars(pgrid);
|
|---|
| 67 | hypre_SStructPVectorNVars(pvector) = nvars;
|
|---|
| 68 | svectors = hypre_TAlloc(hypre_StructVector *, nvars);
|
|---|
| 69 |
|
|---|
| 70 | for (var = 0; var < nvars; var++)
|
|---|
| 71 | {
|
|---|
| 72 | sgrid = hypre_SStructPGridSGrid(pgrid, var);
|
|---|
| 73 | svectors[var] = hypre_StructVectorCreate(comm, sgrid);
|
|---|
| 74 |
|
|---|
| 75 | /* set the Add_num_ghost layer */
|
|---|
| 76 | if (vartypes[var] > 0)
|
|---|
| 77 | {
|
|---|
| 78 | sgrid = hypre_StructVectorGrid(svectors[var]);
|
|---|
| 79 | hypre_SStructVariableGetOffset(vartypes[var], ndim, varoffset);
|
|---|
| 80 | for (d = 0; d < 3; d++)
|
|---|
| 81 | {
|
|---|
| 82 | hypre_StructVectorAddNumGhost(svectors[var])[2*d]=
|
|---|
| 83 | hypre_IndexD(varoffset, d);
|
|---|
| 84 | hypre_StructVectorAddNumGhost(svectors[var])[2*d+1]=
|
|---|
| 85 | hypre_IndexD(varoffset, d);
|
|---|
| 86 | }
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | }
|
|---|
| 90 | hypre_SStructPVectorSVectors(pvector) = svectors;
|
|---|
| 91 | comm_pkgs = hypre_TAlloc(hypre_CommPkg *, nvars);
|
|---|
| 92 | for (var = 0; var < nvars; var++)
|
|---|
| 93 | {
|
|---|
| 94 | comm_pkgs[var] = NULL;
|
|---|
| 95 | }
|
|---|
| 96 | hypre_SStructPVectorCommPkgs(pvector) = comm_pkgs;
|
|---|
| 97 | hypre_SStructPVectorRefCount(pvector) = 1;
|
|---|
| 98 |
|
|---|
| 99 | /* GEC inclusion of dataindices */
|
|---|
| 100 | hypre_SStructPVectorDataIndices(pvector) = NULL ;
|
|---|
| 101 |
|
|---|
| 102 | *pvector_ptr = pvector;
|
|---|
| 103 |
|
|---|
| 104 | return ierr;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | /*--------------------------------------------------------------------------
|
|---|
| 108 | * hypre_SStructPVectorDestroy
|
|---|
| 109 | *--------------------------------------------------------------------------*/
|
|---|
| 110 |
|
|---|
| 111 | int
|
|---|
| 112 | hypre_SStructPVectorDestroy( hypre_SStructPVector *pvector )
|
|---|
| 113 | {
|
|---|
| 114 | int ierr = 0;
|
|---|
| 115 |
|
|---|
| 116 | int nvars;
|
|---|
| 117 | hypre_StructVector **svectors;
|
|---|
| 118 | hypre_CommPkg **comm_pkgs;
|
|---|
| 119 | int var;
|
|---|
| 120 |
|
|---|
| 121 | /* GEC destroying dataindices and data in pvector */
|
|---|
| 122 |
|
|---|
| 123 | int *dataindices;
|
|---|
| 124 |
|
|---|
| 125 | if (pvector)
|
|---|
| 126 | {
|
|---|
| 127 | hypre_SStructPVectorRefCount(pvector) --;
|
|---|
| 128 | if (hypre_SStructPVectorRefCount(pvector) == 0)
|
|---|
| 129 | {
|
|---|
| 130 | nvars = hypre_SStructPVectorNVars(pvector);
|
|---|
| 131 | svectors = hypre_SStructPVectorSVectors(pvector);
|
|---|
| 132 | comm_pkgs = hypre_SStructPVectorCommPkgs(pvector);
|
|---|
| 133 | dataindices = hypre_SStructPVectorDataIndices(pvector);
|
|---|
| 134 | for (var = 0; var < nvars; var++)
|
|---|
| 135 | {
|
|---|
| 136 | hypre_StructVectorDestroy(svectors[var]);
|
|---|
| 137 | hypre_CommPkgDestroy(comm_pkgs[var]);
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | hypre_TFree(dataindices);
|
|---|
| 141 | hypre_TFree(svectors);
|
|---|
| 142 | hypre_TFree(comm_pkgs);
|
|---|
| 143 | hypre_TFree(pvector);
|
|---|
| 144 | }
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | return ierr;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | /*--------------------------------------------------------------------------
|
|---|
| 151 | * hypre_SStructPVectorInitialize
|
|---|
| 152 | *--------------------------------------------------------------------------*/
|
|---|
| 153 |
|
|---|
| 154 | int
|
|---|
| 155 | hypre_SStructPVectorInitialize( hypre_SStructPVector *pvector )
|
|---|
| 156 | {
|
|---|
| 157 | int ierr = 0;
|
|---|
| 158 | int nvars = hypre_SStructPVectorNVars(pvector);
|
|---|
| 159 | int var;
|
|---|
| 160 |
|
|---|
| 161 | for (var = 0; var < nvars; var++)
|
|---|
| 162 | {
|
|---|
| 163 | hypre_StructVectorInitialize(hypre_SStructPVectorSVector(pvector, var));
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | return ierr;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | /*--------------------------------------------------------------------------
|
|---|
| 170 | * hypre_SStructPVectorSetValues
|
|---|
| 171 | *--------------------------------------------------------------------------*/
|
|---|
| 172 |
|
|---|
| 173 | int
|
|---|
| 174 | hypre_SStructPVectorSetValues( hypre_SStructPVector *pvector,
|
|---|
| 175 | hypre_Index index,
|
|---|
| 176 | int var,
|
|---|
| 177 | double *value,
|
|---|
| 178 | int add_to )
|
|---|
| 179 | {
|
|---|
| 180 | int ierr = 0;
|
|---|
| 181 | hypre_StructVector *svector = hypre_SStructPVectorSVector(pvector, var);
|
|---|
| 182 |
|
|---|
| 183 | ierr = hypre_StructVectorSetValues(svector, index, *value, add_to);
|
|---|
| 184 |
|
|---|
| 185 | return ierr;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | /*--------------------------------------------------------------------------
|
|---|
| 189 | * hypre_SStructPVectorSetBoxValues
|
|---|
| 190 | *--------------------------------------------------------------------------*/
|
|---|
| 191 |
|
|---|
| 192 | int
|
|---|
| 193 | hypre_SStructPVectorSetBoxValues( hypre_SStructPVector *pvector,
|
|---|
| 194 | hypre_Index ilower,
|
|---|
| 195 | hypre_Index iupper,
|
|---|
| 196 | int var,
|
|---|
| 197 | double *values,
|
|---|
| 198 | int add_to )
|
|---|
| 199 | {
|
|---|
| 200 | int ierr = 0;
|
|---|
| 201 | hypre_StructVector *svector = hypre_SStructPVectorSVector(pvector, var);
|
|---|
| 202 | hypre_Box *box;
|
|---|
| 203 |
|
|---|
| 204 | box = hypre_BoxCreate();
|
|---|
| 205 | hypre_CopyIndex(ilower, hypre_BoxIMin(box));
|
|---|
| 206 | hypre_CopyIndex(iupper, hypre_BoxIMax(box));
|
|---|
| 207 | ierr = hypre_StructVectorSetBoxValues(svector, box, values, add_to );
|
|---|
| 208 | hypre_BoxDestroy(box);
|
|---|
| 209 |
|
|---|
| 210 | return ierr;
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | /*--------------------------------------------------------------------------
|
|---|
| 214 | * hypre_SStructPVectorAssemble
|
|---|
| 215 | *--------------------------------------------------------------------------*/
|
|---|
| 216 |
|
|---|
| 217 | int
|
|---|
| 218 | hypre_SStructPVectorAssemble( hypre_SStructPVector *pvector )
|
|---|
| 219 | {
|
|---|
| 220 | int ierr = 0;
|
|---|
| 221 |
|
|---|
| 222 | hypre_SStructPGrid *pgrid = hypre_SStructPVectorPGrid(pvector);
|
|---|
| 223 | int nvars = hypre_SStructPVectorNVars(pvector);
|
|---|
| 224 | hypre_StructVector **svectors = hypre_SStructPVectorSVectors(pvector);
|
|---|
| 225 | hypre_CommPkg **comm_pkgs = hypre_SStructPVectorCommPkgs(pvector);
|
|---|
| 226 |
|
|---|
| 227 | hypre_CommInfo *comm_info;
|
|---|
| 228 |
|
|---|
| 229 | int ndim = hypre_SStructPGridNDim(pgrid);
|
|---|
| 230 | HYPRE_SStructVariable *vartypes = hypre_SStructPGridVarTypes(pgrid);
|
|---|
| 231 |
|
|---|
| 232 | hypre_Index varoffset;
|
|---|
| 233 | int num_ghost[6];
|
|---|
| 234 | hypre_StructGrid *sgrid;
|
|---|
| 235 | int var, d;
|
|---|
| 236 |
|
|---|
| 237 | for (var = 0; var < nvars; var++)
|
|---|
| 238 | {
|
|---|
| 239 | hypre_StructVectorAssemble(svectors[var]);
|
|---|
| 240 |
|
|---|
| 241 | if (vartypes[var] > 0)
|
|---|
| 242 | {
|
|---|
| 243 | sgrid = hypre_StructVectorGrid(svectors[var]);
|
|---|
| 244 | hypre_SStructVariableGetOffset(vartypes[var], ndim, varoffset);
|
|---|
| 245 | for (d = 0; d < 3; d++)
|
|---|
| 246 | {
|
|---|
| 247 | num_ghost[2*d] = hypre_IndexD(varoffset, d);
|
|---|
| 248 | num_ghost[2*d+1] = hypre_IndexD(varoffset, d);
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | hypre_CreateCommInfoFromNumGhost(sgrid, num_ghost, &comm_info);
|
|---|
| 252 | hypre_CommPkgDestroy(comm_pkgs[var]);
|
|---|
| 253 | hypre_CommPkgCreate(comm_info,
|
|---|
| 254 | hypre_StructVectorDataSpace(svectors[var]),
|
|---|
| 255 | hypre_StructVectorDataSpace(svectors[var]),
|
|---|
| 256 | 1, hypre_StructVectorComm(svectors[var]),
|
|---|
| 257 | &comm_pkgs[var]);
|
|---|
| 258 | }
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | return ierr;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | /*--------------------------------------------------------------------------
|
|---|
| 265 | * hypre_SStructPVectorGather
|
|---|
| 266 | *--------------------------------------------------------------------------*/
|
|---|
| 267 |
|
|---|
| 268 | int
|
|---|
| 269 | hypre_SStructPVectorGather( hypre_SStructPVector *pvector )
|
|---|
| 270 | {
|
|---|
| 271 | int ierr = 0;
|
|---|
| 272 | int nvars = hypre_SStructPVectorNVars(pvector);
|
|---|
| 273 | hypre_StructVector **svectors = hypre_SStructPVectorSVectors(pvector);
|
|---|
| 274 | hypre_CommPkg **comm_pkgs = hypre_SStructPVectorCommPkgs(pvector);
|
|---|
| 275 | hypre_CommHandle *comm_handle;
|
|---|
| 276 | int var;
|
|---|
| 277 |
|
|---|
| 278 | for (var = 0; var < nvars; var++)
|
|---|
| 279 | {
|
|---|
| 280 | if (comm_pkgs[var] != NULL)
|
|---|
| 281 | {
|
|---|
| 282 | hypre_InitializeCommunication(comm_pkgs[var],
|
|---|
| 283 | hypre_StructVectorData(svectors[var]),
|
|---|
| 284 | hypre_StructVectorData(svectors[var]),
|
|---|
| 285 | &comm_handle);
|
|---|
| 286 | hypre_FinalizeCommunication(comm_handle);
|
|---|
| 287 | }
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | return ierr;
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | /*--------------------------------------------------------------------------
|
|---|
| 294 | * hypre_SStructPVectorGetValues
|
|---|
| 295 | *--------------------------------------------------------------------------*/
|
|---|
| 296 |
|
|---|
| 297 | int
|
|---|
| 298 | hypre_SStructPVectorGetValues( hypre_SStructPVector *pvector,
|
|---|
| 299 | hypre_Index index,
|
|---|
| 300 | int var,
|
|---|
| 301 | double *value )
|
|---|
| 302 | {
|
|---|
| 303 | int ierr = 0;
|
|---|
| 304 | hypre_SStructPGrid *pgrid = hypre_SStructPVectorPGrid(pvector);
|
|---|
| 305 | hypre_StructVector *svector = hypre_SStructPVectorSVector(pvector, var);
|
|---|
| 306 | hypre_StructGrid *sgrid = hypre_StructVectorGrid(svector);
|
|---|
| 307 | hypre_BoxArray *iboxarray = hypre_SStructPGridIBoxArray(pgrid, var);
|
|---|
| 308 | hypre_BoxArray *tboxarray;
|
|---|
| 309 |
|
|---|
| 310 | /* temporarily swap out sgrid boxes in order to get boundary data */
|
|---|
| 311 | tboxarray = hypre_StructGridBoxes(sgrid);
|
|---|
| 312 | hypre_StructGridBoxes(sgrid) = iboxarray;
|
|---|
| 313 | ierr = hypre_StructVectorGetValues(svector, index, value);
|
|---|
| 314 | hypre_StructGridBoxes(sgrid) = tboxarray;
|
|---|
| 315 |
|
|---|
| 316 | return ierr;
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | /*--------------------------------------------------------------------------
|
|---|
| 320 | * hypre_SStructPVectorGetBoxValues
|
|---|
| 321 | *--------------------------------------------------------------------------*/
|
|---|
| 322 |
|
|---|
| 323 | int
|
|---|
| 324 | hypre_SStructPVectorGetBoxValues( hypre_SStructPVector *pvector,
|
|---|
| 325 | hypre_Index ilower,
|
|---|
| 326 | hypre_Index iupper,
|
|---|
| 327 | int var,
|
|---|
| 328 | double *values )
|
|---|
| 329 | {
|
|---|
| 330 | int ierr = 0;
|
|---|
| 331 | hypre_SStructPGrid *pgrid = hypre_SStructPVectorPGrid(pvector);
|
|---|
| 332 | hypre_StructVector *svector = hypre_SStructPVectorSVector(pvector, var);
|
|---|
| 333 | hypre_StructGrid *sgrid = hypre_StructVectorGrid(svector);
|
|---|
| 334 | hypre_BoxArray *iboxarray = hypre_SStructPGridIBoxArray(pgrid, var);
|
|---|
| 335 | hypre_BoxArray *tboxarray;
|
|---|
| 336 | hypre_Box *box;
|
|---|
| 337 |
|
|---|
| 338 | box = hypre_BoxCreate();
|
|---|
| 339 | hypre_CopyIndex(ilower, hypre_BoxIMin(box));
|
|---|
| 340 | hypre_CopyIndex(iupper, hypre_BoxIMax(box));
|
|---|
| 341 | /* temporarily swap out sgrid boxes in order to get boundary data */
|
|---|
| 342 | tboxarray = hypre_StructGridBoxes(sgrid);
|
|---|
| 343 | hypre_StructGridBoxes(sgrid) = iboxarray;
|
|---|
| 344 | ierr = hypre_StructVectorGetBoxValues(svector, box, values);
|
|---|
| 345 | hypre_StructGridBoxes(sgrid) = tboxarray;
|
|---|
| 346 | hypre_BoxDestroy(box);
|
|---|
| 347 |
|
|---|
| 348 | return ierr;
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | /*--------------------------------------------------------------------------
|
|---|
| 352 | * hypre_SStructPVectorSetConstantValues
|
|---|
| 353 | *--------------------------------------------------------------------------*/
|
|---|
| 354 |
|
|---|
| 355 | int
|
|---|
| 356 | hypre_SStructPVectorSetConstantValues( hypre_SStructPVector *pvector,
|
|---|
| 357 | double value )
|
|---|
| 358 | {
|
|---|
| 359 | int ierr = 0;
|
|---|
| 360 | int nvars = hypre_SStructPVectorNVars(pvector);
|
|---|
| 361 | hypre_StructVector *svector;
|
|---|
| 362 | int var;
|
|---|
| 363 |
|
|---|
| 364 | for (var = 0; var < nvars; var++)
|
|---|
| 365 | {
|
|---|
| 366 | svector = hypre_SStructPVectorSVector(pvector, var);
|
|---|
| 367 | hypre_StructVectorSetConstantValues(svector, value);
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | return ierr;
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | /*--------------------------------------------------------------------------
|
|---|
| 374 | * hypre_SStructPVectorPrint: For now, just print multiple files
|
|---|
| 375 | *--------------------------------------------------------------------------*/
|
|---|
| 376 |
|
|---|
| 377 | int
|
|---|
| 378 | hypre_SStructPVectorPrint( const char *filename,
|
|---|
| 379 | hypre_SStructPVector *pvector,
|
|---|
| 380 | int all )
|
|---|
| 381 | {
|
|---|
| 382 | int ierr = 0;
|
|---|
| 383 | int nvars = hypre_SStructPVectorNVars(pvector);
|
|---|
| 384 | int var;
|
|---|
| 385 | char new_filename[255];
|
|---|
| 386 |
|
|---|
| 387 | for (var = 0; var < nvars; var++)
|
|---|
| 388 | {
|
|---|
| 389 | sprintf(new_filename, "%s.%02d", filename, var);
|
|---|
| 390 | hypre_StructVectorPrint(new_filename,
|
|---|
| 391 | hypre_SStructPVectorSVector(pvector, var),
|
|---|
| 392 | all);
|
|---|
| 393 | }
|
|---|
| 394 |
|
|---|
| 395 | return ierr;
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | /*==========================================================================
|
|---|
| 399 | * SStructVector routines
|
|---|
| 400 | *==========================================================================*/
|
|---|
| 401 |
|
|---|
| 402 | /*--------------------------------------------------------------------------
|
|---|
| 403 | * hypre_SStructVectorRef
|
|---|
| 404 | *--------------------------------------------------------------------------*/
|
|---|
| 405 |
|
|---|
| 406 | int
|
|---|
| 407 | hypre_SStructVectorRef( hypre_SStructVector *vector,
|
|---|
| 408 | hypre_SStructVector **vector_ref )
|
|---|
| 409 | {
|
|---|
| 410 | hypre_SStructVectorRefCount(vector) ++;
|
|---|
| 411 | *vector_ref = vector;
|
|---|
| 412 |
|
|---|
| 413 | return 0;
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 | /*--------------------------------------------------------------------------
|
|---|
| 417 | * hypre_SStructVectorSetConstantValues
|
|---|
| 418 | *--------------------------------------------------------------------------*/
|
|---|
| 419 |
|
|---|
| 420 | int
|
|---|
| 421 | hypre_SStructVectorSetConstantValues( hypre_SStructVector *vector,
|
|---|
| 422 | double value )
|
|---|
| 423 | {
|
|---|
| 424 | int ierr = 0;
|
|---|
| 425 | int nparts = hypre_SStructVectorNParts(vector);
|
|---|
| 426 | hypre_SStructPVector *pvector;
|
|---|
| 427 | int part;
|
|---|
| 428 |
|
|---|
| 429 | for (part = 0; part < nparts; part++)
|
|---|
| 430 | {
|
|---|
| 431 | pvector = hypre_SStructVectorPVector(vector, part);
|
|---|
| 432 | hypre_SStructPVectorSetConstantValues(pvector, value);
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 | return ierr;
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | /*--------------------------------------------------------------------------
|
|---|
| 439 | * hypre_SStructVectorConvert
|
|---|
| 440 | *
|
|---|
| 441 | * Here the address of the parvector inside the semistructured vector
|
|---|
| 442 | * is provided to the "outside". It assumes that the vector type
|
|---|
| 443 | * is HYPRE_SSTRUCT
|
|---|
| 444 | *--------------------------------------------------------------------------*/
|
|---|
| 445 |
|
|---|
| 446 | int
|
|---|
| 447 | hypre_SStructVectorConvert( hypre_SStructVector *vector,
|
|---|
| 448 | hypre_ParVector **parvector_ptr )
|
|---|
| 449 | {
|
|---|
| 450 | int ierr = 0;
|
|---|
| 451 |
|
|---|
| 452 | *parvector_ptr = hypre_SStructVectorParVector(vector);
|
|---|
| 453 |
|
|---|
| 454 | return ierr;
|
|---|
| 455 | }
|
|---|
| 456 |
|
|---|
| 457 | /*--------------------------------------------------------------------------
|
|---|
| 458 | * hypre_SStructParVectorConvert
|
|---|
| 459 | *
|
|---|
| 460 | * Copy values from vector to parvector and provide the address
|
|---|
| 461 | *--------------------------------------------------------------------------*/
|
|---|
| 462 |
|
|---|
| 463 | int
|
|---|
| 464 | hypre_SStructVectorParConvert( hypre_SStructVector *vector,
|
|---|
| 465 | hypre_ParVector **parvector_ptr )
|
|---|
| 466 | {
|
|---|
| 467 | int ierr = 0;
|
|---|
| 468 |
|
|---|
| 469 | hypre_ParVector *parvector;
|
|---|
| 470 | double *pardata;
|
|---|
| 471 | int pari;
|
|---|
| 472 |
|
|---|
| 473 | hypre_SStructPVector *pvector;
|
|---|
| 474 | hypre_StructVector *y;
|
|---|
| 475 | hypre_Box *y_data_box;
|
|---|
| 476 | int yi;
|
|---|
| 477 | double *yp;
|
|---|
| 478 | hypre_BoxArray *boxes;
|
|---|
| 479 | hypre_Box *box;
|
|---|
| 480 | int bi;
|
|---|
| 481 | hypre_Index loop_size;
|
|---|
| 482 | hypre_IndexRef start;
|
|---|
| 483 | hypre_Index stride;
|
|---|
| 484 |
|
|---|
| 485 | int nparts, nvars;
|
|---|
| 486 | int part, var, i;
|
|---|
| 487 | int loopi, loopj, loopk;
|
|---|
| 488 |
|
|---|
| 489 | hypre_SetIndex(stride, 1, 1, 1);
|
|---|
| 490 |
|
|---|
| 491 | parvector = hypre_SStructVectorParVector(vector);
|
|---|
| 492 | pardata = hypre_VectorData(hypre_ParVectorLocalVector(parvector));
|
|---|
| 493 | pari = 0;
|
|---|
| 494 | nparts = hypre_SStructVectorNParts(vector);
|
|---|
| 495 | for (part = 0; part < nparts; part++)
|
|---|
| 496 | {
|
|---|
| 497 | pvector = hypre_SStructVectorPVector(vector, part);
|
|---|
| 498 | nvars = hypre_SStructPVectorNVars(pvector);
|
|---|
| 499 | for (var = 0; var < nvars; var++)
|
|---|
| 500 | {
|
|---|
| 501 | y = hypre_SStructPVectorSVector(pvector, var);
|
|---|
| 502 |
|
|---|
| 503 | boxes = hypre_StructGridBoxes(hypre_StructVectorGrid(y));
|
|---|
| 504 | hypre_ForBoxI(i, boxes)
|
|---|
| 505 | {
|
|---|
| 506 | box = hypre_BoxArrayBox(boxes, i);
|
|---|
| 507 | start = hypre_BoxIMin(box);
|
|---|
| 508 |
|
|---|
| 509 | y_data_box =
|
|---|
| 510 | hypre_BoxArrayBox(hypre_StructVectorDataSpace(y), i);
|
|---|
| 511 | yp = hypre_StructVectorBoxData(y, i);
|
|---|
| 512 |
|
|---|
| 513 | hypre_BoxGetSize(box, loop_size);
|
|---|
| 514 | hypre_BoxLoop2Begin(loop_size,
|
|---|
| 515 | y_data_box, start, stride, yi,
|
|---|
| 516 | box, start, stride, bi);
|
|---|
| 517 |
|
|---|
| 518 | hypre_BoxLoop2For(loopi, loopj, loopk, yi, bi)
|
|---|
| 519 | {
|
|---|
| 520 | pardata[pari+bi] = yp[yi];
|
|---|
| 521 | }
|
|---|
| 522 | hypre_BoxLoop2End(yi, bi);
|
|---|
| 523 | pari +=
|
|---|
| 524 | hypre_IndexX(loop_size)*
|
|---|
| 525 | hypre_IndexY(loop_size)*
|
|---|
| 526 | hypre_IndexZ(loop_size);
|
|---|
| 527 | }
|
|---|
| 528 | }
|
|---|
| 529 | }
|
|---|
| 530 |
|
|---|
| 531 | *parvector_ptr = hypre_SStructVectorParVector(vector);
|
|---|
| 532 |
|
|---|
| 533 | return ierr;
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | /*--------------------------------------------------------------------------
|
|---|
| 537 | * hypre_SStructVectorRestore
|
|---|
| 538 | * used for HYPRE_SSTRUCT type semi structured vectors.
|
|---|
| 539 | * A dummy function to indicate that the struct vector part will be used.
|
|---|
| 540 | *--------------------------------------------------------------------------*/
|
|---|
| 541 |
|
|---|
| 542 | int
|
|---|
| 543 | hypre_SStructVectorRestore( hypre_SStructVector *vector,
|
|---|
| 544 | hypre_ParVector *parvector )
|
|---|
| 545 | {
|
|---|
| 546 | int ierr = 0;
|
|---|
| 547 |
|
|---|
| 548 | return ierr;
|
|---|
| 549 | }
|
|---|
| 550 |
|
|---|
| 551 | /*--------------------------------------------------------------------------
|
|---|
| 552 | * hypre_SStructVectorParRestore
|
|---|
| 553 | *
|
|---|
| 554 | * Copy values from parvector to vector
|
|---|
| 555 | *--------------------------------------------------------------------------*/
|
|---|
| 556 |
|
|---|
| 557 | int
|
|---|
| 558 | hypre_SStructVectorParRestore( hypre_SStructVector *vector,
|
|---|
| 559 | hypre_ParVector *parvector )
|
|---|
| 560 | {
|
|---|
| 561 | int ierr = 0;
|
|---|
| 562 |
|
|---|
| 563 | double *pardata;
|
|---|
| 564 | int pari;
|
|---|
| 565 |
|
|---|
| 566 | hypre_SStructPVector *pvector;
|
|---|
| 567 | hypre_StructVector *y;
|
|---|
| 568 | hypre_Box *y_data_box;
|
|---|
| 569 | int yi;
|
|---|
| 570 | double *yp;
|
|---|
| 571 | hypre_BoxArray *boxes;
|
|---|
| 572 | hypre_Box *box;
|
|---|
| 573 | int bi;
|
|---|
| 574 | hypre_Index loop_size;
|
|---|
| 575 | hypre_IndexRef start;
|
|---|
| 576 | hypre_Index stride;
|
|---|
| 577 |
|
|---|
| 578 | int nparts, nvars;
|
|---|
| 579 | int part, var, i;
|
|---|
| 580 | int loopi, loopj, loopk;
|
|---|
| 581 |
|
|---|
| 582 | if (parvector != NULL)
|
|---|
| 583 | {
|
|---|
| 584 | hypre_SetIndex(stride, 1, 1, 1);
|
|---|
| 585 |
|
|---|
| 586 | parvector = hypre_SStructVectorParVector(vector);
|
|---|
| 587 | pardata = hypre_VectorData(hypre_ParVectorLocalVector(parvector));
|
|---|
| 588 | pari = 0;
|
|---|
| 589 | nparts = hypre_SStructVectorNParts(vector);
|
|---|
| 590 | for (part = 0; part < nparts; part++)
|
|---|
| 591 | {
|
|---|
| 592 | pvector = hypre_SStructVectorPVector(vector, part);
|
|---|
| 593 | nvars = hypre_SStructPVectorNVars(pvector);
|
|---|
| 594 | for (var = 0; var < nvars; var++)
|
|---|
| 595 | {
|
|---|
| 596 | y = hypre_SStructPVectorSVector(pvector, var);
|
|---|
| 597 |
|
|---|
| 598 | boxes = hypre_StructGridBoxes(hypre_StructVectorGrid(y));
|
|---|
| 599 | hypre_ForBoxI(i, boxes)
|
|---|
| 600 | {
|
|---|
| 601 | box = hypre_BoxArrayBox(boxes, i);
|
|---|
| 602 | start = hypre_BoxIMin(box);
|
|---|
| 603 |
|
|---|
| 604 | y_data_box =
|
|---|
| 605 | hypre_BoxArrayBox(hypre_StructVectorDataSpace(y), i);
|
|---|
| 606 | yp = hypre_StructVectorBoxData(y, i);
|
|---|
| 607 |
|
|---|
| 608 | hypre_BoxGetSize(box, loop_size);
|
|---|
| 609 | hypre_BoxLoop2Begin(loop_size,
|
|---|
| 610 | y_data_box, start, stride, yi,
|
|---|
| 611 | box, start, stride, bi);
|
|---|
| 612 |
|
|---|
| 613 | hypre_BoxLoop2For(loopi, loopj, loopk, yi, bi)
|
|---|
| 614 | {
|
|---|
| 615 | yp[yi] = pardata[pari+bi];
|
|---|
| 616 | }
|
|---|
| 617 | hypre_BoxLoop2End(yi, bi);
|
|---|
| 618 | pari +=
|
|---|
| 619 | hypre_IndexX(loop_size)*
|
|---|
| 620 | hypre_IndexY(loop_size)*
|
|---|
| 621 | hypre_IndexZ(loop_size);
|
|---|
| 622 | }
|
|---|
| 623 | }
|
|---|
| 624 | }
|
|---|
| 625 | }
|
|---|
| 626 |
|
|---|
| 627 | return ierr;
|
|---|
| 628 | }
|
|---|
| 629 | /*------------------------------------------------------------------
|
|---|
| 630 | * GEC1002 shell initialization of a pvector
|
|---|
| 631 | * if the pvector exists. This function will set the dataindices
|
|---|
| 632 | * and datasize of the pvector. Datasize is the sum of the sizes
|
|---|
| 633 | * of each svector and dataindices is defined as
|
|---|
| 634 | * dataindices[var]= aggregated initial size of the pvector[var]
|
|---|
| 635 | * When ucvars are present we need to modify adding nucvars.
|
|---|
| 636 | *----------------------------------------------------------------*/
|
|---|
| 637 | int
|
|---|
| 638 | hypre_SStructPVectorInitializeShell( hypre_SStructPVector *pvector)
|
|---|
| 639 | {
|
|---|
| 640 | int ierr=0;
|
|---|
| 641 | int nvars = hypre_SStructPVectorNVars(pvector);
|
|---|
| 642 | int var ;
|
|---|
| 643 | int pdatasize;
|
|---|
| 644 | int svectdatasize;
|
|---|
| 645 | int *pdataindices;
|
|---|
| 646 | int nucvars = 0;
|
|---|
| 647 |
|
|---|
| 648 | hypre_StructVector *svector;
|
|---|
| 649 |
|
|---|
| 650 | pdatasize = 0;
|
|---|
| 651 | pdataindices = hypre_CTAlloc(int, nvars);
|
|---|
| 652 |
|
|---|
| 653 | for (var =0; var < nvars; var++)
|
|---|
| 654 | {
|
|---|
| 655 | svector = hypre_SStructPVectorSVector(pvector, var);
|
|---|
| 656 | hypre_StructVectorInitializeShell(svector);
|
|---|
| 657 | pdataindices[var] = pdatasize ;
|
|---|
| 658 | svectdatasize = hypre_StructVectorDataSize(svector);
|
|---|
| 659 | pdatasize += svectdatasize;
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 | /* GEC1002 assuming that the ucvars are located at the end, after the
|
|---|
| 663 | * the size of the vars has been included we add the number of uvar
|
|---|
| 664 | * for this part */
|
|---|
| 665 |
|
|---|
| 666 | hypre_SStructPVectorDataIndices(pvector) = pdataindices;
|
|---|
| 667 | hypre_SStructPVectorDataSize(pvector) = pdatasize+nucvars ;
|
|---|
| 668 |
|
|---|
| 669 | return ierr;
|
|---|
| 670 | }
|
|---|
| 671 |
|
|---|
| 672 | /*------------------------------------------------------------------
|
|---|
| 673 | * GEC1002 shell initialization of a sstructvector
|
|---|
| 674 | * if the vector exists. This function will set the
|
|---|
| 675 | * dataindices and datasize of the vector. When ucvars
|
|---|
| 676 | * are present at the end of all the parts we need to modify adding pieces
|
|---|
| 677 | * for ucvars.
|
|---|
| 678 | *----------------------------------------------------------------*/
|
|---|
| 679 | int
|
|---|
| 680 | hypre_SStructVectorInitializeShell( hypre_SStructVector *vector)
|
|---|
| 681 | {
|
|---|
| 682 | int ierr = 0;
|
|---|
| 683 | int part ;
|
|---|
| 684 | int datasize;
|
|---|
| 685 | int pdatasize;
|
|---|
| 686 | int nparts = hypre_SStructVectorNParts(vector);
|
|---|
| 687 | hypre_SStructPVector *pvector;
|
|---|
| 688 | int *dataindices;
|
|---|
| 689 |
|
|---|
| 690 | datasize = 0;
|
|---|
| 691 | dataindices = hypre_CTAlloc(int, nparts);
|
|---|
| 692 | for (part = 0; part < nparts; part++)
|
|---|
| 693 | {
|
|---|
| 694 | pvector = hypre_SStructVectorPVector(vector, part) ;
|
|---|
| 695 | hypre_SStructPVectorInitializeShell(pvector);
|
|---|
| 696 | pdatasize = hypre_SStructPVectorDataSize(pvector);
|
|---|
| 697 | dataindices[part] = datasize ;
|
|---|
| 698 | datasize += pdatasize ;
|
|---|
| 699 | }
|
|---|
| 700 | hypre_SStructVectorDataIndices(vector) = dataindices;
|
|---|
| 701 | hypre_SStructVectorDataSize(vector) = datasize ;
|
|---|
| 702 |
|
|---|
| 703 | return ierr;
|
|---|
| 704 | }
|
|---|
| 705 |
|
|---|
| 706 |
|
|---|
| 707 | int
|
|---|
| 708 | hypre_SStructVectorClearGhostValues(hypre_SStructVector *vector)
|
|---|
| 709 | {
|
|---|
| 710 | int ierr= 0;
|
|---|
| 711 |
|
|---|
| 712 | int nparts= hypre_SStructVectorNParts(vector);
|
|---|
| 713 | hypre_SStructPVector *pvector;
|
|---|
| 714 | hypre_StructVector *svector;
|
|---|
| 715 |
|
|---|
| 716 | int part;
|
|---|
| 717 | int nvars, var;
|
|---|
| 718 |
|
|---|
| 719 | for (part= 0; part< nparts; part++)
|
|---|
| 720 | {
|
|---|
| 721 | pvector= hypre_SStructVectorPVector(vector, part);
|
|---|
| 722 | nvars = hypre_SStructPVectorNVars(pvector);
|
|---|
| 723 |
|
|---|
| 724 | for (var= 0; var< nvars; var++)
|
|---|
| 725 | {
|
|---|
| 726 | svector= hypre_SStructPVectorSVector(pvector, var);
|
|---|
| 727 | hypre_StructVectorClearGhostValues(svector);
|
|---|
| 728 | }
|
|---|
| 729 | }
|
|---|
| 730 |
|
|---|
| 731 | return ierr;
|
|---|
| 732 | }
|
|---|
| 733 |
|
|---|
| 734 |
|
|---|
| 735 |
|
|---|