AMReX-Astro / Castro

Castro (Compressible Astrophysics): An adaptive mesh, astrophysical compressible (radiation-, magneto-) hydrodynamics simulation code for massively parallel CPU and GPU architectures.
http://amrex-astro.github.io/Castro
Other
301 stars 98 forks source link

NaN values encountered when trying to setup user-defined auxiliary variables #2982

Open RemiLehe opened 3 weeks ago

RemiLehe commented 3 weeks ago

First of all, thanks a lot for developing Castro ; the code is very useful to me!

I recently tried to use auxiliary variables (described in this page of the documentation, accessed with UFX, etc.). More specifically, I did a small test where I started from the 1D Sedov example and added an auxiliary variable that is supposed to mirror exactly eint_e(as a way to check that the variable behaves as expected): see changes in the commit below https://github.com/RemiLehe/Castro/commit/ccfd30fb9d6f236c493bc771305b8edc1fe7caea

However, when running this example, I get an error message:

amrex::Abort::0::State has NaNs in the rho_myenerg component::check_for_nan() !!!

Is this expected? Is there a way to work around this?

How to easily reproduce this issue

Clone my fork from Castro and switch to the branch test_aux_variables (this branch is identical to the current main branch of Castro, but with the additional commit listed above). Then run the 1d Sedov cylindrical test.

git clone https://github.com/RemiLehe/Castro
git submodule update --init
cd Castro/Exec/hydro_tests/Sedov
git checkout test_aux_variables
make DIM=1 -j 4
./Castro1d.gnu.MPI.ex inputs.1d.cyl
yut23 commented 3 weeks ago

Thanks for the easy reproduction instructions, they help a lot!

My first step for debugging is always to build with DEBUG=TRUE and run with amrex.fpe_trap_{invalid,zero,overflow}=1. This adds runtime bounds checks, fills uninitialized arrays with NaNs, and makes any floating-point exceptions immediately trigger a crash. With those, the backtrace points to https://github.com/AMReX-Astro/Microphysics/blob/533f712d2d217ea4f4063f3a809eb16a839c9ef6/EOS/eos_composition.H#L73, which looks like division by zero. The problem is that your single species has Z=0, so sum is always zero.

If I set Z=1.0 in species.net, it makes it through the initialization. However, it still crashes at https://github.com/RemiLehe/Castro/blob/ccfd30fb9d6f236c493bc771305b8edc1fe7caea/Exec/hydro_tests/Sedov/problem_source.H#L36 with the error message amrex::Abort::0:: (-1,0,0,1) is out of bound (0:31,0:0,0:0,0:8) !!!, so it looks like state doesn't have any ghost cells. I'm not sure where this should be addressed myself, but one of the other developers should be able to help.

RemiLehe commented 3 weeks ago

Great, thanks a lot! Let me know if there is any additional test I can to do to help.