-
Notifications
You must be signed in to change notification settings - Fork 8
Fix evaluate() NameError with mixed MeshVariable + coordinate expressions #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,6 +292,27 @@ def _lambdify_and_evaluate(expr, coords, interpolated_results, coord_sys=None, m | |
|
|
||
| r = N.base_scalars()[0:dim] | ||
|
|
||
| # 2b. Canonicalize coordinate symbols for lambdify. | ||
| # The expression may contain UWCoordinate objects (from mesh.X or | ||
| # mesh.CoordinateSystem.unit_e_0) alongside BaseScalar objects. Since | ||
| # lambdify uses object identity to map arguments to generated code, | ||
| # we must ensure only ONE set of coordinate objects appears. | ||
| # Strategy: collect all coordinate-like symbols from the expression, | ||
| # group by index, and replace all variants with a single canonical | ||
| # sympy.Dummy symbol per coordinate. Use the same Dummy as the | ||
| # lambdify argument. | ||
| from sympy.vector.scalar import BaseScalar | ||
| coord_dummies = [sympy.Dummy(f"_coord_{i}") for i in range(dim)] | ||
| coord_subs = {} | ||
| for sym in subbedexpr.free_symbols: | ||
| if isinstance(sym, BaseScalar): | ||
| idx = sym._id[0] | ||
| if idx < dim: | ||
| coord_subs[sym] = coord_dummies[idx] | ||
| if coord_subs: | ||
| subbedexpr = subbedexpr.xreplace(coord_subs) | ||
| r = coord_dummies | ||
|
|
||
|
Comment on lines
+295
to
+315
|
||
| # 3. Handle vector/dyadic expressions | ||
| if isinstance(subbedexpr, sympy.vector.Vector): | ||
| subbedexpr = subbedexpr.to_matrix(N)[0:dim, 0] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The coordinate canonicalization currently replaces all sympy.vector.scalar.BaseScalar symbols based only on their index (
sym._id[0]). This can unintentionally rewrite BaseScalars that belong to a different coordinate system thanN(e.g.,mesh.Gamma_N.xvsmesh.N.x) and make them evaluate againstcoords_listsilently instead of failing, producing incorrect results. Consider restricting replacements to BaseScalars whose_id[1]matches theCoordSys3DinstanceN(or otherwise validating the symbol’s coordinate system) before substituting to Dummy.