Skip to content

Commit 9db73e1

Browse files
author
Martin D. Weinberg
committed
Updated Bonsai reader variant to v2
1 parent 4eaa424 commit 9db73e1

3 files changed

Lines changed: 32 additions & 17 deletions

File tree

exputil/ParticleReader.cc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,7 @@ namespace PR {
18961896

18971897
std::vector<std::string> ParticleReader::readerTypes
18981898
{"PSPout", "PSPspl", "GadgetNative", "GadgetHDF5", "PSPhdf5",
1899-
"TipsyNative", "TipsyXDR", "Bonsai"};
1899+
"TipsyNative", "TipsyXDR", "ChaNGa", "Bonsai"};
19001900

19011901

19021902
std::vector<std::vector<std::string>>
@@ -2031,7 +2031,8 @@ namespace PR {
20312031
exit(1);
20322032
}
20332033
#endif
2034-
2034+
else if (reader.find("ChaNGa") == 0)
2035+
ret = std::make_shared<Tipsy>(file, Tipsy::TipsyType::changa, verbose);
20352036
else if (reader.find("Bonsai") == 0)
20362037
ret = std::make_shared<Tipsy>(file, Tipsy::TipsyType::bonsai, verbose);
20372038
else {
@@ -2184,8 +2185,7 @@ namespace PR {
21842185
P.pos[k] = ps->gas_particles[pcount].pos[k];
21852186
P.vel[k] = ps->gas_particles[pcount].vel[k];
21862187
}
2187-
if (ttype == TipsyType::bonsai) P.indx = ps->gas_particles[pcount].ID();
2188-
else P.indx = ps->getIndexOffset(TipsyReader::Ptype::gas) + pcount + 1;
2188+
P.indx = ps->getIndexOffset(TipsyReader::Ptype::gas) + pcount + 1;
21892189

21902190
pcount++;
21912191
return;
@@ -2198,8 +2198,12 @@ namespace PR {
21982198
P.pos[k] = ps->dark_particles[pcount].pos[k];
21992199
P.vel[k] = ps->dark_particles[pcount].vel[k];
22002200
}
2201-
if (ttype == TipsyType::bonsai) P.indx = ps->dark_particles[pcount].ID();
2202-
else P.indx = ps->getIndexOffset(TipsyReader::Ptype::dark) + pcount + 1;
2201+
if (ttype == TipsyType::bonsai)
2202+
P.indx = ps->dark_particles[pcount].ID2();
2203+
else if (ttype == TipsyType::changa)
2204+
P.indx = ps->dark_particles[pcount].ID();
2205+
else
2206+
P.indx = ps->getIndexOffset(TipsyReader::Ptype::dark) + pcount + 1;
22032207

22042208
pcount++;
22052209
return;
@@ -2212,8 +2216,12 @@ namespace PR {
22122216
P.pos[k] = ps->star_particles[pcount].pos[k];
22132217
P.vel[k] = ps->star_particles[pcount].vel[k];
22142218
}
2215-
if (ttype == TipsyType::bonsai) P.indx = ps->star_particles[pcount].ID();
2216-
else P.indx = ps->getIndexOffset(TipsyReader::Ptype::star) + pcount + 1;
2219+
if (ttype == TipsyType::bonsai)
2220+
P.indx = ps->star_particles[pcount].ID2();
2221+
else if (ttype == TipsyType::changa)
2222+
P.indx = ps->star_particles[pcount].ID();
2223+
else
2224+
P.indx = ps->getIndexOffset(TipsyReader::Ptype::star) + pcount + 1;
22172225

22182226
pcount++;
22192227
return;

include/ParticleReader.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ namespace PR
573573

574574
public:
575575

576-
enum class TipsyType { native, xdr, bonsai };
576+
enum class TipsyType { native, xdr, changa, bonsai };
577577

578578
private:
579579
//! List of files

include/tipsy.H

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ namespace TipsyReader
4040
Real metals ;
4141
Real phi ;
4242
//@}
43-
44-
//! Convert phi to index for Bonsai
45-
int ID() const {
46-
union id {Real v; int i;} u;
47-
u.v = phi; return u.i;
48-
}
4943
} ;
5044

5145
struct dark_particle
@@ -59,11 +53,18 @@ namespace TipsyReader
5953
Real phi ;
6054
//@}
6155

62-
//! Convert phi to index for Bonsai
56+
//! Convert phi to 32-bit index for ChaNGa
6357
int ID() const {
6458
union id {Real v; int i;} u;
6559
u.v = phi; return u.i;
6660
}
61+
62+
//! Convert phi to 64-bit index for Bonsai
63+
unsigned long ID2() const {
64+
union id {Real v[2]; uint64_t i;} u;
65+
u.v[0] = eps; u.v[1] = phi; return u.i;
66+
}
67+
6768
} ;
6869

6970
struct star_particle
@@ -79,11 +80,17 @@ namespace TipsyReader
7980
Real phi ;
8081
//@}
8182

82-
//! Convert phi to index for Bonsai
83+
//! Convert phi to 32-bit index for ChaNGa
8384
int ID() const {
8485
union id {Real v; int i;} u;
8586
u.v = phi; return u.i;
8687
}
88+
89+
//! Convert exp, phi to 64bit index for Bonsai
90+
unsigned long ID2() const {
91+
union id {Real v[2]; uint64_t i;} u;
92+
u.v[0] = eps; u.v[1] = phi; return u.i;
93+
}
8794
} ;
8895

8996
struct Header

0 commit comments

Comments
 (0)