-
Notifications
You must be signed in to change notification settings - Fork 117
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
Fix asymmetry of Coordinates x1f for multiple MeshBlock grids #112
Conversation
Add comments to athena.hpp to clarify 64-bit vs. 32-bit integer quantities in LogicalLocation and RegionSize structs
Need to clarify why the int64_t LogicalLocation.lxi and Mesh class nrbxi loaded by the file are unlikely/cannot to exceed in32_t limits
Flag works with icc, but not all icc-detected violations have been fixed. Comment it out for now.
Use before calling MeshGenerator_[] functions to compute their Real x arguments; use unit_interval=true to compute the [0,1] parameterization expected by user or non-uniform DefaultMeshGen. Use unit_interval=false to compute the zero-centered [-0.5,0.5] fractional location expected by UniformMeshGeneratorX1()
Now, it matches the use_uniform_meshgen_fn_ flag usage
90e6795
to
63de3a0
Compare
A quick and dirty attempt to test refinement symmetry shows a pretty asymmetric solution: rt-ppm-nx1-500-nx2-1000-mbnx-50-amr-newmesh.pdf I had never run any AMR simulations before, so I will have to spend more time on this. Could have issues with the refinement condition (copied from Kelvin-Hemholtz file), input variables, and with using |
While I am not going to fix the AMR asymmetry right now, this test and others revealed that the PR was imperfect. The latest commit to Another small fix to come soon. |
Well, it turns out the latest asymmetries were due to unsafe floating-point compiler optimizations. After merging the PR, I carelessly moved from configuring and compiling with
which used Apple LLVM version 9.1.0 (clang-902.0.39.1) to running parallel simulations with MPICH wrappings on Intel icc (ICC) 18.0.2 20180210; configured and compiled with:
which causes
and resulted in asymmetries in all the cases (regardless if MPI is used or not). The Intel compiler is more aggressive than the GNU compiler with math optimizations. Neither clang nor I tried adding
but the asymmetries disappear. According to Intel fp-model documentation, the only differences between
so clearly that was not the source of the problems here. It seems that breaking the OpenMP vectorization of those loops or disabling the FMA optimizations was essential to maintaining symmetry. The ability of OpenMP SIMD loops to reorder FP operations can be toggled via the environment variable I will add my lesson to the Wiki as a warning to others. The For example, with to |
Description
While #98 fixed the small round-off asymmetries in
Coordinates
class floating-point calculations ofx1f, x1v
for uniform meshes composed of a single MeshBlock, such changes were largely restricted to calculations incoordinates.cpp
. This resulted in a discrepancy with the calculation of MeshBlock boundaries inmesh.cpp
's non-restart class constructorMesh::Mesh()
This pull request applies
UniformMeshGeneratorX1()
to two locations inmesh.cpp
:Mesh::SetBlockSizeAndBoundaries()
computation ofblock_size.x1min
, etc.while also condensing and modularizing the logic of switching between
UniformMeshGeneratorX1(Real x, RegionSize rs)
andDefaultMeshGeneratorX1(Real x, RegionSize rs)
in a new inlined function,ComputeMeshGeneratorX(int64_t index, int64_t nrange, bool sym_interval)
which returns the differentReal x
ranges needed as input for the two functions. User-enrolled mesh generating functions should behave the same asDefaultMeshGeneratorX1()
This also fixes all violations of
clang++
warning flag-Wshorten-64-to-32
(does not exist forg++
mentioned in #94. Most of these were in FFT and Multigrid functionalities, and involved loading theint64_t
quantitiesLogicalLocation.lxi
(inathena.hpp
) and Mesh classnrbxi
intoint
variables. @tomidakn explained that issues were unlikely to result from this, since FFT/Multigrid applications wouldn't have largelxi, nrbxi
. Still, this may change in the future, and implicit conversions are usually bad, so they were all wrapped withfor example. Also, the restart simulation
Mesh()
constructor was using anint
for pointer indexing computed fromIOWrapperSize_t
, which is now a properuint64_t
.Not all
-Wshorten-64-to-32
violations detected byicc
were fixed in this PR. Notably, the shearing box module treatsnrbxi
values as 32-bit integers, e.g.and I am not entirely convinced that we need
nrbxi
to beint64_t
, even though they had beenlong int
before I removed such data model-dependent types from the code.Extending #105, the CI implementations now check for strict compliance to
-Wshorten-64-to-32
clang++ warning viatst/ci/set_warning_cflag.sh
.Testing and validation
As with #98, tested locally on the 2D Rayleigh-Taylor problem. Now, used double precision HDF5 output implemented in #108 and loaded with
h5py
to validate that x1 symmetry was exactly preserved (see #111 for whyathena_read.py
could not be used).Configured for
clang++
with:Tested with
time/xorder=3
on a Cartesian mesh of 100x500 cells, but this time the MeshBlock size was 20x200 cells to ensure that 25x MeshBlocks spanned x1.rt-ppm-nx1-500-mbnx1-20.pdf shows the density solution and the mirrored density differences using
master
.rt-ppm-nx1-500-mbnx1-20-newmesh.pdf
shows the result produced by this pull request, which is exactly symmetric and matches the single MeshBlock solution produced by
master
.I am not sure there is much reason to continue using
DefaultMeshGeneratorX1()
instead of adapting the [-0.5, 0.5] mapping ofUniformMeshGeneratorX1()
to nonuniform meshes-- neither will preserve symmetry in such problems. The only reason I kept the former is because https://github.com/PrincetonUniversity/athena/wiki/Coordinate-Systems-and-Meshes also uses the [0,1] logical location mapping. If we are ok with breaking existing user-defined mesh generators, then the code can be simplified.To-do
nrbxi
asint64_t
icc
warnings of illegal narrowing-Wshorten-64-to-32
fornrbx1
(or make them 32-bit integers), and reenable flag in the CI test on Jenkins.DefaultMeshGeneratorX1()
with a x in [-0.5, 0.5] analog and changing the user-defined mesh generator instructions.