Commit 89d72d8b authored by Jan Zapletal's avatar Jan Zapletal

ENH: added MEX CPP interface

parent 78a48fca
#!/bin/bash
rm -f heatdtn_mex_c_api.o
rm -f c_mexapi_version.o
rm -f heatdtn_mex_c_api.mexa64
rm -f heatdtn_mex.o
rm -f cpp_mexapi_version.o
rm -f heatdtn_mex.mexa64
g++ -c -DMATLAB_DEFAULT_RELEASE=R2018a -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I/usr/local/MATLAB/R2018b/extern/include -I../include -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -O2 -fwrapv -DNDEBUG heatdtn_mex_c_api.cpp -o heatdtn_mex_c_api.o
g++ -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I/usr/local/MATLAB/R2018b/extern/include -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O2 -fwrapv -DNDEBUG "/usr/local/MATLAB/R2018b/extern/version/c_mexapi_version.c" -o c_mexapi_version.o
g++ -pthread -Wl,--no-undefined -Wl,-rpath-link,/usr/local/MATLAB/R2018b/bin/glnxa64 -shared -O -Wl,--version-script,/usr/local/MATLAB/R2018b/extern/lib/glnxa64/c_exportsmexfileversion.map heatdtn_mex_c_api.o c_mexapi_version.o -L"/usr/local/MATLAB/R2018b/bin/glnxa64" -L../dist -Wl,-rpath,../dist -lmx -lmex -lmat -lstdc++ -lheatdtn -o heatdtn_mex_c_api.mexa64
g++ -c -DMATLAB_DEFAULT_RELEASE=R2018a -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I/usr/local/MATLAB/R2018b/extern/include -I../include -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -O2 -fwrapv -DNDEBUG heatdtn_mex.cpp -o heatdtn_mex.o
g++ -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I/usr/local/MATLAB/R2018b/extern/include -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O2 -fwrapv -DNDEBUG "/usr/local/MATLAB/R2018b/extern/version/cpp_mexapi_version.cpp" -o cpp_mexapi_version.o
g++ -pthread -Wl,--no-undefined -Wl,-rpath-link,/usr/local/MATLAB/R2018b/bin/glnxa64 -shared -O -Wl,--version-script,/usr/local/MATLAB/R2018b/extern/lib/glnxa64/c_exportsmexfileversion.map heatdtn_mex.o cpp_mexapi_version.o -L"/usr/local/MATLAB/R2018b/bin/glnxa64" -L../dist -Wl,-rpath,../dist -lMatlabDataArray -lmx -lmex -lmat -lstdc++ -lheatdtn -o heatdtn_mex.mexa64
#!/bin/bash
rm -f heatdtn_mex_c_api.o
rm -f c_mexapi_version.o
rm -f heatdtn_mex_c_api.mexa64
g++ -c -DMATLAB_DEFAULT_RELEASE=R2018a -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I/usr/local/MATLAB/R2018b/extern/include -I../include -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -O2 -fwrapv -DNDEBUG heatdtn_mex_c_api.cpp -o heatdtn_mex_c_api.o
g++ -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I/usr/local/MATLAB/R2018b/extern/include -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O2 -fwrapv -DNDEBUG "/usr/local/MATLAB/R2018b/extern/version/c_mexapi_version.c" -o c_mexapi_version.o
g++ -pthread -Wl,--no-undefined -Wl,-rpath-link,/usr/local/MATLAB/R2018b/bin/glnxa64 -shared -O -Wl,--version-script,/usr/local/MATLAB/R2018b/extern/lib/glnxa64/c_exportsmexfileversion.map heatdtn_mex_c_api.o c_mexapi_version.o -L"/usr/local/MATLAB/R2018b/bin/glnxa64" -L../dist -Wl,-rpath,../dist -lmx -lmex -lmat -lstdc++ -lheatdtn -o heatdtn_mex_c_api.mexa64
#include "mex.hpp"
#include "mexAdapter.hpp"
#include "heatdtn.h"
class MexFunction : public matlab::mex::Function {
matlab::data::ArrayFactory factory;
public:
void operator()(matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) {
checkArguments( outputs, inputs );
matlab::data::TypedArray<double> nodes = inputs[0];
matlab::data::TypedArray<long> elems = inputs[1];
const double alpha = inputs[2][0];
const int qType = inputs[3][0];
const int orderNear = inputs[4][0];
const int orderFar = inputs[5][0];
const bool nonsymmetric = inputs[6][0];
const long nNodes = nodes.getNumberOfElements( ) / 3;
const long nElems = elems.getNumberOfElements( ) / 3;
unsigned long dim = (unsigned long) nNodes;
matlab::data::TypedArray<double> S = factory.createArray<double>( { dim * dim, 1 } );
matlab::data::TypedArray<double> a = factory.createArray<double>( { dim, 1 } );
matlab::data::TypedArray<double> beta = factory.createArray<double>( { 1, 1 } );
bem4i::bem4idata<long, double> * data = nullptr;
bem4i::getLaplaceSteklovPoincare(
(double *) &(*S.begin( )),
(double *) &(*a.begin( )),
(double *) &(*beta.begin( )),
nNodes,
(double *) &(*nodes.begin( )),
nElems,
(long *) &(*elems.begin( )),
alpha,
qType,
orderNear,
orderFar,
data,
nonsymmetric,
false );
bem4i::deleteBem4iData<long, double>( data );
outputs[0] = std::move( S );
outputs[1] = std::move( a );
outputs[2] = std::move( beta );
}
void checkArguments(matlab::mex::ArgumentList & outputs, matlab::mex::ArgumentList & inputs) {
const std::shared_ptr<matlab::engine::MATLABEngine> matlabPtr = getEngine();
if( inputs.size() != 7 ){
matlabPtr->feval( matlab::engine::convertUTF8StringToUTF16String("error"), 0,
std::vector<matlab::data::Array>({ factory.createScalar("Seven input arguments required") }));
}
if( inputs[1].getType() != matlab::data::ArrayType::INT64 ){
matlabPtr->feval( matlab::engine::convertUTF8StringToUTF16String("error"), 0,
std::vector<matlab::data::Array>({ factory.createScalar("elems must be defined as int64") }));
}
if( inputs[3].getType() != matlab::data::ArrayType::INT32 ){
matlabPtr->feval( matlab::engine::convertUTF8StringToUTF16String("error"), 0,
std::vector<matlab::data::Array>({ factory.createScalar("qType must be defined as int32") }));
}
if( inputs[4].getType() != matlab::data::ArrayType::INT32 ){
matlabPtr->feval( matlab::engine::convertUTF8StringToUTF16String("error"), 0,
std::vector<matlab::data::Array>({ factory.createScalar("orderNear must be defined as int32") }));
}
if( inputs[5].getType() != matlab::data::ArrayType::INT32 ){
matlabPtr->feval( matlab::engine::convertUTF8StringToUTF16String("error"), 0,
std::vector<matlab::data::Array>({ factory.createScalar("orderFar must be defined as int32") }));
}
if( inputs[6].getType() != matlab::data::ArrayType::LOGICAL ){
matlabPtr->feval( matlab::engine::convertUTF8StringToUTF16String("error"), 0,
std::vector<matlab::data::Array>({ factory.createScalar("nonsymmetric must be defined as logical") }));
}
if( outputs.size() > 3 ){
matlabPtr->feval( matlab::engine::convertUTF8StringToUTF16String("error"), 0,
std::vector<matlab::data::Array>({ factory.createScalar("Too many output arguments") }));
}
};
};
\ No newline at end of file
......@@ -9,7 +9,7 @@ orderNear = int32( 4 );
orderFar = int32( 4 );
nonsymmetric = false;
[ S, a, beta ] = heatdtn_mex_c_api( nodes, elems, alpha, qType, orderNear, orderFar, nonsymmetric );
[ S, a, beta ] = heatdtn_mex( nodes, elems, alpha, qType, orderNear, orderFar, nonsymmetric );
nNodes = length( nodes ) / 3;
S = reshape( S, nNodes, nNodes );
......
function [ S, a, beta ] = testHeatDtN( )
nodes = [ 1 -1 -1 1 1 -1 -1 1 -1 -1 -1 -1 1 -1 1 1 1 1 -1 1 1 -1 -1 1 ]';
elems = int64( [ 0 1 5 0 5 4 1 2 6 1 6 5 2 7 6 2 3 7 3 0 4 3 4 7 0 3 1 2 1 3 4 5 6 4 6 7 ]' );
alpha = 1.0;
qType = int32( 1 );
orderNear = int32( 4 );
orderFar = int32( 4 );
nonsymmetric = false;
[ S, a, beta ] = heatdtn_mex_c_api( nodes, elems, alpha, qType, orderNear, orderFar, nonsymmetric );
nNodes = length( nodes ) / 3;
S = reshape( S, nNodes, nNodes );
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment