geodynamics / aspect

A parallel, extensible finite element code to simulate convection in both 2D and 3D models.
https://aspect.geodynamics.org/
Other
223 stars 235 forks source link

update the indexing of vector gradients following the idea of defensive programming (compiled) #5801

Closed magmaxt closed 4 months ago

magmaxt commented 4 months ago

Pull Request Checklist. Please read and check each box with an X. Delete any part not applicable. Ask on the forum if you need help with any step.

Describe what you did in this PR and why you did it. The previous code gradients[d] works because the indices of velocity or velocity gradient in the vector gradient are at 1 to dim th locations and so doing a for loop from 1 to dim will get the correct results. However, if in the future, someone changed the orders of "struct ComponentIndices" in aspect/include/aspect/introspection.h, then it will be a hidden bug that could be hard to debug.

Before your first pull request:

For all pull requests:

For new features/models or changes of existing features:

magmaxt commented 4 months ago

Please see defensive programming from blog by @bangerth at Making Myself Better: What Craftspeople Can Teach Us about Software

magmaxt commented 4 months ago

Yes, very nice!

Rene spotted it and taught me about it : )