Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
7bd06f71
Commit
7bd06f71
authored
Feb 19, 2017
by
Matthieu Schaller
Browse files
Refactoed the i/o code to match the coding style of the rest of the code.
parent
4421af3e
Changes
18
Expand all
Hide whitespace changes
Inline
Side-by-side
src/Makefile.am
View file @
7bd06f71
...
...
@@ -45,7 +45,7 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \
physical_constants.h physical_constants_cgs.h potential.h version.h
\
hydro_properties.h riemann.h threadpool.h cooling.h cooling_struct.h sourceterms.h
\
sourceterms_struct.h statistics.h memswap.h cache.h runner_doiact_vec.h profiler.h
\
dump.h logger.h active.h timeline.h
dump.h logger.h active.h timeline.h
xmf.h
# Common source files
AM_SOURCES
=
space.c runner.c queue.c task.c cell.c engine.c
\
...
...
@@ -54,7 +54,8 @@ AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \
kernel_hydro.c tools.c part.c partition.c clocks.c parser.c
\
physical_constants.c potential.c hydro_properties.c
\
runner_doiact_fft.c threadpool.c cooling.c sourceterms.c
\
statistics.c runner_doiact_vec.c profiler.c dump.c logger.c
statistics.c runner_doiact_vec.c profiler.c dump.c logger.c
\
part_type.c xmf.c
# Include files for distribution, not installation.
nobase_noinst_HEADERS
=
align.h approx_math.h atomic.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h
\
...
...
src/common_io.c
View file @
7bd06f71
...
...
@@ -47,9 +47,6 @@
#include
"units.h"
#include
"version.h"
const
char
*
particle_type_names
[
NUM_PARTICLE_TYPES
]
=
{
"Gas"
,
"DM"
,
"Boundary"
,
"Dummy"
,
"Star"
,
"BH"
};
/**
* @brief Converts a C data type to the HDF5 equivalent.
*
...
...
@@ -57,7 +54,7 @@ const char* particle_type_names[NUM_PARTICLE_TYPES] = {
* to change the exact storage types matching the code types in a transparent
*way.
*/
hid_t
hdf5
T
ype
(
enum
DATA_TYPE
type
)
{
hid_t
io_
hdf5
_t
ype
(
enum
IO_
DATA_TYPE
type
)
{
switch
(
type
)
{
case
INT
:
...
...
@@ -87,7 +84,7 @@ hid_t hdf5Type(enum DATA_TYPE type) {
/**
* @brief Returns the memory size of the data type
*/
size_t
size
OfT
ype
(
enum
DATA_TYPE
type
)
{
size_t
io_
size
of_t
ype
(
enum
IO_
DATA_TYPE
type
)
{
switch
(
type
)
{
case
INT
:
...
...
@@ -119,7 +116,7 @@ size_t sizeOfType(enum DATA_TYPE type) {
*
* Returns an error if the type is not FLOAT or DOUBLE
*/
int
i
sD
ouble
P
recision
(
enum
DATA_TYPE
type
)
{
int
i
o_is_d
ouble
_p
recision
(
enum
IO_
DATA_TYPE
type
)
{
switch
(
type
)
{
case
FLOAT
:
...
...
@@ -142,7 +139,8 @@ int isDoublePrecision(enum DATA_TYPE type) {
*
* Calls #error() if an error occurs.
*/
void
readAttribute
(
hid_t
grp
,
char
*
name
,
enum
DATA_TYPE
type
,
void
*
data
)
{
void
io_read_attribute
(
hid_t
grp
,
char
*
name
,
enum
IO_DATA_TYPE
type
,
void
*
data
)
{
hid_t
h_attr
=
0
,
h_err
=
0
;
h_attr
=
H5Aopen
(
grp
,
name
,
H5P_DEFAULT
);
...
...
@@ -150,7 +148,7 @@ void readAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data) {
error
(
"Error while opening attribute '%s'"
,
name
);
}
h_err
=
H5Aread
(
h_attr
,
hdf5
T
ype
(
type
),
data
);
h_err
=
H5Aread
(
h_attr
,
io_
hdf5
_t
ype
(
type
),
data
);
if
(
h_err
<
0
)
{
error
(
"Error while reading attribute '%s'"
,
name
);
}
...
...
@@ -169,8 +167,8 @@ void readAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data) {
*
* Calls #error() if an error occurs.
*/
void
write
A
ttribute
(
hid_t
grp
,
const
char
*
name
,
enum
DATA_TYPE
type
,
void
*
data
,
int
num
)
{
void
io_
write
_a
ttribute
(
hid_t
grp
,
const
char
*
name
,
enum
IO_
DATA_TYPE
type
,
void
*
data
,
int
num
)
{
hid_t
h_space
=
0
,
h_attr
=
0
,
h_err
=
0
;
hsize_t
dim
[
1
]
=
{
num
};
...
...
@@ -184,12 +182,12 @@ void writeAttribute(hid_t grp, const char* name, enum DATA_TYPE type,
error
(
"Error while changing dataspace shape for attribute '%s'."
,
name
);
}
h_attr
=
H5Acreate1
(
grp
,
name
,
hdf5
T
ype
(
type
),
h_space
,
H5P_DEFAULT
);
h_attr
=
H5Acreate1
(
grp
,
name
,
io_
hdf5
_t
ype
(
type
),
h_space
,
H5P_DEFAULT
);
if
(
h_attr
<
0
)
{
error
(
"Error while creating attribute '%s'."
,
name
);
}
h_err
=
H5Awrite
(
h_attr
,
hdf5
T
ype
(
type
),
data
);
h_err
=
H5Awrite
(
h_attr
,
io_
hdf5
_t
ype
(
type
),
data
);
if
(
h_err
<
0
)
{
error
(
"Error while reading attribute '%s'."
,
name
);
}
...
...
@@ -208,8 +206,8 @@ void writeAttribute(hid_t grp, const char* name, enum DATA_TYPE type,
*
* Calls #error() if an error occurs.
*/
void
writeStringAttribute
(
hid_t
grp
,
const
char
*
name
,
const
char
*
str
,
int
length
)
{
void
io_
writeStringAttribute
(
hid_t
grp
,
const
char
*
name
,
const
char
*
str
,
int
length
)
{
hid_t
h_space
=
0
,
h_attr
=
0
,
h_err
=
0
,
h_type
=
0
;
h_space
=
H5Screate
(
H5S_SCALAR
);
...
...
@@ -248,8 +246,8 @@ void writeStringAttribute(hid_t grp, const char* name, const char* str,
* @param name The name of the attribute
* @param data The value to write
*/
void
write
A
ttribute_d
(
hid_t
grp
,
const
char
*
name
,
double
data
)
{
write
A
ttribute
(
grp
,
name
,
DOUBLE
,
&
data
,
1
);
void
io_
write
_a
ttribute_d
(
hid_t
grp
,
const
char
*
name
,
double
data
)
{
io_
write
_a
ttribute
(
grp
,
name
,
DOUBLE
,
&
data
,
1
);
}
/**
...
...
@@ -258,8 +256,8 @@ void writeAttribute_d(hid_t grp, const char* name, double data) {
* @param name The name of the attribute
* @param data The value to write
*/
void
write
A
ttribute_f
(
hid_t
grp
,
const
char
*
name
,
float
data
)
{
write
A
ttribute
(
grp
,
name
,
FLOAT
,
&
data
,
1
);
void
io_
write
_a
ttribute_f
(
hid_t
grp
,
const
char
*
name
,
float
data
)
{
io_
write
_a
ttribute
(
grp
,
name
,
FLOAT
,
&
data
,
1
);
}
/**
...
...
@@ -269,8 +267,8 @@ void writeAttribute_f(hid_t grp, const char* name, float data) {
* @param data The value to write
*/
void
write
A
ttribute_i
(
hid_t
grp
,
const
char
*
name
,
int
data
)
{
write
A
ttribute
(
grp
,
name
,
INT
,
&
data
,
1
);
void
io_
write
_a
ttribute_i
(
hid_t
grp
,
const
char
*
name
,
int
data
)
{
io_
write
_a
ttribute
(
grp
,
name
,
INT
,
&
data
,
1
);
}
/**
...
...
@@ -279,8 +277,8 @@ void writeAttribute_i(hid_t grp, const char* name, int data) {
* @param name The name of the attribute
* @param data The value to write
*/
void
write
A
ttribute_l
(
hid_t
grp
,
const
char
*
name
,
long
data
)
{
write
A
ttribute
(
grp
,
name
,
LONG
,
&
data
,
1
);
void
io_
write
_a
ttribute_l
(
hid_t
grp
,
const
char
*
name
,
long
data
)
{
io_
write
_a
ttribute
(
grp
,
name
,
LONG
,
&
data
,
1
);
}
/**
...
...
@@ -289,8 +287,8 @@ void writeAttribute_l(hid_t grp, const char* name, long data) {
* @param name The name of the attribute
* @param str The string to write
*/
void
write
A
ttribute_s
(
hid_t
grp
,
const
char
*
name
,
const
char
*
str
)
{
writeStringAttribute
(
grp
,
name
,
str
,
strlen
(
str
));
void
io_
write
_a
ttribute_s
(
hid_t
grp
,
const
char
*
name
,
const
char
*
str
)
{
io_
writeStringAttribute
(
grp
,
name
,
str
,
strlen
(
str
));
}
/**
...
...
@@ -300,7 +298,7 @@ void writeAttribute_s(hid_t grp, const char* name, const char* str) {
*
* If the 'Units' group does not exist in the ICs, cgs units will be assumed
*/
void
readUnitSystem
(
hid_t
h_file
,
struct
UnitSystem
*
us
)
{
void
io_
read
_
UnitSystem
(
hid_t
h_file
,
struct
UnitSystem
*
us
)
{
hid_t
h_grp
=
H5Gopen
(
h_file
,
"/Units"
,
H5P_DEFAULT
);
...
...
@@ -318,14 +316,16 @@ void readUnitSystem(hid_t h_file, struct UnitSystem* us) {
}
/* Ok, Read the damn thing */
readAttribute
(
h_grp
,
"Unit length in cgs (U_L)"
,
DOUBLE
,
&
us
->
UnitLength_in_cgs
);
readAttribute
(
h_grp
,
"Unit mass in cgs (U_M)"
,
DOUBLE
,
&
us
->
UnitMass_in_cgs
);
readAttribute
(
h_grp
,
"Unit time in cgs (U_t)"
,
DOUBLE
,
&
us
->
UnitTime_in_cgs
);
readAttribute
(
h_grp
,
"Unit current in cgs (U_I)"
,
DOUBLE
,
&
us
->
UnitCurrent_in_cgs
);
readAttribute
(
h_grp
,
"Unit temperature in cgs (U_T)"
,
DOUBLE
,
&
us
->
UnitTemperature_in_cgs
);
io_read_attribute
(
h_grp
,
"Unit length in cgs (U_L)"
,
DOUBLE
,
&
us
->
UnitLength_in_cgs
);
io_read_attribute
(
h_grp
,
"Unit mass in cgs (U_M)"
,
DOUBLE
,
&
us
->
UnitMass_in_cgs
);
io_read_attribute
(
h_grp
,
"Unit time in cgs (U_t)"
,
DOUBLE
,
&
us
->
UnitTime_in_cgs
);
io_read_attribute
(
h_grp
,
"Unit current in cgs (U_I)"
,
DOUBLE
,
&
us
->
UnitCurrent_in_cgs
);
io_read_attribute
(
h_grp
,
"Unit temperature in cgs (U_T)"
,
DOUBLE
,
&
us
->
UnitTemperature_in_cgs
);
/* Clean up */
H5Gclose
(
h_grp
);
...
...
@@ -337,23 +337,23 @@ void readUnitSystem(hid_t h_file, struct UnitSystem* us) {
* @param us The UnitSystem to dump
* @param groupName The name of the HDF5 group to write to
*/
void
writeUnitSystem
(
hid_t
h_file
,
const
struct
UnitSystem
*
us
,
const
char
*
groupName
)
{
void
io_
write
_
UnitSystem
(
hid_t
h_file
,
const
struct
UnitSystem
*
us
,
const
char
*
groupName
)
{
hid_t
h_grpunit
=
0
;
h_grpunit
=
H5Gcreate1
(
h_file
,
groupName
,
0
);
if
(
h_grpunit
<
0
)
error
(
"Error while creating Unit System group"
);
write
A
ttribute_d
(
h_grpunit
,
"Unit mass in cgs (U_M)"
,
units_get_base_unit
(
us
,
UNIT_MASS
));
write
A
ttribute_d
(
h_grpunit
,
"Unit length in cgs (U_L)"
,
units_get_base_unit
(
us
,
UNIT_LENGTH
));
write
A
ttribute_d
(
h_grpunit
,
"Unit time in cgs (U_t)"
,
units_get_base_unit
(
us
,
UNIT_TIME
));
write
A
ttribute_d
(
h_grpunit
,
"Unit current in cgs (U_I)"
,
units_get_base_unit
(
us
,
UNIT_CURRENT
));
write
A
ttribute_d
(
h_grpunit
,
"Unit temperature in cgs (U_T)"
,
units_get_base_unit
(
us
,
UNIT_TEMPERATURE
));
io_
write
_a
ttribute_d
(
h_grpunit
,
"Unit mass in cgs (U_M)"
,
units_get_base_unit
(
us
,
UNIT_MASS
));
io_
write
_a
ttribute_d
(
h_grpunit
,
"Unit length in cgs (U_L)"
,
units_get_base_unit
(
us
,
UNIT_LENGTH
));
io_
write
_a
ttribute_d
(
h_grpunit
,
"Unit time in cgs (U_t)"
,
units_get_base_unit
(
us
,
UNIT_TIME
));
io_
write
_a
ttribute_d
(
h_grpunit
,
"Unit current in cgs (U_I)"
,
units_get_base_unit
(
us
,
UNIT_CURRENT
));
io_
write
_a
ttribute_d
(
h_grpunit
,
"Unit temperature in cgs (U_T)"
,
units_get_base_unit
(
us
,
UNIT_TEMPERATURE
));
H5Gclose
(
h_grpunit
);
}
...
...
@@ -362,31 +362,32 @@ void writeUnitSystem(hid_t h_file, const struct UnitSystem* us,
* @brief Writes the code version to the file
* @param h_file The (opened) HDF5 file in which to write
*/
void
write
C
ode
D
escription
(
hid_t
h_file
)
{
void
io_
write
_c
ode
_d
escription
(
hid_t
h_file
)
{
hid_t
h_grpcode
=
0
;
h_grpcode
=
H5Gcreate1
(
h_file
,
"/Code"
,
0
);
if
(
h_grpcode
<
0
)
error
(
"Error while creating code group"
);
writeAttribute_s
(
h_grpcode
,
"Code Version"
,
package_version
());
writeAttribute_s
(
h_grpcode
,
"Compiler Name"
,
compiler_name
());
writeAttribute_s
(
h_grpcode
,
"Compiler Version"
,
compiler_version
());
writeAttribute_s
(
h_grpcode
,
"Git Branch"
,
git_branch
());
writeAttribute_s
(
h_grpcode
,
"Git Revision"
,
git_revision
());
writeAttribute_s
(
h_grpcode
,
"Git Date"
,
git_date
());
writeAttribute_s
(
h_grpcode
,
"Configuration options"
,
configuration_options
());
writeAttribute_s
(
h_grpcode
,
"CFLAGS"
,
compilation_cflags
());
writeAttribute_s
(
h_grpcode
,
"HDF5 library version"
,
hdf5_version
());
io_write_attribute_s
(
h_grpcode
,
"Code Version"
,
package_version
());
io_write_attribute_s
(
h_grpcode
,
"Compiler Name"
,
compiler_name
());
io_write_attribute_s
(
h_grpcode
,
"Compiler Version"
,
compiler_version
());
io_write_attribute_s
(
h_grpcode
,
"Git Branch"
,
git_branch
());
io_write_attribute_s
(
h_grpcode
,
"Git Revision"
,
git_revision
());
io_write_attribute_s
(
h_grpcode
,
"Git Date"
,
git_date
());
io_write_attribute_s
(
h_grpcode
,
"Configuration options"
,
configuration_options
());
io_write_attribute_s
(
h_grpcode
,
"CFLAGS"
,
compilation_cflags
());
io_write_attribute_s
(
h_grpcode
,
"HDF5 library version"
,
hdf5_version
());
#ifdef HAVE_FFTW
write
A
ttribute_s
(
h_grpcode
,
"FFTW library version"
,
fftw3_version
());
io_
write
_a
ttribute_s
(
h_grpcode
,
"FFTW library version"
,
fftw3_version
());
#endif
#ifdef WITH_MPI
write
A
ttribute_s
(
h_grpcode
,
"MPI library"
,
mpi_version
());
io_
write
_a
ttribute_s
(
h_grpcode
,
"MPI library"
,
mpi_version
());
#ifdef HAVE_METIS
write
A
ttribute_s
(
h_grpcode
,
"METIS library version"
,
metis_version
());
io_
write
_a
ttribute_s
(
h_grpcode
,
"METIS library version"
,
metis_version
());
#endif
#else
write
A
ttribute_s
(
h_grpcode
,
"MPI library"
,
"Non-MPI version of SWIFT"
);
io_
write
_a
ttribute_s
(
h_grpcode
,
"MPI library"
,
"Non-MPI version of SWIFT"
);
#endif
H5Gclose
(
h_grpcode
);
}
...
...
@@ -406,170 +407,6 @@ void writeCodeDescription(hid_t h_file) {
*
* @todo Use a proper XML library to avoid stupid copies.
*/
FILE
*
prepareXMFfile
(
const
char
*
baseName
)
{
char
buffer
[
1024
];
char
fileName
[
FILENAME_BUFFER_SIZE
];
char
tempFileName
[
FILENAME_BUFFER_SIZE
];
snprintf
(
fileName
,
FILENAME_BUFFER_SIZE
,
"%s.xmf"
,
baseName
);
snprintf
(
tempFileName
,
FILENAME_BUFFER_SIZE
,
"%s_temp.xmf"
,
baseName
);
FILE
*
xmfFile
=
fopen
(
fileName
,
"r"
);
FILE
*
tempFile
=
fopen
(
tempFileName
,
"w"
);
if
(
xmfFile
==
NULL
)
error
(
"Unable to open current XMF file."
);
if
(
tempFile
==
NULL
)
error
(
"Unable to open temporary file."
);
/* First we make a temporary copy of the XMF file and count the lines */
int
counter
=
0
;
while
(
fgets
(
buffer
,
1024
,
xmfFile
)
!=
NULL
)
{
counter
++
;
fprintf
(
tempFile
,
"%s"
,
buffer
);
}
fclose
(
tempFile
);
fclose
(
xmfFile
);
/* We then copy the XMF file back up to the closing lines */
xmfFile
=
fopen
(
fileName
,
"w"
);
tempFile
=
fopen
(
tempFileName
,
"r"
);
if
(
xmfFile
==
NULL
)
error
(
"Unable to open current XMF file."
);
if
(
tempFile
==
NULL
)
error
(
"Unable to open temporary file."
);
int
i
=
0
;
while
(
fgets
(
buffer
,
1024
,
tempFile
)
!=
NULL
&&
i
<
counter
-
3
)
{
i
++
;
fprintf
(
xmfFile
,
"%s"
,
buffer
);
}
fprintf
(
xmfFile
,
"
\n
"
);
fclose
(
tempFile
);
remove
(
tempFileName
);
return
xmfFile
;
}
/**
* @brief Writes the begin of the XMF file
*
* @todo Exploit the XML nature of the XMF format to write a proper XML writer
*and simplify all the XMF-related stuff.
*/
void
createXMFfile
(
const
char
*
baseName
)
{
char
fileName
[
FILENAME_BUFFER_SIZE
];
snprintf
(
fileName
,
FILENAME_BUFFER_SIZE
,
"%s.xmf"
,
baseName
);
FILE
*
xmfFile
=
fopen
(
fileName
,
"w"
);
fprintf
(
xmfFile
,
"<?xml version=
\"
1.0
\"
?>
\n
"
);
fprintf
(
xmfFile
,
"<!DOCTYPE Xdmf SYSTEM
\"
Xdmf.dtd
\"
[]>
\n
"
);
fprintf
(
xmfFile
,
"<Xdmf xmlns:xi=
\"
http://www.w3.org/2003/XInclude
\"
Version=
\"
2.1
\"
>
\n
"
);
fprintf
(
xmfFile
,
"<Domain>
\n
"
);
fprintf
(
xmfFile
,
"<Grid Name=
\"
TimeSeries
\"
GridType=
\"
Collection
\"
"
"CollectionType=
\"
Temporal
\"
>
\n\n
"
);
fprintf
(
xmfFile
,
"</Grid>
\n
"
);
fprintf
(
xmfFile
,
"</Domain>
\n
"
);
fprintf
(
xmfFile
,
"</Xdmf>
\n
"
);
fclose
(
xmfFile
);
}
/**
* @brief Writes the part of the XMF entry presenting the geometry of the
*snapshot
*
* @param xmfFile The file to write in.
* @param hdfFileName The name of the HDF5 file corresponding to this output.
* @param time The current simulation time.
*/
void
writeXMFoutputheader
(
FILE
*
xmfFile
,
char
*
hdfFileName
,
float
time
)
{
/* Write end of file */
fprintf
(
xmfFile
,
"<!-- XMF description for file: %s -->
\n
"
,
hdfFileName
);
fprintf
(
xmfFile
,
"<Grid GridType=
\"
Collection
\"
CollectionType=
\"
Spatial
\"
>
\n
"
);
fprintf
(
xmfFile
,
"<Time Type=
\"
Single
\"
Value=
\"
%f
\"
/>
\n
"
,
time
);
}
/**
* @brief Writes the end of the XMF file (closes all open markups)
*
* @param xmfFile The file to write in.
* @param output The number of this output.
* @param time The current simulation time.
*/
void
writeXMFoutputfooter
(
FILE
*
xmfFile
,
int
output
,
float
time
)
{
/* Write end of the section of this time step */
fprintf
(
xmfFile
,
"
\n
</Grid> <!-- End of meta-data for output=%03i, time=%f -->
\n
"
,
output
,
time
);
fprintf
(
xmfFile
,
"
\n
</Grid> <!-- timeSeries -->
\n
"
);
fprintf
(
xmfFile
,
"</Domain>
\n
"
);
fprintf
(
xmfFile
,
"</Xdmf>
\n
"
);
fclose
(
xmfFile
);
}
void
writeXMFgroupheader
(
FILE
*
xmfFile
,
char
*
hdfFileName
,
size_t
N
,
enum
PARTICLE_TYPE
ptype
)
{
fprintf
(
xmfFile
,
"
\n
<Grid Name=
\"
%s
\"
GridType=
\"
Uniform
\"
>
\n
"
,
particle_type_names
[
ptype
]);
fprintf
(
xmfFile
,
"<Topology TopologyType=
\"
Polyvertex
\"
Dimensions=
\"
%zu
\"
/>
\n
"
,
N
);
fprintf
(
xmfFile
,
"<Geometry GeometryType=
\"
XYZ
\"
>
\n
"
);
fprintf
(
xmfFile
,
"<DataItem Dimensions=
\"
%zu 3
\"
NumberType=
\"
Double
\"
"
"Precision=
\"
8
\"
"
"Format=
\"
HDF
\"
>%s:/PartType%d/Coordinates</DataItem>
\n
"
,
N
,
hdfFileName
,
(
int
)
ptype
);
fprintf
(
xmfFile
,
"</Geometry>
\n
<!-- Done geometry for %s, start of particle fields "
"list -->
\n
"
,
particle_type_names
[
ptype
]);
}
void
writeXMFgroupfooter
(
FILE
*
xmfFile
,
enum
PARTICLE_TYPE
ptype
)
{
fprintf
(
xmfFile
,
"</Grid> <!-- End of meta-data for parttype=%s -->
\n
"
,
particle_type_names
[
ptype
]);
}
/**
* @brief Writes the lines corresponding to an array of the HDF5 output
*
* @param xmfFile The file in which to write
* @param fileName The name of the HDF5 file associated to this XMF descriptor.
* @param partTypeGroupName The name of the group containing the particles in
*the HDF5 file.
* @param name The name of the array in the HDF5 file.
* @param N The number of particles.
* @param dim The dimension of the quantity (1 for scalars, 3 for vectors).
* @param type The type of the data to write.
*
* @todo Treat the types in a better way.
*/
void
writeXMFline
(
FILE
*
xmfFile
,
const
char
*
fileName
,
const
char
*
partTypeGroupName
,
const
char
*
name
,
size_t
N
,
int
dim
,
enum
DATA_TYPE
type
)
{
fprintf
(
xmfFile
,
"<Attribute Name=
\"
%s
\"
AttributeType=
\"
%s
\"
Center=
\"
Node
\"
>
\n
"
,
name
,
dim
==
1
?
"Scalar"
:
"Vector"
);
if
(
dim
==
1
)
fprintf
(
xmfFile
,
"<DataItem Dimensions=
\"
%zu
\"
NumberType=
\"
Double
\"
"
"Precision=
\"
%d
\"
Format=
\"
HDF
\"
>%s:%s/%s</DataItem>
\n
"
,
N
,
type
==
FLOAT
?
4
:
8
,
fileName
,
partTypeGroupName
,
name
);
else
fprintf
(
xmfFile
,
"<DataItem Dimensions=
\"
%zu %d
\"
NumberType=
\"
Double
\"
"
"Precision=
\"
%d
\"
Format=
\"
HDF
\"
>%s:%s/%s</DataItem>
\n
"
,
N
,
dim
,
type
==
FLOAT
?
4
:
8
,
fileName
,
partTypeGroupName
,
name
);
fprintf
(
xmfFile
,
"</Attribute>
\n
"
);
}
/**
* @brief Prepare the DM particles (in gparts) read in for the addition of the
...
...
@@ -581,7 +418,7 @@ void writeXMFline(FILE* xmfFile, const char* fileName,
* @param gparts The array of #gpart freshly read in.
* @param Ndm The number of DM particles read in.
*/
void
prepare_dm_gparts
(
struct
gpart
*
const
gparts
,
size_t
Ndm
)
{
void
io_
prepare_dm_gparts
(
struct
gpart
*
const
gparts
,
size_t
Ndm
)
{
/* Let's give all these gparts a negative id */
for
(
size_t
i
=
0
;
i
<
Ndm
;
++
i
)
{
...
...
@@ -607,9 +444,9 @@ void prepare_dm_gparts(struct gpart* const gparts, size_t Ndm) {
* @param Ngas The number of gas particles read in.
* @param Ndm The number of DM particles read in.
*/
void
duplicate_hydro_gparts
(
struct
part
*
const
parts
,
struct
gpart
*
const
gparts
,
size_t
Ngas
,
size_t
Ndm
)
{
void
io_
duplicate_hydro_gparts
(
struct
part
*
const
parts
,
struct
gpart
*
const
gparts
,
size_t
Ngas
,
size_t
Ndm
)
{
for
(
size_t
i
=
0
;
i
<
Ngas
;
++
i
)
{
...
...
@@ -645,9 +482,9 @@ void duplicate_hydro_gparts(struct part* const parts,
* @param Nstars The number of stars particles read in.
* @param Ndm The number of DM and gas particles read in.
*/
void
duplicate_star_gparts
(
struct
spart
*
const
sparts
,
struct
gpart
*
const
gparts
,
size_t
Nstars
,
size_t
Ndm
)
{
void
io_
duplicate_star_gparts
(
struct
spart
*
const
sparts
,
struct
gpart
*
const
gparts
,
size_t
Nstars
,
size_t
Ndm
)
{
for
(
size_t
i
=
0
;
i
<
Nstars
;
++
i
)
{
...
...
@@ -679,8 +516,8 @@ void duplicate_star_gparts(struct spart* const sparts,
* @param dmparts The array of #gpart containg DM particles to be filled.
* @param Ndm The number of DM particles.
*/
void
collect_dm_gparts
(
const
struct
gpart
*
const
gparts
,
size_t
Ntot
,
struct
gpart
*
const
dmparts
,
size_t
Ndm
)
{
void
io_
collect_dm_gparts
(
const
struct
gpart
*
const
gparts
,
size_t
Ntot
,
struct
gpart
*
const
dmparts
,
size_t
Ndm
)
{
size_t
count
=
0
;
...
...
src/common_io.h
View file @
7bd06f71
...
...
@@ -23,17 +23,22 @@
/* Config parameters. */
#include
"../config.h"
#if defined(HAVE_HDF5)
/* Local includes. */
#include
"part.h"
#include
"units.h"
#define FIELD_BUFFER_SIZE 200
#define PARTICLE_GROUP_BUFFER_SIZE 50
#define FILENAME_BUFFER_SIZE 150
#if defined(HAVE_HDF5)
/**
* @brief The different types of data used in the GADGET IC files.
*
* (This is admittedly a poor substitute to C++ templates...)
*/
enum
DATA_TYPE
{
enum
IO_
DATA_TYPE
{
INT
,
LONG
,
LONGLONG
,
...
...
@@ -45,68 +50,38 @@ enum DATA_TYPE {
CHAR
};
/**
* @brief The different particle types present in a GADGET IC file
*
*/
enum
PARTICLE_TYPE
{
GAS
=
0
,
DM
=
1
,
BOUNDARY
=
2
,
DUMMY
=
3
,
STAR
=
4
,
BH
=
5
,
NUM_PARTICLE_TYPES
};
extern
const
char
*
particle_type_names
[];
#define FILENAME_BUFFER_SIZE 150
#define FIELD_BUFFER_SIZE 200
#define PARTICLE_GROUP_BUFFER_SIZE 50
hid_t
hdf5Type
(
enum
DATA_TYPE
type
);
size_t
sizeOfType
(
enum
DATA_TYPE
type
);
int
isDoublePrecision
(
enum
DATA_TYPE
type
);
void
collect_dm_gparts
(
const
struct
gpart
*
const
gparts
,
size_t
Ntot
,
struct
gpart
*
const
dmparts
,
size_t
Ndm
);
void
prepare_dm_gparts
(
struct
gpart
*
const
gparts
,
size_t
Ndm
);
void
duplicate_hydro_gparts
(
struct
part
*
const
parts
,
struct
gpart
*
const
gparts
,
size_t
Ngas
,
size_t
Ndm
);
void
duplicate_star_gparts
(
struct
spart
*
const
sparts
,
struct
gpart
*
const
gparts
,
size_t
Nstars
,
size_t
Ndm
);
hid_t
io_hdf5_type
(
enum
IO_DATA_TYPE
type
);
size_t
io_sizeof_type
(
enum
IO_DATA_TYPE
type
);
int
io_is_double_precision
(
enum
IO_DATA_TYPE
type
);
void
readAttribute
(
hid_t
grp
,
char
*
name
,
enum
DATA_TYPE
type
,
void
*
data
);
void
io_read_attribute
(
hid_t
grp
,
char
*
name
,
enum
IO_DATA_TYPE
type
,
void
*
data
);
void
write
A
ttribute
(
hid_t
grp
,
const
char
*
name
,
enum
DATA_TYPE
type
,
void
*
data
,
int
num
);
void
io_
write
_a
ttribute
(
hid_t
grp
,
const
char
*
name
,
enum
IO_
DATA_TYPE
type
,
void
*
data
,
int
num
);
void
write
A
ttribute_d
(
hid_t
grp
,
const
char
*
name
,
double
data
);
void
write
A
ttribute_f
(
hid_t
grp
,
const
char
*
name
,
float
data
);
void
write
A
ttribute_i
(
hid_t
grp
,
const
char
*
name
,
int
data
);
void
write
A
ttribute_l
(
hid_t
grp
,
const
char
*
name
,
long
data
);
void
write
A
ttribute_s
(
hid_t
grp
,
const
char
*
name
,
const
char
*
str
);
void
io_
write
_a
ttribute_d
(
hid_t
grp
,
const
char
*
name
,
double
data
);
void
io_
write
_a
ttribute_f
(
hid_t
grp
,
const
char
*
name
,
float
data
);
void
io_
write
_a
ttribute_i
(
hid_t
grp
,
const
char
*
name
,
int
data
);
void
io_
write
_a
ttribute_l
(
hid_t
grp
,
const
char
*
name
,
long
data
);
void
io_
write
_a
ttribute_s
(
hid_t
grp
,
const
char
*
name
,
const
char
*
str
);
void
createXMFfile
(
const
char
*
baseName
);
FILE
*
prepareXMFfile
(
const
char
*
baseName
);
void
writeXMFoutputheader
(
FILE
*
xmfFile
,
char
*
hdfFileName
,
float
time
);
void
writeXMFoutputfooter
(
FILE
*
xmfFile
,
int
outputCount
,
float
time
);
void
writeXMFgroupheader
(
FILE
*
xmfFile
,
char
*
hdfFileName
,
size_t
N
,
enum
PARTICLE_TYPE
ptype
);
void
writeXMFgroupfooter
(
FILE
*
xmfFile
,
enum
PARTICLE_TYPE
ptype
);
void
writeXMFline
(
FILE
*
xmfFile
,
const
char
*
fileName
,
const
char
*
partTypeGroupName
,
const
char
*
name
,
size_t
N
,
int
dim
,
enum
DATA_TYPE
type
);
void
io_write_code_description
(
hid_t
h_file
);
void
writeCodeDescription
(
hid_t
h_file
);
void
readUnitSystem
(
hid_t
h_file
,
struct
UnitSystem
*
us
);
void
writeUnitSystem
(
hid_t
h_grp
,
const
struct
UnitSystem
*
us
,
const
char
*
groupName
);
void
io_read_UnitSystem
(
hid_t
h_file
,
struct
UnitSystem
*
us
);
void
io_write_UnitSystem
(
hid_t
h_grp
,
const
struct
UnitSystem
*
us
,
const
char
*
groupName
);
#endif
/* defined HDF5 */
void
io_collect_dm_gparts
(
const
struct
gpart
*
const
gparts
,
size_t
Ntot
,
struct
gpart
*
const
dmparts
,
size_t
Ndm
);
void
io_prepare_dm_gparts
(
struct
gpart
*
const
gparts
,
size_t
Ndm
);
void
io_duplicate_hydro_gparts
(
struct
part
*
const
parts
,
struct
gpart
*
const
gparts
,
size_t
Ngas
,
size_t
Ndm
);
void
io_duplicate_star_gparts
(
struct
spart
*
const
sparts
,
struct
gpart
*
const
gparts
,
size_t
Nstars
,
size_t
Ndm
);
#endif
/* SWIFT_COMMON_IO_H */
src/hydro/Default/hydro_io.h
View file @
7bd06f71
...
...
@@ -91,21 +91,25 @@ void hydro_write_particles(struct part* parts, struct io_props* list,
void
writeSPHflavour
(
hid_t
h_grpsph
)
{
/* Viscosity and thermal conduction */
writeAttribute_s
(
h_grpsph
,
"Thermal Conductivity Model"
,