Issue with gradient inner product

Hi,

I am trying to implement a weighted version of the inner product (u * grad u * v),
where u = (u1, u2, u3) is a three-dimensional TrialFunction and v is a 3D TestFunction. Since it should be weighted (w1, w2, w3 constants), I am trying to use
w1* inner(u, grad(u1)) * v1 * dx + w2* inner(u, grad(u_prev2)) * v2 * dx +
w3*inner(u, grad(u_prev3)) * v3 * dx,
which gives me the “ValueError: too many values to unpack (expected 2)” error.
The dimensions seem to be ok to me, e.g. u is three-dimensional, u1 is 1D, thus grad(u1) is 3D.

Could someone maybe give me a hint?

Thank you so much!
Nora

Hi,
inner(u, grad(u1))*v1*dx makes no sense if u=(u1,u2,u3) is a TrialFunction. What you are certainly looking for is to solve a nonlinear problem with u being a Function. Checkout the nonlinear demos
https://fenicsproject.org/docs/dolfin/2019.1.0/python/demos/nonlinear-poisson/demo_nonlinear-poisson.py.html
http://home.simula.no/~hpl/homepage/fenics-tutorial/release-1.0-nonabla/webm/nonlinear.html

2 Likes

Thank you so much for your answer. I am trying to understand when to categorise the unknown function as “Function” or “TrialFunction”. TrialFunction is for linear problems and Function is used for nonlinear ones? So if I am looking for a p-u pair with the problem being nonlinear in u and linear in p, one unknown function classifies as Function and the other as TrialFunction? Thank you again.

Not exactly, TrialFunctions are used to define bilinear forms a(u,v) with u,v \in V being respectively the trial and test functions. a(u,v) is represented as a matrix after assembly. Linear or non-linear forms F(v) are defined using TestFunctions but may also depend on the unknown Function w\in V in the case of non-linear problems, in this case F(v) = (G(w),v). When assembled, they are represented by a vector which may depend on the Function w.

FEniCS can solve a linear problem in two different ways:

  • bilinear/linear forms: a(u,v)=L(v) for all v\in V with w the solution
  • residual form: F(v) = a(w, v)-L(v) = 0 for all v\in V, in this form no TrialFunction appears
    In the second case, FEniCS will treat it as a nonlinear problem F(v) and will use a Newton method for finding a solution, this is done by computing the Jacobian (derivative of F with respect to w) along a TrialFunction direction u: J(u,v) = derivative(F, w, u), the Newton system is then in the bilinear/linear form with J being the bilinear form

For you u-p problem, the formulation will depend if you want to solve it in a monolithic fashion (both u and p at the same time) or in a staggered fashion (solve p at fixed u then solve for u at fixed p, then iterate possibly). In the first case, you will have to formulate your coupled problem as a non-linear one (both u and p as Functions, then compute the Jacobian with respect to the (u,p) pair). In the second case, you can define the linear p-problem in any of the two above-mentioned ways with a fixed u Function and then formulate the u-problem as a non-linear problem with a fixed p Function.
Hope this helps.

3 Likes