Skip to content

Commit 65185d0

Browse files
committed
PetscCellMapping::extractEvolvingSubmatrix unit tests
Method that will extract the part of a PetscCellOperator that couples evolving cells to other evolving cells. Dummy implementation with failing tests.
1 parent b433faf commit 65185d0

5 files changed

Lines changed: 516 additions & 3 deletions

File tree

include/bout/petsc_operators.hxx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ struct ForwardLegSpaceTag {};
4444
/// leg space. See @ref ForwardLegSpaceTag and @ref CellSpaceTag.
4545
struct BackwardLegSpaceTag {};
4646

47+
// Forward declare
48+
template <typename OutSpaceTag, typename InSpaceTag>
49+
class PetscOperator;
50+
4751
/// @brief Bidirectional index mapping between mesh-file stored numbering and PETSc
4852
/// row ownership.
4953
///
@@ -290,6 +294,21 @@ public:
290294
/// evolving cells, holding global PETSc row indices.
291295
IS makeEvolvingIS() const;
292296

297+
/// @brief Extract the evolving-cell submatrix from a cell-to-cell operator.
298+
///
299+
/// Restricts @p op to the rows and columns that correspond to evolving
300+
/// interior cells, discarding any rows or columns that belong to inner/outer
301+
/// X-boundary cells or forward/backward parallel boundary virtual cells.
302+
///
303+
/// The returned Mat is an independent copy (MAT_INITIAL_MATRIX): subsequent
304+
/// modifications to @p op do not affect it. The caller owns the returned
305+
/// Mat and must call MatDestroy when finished.
306+
///
307+
/// @param op A cell-to-cell operator whose row and column space is the full
308+
/// cell space C managed by this mapping.
309+
/// @returns A square Mat of global size n_evolving × n_evolving.
310+
Mat extractEvolvingSubmatrix(const PetscOperator<CellSpaceTag, CellSpaceTag>& op) const;
311+
293312
private:
294313
Field3D cell_number; ///< Stored cell numbers for interior/X-boundary cells.
295314
Field3D

src/mesh/petsc_operators.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ IS PetscCellMapping::makeEvolvingIS() const {
142142
return is;
143143
}
144144

145+
// Dummy implementation. Note: Result is owned by the caller.
146+
Mat PetscCellMapping::extractEvolvingSubmatrix(
147+
const PetscOperator<CellSpaceTag, CellSpaceTag>& op) const {
148+
Mat new_mat;
149+
BOUT_DO_PETSC(MatDuplicate(op.raw(), MAT_COPY_VALUES, &new_mat));
150+
return new_mat;
151+
}
152+
145153
PetscLegMapping::PetscLegMapping(int total_legs, std::vector<int> local_leg_indices) {
146154
std::sort(local_leg_indices.begin(), local_leg_indices.end());
147155
local_leg_indices.erase(std::unique(local_leg_indices.begin(), local_leg_indices.end()),

tests/unit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ set(serial_tests_source
9999
./mesh/test_paralleltransform.cxx
100100
./mesh/test_petsc_operators.cxx
101101
./mesh/test_petsc_operators_make_evolving_is.cxx
102+
./mesh/test_petsc_operators_extract_evolving_submatrix.cxx
102103
./solver/test_fakesolver.cxx
103104
./solver/test_fakesolver.hxx
104105
./solver/test_solver.cxx

0 commit comments

Comments
 (0)