Skip to content

Commit ec1f94f

Browse files
committed
snes: Print a warning if the coloring is non-symmetric.
Added comments to explain why the coloring may be non-symmetric around an X-point.
1 parent b8d37c2 commit ec1f94f

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

src/solver/impls/snes/snes.cxx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ int SNESSolver::init() {
377377
auto n_cross = (*options)["stencil:cross"]
378378
.doc("Extent of stencil (cross)")
379379
.withDefault<int>(0);
380-
//Set n_taxi 2 if nothing else is set
381-
//Probably a better way to do this
380+
// Set n_taxi 2 if nothing else is set
381+
// Probably a better way to do this
382382
if (n_square == 0 && n_taxi == 0 && n_cross == 0) {
383383
output_info.write("Setting solver:stencil:taxi = 2\n");
384384
n_taxi = 2;
@@ -485,7 +485,7 @@ int SNESSolver::init() {
485485
d_nnz.reserve(nlocal);
486486

487487
for (int i = 0; i < nlocal; ++i) {
488-
//Assume all elements in the z direction are potentially coupled
488+
// Assume all elements in the z direction are potentially coupled
489489
d_nnz.emplace_back(d_nnz_map3d[i].size() * mesh->LocalNz
490490
+ d_nnz_map2d[i].size());
491491
o_nnz.emplace_back(o_nnz_map3d[i].size() * mesh->LocalNz
@@ -598,9 +598,21 @@ int SNESSolver::init() {
598598
MatAssemblyBegin(Jfd, MAT_FINAL_ASSEMBLY);
599599
MatAssemblyEnd(Jfd, MAT_FINAL_ASSEMBLY);
600600

601-
//The above will probably miss some non-zero entries at process boundaries
602-
//Making sure the colouring matrix is symmetric will in some/all(?)
603-
//of the missing non-zeros
601+
{
602+
// Test if the matrix is symmetric
603+
// Values are 0 or 1 so tolerance (1e-5) shouldn't matter
604+
PetscBool symmetric;
605+
ierr = MatIsSymmetric(Jfd, 1e-5, &symmetric); CHKERRQ(ierr);
606+
if (!symmetric) {
607+
output_warn.write("Jacobian pattern is not symmetric\n");
608+
}
609+
}
610+
611+
// The above can miss entries around the X-point branch cut:
612+
// The diagonal terms are complicated because moving in X then Y
613+
// is different from moving in Y then X at the X-point.
614+
// Making sure the colouring matrix is symmetric does not
615+
// necessarily give the correct stencil but may help.
604616
if ((*options)["force_symmetric_coloring"]
605617
.doc("Modifies coloring matrix to force it to be symmetric")
606618
.withDefault<bool>(false)) {

0 commit comments

Comments
 (0)