Xdmf.i 15.7 KB
Newer Older
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
1 2 3 4 5
/*
XdmfPython.cpp:
swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
*/

6 7 8 9 10 11 12 13 14
%{
#include <cstddef>
#include <iostream>
#if PY_VERSION_HEX >= 0x03020000
    #define SWIGPY_SLICE_ARG(obj) ((PyObject*) (obj))
#else
    #define SWIGPY_SLICE_ARG(obj) ((PySliceObject*) (obj))
#endif
%}
15 16 17

#ifdef XDMF_BUILD_DSM

18 19
%module Xdmf
%{
20 21 22
    // MPI Includes
    #include <mpi.h>

23
    // XdmfCore Includes
24 25
    #include <Xdmf.hpp>
    #include <XdmfArray.hpp>
26
    #include <XdmfArrayReference.hpp>
27 28 29
    #include <XdmfArrayType.hpp>
    #include <XdmfCoreItemFactory.hpp>
    #include <XdmfCoreReader.hpp>
30 31 32
    #include <XdmfDSMManager.hpp>
    #include <XdmfDSMBuffer.hpp>
    #include <XdmfDSMCommMPI.hpp>
33
    #include <XdmfError.hpp>
34
    #include <XdmfFunction.hpp>
35 36 37 38 39 40 41 42 43
    #include <XdmfHDF5Controller.hpp>
    #include <XdmfHDF5Writer.hpp>
    #include <XdmfHDF5ControllerDSM.hpp>
    #include <XdmfHDF5WriterDSM.hpp>
    #include <XdmfHeavyDataController.hpp>
    #include <XdmfHeavyDataWriter.hpp>
    #include <XdmfInformation.hpp>
    #include <XdmfItem.hpp>
    #include <XdmfItemProperty.hpp>
44
    #include <XdmfSharedPtr.hpp>
Kenneth Leiter's avatar
Kenneth Leiter committed
45
    #include <XdmfSparseMatrix.hpp>
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
46
    #include <XdmfSubset.hpp>
47 48 49
    #include <XdmfSystemUtils.hpp>
    #include <XdmfVisitor.hpp>
    #include <XdmfWriter.hpp>
50

51 52 53 54 55 56 57 58
    // Xdmf Includes
    #include <XdmfAttribute.hpp>
    #include <XdmfAttributeCenter.hpp>
    #include <XdmfAttributeType.hpp>
    #include <XdmfCurvilinearGrid.hpp>
    #include <XdmfDomain.hpp>
    #include <XdmfGeometry.hpp>
    #include <XdmfGeometryType.hpp>
Kenneth Leiter's avatar
Kenneth Leiter committed
59
    #include <XdmfGraph.hpp>
60 61 62 63 64 65 66 67 68 69 70 71 72 73
    #include <XdmfGrid.hpp>
    #include <XdmfGridCollection.hpp>
    #include <XdmfGridCollectionType.hpp>
    #include <XdmfItemFactory.hpp>
    #include <XdmfMap.hpp>
    #include <XdmfReader.hpp>
    #include <XdmfRectilinearGrid.hpp>
    #include <XdmfRegularGrid.hpp>
    #include <XdmfSet.hpp>
    #include <XdmfSetType.hpp>
    #include <XdmfTime.hpp>
    #include <XdmfTopology.hpp>
    #include <XdmfTopologyType.hpp>
    #include <XdmfUnstructuredGrid.hpp>
74

75
%}
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
76

77 78
%import XdmfDSM.i

79 80 81 82 83 84
#else
%module Xdmf
%{
    // XdmfCore Includes
    #include <Xdmf.hpp>
    #include <XdmfArray.hpp>
85
    #include <XdmfArrayReference.hpp>
86 87 88 89
    #include <XdmfArrayType.hpp>
    #include <XdmfCoreItemFactory.hpp>
    #include <XdmfCoreReader.hpp>
    #include <XdmfError.hpp>
90
    #include <XdmfFunction.hpp>
91 92 93 94 95 96 97 98
    #include <XdmfHDF5Controller.hpp>
    #include <XdmfHDF5Writer.hpp>
    #include <XdmfHeavyDataController.hpp>
    #include <XdmfHeavyDataWriter.hpp>
    #include <XdmfInformation.hpp>
    #include <XdmfItem.hpp>
    #include <XdmfItemProperty.hpp>
    #include <XdmfSharedPtr.hpp>
99
    #include <XdmfSparseMatrix.hpp>
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
100
    #include <XdmfSubset.hpp>
101 102 103 104 105 106 107 108 109 110 111 112
    #include <XdmfSystemUtils.hpp>
    #include <XdmfVisitor.hpp>
    #include <XdmfWriter.hpp>

    // Xdmf Includes
    #include <XdmfAttribute.hpp>
    #include <XdmfAttributeCenter.hpp>
    #include <XdmfAttributeType.hpp>
    #include <XdmfCurvilinearGrid.hpp>
    #include <XdmfDomain.hpp>
    #include <XdmfGeometry.hpp>
    #include <XdmfGeometryType.hpp>
113
    #include <XdmfGraph.hpp>
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
    #include <XdmfGrid.hpp>
    #include <XdmfGridCollection.hpp>
    #include <XdmfGridCollectionType.hpp>
    #include <XdmfItemFactory.hpp>
    #include <XdmfMap.hpp>
    #include <XdmfReader.hpp>
    #include <XdmfRectilinearGrid.hpp>
    #include <XdmfRegularGrid.hpp>
    #include <XdmfSet.hpp>
    #include <XdmfSetType.hpp>
    #include <XdmfTime.hpp>
    #include <XdmfTopology.hpp>
    #include <XdmfTopologyType.hpp>
    #include <XdmfUnstructuredGrid.hpp>
%}

#endif

132 133
%import XdmfCore.i

134 135
#ifdef SWIGJAVA

136
// Typemaps that work for Java
137

138
%typemap(out) shared_ptr<XdmfItem> {
139 140
    if(shared_ptr<XdmfAttribute> value = shared_dynamic_cast<XdmfAttribute>($1)) {
        *(shared_ptr< XdmfAttribute > **)&($result) = value ? new shared_ptr< XdmfAttribute >(value) : 0;
141
    }
142 143
    else if(shared_ptr<XdmfCurvilinearGrid> value = shared_dynamic_cast<XdmfCurvilinearGrid>($1)) {
        *(shared_ptr< XdmfCurvilinearGrid > **)&($result) = value ? new shared_ptr< XdmfCurvilinearGrid >(value) : 0;
144
    }
145 146 147
    else if(shared_ptr<XdmfGridCollection> value = shared_dynamic_cast<XdmfGridCollection>($1)) {
        *(shared_ptr< XdmfGridCollection > **)&($result) = value ? new shared_ptr< XdmfGridCollection >(value) : 0;
    }
148 149
    else if(shared_ptr<XdmfDomain> value = shared_dynamic_cast<XdmfDomain>($1)) {
        *(shared_ptr< XdmfDomain > **)&($result) = value ? new shared_ptr< XdmfDomain >(value) : 0;
150
    }
151 152
    else if(shared_ptr<XdmfGeometry> value = shared_dynamic_cast<XdmfGeometry>($1)) {
        *(shared_ptr< XdmfGeometry > **)&($result) = value ? new shared_ptr< XdmfGeometry >(value) : 0;
153
    }
154 155
    else if(shared_ptr<XdmfInformation> value = shared_dynamic_cast<XdmfInformation>($1)) {
        *(shared_ptr< XdmfInformation > **)&($result) = value ? new shared_ptr< XdmfInformation >(value) : 0;
156
    }
157 158
    else if(shared_ptr<XdmfRectilinearGrid> value = shared_dynamic_cast<XdmfRectilinearGrid>($1)) {
        *(shared_ptr< XdmfRectilinearGrid > **)&($result) = value ? new shared_ptr< XdmfRectilinearGrid >(value) : 0;
159
    }
160 161
    else if(shared_ptr<XdmfRegularGrid> value = shared_dynamic_cast<XdmfRegularGrid>($1)) {
        *(shared_ptr< XdmfRegularGrid > **)&($result) = value ? new shared_ptr< XdmfRegularGrid >(value) : 0;
162
    }
163 164
    else if(shared_ptr<XdmfSet> value = shared_dynamic_cast<XdmfSet>($1)) {
        *(shared_ptr< XdmfSet > **)&($result) = value ? new shared_ptr< XdmfSet >(value) : 0;
165
    }
166 167
    else if(shared_ptr<XdmfTime> value = shared_dynamic_cast<XdmfTime>($1)) {
        *(shared_ptr< XdmfTime > **)&($result) = value ? new shared_ptr< XdmfTime >(value) : 0;
168
    }
169 170
    else if(shared_ptr<XdmfTopology> value = shared_dynamic_cast<XdmfTopology>($1)) {
        *(shared_ptr< XdmfTopology > **)&($result) = value ? new shared_ptr< XdmfTopology >(value) : 0;
171
    }
172 173
    else if(shared_ptr<XdmfUnstructuredGrid> value = shared_dynamic_cast<XdmfUnstructuredGrid>($1)) {
        *(shared_ptr< XdmfUnstructuredGrid > **)&($result) = value ? new shared_ptr< XdmfUnstructuredGrid >(value) : 0;
174 175
    }
    else {
176
        *(shared_ptr< XdmfItem > **)&($result) = &($1);
177
    }
178
}
179

180 181 182
// Ignore multiple inheritance warning
#pragma SWIG nowarn=813

183
// Ignore const overloaded methods
184 185 186
%ignore XdmfCurvilinearGrid::getDimensions() const;
%ignore XdmfDomain::getCurvilinearGrid(const unsigned int) const;
%ignore XdmfDomain::getCurvilinearGrid(const std::string &) const;
187 188
%ignore XdmfDomain::getGridCollection(const unsigned int) const;
%ignore XdmfDomain::getGridCollection(const std::string &) const;
189 190 191 192 193 194
%ignore XdmfDomain::getRectilinearGrid(const unsigned int) const;
%ignore XdmfDomain::getRectilinearGrid(const std::string &) const;
%ignore XdmfDomain::getRegularGrid(const unsigned int) const;
%ignore XdmfDomain::getRegularGrid(const std::string &) const;
%ignore XdmfDomain::getUnstructuredGrid(const unsigned int) const;
%ignore XdmfDomain::getUnstructuredGrid(const std::string &) const;
195 196 197
%ignore XdmfGrid::getAttribute(const unsigned int) const;
%ignore XdmfGrid::getAttribute(const std::string &) const;
%ignore XdmfGrid::getMap() const;
198 199 200
%ignore XdmfGrid::getMap(unsigned int const) const;
%ignore XdmfGrid::getMap(unsigned int const &) const;
%ignore XdmfGrid::getMap(std::string const &) const;
201 202 203
%ignore XdmfGrid::getSet(const unsigned int) const;
%ignore XdmfGrid::getSet(const std::string &) const;
%ignore XdmfGrid::getTime() const;
204 205 206 207 208 209
%ignore XdmfRectilinearGrid::getCoordinates(const unsigned int) const;
%ignore XdmfRectilinearGrid::getCoordinates() const;
%ignore XdmfRectilinearGrid::getDimensions() const;
%ignore XdmfRegularGrid::getBrickSize() const;
%ignore XdmfRegularGrid::getDimensions() const;
%ignore XdmfRegularGrid::getOrigin() const;
210 211 212 213
%ignore XdmfSet::getAttribute(const unsigned int) const;
%ignore XdmfSet::getAttribute(const std::string &) const;

// Ignore ItemTags
214
%ignore XdmfAttribute::ItemTag;
215
%ignore XdmfCurvilinearGrid::ItemTag;
216 217
%ignore XdmfDomain::ItemTag;
%ignore XdmfGeometry::ItemTag;
Kenneth Leiter's avatar
Kenneth Leiter committed
218
%ignore XdmfGraph::ItemTag;
219 220
%ignore XdmfGrid::ItemTag;
%ignore XdmfGridCollection::ItemTag;
221
%ignore XdmfMap::ItemTag;
222 223
%ignore XdmfRectilinearGrid::ItemTag;
%ignore XdmfRegularGrid::ItemTag;
224 225 226
%ignore XdmfSet::ItemTag;
%ignore XdmfTime::ItemTag;
%ignore XdmfTopology::ItemTag;
227
%ignore XdmfUnstructuredGrid::ItemTag;
228 229

%pragma(java) jniclasscode=%{
230 231 232 233 234
    static {
        try {
            System.loadLibrary("XdmfJava");
        }
        catch (UnsatisfiedLinkError e) {
235 236
            System.err.println("Native code library failed to load for" +
                                "XdmfJava\n" + e);
237 238 239
            System.exit(1);
        }
    }
240 241
%}

242
#endif /* SWIGJAVA */
243

244 245
#ifdef SWIGPYTHON

246 247
%include std_set.i
%include std_map.i
248
%include std_vector.i
249 250 251

#ifdef XDMF_BUILD_DSM

252 253 254
%include mpi4py/mpi4py.i

%mpi4py_typemap(Comm, MPI_Comm);
255

256
#endif /* XDMF_BUILD_DSM */
257

258 259 260
%template(XdmfMapNodeIdSet) std::set<int>;
%template(XdmfMapNodeIdMap) std::map<int, std::set<int> >;
%template(XdmfMapMap) std::map<int, std::map<int, std::set<int> > >;
261 262 263
%template(AttributeVector) std::vector<shared_ptr<XdmfAttribute> >;
%template(MapVector) std::vector<shared_ptr<XdmfMap> >;
%template(ArrayVector) std::vector<shared_ptr<XdmfArray> >;
264

265 266
#ifdef XDMF_BUILD_DSM

267
%pythoncode {
268
    from XdmfCore import *
269
    from XdmfDSM import *
270 271
}

272
#else
273 274

%pythoncode {
275
    from XdmfCore import *
276 277 278 279 280
}

#endif /* XDMF_BUILD_DSM */


281 282 283 284 285 286 287 288 289 290
%fragment("XdmfItemCast", "header") {
    #include <XdmfSharedPtr.hpp>
    PyObject * XdmfItemCast(shared_ptr<XdmfItem> obj) {
        PyObject * result;
        if(shared_ptr<XdmfAttribute> attribute = shared_dynamic_cast<XdmfAttribute>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfAttribute>(attribute)), SWIGTYPE_p_boost__shared_ptrT_XdmfAttribute_t, SWIG_POINTER_OWN);
        }
        else if(shared_ptr<XdmfCurvilinearGrid> gridCurvilinear = shared_dynamic_cast<XdmfCurvilinearGrid>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfCurvilinearGrid>(gridCurvilinear)), SWIGTYPE_p_boost__shared_ptrT_XdmfCurvilinearGrid_t, SWIG_POINTER_OWN);
        }
291 292 293
        else if(shared_ptr<XdmfGridCollection> gridCollection = shared_dynamic_cast<XdmfGridCollection>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfGridCollection>(gridCollection)), SWIGTYPE_p_boost__shared_ptrT_XdmfGridCollection_t, SWIG_POINTER_OWN);
        }
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
        else if(shared_ptr<XdmfDomain> domain = shared_dynamic_cast<XdmfDomain>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfDomain>(domain)), SWIGTYPE_p_boost__shared_ptrT_XdmfDomain_t, SWIG_POINTER_OWN);
        }
        else if(shared_ptr<XdmfGeometry> geometry = shared_dynamic_cast<XdmfGeometry>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfGeometry>(geometry)), SWIGTYPE_p_boost__shared_ptrT_XdmfGeometry_t, SWIG_POINTER_OWN);
        }
        else if(shared_ptr<XdmfGraph> graph = shared_dynamic_cast<XdmfGraph>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfGraph>(graph)), SWIGTYPE_p_boost__shared_ptrT_XdmfGraph_t, SWIG_POINTER_OWN);
        }
        else if(shared_ptr<XdmfInformation> information = shared_dynamic_cast<XdmfInformation>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfInformation>(information)), SWIGTYPE_p_boost__shared_ptrT_XdmfInformation_t, SWIG_POINTER_OWN);
        }
        else if(shared_ptr<XdmfMap> map = shared_dynamic_cast<XdmfMap>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfMap>(map)), SWIGTYPE_p_boost__shared_ptrT_XdmfMap_t, SWIG_POINTER_OWN);
        }
        else if(shared_ptr<XdmfRectilinearGrid> gridRectilinear = shared_dynamic_cast<XdmfRectilinearGrid>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfRectilinearGrid>(gridRectilinear)), SWIGTYPE_p_boost__shared_ptrT_XdmfRectilinearGrid_t, SWIG_POINTER_OWN);
        }
        else if(shared_ptr<XdmfRegularGrid> gridRegular = shared_dynamic_cast<XdmfRegularGrid>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfRegularGrid>(gridRegular)), SWIGTYPE_p_boost__shared_ptrT_XdmfRegularGrid_t, SWIG_POINTER_OWN);
        }
        else if(shared_ptr<XdmfSet> set = shared_dynamic_cast<XdmfSet>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfSet>(set)), SWIGTYPE_p_boost__shared_ptrT_XdmfSet_t, SWIG_POINTER_OWN);
        }
        else if(shared_ptr<XdmfTime> time = shared_dynamic_cast<XdmfTime>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfTime>(time)), SWIGTYPE_p_boost__shared_ptrT_XdmfTime_t, SWIG_POINTER_OWN);
        }
        else if(shared_ptr<XdmfTopology> topology = shared_dynamic_cast<XdmfTopology>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfTopology>(topology)), SWIGTYPE_p_boost__shared_ptrT_XdmfTopology_t, SWIG_POINTER_OWN);
        }
        else if(shared_ptr<XdmfUnstructuredGrid> gridUnstructured = shared_dynamic_cast<XdmfUnstructuredGrid>(obj)) {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfUnstructuredGrid>(gridUnstructured)), SWIGTYPE_p_boost__shared_ptrT_XdmfUnstructuredGrid_t, SWIG_POINTER_OWN);
        }
        else {
            result = SWIG_NewPointerObj(SWIG_as_voidptr(new shared_ptr<XdmfItem>(obj)), SWIGTYPE_p_boost__shared_ptrT_XdmfItem_t, SWIG_POINTER_OWN);
        }
        return result;
331
    }
332 333
}

334 335 336 337 338 339 340 341 342 343 344
%typemap(out, fragment="XdmfItemCast") shared_ptr<XdmfItem> {
    $result = XdmfItemCast($1);
}

%typemap(out, fragment="XdmfItemCast") std::vector<shared_ptr<XdmfItem> > {
    $result = PyList_New($1.size());
    for(std::vector<shared_ptr<XdmfItem> >::size_type i = 0; i < $1.size(); ++i) {
        PyList_SetItem($result, i, XdmfItemCast($1[i]));
    } 
}

345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
%extend XdmfAttributeCenter {
    bool __eq__(const XdmfAttributeCenter * attributeCenter) {
        return $self == attributeCenter;
    }
}

%extend XdmfAttributeType {
    bool __eq__(const XdmfAttributeType * attributeType) {
   	return $self == attributeType;
    }
}

%extend XdmfGeometryType {
    bool __eq__(const XdmfGeometryType * geometryType) {
   	return $self == geometryType;
    }
}

%extend XdmfGridCollectionType {
    bool __eq__(const XdmfGridCollectionType * gridCollectionType) {
   	return $self == gridCollectionType;
    }
}

%extend XdmfSetType {
    bool __eq__(const XdmfSetType * setType) {
   	return $self == setType;
    }
}

%extend XdmfTopologyType {
    bool __eq__(const XdmfTopologyType * topologyType) {
   	return $self == topologyType;
    }
}

381 382
#endif /* SWIGPYTHON */

383
// Shared Pointer Templates
384
%shared_ptr(XdmfAttribute)
385 386
%shared_ptr(XdmfAttributeCenter)
%shared_ptr(XdmfAttributeType)
387
%shared_ptr(XdmfCurvilinearGrid)
388 389
%shared_ptr(XdmfDomain)
%shared_ptr(XdmfGeometry)
390
%shared_ptr(XdmfGeometryType)
Kenneth Leiter's avatar
Kenneth Leiter committed
391
%shared_ptr(XdmfGraph)
392 393
%shared_ptr(XdmfGrid)
%shared_ptr(XdmfGridCollection)
394 395
%shared_ptr(XdmfGridCollectionType)
%shared_ptr(XdmfItemFactory)
396
%shared_ptr(XdmfMap)
397
%shared_ptr(XdmfReader)
398 399
%shared_ptr(XdmfRectilinearGrid)
%shared_ptr(XdmfRegularGrid)
400 401
%shared_ptr(XdmfSet)
%shared_ptr(XdmfSetType)
402
%shared_ptr(XdmfTime)
403
%shared_ptr(XdmfTopology)
404
%shared_ptr(XdmfTopologyType)
405 406
%shared_ptr(XdmfUnstructuredGrid)

407
%include Xdmf.hpp
408
%include XdmfGrid.hpp
409

410
%include XdmfAttribute.hpp
411
%include XdmfAttributeCenter.hpp
412
%include XdmfAttributeType.hpp
413
%include XdmfCurvilinearGrid.hpp
Kenneth Leiter's avatar
Kenneth Leiter committed
414
%include XdmfDomain.hpp
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
415
%include XdmfGeometry.hpp
416
%include XdmfGeometryType.hpp
Kenneth Leiter's avatar
Kenneth Leiter committed
417
%include XdmfGraph.hpp
418 419 420
%include XdmfGridCollection.hpp
%include XdmfGridCollectionType.hpp
%include XdmfItemFactory.hpp
421
%include XdmfMap.hpp
422
%include XdmfReader.hpp
423 424
%include XdmfRectilinearGrid.hpp
%include XdmfRegularGrid.hpp
425 426
%include XdmfSet.hpp
%include XdmfSetType.hpp
427
%include XdmfTime.hpp
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
428
%include XdmfTopology.hpp
429
%include XdmfTopologyType.hpp
430
%include XdmfUnstructuredGrid.hpp