I'm currently integrating the temperature gradient along a boundary by first solving (seems wrong to need a solver) for the gradient of the temperature field and then integrating with Simpson's rule. Is there a cleaner approach with the project I am missing?
I am working in c++, so I have created a ufl file just for calculating the gradient. I've seen some python snippets that do this cleanly with assembling a matrix with 'grad', but I haven't found the c++ equivalent. (I assume its a ufl -> form -> assemble?)
A general way to integrate the gradient over marked facets would be really convenient :)
Example:
UFL file for gradient
vector = VectorElement("Lagrange", triangle, 2)
scalar = FiniteElement("Lagrange", triangle, 2)
q = Coefficient(scalar)
a = inner(u,w)*dx
L = inner(grad(q),w)*dx
Then I would do a simple solve for grad_q
solve(a_grad == L_grad, grad_q);
With grad_q I would integrate along an edge, in this case the negative x-normal from (1,0) to y=(1,1)
double Qn = 0;
int points = 500;
for(int j = 0; j <= points - 1; j++)
{
double y0 = j / (double)points;
double y1 = (j+1) / (double)points;
double yab = 0.5*(y0+y1);
Point pa(x,y0);
Point pb(x,y1);
Point pab(x, yab);
Array<double> values(2);
grad_q(values, pa);
fa = -values[0]; // x-component
grad_q(values, pab);
fab = -values[0]; // x-component
(grad_q(values, pb);
fb = -values[0]; // x-component
Qn += ((y1-y0)/6.0)*(fa + 4*fab+fb);
}
This works, but only because the path is well defined and the normal is also well defined. I'm thinking of an unstructured/curved boundary where I would need to integrate along the facets point to point and calculate the normal components as being painful.
If there was a way to integrate a Function (not necessarily gradient) along a marked boundary that would help, unless I am missing a more direct method?