3. Weak forms and finite elements
How can straight segments solve a curved problem?
Section titled “How can straight segments solve a curved problem?”A finite-element solution may be piecewise linear even when its differential equation contains a second derivative. Within each segment that second derivative is zero. How can it represent a nonzero source?
The answer is to ask the equation to hold in an integrated sense. We will derive that statement, construct one element, and run a mesh comparison. For physical context, can represent a scaled temperature difference in steady conduction.
Predict a field before discretizing
Section titled “Predict a field before discretizing”Use a unit interval and dimensionless coordinate , with . The scaled problem is
Here primes denote differentiation with respect to . Direct substitution gives , so the field is symmetric, positive inside the interval, and has maximum 1 at the center. Its endpoint derivatives are and .
The .eqi source below uses dimensional : its wave number is and
source scale is . Keeping these scales explicit makes the sine’s
argument dimensionless.
Move one derivative onto a test function
Section titled “Move one derivative onto a test function”Multiply by a test function vanishing at both endpoints and integrate:
The boundary term vanishes because vanishes there. The weak problem is therefore: find a function satisfying the endpoint values such that
Only first derivatives now appear. Continuous piecewise linear functions have square-integrable first derivatives even though their slopes jump at nodes. That makes them admissible trial functions. A formal account of the spaces and boundary traces is in Schöberl’s weak formulation of Poisson’s equation.
Build one element
Section titled “Build one element”On an element of length , take
Their derivatives are and . Integrating each product of derivatives gives the element matrix
Notice two structural facts before looking at any output. The matrix is symmetric, and each row sums to zero. A constant local field therefore creates no diffusive flux. Essential endpoint values remove the global constant nullspace in this problem.
Assembly is addition at shared nodes
Section titled “Assembly is addition at shared nodes”Two neighboring elements contribute to the equation at their common node. On a uniform interior mesh their stiffness contributions produce
For constant , , giving the familiar centered second difference after division by . For a variable source, keep the integrated load: replacing it by is an additional approximation.
As a hand calculation, use and two elements of length . The sole interior equation is , so . The exact solution also has value there. Between the nodes the numerical field is still linear, while the exact field is curved. Exact nodal values do not imply an exact field.
Express the equation and run
Section titled “Express the equation and run”model manufactured_poisson() { domain interval = box(0, 1); domain lower_end = boundary(interval, axis = 0, side = lower); domain upper_end = boundary(interval, axis = 0, side = upper);
variable potential: 1 on interval; parameter wave_number: 1 / m = 3.141592653589793; parameter source_scale: 1 / m ^ 2 = 9.869604401089358;
relation balance on interval { -div(grad(potential)) - source_scale * math.sin(wave_number * coordinate(0)) = 0; } relation lower_value on lower_end { trace(potential) = 0; } relation upper_value on upper_end { trace(potential) = 0; }}From the source checkout created in Get started:
cargo run -p eqiora-numerics --example poisson_convergenceRead fem_l2 first. It measures the error in the continuous piecewise linear
field, integrated over the interval. The comparison program runs meshes with
8, 16, 32, 64, and 128 cells. Predict a decreasing error before reading it;
the refinement lesson
derives the order calculation.
The complete run program reads this equation and compares finite elements with finite volumes. The choice of approximation belongs to the computation, while the source states the mathematical problem.
For Python applications, the corresponding choice is
eqiora.fem.Q1(). In one dimension it gives the
linear construction just derived. On Cartesian rectangles, Q1 uses products
of one-dimensional linear basis functions; the resulting fields are bilinear
within each cell. This product structure also explains why mesh geometry and
quadrature matter.
Essential and natural conditions
Section titled “Essential and natural conditions”We imposed endpoint values by restricting the trial field and taking zero test values there. These are essential conditions. If a test function is allowed to be nonzero at an endpoint, the integration-by-parts boundary term remains and carries derivative or flux data: this is the origin of a natural condition. Always derive its sign using the outward normal. Do not silently drop that term on a boundary where the field value is free.
Exercises
Section titled “Exercises”- Assemble the matrix for three equal elements with zero endpoint values. Which entries receive contributions from two elements?
- For the two-element constant-source example, evaluate the numerical and exact fields at . Explain their difference despite the exact midpoint value.
- Show that for a nonzero piecewise linear function with zero endpoint values. Why does removing both endpoint constraints change this?
- Derive the boundary term when the right endpoint derivative is prescribed. State separately the outward diffusive flux .
- In two dimensions, write the four products of linear basis functions on a unit square. Check that they sum to one.
Previous: Time integration · Book map · Next: Finite-volume balance