Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
3f70533d
Commit
3f70533d
authored
Jan 23, 2017
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Can correctly read/write star particles alongside other combinations of gas/DM
parent
7e42c4cb
No related branches found
No related tags found
2 merge requests
!310
Star particles and gparts links over MPI
,
!304
Star particle infrastructure
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
examples/MultiTypes/makeIC.py
+38
-2
38 additions, 2 deletions
examples/MultiTypes/makeIC.py
examples/main.c
+4
-2
4 additions, 2 deletions
examples/main.c
src/single_io.c
+46
-28
46 additions, 28 deletions
src/single_io.c
src/single_io.h
+1
-0
1 addition, 0 deletions
src/single_io.h
with
89 additions
and
32 deletions
examples/MultiTypes/makeIC.py
+
38
−
2
View file @
3f70533d
...
@@ -36,6 +36,9 @@ eta = 1.2349 # 48 ngbs with cubic spline kernel
...
@@ -36,6 +36,9 @@ eta = 1.2349 # 48 ngbs with cubic spline kernel
rhoDM
=
1.
rhoDM
=
1.
Ldm
=
int
(
sys
.
argv
[
2
])
# Number of particles along one axis
Ldm
=
int
(
sys
.
argv
[
2
])
# Number of particles along one axis
massStars
=
0.1
Lstars
=
int
(
sys
.
argv
[
3
])
# Number of particles along one axis
fileName
=
"
multiTypes.hdf5
"
fileName
=
"
multiTypes.hdf5
"
#---------------------------------------------------
#---------------------------------------------------
...
@@ -46,6 +49,10 @@ internalEnergy = P / ((gamma - 1.)*rhoGas)
...
@@ -46,6 +49,10 @@ internalEnergy = P / ((gamma - 1.)*rhoGas)
numDM
=
Ldm
**
3
numDM
=
Ldm
**
3
massDM
=
boxSize
**
3
*
rhoDM
/
numDM
massDM
=
boxSize
**
3
*
rhoDM
/
numDM
numStars
=
Lstars
**
3
massStars
=
massDM
*
massStars
#--------------------------------------------------
#--------------------------------------------------
#File
#File
...
@@ -54,9 +61,9 @@ file = h5py.File(fileName, 'w')
...
@@ -54,9 +61,9 @@ file = h5py.File(fileName, 'w')
# Header
# Header
grp
=
file
.
create_group
(
"
/Header
"
)
grp
=
file
.
create_group
(
"
/Header
"
)
grp
.
attrs
[
"
BoxSize
"
]
=
boxSize
grp
.
attrs
[
"
BoxSize
"
]
=
boxSize
grp
.
attrs
[
"
NumPart_Total
"
]
=
[
numGas
,
numDM
,
0
,
0
,
0
,
0
]
grp
.
attrs
[
"
NumPart_Total
"
]
=
[
numGas
,
numDM
,
0
,
0
,
numStars
,
0
]
grp
.
attrs
[
"
NumPart_Total_HighWord
"
]
=
[
0
,
0
,
0
,
0
,
0
,
0
]
grp
.
attrs
[
"
NumPart_Total_HighWord
"
]
=
[
0
,
0
,
0
,
0
,
0
,
0
]
grp
.
attrs
[
"
NumPart_ThisFile
"
]
=
[
numGas
,
numDM
,
0
,
0
,
0
,
0
]
grp
.
attrs
[
"
NumPart_ThisFile
"
]
=
[
numGas
,
numDM
,
0
,
0
,
numStars
,
0
]
grp
.
attrs
[
"
Time
"
]
=
0.0
grp
.
attrs
[
"
Time
"
]
=
0.0
grp
.
attrs
[
"
NumFilesPerSnapshot
"
]
=
1
grp
.
attrs
[
"
NumFilesPerSnapshot
"
]
=
1
grp
.
attrs
[
"
MassTable
"
]
=
[
0.0
,
massDM
,
0.0
,
0.0
,
0.0
,
0.0
]
grp
.
attrs
[
"
MassTable
"
]
=
[
0.0
,
massDM
,
0.0
,
0.0
,
0.0
,
0.0
]
...
@@ -142,4 +149,33 @@ coords[:,2] = x[:,0] * boxSize / Ldm + boxSize / (2*Ldm)
...
@@ -142,4 +149,33 @@ coords[:,2] = x[:,0] * boxSize / Ldm + boxSize / (2*Ldm)
ds
=
grp
.
create_dataset
(
'
Coordinates
'
,
(
numDM
,
3
),
'
d
'
)
ds
=
grp
.
create_dataset
(
'
Coordinates
'
,
(
numDM
,
3
),
'
d
'
)
ds
[()]
=
coords
ds
[()]
=
coords
# Star Particle group
grp
=
file
.
create_group
(
"
/PartType4
"
)
v
=
zeros
((
numStars
,
3
))
ds
=
grp
.
create_dataset
(
'
Velocities
'
,
(
numStars
,
3
),
'
f
'
)
ds
[()]
=
v
v
=
zeros
(
1
)
m
=
full
((
numStars
,
1
),
massStars
)
ds
=
grp
.
create_dataset
(
'
Masses
'
,
(
numStars
,
1
),
'
f
'
)
ds
[()]
=
m
m
=
zeros
(
1
)
ids
=
linspace
(
0
,
numStars
,
numStars
,
endpoint
=
False
).
reshape
((
numStars
,
1
))
ds
=
grp
.
create_dataset
(
'
ParticleIDs
'
,
(
numStars
,
1
),
'
L
'
)
ds
[()]
=
ids
+
Lgas
**
3
+
1
x
=
ids
%
Ldm
;
y
=
((
ids
-
x
)
/
Ldm
)
%
Ldm
;
z
=
(
ids
-
x
-
Ldm
*
y
)
/
Ldm
**
2
;
coords
=
zeros
((
numStars
,
3
))
coords
[:,
0
]
=
z
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
coords
[:,
1
]
=
y
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
coords
[:,
2
]
=
x
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
ds
=
grp
.
create_dataset
(
'
Coordinates
'
,
(
numStars
,
3
),
'
d
'
)
ds
[()]
=
coords
file
.
close
()
file
.
close
()
This diff is collapsed.
Click to expand it.
examples/main.c
+
4
−
2
View file @
3f70533d
...
@@ -393,7 +393,9 @@ int main(int argc, char *argv[]) {
...
@@ -393,7 +393,9 @@ int main(int argc, char *argv[]) {
#endif
#endif
#else
#else
read_ic_single
(
ICfileName
,
&
us
,
dim
,
&
parts
,
&
gparts
,
&
sparts
,
&
Ngas
,
&
Ngpart
,
read_ic_single
(
ICfileName
,
&
us
,
dim
,
&
parts
,
&
gparts
,
&
sparts
,
&
Ngas
,
&
Ngpart
,
&
Nspart
,
&
periodic
,
&
flag_entropy_ICs
,
dry_run
);
&
Nspart
,
&
periodic
,
&
flag_entropy_ICs
,
with_hydro
,
(
with_external_gravity
||
with_self_gravity
),
with_stars
,
dry_run
);
#endif
#endif
if
(
myrank
==
0
)
{
if
(
myrank
==
0
)
{
clocks_gettime
(
&
toc
);
clocks_gettime
(
&
toc
);
...
@@ -414,7 +416,7 @@ int main(int argc, char *argv[]) {
...
@@ -414,7 +416,7 @@ int main(int argc, char *argv[]) {
if
(
!
with_stars
)
{
if
(
!
with_stars
)
{
free
(
sparts
);
free
(
sparts
);
sparts
=
NULL
;
sparts
=
NULL
;
for
(
size_t
k
=
0
;
k
<
N
s
part
;
++
k
)
for
(
size_t
k
=
0
;
k
<
N
g
part
;
++
k
)
if
(
gparts
[
k
].
type
==
swift_type_star
)
error
(
"Linking problem"
);
if
(
gparts
[
k
].
type
==
swift_type_star
)
error
(
"Linking problem"
);
Nspart
=
0
;
Nspart
=
0
;
}
}
...
...
...
...
This diff is collapsed.
Click to expand it.
src/single_io.c
+
46
−
28
View file @
3f70533d
...
@@ -337,6 +337,7 @@ void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
...
@@ -337,6 +337,7 @@ void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
double
dim
[
3
],
struct
part
**
parts
,
struct
gpart
**
gparts
,
double
dim
[
3
],
struct
part
**
parts
,
struct
gpart
**
gparts
,
struct
spart
**
sparts
,
size_t
*
Ngas
,
size_t
*
Ngparts
,
struct
spart
**
sparts
,
size_t
*
Ngas
,
size_t
*
Ngparts
,
size_t
*
Nstars
,
int
*
periodic
,
int
*
flag_entropy
,
size_t
*
Nstars
,
int
*
periodic
,
int
*
flag_entropy
,
int
with_hydro
,
int
with_gravity
,
int
with_stars
,
int
dry_run
)
{
int
dry_run
)
{
hid_t
h_file
=
0
,
h_grp
=
0
;
hid_t
h_file
=
0
,
h_grp
=
0
;
...
@@ -443,26 +444,32 @@ void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
...
@@ -443,26 +444,32 @@ void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
units_conversion_factor
(
ic_units
,
internal_units
,
UNIT_CONV_LENGTH
);
units_conversion_factor
(
ic_units
,
internal_units
,
UNIT_CONV_LENGTH
);
/* Allocate memory to store SPH particles */
/* Allocate memory to store SPH particles */
if
(
with_hydro
)
{
*
Ngas
=
N
[
GAS
];
*
Ngas
=
N
[
GAS
];
if
(
posix_memalign
((
void
*
)
parts
,
part_align
,
*
Ngas
*
sizeof
(
struct
part
))
!=
if
(
posix_memalign
((
void
*
)
parts
,
part_align
,
*
Ngas
*
sizeof
(
struct
part
))
!=
0
)
0
)
error
(
"Error while allocating memory for SPH particles"
);
error
(
"Error while allocating memory for SPH particles"
);
bzero
(
*
parts
,
*
Ngas
*
sizeof
(
struct
part
));
bzero
(
*
parts
,
*
Ngas
*
sizeof
(
struct
part
));
}
/* Allocate memory to store star particles */
/* Allocate memory to store star particles */
if
(
with_stars
)
{
*
Nstars
=
N
[
STAR
];
*
Nstars
=
N
[
STAR
];
if
(
posix_memalign
((
void
*
)
sparts
,
spart_align
,
if
(
posix_memalign
((
void
*
)
sparts
,
spart_align
,
*
Nstars
*
sizeof
(
struct
spart
))
!=
0
)
*
Nstars
*
sizeof
(
struct
spart
))
!=
0
)
error
(
"Error while allocating memory for star particles"
);
error
(
"Error while allocating memory for star particles"
);
bzero
(
*
sparts
,
*
Nstars
*
sizeof
(
struct
spart
));
bzero
(
*
sparts
,
*
Nstars
*
sizeof
(
struct
spart
));
}
/* Allocate memory to store all particles */
/* Allocate memory to store all gravity particles */
if
(
with_gravity
)
{
Ndm
=
N
[
DM
];
Ndm
=
N
[
DM
];
*
Ngparts
=
N
[
GAS
]
+
N
[
DM
]
+
N
[
STAR
];
*
Ngparts
=
(
with_hydro
?
N
[
GAS
]
:
0
)
+
N
[
DM
]
+
(
with_stars
?
N
[
STAR
]
:
0
)
;
if
(
posix_memalign
((
void
*
)
gparts
,
gpart_align
,
if
(
posix_memalign
((
void
*
)
gparts
,
gpart_align
,
*
Ngparts
*
sizeof
(
struct
gpart
))
!=
0
)
*
Ngparts
*
sizeof
(
struct
gpart
))
!=
0
)
error
(
"Error while allocating memory for gravity particles"
);
error
(
"Error while allocating memory for gravity particles"
);
bzero
(
*
gparts
,
*
Ngparts
*
sizeof
(
struct
gpart
));
bzero
(
*
gparts
,
*
Ngparts
*
sizeof
(
struct
gpart
));
}
/* message("Allocated %8.2f MB for particles.", *N * sizeof(struct part) /
/* message("Allocated %8.2f MB for particles.", *N * sizeof(struct part) /
* (1024.*1024.)); */
* (1024.*1024.)); */
...
@@ -493,18 +500,24 @@ void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
...
@@ -493,18 +500,24 @@ void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
switch
(
ptype
)
{
switch
(
ptype
)
{
case
GAS
:
case
GAS
:
if
(
with_hydro
)
{
Nparticles
=
*
Ngas
;
Nparticles
=
*
Ngas
;
hydro_read_particles
(
*
parts
,
list
,
&
num_fields
);
hydro_read_particles
(
*
parts
,
list
,
&
num_fields
);
}
break
;
break
;
case
DM
:
case
DM
:
if
(
with_gravity
)
{
Nparticles
=
Ndm
;
Nparticles
=
Ndm
;
darkmatter_read_particles
(
*
gparts
,
list
,
&
num_fields
);
darkmatter_read_particles
(
*
gparts
,
list
,
&
num_fields
);
}
break
;
break
;
case
STAR
:
case
STAR
:
if
(
with_stars
)
{
Nparticles
=
*
Nstars
;
Nparticles
=
*
Nstars
;
star_read_particles
(
*
sparts
,
list
,
&
num_fields
);
star_read_particles
(
*
sparts
,
list
,
&
num_fields
);
}
break
;
break
;
default:
default:
...
@@ -521,13 +534,15 @@ void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
...
@@ -521,13 +534,15 @@ void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
}
}
/* Prepare the DM particles */
/* Prepare the DM particles */
if
(
!
dry_run
)
prepare_dm_gparts
(
*
gparts
,
Ndm
);
if
(
!
dry_run
&&
with_gravity
)
prepare_dm_gparts
(
*
gparts
,
Ndm
);
/* Duplicate the hydro particles into gparts */
/* Duplicate the hydro particles into gparts */
if
(
!
dry_run
)
duplicate_hydro_gparts
(
*
parts
,
*
gparts
,
*
Ngas
,
Ndm
);
if
(
!
dry_run
&&
with_gravity
&&
with_hydro
)
duplicate_hydro_gparts
(
*
parts
,
*
gparts
,
*
Ngas
,
Ndm
);
/* Duplicate the star particles into gparts */
/* Duplicate the star particles into gparts */
if
(
!
dry_run
)
duplicate_star_gparts
(
*
sparts
,
*
gparts
,
*
Nstars
,
Ndm
+
*
Ngas
);
if
(
!
dry_run
&&
with_gravity
&&
with_stars
)
duplicate_star_gparts
(
*
sparts
,
*
gparts
,
*
Nstars
,
Ndm
+
*
Ngas
);
/* message("Done Reading particles..."); */
/* message("Done Reading particles..."); */
...
@@ -765,7 +780,10 @@ void write_output_single(struct engine* e, const char* baseName,
...
@@ -765,7 +780,10 @@ void write_output_single(struct engine* e, const char* baseName,
internal_units
,
snapshot_units
);
internal_units
,
snapshot_units
);
/* Free temporary array */
/* Free temporary array */
if
(
dmparts
)
{
free
(
dmparts
);
free
(
dmparts
);
dmparts
=
NULL
;
}
/* Close particle group */
/* Close particle group */
H5Gclose
(
h_grp
);
H5Gclose
(
h_grp
);
...
...
...
...
This diff is collapsed.
Click to expand it.
src/single_io.h
+
1
−
0
View file @
3f70533d
...
@@ -33,6 +33,7 @@ void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
...
@@ -33,6 +33,7 @@ void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
double
dim
[
3
],
struct
part
**
parts
,
struct
gpart
**
gparts
,
double
dim
[
3
],
struct
part
**
parts
,
struct
gpart
**
gparts
,
struct
spart
**
sparts
,
size_t
*
Ngas
,
size_t
*
Ndm
,
struct
spart
**
sparts
,
size_t
*
Ngas
,
size_t
*
Ndm
,
size_t
*
Nstars
,
int
*
periodic
,
int
*
flag_entropy
,
size_t
*
Nstars
,
int
*
periodic
,
int
*
flag_entropy
,
int
with_hydro
,
int
with_gravity
,
int
with_stars
,
int
dry_run
);
int
dry_run
);
void
write_output_single
(
struct
engine
*
e
,
const
char
*
baseName
,
void
write_output_single
(
struct
engine
*
e
,
const
char
*
baseName
,
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment