Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F113708305
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, May 20, 13:42
Size
14 KB
Mime Type
text/x-diff
Expires
Thu, May 22, 13:42 (1 d, 14 h)
Engine
blob
Format
Raw Data
Handle
26302325
Attached To
rTAMAAS tamaas
View Options
diff --git a/python/surface.i b/python/surface.i
index f2250168..ed2b5c2a 100644
--- a/python/surface.i
+++ b/python/surface.i
@@ -1,283 +1,288 @@
/**
*
* @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 tamaas::Grid::iterator::operator++;
-%ignore tamaas::Grid::begin;
-%ignore tamaas::Grid::end;
-%ignore tamaas::Grid::resize(std::initializer_list<UInt>);
-%ignore tamaas::Grid::Grid(std::initializer_list<UInt>,
- std::initializer_list<Real>,
- UInt);
%ignore *::operator=;
+%ignore *::operator++;
+
+// All this just to silence a warning, fu swig
+%include "grid_base.hh"
+%ignore GridBase;
+namespace tamaas {
+ %template (GridBReal) GridBase<Real>;
+ %template (GridBBool) GridBase<bool>;
+ %template (GridBInt) GridBase<Int>;
+ %template (GridBUInt) GridBase<UInt>;
+ %template (GridBComplex) GridBase<Complex>;
+}
%include "grid.hh"
%include "grid_hermitian.hh"
namespace tamaas {
%template (Grid1dReal) Grid<Real, 1>;
%template (Grid2dReal) Grid<Real, 2>;
%template (Grid2dBool) Grid<bool, 2>;
%template (Grid2dComplex) Grid<Complex, 2>;
%template (Grid2dInt) Grid<Int, 2>;
%template (Grid2dUInt) Grid<UInt, 2>;
%template (GridHermitian2dReal) GridHermitian<Real, 2>;
}
%include "types.hh"
%include "grid_hermitian.hh"
%include "surface.hh"
%include "surface_complex.hh"
namespace tamaas {
%template(SurfaceReal) Surface<Real>;
%template(SurfaceInt) Surface<int>;
%template(SurfaceRealComplex) SurfaceComplex<Real>;
}
%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>::storage_type * data
= const_cast<GRID_CLASS<DATA_TYPE, DIM>::storage_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 )
%grid_typemaps(tamaas::Grid, Real, NPY_DOUBLE, 1)
%grid_typemaps(tamaas::Grid, Real, NPY_DOUBLE, 2)
%grid_typemaps(tamaas::Grid, bool, NPY_BOOL, 2)
%grid_typemaps(tamaas::GridHermitian, Real, NPY_COMPLEX128, 2)
%grid_typemaps(tamaas::Grid, UInt, NPY_UINT, 2)
//%grid_typemaps(tamaas::SurfaceComplex<Real>, tamaas::Complex, NPY_COMPLEX128, 2)
/* namespace tamaas { */
/* %template(SurfaceForPythonReal) ::tamaas::SurfaceForPython< Real >; */
/* } */
%include "surface_timer.hh"
diff --git a/src/surface/surface_generator.cpp b/src/surface/surface_generator.cpp
index bd13f98d..db398329 100644
--- a/src/surface/surface_generator.cpp
+++ b/src/surface/surface_generator.cpp
@@ -1,53 +1,62 @@
/**
*
* @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 "surface_generator.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
template<UInt dim>
SurfaceGenerator<dim>::SurfaceGenerator()
{}
/* -------------------------------------------------------------------------- */
template<UInt dim>
SurfaceGenerator<dim>::~SurfaceGenerator()
{}
/* -------------------------------------------------------------------------- */
template<UInt dim>
void SurfaceGenerator<dim>::setSizes(const std::array<UInt, dim> & n) {
grid.resize(n);
}
/* -------------------------------------------------------------------------- */
+template<UInt dim>
+void SurfaceGenerator<dim>::setSizes(const UInt n[dim]) {
+ std::array<UInt, dim> size;
+ std::copy(n, n+dim, size.begin());
+ setSizes(size);
+}
+
+/* -------------------------------------------------------------------------- */
+
template class SurfaceGenerator<1>;
template class SurfaceGenerator<2>;
__END_TAMAAS__
diff --git a/src/surface/surface_generator.hh b/src/surface/surface_generator.hh
index 6d09b29d..c253b86b 100644
--- a/src/surface/surface_generator.hh
+++ b/src/surface/surface_generator.hh
@@ -1,64 +1,66 @@
/**
*
* @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/>.
*
*/
/* -------------------------------------------------------------------------- */
#ifndef SURFACE_GENERATOR_H
#define SURFACE_GENERATOR_H
/* -------------------------------------------------------------------------- */
#include "grid.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
/// Class generating random surfaces
template<UInt dim>
class SurfaceGenerator {
public:
/// Default constructor
SurfaceGenerator();
/// Default destructor
virtual ~SurfaceGenerator();
public:
/// Build surface profile (array of heights)
virtual Grid<Real, dim> & buildSurface() = 0;
/// Set surface sizes
void setSizes(const std::array<UInt, dim> & n);
+ /// Set surface sizes
+ void setSizes(const UInt n[dim]);
TAMAAS_ACCESSOR(random_seed, long, RandomSeed);
/// Maintaining old interface
friend class SurfaceGeneratorFilterFFT;
protected:
Grid<Real, dim> grid;
long random_seed;
};
/* -------------------------------------------------------------------------- */
__END_TAMAAS__
#endif
Event Timeline
Log In to Comment