Commit 78a48fca authored by Jan Zapletal's avatar Jan Zapletal

ENH: added Matlab MEX interface

parent acb4c63c
......@@ -5,5 +5,7 @@ dist/*
fig/formulas.*
fig/figs.svg
*.bak
*.o
*.mexa64
.DS_Store
......@@ -2,8 +2,10 @@
#include <iostream>
const int nNodes = 8;
const int nElems = 12;
typedef long LO;
const LO nNodes = 8;
const LO nElems = 12;
double nodes [ 3 * nNodes ] = {
1.0, -1.0, -1.0,
......@@ -16,7 +18,7 @@ double nodes [ 3 * nNodes ] = {
-1.0, -1.0, 1.0
};
int elems [ 3 * nElems ] = {
LO elems [ 3 * nElems ] = {
0, 1, 5,
0, 5, 4,
1, 2, 6,
......@@ -68,7 +70,7 @@ void testHeatDtN(
int orderNear = 4;
int orderFar = 4;
bem4i::bem4idata<int, double> * data;
bem4i::bem4idata<LO, double> * data = nullptr;
bool nonsymmetric = false;
bool verbose = true;
......@@ -92,15 +94,15 @@ void testHeatDtN(
if( verbose ){
std::cout << "S: " << std::endl;
for( size_t i = 0; i < nNodes; ++i ){
for( size_t j = 0; j < nNodes; ++j ){
for( LO i = 0; i < nNodes; ++i ){
for( LO j = 0; j < nNodes; ++j ){
std::cout << S[ j * nNodes + i ] << " ";
}
std::cout << std::endl;
}
std::cout << "a: " << std::endl;
for( size_t i = 0; i < nNodes; ++i ){
for( LO i = 0; i < nNodes; ++i ){
std::cout << a[ i ] << " ";
}
std::cout << std::endl;
......@@ -119,7 +121,7 @@ void testHeatDtN(
nodes,
nElems,
elems,
1,
(LO) 1,
point,
alpha,
dirichlet,
......@@ -130,6 +132,6 @@ void testHeatDtN(
if( verbose )
std::cout << "value: " << std::endl << value << std::endl;
bem4i::deleteBem4iData<int, double>( data );
bem4i::deleteBem4iData<LO, double>( data );
}
#!/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.h"
#include "matrix.h"
#include "heatdtn.h"
/* Input Arguments */
#define nodes prhs[ 0 ]
#define elems prhs[ 1 ]
#define alpha prhs[ 2 ]
#define qType prhs[ 3 ]
#define orderNear prhs[ 4 ]
#define orderFar prhs[ 5 ]
#define nonsymmetric prhs[ 6 ]
/* Output Arguments */
#define S plhs[ 0 ]
#define a plhs[ 1 ]
#define beta plhs[ 2 ]
void mexFunction(
int nlhs,
mxArray * plhs[ ],
int nrhs,
const mxArray * prhs[ ] ){
if( nrhs != 7 )
mexErrMsgIdAndTxt( "heatdtn:invalidNumInputs", "Seven input arguments required." );
if( !mxIsInt64( elems ) )
mexErrMsgIdAndTxt( "heatdtn:invalidInput", "elems must be defined as int64" );
if( !mxIsInt32( qType ) )
mexErrMsgIdAndTxt( "heatdtn:invalidInput", "qType must be defined as int32" );
if( !mxIsInt32( orderNear ) )
mexErrMsgIdAndTxt( "heatdtn:invalidInput", "orderNear must be defined as int32" );
if( !mxIsInt32( orderFar ) )
mexErrMsgIdAndTxt( "heatdtn:invalidInput", "orderFar must be defined as int32" );
if( !mxIsLogical( nonsymmetric ) )
mexErrMsgIdAndTxt( "heatdtn:invalidInput", "nonsymmetric must be defined as logical" );
if( nlhs > 3 )
mexErrMsgIdAndTxt( "heatdtn:invalidNumOutputs", "Too many output arguments." );
long nNodes = (long) mxGetNumberOfElements( nodes ) / 3;
long nElems = (long) mxGetNumberOfElements( elems ) / 3;
S = mxCreateDoubleMatrix( (mwSize) nNodes * (mwSize) nNodes, 1, mxREAL );
a = mxCreateDoubleMatrix( (mwSize) nNodes, (mwSize) 1, mxREAL );
beta = mxCreateDoubleScalar( 0.0 );
mxDouble * S_p = mxGetDoubles( S );
mxDouble * a_p = mxGetDoubles( a );
mxDouble * beta_p = mxGetDoubles( beta );
mxDouble * nodes_p = mxGetDoubles( nodes );
mxInt64 * elems_p = mxGetInt64s( elems );
mxDouble * alpha_p = mxGetDoubles( alpha );
mxInt32 * qType_p = mxGetInt32s( qType );
mxInt32 * orderNear_p = mxGetInt32s( orderNear );
mxInt32 * orderFar_p = mxGetInt32s( orderFar );
mxLogical * nonsymmetric_p = mxGetLogicals( nonsymmetric );
bem4i::bem4idata<long, double> * data = nullptr;
bem4i::getLaplaceSteklovPoincare(
(double *) S_p,
(double *) a_p,
(double *) beta_p,
nNodes,
(double *) nodes_p,
nElems,
(long *) elems_p,
(double) *alpha_p,
(int) *qType_p,
(int) *orderNear_p,
(int) *orderFar_p,
data,
(bool) *nonsymmetric_p,
false );
bem4i::deleteBem4iData<long, double>( data );
return;
}
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
......@@ -46,7 +46,6 @@ void deleteBem4iData(
delete data;
data = nullptr;
data = nullptr;
}
}
......@@ -317,7 +316,7 @@ template void bem4i::getLaplaceSteklovPoincare< long, double >(
int qType,
int orderNear,
int orderFar,
bem4idata< int, double > *& data,
bem4idata< long, double > *& data,
bool nonsymmetric,
bool verbose
);
......@@ -333,7 +332,7 @@ template void bem4i::evaluateLaplaceRepresentationFormula< long, double >(
double alpha,
double * dirichlet,
int orderFar,
bem4idata< int, double > *& data,
bem4idata< long, double > *& data,
bool verbose
);
......
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