Perform integrals in func

Dear FF developers,
I would like to ask you how to correct the following error,

2 :   {
3 :     Vh w;
4 :     w[] = u;
5 :     real tI;
6 :     tI = int2d(core) (w);
7 :     cout<<tI<<endl;
8 :     return tI;Impossible to cast <Pd> in <3KN_IdE>
     (        <3KN_IdE> :   <P3KNMIdE> )
     (        <3KN_IdE> :   <P2KNIdE> )

Error line number 8, in file FFutils/tilt.idp, before token ;

which comes out when I call this function inside my script,

func real[int] tilt(real[int] & u)
  {
    Vh w;
    w[] = u;
    real tI;
    tI = int2d(core) (w);
    cout<<tI<<endl;
    return tI;
  }

The variable u is defined in the main script as

fespace Vh(core,P1);
Vh  u;

My goal is to perform some integrations over the mesh involving different fespace arrays. Since I have to perform many integrations over the domain for each fespace array I define, I need to use an external function.

Thank you so much for any help
Nicolo’

tI is a real, your function is supposed to return a real[int], you either need to fix the function definition or the declaration of tI.

Thank you prj,
I am sorry for having posted an incorrect version of the code. I tried many things so I posted the wrong version…You are absolutely right, the error message that worries me is the following one, obtained when I declare that the output will be a real:

  247 :     real t1 = tilt(phi1) error operator (  <St4pairIP6FEbaseId5v_fesEiE>
 List of choices
         (        <d> :   <P2KNIdE> )

I cannot understand the variable types <St4pairIP6FEbaseId5v_fesEiE>, <d> and <P2KNIdE>, so it is quite challenging to find out the syntax error…
Thank you for your attention
Nicolo

What is phi1? Post your full (minimalist) example, otherwise we can’t help you.

I am sorry. phi1 is defined as
fespace Vh(core,P1);
Vh phi1
The minimal example (excluding the mesh generation) is

func Pk = [P1, P1];

fespace Vh(core,P1);
fespace VhV(core,Pk);
Vh  phi1, phi2, phic1, phic2, v1, v2, pow, phiTOT;

// define variational forms
varf leakage([phi1,phi2],[v1,v2]) = int2d(core) (div(DFC[0], phi1, v1) + RXS[0]*phi1*v1 - S1[2]*phi2*v1
                                                 +div(DFC[1], phi2, v2) + RXS[1]*phi2*v2 - S1[1]*phi1*v2)
                                                 +on(1,2,3,4, phi1=0, phi2=0);

varf fission([phi1,phi2],[v1,v2]) = int2d(core) (CHIT[0]*NSF[0]*phi1*v1+CHIT[0]*NSF[1]*phi2*v1
                                                 +CHIT[1]*NSF[0]*phi1*v2+CHIT[1]*NSF[1]*phi2*v2);

// build operators
matrix<real> L = leakage(VhV, VhV, tgv = tgv),
             F = fission(VhV, VhV, tgv = tgv);

Mat DistL(L, clean = true);
Mat DistF(DistL, F, clean = true);

real sigma=0;
int nev=6;
real[int] ev(nev), evc(nev); // to store nev eigenvalues
VhV<real>[int] [e1,e2](nev), [ec1,ec2](nev);   // to store nev eigenvectors

// Parameters for the distributed EigenValue solver
string ssparams = " -eps_nev " + nev       + // Number of eigenvalues
                  " -eps_type krylovschur" +
                  " -eps_target "+ sigma   + // Shift value
                  " -st_type sinvert "     +
                  " -st_pc_type lu "       +
                  " -st_pc_factor_mat_solver_type mumps" +
                  " -eps_view";      // coree problem is symmetric

int k = EPSSolve(DistL,              // matrix OP = A − sigma*B
                 DistF,              //
                 vectors = e1, // Array to store the FEM-EigenFunctions
                 values  = ev, // Array to store the EigenValues
                 sparams = ssparams  // Parameters for the distributed EigenValue solver
                 );

k=min(k,nev); // some time the number of converged eigen value can be greater than nev;

// sort eigenvalues
int[int] ind = 0:1:k-1;
phi1 = e1[ind[0]];
phi2 = e2[ind[0]];
real t1 = tilt(phi1);

No definition of tilt in your snippet: impossible to run the code => (almost) impossible to help… I guess you need to change real t1 = tilt(phi1) to real t1 = tilt(phi1[]), but I’m not sure since I can’t run the code.

I am sorry for taking it for granted but tilt is, of course, the function defined in the first post!

func real tilt(real[int] & u)
  {
    Vh w;
    w[] = u;
    real tI;
    tI = int2d(core) (w);
    cout<<tI<<endl;
    return tI;
  }

With you suggestion, now the code works fine, thank you so much for your patience and sorry for not having provided you a complete example from beginning.
If I may, I would suggest you to add a section in the docs where the variable types are specified ( <d>, <P2KNIdE> and so on). This would help a lot to fill some gaps in the docs and to help users to understand their syntax errors…
Thank you again,
Nicolo

I guess it should be real t1 = tilt(phi1[]); in the last line, since the function expects array…