Re: change of particle type

From: Volker Springel <volker_at_MPA-Garching.MPG.DE>
Date: Sat, 10 Sep 2005 18:04:48 +0200

Hi Yves,

Thanks for your clear description of what you changed. I don't see
anything wrong with it, but I think there is a way to avoid having to
rebuild the tree each time you change the type of a particle. This can
then lead to a speed improvement if the type-changes occur frequently.

Note that in treatments of star formation one also typically converts a
type=0 gas particle to a collisionless type. So here one faces the same
issue that you dealt with.

The trick is to (temporarily) give up the requirement that all gas
particles form a contiguous block of length "N_gas" at the beginning of
the particle list. Instead, one can allow for other particle types
within the gas particle block, provided one:

* sets N_gas to one plus the index of the last gas particle (i.e. it
then does not give the actual number of gas particles any more)

* one puts an explicit "if(P[i].Type == 0)" around the body of
"for(i=0;i<N_gas;i++)" loops in density.c, hydra.c, etc.

Once this is done, one can simply change the type of a particle from
type=0 to one of the collisionless types without the need to reconstruct
the tree, and without reducing N_gas. The code will continue just fine.

However, one has to reestablish the proper particle order (i.e. all gas
particles at the beginning) before any of the following:

- a new domain decomposition is done
- a snapshot file is written

For example, one can construct a routine
"rearrange_particle_sequence();" for the reshuffling, which is invoked
in these cases and reduces N_gas back to the real number of gas particles.


Yves Revaz wrote:

> Dear Gadget list,
> One of my aim using Gadget is to simulate a multiphase interstellar
> medium.
> Particles of gas could become non-collisional, like stars and then,
> come back in
> the collisional phase.
> In a first step, I tried to move gas particles in halo type particles.
> To my great surprise,
> it seems to be much more easy than what I thought (Thanks to the
> excellent implementation of Volker ;-) ).
> Here is in summary what I have implemented:
> 1) The routine that changes particle types must be applied when the
> system is synchronized (in run.c),
> after find_next_sync_point_and_drift(); and every_timestep_stuff();,
> before domain_Decomposition();.
> 2) Moving gas particles to a non collisional phase corresponds to
> moving gas elements of P and SphP
> (belonging to the first N_gas positions) after this first N_gas
> positions.
> This operation can be achieved with the function "memmove".
> 3) Update N_gas (N_gas = N_gas - N_move)
> 4) Update All.TotN_gas
> 5) Ensures that a new tree will be constructed
> That's it !
> Some quick tests show a good conservation of the energy,
> meaning that I'm probably on the right way.
> I will be very interested if someone has comments or suggestions about
> the
> procedure used here, especially if something seems to be wrong or may
> be better implemented.
> Cheers.
Received on 2005-09-10 18:04:54

This archive was generated by hypermail 2.3.0 : 2023-01-10 10:01:30 CET