1 |
#include <math.h> |
---|
2 |
#include <stdio.h> |
---|
3 |
#include "mex.h" |
---|
4 |
#include "matrix.h" |
---|
5 |
#include "opnml_mex5_allocs.c" |
---|
6 |
/* Array Access Definitions */ |
---|
7 |
#define MN m*n |
---|
8 |
#define MNP m*n*p |
---|
9 |
#define JXY(i,j,m) jxy[i+m*j] |
---|
10 |
#define FDZGRID(i,j,k,m,n) fdzgrid[i+m*j+m*n*k] /* FDZgrid(i,j,k,m,n) */ |
---|
11 |
#define NN1(i,j,k,m,n) N1[i+m*j+m*n*k] /* N1(i,j,k,m,n) */ |
---|
12 |
#define NN2(i,j,k,m,n) N2[i+m*j+m*n*k] /* N2(i,j,k,m,n) */ |
---|
13 |
#define BB1(i,j,k,m,n) B1[i+m*j+m*n*k] /* B1(i,j,k,m,n) */ |
---|
14 |
#define BB2(i,j,k,m,n) B2[i+m*j+m*n*k] /* B2(i,j,k,m,n) */ |
---|
15 |
#define Z3D(i,j,k,m,n) z3d[i+m*j+m*n*k] /* Z3D(i,j,k,m,n) */ |
---|
16 |
|
---|
17 |
/* PROTOTYPES */ |
---|
18 |
void basis1d2(double *,int,double,int,int,double,double); |
---|
19 |
|
---|
20 |
/************************************************************ |
---|
21 |
|
---|
22 |
#### ## ##### ###### # # ## # # |
---|
23 |
# # # # # # # # # # # # |
---|
24 |
# # # # ##### # # # # # |
---|
25 |
# ### ###### # # # ## # ###### # |
---|
26 |
# # # # # # ## ## # # # |
---|
27 |
#### # # # ###### # # # # # |
---|
28 |
|
---|
29 |
************************************************************/ |
---|
30 |
|
---|
31 |
|
---|
32 |
void mexFunction(int nlhs, |
---|
33 |
mxArray *plhs[], |
---|
34 |
int nrhs, |
---|
35 |
const mxArray *prhs[]) |
---|
36 |
{ |
---|
37 |
/* 0 1 2 3 0 1 2 */ |
---|
38 |
/* [N1,B1,N2,B2]=comp_basis3d_mex5(FDZgrid,jXY,Z3D); */ |
---|
39 |
|
---|
40 |
int i,j,k,l,nx,ny,nnv,*jxy,m,n,p,n1,n2; |
---|
41 |
const int *dims; |
---|
42 |
double *B1,*B2,b1,b2,*djxy,*N1,*N2; |
---|
43 |
double *zref, *fdzgrid, *z3d; |
---|
44 |
mxArray *NNN1,*NNN2,*BBB1,*BBB2; |
---|
45 |
double NaN=mxGetNaN(); |
---|
46 |
unsigned char *start_of_array; |
---|
47 |
size_t bytes_to_copy; |
---|
48 |
int number_of_dims; |
---|
49 |
|
---|
50 |
/* get nx,ny,nz from RHS arg #0 FDZgrid (nx X ny X nnv) */ |
---|
51 |
dims = mxGetDimensions(prhs[0]); |
---|
52 |
nx=dims[0];ny=dims[1];nnv=dims[2]; |
---|
53 |
|
---|
54 |
/* Deref the 3d vertical array Z3D */ |
---|
55 |
z3d=mxGetPr(prhs[2]); |
---|
56 |
|
---|
57 |
/* get m,n,p from RHS arg #2 (m X n X p) */ |
---|
58 |
dims = mxGetDimensions(prhs[2]); |
---|
59 |
m=dims[0];n=dims[1];p=dims[2]; |
---|
60 |
|
---|
61 |
djxy=mxGetPr(prhs[1]); |
---|
62 |
jxy=(int *)mxIvector(0,MN*3); |
---|
63 |
for (i=0;i<3*MN;i++){ |
---|
64 |
jxy[i]=(int)djxy[i]; |
---|
65 |
jxy[i]=jxy[i]-1; |
---|
66 |
} |
---|
67 |
|
---|
68 |
N1=(double *)mxDvector(0,MNP-1); |
---|
69 |
N2=(double *)mxDvector(0,MNP-1); |
---|
70 |
B1=(double *)mxDvector(0,MNP-1); |
---|
71 |
B2=(double *)mxDvector(0,MNP-1); |
---|
72 |
|
---|
73 |
fdzgrid=mxGetPr(prhs[0]); /* FDZgrid */ |
---|
74 |
for (i=0;i<nx+1;i++){/* waitbar((i-1)/nx) */ |
---|
75 |
for (j=0;j<ny+1;j++){ |
---|
76 |
if (!mxIsNaN(JXY(i,j,nx))){ |
---|
77 |
zref=(double *)mxDvector(0,nnv-1); |
---|
78 |
for (l=0;l<nnv;l++)zref[l]=FDZGRID(i,j,l,m,n); |
---|
79 |
for (k=0;k<p+1;k++){ |
---|
80 |
basis1d2(zref,nnv,Z3D(i,j,k,m,n),n1,n2,b1,b2); |
---|
81 |
NN1(i,j,k,m,n)=(double)n1; |
---|
82 |
BB1(i,j,k,m,n)=b1; |
---|
83 |
NN2(i,j,k,m,n)=(double)n2; |
---|
84 |
BB2(i,j,k,m,n)=b2; |
---|
85 |
} |
---|
86 |
} |
---|
87 |
} |
---|
88 |
} |
---|
89 |
|
---|
90 |
/* Load the return arrays */ |
---|
91 |
|
---|
92 |
/* Set pointer to lhs */ |
---|
93 |
start_of_array=(unsigned char *)mxGetPr(NNN1); |
---|
94 |
bytes_to_copy=MNP*mxGetElementSize(NNN1); |
---|
95 |
memcpy(start_of_array,N1,bytes_to_copy); |
---|
96 |
plhs[0]=NNN1; |
---|
97 |
start_of_array=(unsigned char *)mxGetPr(BBB1); |
---|
98 |
bytes_to_copy=MNP*mxGetElementSize(BBB1); |
---|
99 |
memcpy(start_of_array,B1,bytes_to_copy); |
---|
100 |
plhs[1]=BBB1; |
---|
101 |
start_of_array=(unsigned char *)mxGetPr(NNN2); |
---|
102 |
bytes_to_copy=MNP*mxGetElementSize(NNN2); |
---|
103 |
memcpy(start_of_array,N2,bytes_to_copy); |
---|
104 |
plhs[2]=NNN2; |
---|
105 |
start_of_array=(unsigned char *)mxGetPr(BBB2); |
---|
106 |
bytes_to_copy=MNP*mxGetElementSize(BBB2); |
---|
107 |
memcpy(start_of_array,B2,bytes_to_copy); |
---|
108 |
plhs[3]=BBB2; |
---|
109 |
|
---|
110 |
return; |
---|
111 |
} |
---|
112 |
|
---|
113 |
|
---|
114 |
void basis1d2(double *zref,int nz,double zdes,int n1,int n2,double b1,double b2) |
---|
115 |
{ |
---|
116 |
|
---|
117 |
double NaN=mxGetNaN(); |
---|
118 |
int k; |
---|
119 |
double zdiff; |
---|
120 |
|
---|
121 |
for (k=0;k<nz;k++){ |
---|
122 |
if (zdes<zref[k]){ |
---|
123 |
n2=k; |
---|
124 |
n1=k-1; |
---|
125 |
if (n2==1){ |
---|
126 |
n1=nz;b1=0.; |
---|
127 |
b2=1.0;n2=NaN; |
---|
128 |
return; |
---|
129 |
} |
---|
130 |
zdiff=zref[n2]-zref[n1]; |
---|
131 |
b1=(zref[n2]-zdes)/zdiff; |
---|
132 |
b2=(zdes-zref[n1])/zdiff; |
---|
133 |
return; |
---|
134 |
} |
---|
135 |
} |
---|
136 |
b1=1.0;n1=nz;b2=0.;n2=NaN; |
---|
137 |
return; |
---|
138 |
} |
---|
139 |
|
---|
140 |
|
---|
141 |
/* |
---|
142 |
%*********************************************************************** |
---|
143 |
%*********************************************************************** |
---|
144 |
% function [b2,n2,b1,n1]=basis1d2(zref,zdes) |
---|
145 |
%----------------------------------------------------------------------- |
---|
146 |
% purpose: This subroutine evaluates the value of the basis functions |
---|
147 |
% alive on a 1-D linear element at a point |
---|
148 |
% |
---|
149 |
% restrictions: Applicable only for 1-D linear elements |
---|
150 |
% |
---|
151 |
% inputs: nn is the number of entries in the reference z array |
---|
152 |
% zref(nn) is the 1-D array containing the reference z array |
---|
153 |
% NOTE: zref must increase from zref(1) to zref(nn) |
---|
154 |
% zdes is the z value at which the basis functions are desired |
---|
155 |
% |
---|
156 |
% outputs: n1 is the reference node immediately below zdes |
---|
157 |
% b1 is the value of the n1's basis function at zdes |
---|
158 |
% n2 is the reference node immediately above zdes |
---|
159 |
% b2 is the value of the n2's basis function at zdes |
---|
160 |
% |
---|
161 |
% notes: zdes<zref(1) => n1=NaN,b1=0.0,n2=1,b2=1.0 |
---|
162 |
% zdes>zref(nn) => n1=nn,b1=1.0,n2=NaN,b2=0.0 |
---|
163 |
% |
---|
164 |
% history: Written by Christopher E. Naimie |
---|
165 |
% Dartmouth College |
---|
166 |
% 26 AUGUST 1992 |
---|
167 |
%----------------------------------------------------------------------- |
---|
168 |
function [b2,n2,b1,n1]=basis1d1(zref,zdes) |
---|
169 |
% |
---|
170 |
zdiff=zref-zdes;nn=length(zref); |
---|
171 |
if zdiff(1) >= 0; |
---|
172 |
n1=NaN;b1=0.0;n2=1;b2=1.0; |
---|
173 |
elseif zdiff(length(zdiff)) <= 0; |
---|
174 |
n1=nn;b1=1.0;n2=NaN;b2=0.0; |
---|
175 |
else |
---|
176 |
zpast=find(zdiff<=0); |
---|
177 |
n1=zpast(length(zpast)); |
---|
178 |
n2=n1+1; |
---|
179 |
dz=zref(n2)-zref(n1); |
---|
180 |
b1=(zref(n2)-zdes)/dz; |
---|
181 |
b2=(zdes-zref(n1))/dz; |
---|
182 |
end |
---|
183 |
%*********************************************************************** |
---|
184 |
%*********************************************************************** |
---|
185 |
*/ |
---|