Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66907775
surface.i
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jun 18, 19:49
Size
7 KB
Mime Type
text/x-c++
Expires
Thu, Jun 20, 19:49 (2 d)
Engine
blob
Format
Raw Data
Handle
18314583
Attached To
rTAMAAS tamaas
surface.i
View Options
/**
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
%{
#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_gigi.hh"
#include "bem_fft_base.hh"
#include "contact_area.hh"
#include "contact_cluster_collection.hh"
#include "functional.hh"
#include "elastic_energy_functional.hh"
#include "adhesion_functional.hh"
#include "surface_timer.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(SurfaceInt) Surface<int>;
%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("SurfaceForPython: incompatible input which is not a numpy: " + type);
}
UInt _n = PyArray_NDIM((PyArrayObject*)input);
if (_n != 2) SURFACE_FATAL("SurfaceForPython: incompatible numpy dimension " << _n);
npy_intp * ndims = PyArray_DIMS((PyArrayObject*)input);
UInt sz = ndims[0];
UInt sz2 = ndims[1];
if (sz != sz2) SURFACE_FATAL("SurfaceForPython: 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("SurfaceForPython: 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 ("<class 'tamaas.SurfaceForPython" + std::string("DATA_TYPE") + "'>" == __type) {
SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,0);
}
else if ("<class 'tamaas.Surface" + std::string("DATA_TYPE") + "'>" == __type) {
SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,0);
}
else if ("<class 'tamaas.SurfaceComplex" + std::string("DATA_TYPE") + "'>" == __type) {
SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,0);
}
else throw SurfaceException("typemap: incompatible input which is not a proper type: " + __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);
}
}
%inline %{
SURFACE_CLASS & convertSurface(SURFACE_CLASS & s){
return s;
}
%}
%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 >;
%include "surface_timer.hh"
Event Timeline
Log In to Comment