xref: /petsc/src/tao/interface/ftn-custom/ztaosolverf.c (revision ccb4e88a40f0b86eaeca07ff64c64e4de2fae686)
1 #include <petsc/private/fortranimpl.h>
2 #include <petsc/private/f90impl.h>
3 #include <petsc/private/taoimpl.h>
4 
5 #if defined(PETSC_HAVE_FORTRAN_CAPS)
6 #define taosetobjectiveroutine_             TAOSETOBJECTIVEROUTINE
7 #define taosetgradientroutine_              TAOSETGRADIENTROUTINE
8 #define taosetobjectiveandgradientroutine_  TAOSETOBJECTIVEANDGRADIENTROUTINE
9 #define taosethessianroutine_               TAOSETHESSIANROUTINE
10 #define taosetresidualroutine_              TAOSETRESIDUALROUTINE
11 #define taosetjacobianresidualroutine_      TAOSETJACOBIANRESIDUALROUTINE
12 #define taosetjacobianroutine_              TAOSETJACOBIANROUTINE
13 #define taosetjacobianstateroutine_         TAOSETJACOBIANSTATEROUTINE
14 #define taosetjacobiandesignroutine_        TAOSETJACOBIANDESIGNROUTINE
15 #define taosetjacobianinequalityroutine_    TAOSETJACOBIANINEQUALITYROUTINE
16 #define taosetjacobianequalityroutine_      TAOSETJACOBIANEQUALITYROUTINE
17 #define taosetinequalityconstraintsroutine_ TAOSETINEQUALITYCONSTRAINTSROUTINE
18 #define taosetequalityconstraintsroutine_   TAOSETEQUALITYCONSTRAINTSROUTINE
19 #define taosetvariableboundsroutine_        TAOSETVARIABLEBOUNDSROUTINE
20 #define taosetconstraintsroutine_           TAOSETCONSTRAINTSROUTINE
21 #define taosetmonitor_                      TAOSETMONITOR
22 #define taosettype_                         TAOSETTYPE
23 #define taoview_                            TAOVIEW
24 #define taogetconvergencehistory_           TAOGETCONVERGENCEHISTORY
25 #define taosetconvergencetest_              TAOSETCONVERGENCETEST
26 #define taogetoptionsprefix_                TAOGETOPTIONSPREFIX
27 #define taosetoptionsprefix_                TAOSETOPTIONSPREFIX
28 #define taoappendoptionsprefix_             TAOAPPENDOPTIONSPREFIX
29 #define taogettype_                         TAOGETTYPE
30 #define taosetupdate_                       TAOSETUPDATE
31 #define taoviewfromoptions_                 TAOVIEWFROMOPTIONS
32 #define taodestroy_                         TAODESTROY
33 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
34 
35 #define taosetobjectiveroutine_             taosetobjectiveroutine
36 #define taosetgradientroutine_              taosetgradientroutine
37 #define taosetobjectiveandgradientroutine_  taosetobjectiveandgradientroutine
38 #define taosethessianroutine_               taosethessianroutine
39 #define taosetresidualroutine_              taosetresidualroutine
40 #define taosetjacobianresidualroutine_      taosetjacobianresidualroutine
41 #define taosetjacobianroutine_              taosetjacobianroutine
42 #define taosetjacobianstateroutine_         taosetjacobianstateroutine
43 #define taosetjacobiandesignroutine_        taosetjacobiandesignroutine
44 #define taosetjacobianinequalityroutine_    taosetjacobianinequalityroutine
45 #define taosetjacobianequalityroutine_      taosetjacobianequalityroutine
46 #define taosetinequalityconstraintsroutine_ taosetinequalityconstraintsroutine
47 #define taosetequalityconstraintsroutine_   taosetequalityconstraintsroutine
48 #define taosetvariableboundsroutine_        taosetvariableboundsroutine
49 #define taosetconstraintsroutine_           taosetconstraintsroutine
50 #define taosetmonitor_                      taosetmonitor
51 #define taosettype_                         taosettype
52 #define taoview_                            taoview
53 #define taogetconvergencehistory_           taogetconvergencehistory
54 #define taosetconvergencetest_              taosetconvergencetest
55 #define taogetoptionsprefix_                taogetoptionsprefix
56 #define taosetoptionsprefix_                taosetoptionsprefix
57 #define taoappendoptionsprefix_             taoappendoptionsprefix
58 #define taogettype_                         taogettype
59 #define taosetupdate_                       taosetupdate
60 #define taoviewfromoptions_                 taoviewfromoptions
61 #define taodestroy_                         taodestroy
62 #endif
63 
64 static struct {
65   PetscFortranCallbackId obj;
66   PetscFortranCallbackId grad;
67   PetscFortranCallbackId objgrad;
68   PetscFortranCallbackId hess;
69   PetscFortranCallbackId lsres;
70   PetscFortranCallbackId lsjac;
71   PetscFortranCallbackId jac;
72   PetscFortranCallbackId jacstate;
73   PetscFortranCallbackId jacdesign;
74   PetscFortranCallbackId bounds;
75   PetscFortranCallbackId mon;
76   PetscFortranCallbackId mondestroy;
77   PetscFortranCallbackId convtest;
78   PetscFortranCallbackId constraints;
79   PetscFortranCallbackId jacineq;
80   PetscFortranCallbackId jaceq;
81   PetscFortranCallbackId conineq;
82   PetscFortranCallbackId coneq;
83   PetscFortranCallbackId nfuncs;
84   PetscFortranCallbackId update;
85 #if defined(PETSC_HAVE_F90_2PTR_ARG)
86   PetscFortranCallbackId function_pgiptr;
87 #endif
88 } _cb;
89 
90 static PetscErrorCode ourtaoobjectiveroutine(Tao tao, Vec x, PetscReal *f, void *ctx)
91 {
92     PetscObjectUseFortranCallback(tao,_cb.obj,(Tao*,Vec*,PetscReal*,void*,PetscErrorCode*),(&tao,&x,f,_ctx,&ierr));
93 }
94 
95 static PetscErrorCode ourtaogradientroutine(Tao tao, Vec x, Vec g, void *ctx)
96 {
97     PetscObjectUseFortranCallback(tao,_cb.grad,(Tao*,Vec*,Vec*,void*,PetscErrorCode*),(&tao,&x,&g,_ctx,&ierr));
98 }
99 
100 static PetscErrorCode ourtaoobjectiveandgradientroutine(Tao tao, Vec x, PetscReal *f, Vec g, void* ctx)
101 {
102     PetscObjectUseFortranCallback(tao,_cb.objgrad,(Tao*,Vec*,PetscReal*,Vec*,void*,PetscErrorCode*),(&tao,&x,f,&g,_ctx,&ierr));
103 }
104 
105 static PetscErrorCode ourtaohessianroutine(Tao tao, Vec x, Mat H, Mat Hpre, void *ctx)
106 {
107     PetscObjectUseFortranCallback(tao,_cb.hess,(Tao*,Vec*,Mat*,Mat*,void*,PetscErrorCode*),(&tao,&x,&H,&Hpre,_ctx,&ierr));
108 }
109 
110 static PetscErrorCode ourtaojacobianroutine(Tao tao, Vec x, Mat H, Mat Hpre, void *ctx)
111 {
112     PetscObjectUseFortranCallback(tao,_cb.jac,(Tao*,Vec*,Mat*,Mat*,void*,PetscErrorCode*),(&tao,&x,&H,&Hpre,_ctx,&ierr));
113 }
114 
115 static PetscErrorCode ourtaojacobianstateroutine(Tao tao, Vec x, Mat H, Mat Hpre, Mat Hinv, void *ctx)
116 {
117     PetscObjectUseFortranCallback(tao,_cb.jacstate,(Tao*,Vec*,Mat*,Mat*,Mat*,void*,PetscErrorCode*),(&tao,&x,&H,&Hpre,&Hinv,_ctx,&ierr));
118 }
119 
120 static PetscErrorCode ourtaojacobiandesignroutine(Tao tao, Vec x, Mat H, void *ctx)
121 {
122     PetscObjectUseFortranCallback(tao,_cb.jacdesign,(Tao*,Vec*,Mat*,void*,PetscErrorCode*),(&tao,&x,&H,_ctx,&ierr));
123 }
124 
125 static PetscErrorCode ourtaoboundsroutine(Tao tao, Vec xl, Vec xu, void *ctx)
126 {
127     PetscObjectUseFortranCallback(tao,_cb.bounds,(Tao*,Vec*,Vec*,void*,PetscErrorCode*),(&tao,&xl,&xu,_ctx,&ierr));
128 }
129 static PetscErrorCode ourtaoresidualroutine(Tao tao, Vec x, Vec f, void *ctx)
130 {
131     PetscObjectUseFortranCallback(tao,_cb.lsres,(Tao*,Vec*,Vec*,void*,PetscErrorCode*),(&tao,&x,&f,_ctx,&ierr));
132 }
133 
134 static PetscErrorCode ourtaojacobianresidualroutine(Tao tao, Vec x, Mat J, Mat Jpre, void *ctx)
135 {
136     PetscObjectUseFortranCallback(tao,_cb.lsjac,(Tao*,Vec*,Mat*,Mat*,void*,PetscErrorCode*),(&tao,&x,&J,&Jpre,_ctx,&ierr));
137 }
138 
139 static PetscErrorCode ourtaomonitor(Tao tao, void *ctx)
140 {
141     PetscObjectUseFortranCallback(tao,_cb.mon,(Tao *,void*,PetscErrorCode*),(&tao,_ctx,&ierr));
142 }
143 
144 static PetscErrorCode ourtaomondestroy(void **ctx)
145 {
146     Tao tao = (Tao)*ctx;
147     PetscObjectUseFortranCallback(tao,_cb.mondestroy,(void*,PetscErrorCode*),(_ctx,&ierr));
148 }
149 static PetscErrorCode ourtaoconvergencetest(Tao tao, void *ctx)
150 {
151     PetscObjectUseFortranCallback(tao,_cb.convtest,(Tao *,void*,PetscErrorCode*),(&tao,_ctx,&ierr));
152 }
153 
154 static PetscErrorCode ourtaoconstraintsroutine(Tao tao, Vec x, Vec c, void *ctx)
155 {
156     PetscObjectUseFortranCallback(tao,_cb.constraints,(Tao*,Vec*,Vec*,void*,PetscErrorCode*),(&tao,&x,&c,_ctx,&ierr));
157 }
158 
159 static PetscErrorCode ourtaojacobianinequalityroutine(Tao tao, Vec x, Mat J, Mat Jpre, void *ctx)
160 {
161     PetscObjectUseFortranCallback(tao,_cb.jacineq,(Tao*,Vec*,Mat*,Mat*,void*,PetscErrorCode*),(&tao,&x,&J,&Jpre,_ctx,&ierr));
162 }
163 
164 static PetscErrorCode ourtaojacobianequalityroutine(Tao tao, Vec x, Mat J, Mat Jpre, void *ctx)
165 {
166     PetscObjectUseFortranCallback(tao,_cb.jaceq,(Tao*,Vec*,Mat*,Mat*,void*,PetscErrorCode*),(&tao,&x,&J,&Jpre,_ctx,&ierr));
167 }
168 
169 static PetscErrorCode ourtaoinequalityconstraintsroutine(Tao tao, Vec x, Vec c, void *ctx)
170 {
171     PetscObjectUseFortranCallback(tao,_cb.conineq,(Tao*,Vec*,Vec*,void*,PetscErrorCode*),(&tao,&x,&c,_ctx,&ierr));
172 }
173 
174 static PetscErrorCode ourtaoequalityconstraintsroutine(Tao tao, Vec x, Vec c, void *ctx)
175 {
176     PetscObjectUseFortranCallback(tao,_cb.coneq,(Tao*,Vec*,Vec*,void*,PetscErrorCode*),(&tao,&x,&c,_ctx,&ierr));
177 }
178 
179 static PetscErrorCode ourtaoupdateroutine(Tao tao, PetscInt iter, void *ctx)
180 {
181     PetscObjectUseFortranCallback(tao,_cb.update,(Tao*,PetscInt*,void*),(&tao,&iter,_ctx));
182 }
183 
184 EXTERN_C_BEGIN
185 
186 PETSC_EXTERN void taosetobjectiveroutine_(Tao *tao, void (*func)(Tao*, Vec *, PetscReal *, void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
187 {
188     CHKFORTRANNULLFUNCTION(func);
189     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.obj,(PetscVoidFunction)func,ctx);
190     if (!*ierr) *ierr = TaoSetObjectiveRoutine(*tao,ourtaoobjectiveroutine,ctx);
191 }
192 
193 PETSC_EXTERN void taosetgradientroutine_(Tao *tao, void (*func)(Tao*, Vec *, Vec *, void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
194 {
195     CHKFORTRANNULLFUNCTION(func);
196     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.grad,(PetscVoidFunction)func,ctx);
197     if (!*ierr) *ierr = TaoSetGradientRoutine(*tao,ourtaogradientroutine,ctx);
198 }
199 
200 PETSC_EXTERN void taosetobjectiveandgradientroutine_(Tao *tao, void (*func)(Tao*, Vec *, PetscReal *, Vec *, void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
201 {
202     CHKFORTRANNULLFUNCTION(func);
203     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.objgrad,(PetscVoidFunction)func,ctx);
204     if (!*ierr) *ierr = TaoSetObjectiveAndGradientRoutine(*tao,ourtaoobjectiveandgradientroutine,ctx);
205 }
206 
207 PETSC_EXTERN void taosetresidualroutine_(Tao *tao, Vec *F, void (*func)(Tao*, Vec *, Vec *, void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
208 {
209     CHKFORTRANNULLFUNCTION(func);
210     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.lsres,(PetscVoidFunction)func,ctx);
211     if (!*ierr) *ierr = TaoSetResidualRoutine(*tao,*F,ourtaoresidualroutine,ctx);
212 }
213 
214 PETSC_EXTERN void taosetjacobianresidualroutine_(Tao *tao, Mat *J, Mat *Jpre, void (*func)(Tao*, Vec *, Mat *, Mat *, void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
215 {
216     CHKFORTRANNULLFUNCTION(func);
217     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.lsjac,(PetscVoidFunction)func,ctx);
218     if (!*ierr) *ierr = TaoSetJacobianResidualRoutine(*tao,*J,*Jpre,ourtaojacobianresidualroutine,ctx);
219 }
220 
221 PETSC_EXTERN void taosetjacobianroutine_(Tao *tao, Mat *J, Mat *Jp, void (*func)(Tao*, Vec *, Mat *, Mat *, void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
222 {
223     CHKFORTRANNULLFUNCTION(func);
224     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.jac,(PetscVoidFunction)func,ctx);
225     if (!*ierr) *ierr = TaoSetJacobianRoutine(*tao,*J,*Jp,ourtaojacobianroutine,ctx);
226 }
227 
228 PETSC_EXTERN void taosetjacobianstateroutine_(Tao *tao, Mat *J, Mat *Jp, Mat*Jinv, void (*func)(Tao*, Vec *, Mat *, Mat *, Mat*, void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
229 {
230     CHKFORTRANNULLFUNCTION(func);
231     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.jacstate,(PetscVoidFunction)func,ctx);
232     if (!*ierr) *ierr = TaoSetJacobianStateRoutine(*tao,*J,*Jp,*Jinv,ourtaojacobianstateroutine,ctx);
233 }
234 
235 PETSC_EXTERN void taosetjacobiandesignroutine_(Tao *tao, Mat *J, void (*func)(Tao*, Vec *, Mat *, void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
236 {
237     CHKFORTRANNULLFUNCTION(func);
238     *ierr = PetscObjectSetFortranCallback((PetscObject)tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.jacdesign,(PetscVoidFunction)func,ctx);
239     if (!*ierr) *ierr = TaoSetJacobianDesignRoutine(*tao,*J,ourtaojacobiandesignroutine,ctx);
240 }
241 
242 PETSC_EXTERN void taosethessianroutine_(Tao *tao, Mat *J, Mat *Jp, void (*func)(Tao*, Vec *, Mat *, Mat *,void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
243 {
244     CHKFORTRANNULLFUNCTION(func);
245     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.hess,(PetscVoidFunction)func,ctx);
246     if (!*ierr) *ierr = TaoSetHessianRoutine(*tao,*J, *Jp, ourtaohessianroutine,ctx);
247 }
248 
249 PETSC_EXTERN void taosetvariableboundsroutine_(Tao *tao, void (*func)(Tao*,Vec*,Vec*,void*,PetscErrorCode*),void *ctx, PetscErrorCode *ierr)
250 {
251     CHKFORTRANNULLFUNCTION(func);
252     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.bounds,(PetscVoidFunction)func,ctx);
253     if (!*ierr) *ierr = TaoSetVariableBoundsRoutine(*tao,ourtaoboundsroutine,ctx);
254 }
255 
256 PETSC_EXTERN void taosetmonitor_(Tao *tao, void (*func)(Tao*,void*,PetscErrorCode*),void *ctx, void (*mondestroy)(void*,PetscErrorCode*),PetscErrorCode *ierr)
257 {
258     CHKFORTRANNULLFUNCTION(mondestroy);
259     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.mon,(PetscVoidFunction)func,ctx); if (*ierr) return;
260     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.mondestroy,(PetscVoidFunction)mondestroy,ctx); if (*ierr) return;
261     *ierr = TaoSetMonitor(*tao,ourtaomonitor,*tao,ourtaomondestroy);
262 }
263 
264 PETSC_EXTERN void taosetconvergencetest_(Tao *tao, void (*func)(Tao*,void*,PetscErrorCode*),void *ctx, PetscErrorCode *ierr)
265 {
266     CHKFORTRANNULLFUNCTION(func);
267     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.convtest,(PetscVoidFunction)func,ctx);
268     if (!*ierr) *ierr = TaoSetConvergenceTest(*tao,ourtaoconvergencetest,ctx);
269 }
270 
271 PETSC_EXTERN void taosetconstraintsroutine_(Tao *tao, Vec *C, void (*func)(Tao*, Vec *, Vec *, void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
272 {
273     CHKFORTRANNULLFUNCTION(func);
274     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.constraints,(PetscVoidFunction)func,ctx);
275     if (!*ierr) *ierr = TaoSetConstraintsRoutine(*tao,*C,ourtaoconstraintsroutine,ctx);
276 }
277 
278 PETSC_EXTERN void taosettype_(Tao *tao, char* type_name, PetscErrorCode *ierr,PETSC_FORTRAN_CHARLEN_T len)
279 {
280     char *t;
281 
282     FIXCHAR(type_name,len,t);
283     *ierr = TaoSetType(*tao,t);if (*ierr) return;
284     FREECHAR(type_name,t);
285 
286 }
287 
288 PETSC_EXTERN void taoview_(Tao *tao, PetscViewer *viewer, PetscErrorCode *ierr)
289 {
290     PetscViewer v;
291     PetscPatchDefaultViewers_Fortran(viewer,v);
292     *ierr = TaoView(*tao,v);
293 }
294 
295 PETSC_EXTERN void taogetconvergencehistory_(Tao *tao, PetscInt *nhist, PetscErrorCode *ierr)
296 {
297   *ierr = TaoGetConvergenceHistory(*tao,NULL,NULL,NULL,NULL,nhist);
298 }
299 
300 PETSC_EXTERN void taogetoptionsprefix_(Tao *tao, char* prefix, PetscErrorCode *ierr,PETSC_FORTRAN_CHARLEN_T len)
301 {
302   const char *name;
303   *ierr = TaoGetOptionsPrefix(*tao,&name);
304   *ierr = PetscStrncpy(prefix,name,len); if (*ierr) return;
305   FIXRETURNCHAR(PETSC_TRUE,prefix,len);
306 
307 }
308 
309 PETSC_EXTERN void taoappendoptionsprefix_(Tao *tao, char* prefix,PetscErrorCode *ierr,PETSC_FORTRAN_CHARLEN_T len)
310 {
311   char *name;
312   FIXCHAR(prefix,len,name);
313   *ierr = TaoAppendOptionsPrefix(*tao,name);if (*ierr) return;
314   FREECHAR(prefix,name);
315 }
316 
317 PETSC_EXTERN void taosetoptionsprefix_(Tao *tao, char* prefix,PetscErrorCode *ierr,PETSC_FORTRAN_CHARLEN_T len)
318 {
319   char *t;
320   FIXCHAR(prefix,len,t);
321   *ierr = TaoSetOptionsPrefix(*tao,t);if (*ierr) return;
322   FREECHAR(prefix,t);
323 }
324 
325 PETSC_EXTERN void taogettype_(Tao *tao, char* name, PetscErrorCode *ierr,PETSC_FORTRAN_CHARLEN_T len)
326 {
327   const char *tname;
328   *ierr = TaoGetType(*tao,&tname);
329   *ierr = PetscStrncpy(name,tname,len); if (*ierr) return;
330   FIXRETURNCHAR(PETSC_TRUE,name,len);
331 
332 }
333 
334 PETSC_EXTERN void taosetjacobianinequalityroutine_(Tao *tao, Mat *J, Mat *Jp, void (*func)(Tao*, Vec *, Mat *, Mat *,void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
335 {
336     CHKFORTRANNULLFUNCTION(func);
337     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.jacineq,(PetscVoidFunction)func,ctx);
338     if (!*ierr) *ierr = TaoSetJacobianInequalityRoutine(*tao,*J,*Jp,ourtaojacobianinequalityroutine,ctx);
339 }
340 
341 PETSC_EXTERN void taosetjacobianequalityroutine_(Tao *tao, Mat *J, Mat *Jp, void (*func)(Tao*, Vec *, Mat *, Mat *, void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
342 {
343     CHKFORTRANNULLFUNCTION(func);
344     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.jaceq,(PetscVoidFunction)func,ctx);
345     if (!*ierr) *ierr = TaoSetJacobianEqualityRoutine(*tao,*J,*Jp,ourtaojacobianequalityroutine,ctx);
346 }
347 
348 PETSC_EXTERN void taosetinequalityconstraintsroutine_(Tao *tao, Vec *C, void (*func)(Tao*, Vec *, Vec *, void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
349 {
350     CHKFORTRANNULLFUNCTION(func);
351     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.conineq,(PetscVoidFunction)func,ctx);
352     if (!*ierr) *ierr = TaoSetInequalityConstraintsRoutine(*tao,*C,ourtaoinequalityconstraintsroutine,ctx);
353 }
354 
355 PETSC_EXTERN void taosetequalityconstraintsroutine_(Tao *tao, Vec *C, void (*func)(Tao*, Vec *, Vec *, void *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
356 {
357     CHKFORTRANNULLFUNCTION(func);
358     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.coneq,(PetscVoidFunction)func,ctx);
359     if (!*ierr) *ierr = TaoSetEqualityConstraintsRoutine(*tao, *C, ourtaoequalityconstraintsroutine,ctx);
360 }
361 
362 PETSC_EXTERN void taosetupdate_(Tao *tao, void (*func)(Tao *, PetscInt *, PetscErrorCode *), void *ctx, PetscErrorCode *ierr)
363 {
364     CHKFORTRANNULLFUNCTION(func);
365     *ierr = PetscObjectSetFortranCallback((PetscObject)*tao,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.update,(PetscVoidFunction)func,ctx);
366     if (!*ierr) *ierr = TaoSetUpdate(*tao, ourtaoupdateroutine, ctx);
367 }
368 
369 PETSC_EXTERN void taoviewfromoptions_(Tao *ao,PetscObject obj,char* type,PetscErrorCode *ierr,PETSC_FORTRAN_CHARLEN_T len)
370 {
371   char *t;
372 
373   FIXCHAR(type,len,t);
374   CHKFORTRANNULLOBJECT(obj);
375   *ierr = TaoViewFromOptions(*ao,obj,t);if (*ierr) return;
376   FREECHAR(type,t);
377 }
378 
379 PETSC_EXTERN void taodestroy_(Tao *x,int *ierr)
380 {
381   PETSC_FORTRAN_OBJECT_F_DESTROYED_TO_C_NULL(x);
382   *ierr = TaoDestroy(x); if (*ierr) return;
383   PETSC_FORTRAN_OBJECT_C_NULL_TO_F_DESTROYED(x);
384 }
385 
386 EXTERN_C_END
387 
388