This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Transfer discretized finite-dimensional problems, F(unknowns,parameters)=0, to matlab or python.

0 votes

Hi everyone,

I searched in vain for good questions/answers to the following question so let me ask it here.

In my own research I study the structure of solution sets to certain finite-dimensional algebraic problems, often in continuum mechanical problems, and typically this is done using other software packages. This type of study is often known as continuation and bifurcation analysis. In order to do so, I need the finite-dimensional description of the problems as a function handle, f(unknowns,parameters).

While it is possible to transfer the operator for linear problems, i.e., Au=b; I was wondering if there is way of transferring the discrete problems constructed by FEniCS, i.e., the nonlinear functions, preferably such as to obtain f(unknowns,parameters)=0

f:R^n \times R^k \rightarrow R^n.

Either way thanks for checking out my question.

Kinds Regards,
Michael.

asked Dec 27, 2013 by M_Elm FEniCS Novice (120 points)

1 Answer

0 votes

Nonlinear problem is in FEniCS represented symbolically using UFL language. Its discretization is obtained by applying symbolic differentiation and assembling a resulting Jacobian. Having functional Psi depending on coefficient u you can obtain its Gatueax derivative

 F = derivative(Psi, u)

and solve weak non-linear problem

solve(F == 0, u=u, bcs=bcs)

which symbolically computes Jacobian and performs Newton iteration behind the scene.

You can obtain assembled Jacobian for current value of u doing

J = derivative(F, u)
A = assemble(J)

Answer is then that non-linear problems are represented only symbolically as they can't be represented by matrix prior to linearization.

answered Dec 28, 2013 by Jan Blechta FEniCS Expert (51,420 points)

Hi Jan,

thanks for the swift reply!

I am not sure if I fail to understand what you are explaining to me or if I asked my question badly. So let me make it a bit more precise.

I do not need the derivative.

I only need the finite-dimenisonal function (nonlinear equation of residuals from the weak form), which must at some stage behind the scenes be evaluated in FEniCS. (Otherwise residuals and errors would not be possible to assess.)

In the FEniCS book jargon: Trial space functions \phi(x)\in V and Test space functions \hat{\phi}(x)\in \hat{V}. A solution u=U_i \phi_i (summation over repeated index i=1...N.).

For general linear problems the function would in general be A_{ij}U_j=b_i, and an export of the problem to matlab would simply be an export of the vector b and the matrix A. Such a representation is of course not possible for general nonlinear problems.

For nonlinear problems FEniCS must at some stage need to evaluate a more general function that takes as input (implicitly perhaps) the coefficients U_i, i.e., F(U_1,U_2,...,U_N)=0.

F(U_i) is the function I would like to export.

Ok, the residual of the equation to be solved, i.e. F == 0, is evaluated by assembling linear form F. You can get the residual vector by

r = assemble(F)

or

r = assemble(F, bcs)

or by another assembly function.

Every time you change some coefficient of F and you reassemble, you get another vector r. This is how a (non-linear) dependence of forms on its coefficients is handled.

...