Page MenuHomec4science

surface.i
No OneTemporary

File Metadata

Created
Tue, May 21, 07:38

surface.i

%{
#include <complex>
#include "map_2d.hh"
#include "surface.hh"
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <numpy/arrayobject.h>
#include "surface_generator_filter_fft.hh"
#include "smart_pointer.hh"
#include "surface_statistics.hh"
#include "bem_kato.hh"
#include "bem_polonski.hh"
#include "bem_fft_base.hh"
#include "contact_area.hh"
#include "contact_cluster_collection.hh"
%}
%include "cpointer.i"
%include "typemaps.i"
%include "numpy.i"
%init %{
import_array();
%}
/* -------------------------------------------------------------------------- */
/* Wrapping returned pointers
/* -------------------------------------------------------------------------- */
//%include "typemaps.i"
%include "std_string.i"
%include "std_vector.i"
%include "smart_pointer.hh"
%template(VectorReal) std::vector<double>;
%pointer_functions(int, intp);
%pointer_functions(long, longp);
%pointer_functions(unsigned int, uintp);
%pointer_functions(double, doublep);
%pointer_functions(float, floatp);
%pointer_functions(std::complex<double>, comlpexp);
//%define %my_pointer_class(NAME,TYPE)
//
//%template(SmartPointer##NAME) SmartPointer< TYPE >;
//
//%typemap(out) TYPE & {
//#define TOREPLACE SWIGTYPE_p_SmartPointerT_##NAME##_t
// SmartPointer<TYPE> * ptr = new SmartPointer<TYPE>($1);
// $result = SWIG_NewPointerObj(SWIG_as_voidptr(ptr), TOREPLACE, 0 | 0 );
//#undef TOREPLACE
// }
//%enddef
//
//%my_pointer_class(int,int)
//%my_pointer_class(Real,Real)
//%my_pointer_class(long,long)
//%my_pointer_class(vectorReal,std::vector<Real>)
/* -------------------------------------------------------------------------- */
/* Wrapping Surface class */
/* -------------------------------------------------------------------------- */
%include "types.hh"
%include "map_2d.hh"
%template(Map2dComplex) Map2d<complex>;
%template(Map2dInt) Map2d<int>;
%template(Map2dReal) Map2d<Real>;
%include "map_2d_square.hh"
%template(Map2dSquareComplex) Map2dSquare<complex>;
%template(Map2dSquareInt) Map2dSquare<int>;
%template(Map2dSquareReal) Map2dSquare<Real>;
%include "surface.hh"
%include "surface_complex.hh"
%template(SurfaceReal) Surface<Real>;
%template(SurfaceRealComplex) SurfaceComplex<Real>;
%inline %{
template <typename T>
class SurfaceForPython : public Surface<T>{
public:
SurfaceForPython(T * wrapped_memory,
UInt n,
Real L)
: Surface<T>(0,L){
this->__init__(wrapped_memory,n,L);
};
void __init__(T * wrapped_memory,
UInt n,
Real L){
this->n[0] = n;
this->n[1] = n;
this->data.wrapMemory(wrapped_memory,n*n);
}
SurfaceForPython(PyObject * input,Real L = 1.)
: Surface<T>(0,L){
if (!PyArray_Check(input)){
PyObject* obj_type = PyObject_Type(input);
std::string type = PyString_AsString(obj_type);
throw SurfaceException("incompatible input which is not a numpy: " + type);
}
UInt _n = PyArray_NDIM((PyArrayObject*)input);
if (_n != 2) SURFACE_FATAL("incompatible numpy dimension " << _n);
npy_intp * ndims = PyArray_DIMS((PyArrayObject*)input);
UInt sz = ndims[0];
UInt sz2 = ndims[1];
if (sz != sz2) SURFACE_FATAL("incompatible numpy dimensions " << sz << " " << sz2);
PyArrayIterObject *iter = (PyArrayIterObject *)PyArray_IterNew(input);
if (iter == NULL) throw;
this->__init__(( T *)(iter->dataptr),sz,L);
Py_DECREF(iter);
};
~SurfaceForPython(){
};
void resize(UInt new_size){
if (this->size() != new_size)
throw SurfaceException("cannot resize a temporary vector");
}
};
%}
%define %surface_typemaps(SURFACE_CLASS, DATA_TYPE, DATA_TYPECODE)
%typemap(out, fragment="NumPy_Fragments") (SURFACE_CLASS &)
{
UInt nz = $1->size();
npy_intp dims[2] = {nz,nz};
DATA_TYPE * data = const_cast<DATA_TYPE *>($1->getInternalData());
PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, &data[0]);
PyArrayObject* array = (PyArrayObject*) obj;
if (!array) SWIG_fail;
$result = SWIG_Python_AppendOutput($result, obj);
}
%typemap(in) Surface< DATA_TYPE > & {
if (!PyArray_Check($input)){
PyObject* objectsRepresentation = PyObject_Repr(PyObject_Type($input));
const char* s = PyString_AsString(objectsRepresentation);
std::string __type = s;
if (__type == "<class 'rough_contact.SurfaceForPython" + std::string("DATA_TYPE") + "'>")
SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,0);
else throw SurfaceException("incompatible input which is not a numpy: " + __type);
}
else{
UInt _n = PyArray_NDIM((PyArrayObject*)$input);
if (_n != 2) SURFACE_FATAL("incompatible numpy dimension " << _n);
npy_intp * ndims = PyArray_DIMS((PyArrayObject*)$input);
UInt sz = ndims[0];
UInt sz2 = ndims[1];
if (sz != sz2) SURFACE_FATAL("incompatible numpy dimensions " << sz << " " << sz2);
PyArrayIterObject *iter = (PyArrayIterObject *)PyArray_IterNew($input);
if (iter == NULL) throw;
$1 = new SurfaceForPython< DATA_TYPE >(( DATA_TYPE *)(iter->dataptr),sz,1.);
PyArray_ITER_NEXT(iter);
}
}
%enddef
%surface_typemaps(Surface<Real>, Real, NPY_DOUBLE)
%surface_typemaps(SurfaceComplex<Real>, std::complex<Real>, NPY_COMPLEX128 )
%surface_typemaps(Surface<unsigned long>, unsigned long, NPY_UINT )
%surface_typemaps(Surface<UInt>, UInt, NPY_UINT )
%surface_typemaps(Surface<int>, int, NPY_INT )
%template(SurfaceForPythonReal) SurfaceForPython< Real >;

Event Timeline