Re: Potential energy of gas particles in the adiabatic collapse example

From: Volker Springel <volker_at_MPA-Garching.MPG.DE>
Date: Sun, 01 Mar 2009 09:37:14 +0100

O.A. Vaquero wrote:
> Sander Valcke wrote:
>> Hi Oscar,
>>
>> did you add a piece of code reading the potential data in
>> read_snapshot.c?
>>
>> you can check if the data is written to the snapshot correctly by
>> examining what happens in io.c around line 305.
>>
>> kind regards,
>>
>> Sander
>>
>> O.A. Vaquero wrote:
>>> Hi everybody,
>>>
>>> Well, I am just starting to play with Gadget 2.0.3, and it seems
>>> that after activating the options to compute the potential energy in the
>>> Makefile and creating the binary, the potential energy of the
>>> particles is not stored in the field P[i].Potential, being the value
>>> that is stored
>>>
>>> 0.0 for all the particles, as read with read_snapshot.c. I just try
>>> to do a fprintf(stdout, "%f\n", P[i].Potential) in a loop, and it
>>> returns me for
>>> all the particles 0.00000.
>>>
>>> Can anyone help me? Thank you very much in advance.
>>>
>>> Cheers,
>>>
>>> Oscar
>>>
>>>
>>>
>>>
>>> -----------------------------------------------------------
>>> If you wish to unsubscribe from this mailing, send mail to
>>> minimalist_at_MPA-Garching.MPG.de with a subject of: unsubscribe
>>> gadget-list
>>> A web-archive of this mailing list is available here:
>>> http://www.mpa-garching.mpg.de/gadget/gadget-list
>>
>>
>>
>> -----------------------------------------------------------
>> If you wish to unsubscribe from this mailing, send mail to
>> minimalist_at_MPA-Garching.MPG.de with a subject of: unsubscribe
>> gadget-list
>> A web-archive of this mailing list is available here:
>> http://www.mpa-garching.mpg.de/gadget/gadget-list
> Thank you for the answer. I add the field "Potential " and then just
> write it to a file as with the
> Mass, or Kinetic Energy fields. Like that:
> struct particle_data
> {
> float Pos[3];
> float Vel[3];
> float Mass;
> *float Potential;*
> int Type;
>
> float Rho, U, Temp, Ne;
> } *P;
>
> And then...
>
> for(k=0;k<header1.npart[0];k++){
>
> m=m+P[k].Mass;
>
> ke=ke+0.5*(P[k].Mass)*(pow(P[k].Vel[0],2)+pow(P[k].Vel[1],2)+pow(P[k].Vel[2],2));
> p=p+P[k].Potential;
> u=u+P[k].U;
> fprintf(stdout,"%f\n",p);
>
> }
>

Hi,

Well, this change will not actually read in the potential values... You still
have to modify the load_snapshot() routine for that.

In particular, you probably need to add something like


      SKIP;
      for(k=0,pc_new=pc;k<6;k++)
        {
          for(n=0;n<header1.npart[k];n++)
            {
              fread(&P[pc_new].Potential, sizeof(float), 1, fd);
              pc_new++;
            }
        }
      SKIP;

before the call of fclose(fd), and after the "rho" block has been read for the
gas particles, you also need to add a block that reads in the smoothing lengths,
such that they are properly skipped, like


          SKIP;
          for(n=0, pc_sph=pc; n<header1.npart[0];n++)
            {
              fread(&P[pc_sph].Hsml, sizeof(float), 1, fd);
              pc_sph++;
            }
          SKIP;



Volker





> Thank you again
>
> Cheers,
>
> Oscar
>
>
>
>
> -----------------------------------------------------------
>
> If you wish to unsubscribe from this mailing, send mail to
> minimalist_at_MPA-Garching.MPG.de with a subject of: unsubscribe gadget-list
> A web-archive of this mailing list is available here:
> http://www.mpa-garching.mpg.de/gadget/gadget-list
Received on 2009-03-01 09:37:14

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