WIP: Calculate Jacobian coloring using PetscOperator matrices#3350
WIP: Calculate Jacobian coloring using PetscOperator matrices#3350bendudson wants to merge 11 commits intopetsc-operatorsfrom
Conversation
This function should create an index set of the evolving cells. It will be used to extract the part of the PetscOperator that represents coupling between evolving cells. Implementation to follow.
Creates an index set of global PETSc rows that correspond to evolving cells. Passes unit tests.
Method that will extract the part of a PetscCellOperator that couples evolving cells to other evolving cells. Dummy implementation with failing tests.
Passes unit tests
| // Collect global PETSc indices in mapOwnedInteriorCells order. | ||
| // Reserve the known count up front to avoid reallocation. | ||
| std::vector<PetscInt> indices; | ||
| indices.reserve(static_cast<std::size_t>(evolving_region.size())); |
There was a problem hiding this comment.
warning: no header providing "std::size_t" is directly included [misc-include-cleaner]
src/mesh/petsc_operators.cxx:1:
+ #include <cstddef>| mapOwnedInteriorCells( | ||
| [&](PetscInt row, const Ind3D& /*i*/, int /*stored*/) { indices.push_back(row); }); | ||
|
|
||
| IS is; |
There was a problem hiding this comment.
warning: variable 'is' is not initialized [cppcoreguidelines-init-variables]
| IS is; | |
| IS is = nullptr; |
| const PetscOperator<CellSpaceTag, CellSpaceTag>& op) const { | ||
| IS is = makeEvolvingIS(); | ||
|
|
||
| Mat sub; |
There was a problem hiding this comment.
warning: variable 'sub' is not initialized [cppcoreguidelines-init-variables]
| Mat sub; | |
| Mat sub = nullptr; |
Checks the global ordering of cells for consistency as number of processors and nxpe is varied.
Include guards, header includes.
This function will add non-zeros to a Jacobian matrix, based on a submatrix from a PetscCellOperator. Dummy implementation so unit tests fail.
Sets a sparsity pattern in a given Jacobian matrix, based on an operator matrix and the variable indices. Passes unit tests.
Should apply the connectivity pattern to all pairs of variables in the system Jacobian.
Applies the same connectivity in `mat` to all pairs of variables in `J`. Passes unit tests.
|
|
||
| void addOperatorSparsity(Mat Jfd, Mat sub, int out_var, int in_var) { | ||
| // Infer nvars from global sizes | ||
| PetscInt jfd_global{0}, sub_global{0}; |
There was a problem hiding this comment.
warning: multiple declarations in a single statement reduces readability [readability-isolate-declaration]
| PetscInt jfd_global{0}, sub_global{0}; | |
| PetscInt jfd_global{0}; | |
| PetscInt sub_global{0}; |
| ASSERT1(in_var >= 0 && in_var < static_cast<int>(nvars)); | ||
|
|
||
| // Iterate over locally owned rows of sub and insert into Jfd | ||
| PetscInt rstart{0}, rend{0}; |
There was a problem hiding this comment.
warning: multiple declarations in a single statement reduces readability [readability-isolate-declaration]
| PetscInt rstart{0}, rend{0}; | |
| PetscInt rstart{0}; | |
| PetscInt rend{0}; |
| } | ||
|
|
||
| void addOperatorSparsity(Mat Jfd, Mat sub) { | ||
| PetscInt jfd_global{0}, sub_global{0}; |
There was a problem hiding this comment.
warning: multiple declarations in a single statement reduces readability [readability-isolate-declaration]
| PetscInt jfd_global{0}, sub_global{0}; | |
| PetscInt jfd_global{0}; | |
| PetscInt sub_global{0}; |
| #include <bout/petsc_operators.hxx> | ||
| #include <bout/region.hxx> | ||
| #include <bout/utils.hxx> | ||
|
|
There was a problem hiding this comment.
warning: included header utils.hxx is not used directly [misc-include-cleaner]
| MatDestroy(&dummy); | ||
|
|
||
| // ── Compare traversal orderings ─────────────────────────────────────────── | ||
| // Walk mapOwnedInteriorCells and RGN_NOBNDRY in parallel, checking that |
There was a problem hiding this comment.
warning: variable 'Istart' is not initialized [cppcoreguidelines-init-variables]
RMINE);
^this fix will not be applied because it overlaps with another fix
|
|
||
| // ── Compare traversal orderings ─────────────────────────────────────────── | ||
| // Walk mapOwnedInteriorCells and RGN_NOBNDRY in parallel, checking that | ||
| // the local offset produced by each is identical for every cell. |
There was a problem hiding this comment.
warning: multiple declarations in a single statement reduces readability [readability-isolate-declaration]
| // the local offset produced by each is identical for every cell. | |
| RMINE); | |
| t, Iend;PetscInt Istart; | |
| PetscInt Iend; |
|
|
||
| // ── Compare traversal orderings ─────────────────────────────────────────── | ||
| // Walk mapOwnedInteriorCells and RGN_NOBNDRY in parallel, checking that | ||
| // the local offset produced by each is identical for every cell. |
There was a problem hiding this comment.
warning: variable 'Iend' is not initialized [cppcoreguidelines-init-variables]
t, Iend;
^this fix will not be applied because it overlaps with another fix
| } | ||
|
|
||
| if (my_rank == 0) { | ||
| output.write("total_mismatches={}\n", total_mismatches); |
There was a problem hiding this comment.
warning: variable 'my_rank' is not initialized [cppcoreguidelines-init-variables]
tests/integrated/test-petsc-ordering/test_petsc_ordering.cxx:201:
- k;
+ k = 0;
Builds on #3330 , using
PetscOperatormatrices to infer connectivity between cells.The aim is to accelerate transport simulations with FCI by inferring the sparsity pattern of the Jacobian in
SNESSolverandPetscSolver. This will enable coloring to efficiently calculate finite difference Jacobian approximations for LU-like preconditioners. This is the method used for structured grid (e.g. Tokamak) simulations, that so far has not been possible with FCI.