Skip to content

Conversation

@hverhelst
Copy link
Member

@hverhelst hverhelst commented Oct 21, 2025

Improved support for preconditioners and multigrid:

  • Add gsSparseSolver<>::CGCustom, which is an Eigen iterative solver of which we can set the preconditioner from a gsPreconditioner. It is implemented via the gsPreconditionerWrapper, which wraps a gsPreconditioner into a format supported by Eigen.
typename gsSparseSolver<>::CGCustom solver;
solver.preconditioner().set(makeJacobiOp(mat));
  • Add solveWithGuess interface to Eigen's IterativeSolverBase solvers
  • Add gsGridHierarchy methods for hierarchical splines
  • Make the transfer matrix for gsHSplines a RowMajor by default. This is the format which is also used inside the grid hierarchy for Multi-Grid.
  • Add XML support for RowMajor sparse matrices

NEW:
Hierarchical spline support in gsGridHierarchy.
Add refineToLevel, refineCoarsestLevel, unrefineToLevel and unrefineFinestLevel to gsHTensorBasis

IMPROVED:
Template specialization for Gauss-Seidel preconditioner
Add more constructors to gsDofMapper, and make all mapper methods in gsMultiBasis and gsFeSpace use these constructors


  • Have you added an explanation of what your changes do and why
    you'd like us to include them?
  • Have you documented any new codes using Doxygen comments?
  • Have you written new tests or examples for your changes?

- Functions for refinement and coarsening of finer /coarser levels in gsHTensorBasis
- Multi-component DofMapper support for gsMultibasis::getMapper
- Initialization of DoFmapper using BCS (taken from gsFESpace)
@hverhelst hverhelst self-assigned this Oct 21, 2025
@filiatra
Copy link
Member

I think that the multiple constructors are not needed, the should be only one with gsFunctionSet
This accepts all other objects

Copy link
Member

@filiatra filiatra left a comment

Choose a reason for hiding this comment

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

I think that the multiple constructors are not needed, the should be only one with gsFunctionSet
This accepts all other objects.

Also it would be nice to avoid the new inclusion of gsBoxTopology (maybe just move the function body to cpp file.

@stefantakacs
Copy link
Member

Do you think that the changes to the GaussSeidel preconditiner are necessary?

After template instanciation, the compiler only sees for example

void step(const gsMatrix<T> & rhs, gsMatrix<T> & x) const
    {
        if ( gsGaussSeidel::forward == gsGaussSeidel::forward )
            internal::gaussSeidelSweep<T>(m_expr,x,rhs);
        if ( gsGaussSeidel::forward == gsGaussSeidel::reverse )
            internal::reverseGaussSeidelSweep<T>(m_expr,x,rhs);
        if ( gsGaussSeidel::forward == gsGaussSeidel::symmetric )
        {
            internal::gaussSeidelSweep<T>(m_expr,x,rhs);
            internal::reverseGaussSeidelSweep<T>(m_expr,x,rhs);
        }
    }

which immediately simplifies to

void step(const gsMatrix<T> & rhs, gsMatrix<T> & x) const
    {
        internal::gaussSeidelSweep<T>(m_expr,x,rhs);
    }

I do not see the need for any enable_if magic. For newer compilers a constexpr-if would be feasible

Revert Gauss Seidel enable_if's
Replace gsMappedBasis specialization in gsFeSpace
@hverhelst hverhelst marked this pull request as ready for review December 18, 2025 21:20
Copilot AI review requested due to automatic review settings December 18, 2025 21:20
@hverhelst hverhelst requested a review from a team as a code owner December 18, 2025 21:20
@hverhelst hverhelst requested a review from filiatra December 18, 2025 21:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the sparse solver framework with custom preconditioners and significantly improves multi-grid support for hierarchical splines. The changes enable users to integrate Gismo preconditioners with Eigen's iterative solvers and provide comprehensive grid hierarchy construction methods for hierarchical tensor B-spline bases.

Key changes:

  • Added gsPreconditionerWrapper to bridge Gismo preconditioners with Eigen iterative solvers, enabling custom preconditioners in CG and BiCGSTAB
  • Implemented hierarchical coarsening methods for gsGridHierarchy that work with gsHTensorBasis, including new buildByHierarchicalCoarsening functionality
  • Extended gsHTensorBasis with level-based refinement/unrefinement methods (refineToLevel, unrefineToLevel, etc.) and changed transfer matrices to RowMajor format for multi-grid compatibility

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 26 comments.

Show a summary per file
File Description
src/gsSolver/gsPreconditioner.h Introduces gsPreconditionerWrapper class to adapt Gismo preconditioners for Eigen solvers
src/gsMultiGrid/gsGridHierarchy.hpp Implements new grid hierarchy building methods with boundary conditions and hierarchical coarsening support
src/gsMultiGrid/gsGridHierarchy.h Declares new overloads for grid hierarchy construction with component and BC parameters
src/gsMatrix/gsSparseSolver.h Adds CGCustom and BiCGSTABCustom solver types and solveWithGuess interface for iterative solvers
src/gsIO/gsXml*.cpp/hpp/h Extends XML serialization to support both RowMajor and ColMajor sparse matrices via template parameters
src/gsHSplines/gsTHBSpline.hpp Updates transfer matrix type to RowMajor for consistency
src/gsHSplines/gsHTensorBasis.hpp Implements level-based refinement/unrefinement methods and updates transfer matrix types to RowMajor
src/gsHSplines/gsHTensorBasis.h Declares new refinement/unrefinement methods with transfer and coefficient update variants
src/gsExpressions/gsFeSpace.h Refactors mapper initialization to use new gsDofMapper constructors, simplifying BC handling
src/gsCore/gsMultiBasis.hpp Updates combineTransferMatrices to handle multiple components and adds assertions for validation
src/gsCore/gsMultiBasis.h Extends getMapper methods with component count parameters and comprehensive documentation
src/gsCore/gsLinearAlgebra.h Defines CGCustom and BiCGSTABCustom types in Eigen adaptor
src/gsCore/gsForwardDeclarations.h Adds forward declaration for gsPreconditionerWrapper
src/gsCore/gsDofMapper*.cpp/hpp/h Refactors with new constructors supporting topology, boundary conditions, and components; adds helper methods
examples/sparseSolvers_example.cpp Demonstrates usage of custom preconditioner with CG solver
examples/linearSolvers_example.cpp Adds example using custom Gismo preconditioner with Eigen CG solver

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 85 to 94
GISMO_DEPRECATED
template<class T>
gsDofMapper(
const gsMultiBasis<T> &bases,
const gsFunctionSet<T> &bases,
const gsBoundaryConditions<T> &dirichlet,
int unk = 0
) : m_shift(0), m_bshift(0)
{
init(bases, dirichlet, unk); //obsolete, one component
init(bases, dirichlet, unk); //obsolete, one component
}
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

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

The GISMO_DEPRECATED macro is applied to a constructor that takes gsFunctionSet instead of gsMultiBasis. However, the newer constructors below also take gsFunctionSet or gsMultiBasis. This deprecation seems inconsistent with the new API design where gsFunctionSet is the more general base class. The deprecation should either be removed or the reasoning should be clarified in a comment.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants