Skip to content

Conversation

@rennehan
Copy link

I've added the MAGMA2 SPH scheme with improved gradient estimation and 2nd order reconstruction into SWIFT. The implementation follows Rosswog 2020 extremely closely except for a few important changes.

  • When the estimated G_ij vector is severely misaligned with the particle separation vector, the interaction falls back to a Gasoline2-like SPH to improve stability in highly anisotropic regions. That is set by the const_viscosity_cosine_limit compilation parameter in hydro_parameters.h.
  • If the G_ij vector points in the opposite direction of the particle separation vector, it automatically falls-back to Gasoline2-like SPH.
  • When the SPH falls-back to the Gasoline2-like SPH, the viscosity and conductivity are reduced by const_fallback_reduction_factor to prevent overly dissipative flows.
  • There is a Balsara limiter for viscosity on top of the implementation of Rosswog 2020 or else the scheme will not work with cosmological simulations.
  • There is a condition number limit on the matrix inversions from Rosswog 2020 set by const_condition_number_upper_limit. That number has been selected for stability in floating-point calculations and should not be changed from 60. If any of the matrices go above that condition number, the scheme falls-back to a Gasoline2-like SPH.
  • The hydro calculations can be done in double or floating-point precision by compiling with hydro_props_use_double_precision or without it, respectively. It works fine in floating-point precision with the condition number above.
  • The number of neighbors must be hard-coded into hydro_parameters.h for now because of the Van Leer slope limiting procedure in Rosswog 2020 and can be set with const_kernel_target_neighbours. I added in target_neighbours under the SPH section of the parameter file so that it may be set directly instead of resolution_eta.
  • All of the extra debugging information (condition numbers, full matrices, etc.) can be output to disk by configuring SWIFT with --enable-magma2-debugging-checks.
  • It is possible to use the improved gradient G_ij in an interaction but projected along the particle separation vector instead of the exact dot-products used in Rosswog 2020 by compiling with hydro_props_use_radial_artificial_terms in hydro_parameters.h. That should not be necessary, but is good for testing.
  • All of the signal velocities are computed using the raw velocities and separation vectors, not any second order reconstructed quantities. It is very important that this remains the same, or the scheme is unstable.
  • There is a time-step limiter that forces time steps to track at least 25% changes in specific internal energy due to conductivity only to ensure the differential equation is solved correctly.

The hydro tests work well and give good results in 3D and 2D. The results require at least 114 neighbours in 3D for the Wendland C2 kernel. I recommend values of const_viscosity_alpha=2 and const_viscosity_beta=2*const_viscosity_alpha for the viscosity. For conductivity, I recommend no higher than const_conductivity_alpha=0.075 or there will be severe spreading of shocks (see the SedovBlast_3D test).

rennehan added 30 commits July 25, 2025 17:09
…AGMA2_DEBUG_CHECKS to output the ill condition nature.
…e kernel gradients are used in the equations of motion symmetrically. The Sedov test runs for a while, but still eventually crashes.
…t for the antisymmetry of the problem. Also compute dh/dt using the density of particle pi rather than summing over pj contributions.
…ture. I moved all of the gradient relevant tensors and quantites into a new gradients struct in the particle.
…e debugging for the auxiliary velocity gradient tensor. Fixed a couple of issues with the original Gasoline implementation in computing divergences.
…onstruction of the velocity field. There are convenience functions in hydro.h that will compute the tensor and matrix contractions to clean up the code a bit and make it maintainable. Added in viscosity alpha as a constant 1 and changed beta to 2, and set the softening for viscosity to 10% of the softening length. Each particle gets its own artificial pressure rather than averaging as in other methods. The number of neighbors is stored in p->num_ngb now, although this should be constant for each run. Changed correction_matrix to a float since it seems very stable even in the Sedov Blastwave example. There is still a check for numerical conditioning and it will still revert to a Gasoline2-like SPH if the correction matrix is poorly conditioned.
…the hydro.h file that clean up the code a lot and should improve efficiency. Also rewrote the van Leer slope limiter part of the code so that we can now do both scalar and vector fields easily.
…e is extreme noise in front of the shock in the Sedov Blastwave test.
…he vsig calculation as it was also wrong in the Gasoline2 code that I am using as a template.
…um signal velocity to a variable p->v_sig_max that is used to compute the timestep. Now use p->h_min (minimum smoothing length in the kernel) to compute the time-step. Removed old Gasoline2 alpha viscosity estimators and decay terms, as well as the diffusion rate estimators. Small changes to hydro tests to get them to run.
…t seems like they are building up rapidly in the 2nd order reconstruction. It might be that all of these calculations must be done in double precision, or at least zeroed out whenever the dot products are not above FLT_EPSILON.
…e in the Cooling/CoolingSedovBlastwave_3D test case. I fixed the units in the file so that they are in reasonable units.
…othing length) and v_sig_max_ij (maximum signal velocity). Defined new constants for eta_crit and eta_fold in the slope limiting procedure. It seems that slope limiting has a huge effect on the Sedov blastwave noise. I have symmetrized as many operations as possible to avoid floating point rounding errors that seem to be causing a lot of problems. Possible to use the second order velocities directly in the v_ij dot G_ij terms in the hydro equations, using hydro_props_use_second_order_velocities_in_divergence. Must compile with the desired number of neighbours for the slope limiting procedure using const_desired_number_of_neighbours or an error will occur. Must be within 5% of the computed target neighbours for a given SPH: eta in the parameter file. Should be computing the conductivity correctly with the Hubble flow added in.
…ta_crit to be a scaled version of the mean interparticle spacing which is fixed for a kernel/neighbour combination.
…ydro_props_use_double_precision (sets double precision).
…he alternative way. Reorganized the compile-time constants to separate those that can change and those that should be fixed. Changed the SPH divergence estimate to be consistent with the Swift comoving unit system. Conductivity v_sig_cond should be correct now. Allow target_neighbours to be set in the parameter file rather than resolution_eta. Fixed a mistake in makeMovie.py for the Rayleigh-Taylor test.
…dex. Added in a small debugging note if particles penetrate one another. Fixed a bug in the estimation of the mean interparticle spacing. Must not use second order velocities in the SPH divergence sums, that causes severe asymmetries.
… that Rosswog 2020 has a sign error in the conductivity equation, so I fixed that here.
…w temperatures). Got the Hubble flow additions correct for the viscosity.
… relabelled conservative to non-conservative.
…the kernel gradients. Also rewrote dh/dt calculation to match what Swift actually does -- which is a number density constraint on neighbour number, not a mass density constraint! There are more correction terms that need to be added, but those require an additional neighbor loop.
…enter into the average of the kernel gradients, and only really need the 1/Omega contribution. Using the symmetric version (like in SPHENIX) causes problems in extremely complicated flows like the Sedov blastwave. The "grad-h" terms are not actually needed in the MAGMA2 gradients, but it is required for the internal energy evolution equation because of the mismatch between the adiabatic term in the density and specific energy.
… a kernel correction term. However, it assumes that the kernel is isotropic which is most likely wrong (really it assumes that the matrix C_i^kd in Rosswog 2020 is isotropic). If we wanted the true correction factor, we would need another loop over neighbors to find the kernel anisotropies. Added a new function to weight the kernel gradient.
…turn values. Cleaned up the viscosity so that it is in hydro.h and the ifdef statements do the selection there instead of directly in hydro_iact.h.
…w terms for artificial conductivity and viscosity. Must use a much lower condition number of matrices to get good results, or else everything blows up.
…ulations to work. New updates to the best parameters.
…locities when computing the timestep and comparisons. Use a new timestep estimator from Gasoline2, similar to MAGMA2 paper but for adaptive timestepping. Apply a pressure difference limiter to the conductivity to prevent spurious conduction. Only allow conduction if the signal speed allows it. Added a factor that can reduce viscosity and conduction in the fallback SPH, since it can be highly over dissipative.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant