I use Acegen for Finitie Element formulation that gives out residuals and tangents by taking in the field values as inputs. For this in my residual formulation I need to integrate a nonlinear term over the element Area(2D Element). For some reason, this doesn't give a result. I isolated the problem in a smaller version of the code as shown below:

<< AceGen`; NAME = "QIntegrate";
SMSInitialize[NAME, "Language" -> "Matlab", "Mode" -> "Debug"];
SMSModule[NAME, Real[ y$$[2], ue$$[4], a$$, b$$, f$$, intf$$],
  "Input" -> {y$$, ue$$, a$$},
  "Output" -> {f$$, intf$$}];
(*copy Acegen variables to Mathematica variables*)
   y2} \[RightTee] SMSReal[Table[y$$[i], {i, 2}]];
ue \[DoubleRightTee] SMSReal[Table[ue$$[i], {i, 4}]];
ue1 \[DoubleRightTee] SMSReal[ue$$[1]];
ue2 \[DoubleRightTee] SMSReal[ue$$[2]];
ue3 \[DoubleRightTee] SMSReal[ue$$[3]];
ue4 \[DoubleRightTee] SMSReal[ue$$[4]];
a \[DoubleRightTee] SMSReal[a$$];
(*Shape Functions*)
sf \[DoubleRightTee] ConstantArray[1, 4];
sf[[1]] \[DoubleRightTee] 0.25*(1 - y1)*(1 - y2);
sf[[2]] \[DoubleRightTee] 0.25*(1 + y1)*(1 - y2);
sf[[3]] \[DoubleRightTee] 0.25*(1 + y1)*(1 + y2);
sf[[4]] \[DoubleRightTee] 0.25*(1 - y1)*(1 + y2);
(*Field value interpolated at gauss point*)
uGP \[DoubleRightTee] sf . ue;
(*Non-linear function definition*)
f \[DoubleRightTee] Exp[uGP];
(*Integrate the function over the area of the element after restoring y1 and y2 dependencies*)
intf = Integrate[
   SMSSmartRestore[f, y1 | y2], {y1, -1, 1}, {y2, -1, 1}];
(*export the output variables/copy mathematica variables to AceGen \
SMSExport[f, f$$];
SMSExport[intf, intf$$];
SMSWrite[NAME, "LocalAuxiliaryVariables" -> True];
FilePrint[StringJoin[NAME, ".m"]]

This should technically run since the function is integrable. But the code doesnt give any result. Just says:

Expression contains part/parts that can not be numerically evaluated.
User subroutine: QIntegrate
Error in user input parameters for function:  SMSExport  
Input parameter:  {LARGE EXPRESSION}  
Parts that can not be evaluated:  {Undefined}
Events: 0
Version: 7.505 Linux (16 Aug 22) (MMA 13.) Module: SMSExport
See also: Symbolic-Numeric Interface  AceGen Troubleshooting  Continue

I tried many things such as: defining the exponent as a polynomial function instead of a vector multiplication

uGP \[DoubleRightTee] 
 0.25*(1 - y1)*(1 - y2)*ue1 + 0.25*(1 + y1)*(1 - y2)*ue2 + 
  0.25*(1 + y1)*(1 + y2)*ue3 + 0.25*(1 - y1)*(1 + y2)*ue4;

using SMSPower instead

f \[DoubleRightTee] SMSPower[E, uGP];

It only gives a result for:

intf = Integrate[f, {y1, -1, 1}, {y2, -1, 1}];

but here it considers the exponent as independent of y1 and y2 and gives out wrong result.


f \[DoubleRightTee] Exp[a];

where a is an independent variable

but surprisingly f=sf works with array output

f \[DoubleRightTee] Exp[sf];

I'm not able to understand the issue. Please suggest a resolution to this. I'm not sure where the problem is occuring and my entire work depends on this. Any help is extremely appreciated. Thank You!!


1 Answer 1


The result of the Integrate has to be a function, consisting only of basic functions like Power, Sqrt, Sin, Cos, Exp, Log.... that have their counterpart in C/Matlab/Fortran... You cannot export some compond function like ExpIntegralEi[...], that is included in the resulting Integral by mathematica: enter image description here

You have to write this integral in plain form for it to be exported with AceGen

  • $\begingroup$ Thanks a lot for the answer @BHudobivnik. That exactly explains the issue, but is there a way I can extract the plain form in terms of the variables ue?? I tried the same formulation in Mathematica and it gives me a result in terms of ExpIntegralEi, that too in a way that I cannot get a series expansion in terms of the variables. $\endgroup$
    – AceRox
    Commented Mar 31, 2023 at 12:22
  • $\begingroup$ Maybe you can manualy use some integration rules to make it easier for Mathematica. You also have some options like: writing the series expansion of the ExpIntegralEi (usualy one can just add as many terms as needed for double accuracy, hopefully series is convergent for your domain). You can also try rewriting your function with its series approximation. You can try numerical Gauss integration, they can be accurate enough for enough points and you only need to evaluate function at each Gauss point, no integral is needed. Otherwise a clever mathematitian might be needed to solve it $\endgroup$ Commented Mar 31, 2023 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.