Skip to content

Ft stokes collocation iga#490

Merged
clemens-fricke merged 8 commits into
developfrom
ft-stokes-collocation-iga
May 22, 2026
Merged

Ft stokes collocation iga#490
clemens-fricke merged 8 commits into
developfrom
ft-stokes-collocation-iga

Conversation

@jzwar

@jzwar jzwar commented May 10, 2026

Copy link
Copy Markdown
Collaborator

Overview

Test stokes example with L2-IGA-collocation based on the example in Finite Element Methods for Flow Problems by Donea and Huerta (Chapter 6.8.1, p. 306).!

Thanks to @danielwolff1 for finding the bug.

Addressed issues

None. This PR mainly adds a showcase/example problem and I had too much free time...

This is the output:
image

Feedback and further improvements are welcome.

Summary by CodeRabbit

  • Documentation
    • Added a comprehensive example demonstrating a sparse-collocation Stokes solver with mixed spline velocity/pressure spaces, analytic source terms and boundary profiles, assembly of a sparse coupled operator, optional pressure constraint handling, least-squares solution and mapping back to splines, sparsity-pattern and field visualizations, analytic solution/error computation, and residual-based loss functions.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 10, 2026

Copy link
Copy Markdown

Walkthrough

This PR adds a complete example script that demonstrates a collocation-based approach to solving the Stokes flow problem using splinepy mixed velocity/pressure splines on the unit square. The script constructs refined B-spline spaces, assembles sparse coupled equations, imposes boundary conditions, solves the system, and visualizes solutions and error fields.

Changes

Sparse Stokes Collocation Example

Layer / File(s) Summary
Geometry and spline space construction
examples/iga/collocation_stokes_problem_sparse.py (lines 1–47)
Defines script parameters (viscosity, mass factor, pressure-BC toggle), constructs unit-square B-spline reference geometry, and builds degree-elevated pressure and velocity spaces for the mixed formulation.
Analytic problem definition & mappers
examples/iga/collocation_stokes_problem_sparse.py (lines 48–102)
Defines source functions for u and v momentum equations, velocity Dirichlet boundary conditions, pressure boundary profile, computes Greville abscissae for collocation, and instantiates mappers for u/v/p.
Collocation operator assembly
examples/iga/collocation_stokes_problem_sparse.py (lines 103–164)
Assembles block-structured sparse matrices for Laplacian-based velocity terms, pressure gradient coupling, and divergence/mass-factor equations; constructs corresponding RHS vectors.
Boundary condition imposition and system finalization
examples/iga/collocation_stokes_problem_sparse.py (lines 166–258)
Builds evaluation-point indices and basis/support matrices for velocity Dirichlet constraints, optionally appends pressure BC constraints, and finalizes augmented RHS and block-matrix list.
Sparse solving and solution mapping
examples/iga/collocation_stokes_problem_sparse.py (lines 259–293)
Assembles the global sparse block matrix with bmat, solves the least-squares system via scipy.sparse.linalg.lsqr, prints solver diagnostics, maps the solution vector back into control points, and visualizes the sparsity pattern.
Analytic solutions and error computation
examples/iga/collocation_stokes_problem_sparse.py (lines 296–385)
Defines analytic exact solutions for velocity and pressure, computes absolute error fields, applies pressure constant-offset correction when BCs are not imposed, and configures splinepy adaptors for visualization.
Residual loss functions and field rendering
examples/iga/collocation_stokes_problem_sparse.py (lines 387–445)
Defines residual-based loss functions for u/v/p using mapper differential operators and source terms, and renders solution, error, and loss fields via sp.show.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I hopped through splines and sparse arrays bright,
Collocation points guiding each tiny flight,
Velocity, pressure—mixed steps align,
LSQR hums, errors plot in soft light,
A rabbit's nod: the example runs right.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Ft stokes collocation iga' is vague and uses non-descriptive abbreviations (Ft, iga) that don't clearly convey the main change to someone unfamiliar with the project context. Expand the title to be more descriptive, such as 'Add L2-IGA-collocation Stokes example' or 'Add sparse collocation Stokes problem example' to clearly indicate that this adds a new example.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description includes overview, addressed issues, showcase image, but is missing explicit documentation checklist items and does not provide a code snippet showcase as specified in the template.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ft-stokes-collocation-iga

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jzwar jzwar added enhancement New feature or request help wanted Extra attention is needed testing All about software testing labels May 10, 2026
Comment thread examples/iga/collocation_stokes_problem_sparse.py Outdated
@jzwar jzwar marked this pull request as ready for review May 17, 2026 11:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/iga/collocation_stokes_problem_sparse.py`:
- Around line 309-315: The factory function error_u currently defines and
returns an inner function also named error_u, which shadows the outer name;
rename the inner function to something like _error_u or compute_error (and
similarly rename inner functions in error_v and error_p) to avoid shadowing,
update the inner function body to call solution_u.evaluate(on) and
analytical_solution_u(data, on) as before, and return the renamed inner function
so all callers of the outer factory continue to receive the correct closure
without ambiguous symbol names.
- Around line 414-417: The loss_function_p currently returns a signed
divergence: mass_factor * (mapper_u.gradient(on)[:, 0, 0] +
mapper_v.gradient(on)[:, 0, 1]); change it to return the absolute value to match
loss_function_u/v and the plot label by wrapping the whole expression with
np.abs (use numpy imported as np), i.e., compute the divergence via
mapper_u.gradient and mapper_v.gradient as before, multiply by mass_factor, then
apply np.abs before returning from loss_function_p.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3306b836-2555-47d5-a8d3-1fa472d0e01b

📥 Commits

Reviewing files that changed from the base of the PR and between b2fe81e and c0b7103.

📒 Files selected for processing (1)
  • examples/iga/collocation_stokes_problem_sparse.py

Comment thread examples/iga/collocation_stokes_problem_sparse.py Outdated
Comment thread examples/iga/collocation_stokes_problem_sparse.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
examples/iga/collocation_stokes_problem_sparse.py (1)

152-159: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Comment typo: this row is dvdy, not dvdx.

The third block-matrix row is the continuity equation ∂u/∂x + ∂v/∂y = 0, and the code correctly indexes gradient_v[:, :, 1] (i.e., ∂v/∂y). The comment on line 152 still labels it A_v_tp dvdx, which mislabels the term and is inconsistent with line 144 (A_u_tp dudx).

📝 Proposed fix
-# A_v_tp dvdx
+# A_v_tp dvdy
 gradient_v, support_v = mapper_v.basis_gradient_and_support(greville_points_p)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/iga/collocation_stokes_problem_sparse.py` around lines 152 - 159,
The inline comment labeling the third block-matrix row is incorrect: change the
comment "A_v_tp dvdx" to "A_v_tp dvdy" (or "A_v_tp ∂v/∂y") to match the indexed
gradient component gradient_v[:, :, 1] used when building A_v_tp (created from
mapper_v.basis_gradient_and_support and mass_factor and
solution_field_velocity_v.cps). Ensure the updated comment mirrors the style of
the corresponding "A_u_tp dudx" comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@examples/iga/collocation_stokes_problem_sparse.py`:
- Around line 152-159: The inline comment labeling the third block-matrix row is
incorrect: change the comment "A_v_tp dvdx" to "A_v_tp dvdy" (or "A_v_tp ∂v/∂y")
to match the indexed gradient component gradient_v[:, :, 1] used when building
A_v_tp (created from mapper_v.basis_gradient_and_support and mass_factor and
solution_field_velocity_v.cps). Ensure the updated comment mirrors the style of
the corresponding "A_u_tp dudx" comment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 85170967-18f6-4ba9-b5ce-4628dc5a6b12

📥 Commits

Reviewing files that changed from the base of the PR and between c0b7103 and 6a1ddf1.

📒 Files selected for processing (1)
  • examples/iga/collocation_stokes_problem_sparse.py

@clemens-fricke clemens-fricke changed the base branch from main to develop May 22, 2026 10:09

@clemens-fricke clemens-fricke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good thank you @jzwar for starting this and providing this very nice example, and thank you @danielwolff1 for looking over it and finding the error.

@clemens-fricke clemens-fricke merged commit b92b922 into develop May 22, 2026
27 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request help wanted Extra attention is needed testing All about software testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants