xref: /petsc/src/binding/petsc4py/src/petsc4py/include/petsc4py/petsc4py.i (revision c12c126234ed623246a63bfa78c9f75a3aa00323)
1 /* Author:  Lisandro Dalcin   */
2 /* Contact: dalcinl@gmail.com */
3 
4 /* ---------------------------------------------------------------- */
5 
6 %header %{#include <petsc4py/petsc4py.h>%}
7 %init   %{import_petsc4py();%}
8 
9 /* ---------------------------------------------------------------- */
10 
11 %runtime %{
12 SWIGINTERNINLINE PyObject*
SWIG_getattr_this(PyObject * obj)13 SWIG_getattr_this(PyObject* obj) {
14   if (!obj) return NULL;
15   obj = PyObject_GetAttr(obj, SWIG_This());
16   if (!obj) PyErr_Clear();
17   return obj;
18 }
19 SWIGINTERNINLINE int
SWIG_convert_ptr(PyObject * obj,void ** ptr,swig_type_info * ty,int flags)20 SWIG_convert_ptr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {
21   int res = SWIG_ConvertPtr(obj, ptr, ty, flags);
22   if (!SWIG_IsOK(res)) {
23     PyObject* _this = SWIG_getattr_this(obj);
24     res = SWIG_ConvertPtr(_this, ptr, ty, flags);
25     Py_XDECREF(_this);
26   }
27   return res;
28 }
29 #undef  SWIG_ConvertPtr
30 #define SWIG_ConvertPtr(obj, pptr, type, flags) \
31         SWIG_convert_ptr(obj, pptr, type, flags)
32 %}
33 
34 /* ---------------------------------------------------------------- */
35 
36 
37 /* ---------------------------------------------------------------- */
38 /* PETSc Error Codes                                                */
39 /* ---------------------------------------------------------------- */
40 
41 %define %petsc4py_errt(Pkg, PyType, Type)
42 
43 %wrapper %{
44 #ifndef Py##Pkg##_ChkErrQ
45 #define Py##Pkg##_ChkErrQ(ierr)                         \
46     do {                                                \
47       if (ierr != PETSC_SUCCESS) {                      \
48         Py##Pkg##PyType##_Set((ierr)); SWIG_fail;       \
49       }                                                 \
50     } while (0)
51 #endif /* defined Py##Pkg##_ChkErrQ */
52 %}
53 
54 %typemap(out,noblock=1) Type {
55 Py##Pkg##_ChkErrQ($1); %set_output(VOID_Object);
56 }
57 
58 %enddef
59 
60 /* ---------------------------------------------------------------- */
61 
62 
63 
64 /* ---------------------------------------------------------------- */
65 /* Numeric Types                                                    */
66 /* ---------------------------------------------------------------- */
67 
68 %define SWIG_TYPECHECK_PETSC_INT      SWIG_TYPECHECK_INT32   %enddef
69 %define SWIG_TYPECHECK_PETSC_REAL     SWIG_TYPECHECK_DOUBLE  %enddef
70 %define SWIG_TYPECHECK_PETSC_COMPLEX  SWIG_TYPECHECK_CPLXDBL %enddef
71 %define SWIG_TYPECHECK_PETSC_SCALAR   SWIG_TYPECHECK_CPLXDBL %enddef
72 
73 /* PetscInt */
74 /* -------- */
75 %fragment(SWIG_From_frag(PetscInt64),"header",
76           fragment=SWIG_From_frag(long long),
77           fragment=SWIG_From_frag(long))
78 {
79 SWIGINTERN SWIG_Object
PetscInt64(PetscInt64 val)80 SWIG_From_dec(PetscInt64)(PetscInt64 val) {
81 %#if PETSC_SIZEOF_LONG == 8
82   return SWIG_From(long)(%numeric_cast(val,long));
83 %#else
84   return SWIG_From(long long)(%numeric_cast(val,long long));
85 %#endif
86 }
87 }
88 %fragment(SWIG_AsVal_frag(PetscInt64),"header",
89           fragment=SWIG_AsVal_frag(long long),
90           fragment=SWIG_AsVal_frag(long))
91 {
92 SWIGINTERN int
PetscInt64(SWIG_Object obj,PetscInt64 * val)93 SWIG_AsVal_dec(PetscInt64)(SWIG_Object obj, PetscInt64 *val) {
94 %#if PETSC_SIZEOF_LONG == 8
95   long v; int res = SWIG_AsVal(long)(obj, &v);
96 %#else
97   long long v; int res = SWIG_AsVal(long long)(obj, &v);
98 %#endif
99   if (SWIG_IsOK(res) && val) if (val) *val = %numeric_cast(v,PetscInt64);
100   return res;
101 }
102 }
103 %fragment(SWIG_From_frag(PetscInt),"header",
104           fragment=SWIG_From_frag(PetscInt64),
105           fragment=SWIG_From_frag(int))
106 {
107 %#if defined(PETSC_USE_64BIT_INDICES)
108 %define_as(SWIG_From(PetscInt), SWIG_From(PetscInt64))
109 %#else
110 %define_as(SWIG_From(PetscInt), SWIG_From(int))
111 %#endif
112 }
113 %fragment(SWIG_AsVal_frag(PetscInt),"header",
114           fragment=SWIG_AsVal_frag(PetscInt64),
115           fragment=SWIG_AsVal_frag(int))
116 {
117 %#if defined(PETSC_USE_64BIT_INDICES)
118 %define_as(SWIG_AsVal(PetscInt), SWIG_AsVal(PetscInt64))
119 %#else
120 %define_as(SWIG_AsVal(PetscInt), SWIG_AsVal(int))
121 %#endif
122 }
123 
124 /* PetscReal */
125 /* --------- */
126 %fragment(SWIG_From_frag(long double),"header",
127           fragment=SWIG_From_frag(double))
128 {
129 SWIGINTERN SWIG_Object
SWIG_From_dec(long double)130 SWIG_From_dec(long double)(long double val) {
131   return SWIG_From(double)((double)val);
132 }
133 }
134 %fragment(SWIG_AsVal_frag(long double),"header",
135           fragment=SWIG_AsVal_frag(double))
136 {
137 SWIGINTERN int
SWIG_AsVal_dec(long double)138 SWIG_AsVal_dec(long double)(SWIG_Object obj, long double *val) {
139   double v; int res = SWIG_AsVal(double)(obj, &v);
140   if (SWIG_IsOK(res) && val) if (val) *val = %numeric_cast(v,long double);
141   return res;
142 }
143 }
144 %fragment(SWIG_From_frag(PetscReal),"header",
145           fragment=SWIG_From_frag(long double),
146           fragment=SWIG_From_frag(double),
147           fragment=SWIG_From_frag(float))
148 {
149 %#if   defined(PETSC_USE_REAL_SINGLE)
150 %define_as(SWIG_From(PetscReal), SWIG_From(float))
151 %#elif defined(PETSC_USE_REAL_DOUBLE)
152 %define_as(SWIG_From(PetscReal), SWIG_From(double))
153 %#elif defined(PETSC_USE_REAL_LONG_DOUBLE)
154 %define_as(SWIG_From(PetscReal), SWIG_From(long double))
155 %#endif
156 }
157 %fragment(SWIG_AsVal_frag(PetscReal),"header",
158           fragment=SWIG_AsVal_frag(long double),
159           fragment=SWIG_AsVal_frag(double),
160           fragment=SWIG_AsVal_frag(float))
161 {
162 %#if   defined(PETSC_USE_REAL_SINGLE)
163 %define_as(SWIG_AsVal(PetscReal),  SWIG_AsVal(float))
164 %#elif defined(PETSC_USE_REAL_DOUBLE)
165 %define_as(SWIG_AsVal(PetscReal),  SWIG_AsVal(double))
166 %#elif defined(PETSC_USE_REAL_LONG_DOUBLE)
167 %define_as(SWIG_AsVal(PetscReal),  SWIG_AsVal(long double))
168 %#endif
169 }
170 
171 /* PetscComplex */
172 /* ------------ */
173 %include complex.i
174 %fragment(SWIG_From_frag(PetscComplex),"header",
175 #ifdef __cplusplus
176           fragment=SWIG_From_frag(std::complex<long double>),
177           fragment=SWIG_From_frag(std::complex<double>),
178           fragment=SWIG_From_frag(std::complex<float>))
179 #else
180           fragment=SWIG_From_frag(long double complex),
181           fragment=SWIG_From_frag(double complex),
182           fragment=SWIG_From_frag(float complex))
183 #endif
184 {
185 %#if defined(PETSC_CLANGUAGE_CXX)
186 %define_as(SWIG_From(PetscComplex), SWIG_From(std::complex<double>))
187 %#else
188 %define_as(SWIG_From(PetscComplex), SWIG_From(double complex))
189 %#endif
190 }
191 
192 %fragment(SWIG_AsVal_frag(PetscComplex),"header",
193 #ifdef __cplusplus
194           fragment=SWIG_AsVal_frag(std::complex<long double>),
195           fragment=SWIG_AsVal_frag(std::complex<double>),
196           fragment=SWIG_AsVal_frag(std::complex<float>))
197 #else
198           fragment=SWIG_AsVal_frag(long double complex),
199           fragment=SWIG_AsVal_frag(double complex),
200           fragment=SWIG_AsVal_frag(float complex))
201 #endif
202 {
203 %#if defined(PETSC_CLANGUAGE_CXX)
204 %define_as(SWIG_AsVal(PetscComplex), SWIG_AsVal(std::complex<double>))
205 %#else
206 %define_as(SWIG_AsVal(PetscComplex), SWIG_AsVal(double complex))
207 %#endif
208 }
209 
210 /* PetscScalar */
211 /* ----------- */
212 %fragment(SWIG_From_frag(PetscScalar), "header",
213           fragment=SWIG_From_frag(PetscReal),
214           fragment=SWIG_From_frag(PetscComplex))
215 {
216 %#if   defined(PETSC_USE_COMPLEX)
217 %define_as(SWIG_From(PetscScalar), SWIG_From(PetscComplex))
218 %#else
219 %define_as(SWIG_From(PetscScalar), SWIG_From(PetscReal))
220 %#endif
221 }
222 %fragment(SWIG_AsVal_frag(PetscScalar), "header",
223           fragment=SWIG_AsVal_frag(PetscReal),
224           fragment=SWIG_AsVal_frag(PetscComplex))
225 {
226 %#if   defined(PETSC_USE_COMPLEX)
227 %define_as(SWIG_AsVal(PetscScalar), SWIG_AsVal(PetscComplex))
228 %#else
229 %define_as(SWIG_AsVal(PetscScalar), SWIG_AsVal(PetscReal))
230 %#endif
231 }
232 
233 %define %petsc4py_numt(Pkg, PyType, Type, CheckCode, UNUSED)
234 %types(Type,Type*);
235 %typemaps_primitive(%checkcode(CheckCode), Type);
236 /* INPUT value typemap*/
237 %typemap(typecheck,
238          precedence=%checkcode(CheckCode),
239          fragment=SWIG_AsVal_frag(Type))
240 Type, const Type & {
241   int res = SWIG_AsVal(Type)($input, 0);
242   $1 = SWIG_CheckState(res);
243 }
244 %typemap(in,noblock=1,fragment=SWIG_AsVal_frag(Type))
245 Type (Type val, int ecode = 0) {
246   ecode = SWIG_AsVal(Type)($input, &val);
247   if (!SWIG_IsOK(ecode)) %argument_fail(ecode, "$ltype", $symname, $argnum);
248   $1 = %static_cast(val,$ltype);
249 }
250 %typemap(in,noblock=1,fragment=SWIG_AsVal_frag(Type))
251 const Type & ($*ltype temp, Type val, int ecode = 0) {
252   ecode = SWIG_AsVal(Type)($input, &val);
253   if (!SWIG_IsOK(ecode)) %argument_fail(ecode, "$*ltype", $symname, $argnum);
254   temp = %static_cast(val,$*ltype);
255   $1 = &temp;
256 }
257 %typemap(freearg) Type, const Type & "";
258 /* INPUT pointer/reference typemap */
259 %typemap(typecheck,
260          precedence=%checkcode(CheckCode),
261          fragment=SWIG_AsVal_frag(Type))
262 Type *INPUT, Type &INPUT {
263   int res = SWIG_AsVal(Type)($input, 0);
264   $1 = SWIG_CheckState(res);
265 }
266 %typemap(in,noblock=1,fragment=SWIG_AsVal_frag(Type))
267 Type *INPUT ($*ltype temp, int res = 0) {
268   res = SWIG_AsVal(Type)($input, &temp);
269   if (!SWIG_IsOK(res)) %argument_fail(res, "$*ltype",$symname, $argnum);
270   $1 = &temp;
271 }
272 %typemap(in,noblock=1,fragment=SWIG_AsVal_frag(Type))
273 Type &INPUT ($*ltype temp, int res = 0) {
274   res = SWIG_AsVal(Type)($input, &temp);
275   if (!SWIG_IsOK(res)) %argument_fail(res, "$*ltype",$symname, $argnum);
276   $1 = &temp;
277 }
278 %typemap(freearg) Type *INPUT, Type &INPUT "";
279 /* OUTPUT pointer/reference typemap */
280 %typemap(in,numinputs=0,noblock=1)
281  Type *OUTPUT ($*ltype temp=0) "$1 = &temp;";
282 %typemap(in,numinputs=0,noblock=1)
283 Type &OUTPUT ($*ltype temp=0)  "$1 = &temp;";
284 %typemap(argout,noblock=1,fragment=SWIG_From_frag(Type))
285 Type* OUTPUT, Type &OUTPUT { %append_output(SWIG_From(Type)((*$1))); }
286 %typemap(freearg) Type *OUTPUT "";
287 /* INOUT pointer/reference typemap */
288 %typemap(typecheck) Type *INOUT = Type *INPUT;
289 %typemap(in)        Type *INOUT = Type *INPUT;
290 %typemap(argout)    Type *INOUT = Type *OUTPUT;
291 %typemap(freearg)   Type *INOUT "";
292 %typemap(typecheck) Type &INOUT = Type &INPUT;
293 %typemap(in)        Type &INOUT = Type &INPUT;
294 %typemap(argout)    Type &INOUT = Type &OUTPUT;
295 %typemap(freearg)   Type &INOUT "";
296 /* default typemap for pointer argument */
297 %apply Type *OUTPUT { Type * }
298 %enddef /* %petsc4py_numt */
299 
300 /* ---------------------------------------------------------------- */
301 
302 
303 
304 /* ---------------------------------------------------------------- */
305 /* Enumerations                                                     */
306 /* ---------------------------------------------------------------- */
307 
308 %define SWIG_TYPECHECK_PETSC_ENUM SWIG_TYPECHECK_INT32 %enddef
309 
310 %fragment(SWIG_From_frag(PetscEnum),"header",
311           fragment=SWIG_From_frag(int))
312 {
313 SWIGINTERN SWIG_Object
PetscEnum(PetscEnum val)314 SWIG_From_dec(PetscEnum)(PetscEnum val) {
315   return SWIG_From(int)((PetscEnum)val);
316 }
317 }
318 %fragment(SWIG_AsVal_frag(PetscEnum),"header",
319           fragment=SWIG_AsVal_frag(int))
320 {
321 SWIGINTERN int
PetscEnum(SWIG_Object obj,PetscEnum * val)322 SWIG_AsVal_dec(PetscEnum)(SWIG_Object obj, PetscEnum *val) {
323   int v; int res = SWIG_AsVal(int)(obj, &v);
324   if (SWIG_IsOK(res) && val) *val = %static_cast(v,PetscEnum);
325   return res;
326 }
327 }
328 
329 %typemaps_primitive(%checkcode(PETSC_ENUM), PetscEnum);
330 
331 %typemap(in,numinputs=0)
332 PetscEnum *OUTPUT ($*ltype temp) "$1 = &temp;"
333 %typemap(argout,noblock=1,fragment=SWIG_From_frag(PetscEnum))
334 PetscEnum *OUTPUT { %append_output(SWIG_From(PetscEnum)(%static_cast(*$1,PetscEnum))); }
335 %apply PetscEnum *INPUT { PetscEnum const * }
336 %typemap(argout) PetscEnum const* "";
337 %apply PetscEnum *OUTPUT { PetscEnum * }
338 
339 %define %petsc4py_enum(EnumType)
340 %apply PetscEnum         { EnumType         }
341 %apply PetscEnum *       { EnumType *       }
342 %apply PetscEnum *INPUT  { EnumType *INPUT  }
343 %apply PetscEnum *OUTPUT { EnumType *OUTPUT }
344 %apply PetscEnum *INOUT  { EnumType *INOUT  }
345 %enddef
346 
347 /* ---------------------------------------------------------------- */
348 
349 
350 %define %petsc4py_fragments(Pkg, PyType, Type, OBJECT_DEFAULT)
351 /* AsVal */
352 /* ----- */
353 %fragment(SWIG_AsVal_frag(Type),"header")
354 {
355 SWIGINTERN int
Type(SWIG_Object input,Type * v)356 SWIG_AsVal_dec(Type)(SWIG_Object input, Type *v) {
357   if (input == Py_None) {
358     if (v) *v = OBJECT_DEFAULT;
359     return SWIG_OK;
360   } else if (PyObject_TypeCheck(input,&Py##Pkg##PyType##_Type)) {
361     if (v) *v = Py##Pkg##PyType##_Get(input);
362     return SWIG_OK;
363   } else {
364     void *argp = 0;
365     int res = SWIG_ConvertPtr(input,&argp,%descriptor(p_##Type), 0);
366     if (!SWIG_IsOK(res)) return res;
367     if (!argp) return SWIG_ValueError;
368     if (v) *v = *(%static_cast(argp,Type*));
369     return SWIG_OK;
370   }
371 }
372 }
373 /* AsPtr */
374 /* ----- */
375 %fragment(SWIG_AsPtr_frag(Type),"header",
376           fragment=%fragment_name(GetPtr,Type))
377 {
378 SWIGINTERN int
Type(SWIG_Object input,Type ** p)379 SWIG_AsPtr_dec(Type)(SWIG_Object input, Type **p) {
380   if (input == Py_None) {
381     if (p) *p = 0;
382     return SWIG_OK;
383   } else if (PyObject_TypeCheck(input,&Py##Pkg##PyType##_Type)) {
384     if (p) *p = Py##Pkg##PyType##_GetPtr(input);
385     return SWIG_OK;
386   } else {
387     void *argp = 0;
388     int res = SWIG_ConvertPtr(input,&argp,%descriptor(p_##Type), 0);
389     if (!SWIG_IsOK(res)) return res;
390     if (!argp) return SWIG_ValueError;
391     if (p) *p = %static_cast(argp,Type*);
392     return SWIG_OK;
393   }
394 }
395 }
396 /* From */
397 /* ---- */
398 %fragment(SWIG_From_frag(Type),"header")
399 {
400 SWIGINTERN SWIG_Object
Type(Type v)401 SWIG_From_dec(Type)(Type v) {
402   return Py##Pkg##PyType##_New(v);
403 }
404 }
405 %enddef /*petsc4py_fragments*/
406 
407 
408 
409 /* ---------------------------------------------------------------- */
410 /* MPI Communicator                                                 */
411 /* ---------------------------------------------------------------- */
412 
413 %define SWIG_TYPECHECK_MPI_COMM 600 %enddef
414 
415 %define %petsc4py_comm(Pkg, PyType, Type, CODE, OBJECT_NULL)
416 
417 /* pointer type */
418 %types(Type*);  /* XXX find better way */
419 /* fragments */
420 %fragment(%fragment_name(GetPtr,MPI_Comm),"header") { }
421 %petsc4py_fragments(Pkg, PyType, Type, PETSC_COMM_WORLD)
422 /* base typemaps */
423 %typemaps_asvalfromn(%checkcode(MPI_COMM), Type);
424 /* custom typemaps */
425 %typemap(check,noblock=1) Type {
426   if ($1 == OBJECT_NULL)
427     %argument_nullref("$ltype",$symname,$argnum);
428 }
429 
430 %enddef  /* %petsc4py_comm */
431 
432 
433 /* ---------------------------------------------------------------- */
434 /* PETSc Objects                                                    */
435 /* ---------------------------------------------------------------- */
436 
437 %define SWIG_TYPECHECK_PETSC_OBJECT           500 %enddef
438 %define SWIG_TYPECHECK_PETSC_VIEWER           501 %enddef
439 %define SWIG_TYPECHECK_PETSC_RANDOM           502 %enddef
440 %define SWIG_TYPECHECK_PETSC_DEVICE_CONTEXT   503 %enddef
441 
442 %define SWIG_TYPECHECK_PETSC_IS               510 %enddef
443 %define SWIG_TYPECHECK_PETSC_IS_LTOGM         511 %enddef
444 %define SWIG_TYPECHECK_PETSC_SF               512 %enddef
445 %define SWIG_TYPECHECK_PETSC_VEC              513 %enddef
446 %define SWIG_TYPECHECK_PETSC_VEC_SCATTER      514 %enddef
447 %define SWIG_TYPECHECK_PETSC_SECTION          515 %enddef
448 
449 %define SWIG_TYPECHECK_PETSC_MAT              520 %enddef
450 %define SWIG_TYPECHECK_PETSC_MAT_PARTITIONING 521 %enddef
451 %define SWIG_TYPECHECK_PETSC_MAT_NULLSPACE    522 %enddef
452 
453 %define SWIG_TYPECHECK_PETSC_KSP              530 %enddef
454 %define SWIG_TYPECHECK_PETSC_PC               531 %enddef
455 %define SWIG_TYPECHECK_PETSC_SNES             532 %enddef
456 %define SWIG_TYPECHECK_PETSC_TS               533 %enddef
457 %define SWIG_TYPECHECK_PETSC_TAO              534 %enddef
458 %define SWIG_TYPECHECK_PETSC_REGRESSOR        535 %enddef
459 
460 %define SWIG_TYPECHECK_PETSC_AO               540 %enddef
461 %define SWIG_TYPECHECK_PETSC_DM               541 %enddef
462 %define SWIG_TYPECHECK_PETSC_DS               542 %enddef
463 %define SWIG_TYPECHECK_PETSC_PARTITIONER      543 %enddef
464 
465 %define SWIG_TYPECHECK_PETSC_FE               550 %enddef
466 %define SWIG_TYPECHECK_PETSC_QUADRATURE       551 %enddef
467 %define SWIG_TYPECHECK_PETSC_SPACE            552 %enddef
468 %define SWIG_TYPECHECK_PETSC_DUALSPACE        553 %enddef
469 
470 %define SWIG_TYPECHECK_PETSC_DMLABEL          560 %enddef
471 
472 %define %petsc4py_objt(Pkg, PyType, Type, CODE)
473 
474 /* pointer type */
475 %types(Type*); /* XXX find better way */
476 /* fragments */
477 %fragment(%fragment_name(GetPtr,Type),"header")
478 { /* XXX implement this better*/
479 %define_as(Py##Pkg##PyType##_GetPtr(ob), (Type *)PyPetscObject_GetPtr(ob))
480 }
481 %petsc4py_fragments(Pkg, PyType, Type, NULL)
482 /* base typemaps */
483 %typemaps_asptrfromn(%checkcode(CODE), Type);
484 
485 
486 /* Custom Typemaps */
487 /* --------------- */
488 
489 /* freearg */
490 %typemap(freearg) Type, Type*, Type& "";
491 
492 /* check */
493 %typemap(check,noblock=1) Type INPUT {
494   if ($1 == NULL)
495     %argument_nullref("$type", $symname, $argnum);
496 }
497 
498 /* input pointer */
499 %typemap(in,fragment=SWIG_AsPtr_frag(Type)) Type *INPUT (int res = SWIG_OLDOBJ) {
500   Type *ptr = (Type *)0;
501   res = SWIG_AsPtr(Type)($input, &ptr);
502   if (!SWIG_IsOK(res)) { %argument_fail(res,"$type", $symname, $argnum); }
503   $1 = ptr;
504 }
505 %typemap(check,noblock=1) Type *INPUT {
506   if ($1 == NULL || (*$1) == NULL)
507     %argument_nullref("$type", $symname, $argnum);
508 }
509 
510 /* input reference */
511 %apply Type *INPUT { Type& }
512 
513 /* optional value */
514 %typemap(arginit) Type OPTIONAL "$1 = NULL;"
515 %typemap(in,fragment=SWIG_AsPtr_frag(Type)) Type OPTIONAL (int res = 0) {
516   Type *ptr = (Type *)0;
517   res = SWIG_AsPtr(Type)($input, &ptr);
518   if (!SWIG_IsOK(res)) { %argument_fail(res, "$type", $symname, $argnum); }
519   if (ptr) $1 = *ptr;
520 }
521 
522 /* optional reference */
523 %typemap(in,fragment=SWIG_AsPtr_frag(Type)) Type& OPTIONAL (int res = 0) {
524   Type *ptr = (Type *)0;
525   res = SWIG_AsPtr(Type)($input, &ptr);
526   if (!SWIG_IsOK(res)) { %argument_fail(res, "$type", $symname, $argnum); }
527   if (!ptr) %argument_nullref("$type", $symname, $argnum);
528   $1 = ptr;
529   if (SWIG_IsNewObj(res)) %delete(ptr);
530 }
531 
532 %typemap(in,numinputs=0) Type* OUTREF, Type* OUTNEW
533 ($*ltype temp = NULL) "$1 = &temp;";
534 %typemap(freearg) Type* OUTREF, Type* OUTNEW  "";
535 %typemap(check) Type* OUTREF, Type* OUTNEW  "";
536 %typemap(argout) Type* OUTREF {
537   SWIG_Object o = Py##Pkg##PyType##_New(*$1);
538   %append_output(o);
539 }
540 %typemap(argout) Type* OUTNEW {
541   SWIG_Object o = Py##Pkg##PyType##_New(*$1);
542   if (o!=NULL) PetscObjectDereference((PetscObject)(*$1));
543   %append_output(o);
544 }
545 
546 
547 %apply Type  OPTIONAL { Type  MAYBE  }
548 %apply Type& OPTIONAL { Type& MAYBE  }
549 %apply Type* OUTNEW   { Type* NEWOBJ }
550 %apply Type* OUTREF   { Type* NEWREF }
551 
552 %enddef /* %petsc4py_objt */
553 
554 
555 /* ---------------------------------------------------------------- */
556 /*                                                                  */
557 /* ---------------------------------------------------------------- */
558 
559 %petsc4py_errt( Petsc , Error   , PetscErrorCode )
560 
561 %petsc4py_numt( Petsc , Int     , PetscInt     , PETSC_INT     , 0 )
562 %petsc4py_numt( Petsc , Real    , PetscReal    , PETSC_REAL    , 0 )
563 %petsc4py_numt( Petsc , Complex , PetscComplex , PETSC_COMPLEX , 0 )
564 %petsc4py_numt( Petsc , Scalar  , PetscScalar  , PETSC_SCALAR  , 0 )
565 
566 %petsc4py_comm( Petsc, Comm , MPI_Comm , MPI_COMM , MPI_COMM_NULL )
567 
568 %petsc4py_objt( Petsc , Object         , PetscObject            , PETSC_OBJECT           )
569 %petsc4py_objt( Petsc , Viewer         , PetscViewer            , PETSC_VIEWER           )
570 %petsc4py_objt( Petsc , Random         , PetscRandom            , PETSC_RANDOM           )
571 %petsc4py_objt( Petsc , DeviceContext  , PetscDeviceContext     , PETSC_DEVICE_CONTEXT   )
572 
573 %petsc4py_objt( Petsc , IS             , IS                     , PETSC_IS               )
574 %petsc4py_objt( Petsc , LGMap          , ISLocalToGlobalMapping , PETSC_IS_LTOGM         )
575 %petsc4py_objt( Petsc , SF             , PetscSF                , PETSC_SF               )
576 %petsc4py_objt( Petsc , Vec            , Vec                    , PETSC_VEC              )
577 %petsc4py_objt( Petsc , Scatter        , VecScatter             , PETSC_VEC_SCATTER      )
578 %petsc4py_objt( Petsc , Section        , PetscSection           , PETSC_SECTION          )
579 
580 %petsc4py_objt( Petsc , Mat            , Mat                    , PETSC_MAT              )
581 %petsc4py_objt( Petsc , MatPartitioning, MatPartitioning        , PETSC_MAT_PARTITIONING )
582 %petsc4py_objt( Petsc , NullSpace      , MatNullSpace           , PETSC_MAT_NULLSPACE    )
583 
584 %petsc4py_objt( Petsc , KSP            , KSP                    , PETSC_KSP              )
585 %petsc4py_objt( Petsc , PC             , PC                     , PETSC_PC               )
586 %petsc4py_objt( Petsc , SNES           , SNES                   , PETSC_SNES             )
587 %petsc4py_objt( Petsc , TS             , TS                     , PETSC_TS               )
588 %petsc4py_objt( Petsc , TAO            , Tao                    , PETSC_TAO              )
589 %petsc4py_objt( Petsc , Regressor      , PetscRegressor         , PETSC_REGRESSOR        )
590 
591 %petsc4py_objt( Petsc , AO             , AO                     , PETSC_AO               )
592 %petsc4py_objt( Petsc , DM             , DM                     , PETSC_DM               )
593 %petsc4py_objt( Petsc , DS             , PetscDS                , PETSC_DS               )
594 %petsc4py_objt( Petsc , Partitioner    , PetscPartitioner       , PETSC_PARTITIONER      )
595 
596 %petsc4py_objt( Petsc , FE             , PetscFE                , PETSC_FE               )
597 %petsc4py_objt( Petsc , Quad           , PetscQuadrature        , PETSC_QUADRATURE       )
598 %petsc4py_objt( Petsc , Space          , PetscSpace             , PETSC_SPACE            )
599 %petsc4py_objt( Petsc , DualSpace      , PetscDualSpace         , PETSC_DUALSPACE        )
600 
601 %petsc4py_objt( Petsc , DMLabel        , PetscDMLabel           , PETSC_DMLABEL          )
602 
603 /* ---------------------------------------------------------------- */
604 
605 /*
606  * Local Variables:
607  * mode: C
608  * End:
609  */
610