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
e78c4d7a
Commit
e78c4d7a
authored
Apr 24, 2016
by
Matthieu Schaller
Browse files
Read snapshot basename and interval between snapshots from yaml file.
parent
66361636
Changes
13
Hide whitespace changes
Inline
Side-by-side
examples/UniformBox/uniformBox.yml
View file @
e78c4d7a
...
...
@@ -21,6 +21,12 @@ TimeIntegration:
dt_min
:
1e-6
# The minimal time-step size of the simulation (in internal units).
dt_max
:
1e-2
# The maximal time-step size of the simulation (in internal units).
# Parameters governing the snapshots
Snapshots
:
basename
:
uniformBox
# Common part of the name of output files
time_first
:
0.
# Time of the frist output (in internal units)
delta_time
:
0.01
# Time difference between consecutive outputs (in internal units)
# Parameters for the hydrodynamics scheme
SPH
:
resolution_eta
:
1.2349
# Target smoothing length in units of the mean inter-particle separation (1.2349 == 48Ngbs with the cubic spline kernel).
...
...
examples/main.c
View file @
e78c4d7a
...
...
@@ -422,24 +422,22 @@ int main(int argc, char *argv[]) {
fflush
(
stdout
);
}
/* Now that everything is ready, no need for the parameters any more */
free
(
params
);
params
=
NULL
;
int
with_outputs
=
1
;
char
baseName
[
200
];
parser_get_param_string
(
params
,
"Snapshots:basename"
,
baseName
);
if
(
with_outputs
&&
!
dry_run
)
{
/* Write the state of the system before starting time integration. */
if
(
myrank
==
0
)
clocks_gettime
(
&
tic
);
#if defined(WITH_MPI)
#if defined(HAVE_PARALLEL_HDF5)
write_output_parallel
(
&
e
,
&
us
,
myrank
,
nr_nodes
,
MPI_COMM_WORLD
,
write_output_parallel
(
&
e
,
baseName
,
&
us
,
myrank
,
nr_nodes
,
MPI_COMM_WORLD
,
MPI_INFO_NULL
);
#else
write_output_serial
(
&
e
,
&
us
,
myrank
,
nr_nodes
,
MPI_COMM_WORLD
,
write_output_serial
(
&
e
,
baseName
,
&
us
,
myrank
,
nr_nodes
,
MPI_COMM_WORLD
,
MPI_INFO_NULL
);
#endif
#else
write_output_single
(
&
e
,
&
us
);
write_output_single
(
&
e
,
baseName
,
&
us
);
#endif
if
(
myrank
==
0
&&
verbose
)
{
clocks_gettime
(
&
toc
);
...
...
@@ -449,6 +447,10 @@ int main(int argc, char *argv[]) {
}
}
/* Now that everything is ready, no need for the parameters any more */
free
(
params
);
params
=
NULL
;
/* Init the runner history. */
#ifdef HIST
for
(
k
=
0
;
k
<
runner_hist_N
;
k
++
)
runner_hist_bins
[
k
]
=
0
;
...
...
@@ -505,7 +507,7 @@ int main(int argc, char *argv[]) {
/* Take a step. */
engine_step
(
&
e
);
if
(
with_outputs
&&
j
%
10
0
==
0
)
{
if
(
with_outputs
&&
j
%
10
==
0
)
{
if
(
myrank
==
0
)
clocks_gettime
(
&
tic
);
#if defined(WITH_MPI)
...
...
@@ -517,7 +519,7 @@ int main(int argc, char *argv[]) {
MPI_INFO_NULL
);
#endif
#else
write_output_single
(
&
e
,
&
us
);
write_output_single
(
&
e
,
baseName
,
&
us
);
#endif
if
(
myrank
==
0
&&
verbose
)
{
clocks_gettime
(
&
toc
);
...
...
@@ -621,7 +623,7 @@ int main(int argc, char *argv[]) {
MPI_INFO_NULL
);
#endif
#else
write_output_single
(
&
e
,
&
us
);
write_output_single
(
&
e
,
baseName
,
&
us
);
#endif
if
(
myrank
==
0
&&
verbose
)
{
clocks_gettime
(
&
toc
);
...
...
examples/parameter_example.yml
View file @
e78c4d7a
...
...
@@ -21,6 +21,12 @@ TimeIntegration:
dt_min
:
1e-6
# The minimal time-step size of the simulation (in internal units).
dt_max
:
1e-2
# The maximal time-step size of the simulation (in internal units).
# Parameters governing the snapshots
Snapshots
:
basename
:
uniformBox
# Common part of the name of output files
time_first
:
0.
# Time of the frist output (in internal units)
delta_time
:
0.01
# Time difference between consecutive outputs (in internal units)
# Parameters for the hydrodynamics scheme
SPH
:
resolution_eta
:
1.2349
# Target smoothing length in units of the mean inter-particle separation (1.2349 == 48Ngbs with the cubic spline kernel).
...
...
src/common_io.c
View file @
e78c4d7a
...
...
@@ -335,11 +335,15 @@ void writeCodeDescription(hid_t h_file) {
*
* @todo Use a proper XML library to avoid stupid copies.
*/
FILE
*
prepareXMFfile
()
{
FILE
*
prepareXMFfile
(
const
char
*
baseName
)
{
char
buffer
[
1024
];
FILE
*
xmfFile
=
fopen
(
"output.xmf"
,
"r"
);
FILE
*
tempFile
=
fopen
(
"output_temp.xmf"
,
"w"
);
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."
);
...
...
@@ -355,8 +359,8 @@ FILE* prepareXMFfile() {
fclose
(
xmfFile
);
/* We then copy the XMF file back up to the closing lines */
xmfFile
=
fopen
(
"output.xmf"
,
"w"
);
tempFile
=
fopen
(
"output_temp.xmf"
,
"r"
);
xmfFile
=
fopen
(
fileName
,
"w"
);
tempFile
=
fopen
(
tempFileName
,
"r"
);
if
(
xmfFile
==
NULL
)
error
(
"Unable to open current XMF file."
);
...
...
@@ -369,7 +373,7 @@ FILE* prepareXMFfile() {
}
fprintf
(
xmfFile
,
"
\n
"
);
fclose
(
tempFile
);
remove
(
"output_temp.xmf"
);
remove
(
tempFileName
);
return
xmfFile
;
}
...
...
@@ -380,8 +384,11 @@ FILE* prepareXMFfile() {
* @todo Exploit the XML nature of the XMF format to write a proper XML writer
*and simplify all the XMF-related stuff.
*/
void
createXMFfile
()
{
FILE
*
xmfFile
=
fopen
(
"output.xmf"
,
"w"
);
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
"
);
...
...
src/common_io.h
View file @
e78c4d7a
...
...
@@ -97,8 +97,8 @@ void writeAttribute_i(hid_t grp, char* name, int data);
void
writeAttribute_l
(
hid_t
grp
,
char
*
name
,
long
data
);
void
writeAttribute_s
(
hid_t
grp
,
char
*
name
,
const
char
*
str
);
void
createXMFfile
();
FILE
*
prepareXMFfile
();
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
,
...
...
src/engine.c
View file @
e78c4d7a
...
...
@@ -2381,6 +2381,11 @@ void engine_init(struct engine *e, struct space *s,
e
->
ti_old
=
0
;
e
->
ti_current
=
0
;
e
->
timeStep
=
0
.;
e
->
timeBase
=
0
.;
e
->
timeFirstSnapshot
=
parser_get_param_double
(
params
,
"Snapshots:time_first"
);
e
->
deltaTimeSnapshot
=
parser_get_param_double
(
params
,
"Snapshots:delta_time"
);
e
->
dt_min
=
parser_get_param_double
(
params
,
"TimeIntegration:dt_min"
);
e
->
dt_max
=
parser_get_param_double
(
params
,
"TimeIntegration:dt_max"
);
e
->
file_stats
=
NULL
;
...
...
@@ -2557,6 +2562,16 @@ void engine_init(struct engine *e, struct space *s,
error
(
"Maximal time-step size larger than the simulation run time t=%e"
,
e
->
timeEnd
-
e
->
timeBegin
);
/* Deal with outputs */
if
(
e
->
deltaTimeSnapshot
<
0
.)
error
(
"Time between snapshots (%e) must be positive."
,
e
->
deltaTimeSnapshot
);
if
(
e
->
timeFirstSnapshot
<
e
->
timeBegin
)
error
(
"Time of first snapshot (%e) must be after the simulation start t=%e."
,
e
->
timeFirstSnapshot
,
e
->
timeBegin
);
/* Construct types for MPI communications */
#ifdef WITH_MPI
part_create_mpi_types
();
...
...
src/engine.h
View file @
e78c4d7a
...
...
@@ -131,6 +131,10 @@ struct engine {
/* Time base */
double
timeBase
;
/* Snapshot times */
double
timeFirstSnapshot
;
double
deltaTimeSnapshot
;
/* File for statistics */
FILE
*
file_stats
;
...
...
src/parallel_io.c
View file @
e78c4d7a
...
...
@@ -509,8 +509,12 @@ void read_ic_parallel(char* fileName, double dim[3], struct part** parts,
*its XMF descriptor
*
* @param e The engine containing all the system.
* @param us The UnitSystem used for the conversion of units
*in the output
* @param baseName The common part of the snapshot file name.
* @param us The UnitSystem used for the conversion of units in the output.
* @param mpi_rank The MPI rank of this node.
* @param mpi_size The number of MPI ranks.
* @param comm The MPI communicator.
* @param info The MPI information object
*
* Creates an HDF5 output file and writes the particles
*contained
...
...
@@ -522,9 +526,9 @@ void read_ic_parallel(char* fileName, double dim[3], struct part** parts,
* Calls #error() if an error occurs.
*
*/
void
write_output_parallel
(
struct
engine
*
e
,
struct
UnitSystem
*
us
,
int
mpi_rank
,
int
mpi_size
,
MPI_Comm
comm
,
MPI_Info
info
)
{
void
write_output_parallel
(
struct
engine
*
e
,
const
char
*
baseName
,
struct
UnitSystem
*
us
,
int
mpi_rank
,
int
mpi_size
,
MPI_Comm
comm
,
MPI_Info
info
)
{
hid_t
h_file
=
0
,
h_grp
=
0
,
h_grpsph
=
0
;
const
size_t
Ngas
=
e
->
s
->
nr_parts
;
const
size_t
Ntot
=
e
->
s
->
nr_gparts
;
...
...
@@ -536,22 +540,19 @@ void write_output_parallel(struct engine* e, struct UnitSystem* us,
static
int
outputCount
=
0
;
FILE
*
xmfFile
=
0
;
/* Number of particles of each type */
// const size_t Ndm = Ntot - Ngas;
/* MATTHIEU: Temporary fix to preserve master */
/* Number of unassociated gparts */
const
size_t
Ndm
=
Ntot
>
0
?
Ntot
-
Ngas
:
0
;
/* MATTHIEU: End temporary fix */
/* File name */
char
fileName
[
FILENAME_BUFFER_SIZE
];
snprintf
(
fileName
,
FILENAME_BUFFER_SIZE
,
"output_%03i.hdf5"
,
outputCount
);
snprintf
(
fileName
,
FILENAME_BUFFER_SIZE
,
"%s_%03i.hdf5"
,
baseName
,
outputCount
);
/* First time, we need to create the XMF file */
if
(
outputCount
==
0
&&
mpi_rank
==
0
)
createXMFfile
();
if
(
outputCount
==
0
&&
mpi_rank
==
0
)
createXMFfile
(
baseName
);
/* Prepare the XMF file for the new entry */
if
(
mpi_rank
==
0
)
xmfFile
=
prepareXMFfile
();
if
(
mpi_rank
==
0
)
xmfFile
=
prepareXMFfile
(
baseName
);
/* Open HDF5 file */
hid_t
plist_id
=
H5Pcreate
(
H5P_FILE_ACCESS
);
...
...
src/parallel_io.h
View file @
e78c4d7a
...
...
@@ -36,9 +36,9 @@ void read_ic_parallel(char* fileName, double dim[3], struct part** parts,
int
*
periodic
,
int
mpi_rank
,
int
mpi_size
,
MPI_Comm
comm
,
MPI_Info
info
,
int
dry_run
);
void
write_output_parallel
(
struct
engine
*
e
,
struct
UnitSystem
*
us
,
int
mpi_rank
,
int
mpi_size
,
MPI_Comm
comm
,
MPI_Info
info
);
void
write_output_parallel
(
struct
engine
*
e
,
const
char
*
baseName
,
struct
UnitSystem
*
us
,
int
mpi_rank
,
int
mpi_size
,
MPI_Comm
comm
,
MPI_Info
info
);
#endif
...
...
src/serial_io.c
View file @
e78c4d7a
...
...
@@ -590,6 +590,7 @@ void read_ic_serial(char* fileName, double dim[3], struct part** parts,
* @brief Writes an HDF5 output file (GADGET-3 type) with its XMF descriptor
*
* @param e The engine containing all the system.
* @param baseName The common part of the snapshot file name.
* @param us The UnitSystem used for the conversion of units in the output.
* @param mpi_rank The MPI rank of this node.
* @param mpi_size The number of MPI ranks.
...
...
@@ -604,8 +605,9 @@ void read_ic_serial(char* fileName, double dim[3], struct part** parts,
* Calls #error() if an error occurs.
*
*/
void
write_output_serial
(
struct
engine
*
e
,
struct
UnitSystem
*
us
,
int
mpi_rank
,
int
mpi_size
,
MPI_Comm
comm
,
MPI_Info
info
)
{
void
write_output_serial
(
struct
engine
*
e
,
const
char
*
baseName
,
struct
UnitSystem
*
us
,
int
mpi_rank
,
int
mpi_size
,
MPI_Comm
comm
,
MPI_Info
info
)
{
hid_t
h_file
=
0
,
h_grp
=
0
,
h_grpsph
=
0
;
const
size_t
Ngas
=
e
->
s
->
nr_parts
;
const
size_t
Ntot
=
e
->
s
->
nr_gparts
;
...
...
@@ -617,16 +619,13 @@ void write_output_serial(struct engine* e, struct UnitSystem* us, int mpi_rank,
static
int
outputCount
=
0
;
FILE
*
xmfFile
=
0
;
/* Number of particles of each type */
// const size_t Ndm = Ntot - Ngas;
/* MATTHIEU: Temporary fix to preserve master */
/* Number of unassociated gparts */
const
size_t
Ndm
=
Ntot
>
0
?
Ntot
-
Ngas
:
0
;
/* MATTHIEU: End temporary fix */
/* File name */
char
fileName
[
FILENAME_BUFFER_SIZE
];
snprintf
(
fileName
,
FILENAME_BUFFER_SIZE
,
"output_%03i.hdf5"
,
outputCount
);
snprintf
(
fileName
,
FILENAME_BUFFER_SIZE
,
"%s_%03i.hdf5"
,
baseName
,
outputCount
);
/* Compute offset in the file and total number of particles */
size_t
N
[
NUM_PARTICLE_TYPES
]
=
{
Ngas
,
Ndm
,
0
};
...
...
@@ -646,10 +645,10 @@ void write_output_serial(struct engine* e, struct UnitSystem* us, int mpi_rank,
if
(
mpi_rank
==
0
)
{
/* First time, we need to create the XMF file */
if
(
outputCount
==
0
)
createXMFfile
();
if
(
outputCount
==
0
)
createXMFfile
(
baseName
);
/* Prepare the XMF file for the new entry */
xmfFile
=
prepareXMFfile
();
xmfFile
=
prepareXMFfile
(
baseName
);
/* Write the part corresponding to this specific output */
writeXMFoutputheader
(
xmfFile
,
fileName
,
e
->
time
);
...
...
src/serial_io.h
View file @
e78c4d7a
...
...
@@ -36,8 +36,9 @@ void read_ic_serial(char* fileName, double dim[3], struct part** parts,
int
*
periodic
,
int
mpi_rank
,
int
mpi_size
,
MPI_Comm
comm
,
MPI_Info
info
,
int
dry_run
);
void
write_output_serial
(
struct
engine
*
e
,
struct
UnitSystem
*
us
,
int
mpi_rank
,
int
mpi_size
,
MPI_Comm
comm
,
MPI_Info
info
);
void
write_output_serial
(
struct
engine
*
e
,
const
char
*
baseName
,
struct
UnitSystem
*
us
,
int
mpi_rank
,
int
mpi_size
,
MPI_Comm
comm
,
MPI_Info
info
);
#endif
...
...
src/single_io.c
View file @
e78c4d7a
...
...
@@ -456,7 +456,8 @@ void read_ic_single(char* fileName, double dim[3], struct part** parts,
* @brief Writes an HDF5 output file (GADGET-3 type) with its XMF descriptor
*
* @param e The engine containing all the system.
* @param us The UnitSystem used for the conversion of units in the output
* @param baseName The common part of the snapshot file name.
* @param us The UnitSystem used for the conversion of units in the output.
*
* Creates an HDF5 output file and writes the particles contained
* in the engine. If such a file already exists, it is erased and replaced
...
...
@@ -466,7 +467,8 @@ void read_ic_single(char* fileName, double dim[3], struct part** parts,
* Calls #error() if an error occurs.
*
*/
void
write_output_single
(
struct
engine
*
e
,
struct
UnitSystem
*
us
)
{
void
write_output_single
(
struct
engine
*
e
,
const
char
*
baseName
,
struct
UnitSystem
*
us
)
{
hid_t
h_file
=
0
,
h_grp
=
0
;
const
size_t
Ngas
=
e
->
s
->
nr_parts
;
...
...
@@ -478,25 +480,22 @@ void write_output_single(struct engine* e, struct UnitSystem* us) {
struct
gpart
*
dmparts
=
NULL
;
static
int
outputCount
=
0
;
/* Number of particles of each type */
// const size_t Ndm = Ntot - Ngas;
/* MATTHIEU: Temporary fix to preserve master */
/* Number of unassociated gparts */
const
size_t
Ndm
=
Ntot
>
0
?
Ntot
-
Ngas
:
0
;
/* MATTHIEU: End temporary fix */
long
long
N_total
[
NUM_PARTICLE_TYPES
]
=
{
Ngas
,
Ndm
,
0
};
/* File name */
char
fileName
[
FILENAME_BUFFER_SIZE
];
snprintf
(
fileName
,
FILENAME_BUFFER_SIZE
,
"output_%03i.hdf5"
,
outputCount
);
snprintf
(
fileName
,
FILENAME_BUFFER_SIZE
,
"%s_%03i.hdf5"
,
baseName
,
outputCount
);
/* First time, we need to create the XMF file */
if
(
outputCount
==
0
)
createXMFfile
();
if
(
outputCount
==
0
)
createXMFfile
(
baseName
);
/* Prepare the XMF file for the new entry */
FILE
*
xmfFile
=
0
;
xmfFile
=
prepareXMFfile
();
xmfFile
=
prepareXMFfile
(
baseName
);
/* Write the part corresponding to this specific output */
writeXMFoutputheader
(
xmfFile
,
fileName
,
e
->
time
);
...
...
src/single_io.h
View file @
e78c4d7a
...
...
@@ -30,7 +30,8 @@ void read_ic_single(char* fileName, double dim[3], struct part** parts,
struct
gpart
**
gparts
,
size_t
*
Ngas
,
size_t
*
Ndm
,
int
*
periodic
,
int
dry_run
);
void
write_output_single
(
struct
engine
*
e
,
struct
UnitSystem
*
us
);
void
write_output_single
(
struct
engine
*
e
,
const
char
*
baseName
,
struct
UnitSystem
*
us
);
#endif
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment