I am trying to create a compiled function that takes in several arguments. However, some of the arguments contain symbolic entries and thus I get the following error message when executing the cell containing the compiled function:
Compile::cplist: b should be a tensor of type Integer, Real, or Complex; evaluation will use the uncompiled function.
Compile::cret: The type of return values in [...] are different. Evaluation will use the uncompiled function.
and this error message when trying to call the function:
CompiledFunction::cfta: "Argument {<<1>>} at position 2 should be a rank 2 tensor of !(\"machine-size real number\")s. "
Here is the compiled function I am trying to create:
calcK=Compile[{{nnpe,_Integer,0},b,{d,_Real,2},j,{t,_Real,0}},
Module[
{i,k,numQuadPts,p,pCoords,w,kSub},
k=Array[0`&,{nnpe*2,nnpe*2}];
numQuadPts=4;
p=1/Sqrt[3];
pCoords={{-p,-p},{p,-p},{p,p},{-p,p}};
w={1,1,1,1};
For[i=1,i<=numQuadPts,i++,
k+=Transpose[b].d.b*Det[j]*w[[i]]/.{xi->pCoords[[i,1]],eta->pCoords[[i,2]]};
];
Return[t*k]];
];
Here is some sample input data (I apologize in advance for the large lists):
nnpe=4;
t=.25;
d={{1.0989*10^9, 3.2967*10^8, 0}, {3.2967*10^8, 1.0989*10^9, 0}, {0, 0,3.84615*10^8}};
b={{((-(1/4) + eta/4)*(0.25*(1/4 - xi/4) + 0.25*(1/4 + xi/4)))/(0. - 0.625*eta) +
((-0.25*(-(1/4) - eta/4) - 0.25*(1/4 + eta/4))*(-(1/4) + xi/4))/(0. - 0.625*eta),
0, ((1/4 - eta/4)*(0.25*(1/4 - xi/4) + 0.25*(1/4 + xi/4)))/(0. - 0.625*eta) +
((-0.25*(-(1/4) - eta/4) - 0.25*(1/4 + eta/4))*(-(1/4) - xi/4))/(0. - 0.625*eta),
0, ((1/4 + eta/4)*(0.25*(1/4 - xi/4) + 0.25*(1/4 + xi/4)))/(0. - 0.625*eta) +
((-0.25*(-(1/4) - eta/4) - 0.25*(1/4 + eta/4))*(1/4 + xi/4))/(0. - 0.625*eta), 0,
((-(1/4) - eta/4)*(0.25*(1/4 - xi/4) + 0.25*(1/4 + xi/4)))/(0. - 0.625*eta) +
((-0.25*(-(1/4) - eta/4) - 0.25*(1/4 + eta/4))*(1/4 - xi/4))/(0. - 0.625*eta),
0}, {0, ((-(1/4) + eta/4)*(-10.*(-(1/4) - xi/4) - 10.*(1/4 - xi/4)))/
(0. - 0.625*eta) + ((10.*(-(1/4) - eta/4) + 10.*(1/4 - eta/4))*(-(1/4) + xi/4))/
(0. - 0.625*eta), 0, ((1/4 - eta/4)*(-10.*(-(1/4) - xi/4) - 10.*(1/4 - xi/4)))/
(0. - 0.625*eta) + ((10.*(-(1/4) - eta/4) + 10.*(1/4 - eta/4))*(-(1/4) - xi/4))/
(0. - 0.625*eta), 0, ((1/4 + eta/4)*(-10.*(-(1/4) - xi/4) - 10.*(1/4 - xi/4)))/
(0. - 0.625*eta) + ((10.*(-(1/4) - eta/4) + 10.*(1/4 - eta/4))*(1/4 + xi/4))/
(0. - 0.625*eta), 0,
((-(1/4) - eta/4)*(-10.*(-(1/4) - xi/4) - 10.*(1/4 - xi/4)))/(0. - 0.625*eta) +
((10.*(-(1/4) - eta/4) + 10.*(1/4 - eta/4))*(1/4 - xi/4))/(0. - 0.625*eta)},
{((-(1/4) + eta/4)*(-10.*(-(1/4) - xi/4) - 10.*(1/4 - xi/4)))/(0. - 0.625*eta) +
((10.*(-(1/4) - eta/4) + 10.*(1/4 - eta/4))*(-(1/4) + xi/4))/(0. - 0.625*eta),
((-(1/4) + eta/4)*(0.25*(1/4 - xi/4) + 0.25*(1/4 + xi/4)))/(0. - 0.625*eta) +
((-0.25*(-(1/4) - eta/4) - 0.25*(1/4 + eta/4))*(-(1/4) + xi/4))/(0. - 0.625*eta),
((1/4 - eta/4)*(-10.*(-(1/4) - xi/4) - 10.*(1/4 - xi/4)))/(0. - 0.625*eta) +
((10.*(-(1/4) - eta/4) + 10.*(1/4 - eta/4))*(-(1/4) - xi/4))/(0. - 0.625*eta),
((1/4 - eta/4)*(0.25*(1/4 - xi/4) + 0.25*(1/4 + xi/4)))/(0. - 0.625*eta) +
((-0.25*(-(1/4) - eta/4) - 0.25*(1/4 + eta/4))*(-(1/4) - xi/4))/(0. - 0.625*eta),
((1/4 + eta/4)*(-10.*(-(1/4) - xi/4) - 10.*(1/4 - xi/4)))/(0. - 0.625*eta) +
((10.*(-(1/4) - eta/4) + 10.*(1/4 - eta/4))*(1/4 + xi/4))/(0. - 0.625*eta),
((1/4 + eta/4)*(0.25*(1/4 - xi/4) + 0.25*(1/4 + xi/4)))/(0. - 0.625*eta) +
((-0.25*(-(1/4) - eta/4) - 0.25*(1/4 + eta/4))*(1/4 + xi/4))/(0. - 0.625*eta),
((-(1/4) - eta/4)*(-10.*(-(1/4) - xi/4) - 10.*(1/4 - xi/4)))/(0. - 0.625*eta) +
((10.*(-(1/4) - eta/4) + 10.*(1/4 - eta/4))*(1/4 - xi/4))/(0. - 0.625*eta),
((-(1/4) - eta/4)*(0.25*(1/4 - xi/4) + 0.25*(1/4 + xi/4)))/(0. - 0.625*eta) +
((-0.25*(-(1/4) - eta/4) - 0.25*(1/4 + eta/4))*(1/4 - xi/4))/(0. - 0.625*eta)}};
j={{10.*(-(1/4) - eta/4) + 10.*(1/4 - eta/4), 0.25*(-(1/4) - eta/4) +
0.25*(1/4 + eta/4)}, {10.*(-(1/4) - xi/4) + 10.*(1/4 - xi/4),
0.25*(1/4 - xi/4) + 0.25*(1/4 + xi/4)}};
And finally, I call the compiled function with:
calcK[nnpe, b, d, j, t]
which produces the aforementioned error message. I'm thinking it has something to do with the fact that the "b" and "j" matrices contain "xi" and "eta". Thus, I cannot define the type in the compiled function definition.
Compile[]
to ask to much toCompile[]
. Nevertheless it would be good to have a more concise code (no more than the necessary code that reveals the problem) $\endgroup$