#include #include #include "mex.h" #include "opnml_mex5_allocs.c" #define ELE(i,j,m) ele[i+m*j] /* PROTOTYPES */ #ifdef __STDC__ void comp_bwidth(int,int *,int *); void bandmsolve_c(int, double **, double *, int, int); void grad_assem_lhs(int nn, int ne, int nbw, double *x, double *y, int *ele, double **lhs); void grad_assem_rhs(int nn, int ne, int nbw, double *x, double *y, int *ele, double *q, double *grax, double *gray); #endif /************************************************************ #### ## ##### ###### # # ## # # # # # # # # # # # # # # # # # # ##### # # # # # # ### ###### # # # ## # ###### # # # # # # # ## ## # # # #### # # # ###### # # # # # ************************************************************/ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int i,j,nn,ne,nbw,nh,LHSout,NeedLHS; double *x,*y,*q,*dele,*dqdx,*dqdy; double **lhs; int *ele; double *temp,*LHS,*lhstemp; /* ---- gradmex5 will be called as : [dqdx,dqdy,LHSout]=gradmex5(x,y,ele,q,LHS); ------------------------------- */ /* ---- check I/O arguments ----------------------------------------- */ if (nrhs != 5) mexErrMsgTxt("gradmex5 requires 5 input arguments."); else if (nlhs != 3) mexErrMsgTxt("gradmex5 requires 3 output arguments."); /* ---- dereference input arrays ------------------------------------ */ x=mxGetPr(prhs[0]); y=mxGetPr(prhs[1]); dele=mxGetPr(prhs[2]); q=mxGetPr(prhs[3]); LHS=mxGetPr(prhs[4]); nn=mxGetM(prhs[0]); ne=mxGetM(prhs[2]); fprintf(stderr,"NN=%d NE=%d\n",nn,ne); if (LHS[0]==1. & LHS[1]==0. & LHS[2]==1. & LHS[3]==1.) NeedLHS=1; else NeedLHS=0; /* ---- allocate space for int representation of dele & convert double element representation to int & shift node numbers toward 0 by 1 for proper indexing -------- */ ele=(int *)mxIvector(0,3*ne); for (i=0;i<3*ne;i++){ ele[i]=(int)dele[i]; ele[i]=ele[i]-1; } /* ---- get bandwidth ----------------------------------------------- */ comp_bwidth(ne,ele,&nbw); nh=(nbw-1)/2; fprintf(stderr,"BW,HBW,NeedLHS = %d %d %d\n",nbw,nh,NeedLHS); /* ---- allocate space for gradient lists following NRC allocation style ------------- */ dqdx = (double *) mxDvector(0,nn-1); dqdy = (double *) mxDvector(0,nn-1); /* ---- Allocate, assemble, and triangularize LHS, if needed */ lhs = (double **) mxDmatrix(0,nbw-1,0,nn-1); if (NeedLHS){ grad_assem_lhs(nn,ne,nbw,x,y,ele,lhs); bandmsolve_c(0,lhs,dqdx,nn,nh); puts("LHS triangularized"); } else{ for (i=0;i