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
f8aac6f5
Commit
f8aac6f5
authored
Jun 05, 2016
by
Matthieu Schaller
Browse files
Add ability to the parser to treat optional parameters
parent
b90156c9
Changes
10
Hide whitespace changes
Inline
Side-by-side
examples/CosmoVolume/cosmoVolume.yml
View file @
f8aac6f5
...
...
@@ -6,13 +6,6 @@ InternalUnitSystem:
UnitCurrent_in_cgs
:
1
# Amperes
UnitTemp_in_cgs
:
1
# Kelvin
# Parameters for the task scheduling
Scheduler
:
nr_queues
:
0
# The number of task queues to use. Use 0 to let the system decide.
cell_max_size
:
8000000
# Maximal number of interactions per task (this is the default value).
cell_sub_size
:
5000
# Maximal number of interactions per sub-task (this is the default value).
cell_split_size
:
400
# Maximal number of particles per cell (this is the default value).
# Parameters governing the time integration
TimeIntegration
:
time_begin
:
0.
# The starting time of the simulation (in internal units).
...
...
@@ -47,10 +40,6 @@ SPH:
# Parameters related to the initial conditions
InitialConditions
:
file_name
:
./cosmoVolume.hdf5
# The file to read
h_scaling
:
1.
# A scaling factor to apply to all smoothing lengths in the ICs.
shift_x
:
0.
# A shift to apply to all particles read from the ICs (in internal units).
shift_y
:
0.
shift_z
:
0.
# Parameters govering domain decomposition
DomainDecomposition
:
...
...
examples/ExternalPointMass/externalPointMass.yml
View file @
f8aac6f5
...
...
@@ -6,13 +6,6 @@ InternalUnitSystem:
UnitCurrent_in_cgs
:
1
# Amperes
UnitTemp_in_cgs
:
1
# Kelvin
# Parameters for the task scheduling
Scheduler
:
nr_queues
:
0
# The number of task queues to use. Use 0 to let the system decide.
cell_max_size
:
8000000
# Maximal number of interactions per task (this is the default value).
cell_sub_size
:
8000000
# Maximal number of interactions per sub-task (this is the default value).
cell_split_size
:
400
# Maximal number of particles per cell (this is the default value).
# Parameters governing the time integration
TimeIntegration
:
time_begin
:
0.
# The starting time of the simulation (in internal units).
...
...
@@ -47,7 +40,6 @@ SPH:
# Parameters related to the initial conditions
InitialConditions
:
file_name
:
Sphere.hdf5
# The file to read
h_scaling
:
1.
# A scaling factor to apply to all smoothing lengths in the ICs.
shift_x
:
50.
# A shift to apply to all particles read from the ICs (in internal units).
shift_y
:
50.
shift_z
:
50.
...
...
examples/SedovBlast/sedov.yml
View file @
f8aac6f5
...
...
@@ -6,13 +6,6 @@ InternalUnitSystem:
UnitCurrent_in_cgs
:
1
# Amperes
UnitTemp_in_cgs
:
1
# Kelvin
# Parameters for the task scheduling
Scheduler
:
nr_queues
:
0
# The number of task queues to use. Use 0 to let the system decide.
cell_max_size
:
8000000
# Maximal number of interactions per task (this is the default value).
cell_sub_size
:
5000
# Maximal number of interactions per sub-task (this is the default value).
cell_split_size
:
400
# Maximal number of particles per cell (this is the default value).
# Parameters governing the time integration
TimeIntegration
:
time_begin
:
0.
# The starting time of the simulation (in internal units).
...
...
@@ -47,10 +40,6 @@ SPH:
# Parameters related to the initial conditions
InitialConditions
:
file_name
:
./sedov.hdf5
# The file to read
h_scaling
:
1.
# A scaling factor to apply to all smoothing lengths in the ICs.
shift_x
:
0.
# A shift to apply to all particles read from the ICs (in internal units).
shift_y
:
0.
shift_z
:
0.
# Parameters govering domain decomposition
DomainDecomposition
:
...
...
examples/SodShock/sodShock.yml
View file @
f8aac6f5
...
...
@@ -6,13 +6,6 @@ InternalUnitSystem:
UnitCurrent_in_cgs
:
1
# Amperes
UnitTemp_in_cgs
:
1
# Kelvin
# Parameters for the task scheduling
Scheduler
:
nr_queues
:
0
# The number of task queues to use. Use 0 to let the system decide.
cell_max_size
:
8000000
# Maximal number of interactions per task (this is the default value).
cell_sub_size
:
5000
# Maximal number of interactions per sub-task.
cell_split_size
:
400
# Maximal number of particles per cell (this is the default value).
# Parameters governing the time integration
TimeIntegration
:
time_begin
:
0.
# The starting time of the simulation (in internal units).
...
...
@@ -47,10 +40,6 @@ SPH:
# Parameters related to the initial conditions
InitialConditions
:
file_name
:
./sodShock.hdf5
# The file to read
h_scaling
:
1.
# A scaling factor to apply to all smoothing lengths in the ICs.
shift_x
:
0.
# A shift to apply to all particles read from the ICs (in internal units).
shift_y
:
0.
shift_z
:
0.
# Parameters govering domain decomposition
DomainDecomposition
:
...
...
examples/UniformBox/uniformBox.yml
View file @
f8aac6f5
...
...
@@ -6,13 +6,6 @@ InternalUnitSystem:
UnitCurrent_in_cgs
:
1
# Amperes
UnitTemp_in_cgs
:
1
# Kelvin
# Parameters for the task scheduling
Scheduler
:
nr_queues
:
0
# The number of task queues to use. Use 0 to let the system decide.
cell_max_size
:
8000000
# Maximal number of interactions per task (this is the default value).
cell_sub_size
:
5000
# Maximal number of interactions per sub-task (this is the default value).
cell_split_size
:
400
# Maximal number of particles per cell (this is the default value).
# Parameters governing the time integration
TimeIntegration
:
time_begin
:
0.
# The starting time of the simulation (in internal units).
...
...
@@ -47,10 +40,6 @@ SPH:
# Parameters related to the initial conditions
InitialConditions
:
file_name
:
./uniformBox.hdf5
# The file to read
h_scaling
:
1.
# A scaling factor to apply to all smoothing lengths in the ICs.
shift_x
:
0.
# A shift to apply to all particles read from the ICs (in internal units).
shift_y
:
0.
shift_z
:
0.
# Parameters govering domain decomposition
DomainDecomposition
:
...
...
examples/parameter_example.yml
View file @
f8aac6f5
...
...
@@ -8,10 +8,10 @@ InternalUnitSystem:
# Parameters for the task scheduling
Scheduler
:
nr_queues
:
0
# The number of task queues to use. Use 0 to let the system decide.
cell_max_size
:
8000000
# Maximal number of interactions per task (this is the default value).
cell_sub_size
:
8000000
# Maximal number of interactions per sub-task (this is the default value).
cell_split_size
:
400
# Maximal number of particles per cell (this is the default value).
nr_queues
:
0
#
(Optional)
The number of task queues to use. Use 0 to let the system decide.
cell_max_size
:
8000000
#
(Optional)
Maximal number of interactions per task (this is the default value).
cell_sub_size
:
8000000
#
(Optional)
Maximal number of interactions per sub-task (this is the default value).
cell_split_size
:
400
#
(Optional)
Maximal number of particles per cell (this is the default value).
# Parameters governing the time integration
TimeIntegration
:
...
...
@@ -42,13 +42,13 @@ SPH:
max_ghost_iterations
:
30
# Maximal number of iterations allowed to converge towards the smoothing length.
max_smoothing_length
:
0.1
# Maximal smoothing length allowed (in internal units).
CFL_condition
:
0.1
# Courant-Friedrich-Levy condition for time integration.
max_volume_change
:
2.
# Maximal allowed change of volume over one time-step
max_volume_change
:
2.
# Maximal allowed change of
kernel
volume over one time-step
# Parameters related to the initial conditions
InitialConditions
:
file_name
:
SedovBlast/sedov.hdf5
# The file to read
h_scaling
:
1.
# A scaling factor to apply to all smoothing lengths in the ICs.
shift_x
:
0.
# A shift to apply to all particles read from the ICs (in internal units).
h_scaling
:
1.
#
(Optional)
A scaling factor to apply to all smoothing lengths in the ICs.
shift_x
:
0.
#
(Optional)
A shift to apply to all particles read from the ICs (in internal units).
shift_y
:
0.
shift_z
:
0.
...
...
src/engine.c
View file @
f8aac6f5
...
...
@@ -2626,8 +2626,11 @@ void engine_init(struct engine *e, struct space *s,
s
->
e
=
e
;
/* Get the number of queues */
int
nr_queues
=
parser_get_param_int
(
params
,
"Scheduler:nr_queues"
);
int
nr_queues
=
parser_get_opt_param_int
(
params
,
"Scheduler:nr_queues"
,
nr_threads
);
if
(
nr_queues
<=
0
)
nr_queues
=
e
->
nr_threads
;
if
(
nr_queues
!=
nr_threads
)
message
(
"Number of task queues set to %d"
,
nr_queues
);
s
->
nr_queues
=
nr_queues
;
/* Deal with affinity. For now, just figure out the number of cores. */
...
...
src/parser.c
View file @
f8aac6f5
...
...
@@ -158,7 +158,6 @@ static int is_empty(const char *str) {
static
void
find_duplicate_params
(
const
struct
swift_params
*
params
,
const
char
*
param_name
)
{
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
/*strcmp returns 0 if both strings are the same.*/
if
(
!
strcmp
(
param_name
,
params
->
data
[
i
].
name
))
{
error
(
"Invalid line:%d '%s', parameter is a duplicate."
,
lineNumber
,
param_name
);
...
...
@@ -176,7 +175,6 @@ static void find_duplicate_params(const struct swift_params *params,
static
void
find_duplicate_section
(
const
struct
swift_params
*
params
,
const
char
*
section_name
)
{
for
(
int
i
=
0
;
i
<
params
->
sectionCount
;
i
++
)
{
/*strcmp returns 0 if both strings are the same.*/
if
(
!
strcmp
(
section_name
,
params
->
section
[
i
].
name
))
{
error
(
"Invalid line:%d '%s', section is a duplicate."
,
lineNumber
,
section_name
);
...
...
@@ -212,7 +210,6 @@ static void parse_line(char *line, struct swift_params *params) {
parse_value
(
trim_line
,
params
);
}
/* Check for invalid lines,not including the start and end of file. */
/* Note: strcmp returns 0 if both strings are the same.*/
else
if
(
strcmp
(
trim_line
,
PARSER_START_OF_FILE
)
&&
strcmp
(
trim_line
,
PARSER_END_OF_FILE
))
{
error
(
"Invalid line:%d '%s'."
,
lineNumber
,
trim_line
);
...
...
@@ -381,7 +378,6 @@ int parser_get_param_int(const struct swift_params *params, const char *name) {
int
retParam
=
0
;
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
/*strcmp returns 0 if both strings are the same.*/
if
(
!
strcmp
(
name
,
params
->
data
[
i
].
name
))
{
/* Check that exactly one number is parsed. */
if
(
sscanf
(
params
->
data
[
i
].
value
,
"%d%s"
,
&
retParam
,
str
)
!=
1
)
{
...
...
@@ -414,7 +410,6 @@ char parser_get_param_char(const struct swift_params *params,
char
retParam
=
0
;
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
/*strcmp returns 0 if both strings are the same.*/
if
(
!
strcmp
(
name
,
params
->
data
[
i
].
name
))
{
/* Check that exactly one number is parsed. */
if
(
sscanf
(
params
->
data
[
i
].
value
,
"%c%s"
,
&
retParam
,
str
)
!=
1
)
{
...
...
@@ -447,7 +442,6 @@ float parser_get_param_float(const struct swift_params *params,
float
retParam
=
0
.
f
;
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
/*strcmp returns 0 if both strings are the same.*/
if
(
!
strcmp
(
name
,
params
->
data
[
i
].
name
))
{
/* Check that exactly one number is parsed. */
if
(
sscanf
(
params
->
data
[
i
].
value
,
"%f%s"
,
&
retParam
,
str
)
!=
1
)
{
...
...
@@ -480,7 +474,6 @@ double parser_get_param_double(const struct swift_params *params,
double
retParam
=
0
.;
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
/*strcmp returns 0 if both strings are the same.*/
if
(
!
strcmp
(
name
,
params
->
data
[
i
].
name
))
{
/* Check that exactly one number is parsed. */
if
(
sscanf
(
params
->
data
[
i
].
value
,
"%lf%s"
,
&
retParam
,
str
)
!=
1
)
{
...
...
@@ -508,7 +501,6 @@ double parser_get_param_double(const struct swift_params *params,
void
parser_get_param_string
(
const
struct
swift_params
*
params
,
const
char
*
name
,
char
*
retParam
)
{
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
/*strcmp returns 0 if both strings are the same.*/
if
(
!
strcmp
(
name
,
params
->
data
[
i
].
name
))
{
strcpy
(
retParam
,
params
->
data
[
i
].
value
);
return
;
...
...
@@ -518,6 +510,150 @@ void parser_get_param_string(const struct swift_params *params,
error
(
"Cannot find '%s' in the structure."
,
name
);
}
/**
* @brief Retrieve optional integer parameter from structure.
*
* @param params Structure that holds the parameters
* @param name Name of the parameter to be found
* @param def Default value of the parameter of not found.
* @return Value of the parameter found
*/
int
parser_get_opt_param_int
(
const
struct
swift_params
*
params
,
const
char
*
name
,
int
def
)
{
char
str
[
PARSER_MAX_LINE_SIZE
];
int
retParam
=
0
;
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
if
(
!
strcmp
(
name
,
params
->
data
[
i
].
name
))
{
/* Check that exactly one number is parsed. */
if
(
sscanf
(
params
->
data
[
i
].
value
,
"%d%s"
,
&
retParam
,
str
)
!=
1
)
{
error
(
"Tried parsing int '%s' but found '%s' with illegal integer "
"characters '%s'."
,
params
->
data
[
i
].
name
,
params
->
data
[
i
].
value
,
str
);
}
return
retParam
;
}
}
return
def
;
}
/**
* @brief Retrieve optional char parameter from structure.
*
* @param params Structure that holds the parameters
* @param name Name of the parameter to be found
* @param def Default value of the parameter of not found.
* @return Value of the parameter found
*/
char
parser_get_opt_param_char
(
const
struct
swift_params
*
params
,
const
char
*
name
,
char
def
)
{
char
str
[
PARSER_MAX_LINE_SIZE
];
char
retParam
=
0
;
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
if
(
!
strcmp
(
name
,
params
->
data
[
i
].
name
))
{
/* Check that exactly one number is parsed. */
if
(
sscanf
(
params
->
data
[
i
].
value
,
"%c%s"
,
&
retParam
,
str
)
!=
1
)
{
error
(
"Tried parsing char '%s' but found '%s' with illegal char "
"characters '%s'."
,
params
->
data
[
i
].
name
,
params
->
data
[
i
].
value
,
str
);
}
return
retParam
;
}
}
return
def
;
}
/**
* @brief Retrieve optional float parameter from structure.
*
* @param params Structure that holds the parameters
* @param name Name of the parameter to be found
* @param def Default value of the parameter of not found.
* @return Value of the parameter found
*/
float
parser_get_opt_param_float
(
const
struct
swift_params
*
params
,
const
char
*
name
,
float
def
)
{
char
str
[
PARSER_MAX_LINE_SIZE
];
float
retParam
=
0
.
f
;
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
if
(
!
strcmp
(
name
,
params
->
data
[
i
].
name
))
{
/* Check that exactly one number is parsed. */
if
(
sscanf
(
params
->
data
[
i
].
value
,
"%f%s"
,
&
retParam
,
str
)
!=
1
)
{
error
(
"Tried parsing float '%s' but found '%s' with illegal float "
"characters '%s'."
,
params
->
data
[
i
].
name
,
params
->
data
[
i
].
value
,
str
);
}
return
retParam
;
}
}
return
def
;
}
/**
* @brief Retrieve optional double parameter from structure.
*
* @param params Structure that holds the parameters
* @param name Name of the parameter to be found
* @param def Default value of the parameter of not found.
* @return Value of the parameter found
*/
double
parser_get_opt_param_double
(
const
struct
swift_params
*
params
,
const
char
*
name
,
double
def
)
{
char
str
[
PARSER_MAX_LINE_SIZE
];
double
retParam
=
0
.;
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
if
(
!
strcmp
(
name
,
params
->
data
[
i
].
name
))
{
/* Check that exactly one number is parsed. */
if
(
sscanf
(
params
->
data
[
i
].
value
,
"%lf%s"
,
&
retParam
,
str
)
!=
1
)
{
error
(
"Tried parsing double '%s' but found '%s' with illegal double "
"characters '%s'."
,
params
->
data
[
i
].
name
,
params
->
data
[
i
].
value
,
str
);
}
return
retParam
;
}
}
return
def
;
}
/**
* @brief Retrieve string parameter from structure.
*
* @param params Structure that holds the parameters
* @param name Name of the parameter to be found
* @param def Default value of the parameter of not found.
* @param retParam (return) Value of the parameter found
*/
void
parser_get_opt_param_string
(
const
struct
swift_params
*
params
,
const
char
*
name
,
char
*
retParam
,
const
char
*
def
)
{
for
(
int
i
=
0
;
i
<
params
->
paramCount
;
i
++
)
{
if
(
!
strcmp
(
name
,
params
->
data
[
i
].
name
))
{
strcpy
(
retParam
,
params
->
data
[
i
].
value
);
return
;
}
}
strcpy
(
retParam
,
def
);
}
/**
* @brief Prints the contents of the parameter structure.
*
...
...
src/parser.h
View file @
f8aac6f5
...
...
@@ -55,6 +55,7 @@ void parser_read_file(const char *file_name, struct swift_params *params);
void
parser_print_params
(
const
struct
swift_params
*
params
);
void
parser_write_params_to_file
(
const
struct
swift_params
*
params
,
const
char
*
file_name
);
char
parser_get_param_char
(
const
struct
swift_params
*
params
,
const
char
*
name
);
int
parser_get_param_int
(
const
struct
swift_params
*
params
,
const
char
*
name
);
float
parser_get_param_float
(
const
struct
swift_params
*
params
,
...
...
@@ -64,6 +65,18 @@ double parser_get_param_double(const struct swift_params *params,
void
parser_get_param_string
(
const
struct
swift_params
*
params
,
const
char
*
name
,
char
*
retParam
);
char
parser_get_opt_param_char
(
const
struct
swift_params
*
params
,
const
char
*
name
,
char
def
);
int
parser_get_opt_param_int
(
const
struct
swift_params
*
params
,
const
char
*
name
,
int
def
);
float
parser_get_opt_param_float
(
const
struct
swift_params
*
params
,
const
char
*
name
,
float
def
);
double
parser_get_opt_param_double
(
const
struct
swift_params
*
params
,
const
char
*
name
,
double
def
);
void
parser_get_opt_param_string
(
const
struct
swift_params
*
params
,
const
char
*
name
,
char
*
retParam
,
const
char
*
def
);
#if defined(HAVE_HDF5)
void
parser_write_params_to_hdf5
(
const
struct
swift_params
*
params
,
hid_t
grp
);
#endif
...
...
src/space.c
View file @
f8aac6f5
...
...
@@ -1437,9 +1437,12 @@ void space_init(struct space *s, const struct swift_params *params,
s
->
size_parts_foreign
=
0
;
/* Get the constants for the scheduler */
space_maxsize
=
parser_get_param_int
(
params
,
"Scheduler:cell_max_size"
);
space_subsize
=
parser_get_param_int
(
params
,
"Scheduler:cell_sub_size"
);
space_splitsize
=
parser_get_param_int
(
params
,
"Scheduler:cell_split_size"
);
space_maxsize
=
parser_get_opt_param_int
(
params
,
"Scheduler:cell_max_size"
,
space_maxsize_default
);
space_subsize
=
parser_get_opt_param_int
(
params
,
"Scheduler:cell_sub_size"
,
space_subsize_default
);
space_splitsize
=
parser_get_opt_param_int
(
params
,
"Scheduler:cell_split_size"
,
space_splitsize_default
);
if
(
verbose
)
message
(
"max_size set to %d, sub_size set to %d, split_size set to %d"
,
space_maxsize
,
space_subsize
,
space_splitsize
);
...
...
@@ -1454,7 +1457,7 @@ void space_init(struct space *s, const struct swift_params *params,
/* Apply h scaling */
const
double
scaling
=
parser_get_param_double
(
params
,
"InitialConditions:h_scaling"
);
parser_get_
opt_
param_double
(
params
,
"InitialConditions:h_scaling"
,
1
.
0
);
if
(
scaling
!=
1
.
0
&&
!
dry_run
)
{
message
(
"Re-scaling smoothing lengths by a factor %e"
,
scaling
);
for
(
size_t
k
=
0
;
k
<
Npart
;
k
++
)
parts
[
k
].
h
*=
scaling
;
...
...
@@ -1462,10 +1465,13 @@ void space_init(struct space *s, const struct swift_params *params,
/* Apply shift */
double
shift
[
3
]
=
{
0
.
0
,
0
.
0
,
0
.
0
};
shift
[
0
]
=
parser_get_param_double
(
params
,
"InitialConditions:shift_x"
);
shift
[
1
]
=
parser_get_param_double
(
params
,
"InitialConditions:shift_y"
);
shift
[
2
]
=
parser_get_param_double
(
params
,
"InitialConditions:shift_z"
);
if
((
shift
[
0
]
!=
0
||
shift
[
1
]
!=
0
||
shift
[
2
]
!=
0
)
&&
!
dry_run
)
{
shift
[
0
]
=
parser_get_opt_param_double
(
params
,
"InitialConditions:shift_x"
,
0
.
0
);
shift
[
1
]
=
parser_get_opt_param_double
(
params
,
"InitialConditions:shift_y"
,
0
.
0
);
shift
[
2
]
=
parser_get_opt_param_double
(
params
,
"InitialConditions:shift_z"
,
0
.
0
);
if
((
shift
[
0
]
!=
0
.
||
shift
[
1
]
!=
0
.
||
shift
[
2
]
!=
0
.)
&&
!
dry_run
)
{
message
(
"Shifting particles by [%e %e %e]"
,
shift
[
0
],
shift
[
1
],
shift
[
2
]);
for
(
size_t
k
=
0
;
k
<
Npart
;
k
++
)
{
parts
[
k
].
x
[
0
]
+=
shift
[
0
];
...
...
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