Re: Piecewise equation of state in Gadget code

From: Volker Springel <vspringel_at_MPA-Garching.MPG.DE>
Date: Tue, 16 Aug 2022 08:55:02 +0200

Dear Hassan,

Yes, this should be easily possible.

There is only one place in the code that defines the pressure of a particle. In the file src/data/sph_particle_data.h you should find a function get_pressure(). This defines the pressure of a particle (i.e. the equation of state). You could modify what is returned and make it density dependent. This would be one possible approach to implement the behaviour you want.

I note however that GAMMA itself is a compile-time constant. Probably a preferable approach to achieve your desired behavior would be to run the code in normal adiabatic mode. But below your threshold density, you reset the thermal energy (or entropy for that matter) of particles in each timestep such that you enforce isothermal conditions for them. This effectively corresponds to a cooling/heating function that brings back the particle temperature to constant value on an arbitrarily short timescale.


> On 9. Aug 2022, at 13:39, Hassan Fathivavsari <> wrote:
> Dear all,
> I am using Gadget 4 to simulate the collapse of a spherical gas cloud.
> Initially, the process is isothermal but when the density reaches a
> certain value, the process becomes adiabatic. Therefore, I would need
> the Gadget code to consider a piecewise equation of state depending
> on the gas density. Would it be possible to do this in Gadget code?
> I would be grateful for any help with this.
> Many thanks.
> Best regards,
> Hassan
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> with a subject of: unsubscribe gadget-list
> A web-archive of this mailing list is available here:
Received on 2022-08-16 08:55:02

This archive was generated by hypermail 2.3.0 : 2022-09-01 14:03:43 CEST