Skip to content

Eigen subvector support, unit tests#4415

Open
roystgnr wants to merge 7 commits intolibMesh:develfrom
roystgnr:eigen_subvector
Open

Eigen subvector support, unit tests#4415
roystgnr wants to merge 7 commits intolibMesh:develfrom
roystgnr:eigen_subvector

Conversation

@roystgnr
Copy link
Member

@roystgnr roystgnr commented Mar 4, 2026

Not sure how far I'm going to go with the Eigen support here (I wanted something a little simpler than PETSc to use for testing other code) but what's here so far was simple enough and was good motivation for adding missing test coverage.

roystgnr added 4 commits March 4, 2026 14:59
I thought I could get another backend supporting StaticCondensation, but
no, we'll need shell matrix solves from Eigen too.
We now support another backend; also this wording seemed clearer to me.
template <typename T>
void EigenSparseVector<T>::create_subvector(NumericVector<T> & subvector,
const std::vector<numeric_index_type> & rows,
const bool /* supplying_global_rows */) const
Copy link
Member

Choose a reason for hiding this comment

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

Is Eigen always a serial vector?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

Comment on lines +444 to +447
// Construct index set
//Eigen::Map<Eigen::ArrayXi> ind_vec_map(rows.data(),
//cast_int<Eigen::Index>(rows.size()));

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Construct index set
//Eigen::Map<Eigen::ArrayXi> ind_vec_map(rows.data(),
//cast_int<Eigen::Index>(rows.size()));

//cast_int<Eigen::Index>(rows.size()));

eigen_subvector->vec() = this->vec()(rows);
// eigen_subvector->vec() = ind_vec_map.unaryExpr(this->vec());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// eigen_subvector->vec() = ind_vec_map.unaryExpr(this->vec());

Comment on lines +477 to +480
// Construct index set
// Eigen::Map<Eigen::ArrayXi> ind_vec_map(rows.data(),
// cast_int<Eigen::Index>(rows.size()));

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Construct index set
// Eigen::Map<Eigen::ArrayXi> ind_vec_map(rows.data(),
// cast_int<Eigen::Index>(rows.size()));

// Eigen::Map<Eigen::ArrayXi> ind_vec_map(rows.data(),
// cast_int<Eigen::Index>(rows.size()));

DataType subvec = eigen_subvector->vec();
Copy link
Member

Choose a reason for hiding this comment

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

Is subvec unused here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is - artifact (along with those comments) of a previous uglier implementation. I'll clean it up too.


DataType subvec = eigen_subvector->vec();
this->vec()(rows) = eigen_subvector->vec();
this->_is_closed = true;
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, should we mark this->_is_closed = false in the getter? Wondering whether we could also do the same in petsc_vector

Copy link
Member Author

Choose a reason for hiding this comment

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

We're basically not supposed to touch the original vector until the subvector is restored, right? Marking it non-closed would make that misuse subject to a whole bunch more assertions. I'll do it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops - you already did it in the PETSc version. I just missed that when I was implementing here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we assert that we're already closed when we get_subvector(), though?



template <class Base, class Derived>
void Subvectors()
Copy link
Member

Choose a reason for hiding this comment

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

Not subvectors() ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah; I'm trying to match the naming scheme of the other tests here.

roystgnr and others added 3 commits March 4, 2026 18:26
Co-authored-by: Alex Lindsay <alexander.lindsay@inl.gov>
That way our assertions to the contrary will scream if anyone tries to
use the parent before the subvector is restored.
@roystgnr
Copy link
Member Author

roystgnr commented Mar 6, 2026

It looks like I just don't understand what supplying_global_rows was supposed to mean. The original docs were "The boolean parameter

  • communicates whether the supplied vector of rows corresponds to all the
  • rows that should be used in the subvector's index set, e.g. whether the
  • rows correspond to the global collective."

So I supplied a globally-synchronized set of 10 row ids for that case, corresponding to all the rows I wanted in the subvector ... And I got a vector of length 20 on two processors, I suppose corresponding to two copies of all the rows I asked for?

@lindsayad , clarification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants