> On 18 Sep 2015, at 10:29, Justin Chang <jychang48@gmail.com> wrote:
>
> Hi Lawrence,
>
> So I attempted what you had suggested but I am getting these nasty errors,
> which I do not understand at all:
...
> ===========
>
> When I look at the error log, it says "error: use of undeclared identifier
> 'Nvals'". I attached the working code. How do I declare that value?
Ah, I see. I intended you to replace that with the number of components your reaction system has! Since these appear to be scalars, you could replace Nvals with 1. Or else, if you want to be a little more generic do something like this:
species_kernel = op2.Kernel("""
// Solve reactions at each nodee
void solve_system(const double psi_A, const double psi_B, const double k1,
double *c_A, double *c_B, double *c_C) {
*c_A = (sqrt(pow(psi_A*k1 - psi_B*k1 - 1,2) + 4*psi_A*k1) + psi_A*k1 - psi_B*k1 - 1)/(2*k1);
*c_B = (sqrt(pow(psi_A*k1 - psi_B*k1 - 1,2) + 4*psi_A*k1) - psi_A*k1 + psi_B*k1 - 1)/(2*k1);
*c_C = (sqrt(pow(psi_A*k1 - psi_B*k1 - 1,2) + 4*psi_A*k1) + psi_A*k1 + psi_B*k1 + 1)/(2*k1);
}
// Iterate through the node
void solve_kernel(const double *psi_A, const double *psi_B, const double *k1,
double *c_A, double *c_B, double *c_C) {
const int Nvals = %(nvals)d;
for (int i = 0; i < Nvals; i++) {
solve_system(psi_A[i],psi_B[i],k1[0],&(c_A[i]),&(c_B[i]),&(c_C[i]));
}
}
""" % {'nvals': Q.dof_dset.cdim}, "solve_kernel")
So all I've done here is declare:
const int Nvals = %(nvals)d;
in the kernel, and use the format spec to replace the assignment by whatever the correct value is (Q.dof_dset.cdim). So the code the compiler sees will now be:
const int Nvals = 1;
for (int i = 0; i < Nvals; i++) {
...;
}
Rather than previously where Nvals was never declared.
Hope this works!
Lawrence
_______________________________________________
firedrake mailing list
firedrake@imperial.ac.uk
https://mailman.ic.ac.uk/mailman/listinfo/firedrake