shell.c (8a1243692a7577dbaf7e3932d63d3490e8f07c26) shell.c (ef66eb6987ddfdf4e414d6b820cbc8d8d7d17bc2)
1/*$Id: shell.c,v 1.86 2001/03/28 19:41:21 balay Exp bsmith $*/
1/*$Id: shell.c,v 1.87 2001/07/20 21:20:12 bsmith Exp bsmith $*/
2
3/*
4 This provides a simple shell for Fortran (and C programmers) to
5 create a very simple matrix class for use with KSP without coding
6 much of anything.
7*/
8
9#include "src/mat/matimpl.h" /*I "petscmat.h" I*/
10#include "src/vec/vecimpl.h"
11
12typedef struct {
2
3/*
4 This provides a simple shell for Fortran (and C programmers) to
5 create a very simple matrix class for use with KSP without coding
6 much of anything.
7*/
8
9#include "src/mat/matimpl.h" /*I "petscmat.h" I*/
10#include "src/vec/vecimpl.h"
11
12typedef struct {
13 int (*destroy)(Mat);
14 void *ctx;
13 int (*destroy)(Mat);
14 int (*mult)(Mat,Vec,Vec);
15 PetscTruth scale,shift;
16 PetscScalar vscale,vshift;
17 void *ctx;
15} Mat_Shell;
16
17#undef __FUNCT__
18#define __FUNCT__ "MatShellGetContext"
19/*@
20 MatShellGetContext - Returns the user-provided context associated with a shell matrix.
21
22 Not Collective

--- 48 unchanged lines hidden (view full) ---

71 int ierr,tmp;
72
73 PetscFunctionBegin;
74 ierr = MPI_Scan(&mat->m,&tmp,1,MPI_INT,MPI_SUM,mat->comm);CHKERRQ(ierr);
75 if (rstart) *rstart = tmp - mat->m;
76 if (rend) *rend = tmp;
77 PetscFunctionReturn(0);
78}
18} Mat_Shell;
19
20#undef __FUNCT__
21#define __FUNCT__ "MatShellGetContext"
22/*@
23 MatShellGetContext - Returns the user-provided context associated with a shell matrix.
24
25 Not Collective

--- 48 unchanged lines hidden (view full) ---

74 int ierr,tmp;
75
76 PetscFunctionBegin;
77 ierr = MPI_Scan(&mat->m,&tmp,1,MPI_INT,MPI_SUM,mat->comm);CHKERRQ(ierr);
78 if (rstart) *rstart = tmp - mat->m;
79 if (rend) *rend = tmp;
80 PetscFunctionReturn(0);
81}
82
83#undef __FUNCT__
84#define __FUNCT__ "MatMult_Shell"
85int MatMult_Shell(Mat A,Vec x,Vec y)
86{
87 Mat_Shell *shell = (Mat_Shell*)A->data;
88 int ierr;
89
90 PetscFunctionBegin;
91 ierr = (*shell->mult)(A,x,y);CHKERRQ(ierr);
92 if (shell->shift && shell->scale) {
93 ierr = VecAXPBY(&shell->vshift,&shell->vscale,x,y);CHKERRQ(ierr);
94 } else if (shell->scale) {
95 ierr = VecScale(&shell->vscale,y);CHKERRQ(ierr);
96 } else {
97 ierr = VecAXPY(&shell->vshift,x,y);CHKERRQ(ierr);
98 }
99 PetscFunctionReturn(0);
100}
101
102#undef __FUNCT__
103#define __FUNCT__ "MatShift_Shell"
104int MatShift_Shell(PetscScalar *a,Mat Y)
105{
106 Mat_Shell *shell = (Mat_Shell*)Y->data;
107 PetscFunctionBegin;
108 if (shell->scale || shell->shift) {
109 shell->vshift += *a;
110 } else {
111 shell->mult = Y->ops->mult;
112 Y->ops->mult = MatMult_Shell;
113 shell->vshift = *a;
114 }
115 shell->shift = PETSC_TRUE;
116 PetscFunctionReturn(0);
117}
118
119#undef __FUNCT__
120#define __FUNCT__ "MatScale_Shell"
121int MatScale_Shell(PetscScalar *a,Mat Y)
122{
123 Mat_Shell *shell = (Mat_Shell*)Y->data;
124 PetscFunctionBegin;
125 if (shell->scale || shell->shift) {
126 shell->vscale *= *a;
127 } else {
128 shell->mult = Y->ops->mult;
129 Y->ops->mult = MatMult_Shell;
130 shell->vscale = *a;
131 }
132 shell->scale = PETSC_TRUE;
133 PetscFunctionReturn(0);
134}
135
136#undef __FUNCT__
137#define __FUNCT__ "MatAssemblyEnd_Shell"
138int MatAssemblyEnd_Shell(Mat Y,MatAssemblyType t)
139{
140 Mat_Shell *shell = (Mat_Shell*)Y->data;
141
142 PetscFunctionBegin;
143 if ((shell->shift || shell->scale) && t == MAT_FINAL_ASSEMBLY) {
144 shell->scale = PETSC_FALSE;
145 shell->shift = PETSC_FALSE;
146 shell->vshift = 0.0;
147 shell->vscale = 1.0;
148 Y->ops->mult = shell->mult;
149 }
150 PetscFunctionReturn(0);
151}
152
79extern int MatConvert_Shell(Mat,MatType,Mat*);
80
81static struct _MatOps MatOps_Values = {0,
82 0,
83 0,
84 0,
85 0,
86 0,

--- 7 unchanged lines hidden (view full) ---

94 0,
95 0,
96 0,
97 0,
98 0,
99 0,
100 0,
101 0,
153extern int MatConvert_Shell(Mat,MatType,Mat*);
154
155static struct _MatOps MatOps_Values = {0,
156 0,
157 0,
158 0,
159 0,
160 0,

--- 7 unchanged lines hidden (view full) ---

168 0,
169 0,
170 0,
171 0,
172 0,
173 0,
174 0,
175 0,
176 MatAssemblyEnd_Shell,
102 0,
103 0,
104 0,
105 0,
106 0,
107 0,
108 0,
109 0,
110 0,
177 0,
178 0,
179 0,
180 0,
181 0,
182 0,
183 0,
184 0,
185 0,
111 0,
112 MatGetOwnershipRange_Shell,
113 0,
114 0,
115 0,
116 0,
117 0,
118 0,
119 0,
120 0,
121 0,
122 0,
123 0,
124 0,
125 0,
126 0,
127 0,
128 0,
186 MatGetOwnershipRange_Shell,
187 0,
188 0,
189 0,
190 0,
191 0,
192 0,
193 0,
194 0,
195 0,
196 0,
197 0,
198 0,
199 0,
200 0,
201 0,
202 0,
203 MatScale_Shell,
204 MatShift_Shell,
129 0,
130 0,
131 0,
132 0,
133 0,
134 0,
135 0,
136 0,
137 0,
138 0,
139 0,
140 0,
141 0,
205 0,
206 0,
207 0,
208 0,
209 0,
210 0,
211 0,
212 0,
213 0,
214 0,
215 0,
216 0,
217 0,
142 0,
143 0,
144 MatDestroy_Shell,
145 0,
146 MatGetPetscMaps_Petsc,
147 0,
148 0,
149 0,
150 0,
151 0,

--- 22 unchanged lines hidden (view full) ---

174 }
175
176 ierr = PetscSplitOwnership(A->comm,&A->m,&A->M);CHKERRQ(ierr);
177 ierr = PetscSplitOwnership(A->comm,&A->n,&A->N);CHKERRQ(ierr);
178
179 ierr = PetscMapCreateMPI(A->comm,A->m,A->M,&A->rmap);CHKERRQ(ierr);
180 ierr = PetscMapCreateMPI(A->comm,A->n,A->N,&A->cmap);CHKERRQ(ierr);
181
218 MatDestroy_Shell,
219 0,
220 MatGetPetscMaps_Petsc,
221 0,
222 0,
223 0,
224 0,
225 0,

--- 22 unchanged lines hidden (view full) ---

248 }
249
250 ierr = PetscSplitOwnership(A->comm,&A->m,&A->M);CHKERRQ(ierr);
251 ierr = PetscSplitOwnership(A->comm,&A->n,&A->N);CHKERRQ(ierr);
252
253 ierr = PetscMapCreateMPI(A->comm,A->m,A->M,&A->rmap);CHKERRQ(ierr);
254 ierr = PetscMapCreateMPI(A->comm,A->n,A->N,&A->cmap);CHKERRQ(ierr);
255
182 b->ctx = 0;
256 b->ctx = 0;
257 b->scale = PETSC_FALSE;
258 b->shift = PETSC_FALSE;
259 b->vshift = 0.0;
260 b->vscale = 1.0;
261 b->mult = 0;
183 A->assembled = PETSC_TRUE;
184 A->preallocated = PETSC_TRUE;
185 PetscFunctionReturn(0);
186}
187EXTERN_C_END
188
189#undef __FUNCT__
190#define __FUNCT__ "MatCreateShell"

--- 223 unchanged lines hidden ---
262 A->assembled = PETSC_TRUE;
263 A->preallocated = PETSC_TRUE;
264 PetscFunctionReturn(0);
265}
266EXTERN_C_END
267
268#undef __FUNCT__
269#define __FUNCT__ "MatCreateShell"

--- 223 unchanged lines hidden ---