Going Variational
Motivation and context
How to solve PDEs with modern tools
Challenges I faced
- There are tons of good resources about the FEM, its theory and practical applications and the material is indeed overwhelming. Here some books that built my path towards a medium understanding of what I’m doing:
- Zienkiewicz and Taylor 2006 - The Finite Element Method for Solid and Structural Mechanics.
- Lanczos 1949 - The Variational Principles of Mechanics.
- Madier 2020 - Practical Finite Element Analysis for Mechanical Engineers.
Structural analogy
- As many other complex tools, the FEM method was not invented by mathematicians. Mathematicians made a strong tool out of an original idea developed in the last century by structural engineers.
- I’m convinced this happens because need is the mother of invention and structural engineers of the past century really started to need to predict how their structure behaved before they build and test them as those structures became more and more complex and the testing conditions more and more dangerous.
- This is why usually in formal textbooks the FEM is introduced with a structural analogy: take a complex structure, divide it in multiple sub-elements each with its stiffness and its bounding points to track the displacement of and solve a complex problem by expressing it in matrix form. Done. Nice.
- While this explanation is actually legit it has its limitations as one tries to better understand what is going on under the hood of a FEM software or, as in my case, while developing a new formulation for a mechanical problem involving modification to the problem PDEs.
- In these cases mathematicians really shine for their competences as the tool they created from the engineers ideas is robust, flexible and fool-proof.
- As said by Chris Staecker, a very undervalued youtuber, Math is the process of taking an idea and polishing it so good that it becomes to shine like a star.
- Variational formulation of a PDE problem can be leveraged to solve any kind of problem, even in cases in which the structural analogy lacks its meaning.
Starting from a strong differential form
- Take a PDE problem in its differential form
- Multiply by a function v (called a test function)
- This function has to have certain characteristics, mathematicians would say it has to be an Hilber function
- As far as I understand it has to be bounded, which means that the value of the integral of the function squared (and for some reasons also of the modulus of the gradient of the function squared) has to be less than infinite
- Note that this clarification is crucial, if the test function is taken in the wrong space the solution is meaningless. Take the spaces of all functions equal to zero and you will get that anything can be the solution to the PDE problem.
- Also note that this step is the equivalent in function vector spaces of a projection of the problem on the space of test functions
- This function has to have certain characteristics, mathematicians would say it has to be an Hilber function
- Use integration by parts in order to take out some complexity
- Integration by parts is extremely useful cause it allow to express an integral over a domain as the sum of two terms, one in which a derivative is present (usually that weakens the problem a bit), the other in which the integral is taken over the boundary of the domain instead of the domain itself. This is usually an advantage as problems of this kind come with specifications to what happens to the function at the boundary
- Now express the solution function, also referred to as trial function, and the test function as linear combination of basis functions.
- The concept of a basis function is somehow intimidating, but it is actually just a way to express a function in an approximated form. In this case the approximation leverages the concept of a vector space.
- Everything is much simpler if you think of it the same way you think of a generic vector in its vector space projected to the axes of the space. The basis function are the axes of a space of functions, it basis indeed.
- The choice of the expression of a basis function is a tricky point. Take a mechanical problem for example. The unknown is usually a displacement, its derivative is a strain which can be directly proportional to a stress. If the basis function is linear the corresponding derivative and thus stress and strain, will be continuous in the element and consequently discontinuous between elements. This is why it is usually a bad choice to use linear triangular elements for mechanical problems (this and other tricky stuff such as uncompressibility).
- Note that the projection over the space of trial functions and the use of a finite dimensional vector spaces to represent the trial and test functions is crucial to obtain a suitable form in linear algebra matrix vector terms.
- The concept of a basis function is somehow intimidating, but it is actually just a way to express a function in an approximated form. In this case the approximation leverages the concept of a vector space.
- The use of two sets of functions and of their representation using basis functions naturally brings to the expression of the problem in linear algebra matrix form. Now the unknowns are the coefficients of the linear combination representing the trial function.
- Note that the computation of the matrix components requires the integration of the basis functions, here things start to become really tricky.
- The basis functions are usually polynomials so it is possible to compute the integral using a quadrature formula, usually Gauss quadrature formula. This actually breaks the variational theory and the proof of existence of a solution that mathematicians developed.
- This is known as a variational crime (no joking here, Gilber Strang coined the term) but integrals have to be computed and a little breaking the rules causes no harm… if you are aware of what you are doing!
- Poor choice of basis functions and quadrature formulas can lead to problems with the rank of the solution matrix!
- The basis functions are usually polynomials so it is possible to compute the integral using a quadrature formula, usually Gauss quadrature formula. This actually breaks the variational theory and the proof of existence of a solution that mathematicians developed.
Starting from a weak integral form
- Think of the integral form of the problem as an energy quantity, this is usually how the integral form itself has been written down.
- Most of the times the physical principle underneath an equation is integral itself, the differential form is just an extrapolation which is used to bring some insights in the problem not really visible in the potential form.
- The solution of the underneath PDE problem is usually an equilibrium state which corresponds to the condition of minimum of the energy integral
- As in any other minimization problem just take the first derivative and set it equal to zero.
- In taking the derivative consider using the chain rule to take into account all the possible unknowns of the problem.
- This derivative I’m talking about is sometimes referred to as a variation and expressed with a different symbol then the usual derivative, it can indeed be considered as a small variation of the unknown, remember from calculus that in the small neighborhood of a maximum or minimum the tangent is actually with a zero slope, zero increment of energy for small variation.
- Careful: in this form the differentials of the unknowns are basically the test functions while the unknowns themselves in the formulation are the trial functions.
- Indeed in the literature it is possible to find derivations of weak forms from strong ones in which the test functions symbol is that of a variational differential.
- Just to conclude, a quick but insightful remark on terminology.
- From a mathematical point of view the first derivative of the energy integral is more correctly called first variation. This because this operation is framed in the variational theory which assures consistence and meaning from strong math grounds.
- Given a functional operating on functions and returning scalar values, consider as input to the functional a linear combination of a test function and a trial function where the coefficients of the linear combination are one for the trial and a small parameter for the test.
- The first variation of the functional is the value calculated for the limit of the small t parameter to 0.
- Trying to give an intuitive interpretation to this operation consider the functional as an energy quantity, as usual in the applications, and suppose we’re looking for a function u which minimizes this functional expression, this is the case in a lot of engineering problems.
- How to find the u that minimizes the functional? Try with a generic u, let’s call it a trial function, and poke around in a small surrounding of u to see if u satisfies the condition we pose in the minimization problem.
- This poking could be i.e. sum to the trial another generic function v, let’s call it test, of small value… or better let the value be generic and let’s multiply it for a small parameter t, then for the limit of the small parameter t to 0 if the trial u is still minimizing the potential functional then it is actually a solution to our problem!
- How to find the u that minimizes the functional? Try with a generic u, let’s call it a trial function, and poke around in a small surrounding of u to see if u satisfies the condition we pose in the minimization problem.
- To summarize we took a potential functional, considered a possible solution to the problem of minimizing this functional with a trial function and checked if the trial is actually a solution to the minimization problem using a test function.
- This seems like a good justification for the terminology used in variational formulations and the Finite Element Method approach and an easy way to understand and fix these concepts.
- From a mathematical point of view the first derivative of the energy integral is more correctly called first variation. This because this operation is framed in the variational theory which assures consistence and meaning from strong math grounds.
Useful lessons I learned
- The concepts described above are important in order to understand the whole picture of the variational approach but in the FEM practice, writing a solver from scratch, the attention is driven by other aspects of the approach and other details difficult to catch but with the potential of breaking the whole process.
- This is why I decided to try to write my own solver [[FEM1elem]] and get a better understanding not only of the overlying principles but also of all the implementation details.
- That’s it! I hope this information would turn out useful to anyone.