| 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 | * HYPRE_StructMatrix interface
|
|---|
| 17 | *
|
|---|
| 18 | *****************************************************************************/
|
|---|
| 19 |
|
|---|
| 20 | #include "headers.h"
|
|---|
| 21 |
|
|---|
| 22 | /*--------------------------------------------------------------------------
|
|---|
| 23 | * HYPRE_StructMatrixCreate
|
|---|
| 24 | *--------------------------------------------------------------------------*/
|
|---|
| 25 |
|
|---|
| 26 | int
|
|---|
| 27 | HYPRE_StructMatrixCreate( MPI_Comm comm,
|
|---|
| 28 | HYPRE_StructGrid grid,
|
|---|
| 29 | HYPRE_StructStencil stencil,
|
|---|
| 30 | HYPRE_StructMatrix *matrix )
|
|---|
| 31 | {
|
|---|
| 32 | *matrix = hypre_StructMatrixCreate(comm, grid, stencil);
|
|---|
| 33 |
|
|---|
| 34 | return 0;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | /*--------------------------------------------------------------------------
|
|---|
| 38 | * HYPRE_StructMatrixDestroy
|
|---|
| 39 | *--------------------------------------------------------------------------*/
|
|---|
| 40 |
|
|---|
| 41 | int
|
|---|
| 42 | HYPRE_StructMatrixDestroy( HYPRE_StructMatrix matrix )
|
|---|
| 43 | {
|
|---|
| 44 | return( hypre_StructMatrixDestroy(matrix) );
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | /*--------------------------------------------------------------------------
|
|---|
| 48 | * HYPRE_StructMatrixInitialize
|
|---|
| 49 | *--------------------------------------------------------------------------*/
|
|---|
| 50 |
|
|---|
| 51 | int
|
|---|
| 52 | HYPRE_StructMatrixInitialize( HYPRE_StructMatrix matrix )
|
|---|
| 53 | {
|
|---|
| 54 | return ( hypre_StructMatrixInitialize(matrix) );
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | /*--------------------------------------------------------------------------
|
|---|
| 58 | * HYPRE_StructMatrixSetValues
|
|---|
| 59 | *--------------------------------------------------------------------------*/
|
|---|
| 60 |
|
|---|
| 61 | int
|
|---|
| 62 | HYPRE_StructMatrixSetValues( HYPRE_StructMatrix matrix,
|
|---|
| 63 | int *grid_index,
|
|---|
| 64 | int num_stencil_indices,
|
|---|
| 65 | int *stencil_indices,
|
|---|
| 66 | double *values )
|
|---|
| 67 | {
|
|---|
| 68 | hypre_Index new_grid_index;
|
|---|
| 69 |
|
|---|
| 70 | int d;
|
|---|
| 71 | int ierr = 0;
|
|---|
| 72 |
|
|---|
| 73 | hypre_ClearIndex(new_grid_index);
|
|---|
| 74 | for (d = 0; d < hypre_StructGridDim(hypre_StructMatrixGrid(matrix)); d++)
|
|---|
| 75 | {
|
|---|
| 76 | hypre_IndexD(new_grid_index, d) = grid_index[d];
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | ierr = hypre_StructMatrixSetValues(matrix, new_grid_index,
|
|---|
| 80 | num_stencil_indices, stencil_indices,
|
|---|
| 81 | values, 0);
|
|---|
| 82 |
|
|---|
| 83 | return (ierr);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | /*--------------------------------------------------------------------------
|
|---|
| 87 | * HYPRE_StructMatrixSetBoxValues
|
|---|
| 88 | *--------------------------------------------------------------------------*/
|
|---|
| 89 |
|
|---|
| 90 | int
|
|---|
| 91 | HYPRE_StructMatrixSetBoxValues( HYPRE_StructMatrix matrix,
|
|---|
| 92 | int *ilower,
|
|---|
| 93 | int *iupper,
|
|---|
| 94 | int num_stencil_indices,
|
|---|
| 95 | int *stencil_indices,
|
|---|
| 96 | double *values )
|
|---|
| 97 | {
|
|---|
| 98 | hypre_Index new_ilower;
|
|---|
| 99 | hypre_Index new_iupper;
|
|---|
| 100 | hypre_Box *new_value_box;
|
|---|
| 101 |
|
|---|
| 102 | int d;
|
|---|
| 103 | int ierr = 0;
|
|---|
| 104 |
|
|---|
| 105 | hypre_ClearIndex(new_ilower);
|
|---|
| 106 | hypre_ClearIndex(new_iupper);
|
|---|
| 107 | for (d = 0; d < hypre_StructGridDim(hypre_StructMatrixGrid(matrix)); d++)
|
|---|
| 108 | {
|
|---|
| 109 | hypre_IndexD(new_ilower, d) = ilower[d];
|
|---|
| 110 | hypre_IndexD(new_iupper, d) = iupper[d];
|
|---|
| 111 | }
|
|---|
| 112 | new_value_box = hypre_BoxCreate();
|
|---|
| 113 | hypre_BoxSetExtents(new_value_box, new_ilower, new_iupper);
|
|---|
| 114 |
|
|---|
| 115 | ierr = hypre_StructMatrixSetBoxValues(matrix, new_value_box,
|
|---|
| 116 | num_stencil_indices, stencil_indices,
|
|---|
| 117 | values, 0);
|
|---|
| 118 |
|
|---|
| 119 | hypre_BoxDestroy(new_value_box);
|
|---|
| 120 |
|
|---|
| 121 | return (ierr);
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | /*--------------------------------------------------------------------------
|
|---|
| 125 | * HYPRE_StructMatrixGetBoxValues
|
|---|
| 126 | *--------------------------------------------------------------------------*/
|
|---|
| 127 |
|
|---|
| 128 | int
|
|---|
| 129 | HYPRE_StructMatrixGetBoxValues( HYPRE_StructMatrix matrix,
|
|---|
| 130 | int *ilower,
|
|---|
| 131 | int *iupper,
|
|---|
| 132 | int num_stencil_indices,
|
|---|
| 133 | int *stencil_indices,
|
|---|
| 134 | double *values )
|
|---|
| 135 | {
|
|---|
| 136 | hypre_Index new_ilower;
|
|---|
| 137 | hypre_Index new_iupper;
|
|---|
| 138 | hypre_Box *new_value_box;
|
|---|
| 139 |
|
|---|
| 140 | int d;
|
|---|
| 141 | int ierr = 0;
|
|---|
| 142 |
|
|---|
| 143 | hypre_ClearIndex(new_ilower);
|
|---|
| 144 | hypre_ClearIndex(new_iupper);
|
|---|
| 145 | for (d = 0; d < hypre_StructGridDim(hypre_StructMatrixGrid(matrix)); d++)
|
|---|
| 146 | {
|
|---|
| 147 | hypre_IndexD(new_ilower, d) = ilower[d];
|
|---|
| 148 | hypre_IndexD(new_iupper, d) = iupper[d];
|
|---|
| 149 | }
|
|---|
| 150 | new_value_box = hypre_BoxCreate();
|
|---|
| 151 | hypre_BoxSetExtents(new_value_box, new_ilower, new_iupper);
|
|---|
| 152 |
|
|---|
| 153 | ierr = hypre_StructMatrixSetBoxValues(matrix, new_value_box,
|
|---|
| 154 | num_stencil_indices, stencil_indices,
|
|---|
| 155 | values, -2);
|
|---|
| 156 |
|
|---|
| 157 | hypre_BoxDestroy(new_value_box);
|
|---|
| 158 |
|
|---|
| 159 | return (ierr);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 | /*--------------------------------------------------------------------------
|
|---|
| 164 | * HYPRE_StructMatrixSetConstantValues
|
|---|
| 165 | *--------------------------------------------------------------------------*/
|
|---|
| 166 |
|
|---|
| 167 | int
|
|---|
| 168 | HYPRE_StructMatrixSetConstantValues( HYPRE_StructMatrix matrix,
|
|---|
| 169 | int num_stencil_indices,
|
|---|
| 170 | int *stencil_indices,
|
|---|
| 171 | double *values )
|
|---|
| 172 | {
|
|---|
| 173 | return hypre_StructMatrixSetConstantValues( matrix,
|
|---|
| 174 | num_stencil_indices,
|
|---|
| 175 | stencil_indices,
|
|---|
| 176 | values,
|
|---|
| 177 | 0 );
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | /*--------------------------------------------------------------------------
|
|---|
| 181 | * HYPRE_StructMatrixAddToValues
|
|---|
| 182 | *--------------------------------------------------------------------------*/
|
|---|
| 183 |
|
|---|
| 184 | int
|
|---|
| 185 | HYPRE_StructMatrixAddToValues( HYPRE_StructMatrix matrix,
|
|---|
| 186 | int *grid_index,
|
|---|
| 187 | int num_stencil_indices,
|
|---|
| 188 | int *stencil_indices,
|
|---|
| 189 | double *values )
|
|---|
| 190 | {
|
|---|
| 191 | hypre_Index new_grid_index;
|
|---|
| 192 |
|
|---|
| 193 | int d;
|
|---|
| 194 | int ierr = 0;
|
|---|
| 195 |
|
|---|
| 196 | hypre_ClearIndex(new_grid_index);
|
|---|
| 197 | for (d = 0; d < hypre_StructGridDim(hypre_StructMatrixGrid(matrix)); d++)
|
|---|
| 198 | {
|
|---|
| 199 | hypre_IndexD(new_grid_index, d) = grid_index[d];
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | ierr = hypre_StructMatrixSetValues(matrix, new_grid_index,
|
|---|
| 203 | num_stencil_indices, stencil_indices,
|
|---|
| 204 | values, 1);
|
|---|
| 205 |
|
|---|
| 206 | return (ierr);
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | /*--------------------------------------------------------------------------
|
|---|
| 210 | * HYPRE_StructMatrixAddToBoxValues
|
|---|
| 211 | *--------------------------------------------------------------------------*/
|
|---|
| 212 |
|
|---|
| 213 | int
|
|---|
| 214 | HYPRE_StructMatrixAddToBoxValues( HYPRE_StructMatrix matrix,
|
|---|
| 215 | int *ilower,
|
|---|
| 216 | int *iupper,
|
|---|
| 217 | int num_stencil_indices,
|
|---|
| 218 | int *stencil_indices,
|
|---|
| 219 | double *values )
|
|---|
| 220 | {
|
|---|
| 221 | hypre_Index new_ilower;
|
|---|
| 222 | hypre_Index new_iupper;
|
|---|
| 223 | hypre_Box *new_value_box;
|
|---|
| 224 |
|
|---|
| 225 | int d;
|
|---|
| 226 | int ierr = 0;
|
|---|
| 227 |
|
|---|
| 228 | hypre_ClearIndex(new_ilower);
|
|---|
| 229 | hypre_ClearIndex(new_iupper);
|
|---|
| 230 | for (d = 0; d < hypre_StructGridDim(hypre_StructMatrixGrid(matrix)); d++)
|
|---|
| 231 | {
|
|---|
| 232 | hypre_IndexD(new_ilower, d) = ilower[d];
|
|---|
| 233 | hypre_IndexD(new_iupper, d) = iupper[d];
|
|---|
| 234 | }
|
|---|
| 235 | new_value_box = hypre_BoxCreate();
|
|---|
| 236 | hypre_BoxSetExtents(new_value_box, new_ilower, new_iupper);
|
|---|
| 237 |
|
|---|
| 238 | ierr = hypre_StructMatrixSetBoxValues(matrix, new_value_box,
|
|---|
| 239 | num_stencil_indices, stencil_indices,
|
|---|
| 240 | values, 1);
|
|---|
| 241 |
|
|---|
| 242 | hypre_BoxDestroy(new_value_box);
|
|---|
| 243 |
|
|---|
| 244 | return (ierr);
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | /*--------------------------------------------------------------------------
|
|---|
| 248 | * HYPRE_StructMatrixAddToConstantValues
|
|---|
| 249 | *--------------------------------------------------------------------------*/
|
|---|
| 250 |
|
|---|
| 251 | int
|
|---|
| 252 | HYPRE_StructMatrixAddToConstantValues( HYPRE_StructMatrix matrix,
|
|---|
| 253 | int num_stencil_indices,
|
|---|
| 254 | int *stencil_indices,
|
|---|
| 255 | double *values )
|
|---|
| 256 | {
|
|---|
| 257 | return hypre_StructMatrixSetConstantValues( matrix,
|
|---|
| 258 | num_stencil_indices,
|
|---|
| 259 | stencil_indices,
|
|---|
| 260 | values,
|
|---|
| 261 | 1 );
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | /*--------------------------------------------------------------------------
|
|---|
| 265 | * HYPRE_StructMatrixAssemble
|
|---|
| 266 | *--------------------------------------------------------------------------*/
|
|---|
| 267 |
|
|---|
| 268 | int
|
|---|
| 269 | HYPRE_StructMatrixAssemble( HYPRE_StructMatrix matrix )
|
|---|
| 270 | {
|
|---|
| 271 | return( hypre_StructMatrixAssemble(matrix) );
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | /*--------------------------------------------------------------------------
|
|---|
| 275 | * HYPRE_StructMatrixSetNumGhost
|
|---|
| 276 | *--------------------------------------------------------------------------*/
|
|---|
| 277 |
|
|---|
| 278 | int
|
|---|
| 279 | HYPRE_StructMatrixSetNumGhost( HYPRE_StructMatrix matrix,
|
|---|
| 280 | int *num_ghost )
|
|---|
| 281 | {
|
|---|
| 282 | return ( hypre_StructMatrixSetNumGhost(matrix, num_ghost) );
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | /*--------------------------------------------------------------------------
|
|---|
| 286 | * HYPRE_StructMatrixGetGrid
|
|---|
| 287 | *--------------------------------------------------------------------------*/
|
|---|
| 288 |
|
|---|
| 289 | int
|
|---|
| 290 | HYPRE_StructMatrixGetGrid( HYPRE_StructMatrix matrix, HYPRE_StructGrid *grid )
|
|---|
| 291 | {
|
|---|
| 292 | int ierr = 0;
|
|---|
| 293 |
|
|---|
| 294 | *grid = hypre_StructMatrixGrid(matrix);
|
|---|
| 295 |
|
|---|
| 296 | return ierr;
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | /*--------------------------------------------------------------------------
|
|---|
| 300 | * HYPRE_StructMatrixSetSymmetric
|
|---|
| 301 | *--------------------------------------------------------------------------*/
|
|---|
| 302 |
|
|---|
| 303 | int
|
|---|
| 304 | HYPRE_StructMatrixSetSymmetric( HYPRE_StructMatrix matrix,
|
|---|
| 305 | int symmetric )
|
|---|
| 306 | {
|
|---|
| 307 | int ierr = 0;
|
|---|
| 308 |
|
|---|
| 309 | hypre_StructMatrixSymmetric(matrix) = symmetric;
|
|---|
| 310 |
|
|---|
| 311 | return ierr;
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | /*--------------------------------------------------------------------------
|
|---|
| 315 | * HYPRE_StructMatrixSetConstantEntries
|
|---|
| 316 | * Call this function to declare that certain stencil points are constant
|
|---|
| 317 | * throughout the mesh.
|
|---|
| 318 | * - nentries is the number of array entries
|
|---|
| 319 | * - Each int entries[i] is an index into the shape array of the stencil of the
|
|---|
| 320 | * matrix.
|
|---|
| 321 | * In the present version, only three possibilites are recognized:
|
|---|
| 322 | * - no entries constant (constant_coefficient==0)
|
|---|
| 323 | * - all entries constant (constant_coefficient==1)
|
|---|
| 324 | * - all but the diagonal entry constant (constant_coefficient==2)
|
|---|
| 325 | * If something else is attempted, this function will return a nonzero error.
|
|---|
| 326 | * In the present version, if this function is called more than once, only
|
|---|
| 327 | * the last call will take effect.
|
|---|
| 328 | *--------------------------------------------------------------------------*/
|
|---|
| 329 |
|
|---|
| 330 | int HYPRE_StructMatrixSetConstantEntries( HYPRE_StructMatrix matrix,
|
|---|
| 331 | int nentries,
|
|---|
| 332 | int *entries )
|
|---|
| 333 | {
|
|---|
| 334 | return hypre_StructMatrixSetConstantEntries( matrix, nentries, entries );
|
|---|
| 335 | }
|
|---|
| 336 |
|
|---|
| 337 | /*--------------------------------------------------------------------------
|
|---|
| 338 | * HYPRE_StructMatrixPrint
|
|---|
| 339 | *--------------------------------------------------------------------------*/
|
|---|
| 340 |
|
|---|
| 341 | int
|
|---|
| 342 | HYPRE_StructMatrixPrint( const char *filename,
|
|---|
| 343 | HYPRE_StructMatrix matrix,
|
|---|
| 344 | int all )
|
|---|
| 345 | {
|
|---|
| 346 | return ( hypre_StructMatrixPrint(filename, matrix, all) );
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | /*--------------------------------------------------------------------------
|
|---|
| 350 | * HYPRE_StructMatrixMatvec
|
|---|
| 351 | *--------------------------------------------------------------------------*/
|
|---|
| 352 |
|
|---|
| 353 | int
|
|---|
| 354 | HYPRE_StructMatrixMatvec( double alpha,
|
|---|
| 355 | HYPRE_StructMatrix A,
|
|---|
| 356 | HYPRE_StructVector x,
|
|---|
| 357 | double beta,
|
|---|
| 358 | HYPRE_StructVector y )
|
|---|
| 359 | {
|
|---|
| 360 | return ( hypre_StructMatvec( alpha, (hypre_StructMatrix *) A,
|
|---|
| 361 | (hypre_StructVector *) x, beta, (hypre_StructVector *) y) );
|
|---|
| 362 | }
|
|---|
| 363 |
|
|---|