Skip to content

Treat the 2D curl of a scalar function as the vector curl - #206

Open
syahra712 wants to merge 1 commit into
pyccel:masterfrom
syahra712:fix/curl-scalar-2d
Open

syahra712 wants to merge 1 commit into
pyccel:masterfrom
syahra712:fix/curl-scalar-2d

Conversation

@syahra712

Copy link
Copy Markdown
Contributor

Fixes #152.

In 2D, curl(u) of a scalar function u should be the vector curl. Two things were wrong:

  • curl(u).is_scalar was True, because Curl.__new__ marked every 2D curl as scalar.
  • TerminalExpr(curl(u), domain) raised TypeError: 'ScalarFunction' object is not subscriptable, because Curl_2d and LogicalCurl_2d compute dx(u[1]) - dy(u[0]) and so expect a vector. This also broke any form using it, e.g. integral(domain, dot(curl(u), curl(v))).

Changes:

  • Curl.__new__ (sympde/calculus/core.py): a 2D curl is scalar only when its argument is not in a ScalarFunctionSpace. This also covers minus(u) and plus(u).
  • Curl_2d and LogicalCurl_2d (sympde/topology/derivatives.py): when the evaluated argument is not a matrix, return the result of Rot_2d / LogicalRot_2d, i.e. (du/dy, -du/dx). As the issue notes, this is what rot(u) already gives. The vector case is unchanged.
  • A CHANGELOG entry under Fixed.

The curl of a vector field in 2D is still scalar, and 3D is unchanged.

Test: test_curl_scalar_2d in sympde/calculus/tests/test_calculus.py checks is_scalar for curl(u), curl(minus(u)) and curl(w), and that TerminalExpr(curl(u)) equals TerminalExpr(rot(u)). It fails on master with assert not True. I also checked by hand that the bilinear form dot(curl(u), curl(v)) gives the same terminal expression as dot(rot(u), rot(v)), and that curl(u) matches rot(u) on a domain with a PolarMapping.

pytest sympde/calculus sympde/expr sympde/topology: 158 passed, 2 skipped.

In 2D, curl(u) of a scalar function u was marked scalar, and
TerminalExpr(curl(u), domain) raised TypeError because Curl_2d and
LogicalCurl_2d index their argument as a vector. Mark it as a vector
and evaluate it like rot(u), so both give (du/dy, -du/dx).

Fixes pyccel#152

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Curl of scalar function in 2D should be vector

1 participant