Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F82414167
surface_python.hh
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
Wed, Sep 11, 06:52
Size
2 KB
Mime Type
text/x-c++
Expires
Fri, Sep 13, 06:52 (2 d)
Engine
blob
Format
Raw Data
Handle
20695439
Attached To
rTAMAAS tamaas
surface_python.hh
View Options
/**
*
* @author Lucas Frérot <lucas.frerot@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_PYTHON_HH__
#define __SURFACE_PYTHON_HH__
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
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);
this->computeStrides();
}
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 Exception("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 Exception("SurfaceForPython: cannot resize a temporary vector");
}
};
__END_TAMAAS__
#endif // __SURFACE_PYTHON_HH__
Event Timeline
Log In to Comment