Skip to content

Implement a composition-based wrapper for SerialDenseVector#1923

Merged
bgoderbauer merged 3 commits into4C-multiphysics:mainfrom
bgoderbauer:wrap-serialdensevector
Apr 14, 2026
Merged

Implement a composition-based wrapper for SerialDenseVector#1923
bgoderbauer merged 3 commits into4C-multiphysics:mainfrom
bgoderbauer:wrap-serialdensevector

Conversation

@bgoderbauer
Copy link
Copy Markdown
Contributor

@bgoderbauer bgoderbauer commented Apr 1, 2026

Description and Context

This PR migrates the current SerialDenseVector from inheritance to a true composition-based wrapper.
One major issue is that Trilinos treats a SerialDenseVector as a SerialDenseMatrix, and this is abused in a few places in our code. The new wrapper explicitly differentiates between them, so it is no longer possible to interchange them. Therefore, I had to (unfortunately) add more multiply and assemble overloads to preserve behavior. I hope we can unify or reduce them at some point. 22 different multipliers for SerialDense objects is IMO too many. Also, while working on this, I've noticed many places in the code where there are questionable decisions about the use of vectors and matrices, and their interchange. When these are fixed, the assemble methods can be reduced as well.

Some calls to base() (i.e., the Trilinos object) are still necessary until the Teuchos::SerialDenseSolver is wrapped. I will tackle this soon 🤞.

I also added the corresponding implementation for EXPECT_NEAR, which is now necessary since a vector is no longer a matrix with a second dimension of size 1.

Related Issues and Pull Requests

Follows #1209

@bgoderbauer bgoderbauer self-assigned this Apr 1, 2026
@bgoderbauer bgoderbauer added the type: enhancement A new feature or enhancement to be implemented label Apr 1, 2026
@mayrmt
Copy link
Copy Markdown
Member

mayrmt commented Apr 1, 2026

@bgoderbauer Trilinos recommends to use Kokkos data structures for local (serial) vectors and matrices (in fact multi-dimensional arrays). I am not saying, that we should switch right away, though this might be useful information before we pour too much effort into the Teuchos::Serial stuff.

@bgoderbauer
Copy link
Copy Markdown
Contributor Author

@bgoderbauer Trilinos recommends to use Kokkos data structures for local (serial) vectors and matrices (in fact multi-dimensional arrays). I am not saying, that we should switch right away, though this might be useful information before we pour too much effort into the Teuchos::Serial stuff.

Good to know! So, should we ultimately switch to Kokkos in the long run? With a nice abstract wrapper, it should be easy to exchange the backend.

@mayrmt
Copy link
Copy Markdown
Member

mayrmt commented Apr 1, 2026

@bgoderbauer at least, we should think about it and make an educated assessment, so that we can make a well informed decision.

@maxfirmbach
Copy link
Copy Markdown
Contributor

@bgoderbauer @mayrmt I think this is a good first step. With this PR we don't inherit from Teuchos anymore, which is the right thing to do. Everything that could be done in the future is most likely worth a separate PR. I'm fine with the current state and approach.

Comment thread src/core/linalg/src/dense/4C_linalg_serialdensevector.cpp
Comment thread src/core/linalg/src/dense/4C_linalg_serialdensevector.hpp Outdated
@bgoderbauer
Copy link
Copy Markdown
Contributor Author

I like the idea with group comments. I'll check whether it works as intended this way.

@bgoderbauer
Copy link
Copy Markdown
Contributor Author

I think the documentation looks nice this way. What do you think?

Copy link
Copy Markdown

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 completes the migration of Core::LinAlg::SerialDenseVector from inheriting Teuchos::SerialDenseVector to being a composition-based wrapper, updating call sites to explicitly access the Trilinos object via base() and adding missing utility overloads to preserve existing behavior (notably in dense multiply, sparse assembly, and test assertions).

Changes:

  • Introduce a composition wrapper for Core::LinAlg::SerialDenseVector and update vector APIs/usages accordingly.
  • Update Trilinos solver/multiply call sites to pass vec.base() explicitly where required.
  • Extend test utilities (EXPECT_NEAR) and assembly/multiply helpers to handle vectors as true vectors (not 1-column matrices).

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
unittests/common/unittest_utils/4C_unittest_utils_assertions_test.hpp Adds EXPECT_NEAR predicate support for SerialDenseVector.
src/w1/4C_w1_input.cpp Converts EAS vector storage to an explicit matrix wrapper when stored in history.
src/scatra_ele/4C_scatra_ele_calc_hdg.cpp Updates SerialDenseSolver::setVectors to use trVec.base().
src/fluid/4C_fluid_DbcHDG.cpp Replaces vector-as-matrix reshaping with vector resize.
src/fluid_ele/4C_fluid_ele_boundary_parent_calc.hpp Updates interfaces to accept SerialDenseVector wrapper (no ::Base).
src/fluid_ele/4C_fluid_ele_boundary_parent_calc.cpp Implements the corresponding signature updates.
src/fbi/src/4C_fbi_beam_to_fluid_mortar_manager.cpp Adjusts kappa sizing check for vector semantics.
src/core/utils/src/numerics/4C_utils_local_newton.hpp Updates solver RHS/unknown vectors to pass base().
src/core/utils/src/numerics/4C_utils_cubic_spline_interpolation.cpp Updates solver vector passing to use base().
src/core/linalg/src/sparse/4C_linalg_utils_sparse_algebra_math.cpp Updates QR solver vector passing to use base().
src/core/linalg/src/sparse/4C_linalg_sparseoperator.hpp Adds vector overloads for sparse operator assembly (vector→column-matrix).
src/core/linalg/src/sparse/4C_linalg_sparsematrix.hpp Adds vector overloads for sparse matrix assembly (vector→column-matrix).
src/core/linalg/src/dense/4C_linalg_utils_tensor_interpolation.cpp Updates dense multiply calls to use SerialDenseVector::base() explicitly.
src/core/linalg/src/dense/4C_linalg_utils_densematrix_multiply.hpp Expands multiply overload set and improves debug dimension reporting for vectors.
src/core/linalg/src/dense/4C_linalg_utils_densematrix_eigen.cpp Replaces SerialDenseVector::Base temporaries with wrapper type.
src/core/linalg/src/dense/4C_linalg_serialdensevector.hpp Introduces the new composition-based SerialDenseVector wrapper API.
src/core/linalg/src/dense/4C_linalg_serialdensevector.cpp Implements wrapper methods and keeps free norm2/update utilities working.
src/core/linalg/src/dense/4C_linalg_fixedsizematrix.hpp Updates documentation reference from SerialDenseVector::Base to wrapper.
src/core/fem/tests/geometry/4C_fem_geometry_element_volume_test.cpp Updates test code from reshape(...,1) to vector resize.
src/core/fem/src/general/utils/4C_fem_general_utils_polynomial.cpp Updates solver vector passing and vector sizing to match new wrapper semantics.
src/core/fem/src/discretization/4C_fem_discretization_hdg.cpp Replaces vector-as-matrix reshaping with resize.
src/beaminteraction/src/crosslinking/4C_beaminteraction_crosslinking_submodel_evaluator.cpp Replaces vector-as-matrix reshaping with resize.
src/art_net/4C_art_net_art_junction.cpp Updates solver vector passing to use base().

Comment thread src/core/linalg/src/sparse/4C_linalg_sparseoperator.hpp Outdated
Comment thread src/core/linalg/src/sparse/4C_linalg_sparsematrix.hpp Outdated
Comment thread src/core/linalg/src/sparse/4C_linalg_sparsematrix.hpp Outdated
Comment thread src/fbi/src/4C_fbi_beam_to_fluid_mortar_manager.cpp
@bgoderbauer bgoderbauer force-pushed the wrap-serialdensevector branch from fb99e9d to 9a6cabb Compare April 2, 2026 15:22
Comment thread src/core/linalg/src/dense/4C_linalg_serialdensevector.cpp
Comment thread src/core/linalg/src/dense/4C_linalg_serialdensevector.cpp
Comment thread src/core/linalg/src/dense/4C_linalg_serialdensevector.cpp
mayrmt
mayrmt previously approved these changes Apr 7, 2026
Copy link
Copy Markdown
Member

@mayrmt mayrmt left a comment

Choose a reason for hiding this comment

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

@bgoderbauer Looks good overall! I left some comments for possible further improvement within this PR.

Comment thread src/core/linalg/src/dense/4C_linalg_serialdensevector.hpp
Comment thread src/core/linalg/src/sparse/4C_linalg_sparseoperator.hpp Outdated
@bgoderbauer bgoderbauer enabled auto-merge April 14, 2026 12:33
@bgoderbauer bgoderbauer merged commit 077db15 into 4C-multiphysics:main Apr 14, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A new feature or enhancement to be implemented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants