Actual source code: const.c
1: /*$Id: const.c,v 1.20 2001/08/07 03:05:08 balay Exp $*/
2: #include src/pf/pfimpl.h
4: #undef __FUNCT__
6: int PFApply_Constant(void *value,int n,PetscScalar *x,PetscScalar *y)
7: {
8: int i;
9: PetscScalar v = ((PetscScalar*)value)[0];
12: n *= (int) PetscRealPart(((PetscScalar*)value)[1]);
13: for (i=0; i<n; i++) {
14: y[i] = v;
15: }
16: return(0);
17: }
19: #undef __FUNCT__
21: int PFApplyVec_Constant(void *value,Vec x,Vec y)
22: {
25: VecSet((PetscScalar*)value,y);
26: return(0);
27: }
28: #undef __FUNCT__
30: int PFView_Constant(void *value,PetscViewer viewer)
31: {
32: int ierr;
33: PetscTruth isascii;
36: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&isascii);
37: if (isascii) {
38: #if !defined(PETSC_USE_COMPLEX)
39: PetscViewerASCIIPrintf(viewer,"Constant = %gn",*(double*)value);
40: #else
41: PetscViewerASCIIPrintf(viewer,"Constant = %g + %gin",PetscRealPart(*(PetscScalar*)value),PetscImaginaryPart(*(PetscScalar*)value));
42: #endif
43: }
44: return(0);
45: }
46: #undef __FUNCT__
48: int PFDestroy_Constant(void *value)
49: {
52: PetscFree(value);
53: return(0);
54: }
56: #undef __FUNCT__
58: int PFSetFromOptions_Constant(PF pf)
59: {
60: int ierr;
61: PetscScalar *value = (PetscScalar *)pf->data;
64: PetscOptionsHead("Constant function options");
65: PetscOptionsScalar("-pf_constant","The constant value","None",*value,value,0);
66: PetscOptionsTail();
67: return(0);
68: }
70: EXTERN_C_BEGIN
71: #undef __FUNCT__
73: int PFCreate_Constant(PF pf,void *value)
74: {
75: int ierr;
76: PetscScalar *loc;
79: PetscMalloc(2*sizeof(PetscScalar),&loc);
80: if (value) loc[0] = *(PetscScalar*)value; else loc[0] = 0.0;
81: loc[1] = pf->dimout;
82: ierr = PFSet(pf,PFApply_Constant,PFApplyVec_Constant,PFView_Constant,PFDestroy_Constant,loc);
84: pf->ops->setfromoptions = PFSetFromOptions_Constant;
85: return(0);
86: }
87: EXTERN_C_END
89: EXTERN_C_BEGIN
90: #undef __FUNCT__
92: int PFCreate_Quick(PF pf,void *function)
93: {
94: int ierr;
98: PFSet(pf,(int (*)(void*,int,PetscScalar*,PetscScalar*))function,0,0,0,0);
99: return(0);
100: }
101: EXTERN_C_END
103: /* -------------------------------------------------------------------------------------------------------------------*/
104: #undef __FUNCT__
106: int PFApply_Identity(void *value,int n,PetscScalar *x,PetscScalar *y)
107: {
108: int i;
111: n *= *(int*)value;
112: for (i=0; i<n; i++) {
113: y[i] = x[i];
114: }
115: return(0);
116: }
118: #undef __FUNCT__
120: int PFApplyVec_Identity(void *value,Vec x,Vec y)
121: {
124: VecCopy(x,y);
125: return(0);
126: }
127: #undef __FUNCT__
129: int PFView_Identity(void *value,PetscViewer viewer)
130: {
131: int ierr;
132: PetscTruth isascii;
135: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&isascii);
136: if (isascii) {
137: PetscViewerASCIIPrintf(viewer,"Identity functionn");
138: }
139: return(0);
140: }
141: #undef __FUNCT__
143: int PFDestroy_Identity(void *value)
144: {
147: PetscFree(value);
148: return(0);
149: }
151: EXTERN_C_BEGIN
152: #undef __FUNCT__
154: int PFCreate_Identity(PF pf,void *value)
155: {
156: int ierr,*loc;
159: if (pf->dimout != pf->dimin) {
160: SETERRQ2(1,"Input dimension must match output dimension for Identity function, dimin = %d dimout = %dn",pf->dimin,pf->dimout);
161: }
162: PetscMalloc(sizeof(int),&loc);
163: loc[0] = pf->dimout;
164: ierr = PFSet(pf,PFApply_Identity,PFApplyVec_Identity,PFView_Identity,PFDestroy_Identity,loc);
165: return(0);
166: }
167: EXTERN_C_END