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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
727d3f45
Commit
727d3f45
authored
8 years ago
by
Pedro Gonnet
Browse files
Options
Downloads
Patches
Plain Diff
add logging for gparts and timestamps as well.
parent
fa561bd5
No related branches found
No related tags found
1 merge request
!299
Particle logger
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/logger.c
+94
-2
94 additions, 2 deletions
src/logger.c
src/logger.h
+2
-1
2 additions, 1 deletion
src/logger.h
with
96 additions
and
3 deletions
src/logger.c
+
94
−
2
View file @
727d3f45
...
...
@@ -111,8 +111,8 @@ void logger_log_part(struct part *p, unsigned int mask, size_t *offset,
char
*
buff
=
dump_get
(
dump
,
size
,
&
offset_new
);
/* Write the header. */
uint64_t
temp
=
(((
uint64_t
)
*
offset
)
&
0xffffffffffffffL
)
|
((
uint64_t
)
mask
<<
56
);
uint64_t
temp
=
(((
uint64_t
)(
offset_new
-
*
offset
))
&
0xffffffffffffffL
)
|
((
uint64_t
)
mask
<<
56
);
memcpy
(
buff
,
&
temp
,
8
);
buff
+=
8
;
...
...
@@ -167,3 +167,95 @@ void logger_log_part(struct part *p, unsigned int mask, size_t *offset,
/* Update the log message offset. */
*
offset
=
offset_new
;
}
/**
* @brief Dump a #gpart to the log.
*
* @param gpart The #gpart to dump.
* @param mask The mask of the data to dump.
* @param offset Pointer to the offset of the previous log of this particle.
* @param dump The #dump in which to log the particle data.
*/
void
logger_log_gpart
(
struct
gpart
*
p
,
unsigned
int
mask
,
size_t
*
offset
,
struct
dump
*
dump
)
{
/* Make sure we're not writing a timestamp. */
if
(
mask
&
logger_mask_timestamp
)
error
(
"You should not log particles as timestamps."
);
/* Make sure we're not looging fields not supported by gparts. */
if
(
mask
&
(
logger_mask_u
|
logger_mask_rho
))
error
(
"Can't log SPH quantities for gparts."
);
/* Start by computing the size of the message. */
const
int
size
=
logger_size
(
mask
);
/* Allocate a chunk of memory in the dump of the right size. */
size_t
offset_new
;
char
*
buff
=
dump_get
(
dump
,
size
,
&
offset_new
);
/* Write the header. */
uint64_t
temp
=
(((
uint64_t
)(
offset_new
-
*
offset
))
&
0xffffffffffffffL
)
|
((
uint64_t
)
mask
<<
56
);
memcpy
(
buff
,
&
temp
,
8
);
buff
+=
8
;
/* Particle position as three doubles. */
if
(
mask
&
logger_mask_x
)
{
memcpy
(
buff
,
p
->
x
,
3
*
sizeof
(
double
));
buff
+=
3
*
sizeof
(
double
);
}
/* Particle velocity as three floats. */
if
(
mask
&
logger_mask_v
)
{
memcpy
(
buff
,
p
->
v_full
,
3
*
sizeof
(
float
));
buff
+=
3
*
sizeof
(
float
);
}
/* Particle accelleration as three floats. */
if
(
mask
&
logger_mask_a
)
{
memcpy
(
buff
,
p
->
a_grav
,
3
*
sizeof
(
float
));
buff
+=
3
*
sizeof
(
float
);
}
/* Particle smoothing length as a single float. */
if
(
mask
&
logger_mask_h
)
{
memcpy
(
buff
,
&
p
->
epsilon
,
sizeof
(
float
));
buff
+=
sizeof
(
float
);
}
/* Particle constants, which is a bit more complicated. */
if
(
mask
&
logger_mask_rho
)
{
memcpy
(
buff
,
&
p
->
mass
,
sizeof
(
float
));
buff
+=
sizeof
(
float
);
memcpy
(
buff
,
&
p
->
id_or_neg_offset
,
sizeof
(
long
long
));
buff
+=
sizeof
(
long
long
);
}
/* Update the log message offset. */
*
offset
=
offset_new
;
}
void
logger_log_timestamp
(
unsigned
long
long
int
timestamp
,
size_t
*
offset
,
struct
dump
*
dump
)
{
/* Start by computing the size of the message. */
const
int
size
=
logger_size
(
logger_mask_timestamp
);
/* Allocate a chunk of memory in the dump of the right size. */
size_t
offset_new
;
char
*
buff
=
dump_get
(
dump
,
size
,
&
offset_new
);
/* Write the header. */
uint64_t
temp
=
(((
uint64_t
)(
offset_new
-
*
offset
))
&
0xffffffffffffffL
)
|
((
uint64_t
)
logger_mask_timestamp
<<
56
);
memcpy
(
buff
,
&
temp
,
8
);
buff
+=
8
;
/* Store the timestamp. */
memcpy
(
buff
,
&
timestamp
,
sizeof
(
unsigned
long
long
int
));
/* Update the log message offset. */
*
offset
=
offset_new
;
}
This diff is collapsed.
Click to expand it.
src/logger.h
+
2
−
1
View file @
727d3f45
...
...
@@ -45,7 +45,8 @@
* 2 | a | 12 | Particle acceleration, stored as three floats.
* 3 | u | 4 | Particle internal energy (or entropy, if Gadget-SPH
* | | | is used), stored as a single float.
* 4 | h | 4 | Particle smoothing length, stored as a single float.
* 4 | h | 4 | Particle smoothing length (or epsilon, if a gpart),
* | | | stored as a single float.
* 5 | rho | 4 | Particle density, stored as a single float.
* 6 | consts | 12 | Particle constants, i.e. mass and ID.
* 7 | time | 8 | Timestamp, not associated with a particle, just
...
...
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
register
or
sign in
to comment