forked from hypre-space/hypre
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHYPRE_sstruct_stencil.c
130 lines (102 loc) · 4.21 KB
/
HYPRE_sstruct_stencil.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/******************************************************************************
* Copyright (c) 1998 Lawrence Livermore National Security, LLC and other
* HYPRE Project Developers. See the top-level COPYRIGHT file for details.
*
* SPDX-License-Identifier: (Apache-2.0 OR MIT)
******************************************************************************/
/******************************************************************************
*
* HYPRE_SStructStencil interface
*
*****************************************************************************/
#include "_hypre_sstruct_mv.h"
/*--------------------------------------------------------------------------
*--------------------------------------------------------------------------*/
HYPRE_Int
HYPRE_SStructStencilCreate( HYPRE_Int ndim,
HYPRE_Int size,
HYPRE_SStructStencil *stencil_ptr )
{
hypre_SStructStencil *stencil;
hypre_StructStencil *sstencil;
HYPRE_Int *vars;
stencil = hypre_TAlloc(hypre_SStructStencil, 1, HYPRE_MEMORY_HOST);
HYPRE_StructStencilCreate(ndim, size, &sstencil);
vars = hypre_CTAlloc(HYPRE_Int, hypre_StructStencilSize(sstencil), HYPRE_MEMORY_HOST);
hypre_SStructStencilSStencil(stencil) = sstencil;
hypre_SStructStencilVars(stencil) = vars;
hypre_SStructStencilRefCount(stencil) = 1;
*stencil_ptr = stencil;
return hypre_error_flag;
}
/*--------------------------------------------------------------------------
*--------------------------------------------------------------------------*/
HYPRE_Int
HYPRE_SStructStencilDestroy( HYPRE_SStructStencil stencil )
{
if (stencil)
{
hypre_SStructStencilRefCount(stencil) --;
if (hypre_SStructStencilRefCount(stencil) == 0)
{
HYPRE_StructStencilDestroy(hypre_SStructStencilSStencil(stencil));
hypre_TFree(hypre_SStructStencilVars(stencil), HYPRE_MEMORY_HOST);
hypre_TFree(stencil, HYPRE_MEMORY_HOST);
}
}
return hypre_error_flag;
}
/*--------------------------------------------------------------------------
*--------------------------------------------------------------------------*/
HYPRE_Int
HYPRE_SStructStencilSetEntry( HYPRE_SStructStencil stencil,
HYPRE_Int entry,
HYPRE_Int *offset,
HYPRE_Int var )
{
hypre_StructStencil *sstencil = hypre_SStructStencilSStencil(stencil);
HYPRE_StructStencilSetElement(sstencil, entry, offset);
hypre_SStructStencilVar(stencil, entry) = var;
return hypre_error_flag;
}
/*--------------------------------------------------------------------------
*--------------------------------------------------------------------------*/
HYPRE_Int
HYPRE_SStructStencilPrint( FILE *file, HYPRE_SStructStencil stencil )
{
HYPRE_Int ndim = hypre_SStructStencilNDim(stencil);
HYPRE_Int *vars = hypre_SStructStencilVars(stencil);
hypre_Index *shape = hypre_SStructStencilShape(stencil);
HYPRE_Int size = hypre_SStructStencilSize(stencil);
HYPRE_Int i;
hypre_fprintf(file, "StencilCreate: %d %d", ndim, size);
for (i = 0; i < size; i++)
{
hypre_fprintf(file, "\nStencilSetEntry: %d %d ", i, vars[i]);
hypre_IndexPrint(file, ndim, shape[i]);
}
hypre_fprintf(file, "\n");
return hypre_error_flag;
}
/*--------------------------------------------------------------------------
*--------------------------------------------------------------------------*/
HYPRE_Int
HYPRE_SStructStencilRead( FILE *file, HYPRE_SStructStencil *stencil_ptr )
{
HYPRE_SStructStencil stencil;
HYPRE_Int var;
hypre_Index shape;
HYPRE_Int i, ndim;
HYPRE_Int entry, size;
hypre_fscanf(file, "StencilCreate: %d %d", &ndim, &size);
HYPRE_SStructStencilCreate(ndim, size, &stencil);
for (i = 0; i < size; i++)
{
hypre_fscanf(file, "\nStencilSetEntry: %d %d ", &entry, &var);
hypre_IndexRead(file, ndim, shape);
HYPRE_SStructStencilSetEntry(stencil, entry, shape, var);
}
hypre_fscanf(file, "\n");
*stencil_ptr = stencil;
return hypre_error_flag;
}