Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Residual for refined mesh is assembled incorrectly #679

Open
baagaard-usgs opened this issue Jan 31, 2024 · 2 comments
Open

Residual for refined mesh is assembled incorrectly #679

baagaard-usgs opened this issue Jan 31, 2024 · 2 comments
Assignees
Labels
bug:petsc PETSc related bug

Comments

@baagaard-usgs
Copy link
Contributor

baagaard-usgs commented Jan 31, 2024

Describe the bug

Refinement appears to be working for simulations without faults. However, the residual is wrong for refinement in simulations with a fault. The PyLith Jacobian looks correct but the finite-difference Jacobian does not; this is consistent with the residual being wrong. I don't see anything wrong in the topology or the labels. My wild guess is that we are taking the wrong path in the code when assembling the residual for a hybrid cell for the Lagrange multiplier field.

Update: Originally I thought the bug was only associated with meshes from Gmsh, but this does not appear to be the case as the same ASCII mesh also generates the error.

To Reproduce

PETSc branch: knepley/pylith-4.0
PyLith fork: https://github.com/baagaard-usgs/pylith.git
PyLith branch: add-refine-tests

cd $SRC/tests/fullscale/linearelasticity/faults-2d
pylith pylithapp_minmesh.cfg minmesh_noslip.cfg minmesh_noslip_quad.cfg --mesh_generator.refiner=pylith.topology.RefineUniform --mesh_generator.refiner.levels=1 --petsc.snes_test_jacobian --petsc.snes_test_jacobian_view

Diagram of mesh
refinedmesh.pdf

PyLith Jacobian

row 24: (4, 0.166667)  (5, 0.)  (6, 0.166667)  (7, 0.)  (8, -0.166667)  (9, 0.)  (10, -0.166667)  (11, 0.)  (14, 0.666667)  (15, 0.)  (22, -0.666667)  (23, 0.)  (24, 0.)  (25, 0.)  (26, 0.)  (27, 0.)  (28, 0.)  (29, 0.)
row 25: (4, 0.)  (5, 0.166667)  (6, 0.)  (7, 0.166667)  (8, 0.)  (9, -0.166667)  (10, 0.)  (11, -0.166667)  (14, 0.)  (15, 0.666667)  (22, 0.)  (23, -0.666667)  (24, 0.)  (25, 0.)  (26, 0.)  (27, 0.)  (28, 0.)  (29, 0.)
row 26: (4, 0.333333)  (5, 0.)  (8, -0.333333)  (9, 0.)  (14, 0.166667)  (15, 0.)  (22, -0.166667)  (23, 0.)  (24, 0.)  (25, 0.)  (26, 0.)  (27, 0.)
row 27: (4, 0.)  (5, 0.333333)  (8, 0.)  (9, -0.333333)  (14, 0.)  (15, 0.166667)  (22, 0.)  (23, -0.166667)  (24, 0.)  (25, 0.)  (26, 0.)  (27, 0.)
row 28: (6, 0.333333)  (7, 0.)  (10, -0.333333)  (11, 0.)  (14, 0.166667)  (15, 0.)  (22, -0.166667)  (23, 0.)  (24, 0.)  (25, 0.)  (28, 0.)  (29, 0.)
row 29: (6, 0.)  (7, 0.333333)  (10, 0.)  (11, -0.333333)  (14, 0.)  (15, 0.166667)  (22, 0.)  (23, -0.166667)  (24, 0.)  (25, 0.)  (28, 0.)  (29, 0.)

Finite-difference Jacobian

row 24: (2, -0.333333)  (4, 0.166667)  (6, 0.166667)  (14, 0.666667)  (18, -0.333333)  (20, -0.333333)  (24, 0.)
row 25: (3, -0.333333)  (5, 0.166667)  (7, 0.166667)  (15, 0.666667)  (19, -0.333333)  (21, -0.333333)  (25, 0.)
row 26: (2, -0.333333)  (4, 0.333333)  (14, 0.166667)  (18, -0.166667)  (26, 0.)
row 27: (3, -0.333333)  (5, 0.333333)  (15, 0.166667)  (19, -0.166667)  (27, 0.)
row 28: (2, -0.333333)  (6, 0.333333)  (14, 0.166667)  (20, -0.166667)  (28, 0.)
row 29: (3, -0.333333)  (7, 0.333333)  (15, 0.166667)  (21, -0.166667)  (29, 0.)
@baagaard-usgs baagaard-usgs added the bug:petsc PETSc related bug label Jan 31, 2024
@baagaard-usgs baagaard-usgs added this to the Release v4.1.0 milestone Jan 31, 2024
@baagaard-usgs baagaard-usgs changed the title Residual for refined mesh from Gmsh is assembled incorrectly Residual for refined mesh is assembled incorrectly Jan 31, 2024
@knepley
Copy link
Contributor

knepley commented Feb 4, 2024

It will not let me push to your branch. I am not sure what is wrong. Here is the diff that fixes it

 141add-refine-tests *$:/PETSc3/cig/pylith-git$ git log -1 -p
commit 9da7a4f5e51dfefd3d8139f980d3ef55c91536e0 (HEAD -> add-refine-tests)
Author: Matthew G. Knepley <knepley@gmail.com>
Date:   Sun Feb 4 11:19:41 2024 -0500

    Refine: Must order cohesive supports after refinement


diff --git a/libsrc/pylith/topology/RefineUniform.cc b/libsrc/pylith/topology/RefineUniform.cc
index efd90cda9..be5e45059 100644
--- a/libsrc/pylith/topology/RefineUniform.cc
+++ b/libsrc/pylith/topology/RefineUniform.cc
@@ -79,6 +79,7 @@ pylith::topology::RefineUniform::refine(Mesh* const newMesh,

         err = DMDestroy(&dmCur);PYLITH_CHECK_ERROR(err);
     } // for
+    err = DMPlexReorderCohesiveSupports(dmNew);PYLITH_CHECK_ERROR(err);

     newMesh->setDM(dmNew);

@@ -117,6 +118,7 @@ pylith::topology::RefineUniform::refine(Mesh* const newMesh,

     topology::MeshOps::checkTopology(*newMesh);

     // newMesh->view("REFINED_MESH", "::ascii_info_detail");
+    err = DMViewFromOptions(dmNew, NULL, "-pylith_ref_dm_view");PYLITH_CHECK_ERROR(err);


     PYLITH_METHOD_END;
 } // refine

@baagaard-usgs
Copy link
Contributor Author

This fix resolves the issue.

  • Finish adding refinement tests in tests/fullscale/linearelasticity/faults-2d
  • Add static C++ method in MeshOps.cc for computing the centroid of a cell
  • Update MMS tests to include refinement in tests/mmstests/linearelasticity/faults-2d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:petsc PETSc related bug
Projects
None yet
Development

No branches or pull requests

2 participants