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
c93262ad
Commit
c93262ad
authored
Jul 18, 2016
by
Matthieu Schaller
Browse files
Have a default unit system for the snapshots when none is provided
parent
f67f292b
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/engine.c
View file @
c93262ad
...
...
@@ -2672,7 +2672,7 @@ void engine_dump_snapshot(struct engine *e) {
struct
clocks_time
time1
,
time2
;
clocks_gettime
(
&
time1
);
if
(
e
->
verbose
)
message
(
"writing snapshot at t=%
f
."
,
e
->
time
);
if
(
e
->
verbose
)
message
(
"writing snapshot at t=%
e
."
,
e
->
time
);
/* Dump... */
#if defined(WITH_MPI)
...
...
@@ -2808,7 +2808,7 @@ void engine_init(struct engine *e, struct space *s,
e
->
ti_nextSnapshot
=
0
;
parser_get_param_string
(
params
,
"Snapshots:basename"
,
e
->
snapshotBaseName
);
e
->
snapshotUnits
=
malloc
(
sizeof
(
struct
UnitSystem
));
units_init
(
e
->
snapshotUnits
,
params
,
"Snapshots"
);
units_init
_default
(
e
->
snapshotUnits
,
params
,
"Snapshots"
,
internal_units
);
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
;
...
...
@@ -3228,6 +3228,6 @@ void engine_compute_next_snapshot_time(struct engine *e) {
const
float
next_snapshot_time
=
e
->
ti_nextSnapshot
*
e
->
timeBase
+
e
->
timeBegin
;
if
(
e
->
verbose
)
message
(
"Next output time set to t=%
f
."
,
next_snapshot_time
);
message
(
"Next output time set to t=%
e
."
,
next_snapshot_time
);
}
}
src/units.c
View file @
c93262ad
...
...
@@ -66,6 +66,41 @@ void units_init(struct UnitSystem* us, const struct swift_params* params,
us
->
UnitTemperature_in_cgs
=
parser_get_param_double
(
params
,
buffer
);
}
/**
* @brief Initialises the UnitSystem structure with the constants given in
* rhe parameter file. Uses a default if the values are not present in the file.
*
* @param us The UnitSystem to initialize.
* @param params The parsed parameter file.
* @param category The section of the parameter file to read from.
* @param def The default unit system to copy from if required.
*/
void
units_init_default
(
struct
UnitSystem
*
us
,
const
struct
swift_params
*
params
,
const
char
*
category
,
const
struct
UnitSystem
*
def
)
{
if
(
!
def
)
error
(
"Default UnitSystem not allocated"
);
char
buffer
[
200
];
sprintf
(
buffer
,
"%s:UnitMass_in_cgs"
,
category
);
us
->
UnitMass_in_cgs
=
parser_get_opt_param_double
(
params
,
buffer
,
def
->
UnitMass_in_cgs
);
sprintf
(
buffer
,
"%s:UnitLength_in_cgs"
,
category
);
us
->
UnitLength_in_cgs
=
parser_get_opt_param_double
(
params
,
buffer
,
def
->
UnitLength_in_cgs
);
sprintf
(
buffer
,
"%s:UnitVelocity_in_cgs"
,
category
);
const
double
defaultVelocity
=
def
->
UnitLength_in_cgs
/
def
->
UnitTime_in_cgs
;
const
double
unitVelocity
=
parser_get_opt_param_double
(
params
,
buffer
,
defaultVelocity
);
us
->
UnitTime_in_cgs
=
us
->
UnitLength_in_cgs
/
unitVelocity
;
sprintf
(
buffer
,
"%s:UnitCurrent_in_cgs"
,
category
);
us
->
UnitCurrent_in_cgs
=
parser_get_opt_param_double
(
params
,
buffer
,
def
->
UnitCurrent_in_cgs
);
sprintf
(
buffer
,
"%s:UnitTemp_in_cgs"
,
category
);
us
->
UnitTemperature_in_cgs
=
parser_get_opt_param_double
(
params
,
buffer
,
def
->
UnitTemperature_in_cgs
);
}
/**
* @brief Returns the base unit conversion factor for a given unit system
* @param us The UnitSystem used
...
...
src/units.h
View file @
c93262ad
...
...
@@ -94,6 +94,10 @@ enum UnitConversionFactor {
void
units_init
(
struct
UnitSystem
*
,
const
struct
swift_params
*
,
const
char
*
category
);
void
units_init_default
(
struct
UnitSystem
*
us
,
const
struct
swift_params
*
params
,
const
char
*
category
,
const
struct
UnitSystem
*
def
);
int
units_are_equal
(
const
struct
UnitSystem
*
a
,
const
struct
UnitSystem
*
b
);
/* Base units */
...
...
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