source: CIVL/examples/mpi-omp/AMG2013/struct_mv/HYPRE_struct_matrix.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: 13.6 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 * HYPRE_StructMatrix interface
17 *
18 *****************************************************************************/
19
20#include "headers.h"
21
22/*--------------------------------------------------------------------------
23 * HYPRE_StructMatrixCreate
24 *--------------------------------------------------------------------------*/
25
26int
27HYPRE_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
41int
42HYPRE_StructMatrixDestroy( HYPRE_StructMatrix matrix )
43{
44 return( hypre_StructMatrixDestroy(matrix) );
45}
46
47/*--------------------------------------------------------------------------
48 * HYPRE_StructMatrixInitialize
49 *--------------------------------------------------------------------------*/
50
51int
52HYPRE_StructMatrixInitialize( HYPRE_StructMatrix matrix )
53{
54 return ( hypre_StructMatrixInitialize(matrix) );
55}
56
57/*--------------------------------------------------------------------------
58 * HYPRE_StructMatrixSetValues
59 *--------------------------------------------------------------------------*/
60
61int
62HYPRE_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
90int
91HYPRE_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
128int
129HYPRE_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
167int
168HYPRE_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
184int
185HYPRE_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
213int
214HYPRE_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
251int
252HYPRE_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
268int
269HYPRE_StructMatrixAssemble( HYPRE_StructMatrix matrix )
270{
271 return( hypre_StructMatrixAssemble(matrix) );
272}
273
274/*--------------------------------------------------------------------------
275 * HYPRE_StructMatrixSetNumGhost
276 *--------------------------------------------------------------------------*/
277
278int
279HYPRE_StructMatrixSetNumGhost( HYPRE_StructMatrix matrix,
280 int *num_ghost )
281{
282 return ( hypre_StructMatrixSetNumGhost(matrix, num_ghost) );
283}
284
285/*--------------------------------------------------------------------------
286 * HYPRE_StructMatrixGetGrid
287 *--------------------------------------------------------------------------*/
288
289int
290HYPRE_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
303int
304HYPRE_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
330int 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
341int
342HYPRE_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
353int
354HYPRE_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
Note: See TracBrowser for help on using the repository browser.