Array corruption when accessing boundary field
Summary
The cell volume field mesh.V() gets corrupted when a new surfaceVectorField is created and boundary values altered.
Steps to reproduce
Compile and run the attached code 'cellVolume'. It will output the cell volumes in the mesh as well as the min/max volume. Run this code on the cavity case 2D. Ideally, all volumes should be equal. However, you will see that the cells on the boundary have a different volume. But after commenting out the part where the boundary fields are changed, the cell volumes are all correct. Also, if you uncomment the very first occurrence of mesh.V(), it works. Running with valgrind shows no memory leaks. Either I am doing something really stupid or there is an underlying issue.
Example case
Run it on the cavity case from icoFoam.
What is the current bug behaviour?
Incorrect cell volume on the boundary
What is the expected correct behavior?
Should give the expected cell volume
Relevant logs and/or images
Environment information
- OpenFOAM version : v1812 and v1912
- Operating system : ubuntucellVolume.tar.gzcellVolume.tar.gz
- Hardware info :
- Compiler : gcc