Bug Summary

File:mat/impls/mffd/mffd.c
Warning:line 126, column 3
Value stored to 'ierr' is never read

Annotated Source Code

[?] Use j/k keys for keyboard navigation

1
2#include <petsc/private/matimpl.h>
3#include <../src/mat/impls/mffd/mffdimpl.h> /*I "petscmat.h" I*/
4
5PetscFunctionList MatMFFDList = 0;
6PetscBool MatMFFDRegisterAllCalled = PETSC_FALSE;
7
8PetscClassId MATMFFD_CLASSID;
9PetscLogEvent MATMFFD_Mult;
10
11static PetscBool MatMFFDPackageInitialized = PETSC_FALSE;
12/*@C
13 MatMFFDFinalizePackage - This function destroys everything in the MatMFFD package. It is
14 called from PetscFinalize().
15
16 Level: developer
17
18.seealso: PetscFinalize(), MatCreateMFFD(), MatCreateSNESMF()
19@*/
20PetscErrorCode MatMFFDFinalizePackage(void)
21{
22 PetscErrorCode ierr;
23
24 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 24; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
25 ierr = PetscFunctionListDestroy(&MatMFFDList);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),25,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
26 MatMFFDPackageInitialized = PETSC_FALSE;
27 MatMFFDRegisterAllCalled = PETSC_FALSE;
28 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
29}
30
31/*@C
32 MatMFFDInitializePackage - This function initializes everything in the MatMFFD package. It is called
33 from MatInitializePackage().
34
35 Level: developer
36
37.seealso: PetscInitialize()
38@*/
39PetscErrorCode MatMFFDInitializePackage(void)
40{
41 char logList[256];
42 PetscBool opt,pkg;
43 PetscErrorCode ierr;
44
45 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 45; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
46 if (MatMFFDPackageInitialized) PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
47 MatMFFDPackageInitialized = PETSC_TRUE;
48 /* Register Classes */
49 ierr = PetscClassIdRegister("MatMFFD",&MATMFFD_CLASSID);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),49,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
50 /* Register Constructors */
51 ierr = MatMFFDRegisterAll();CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),51,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
52 /* Register Events */
53 ierr = PetscLogEventRegister("MatMult MF",MATMFFD_CLASSID,&MATMFFD_Mult);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),53,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
54 /* Process info exclusions */
55 ierr = PetscOptionsGetString(NULL((void*)0),NULL((void*)0),"-info_exclude",logList,sizeof(logList),&opt);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),55,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
56 if (opt) {
57 ierr = PetscStrInList("matmffd",logList,',',&pkg);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),57,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
58 if (pkg) {ierr = PetscInfoDeactivateClass(MATMFFD_CLASSID);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),58,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;}
59 }
60 /* Process summary exclusions */
61 ierr = PetscOptionsGetString(NULL((void*)0),NULL((void*)0),"-log_exclude",logList,sizeof(logList),&opt);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),61,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
62 if (opt) {
63 ierr = PetscStrInList("matmffd",logList,',',&pkg);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),63,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
64 if (pkg) {ierr = PetscLogEventExcludeClass(MATMFFD_CLASSID);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),64,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;}
65 }
66 /* Register package finalizer */
67 ierr = PetscRegisterFinalize(MatMFFDFinalizePackage);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),67,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
68 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
69}
70
71static PetscErrorCode MatMFFDSetType_MFFD(Mat mat,MatMFFDType ftype)
72{
73 PetscErrorCode ierr,(*r)(MatMFFD);
74 MatMFFD ctx;
75 PetscBool match;
76
77 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 77; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
78 PetscValidHeaderSpecific(mat,MAT_CLASSID,1)do { if (!mat) return PetscError(((MPI_Comm)0x44000001),78,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(mat,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),
78,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(mat))->classid != MAT_CLASSID) { if
(((PetscObject)(mat))->classid == -1) return PetscError((
(MPI_Comm)0x44000001),78,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),78,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
79 PetscValidCharPointer(ftype,2)do { if (!ftype) return PetscError(((MPI_Comm)0x44000001),79,
__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,85,PETSC_ERROR_INITIAL,"Null Pointer: Parameter # %d",2); if
(!PetscCheckPointer(ftype,PETSC_CHAR)) return PetscError(((MPI_Comm
)0x44000001),79,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,68,PETSC_ERROR_INITIAL,"Invalid Pointer to char: Parameter # %d"
,2); } while (0)
;
80 ierr = MatShellGetContext(mat,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),80,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
81
82 /* already set, so just return */
83 ierr = PetscObjectTypeCompare((PetscObject)ctx,ftype,&match);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),83,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
84 if (match) PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
85
86 /* destroy the old one if it exists */
87 if (ctx->ops->destroy) {
88 ierr = (*ctx->ops->destroy)(ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),88,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
89 }
90
91 ierr = PetscFunctionListFind(MatMFFDList,ftype,&r)PetscFunctionListFind_Private((MatMFFDList),(ftype),(PetscVoidFunction
*)(&r))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),91,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
92 if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown MatMFFD type %s given",ftype)return PetscError(((MPI_Comm)0x44000001),92,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,86,PETSC_ERROR_INITIAL,"Unknown MatMFFD type %s given",ftype
)
;
93 ierr = (*r)(ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),93,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
94 ierr = PetscObjectChangeTypeName((PetscObject)ctx,ftype);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),94,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
95 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
96}
97
98/*@C
99 MatMFFDSetType - Sets the method that is used to compute the
100 differencing parameter for finite differene matrix-free formulations.
101
102 Input Parameters:
103+ mat - the "matrix-free" matrix created via MatCreateSNESMF(), or MatCreateMFFD()
104 or MatSetType(mat,MATMFFD);
105- ftype - the type requested, either MATMFFD_WP or MATMFFD_DS
106
107 Level: advanced
108
109 Notes:
110 For example, such routines can compute h for use in
111 Jacobian-vector products of the form
112
113 F(x+ha) - F(x)
114 F'(u)a ~= ----------------
115 h
116
117.seealso: MatCreateSNESMF(), MatMFFDRegister(), MatMFFDSetFunction(), MatCreateMFFD()
118@*/
119PetscErrorCode MatMFFDSetType(Mat mat,MatMFFDType ftype)
120{
121 PetscErrorCode ierr;
122
123 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 123; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
124 PetscValidHeaderSpecific(mat,MAT_CLASSID,1)do { if (!mat) return PetscError(((MPI_Comm)0x44000001),124,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(mat,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),
124,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(mat))->classid != MAT_CLASSID) { if
(((PetscObject)(mat))->classid == -1) return PetscError((
(MPI_Comm)0x44000001),124,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),124,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
125 PetscValidCharPointer(ftype,2)do { if (!ftype) return PetscError(((MPI_Comm)0x44000001),125
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,85,PETSC_ERROR_INITIAL,"Null Pointer: Parameter # %d",2); if
(!PetscCheckPointer(ftype,PETSC_CHAR)) return PetscError(((MPI_Comm
)0x44000001),125,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,68,PETSC_ERROR_INITIAL,"Invalid Pointer to char: Parameter # %d"
,2); } while (0)
;
126 ierr = PetscTryMethod(mat,"MatMFFDSetType_C",(Mat,MatMFFDType),(mat,ftype))0; do { PetscErrorCode (*_7_f)(Mat,MatMFFDType), _7_ierr; _7_ierr
= PetscObjectQueryFunction_Private(((PetscObject)(mat)),("MatMFFDSetType_C"
),(PetscVoidFunction*)(&_7_f));do {if (__builtin_expect(!
!(_7_ierr),0)) return PetscError(((MPI_Comm)0x44000001),126,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",_7_ierr
,PETSC_ERROR_REPEAT," ");} while (0); if (_7_f) {_7_ierr = (*
_7_f)(mat,ftype);do {if (__builtin_expect(!!(_7_ierr),0)) return
PetscError(((MPI_Comm)0x44000001),126,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0);} } while(0)
;
Value stored to 'ierr' is never read
127 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
128}
129
130static PetscErrorCode MatGetDiagonal_MFFD(Mat,Vec);
131
132typedef PetscErrorCode (*FCN1)(void*,Vec); /* force argument to next function to not be extern C*/
133static PetscErrorCode MatMFFDSetFunctioniBase_MFFD(Mat mat,FCN1 func)
134{
135 MatMFFD ctx;
136 PetscErrorCode ierr;
137
138 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 138; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
139 ierr = MatShellGetContext(mat,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),139,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
140 ctx->funcisetbase = func;
141 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
142}
143
144typedef PetscErrorCode (*FCN2)(void*,PetscInt,Vec,PetscScalar*); /* force argument to next function to not be extern C*/
145static PetscErrorCode MatMFFDSetFunctioni_MFFD(Mat mat,FCN2 funci)
146{
147 MatMFFD ctx;
148 PetscErrorCode ierr;
149
150 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 150; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
151 ierr = MatShellGetContext(mat,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),151,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
152 ctx->funci = funci;
153 ierr = MatShellSetOperation(mat,MATOP_GET_DIAGONAL,(void (*)(void))MatGetDiagonal_MFFD);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),153,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
154 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
155}
156
157static PetscErrorCode MatMFFDGetH_MFFD(Mat mat,PetscScalar *h)
158{
159 MatMFFD ctx;
160 PetscErrorCode ierr;
161
162 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 162; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
163 ierr = MatShellGetContext(mat,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),163,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
164 *h = ctx->currenth;
165 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
166}
167
168static PetscErrorCode MatMFFDResetHHistory_MFFD(Mat J)
169{
170 MatMFFD ctx;
171 PetscErrorCode ierr;
172
173 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 173; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
174 ierr = MatShellGetContext(J,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),174,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
175 ctx->ncurrenth = 0;
176 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
177}
178
179/*@C
180 MatMFFDRegister - Adds a method to the MatMFFD registry.
181
182 Not Collective
183
184 Input Parameters:
185+ name_solver - name of a new user-defined compute-h module
186- routine_create - routine to create method context
187
188 Level: developer
189
190 Notes:
191 MatMFFDRegister() may be called multiple times to add several user-defined solvers.
192
193 Sample usage:
194.vb
195 MatMFFDRegister("my_h",MyHCreate);
196.ve
197
198 Then, your solver can be chosen with the procedural interface via
199$ MatMFFDSetType(mfctx,"my_h")
200 or at runtime via the option
201$ -mat_mffd_type my_h
202
203.seealso: MatMFFDRegisterAll(), MatMFFDRegisterDestroy()
204 @*/
205PetscErrorCode MatMFFDRegister(const char sname[],PetscErrorCode (*function)(MatMFFD))
206{
207 PetscErrorCode ierr;
208
209 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 209; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
210 ierr = MatInitializePackage();CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),210,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
211 ierr = PetscFunctionListAdd(&MatMFFDList,sname,function)PetscFunctionListAdd_Private((&MatMFFDList),(sname),(PetscVoidFunction
)(function))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),211,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
212 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
213}
214
215/* ----------------------------------------------------------------------------------------*/
216static PetscErrorCode MatDestroy_MFFD(Mat mat)
217{
218 PetscErrorCode ierr;
219 MatMFFD ctx;
220
221 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 221; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
222 ierr = MatShellGetContext(mat,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),222,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
223 ierr = VecDestroy(&ctx->w);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),223,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
224 ierr = VecDestroy(&ctx->current_u);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),224,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
225 if (ctx->current_f_allocated) {
226 ierr = VecDestroy(&ctx->current_f);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),226,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
227 }
228 if (ctx->ops->destroy) {ierr = (*ctx->ops->destroy)(ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),228,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;}
229 ierr = PetscHeaderDestroy(&ctx)(PetscHeaderDestroy_Private((PetscObject)(*&ctx)) || ((*PetscTrFree
)((void*)(*&ctx),229,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
) || ((*&ctx) = 0,0)))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),229,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
230
231 ierr = PetscObjectComposeFunction((PetscObject)mat,"MatMFFDSetBase_C",NULL)PetscObjectComposeFunction_Private((PetscObject)mat,"MatMFFDSetBase_C"
,(PetscVoidFunction)(((void*)0)))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),231,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
232 ierr = PetscObjectComposeFunction((PetscObject)mat,"MatMFFDSetFunctioniBase_C",NULL)PetscObjectComposeFunction_Private((PetscObject)mat,"MatMFFDSetFunctioniBase_C"
,(PetscVoidFunction)(((void*)0)))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),232,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
233 ierr = PetscObjectComposeFunction((PetscObject)mat,"MatMFFDSetFunctioni_C",NULL)PetscObjectComposeFunction_Private((PetscObject)mat,"MatMFFDSetFunctioni_C"
,(PetscVoidFunction)(((void*)0)))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),233,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
234 ierr = PetscObjectComposeFunction((PetscObject)mat,"MatMFFDSetFunction_C",NULL)PetscObjectComposeFunction_Private((PetscObject)mat,"MatMFFDSetFunction_C"
,(PetscVoidFunction)(((void*)0)))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),234,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
235 ierr = PetscObjectComposeFunction((PetscObject)mat,"MatMFFDSetFunctionError_C",NULL)PetscObjectComposeFunction_Private((PetscObject)mat,"MatMFFDSetFunctionError_C"
,(PetscVoidFunction)(((void*)0)))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),235,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
236 ierr = PetscObjectComposeFunction((PetscObject)mat,"MatMFFDSetCheckh_C",NULL)PetscObjectComposeFunction_Private((PetscObject)mat,"MatMFFDSetCheckh_C"
,(PetscVoidFunction)(((void*)0)))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),236,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
237 ierr = PetscObjectComposeFunction((PetscObject)mat,"MatMFFDSetPeriod_C",NULL)PetscObjectComposeFunction_Private((PetscObject)mat,"MatMFFDSetPeriod_C"
,(PetscVoidFunction)(((void*)0)))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),237,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
238 ierr = PetscObjectComposeFunction((PetscObject)mat,"MatMFFDResetHHistory_C",NULL)PetscObjectComposeFunction_Private((PetscObject)mat,"MatMFFDResetHHistory_C"
,(PetscVoidFunction)(((void*)0)))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),238,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
239 ierr = PetscObjectComposeFunction((PetscObject)mat,"MatMFFDSetHHistory_C",NULL)PetscObjectComposeFunction_Private((PetscObject)mat,"MatMFFDSetHHistory_C"
,(PetscVoidFunction)(((void*)0)))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),239,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
240 ierr = PetscObjectComposeFunction((PetscObject)mat,"MatMFFDSetType_C",NULL)PetscObjectComposeFunction_Private((PetscObject)mat,"MatMFFDSetType_C"
,(PetscVoidFunction)(((void*)0)))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),240,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
241 ierr = PetscObjectComposeFunction((PetscObject)mat,"MatMFFDGetH_C",NULL)PetscObjectComposeFunction_Private((PetscObject)mat,"MatMFFDGetH_C"
,(PetscVoidFunction)(((void*)0)))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),241,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
242 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
243}
244
245/*
246 MatMFFDView_MFFD - Views matrix-free parameters.
247
248*/
249static PetscErrorCode MatView_MFFD(Mat J,PetscViewer viewer)
250{
251 PetscErrorCode ierr;
252 MatMFFD ctx;
253 PetscBool iascii, viewbase, viewfunction;
254 const char *prefix;
255
256 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 256; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
257 ierr = MatShellGetContext(J,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),257,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
258 ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII"ascii",&iascii);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),258,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
259 if (iascii) {
260 ierr = PetscViewerASCIIPrintf(viewer,"Matrix-free approximation:\n");CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),260,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
261 ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),261,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
262 ierr = PetscViewerASCIIPrintf(viewer,"err=%g (relative error in function evaluation)\n",(double)ctx->error_rel);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),262,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
263 if (!((PetscObject)ctx)->type_name) {
264 ierr = PetscViewerASCIIPrintf(viewer,"The compute h routine has not yet been set\n");CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),264,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
265 } else {
266 ierr = PetscViewerASCIIPrintf(viewer,"Using %s compute h routine\n",((PetscObject)ctx)->type_name);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),266,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
267 }
268#if defined(PETSC_USE_COMPLEX)
269 if (ctx->usecomplex) {
270 ierr = PetscViewerASCIIPrintf(viewer,"Using Lyness complex number trick to compute the matrix-vector product\n");CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),270,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
271 }
272#endif
273 if (ctx->ops->view) {
274 ierr = (*ctx->ops->view)(ctx,viewer);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),274,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
275 }
276 ierr = PetscObjectGetOptionsPrefix((PetscObject)J, &prefix);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),276,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
277
278 ierr = PetscOptionsHasName(((PetscObject)J)->options,prefix, "-mat_mffd_view_base", &viewbase);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),278,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
279 if (viewbase) {
280 ierr = PetscViewerASCIIPrintf(viewer, "Base:\n");CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),280,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
281 ierr = VecView(ctx->current_u, viewer);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),281,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
282 }
283 ierr = PetscOptionsHasName(((PetscObject)J)->options,prefix, "-mat_mffd_view_function", &viewfunction);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),283,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
284 if (viewfunction) {
285 ierr = PetscViewerASCIIPrintf(viewer, "Function:\n");CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),285,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
286 ierr = VecView(ctx->current_f, viewer);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),286,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
287 }
288 ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),288,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
289 }
290 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
291}
292
293/*
294 MatAssemblyEnd_MFFD - Resets the ctx->ncurrenth to zero. This
295 allows the user to indicate the beginning of a new linear solve by calling
296 MatAssemblyXXX() on the matrix free matrix. This then allows the
297 MatCreateMFFD_WP() to properly compute ||U|| only the first time
298 in the linear solver rather than every time.
299
300 This function is referenced directly from MatAssemblyEnd_SNESMF(), which may be in a different shared library hence
301 it must be labeled as PETSC_EXTERN
302*/
303PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode MatAssemblyEnd_MFFD(Mat J,MatAssemblyType mt)
304{
305 PetscErrorCode ierr;
306 MatMFFD j;
307
308 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 308; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
309 ierr = MatShellGetContext(J,&j);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),309,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
310 ierr = MatMFFDResetHHistory(J);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),310,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
311 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
312}
313
314/*
315 MatMult_MFFD - Default matrix-free form for Jacobian-vector product, y = F'(u)*a:
316
317 y ~= (F(u + ha) - F(u))/h,
318 where F = nonlinear function, as set by SNESSetFunction()
319 u = current iterate
320 h = difference interval
321*/
322static PetscErrorCode MatMult_MFFD(Mat mat,Vec a,Vec y)
323{
324 MatMFFD ctx;
325 PetscScalar h;
326 Vec w,U,F;
327 PetscErrorCode ierr;
328 PetscBool zeroa;
329
330 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 330; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
331 ierr = MatShellGetContext(mat,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),331,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
332 if (!ctx->current_u) SETERRQ(PetscObjectComm((PetscObject)mat),PETSC_ERR_ARG_WRONGSTATE,"MatMFFDSetBase() has not been called, this is often caused by forgetting to call \n\t\tMatAssemblyBegin/End on the first Mat in the SNES compute function")return PetscError(PetscObjectComm((PetscObject)mat),332,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",73
,PETSC_ERROR_INITIAL,"MatMFFDSetBase() has not been called, this is often caused by forgetting to call \n\t\tMatAssemblyBegin/End on the first Mat in the SNES compute function"
)
;
333 /* We log matrix-free matrix-vector products separately, so that we can
334 separate the performance monitoring from the cases that use conventional
335 storage. We may eventually modify event logging to associate events
336 with particular objects, hence alleviating the more general problem. */
337 ierr = PetscLogEventBegin(MATMFFD_Mult,a,y,0,0)(((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog
->curStage].perfInfo.active && petsc_stageLog->
stageInfo[petsc_stageLog->curStage].eventLog->eventInfo
[MATMFFD_Mult].active) ? (*PetscLogPLB)((MATMFFD_Mult),0,(PetscObject
)(a),(PetscObject)(y),(PetscObject)(0),(PetscObject)(0)) : 0 )
)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),337,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
338
339 w = ctx->w;
340 U = ctx->current_u;
341 F = ctx->current_f;
342 /*
343 Compute differencing parameter
344 */
345 if (!((PetscObject)ctx)->type_name) {
346 ierr = MatMFFDSetType(mat,MATMFFD_WP"wp");CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),346,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
347 ierr = MatSetFromOptions(mat);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),347,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
348 }
349 ierr = (*ctx->ops->compute)(ctx,U,a,&h,&zeroa);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),349,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
350 if (zeroa) {
351 ierr = VecSet(y,0.0);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),351,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
352 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
353 }
354
355 if (mat->erroriffailure && PetscIsInfOrNanScalar(h)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Computed Nan differencing parameter h")return PetscError(((MPI_Comm)0x44000001),355,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,77,PETSC_ERROR_INITIAL,"Computed Nan differencing parameter h"
)
;
356 if (ctx->checkh) {
357 ierr = (*ctx->checkh)(ctx->checkhctx,U,a,&h);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),357,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
358 }
359
360 /* keep a record of the current differencing parameter h */
361 ctx->currenth = h;
362#if defined(PETSC_USE_COMPLEX)
363 ierr = PetscInfo2(mat,"Current differencing parameter: %g + %g i\n",(double)PetscRealPart(h),(double)PetscImaginaryPart(h))PetscInfo_Private(__func__,mat,"Current differencing parameter: %g + %g i\n"
,(double)(h),(double)((PetscReal)0.))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),363,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
364#else
365 ierr = PetscInfo1(mat,"Current differencing parameter: %15.12e\n",h)PetscInfo_Private(__func__,mat,"Current differencing parameter: %15.12e\n"
,h)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),365,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
366#endif
367 if (ctx->historyh && ctx->ncurrenth < ctx->maxcurrenth) {
368 ctx->historyh[ctx->ncurrenth] = h;
369 }
370 ctx->ncurrenth++;
371
372#if defined(PETSC_USE_COMPLEX)
373 if (ctx->usecomplex) h = PETSC_i*h;
374#endif
375
376 /* w = u + ha */
377 ierr = VecWAXPY(w,h,a,U);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),377,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
378
379 /* compute func(U) as base for differencing; only needed first time in and not when provided by user */
380 if (ctx->ncurrenth == 1 && ctx->current_f_allocated) {
381 ierr = (*ctx->func)(ctx->funcctx,U,F);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),381,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
382 }
383 ierr = (*ctx->func)(ctx->funcctx,w,y);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),383,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
384
385#if defined(PETSC_USE_COMPLEX)
386 if (ctx->usecomplex) {
387 ierr = VecImaginaryPart(y);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),387,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
388 h = PetscImaginaryPart(h)((PetscReal)0.);
389 } else {
390 ierr = VecAXPY(y,-1.0,F);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),390,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
391 }
392#else
393 ierr = VecAXPY(y,-1.0,F);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),393,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
394#endif
395 ierr = VecScale(y,1.0/h);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),395,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
396 if (mat->nullsp) {ierr = MatNullSpaceRemove(mat->nullsp,y);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),396,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;}
397
398 ierr = PetscLogEventEnd(MATMFFD_Mult,a,y,0,0)(((PetscLogPLE && petsc_stageLog->stageInfo[petsc_stageLog
->curStage].perfInfo.active && petsc_stageLog->
stageInfo[petsc_stageLog->curStage].eventLog->eventInfo
[MATMFFD_Mult].active) ? (*PetscLogPLE)((MATMFFD_Mult),0,(PetscObject
)(a),(PetscObject)(y),(PetscObject)(0),(PetscObject)(0)) : 0 )
)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),398,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
399 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
400}
401
402/*
403 MatGetDiagonal_MFFD - Gets the diagonal for a matrix free matrix
404
405 y ~= (F(u + ha) - F(u))/h,
406 where F = nonlinear function, as set by SNESSetFunction()
407 u = current iterate
408 h = difference interval
409*/
410PetscErrorCode MatGetDiagonal_MFFD(Mat mat,Vec a)
411{
412 MatMFFD ctx;
413 PetscScalar h,*aa,*ww,v;
414 PetscReal epsilon = PETSC_SQRT_MACHINE_EPSILON1.490116119384766e-08,umin = 100.0*PETSC_SQRT_MACHINE_EPSILON1.490116119384766e-08;
415 Vec w,U;
416 PetscErrorCode ierr;
417 PetscInt i,rstart,rend;
418
419 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 419; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
420 ierr = MatShellGetContext(mat,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),420,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
421 if (!ctx->func) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Requires calling MatMFFDSetFunction() first")return PetscError(((MPI_Comm)0x44000001),421,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,73,PETSC_ERROR_INITIAL,"Requires calling MatMFFDSetFunction() first"
)
;
422 if (!ctx->funci) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Requires calling MatMFFDSetFunctioni() first")return PetscError(((MPI_Comm)0x44000001),422,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,73,PETSC_ERROR_INITIAL,"Requires calling MatMFFDSetFunctioni() first"
)
;
423 w = ctx->w;
424 U = ctx->current_u;
425 ierr = (*ctx->func)(ctx->funcctx,U,a);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),425,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
426 if (ctx->funcisetbase) {
427 ierr = (*ctx->funcisetbase)(ctx->funcctx,U);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),427,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
428 }
429 ierr = VecCopy(U,w);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),429,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
430
431 ierr = VecGetOwnershipRange(a,&rstart,&rend);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),431,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
432 ierr = VecGetArray(a,&aa);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),432,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
433 for (i=rstart; i<rend; i++) {
434 ierr = VecGetArray(w,&ww);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),434,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
435 h = ww[i-rstart];
436 if (h == 0.0) h = 1.0;
437 if (PetscAbsScalar(h) < umin && PetscRealPart(h)(h) >= 0.0) h = umin;
438 else if (PetscRealPart(h)(h) < 0.0 && PetscAbsScalar(h) < umin) h = -umin;
439 h *= epsilon;
440
441 ww[i-rstart] += h;
442 ierr = VecRestoreArray(w,&ww);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),442,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
443 ierr = (*ctx->funci)(ctx->funcctx,i,w,&v);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),443,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
444 aa[i-rstart] = (v - aa[i-rstart])/h;
445
446 ierr = VecGetArray(w,&ww);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),446,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
447 ww[i-rstart] -= h;
448 ierr = VecRestoreArray(w,&ww);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),448,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
449 }
450 ierr = VecRestoreArray(a,&aa);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),450,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
451 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
452}
453
454PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode MatMFFDSetBase_MFFD(Mat J,Vec U,Vec F)
455{
456 PetscErrorCode ierr;
457 MatMFFD ctx;
458
459 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 459; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
460 ierr = MatShellGetContext(J,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),460,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
461 ierr = MatMFFDResetHHistory(J);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),461,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
462 if (!ctx->current_u) {
463 ierr = VecDuplicate(U,&ctx->current_u);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),463,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
464 ierr = VecLockReadPush(ctx->current_u);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),464,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
465 }
466 ierr = VecLockReadPop(ctx->current_u);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),466,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
467 ierr = VecCopy(U,ctx->current_u);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),467,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
468 ierr = VecLockReadPush(ctx->current_u);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),468,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
469 if (F) {
470 if (ctx->current_f_allocated) {ierr = VecDestroy(&ctx->current_f);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),470,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;}
471 ctx->current_f = F;
472 ctx->current_f_allocated = PETSC_FALSE;
473 } else if (!ctx->current_f_allocated) {
474 ierr = MatCreateVecs(J,NULL((void*)0),&ctx->current_f);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),474,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
475
476 ctx->current_f_allocated = PETSC_TRUE;
477 }
478 if (!ctx->w) {
479 ierr = VecDuplicate(ctx->current_u,&ctx->w);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),479,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
480 }
481 J->assembled = PETSC_TRUE;
482 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
483}
484
485typedef PetscErrorCode (*FCN3)(void*,Vec,Vec,PetscScalar*); /* force argument to next function to not be extern C*/
486
487static PetscErrorCode MatMFFDSetCheckh_MFFD(Mat J,FCN3 fun,void *ectx)
488{
489 MatMFFD ctx;
490 PetscErrorCode ierr;
491
492 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 492; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
493 ierr = MatShellGetContext(J,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),493,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
494 ctx->checkh = fun;
495 ctx->checkhctx = ectx;
496 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
497}
498
499/*@C
500 MatMFFDSetOptionsPrefix - Sets the prefix used for searching for all
501 MatMFFD options in the database.
502
503 Collective on Mat
504
505 Input Parameter:
506+ A - the Mat context
507- prefix - the prefix to prepend to all option names
508
509 Notes:
510 A hyphen (-) must NOT be given at the beginning of the prefix name.
511 The first character of all runtime options is AUTOMATICALLY the hyphen.
512
513 Level: advanced
514
515.seealso: MatSetFromOptions(), MatCreateSNESMF(), MatCreateMFFD()
516@*/
517PetscErrorCode MatMFFDSetOptionsPrefix(Mat mat,const char prefix[])
518
519{
520 MatMFFD mfctx;
521 PetscErrorCode ierr;
522
523 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 523; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
524 PetscValidHeaderSpecific(mat,MAT_CLASSID,1)do { if (!mat) return PetscError(((MPI_Comm)0x44000001),524,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(mat,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),
524,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(mat))->classid != MAT_CLASSID) { if
(((PetscObject)(mat))->classid == -1) return PetscError((
(MPI_Comm)0x44000001),524,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),524,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
525 ierr = MatShellGetContext(mat,&mfctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),525,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
526 PetscValidHeaderSpecific(mfctx,MATMFFD_CLASSID,1)do { if (!mfctx) return PetscError(((MPI_Comm)0x44000001),526
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,85,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (
!PetscCheckPointer(mfctx,PETSC_OBJECT)) return PetscError(((MPI_Comm
)0x44000001),526,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(mfctx))->classid != MATMFFD_CLASSID
) { if (((PetscObject)(mfctx))->classid == -1) return PetscError
(((MPI_Comm)0x44000001),526,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),526,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
527 ierr = PetscObjectSetOptionsPrefix((PetscObject)mfctx,prefix);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),527,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
528 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
529}
530
531static PetscErrorCode MatSetFromOptions_MFFD(PetscOptionItems *PetscOptionsObject,Mat mat)
532{
533 MatMFFD mfctx;
534 PetscErrorCode ierr;
535 PetscBool flg;
536 char ftype[256];
537
538 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 538; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
539 PetscValidHeaderSpecific(mat,MAT_CLASSID,1)do { if (!mat) return PetscError(((MPI_Comm)0x44000001),539,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(mat,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),
539,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(mat))->classid != MAT_CLASSID) { if
(((PetscObject)(mat))->classid == -1) return PetscError((
(MPI_Comm)0x44000001),539,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),539,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
540 ierr = MatShellGetContext(mat,&mfctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),540,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
541 PetscValidHeaderSpecific(mfctx,MATMFFD_CLASSID,1)do { if (!mfctx) return PetscError(((MPI_Comm)0x44000001),541
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,85,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (
!PetscCheckPointer(mfctx,PETSC_OBJECT)) return PetscError(((MPI_Comm
)0x44000001),541,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(mfctx))->classid != MATMFFD_CLASSID
) { if (((PetscObject)(mfctx))->classid == -1) return PetscError
(((MPI_Comm)0x44000001),541,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),541,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
542 ierr = PetscObjectOptionsBegin((PetscObject)mfctx)0; do { PetscOptionItems PetscOptionsObjectBase; PetscOptionItems
*PetscOptionsObject = &PetscOptionsObjectBase; PetscOptionsObject
->options = ((PetscObject)(PetscObject)mfctx)->options;
for (PetscOptionsObject->count=(PetscOptionsPublish?-1:1)
; PetscOptionsObject->count<2; PetscOptionsObject->count
++) { PetscErrorCode _5_ierr = PetscObjectOptionsBegin_Private
(PetscOptionsObject,(PetscObject)mfctx);do {if (__builtin_expect
(!!(_5_ierr),0)) return PetscError(((MPI_Comm)0x44000001),542
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_5_ierr,PETSC_ERROR_REPEAT," ");} while (0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),542,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
543 ierr = PetscOptionsFList("-mat_mffd_type","Matrix free type","MatMFFDSetType",MatMFFDList,((PetscObject)mfctx)->type_name,ftype,256,&flg)PetscOptionsFList_Private(PetscOptionsObject,"-mat_mffd_type"
,"Matrix free type","MatMFFDSetType",MatMFFDList,((PetscObject
)mfctx)->type_name,ftype,256,&flg)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),543,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
544 if (flg) {
545 ierr = MatMFFDSetType(mat,ftype);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),545,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
546 }
547
548 ierr = PetscOptionsReal("-mat_mffd_err","set sqrt relative error in function","MatMFFDSetFunctionError",mfctx->error_rel,&mfctx->error_rel,0)PetscOptionsReal_Private(PetscOptionsObject,"-mat_mffd_err","set sqrt relative error in function"
,"MatMFFDSetFunctionError",mfctx->error_rel,&mfctx->
error_rel,0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),548,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
549 ierr = PetscOptionsInt("-mat_mffd_period","how often h is recomputed","MatMFFDSetPeriod",mfctx->recomputeperiod,&mfctx->recomputeperiod,0)PetscOptionsInt_Private(PetscOptionsObject,"-mat_mffd_period"
,"how often h is recomputed","MatMFFDSetPeriod",mfctx->recomputeperiod
,&mfctx->recomputeperiod,0,(-2147483647 - 1),2147483647
)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),549,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
550
551 flg = PETSC_FALSE;
552 ierr = PetscOptionsBool("-mat_mffd_check_positivity","Insure that U + h*a is nonnegative","MatMFFDSetCheckh",flg,&flg,NULL)PetscOptionsBool_Private(PetscOptionsObject,"-mat_mffd_check_positivity"
,"Insure that U + h*a is nonnegative","MatMFFDSetCheckh",flg,
&flg,((void*)0))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),552,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
553 if (flg) {
554 ierr = MatMFFDSetCheckh(mat,MatMFFDCheckPositivity,0);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),554,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
555 }
556#if defined(PETSC_USE_COMPLEX)
557 ierr = PetscOptionsBool("-mat_mffd_complex","Use Lyness complex number trick to compute the matrix-vector product","None",mfctx->usecomplex,&mfctx->usecomplex,NULL)PetscOptionsBool_Private(PetscOptionsObject,"-mat_mffd_complex"
,"Use Lyness complex number trick to compute the matrix-vector product"
,"None",mfctx->usecomplex,&mfctx->usecomplex,((void
*)0))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),557,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
558#endif
559 if (mfctx->ops->setfromoptions) {
560 ierr = (*mfctx->ops->setfromoptions)(PetscOptionsObject,mfctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),560,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
561 }
562 ierr = PetscOptionsEnd()_5_ierr = PetscOptionsEnd_Private(PetscOptionsObject);do {if (
__builtin_expect(!!(_5_ierr),0)) return PetscError(((MPI_Comm
)0x44000001),562,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_5_ierr,PETSC_ERROR_REPEAT," ");} while (0);}} while (0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),562,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
563 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
564}
565
566static PetscErrorCode MatMFFDSetPeriod_MFFD(Mat mat,PetscInt period)
567{
568 MatMFFD ctx;
569 PetscErrorCode ierr;
570
571 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 571; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
572 ierr = MatShellGetContext(mat,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),572,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
573 ctx->recomputeperiod = period;
574 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
575}
576
577static PetscErrorCode MatMFFDSetFunction_MFFD(Mat mat,PetscErrorCode (*func)(void*,Vec,Vec),void *funcctx)
578{
579 MatMFFD ctx;
580 PetscErrorCode ierr;
581
582 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 582; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
583 ierr = MatShellGetContext(mat,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),583,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
584 ctx->func = func;
585 ctx->funcctx = funcctx;
586 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
587}
588
589static PetscErrorCode MatMFFDSetFunctionError_MFFD(Mat mat,PetscReal error)
590{
591 MatMFFD ctx;
592 PetscErrorCode ierr;
593
594 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 594; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
595 ierr = MatShellGetContext(mat,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),595,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
596 if (error != PETSC_DEFAULT-2) ctx->error_rel = error;
597 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
598}
599
600PetscErrorCode MatMFFDSetHHistory_MFFD(Mat J,PetscScalar history[],PetscInt nhistory)
601{
602 MatMFFD ctx;
603 PetscErrorCode ierr;
604
605 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 605; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
606 ierr = MatShellGetContext(J,&ctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),606,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
607 ctx->historyh = history;
608 ctx->maxcurrenth = nhistory;
609 ctx->currenth = 0.;
610 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
611}
612
613/*MC
614 MATMFFD - MATMFFD = "mffd" - A matrix free matrix type.
615
616 Level: advanced
617
618 Developers Note: This is implemented on top of MATSHELL to get support for scaling and shifting without requiring duplicate code
619
620.seealso: MatCreateMFFD(), MatCreateSNESMF(), MatMFFDSetFunction(), MatMFFDSetType(),
621 MatMFFDSetFunctionError(), MatMFFDDSSetUmin(), MatMFFDSetFunction()
622 MatMFFDSetHHistory(), MatMFFDResetHHistory(), MatCreateSNESMF(),
623 MatMFFDGetH(),
624M*/
625PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode MatCreate_MFFD(Mat A)
626{
627 MatMFFD mfctx;
628 PetscErrorCode ierr;
629
630 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 630; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
631 ierr = MatMFFDInitializePackage();CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),631,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
632
633 ierr = PetscHeaderCreate(mfctx,MATMFFD_CLASSID,"MatMFFD","Matrix-free Finite Differencing","Mat",PetscObjectComm((PetscObject)A),NULL,NULL)(PetscMallocA(1,PETSC_TRUE,633,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,(size_t)(1)*sizeof(**((&(mfctx)))),((&(mfctx)))) || PetscHeaderCreate_Private
((PetscObject)mfctx,MATMFFD_CLASSID,"MatMFFD","Matrix-free Finite Differencing"
,"Mat",PetscObjectComm((PetscObject)A),(PetscObjectDestroyFunction
)((void*)0),(PetscObjectViewFunction)((void*)0)) || ((PetscLogPHC
) ? (*PetscLogPHC)((PetscObject)(mfctx)) : 0) || PetscLogObjectMemory
((PetscObject)mfctx,sizeof(*(mfctx))))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),633,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
634
635 mfctx->error_rel = PETSC_SQRT_MACHINE_EPSILON1.490116119384766e-08;
636 mfctx->recomputeperiod = 1;
637 mfctx->count = 0;
638 mfctx->currenth = 0.0;
639 mfctx->historyh = NULL((void*)0);
640 mfctx->ncurrenth = 0;
641 mfctx->maxcurrenth = 0;
642 ((PetscObject)mfctx)->type_name = 0;
643
644 /*
645 Create the empty data structure to contain compute-h routines.
646 These will be filled in below from the command line options or
647 a later call with MatMFFDSetType() or if that is not called
648 then it will default in the first use of MatMult_MFFD()
649 */
650 mfctx->ops->compute = 0;
651 mfctx->ops->destroy = 0;
652 mfctx->ops->view = 0;
653 mfctx->ops->setfromoptions = 0;
654 mfctx->hctx = 0;
655
656 mfctx->func = 0;
657 mfctx->funcctx = 0;
658 mfctx->w = NULL((void*)0);
659 mfctx->mat = A;
660
661 ierr = MatSetType(A,MATSHELL"shell");CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),661,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
662 ierr = MatShellSetContext(A,mfctx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),662,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
663 ierr = MatShellSetOperation(A,MATOP_MULT,(void (*)(void))MatMult_MFFD);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),663,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
664 ierr = MatShellSetOperation(A,MATOP_DESTROY,(void (*)(void))MatDestroy_MFFD);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),664,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
665 ierr = MatShellSetOperation(A,MATOP_VIEW,(void (*)(void))MatView_MFFD);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),665,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
666 ierr = MatShellSetOperation(A,MATOP_ASSEMBLY_END,(void (*)(void))MatAssemblyEnd_MFFD);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),666,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
667 ierr = MatShellSetOperation(A,MATOP_SET_FROM_OPTIONS,(void (*)(void))MatSetFromOptions_MFFD);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),667,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
668
669 ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetBase_C",MatMFFDSetBase_MFFD)PetscObjectComposeFunction_Private((PetscObject)A,"MatMFFDSetBase_C"
,(PetscVoidFunction)(MatMFFDSetBase_MFFD))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),669,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
670 ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetFunctioniBase_C",MatMFFDSetFunctioniBase_MFFD)PetscObjectComposeFunction_Private((PetscObject)A,"MatMFFDSetFunctioniBase_C"
,(PetscVoidFunction)(MatMFFDSetFunctioniBase_MFFD))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),670,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
671 ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetFunctioni_C",MatMFFDSetFunctioni_MFFD)PetscObjectComposeFunction_Private((PetscObject)A,"MatMFFDSetFunctioni_C"
,(PetscVoidFunction)(MatMFFDSetFunctioni_MFFD))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),671,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
672 ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetFunction_C",MatMFFDSetFunction_MFFD)PetscObjectComposeFunction_Private((PetscObject)A,"MatMFFDSetFunction_C"
,(PetscVoidFunction)(MatMFFDSetFunction_MFFD))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),672,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
673 ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetCheckh_C",MatMFFDSetCheckh_MFFD)PetscObjectComposeFunction_Private((PetscObject)A,"MatMFFDSetCheckh_C"
,(PetscVoidFunction)(MatMFFDSetCheckh_MFFD))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),673,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
674 ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetPeriod_C",MatMFFDSetPeriod_MFFD)PetscObjectComposeFunction_Private((PetscObject)A,"MatMFFDSetPeriod_C"
,(PetscVoidFunction)(MatMFFDSetPeriod_MFFD))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),674,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
675 ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetFunctionError_C",MatMFFDSetFunctionError_MFFD)PetscObjectComposeFunction_Private((PetscObject)A,"MatMFFDSetFunctionError_C"
,(PetscVoidFunction)(MatMFFDSetFunctionError_MFFD))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),675,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
676 ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDResetHHistory_C",MatMFFDResetHHistory_MFFD)PetscObjectComposeFunction_Private((PetscObject)A,"MatMFFDResetHHistory_C"
,(PetscVoidFunction)(MatMFFDResetHHistory_MFFD))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),676,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
677 ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetHHistory_C",MatMFFDSetHHistory_MFFD)PetscObjectComposeFunction_Private((PetscObject)A,"MatMFFDSetHHistory_C"
,(PetscVoidFunction)(MatMFFDSetHHistory_MFFD))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),677,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
678 ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetType_C",MatMFFDSetType_MFFD)PetscObjectComposeFunction_Private((PetscObject)A,"MatMFFDSetType_C"
,(PetscVoidFunction)(MatMFFDSetType_MFFD))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),678,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
679 ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDGetH_C",MatMFFDGetH_MFFD)PetscObjectComposeFunction_Private((PetscObject)A,"MatMFFDGetH_C"
,(PetscVoidFunction)(MatMFFDGetH_MFFD))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),679,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
680 ierr = PetscObjectChangeTypeName((PetscObject)A,MATMFFD"mffd");CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),680,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
681 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
682}
683
684/*@
685 MatCreateMFFD - Creates a matrix-free matrix. See also MatCreateSNESMF()
686
687 Collective on Vec
688
689 Input Parameters:
690+ comm - MPI communicator
691. m - number of local rows (or PETSC_DECIDE to have calculated if M is given)
692 This value should be the same as the local size used in creating the
693 y vector for the matrix-vector product y = Ax.
694. n - This value should be the same as the local size used in creating the
695 x vector for the matrix-vector product y = Ax. (or PETSC_DECIDE to have
696 calculated if N is given) For square matrices n is almost always m.
697. M - number of global rows (or PETSC_DETERMINE to have calculated if m is given)
698- N - number of global columns (or PETSC_DETERMINE to have calculated if n is given)
699
700
701 Output Parameter:
702. J - the matrix-free matrix
703
704 Options Database Keys: call MatSetFromOptions() to trigger these
705+ -mat_mffd_type - wp or ds (see MATMFFD_WP or MATMFFD_DS)
706. -mat_mffd_err - square root of estimated relative error in function evaluation
707. -mat_mffd_period - how often h is recomputed, defaults to 1, everytime
708. -mat_mffd_check_positivity - possibly decrease h until U + h*a has only positive values
709- -mat_mffd_complex - use the Lyness trick with complex numbers to compute the matrix-vector product instead of differencing
710 (requires real valued functions but that PETSc be configured for complex numbers)
711
712
713 Level: advanced
714
715 Notes:
716 The matrix-free matrix context merely contains the function pointers
717 and work space for performing finite difference approximations of
718 Jacobian-vector products, F'(u)*a,
719
720 The default code uses the following approach to compute h
721
722.vb
723 F'(u)*a = [F(u+h*a) - F(u)]/h where
724 h = error_rel*u'a/||a||^2 if |u'a| > umin*||a||_{1}
725 = error_rel*umin*sign(u'a)*||a||_{1}/||a||^2 otherwise
726 where
727 error_rel = square root of relative error in function evaluation
728 umin = minimum iterate parameter
729.ve
730
731 You can call SNESSetJacobian() with MatMFFDComputeJacobian() if you are using matrix and not a different
732 preconditioner matrix
733
734 The user can set the error_rel via MatMFFDSetFunctionError() and
735 umin via MatMFFDDSSetUmin(); see Users-Manual: ch_snes for details.
736
737 The user should call MatDestroy() when finished with the matrix-free
738 matrix context.
739
740 Options Database Keys:
741+ -mat_mffd_err <error_rel> - Sets error_rel
742. -mat_mffd_unim <umin> - Sets umin (for default PETSc routine that computes h only)
743- -mat_mffd_check_positivity
744
745.seealso: MatDestroy(), MatMFFDSetFunctionError(), MatMFFDDSSetUmin(), MatMFFDSetFunction()
746 MatMFFDSetHHistory(), MatMFFDResetHHistory(), MatCreateSNESMF(),
747 MatMFFDGetH(), MatMFFDRegister(), MatMFFDComputeJacobian()
748
749@*/
750PetscErrorCode MatCreateMFFD(MPI_Comm comm,PetscInt m,PetscInt n,PetscInt M,PetscInt N,Mat *J)
751{
752 PetscErrorCode ierr;
753
754 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 754; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
755 ierr = MatCreate(comm,J);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),755,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
756 ierr = MatSetSizes(*J,m,n,M,N);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),756,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
757 ierr = MatSetType(*J,MATMFFD"mffd");CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),757,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
758 ierr = MatSetUp(*J);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),758,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
759 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
760}
761
762/*@
763 MatMFFDGetH - Gets the last value that was used as the differencing
764 parameter.
765
766 Not Collective
767
768 Input Parameters:
769. mat - the matrix obtained with MatCreateSNESMF()
770
771 Output Paramter:
772. h - the differencing step size
773
774 Level: advanced
775
776.seealso: MatCreateSNESMF(),MatMFFDSetHHistory(), MatCreateMFFD(), MATMFFD, MatMFFDResetHHistory()
777@*/
778PetscErrorCode MatMFFDGetH(Mat mat,PetscScalar *h)
779{
780 PetscErrorCode ierr;
781
782 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 782; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
783 PetscValidHeaderSpecific(mat,MAT_CLASSID,1)do { if (!mat) return PetscError(((MPI_Comm)0x44000001),783,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(mat,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),
783,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(mat))->classid != MAT_CLASSID) { if
(((PetscObject)(mat))->classid == -1) return PetscError((
(MPI_Comm)0x44000001),783,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),783,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
784 PetscValidPointer(h,2)do { if (!h) return PetscError(((MPI_Comm)0x44000001),784,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Pointer: Parameter # %d",2); if (!
PetscCheckPointer(h,PETSC_CHAR)) return PetscError(((MPI_Comm
)0x44000001),784,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,68,PETSC_ERROR_INITIAL,"Invalid Pointer: Parameter # %d",2);
} while (0)
;
785 ierr = PetscUseMethod(mat,"MatMFFDGetH_C",(Mat,PetscScalar*),(mat,h))0; do { PetscErrorCode (*_7_f)(Mat,PetscScalar*), _7_ierr; _7_ierr
= PetscObjectQueryFunction_Private(((PetscObject)(mat)),("MatMFFDGetH_C"
),(PetscVoidFunction*)(&_7_f));do {if (__builtin_expect(!
!(_7_ierr),0)) return PetscError(((MPI_Comm)0x44000001),785,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",_7_ierr
,PETSC_ERROR_REPEAT," ");} while (0); if (_7_f) {_7_ierr = (*
_7_f)(mat,h);do {if (__builtin_expect(!!(_7_ierr),0)) return PetscError
(((MPI_Comm)0x44000001),785,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0);} else return PetscError
(PetscObjectComm((PetscObject)(mat)),785,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,56,PETSC_ERROR_INITIAL,"Cannot locate function %s in object"
,"MatMFFDGetH_C"); } while(0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),785,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
786 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
787}
788
789/*@C
790 MatMFFDSetFunction - Sets the function used in applying the matrix free.
791
792 Logically Collective on Mat
793
794 Input Parameters:
795+ mat - the matrix free matrix created via MatCreateSNESMF() or MatCreateMFFD()
796. func - the function to use
797- funcctx - optional function context passed to function
798
799 Calling Sequence of func:
800$ func (void *funcctx, Vec x, Vec f)
801
802+ funcctx - user provided context
803. x - input vector
804- f - computed output function
805
806 Level: advanced
807
808 Notes:
809 If you use this you MUST call MatAssemblyBegin()/MatAssemblyEnd() on the matrix free
810 matrix inside your compute Jacobian routine
811
812 If this is not set then it will use the function set with SNESSetFunction() if MatCreateSNESMF() was used.
813
814.seealso: MatCreateSNESMF(),MatMFFDGetH(), MatCreateMFFD(), MATMFFD,
815 MatMFFDSetHHistory(), MatMFFDResetHHistory(), SNESetFunction()
816@*/
817PetscErrorCode MatMFFDSetFunction(Mat mat,PetscErrorCode (*func)(void*,Vec,Vec),void *funcctx)
818{
819 PetscErrorCode ierr;
820
821 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 821; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
822 PetscValidHeaderSpecific(mat,MAT_CLASSID,1)do { if (!mat) return PetscError(((MPI_Comm)0x44000001),822,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(mat,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),
822,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(mat))->classid != MAT_CLASSID) { if
(((PetscObject)(mat))->classid == -1) return PetscError((
(MPI_Comm)0x44000001),822,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),822,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
823 ierr = PetscTryMethod(mat,"MatMFFDSetFunction_C",(Mat,PetscErrorCode (*)(void*,Vec,Vec),void*),(mat,func,funcctx))0; do { PetscErrorCode (*_7_f)(Mat,PetscErrorCode (*)(void*,Vec
,Vec),void*), _7_ierr; _7_ierr = PetscObjectQueryFunction_Private
(((PetscObject)(mat)),("MatMFFDSetFunction_C"),(PetscVoidFunction
*)(&_7_f));do {if (__builtin_expect(!!(_7_ierr),0)) return
PetscError(((MPI_Comm)0x44000001),823,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0); if (_7_f) {_7_ierr
= (*_7_f)(mat,func,funcctx);do {if (__builtin_expect(!!(_7_ierr
),0)) return PetscError(((MPI_Comm)0x44000001),823,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0);} } while(0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),823,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
824 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
825}
826
827/*@C
828 MatMFFDSetFunctioni - Sets the function for a single component
829
830 Logically Collective on Mat
831
832 Input Parameters:
833+ mat - the matrix free matrix created via MatCreateSNESMF()
834- funci - the function to use
835
836 Level: advanced
837
838 Notes:
839 If you use this you MUST call MatAssemblyBegin()/MatAssemblyEnd() on the matrix free
840 matrix inside your compute Jacobian routine.
841 This function is necessary to compute the diagonal of the matrix.
842 funci must not contain any MPI call as it is called inside a loop on the local portion of the vector.
843
844.seealso: MatCreateSNESMF(),MatMFFDGetH(), MatMFFDSetHHistory(), MatMFFDResetHHistory(), SNESetFunction(), MatGetDiagonal()
845
846@*/
847PetscErrorCode MatMFFDSetFunctioni(Mat mat,PetscErrorCode (*funci)(void*,PetscInt,Vec,PetscScalar*))
848{
849 PetscErrorCode ierr;
850
851 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 851; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
852 PetscValidHeaderSpecific(mat,MAT_CLASSID,1)do { if (!mat) return PetscError(((MPI_Comm)0x44000001),852,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(mat,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),
852,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(mat))->classid != MAT_CLASSID) { if
(((PetscObject)(mat))->classid == -1) return PetscError((
(MPI_Comm)0x44000001),852,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),852,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
853 ierr = PetscTryMethod(mat,"MatMFFDSetFunctioni_C",(Mat,PetscErrorCode (*)(void*,PetscInt,Vec,PetscScalar*)),(mat,funci))0; do { PetscErrorCode (*_7_f)(Mat,PetscErrorCode (*)(void*,PetscInt
,Vec,PetscScalar*)), _7_ierr; _7_ierr = PetscObjectQueryFunction_Private
(((PetscObject)(mat)),("MatMFFDSetFunctioni_C"),(PetscVoidFunction
*)(&_7_f));do {if (__builtin_expect(!!(_7_ierr),0)) return
PetscError(((MPI_Comm)0x44000001),853,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0); if (_7_f) {_7_ierr
= (*_7_f)(mat,funci);do {if (__builtin_expect(!!(_7_ierr),0)
) return PetscError(((MPI_Comm)0x44000001),853,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0);} } while(0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),853,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
854 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
855}
856
857/*@C
858 MatMFFDSetFunctioniBase - Sets the base vector for a single component function evaluation
859
860 Logically Collective on Mat
861
862 Input Parameters:
863+ mat - the matrix free matrix created via MatCreateSNESMF()
864- func - the function to use
865
866 Level: advanced
867
868 Notes:
869 If you use this you MUST call MatAssemblyBegin()/MatAssemblyEnd() on the matrix free
870 matrix inside your compute Jacobian routine.
871 This function is necessary to compute the diagonal of the matrix.
872
873
874.seealso: MatCreateSNESMF(),MatMFFDGetH(), MatCreateMFFD(), MATMFFD
875 MatMFFDSetHHistory(), MatMFFDResetHHistory(), SNESetFunction(), MatGetDiagonal()
876@*/
877PetscErrorCode MatMFFDSetFunctioniBase(Mat mat,PetscErrorCode (*func)(void*,Vec))
878{
879 PetscErrorCode ierr;
880
881 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 881; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
882 PetscValidHeaderSpecific(mat,MAT_CLASSID,1)do { if (!mat) return PetscError(((MPI_Comm)0x44000001),882,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(mat,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),
882,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(mat))->classid != MAT_CLASSID) { if
(((PetscObject)(mat))->classid == -1) return PetscError((
(MPI_Comm)0x44000001),882,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),882,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
883 ierr = PetscTryMethod(mat,"MatMFFDSetFunctioniBase_C",(Mat,PetscErrorCode (*)(void*,Vec)),(mat,func))0; do { PetscErrorCode (*_7_f)(Mat,PetscErrorCode (*)(void*,Vec
)), _7_ierr; _7_ierr = PetscObjectQueryFunction_Private(((PetscObject
)(mat)),("MatMFFDSetFunctioniBase_C"),(PetscVoidFunction*)(&
_7_f));do {if (__builtin_expect(!!(_7_ierr),0)) return PetscError
(((MPI_Comm)0x44000001),883,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0); if (_7_f) {_7_ierr
= (*_7_f)(mat,func);do {if (__builtin_expect(!!(_7_ierr),0))
return PetscError(((MPI_Comm)0x44000001),883,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0);} } while(0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),883,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
884 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
885}
886
887/*@
888 MatMFFDSetPeriod - Sets how often h is recomputed, by default it is everytime
889
890 Logically Collective on Mat
891
892 Input Parameters:
893+ mat - the matrix free matrix created via MatCreateSNESMF()
894- period - 1 for everytime, 2 for every second etc
895
896 Options Database Keys:
897. -mat_mffd_period <period>
898
899 Level: advanced
900
901
902.seealso: MatCreateSNESMF(),MatMFFDGetH(),
903 MatMFFDSetHHistory(), MatMFFDResetHHistory()
904@*/
905PetscErrorCode MatMFFDSetPeriod(Mat mat,PetscInt period)
906{
907 PetscErrorCode ierr;
908
909 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 909; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
910 PetscValidHeaderSpecific(mat,MAT_CLASSID,1)do { if (!mat) return PetscError(((MPI_Comm)0x44000001),910,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(mat,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),
910,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(mat))->classid != MAT_CLASSID) { if
(((PetscObject)(mat))->classid == -1) return PetscError((
(MPI_Comm)0x44000001),910,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),910,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
911 PetscValidLogicalCollectiveInt(mat,period,2)do { PetscErrorCode _7_ierr; PetscInt b1[2],b2[2]; b1[0] = -period
; b1[1] = period; _7_ierr = (PetscAllreduceBarrierCheck(PetscObjectComm
((PetscObject)mat),2,911,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
) || ((petsc_allreduce_ct += PetscMPIParallelComm((PetscObjectComm
((PetscObject)mat))),0) || MPI_Allreduce((b1),(b2),(2),(((MPI_Datatype
)0x4c000405)),((MPI_Op)(0x58000001)),(PetscObjectComm((PetscObject
)mat)))));do {if (__builtin_expect(!!(_7_ierr),0)) return PetscError
(((MPI_Comm)0x44000001),911,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0); if (-b2[0] != b2
[1]) return PetscError(PetscObjectComm((PetscObject)mat),911,
__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,62,PETSC_ERROR_INITIAL,"Int value must be same on all processes, argument # %d"
,2); } while (0)
;
912 ierr = PetscTryMethod(mat,"MatMFFDSetPeriod_C",(Mat,PetscInt),(mat,period))0; do { PetscErrorCode (*_7_f)(Mat,PetscInt), _7_ierr; _7_ierr
= PetscObjectQueryFunction_Private(((PetscObject)(mat)),("MatMFFDSetPeriod_C"
),(PetscVoidFunction*)(&_7_f));do {if (__builtin_expect(!
!(_7_ierr),0)) return PetscError(((MPI_Comm)0x44000001),912,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",_7_ierr
,PETSC_ERROR_REPEAT," ");} while (0); if (_7_f) {_7_ierr = (*
_7_f)(mat,period);do {if (__builtin_expect(!!(_7_ierr),0)) return
PetscError(((MPI_Comm)0x44000001),912,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0);} } while(0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),912,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
913 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
914}
915
916/*@
917 MatMFFDSetFunctionError - Sets the error_rel for the approximation of
918 matrix-vector products using finite differences.
919
920 Logically Collective on Mat
921
922 Input Parameters:
923+ mat - the matrix free matrix created via MatCreateMFFD() or MatCreateSNESMF()
924- error_rel - relative error (should be set to the square root of
925 the relative error in the function evaluations)
926
927 Options Database Keys:
928. -mat_mffd_err <error_rel> - Sets error_rel
929
930 Level: advanced
931
932 Notes:
933 The default matrix-free matrix-vector product routine computes
934.vb
935 F'(u)*a = [F(u+h*a) - F(u)]/h where
936 h = error_rel*u'a/||a||^2 if |u'a| > umin*||a||_{1}
937 = error_rel*umin*sign(u'a)*||a||_{1}/||a||^2 else
938.ve
939
940.seealso: MatCreateSNESMF(),MatMFFDGetH(), MatCreateMFFD(), MATMFFD
941 MatMFFDSetHHistory(), MatMFFDResetHHistory()
942@*/
943PetscErrorCode MatMFFDSetFunctionError(Mat mat,PetscReal error)
944{
945 PetscErrorCode ierr;
946
947 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 947; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
948 PetscValidHeaderSpecific(mat,MAT_CLASSID,1)do { if (!mat) return PetscError(((MPI_Comm)0x44000001),948,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(mat,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),
948,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(mat))->classid != MAT_CLASSID) { if
(((PetscObject)(mat))->classid == -1) return PetscError((
(MPI_Comm)0x44000001),948,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),948,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
949 PetscValidLogicalCollectiveReal(mat,error,2)do { PetscErrorCode _7_ierr; PetscReal b1[3],b2[3]; if (PetscIsNanReal
(error)) {b1[2] = 1;} else {b1[2] = 0;}; b1[0] = -error; b1[1
] = error; _7_ierr = ((petsc_allreduce_ct += PetscMPIParallelComm
((PetscObjectComm((PetscObject)mat))),0) || MPI_Allreduce((b1
),(b2),(3),(((MPI_Datatype)0x4c00080b)),((MPI_Op)(0x58000001)
),(PetscObjectComm((PetscObject)mat))));do {if (__builtin_expect
(!!(_7_ierr),0)) return PetscError(((MPI_Comm)0x44000001),949
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0); if (!(b2[2] >
0) && !PetscEqualReal(-b2[0],b2[1])) return PetscError
(PetscObjectComm((PetscObject)mat),949,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,62,PETSC_ERROR_INITIAL,"Real value must be same on all processes, argument # %d"
,2); } while (0)
;
950 ierr = PetscTryMethod(mat,"MatMFFDSetFunctionError_C",(Mat,PetscReal),(mat,error))0; do { PetscErrorCode (*_7_f)(Mat,PetscReal), _7_ierr; _7_ierr
= PetscObjectQueryFunction_Private(((PetscObject)(mat)),("MatMFFDSetFunctionError_C"
),(PetscVoidFunction*)(&_7_f));do {if (__builtin_expect(!
!(_7_ierr),0)) return PetscError(((MPI_Comm)0x44000001),950,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",_7_ierr
,PETSC_ERROR_REPEAT," ");} while (0); if (_7_f) {_7_ierr = (*
_7_f)(mat,error);do {if (__builtin_expect(!!(_7_ierr),0)) return
PetscError(((MPI_Comm)0x44000001),950,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0);} } while(0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),950,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
951 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
952}
953
954/*@
955 MatMFFDSetHHistory - Sets an array to collect a history of the
956 differencing values (h) computed for the matrix-free product.
957
958 Logically Collective on Mat
959
960 Input Parameters:
961+ J - the matrix-free matrix context
962. histroy - space to hold the history
963- nhistory - number of entries in history, if more entries are generated than
964 nhistory, then the later ones are discarded
965
966 Level: advanced
967
968 Notes:
969 Use MatMFFDResetHHistory() to reset the history counter and collect
970 a new batch of differencing parameters, h.
971
972.seealso: MatMFFDGetH(), MatCreateSNESMF(),
973 MatMFFDResetHHistory(), MatMFFDSetFunctionError()
974
975@*/
976PetscErrorCode MatMFFDSetHHistory(Mat J,PetscScalar history[],PetscInt nhistory)
977{
978 PetscErrorCode ierr;
979
980 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 980; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
981 PetscValidHeaderSpecific(J,MAT_CLASSID,1)do { if (!J) return PetscError(((MPI_Comm)0x44000001),981,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(J,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),981
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(J))->classid != MAT_CLASSID) { if (
((PetscObject)(J))->classid == -1) return PetscError(((MPI_Comm
)0x44000001),981,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),981,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
982 if (history) PetscValidPointer(history,2)do { if (!history) return PetscError(((MPI_Comm)0x44000001),982
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,85,PETSC_ERROR_INITIAL,"Null Pointer: Parameter # %d",2); if
(!PetscCheckPointer(history,PETSC_CHAR)) return PetscError((
(MPI_Comm)0x44000001),982,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,68,PETSC_ERROR_INITIAL,"Invalid Pointer: Parameter # %d",2);
} while (0)
;
983 PetscValidLogicalCollectiveInt(J,nhistory,3)do { PetscErrorCode _7_ierr; PetscInt b1[2],b2[2]; b1[0] = -nhistory
; b1[1] = nhistory; _7_ierr = (PetscAllreduceBarrierCheck(PetscObjectComm
((PetscObject)J),2,983,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
) || ((petsc_allreduce_ct += PetscMPIParallelComm((PetscObjectComm
((PetscObject)J))),0) || MPI_Allreduce((b1),(b2),(2),(((MPI_Datatype
)0x4c000405)),((MPI_Op)(0x58000001)),(PetscObjectComm((PetscObject
)J)))));do {if (__builtin_expect(!!(_7_ierr),0)) return PetscError
(((MPI_Comm)0x44000001),983,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0); if (-b2[0] != b2
[1]) return PetscError(PetscObjectComm((PetscObject)J),983,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Int value must be same on all processes, argument # %d"
,3); } while (0)
;
984 ierr = PetscUseMethod(J,"MatMFFDSetHHistory_C",(Mat,PetscScalar[],PetscInt),(J,history,nhistory))0; do { PetscErrorCode (*_7_f)(Mat,PetscScalar[],PetscInt), _7_ierr
; _7_ierr = PetscObjectQueryFunction_Private(((PetscObject)(J
)),("MatMFFDSetHHistory_C"),(PetscVoidFunction*)(&_7_f));
do {if (__builtin_expect(!!(_7_ierr),0)) return PetscError(((
MPI_Comm)0x44000001),984,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0); if (_7_f) {_7_ierr
= (*_7_f)(J,history,nhistory);do {if (__builtin_expect(!!(_7_ierr
),0)) return PetscError(((MPI_Comm)0x44000001),984,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0);} else return PetscError
(PetscObjectComm((PetscObject)(J)),984,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,56,PETSC_ERROR_INITIAL,"Cannot locate function %s in object"
,"MatMFFDSetHHistory_C"); } while(0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),984,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
985 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
986}
987
988/*@
989 MatMFFDResetHHistory - Resets the counter to zero to begin
990 collecting a new set of differencing histories.
991
992 Logically Collective on Mat
993
994 Input Parameters:
995. J - the matrix-free matrix context
996
997 Level: advanced
998
999 Notes:
1000 Use MatMFFDSetHHistory() to create the original history counter.
1001
1002.seealso: MatMFFDGetH(), MatCreateSNESMF(),
1003 MatMFFDSetHHistory(), MatMFFDSetFunctionError()
1004
1005@*/
1006PetscErrorCode MatMFFDResetHHistory(Mat J)
1007{
1008 PetscErrorCode ierr;
1009
1010 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 1010; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
1011 PetscValidHeaderSpecific(J,MAT_CLASSID,1)do { if (!J) return PetscError(((MPI_Comm)0x44000001),1011,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(J,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),1011
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(J))->classid != MAT_CLASSID) { if (
((PetscObject)(J))->classid == -1) return PetscError(((MPI_Comm
)0x44000001),1011,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),1011,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
1012 ierr = PetscTryMethod(J,"MatMFFDResetHHistory_C",(Mat),(J))0; do { PetscErrorCode (*_7_f)(Mat), _7_ierr; _7_ierr = PetscObjectQueryFunction_Private
(((PetscObject)(J)),("MatMFFDResetHHistory_C"),(PetscVoidFunction
*)(&_7_f));do {if (__builtin_expect(!!(_7_ierr),0)) return
PetscError(((MPI_Comm)0x44000001),1012,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0); if (_7_f) {_7_ierr
= (*_7_f)(J);do {if (__builtin_expect(!!(_7_ierr),0)) return
PetscError(((MPI_Comm)0x44000001),1012,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0);} } while(0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),1012,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
1013 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
1014}
1015
1016/*@
1017 MatMFFDSetBase - Sets the vector U at which matrix vector products of the
1018 Jacobian are computed
1019
1020 Logically Collective on Mat
1021
1022 Input Parameters:
1023+ J - the MatMFFD matrix
1024. U - the vector
1025- F - (optional) vector that contains F(u) if it has been already computed
1026
1027 Notes:
1028 This is rarely used directly
1029
1030 If F is provided then it is not recomputed. Otherwise the function is evaluated at the base
1031 point during the first MatMult() after each call to MatMFFDSetBase().
1032
1033 Level: advanced
1034
1035@*/
1036PetscErrorCode MatMFFDSetBase(Mat J,Vec U,Vec F)
1037{
1038 PetscErrorCode ierr;
1039
1040 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 1040; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
1041 PetscValidHeaderSpecific(J,MAT_CLASSID,1)do { if (!J) return PetscError(((MPI_Comm)0x44000001),1041,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(J,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),1041
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(J))->classid != MAT_CLASSID) { if (
((PetscObject)(J))->classid == -1) return PetscError(((MPI_Comm
)0x44000001),1041,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),1041,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
1042 PetscValidHeaderSpecific(U,VEC_CLASSID,2)do { if (!U) return PetscError(((MPI_Comm)0x44000001),1042,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",2); if (!PetscCheckPointer
(U,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),1042
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,2); if (((PetscObject)(U))->classid != VEC_CLASSID) { if (
((PetscObject)(U))->classid == -1) return PetscError(((MPI_Comm
)0x44000001),1042,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,2); else return PetscError(((MPI_Comm)0x44000001),1042,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",2
); } } while (0)
;
1043 if (F) PetscValidHeaderSpecific(F,VEC_CLASSID,3)do { if (!F) return PetscError(((MPI_Comm)0x44000001),1043,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",3); if (!PetscCheckPointer
(F,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),1043
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,3); if (((PetscObject)(F))->classid != VEC_CLASSID) { if (
((PetscObject)(F))->classid == -1) return PetscError(((MPI_Comm
)0x44000001),1043,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,3); else return PetscError(((MPI_Comm)0x44000001),1043,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",3
); } } while (0)
;
1044 ierr = PetscTryMethod(J,"MatMFFDSetBase_C",(Mat,Vec,Vec),(J,U,F))0; do { PetscErrorCode (*_7_f)(Mat,Vec,Vec), _7_ierr; _7_ierr
= PetscObjectQueryFunction_Private(((PetscObject)(J)),("MatMFFDSetBase_C"
),(PetscVoidFunction*)(&_7_f));do {if (__builtin_expect(!
!(_7_ierr),0)) return PetscError(((MPI_Comm)0x44000001),1044,
__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0); if (_7_f) {_7_ierr
= (*_7_f)(J,U,F);do {if (__builtin_expect(!!(_7_ierr),0)) return
PetscError(((MPI_Comm)0x44000001),1044,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0);} } while(0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),1044,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
1045 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
1046}
1047
1048/*@C
1049 MatMFFDSetCheckh - Sets a function that checks the computed h and adjusts
1050 it to satisfy some criteria
1051
1052 Logically Collective on Mat
1053
1054 Input Parameters:
1055+ J - the MatMFFD matrix
1056. fun - the function that checks h
1057- ctx - any context needed by the function
1058
1059 Options Database Keys:
1060. -mat_mffd_check_positivity
1061
1062 Level: advanced
1063
1064 Notes:
1065 For example, MatMFFDCheckPositivity() insures that all entries
1066 of U + h*a are non-negative
1067
1068 The function you provide is called after the default h has been computed and allows you to
1069 modify it.
1070
1071.seealso: MatMFFDCheckPositivity()
1072@*/
1073PetscErrorCode MatMFFDSetCheckh(Mat J,PetscErrorCode (*fun)(void*,Vec,Vec,PetscScalar*),void *ctx)
1074{
1075 PetscErrorCode ierr;
1076
1077 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 1077; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
1078 PetscValidHeaderSpecific(J,MAT_CLASSID,1)do { if (!J) return PetscError(((MPI_Comm)0x44000001),1078,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",1); if (!PetscCheckPointer
(J,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),1078
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,1); if (((PetscObject)(J))->classid != MAT_CLASSID) { if (
((PetscObject)(J))->classid == -1) return PetscError(((MPI_Comm
)0x44000001),1078,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,1); else return PetscError(((MPI_Comm)0x44000001),1078,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",1
); } } while (0)
;
1079 ierr = PetscTryMethod(J,"MatMFFDSetCheckh_C",(Mat,PetscErrorCode (*)(void*,Vec,Vec,PetscScalar*),void*),(J,fun,ctx))0; do { PetscErrorCode (*_7_f)(Mat,PetscErrorCode (*)(void*,Vec
,Vec,PetscScalar*),void*), _7_ierr; _7_ierr = PetscObjectQueryFunction_Private
(((PetscObject)(J)),("MatMFFDSetCheckh_C"),(PetscVoidFunction
*)(&_7_f));do {if (__builtin_expect(!!(_7_ierr),0)) return
PetscError(((MPI_Comm)0x44000001),1079,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0); if (_7_f) {_7_ierr
= (*_7_f)(J,fun,ctx);do {if (__builtin_expect(!!(_7_ierr),0)
) return PetscError(((MPI_Comm)0x44000001),1079,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,_7_ierr,PETSC_ERROR_REPEAT," ");} while (0);} } while(0)
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),1079,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
1080 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
1081}
1082
1083/*@
1084 MatMFFDCheckPositivity - Checks that all entries in U + h*a are positive or
1085 zero, decreases h until this is satisfied.
1086
1087 Logically Collective on Vec
1088
1089 Input Parameters:
1090+ U - base vector that is added to
1091. a - vector that is added
1092. h - scaling factor on a
1093- dummy - context variable (unused)
1094
1095 Options Database Keys:
1096. -mat_mffd_check_positivity
1097
1098 Level: advanced
1099
1100 Notes:
1101 This is rarely used directly, rather it is passed as an argument to
1102 MatMFFDSetCheckh()
1103
1104.seealso: MatMFFDSetCheckh()
1105@*/
1106PetscErrorCode MatMFFDCheckPositivity(void *dummy,Vec U,Vec a,PetscScalar *h)
1107{
1108 PetscReal val, minval;
1109 PetscScalar *u_vec, *a_vec;
1110 PetscErrorCode ierr;
1111 PetscInt i,n;
1112 MPI_Comm comm;
1113
1114 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c";
petscstack->line[petscstack->currentsize] = 1114; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
1115 PetscValidHeaderSpecific(U,VEC_CLASSID,2)do { if (!U) return PetscError(((MPI_Comm)0x44000001),1115,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",2); if (!PetscCheckPointer
(U,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),1115
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,2); if (((PetscObject)(U))->classid != VEC_CLASSID) { if (
((PetscObject)(U))->classid == -1) return PetscError(((MPI_Comm
)0x44000001),1115,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,2); else return PetscError(((MPI_Comm)0x44000001),1115,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",2
); } } while (0)
;
1116 PetscValidHeaderSpecific(a,VEC_CLASSID,3)do { if (!a) return PetscError(((MPI_Comm)0x44000001),1116,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Object: Parameter # %d",3); if (!PetscCheckPointer
(a,PETSC_OBJECT)) return PetscError(((MPI_Comm)0x44000001),1116
,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Invalid Pointer to Object: Parameter # %d"
,3); if (((PetscObject)(a))->classid != VEC_CLASSID) { if (
((PetscObject)(a))->classid == -1) return PetscError(((MPI_Comm
)0x44000001),1116,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,64,PETSC_ERROR_INITIAL,"Object already free: Parameter # %d"
,3); else return PetscError(((MPI_Comm)0x44000001),1116,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",62
,PETSC_ERROR_INITIAL,"Wrong type of object: Parameter # %d",3
); } } while (0)
;
1117 PetscValidPointer(h,4)do { if (!h) return PetscError(((MPI_Comm)0x44000001),1117,__func__
,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c",85
,PETSC_ERROR_INITIAL,"Null Pointer: Parameter # %d",4); if (!
PetscCheckPointer(h,PETSC_CHAR)) return PetscError(((MPI_Comm
)0x44000001),1117,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,68,PETSC_ERROR_INITIAL,"Invalid Pointer: Parameter # %d",4);
} while (0)
;
1118 ierr = PetscObjectGetComm((PetscObject)U,&comm);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),1118,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
1119 ierr = VecGetArray(U,&u_vec);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),1119,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
1120 ierr = VecGetArray(a,&a_vec);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),1120,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
1121 ierr = VecGetLocalSize(U,&n);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),1121,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
1122 minval = PetscAbsScalar(*h)*PetscRealConstant(1.01)1.01;
1123 for (i=0; i<n; i++) {
1124 if (PetscRealPart(u_vec[i] + *h*a_vec[i])(u_vec[i] + *h*a_vec[i]) <= 0.0) {
1125 val = PetscAbsScalar(u_vec[i]/a_vec[i]);
1126 if (val < minval) minval = val;
1127 }
1128 }
1129 ierr = VecRestoreArray(U,&u_vec);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),1129,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
1130 ierr = VecRestoreArray(a,&a_vec);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),1130,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
1131 ierr = MPIU_Allreduce(&minval,&val,1,MPIU_REAL,MPIU_MIN,comm)(PetscAllreduceBarrierCheck(comm,1,1131,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
) || ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) ||
MPI_Allreduce((&minval),(&val),(1),(((MPI_Datatype)0x4c00080b
)),((MPI_Op)(0x58000002)),(comm))))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),1131,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
1132 if (val <= PetscAbsScalar(*h)) {
1133 ierr = PetscInfo2(U,"Scaling back h from %g to %g\n",(double)PetscRealPart(*h),(double)(.99*val))PetscInfo_Private(__func__,U,"Scaling back h from %g to %g\n"
,(double)(*h),(double)(.99*val))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),1133,__func__,"/sandbox/petsc/petsc.next-tmp/src/mat/impls/mffd/mffd.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
1134 if (PetscRealPart(*h)(*h) > 0.0) *h = 0.99*val;
1135 else *h = -0.99*val;
1136 }
1137 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
1138}