Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F70234436
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
Fri, Jul 5, 21:25
Size
8 KB
Mime Type
text/x-c
Expires
Sun, Jul 7, 21:25 (2 d)
Engine
blob
Format
Raw Data
Handle
18810439
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 <set>
#include "surface.hh"
#include "types.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_penalty.hh"
#include "bem_gigi.hh"
#include "bem_gigipol.hh"
#include "bem_uzawa.hh"
#include "bem_fft_base.hh"
#include "bem_grid.hh"
#include "bem_grid_polonski.hh"
#include "bem_grid_kato.hh"
#include "bem_grid_teboulle.hh"
#include "bem_grid_condat.hh"
#include "functional.hh"
#include "meta_functional.hh"
#include "elastic_energy_functional.hh"
#include "complimentary_term_functional.hh"
#include "exponential_adhesion_functional.hh"
#include "squared_exponential_adhesion_functional.hh"
#include "maugis_adhesion_functional.hh"
#include "surface_timer.hh"
#include "fftransform_fftw.hh"
#include "flood_fill.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(double,double)
%my_pointer_class(long,long)
%my_pointer_class(unsigned_int,tamaas::UInt)
%my_pointer_class(vectorReal,std::vector<tamaas::Real>)
%apply (unsigned int IN_ARRAY1[ANY]) {(tamaas::UInt n[ANY])};
/* -------------------------------------------------------------------------- */
/* Wrapping Surface class */
/* -------------------------------------------------------------------------- */
%include "tamaas.hh"
%ignore *::operator=;
%ignore *::operator++;
%ignore *::begin;
%ignore *::end;
%include "grid_base.hh"
%include "grid.hh"
%include "grid_hermitian.hh"
%include "types.hh"
%include "surface.hh"
%include "surface_complex.hh"
%ignore GridBase;
%ignore Grid;
%ignore GridHermitian;
%ignore Surface;
%ignore SurfaceComplex;
%inline %{
__BEGIN_TAMAAS__
template <int required_type>
void sanityCheck(PyObject * input) {
if (PyArray_TYPE((PyArrayObject*)input) != required_type)
throw Exception("Sanity check: python object stores wrong type");
}
__END_TAMAAS__
%}
%{
#include "python/grid_python.hh"
#include "python/surface_python.hh"
%}
%define %grid_typemaps(GRID_CLASS, DATA_TYPE, DATA_TYPECODE, DIM)
%typemap(out, fragment="NumPy_Fragments") (GRID_CLASS<DATA_TYPE, DIM> &)
{
using namespace tamaas;
UInt additional_dim = ($1->getNbComponents() == 1)? 0:1;
UInt dim = DIM+additional_dim;
npy_intp dims[dim];
for (UInt i = 0 ; i < DIM ; i++) dims[i] = (npy_intp)$1->sizes()[i];
if (additional_dim)
dims[dim-1] = $1->getNbComponents();
GRID_CLASS<DATA_TYPE, DIM>::value_type * data
= const_cast<GRID_CLASS<DATA_TYPE, DIM>::value_type *>($1->getInternalData());
PyObject* obj = PyArray_SimpleNewFromData(dim,
dims,
DATA_TYPECODE,
&data[0]);
PyArrayObject* array = (PyArrayObject*) obj;
if (!array) SWIG_fail;
$result = SWIG_Python_AppendOutput($result, obj);
}
%typemap(in) GRID_CLASS<DATA_TYPE, DIM> & {
using namespace tamaas;
if (!PyArray_Check($input)) {
PyObject* objectsRepresentation = PyObject_Repr(PyObject_Type($input));
const char* s = PyString_AsString(objectsRepresentation);
std::string __type = s;
// Remove namespace (tamaas::) from class name
std::string basename = std::string("GRID_CLASS").substr(8);
std::set<std::string> types = {
"<class 'tamaas.GridPython" + std::string("DATA_TYPE") + "'>",
"<class 'tamaas."+ basename + std::string("DIM") + "d" + std::string("DATA_TYPE") + "'>"
};
if (types.find(__type) != types.end()) {
SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,0);
}
else throw tamaas::Exception("typemap: incompatible input which is not a proper type: "
+ __type + " (DATATYPE = " + std::string("DATA_TYPE") + ")");
} else {
$1 = new tamaas::GridPython< GRID_CLASS<DATA_TYPE, DIM> >($input);
sanityCheck< DATA_TYPECODE >($input);
}
}
%inline %{
namespace tamaas {
GRID_CLASS<DATA_TYPE, DIM> & convertGrid(GRID_CLASS<DATA_TYPE, DIM> & s){
return s;
}
}
%}
%enddef
%define %surface_typemaps(SURFACE_CLASS, DATA_TYPE, DATA_TYPECODE)
%typemap(out, fragment="NumPy_Fragments") (SURFACE_CLASS &)
{
using namespace tamaas;
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) tamaas::Surface< DATA_TYPE > & {
using namespace tamaas;
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 tamaas::Exception("typemap: incompatible input which is not a proper type: " + __type + " (DATATYPE = " + std::string("DATA_TYPE") + ")");
}
else{
$1 = new SurfaceForPython< DATA_TYPE >($input);
sanityCheck< DATA_TYPECODE >($input);
}
}
%inline %{
namespace tamaas {
SURFACE_CLASS & convertSurface(SURFACE_CLASS & s){
return s;
}
}
%}
%enddef
%surface_typemaps(tamaas::Surface<Real>, Real, NPY_DOUBLE)
%surface_typemaps(tamaas::SurfaceComplex<Real>, std::complex<Real>, NPY_COMPLEX128 )
%surface_typemaps(tamaas::Surface<unsigned long>, unsigned long, NPY_UINT )
%surface_typemaps(tamaas::Surface<UInt>, UInt, NPY_UINT )
%surface_typemaps(tamaas::Surface<int>, int, NPY_INT )
// Must use c-type names here for some reason
%grid_typemaps(tamaas::Grid, double, NPY_DOUBLE, 1)
%grid_typemaps(tamaas::Grid, double, NPY_DOUBLE, 2)
%grid_typemaps(tamaas::Grid, bool, NPY_BOOL, 2)
%grid_typemaps(tamaas::GridHermitian, double, NPY_COMPLEX128, 2)
%grid_typemaps(tamaas::Grid, unsigned int, NPY_UINT, 2)
%include "surface_timer.hh"
Event Timeline
Log In to Comment