source: CIVL/examples/mpi-omp/AMG2013/struct_mv/struct_matrix_mask.c@ 397ae5f

main test-branch
Last change on this file since 397ae5f 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: 4.7 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 * Member functions for hypre_StructMatrix class.
17 *
18 *****************************************************************************/
19
20#include "headers.h"
21
22/*--------------------------------------------------------------------------
23 * hypre_StructMatrixCreateMask
24 * This routine returns the matrix, `mask', containing pointers to
25 * some of the data in the input matrix `matrix'. This can be useful,
26 * for example, to construct "splittings" of a matrix for use in
27 * iterative methods. The key note here is that the matrix `mask' does
28 * NOT contain a copy of the data in `matrix', but it can be used as
29 * if it were a normal StructMatrix object.
30 *
31 * Notes:
32 * (1) Only the stencil, data_indices, and global_size components of the
33 * StructMatrix structure are modified.
34 * (2) PrintStructMatrix will not correctly print the stencil-to-data
35 * correspondence.
36 *--------------------------------------------------------------------------*/
37
38hypre_StructMatrix *
39hypre_StructMatrixCreateMask( hypre_StructMatrix *matrix,
40 int num_stencil_indices,
41 int *stencil_indices )
42{
43 hypre_StructMatrix *mask;
44
45 hypre_StructStencil *stencil;
46 hypre_Index *stencil_shape;
47 int stencil_size;
48 hypre_Index *mask_stencil_shape;
49 int mask_stencil_size;
50
51 hypre_BoxArray *data_space;
52 int **data_indices;
53 int **mask_data_indices;
54
55 int i, j;
56
57 stencil = hypre_StructMatrixStencil(matrix);
58 stencil_shape = hypre_StructStencilShape(stencil);
59 stencil_size = hypre_StructStencilSize(stencil);
60
61 mask = hypre_CTAlloc(hypre_StructMatrix, 1);
62
63 hypre_StructMatrixComm(mask) = hypre_StructMatrixComm(matrix);
64
65 hypre_StructGridRef(hypre_StructMatrixGrid(matrix),
66 &hypre_StructMatrixGrid(mask));
67
68 hypre_StructMatrixUserStencil(mask) =
69 hypre_StructStencilRef(hypre_StructMatrixUserStencil(matrix));
70
71 mask_stencil_size = num_stencil_indices;
72 mask_stencil_shape = hypre_CTAlloc(hypre_Index, num_stencil_indices);
73 for (i = 0; i < num_stencil_indices; i++)
74 {
75 hypre_CopyIndex(stencil_shape[stencil_indices[i]],
76 mask_stencil_shape[i]);
77 }
78 hypre_StructMatrixStencil(mask) =
79 hypre_StructStencilCreate(hypre_StructStencilDim(stencil),
80 mask_stencil_size,
81 mask_stencil_shape);
82
83 hypre_StructMatrixNumValues(mask) = hypre_StructMatrixNumValues(matrix);
84
85 hypre_StructMatrixDataSpace(mask) =
86 hypre_BoxArrayDuplicate(hypre_StructMatrixDataSpace(matrix));
87
88 hypre_StructMatrixData(mask) = hypre_StructMatrixData(matrix);
89 hypre_StructMatrixDataAlloced(mask) = 0;
90 hypre_StructMatrixDataSize(mask) = hypre_StructMatrixDataSize(matrix);
91 data_space = hypre_StructMatrixDataSpace(matrix);
92 data_indices = hypre_StructMatrixDataIndices(matrix);
93 mask_data_indices = hypre_CTAlloc(int *, hypre_BoxArraySize(data_space));
94 hypre_ForBoxI(i, data_space)
95 {
96 mask_data_indices[i] = hypre_TAlloc(int, num_stencil_indices);
97 for (j = 0; j < num_stencil_indices; j++)
98 {
99 mask_data_indices[i][j] = data_indices[i][stencil_indices[j]];
100 }
101 }
102 hypre_StructMatrixDataIndices(mask) = mask_data_indices;
103
104 hypre_StructMatrixSymmetric(mask) = hypre_StructMatrixSymmetric(matrix);
105
106 hypre_StructMatrixSymmElements(mask) = hypre_TAlloc(int, stencil_size);
107 for (i = 0; i < stencil_size; i++)
108 {
109 hypre_StructMatrixSymmElements(mask)[i] =
110 hypre_StructMatrixSymmElements(matrix)[i];
111 }
112
113 for (i = 0; i < 6; i++)
114 {
115 hypre_StructMatrixNumGhost(mask)[i] =
116 hypre_StructMatrixNumGhost(matrix)[i];
117 }
118
119 hypre_StructMatrixGlobalSize(mask) =
120 hypre_StructGridGlobalSize(hypre_StructMatrixGrid(mask)) *
121 mask_stencil_size;
122
123 hypre_StructMatrixCommPkg(mask) = NULL;
124
125 hypre_StructMatrixRefCount(mask) = 1;
126
127 return mask;
128}
129
Note: See TracBrowser for help on using the repository browser.