BUG: Are facet normals correct for periodic rectangle meshes of width 1 or 2?

オープン
#5,266 コメント 1 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@connorjward がすでに取り組んでいます。

2026年7月21日 から。

評価

この issue はまだ評価されていません。

説明

bug

One of the Gusto "case study" tests seems to have been failing since we picked up the Firedrake 2026.04.1 release. The Skamarock-Klemp hydrostatic gravity wave uses a PeriodicRectangleMesh which is 1 cell wide in the y-direction.

The pressure gradient is calculated via a term which includes cp*avg(exner)*jump(theta*w, n)*dS_v, where:
cp is the specific heat capacity at constant pressure, exner is the "Exner" pressure, theta is the potential temperature, w is the velocity test function and n is the FacetNormal. In our test, the pressure gradient in the y-direction should be essentially zero, but this term now seems to be enormous and causes the model to blown up in the first timestep.

I think the issue is that there has been a change in behaviour for FacetNormal on the PeriodicRectangleMesh, specifically when the mesh is only 1 or 2 cells wide.

To investigate this, I checked whether n takes equal but opposite values on the '+' and '-' sides of each facet. It seems that for the PeriodicRectangleMesh it now doesn't when the mesh is 1 or 2 cells wide.

I wonder if this was a side effect of #4836?

If I change the Gusto test to use a width of 3, it runs successfully.

Here is an MFE:

"""
Minimum failing example demonstrating that facet normals are not computed
correctly on periodic meshes of widths 1 or 2.

Facet normals on the '+' and '-' sides of a facet should sum to zero, as they
should be of equal size but opposite direction.

At the time of writing, this test passes for a width of 3 or more but fails
for a width
of 1 or 2.
"""

from firedrake import (
    PeriodicRectangleMesh, FunctionSpace, Function, FacetNormal,
    TestFunction, TrialFunction, inner, dS,
    LinearVariationalProblem, LinearVariationalSolver, VTKFile
)
import numpy as np

to_output = False
mesh_widths = [4, 3, 2, 1]  # Number of cells in y-direction

for width in mesh_widths:
    # Periodic rectangle mesh
    mesh = PeriodicRectangleMesh(5, width, 10.0, 10.0/width, quadrilateral=True)

    # RTCF1 has one degree of freedom per facet
    HDiv = FunctionSpace(mesh, "RTCF", 1)

    n = FacetNormal(mesh)
    psi = TestFunction(HDiv)
    p = TrialFunction(HDiv)
    n_plus = Function(HDiv, name='n_plus')    # Takes value of n on + side
    n_minus = Function(HDiv, name='n_minus')  # Takes value of n on - side
    n_sum = Function(HDiv, name='n_sum')      # Sum of n+ and n-

    # Project the facet normals onto the HDiv space
    # As psi and p are continuous, their label on the facet doesn't matter
    a = inner(p('+'), psi('+'))*dS
    L_plus = inner(n('+'), psi('+'))*dS
    L_minus = inner(n('-'), psi('+'))*dS
    problem_plus = LinearVariationalProblem(a, L_plus, n_plus)
    problem_minus = LinearVariationalProblem(a, L_minus, n_minus)
    solver_plus = LinearVariationalSolver(problem_plus)
    solver_minus = LinearVariationalSolver(problem_minus)
    solver_plus.solve()
    solver_minus.solve()

    n_sum.project(n_plus + n_minus)

    if to_output:
        output = VTKFile(f"facet_normals_{width}.pvd")
        output.write(n_plus, n_minus, n_sum)

    assert np.allclose(n_sum.dat.data_ro, 0.0, 1e-16), \
        f"Facet normals do not sum to zero for mesh width {width}"
主要言語
Python
スター
684
フォーク
204
平均マージ
4日 14時間
マージ済み PR(30日)
46

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firedrakeproject/firedrake のほかの issue

firedrakeproject/firedrake の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。