Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Análise de Erros e Verificação

LNCC - Laboratório Nacional de Computação Científica

Para verificar a implementação do método de elementos finitos, calculamos erros entre a solução numérica uhu_h e a solução exata uu.

Normas de Erro

Definimos as seguintes normas de erro:

Norma L2L^2

∥e∥L2(Ω)=∫Ω(u−uh)2 dx\|e\|_{L^2(\Omega)} = \sqrt{\int_\Omega (u - u_h)^2 \, d\mathbf{x}}

Para calcular numericamente:

∥e∥L22≈∑K∫K(u−uh)2 dx=∑K∑qwq∣u(xq)−uh(xq)∣2∣JK(x^q)∣\|e\|_{L^2}^2 \approx \sum_{K} \int_K (u - u_h)^2 \, d\mathbf{x} = \sum_{K} \sum_q w_q |u(\mathbf{x}_q) - u_h(\mathbf{x}_q)|^2 |J_K(\hat{\mathbf{x}}_q)|

onde:

Seminorma H1H^1 (Gradiente)

∣e∣H1(Ω)=∫Ω∣∇(u−uh)∣2 dx|e|_{H^1(\Omega)} = \sqrt{\int_\Omega |\nabla(u - u_h)|^2 \, d\mathbf{x}}

Numericamente:

∣e∣H12≈∑K∑qwq∣∇u(xq)−∇uh(xq)∣2∣JK(x^q)∣|e|_{H^1}^2 \approx \sum_{K} \sum_q w_q |\nabla u(\mathbf{x}_q) - \nabla u_h(\mathbf{x}_q)|^2 |J_K(\hat{\mathbf{x}}_q)|

onde:

∇uh(xq)=∑iui∇Ni(xq)\nabla u_h(\mathbf{x}_q) = \sum_i u_i \nabla N_i(\mathbf{x}_q)

Norma H1H^1 (Completa)

∥e∥H1(Ω)=∥e∥L22+∣e∣H12\|e\|_{H^1(\Omega)} = \sqrt{\|e\|_{L^2}^2 + |e|_{H^1}^2}

Norma do Máximo (L∞L^\infty)

∥e∥L∞(Ω)=max⁡x∈Ω∣u(x)−uh(x)∣\|e\|_{L^\infty(\Omega)} = \max_{\mathbf{x} \in \Omega} |u(\mathbf{x}) - u_h(\mathbf{x})|

Aproximadamente:

∥e∥L∞≈max⁡i∣u(xi)−ui∣\|e\|_{L^\infty} \approx \max_i |u(\mathbf{x}_i) - u_i|

onde a maximização é feita sobre todos os nós.

Taxas de Convergência

Para uma família de malhas com tamanho característico h→0h \to 0, esperamos:

∥u−uh∥L2=O(hp+1)\|u - u_h\|_{L^2} = \mathcal{O}(h^{p+1})
∣u−uh∣H1=O(hp)|u - u_h|_{H^1} = \mathcal{O}(h^p)

onde pp é o grau polinomial do espaço de elementos finitos:

Estimativa Experimental da Taxa

Para estimar a taxa de convergência experimentalmente, considere duas malhas com tamanhos h1>h2h_1 > h_2:

taxa=log⁡(E1/E2)log⁡(h1/h2)\text{taxa} = \frac{\log(E_1 / E_2)}{\log(h_1 / h_2)}

onde E1E_1 e E2E_2 são os erros correspondentes.

Se plotarmos log⁡E\log E vs log⁡h\log h, a inclinação da reta é a taxa de convergência.

Method of Manufactured Solutions (MMS)

Para verificar a implementação:

  1. Escolha uma solução exata u(x)u(\mathbf{x}) suave

  2. Calcule o termo fonte correspondente:

    f(x)=−∇2u(x)f(\mathbf{x}) = -\nabla^2 u(\mathbf{x})
  3. Resolva o problema de elementos finitos com ff e condições de contorno g=u∣∂Ωg = u|_{\partial\Omega}

  4. Calcule os erros comparando uhu_h com uu

  5. Verifique as taxas de convergência refinando a malha

Exemplo 1D

Solução manufaturada:

u(x)=sin⁡(πx)u(x) = \sin(\pi x)

Termo fonte:

f(x)=−u′′(x)=π2sin⁡(πx)f(x) = -u''(x) = \pi^2 \sin(\pi x)

Condições de contorno em [0,1][0, 1]:

u(0)=0,u(1)=0u(0) = 0, \quad u(1) = 0

Exemplo 2D

Solução manufaturada:

u(x,y)=sin⁡(2πx)sin⁡(2πy)u(x, y) = \sin(2\pi x) \sin(2\pi y)

Termo fonte:

f(x,y)=−∇2u=8π2sin⁡(2πx)sin⁡(2πy)f(x, y) = -\nabla^2 u = 8\pi^2 \sin(2\pi x) \sin(2\pi y)

Condições de contorno em [0,1]×[0,1][0, 1] \times [0, 1]:

u=0 em ∂Ωu = 0 \text{ em } \partial\Omega

Teste de Convergência

Algoritmo típico:

for h in [h1, h2, h3, ...]:  # Sequência de malhas cada vez mais finas
    mesh = create_mesh(h)
    A = assemble_stiffness(mesh, space)
    b = assemble_load(mesh, space, f)
    A_bc, b_bc = apply_dirichlet_bc(A, b, mesh, g)
    u_h = solve(A_bc, b_bc)

    error_L2 = compute_L2_error(u_h, u_exact, mesh, space)
    error_H1 = compute_H1_error(u_h, u_exact, grad_u_exact, mesh, space)

    print(f"h={h:.4f}, L2={error_L2:.6e}, H1={error_H1:.6e}")

# Plotar log(erro) vs log(h) e verificar inclinação

Para elementos P1/Q1, esperamos:

Implementação no fempack

O módulo fempack.verification fornece:

Exemplo:

from fempack.verification import compute_l2_error, compute_h1_error

error_L2 = compute_l2_error(u_h, mesh, space, u_exact)
error_H1 = compute_h1_error(u_h, mesh, space, u_exact, grad_u_exact)

print(f"||e||_L2 = {error_L2:.6e}")
print(f"|e|_H1 = {error_H1:.6e}")

Os notebooks em notebooks/ demonstram estudos completos de convergência para diferentes tipos de elementos.