Implement a composition-based wrapper for SerialDenseVector#1923
Implement a composition-based wrapper for SerialDenseVector#1923bgoderbauer merged 3 commits into4C-multiphysics:mainfrom
Conversation
|
@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. |
|
@bgoderbauer at least, we should think about it and make an educated assessment, so that we can make a well informed decision. |
|
@bgoderbauer @mayrmt I think this is a good first step. With this PR we don't inherit from |
|
I like the idea with group comments. I'll check whether it works as intended this way. |
|
I think the documentation looks nice this way. What do you think? |
There was a problem hiding this comment.
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::SerialDenseVectorand 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(). |
fb99e9d to
9a6cabb
Compare
mayrmt
left a comment
There was a problem hiding this comment.
@bgoderbauer Looks good overall! I left some comments for possible further improvement within this PR.
9a6cabb to
5b855ba
Compare
Description and Context
This PR migrates the current
SerialDenseVectorfrom inheritance to a true composition-based wrapper.One major issue is that Trilinos treats a
SerialDenseVectoras aSerialDenseMatrix, 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 theTeuchos::SerialDenseSolveris 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