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
adb3382b
Commit
adb3382b
authored
Jan 23, 2017
by
Matthieu Schaller
Browse files
New debugging function checking that all the gpart<->part and gpart<->spart links are correct.
parent
2166fb0c
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/engine.c
View file @
adb3382b
...
...
@@ -532,27 +532,10 @@ void engine_redistribute(struct engine *e) {
cells
[
cid
].
nodeID
);
}
/* Verify that the links are correct */
for
(
size_t
k
=
0
;
k
<
nr_gparts
;
++
k
)
{
if
(
gparts_new
[
k
].
id_or_neg_offset
<=
0
)
{
struct
part
*
part
=
&
parts_new
[
-
gparts_new
[
k
].
id_or_neg_offset
];
if
(
part
->
gpart
!=
&
gparts_new
[
k
])
error
(
"Linking problem !"
);
if
(
gparts_new
[
k
].
x
[
0
]
!=
part
->
x
[
0
]
||
gparts_new
[
k
].
x
[
1
]
!=
part
->
x
[
1
]
||
gparts_new
[
k
].
x
[
2
]
!=
part
->
x
[
2
])
error
(
"Linked particles are not at the same position !"
);
}
}
for
(
size_t
k
=
0
;
k
<
nr_parts
;
++
k
)
{
if
(
parts_new
[
k
].
gpart
!=
NULL
&&
parts_new
[
k
].
gpart
->
id_or_neg_offset
!=
-
(
ptrdiff_t
)
k
)
{
error
(
"Linking problem !"
);
}
}
/* Verify that the links are correct */
// part_verify_links(parts_new, gparts_new, sparts_new, nr_parts, nr_gparts,
// nr_sparts);
// MATTHIEU
#endif
/* Set the new part data, free the old. */
...
...
@@ -2972,28 +2955,9 @@ void engine_split(struct engine *e, struct partition *initial_partition) {
part_relink_parts_to_gparts
(
s
->
gparts
,
s
->
nr_gparts
,
s
->
parts
);
#ifdef SWIFT_DEBUG_CHECKS
/* Verify that the links are correct */
for
(
size_t
k
=
0
;
k
<
s
->
nr_gparts
;
++
k
)
{
if
(
s
->
gparts
[
k
].
id_or_neg_offset
<=
0
)
{
struct
part
*
part
=
&
s
->
parts
[
-
s
->
gparts
[
k
].
id_or_neg_offset
];
if
(
part
->
gpart
!=
&
s
->
gparts
[
k
])
error
(
"Linking problem !"
);
if
(
s
->
gparts
[
k
].
x
[
0
]
!=
part
->
x
[
0
]
||
s
->
gparts
[
k
].
x
[
1
]
!=
part
->
x
[
1
]
||
s
->
gparts
[
k
].
x
[
2
]
!=
part
->
x
[
2
])
error
(
"Linked particles are not at the same position !"
);
}
}
for
(
size_t
k
=
0
;
k
<
s
->
nr_parts
;
++
k
)
{
if
(
s
->
parts
[
k
].
gpart
!=
NULL
&&
s
->
parts
[
k
].
gpart
->
id_or_neg_offset
!=
-
(
ptrdiff_t
)
k
)
error
(
"Linking problem !"
);
}
part_verify_links
(
s
->
parts
,
s
->
gparts
,
s
->
sparts
,
s
->
nr_parts
,
s
->
nr_gparts
,
s
->
nr_sparts
);
#endif
#else
...
...
src/part.c
View file @
adb3382b
...
...
@@ -93,6 +93,112 @@ void part_relink_sparts_to_gparts(struct gpart *gparts, size_t N,
}
}
/**
* @brief Verifies that the #gpart, #part and #spart are correctly linked
* together
* and that the particle poisitions match.
*
* This is a debugging function.
*
* @param parts The #part array.
* @param gparts The #gpart array.
* @param sparts The #spart array.
* @param nr_parts The number of #part in the array.
* @param nr_gparts The number of #gpart in the array.
* @param nr_sparts The number of #spart in the array.
*/
void
part_verify_links
(
struct
part
*
parts
,
struct
gpart
*
gparts
,
struct
spart
*
sparts
,
size_t
nr_parts
,
size_t
nr_gparts
,
size_t
nr_sparts
)
{
for
(
size_t
k
=
0
;
k
<
nr_gparts
;
++
k
)
{
/* We have a DM particle */
if
(
gparts
[
k
].
type
==
swift_type_dark_matter
)
{
/* Check that it's not linked */
if
(
gparts
[
k
].
id_or_neg_offset
<
0
)
error
(
"DM gpart particle linked to something !"
);
}
/* We have a gas particle */
else
if
(
gparts
[
k
].
type
==
swift_type_gas
)
{
/* Check that it is linked */
if
(
gparts
[
k
].
id_or_neg_offset
>
0
)
error
(
"Gas gpart not linked to anything !"
);
/* Find its link */
const
struct
part
*
part
=
&
parts
[
-
gparts
[
k
].
id_or_neg_offset
];
/* Check the reverse link */
if
(
part
->
gpart
!=
&
gparts
[
k
])
error
(
"Linking problem !"
);
/* Check that the particles are at the same place */
if
(
gparts
[
k
].
x
[
0
]
!=
part
->
x
[
0
]
||
gparts
[
k
].
x
[
1
]
!=
part
->
x
[
1
]
||
gparts
[
k
].
x
[
2
]
!=
part
->
x
[
2
])
error
(
"Linked particles are not at the same position !"
);
}
else
if
(
gparts
[
k
].
type
==
swift_type_star
)
{
/* Check that it is linked */
if
(
gparts
[
k
].
id_or_neg_offset
>
0
)
error
(
"Gas gpart not linked to anything !"
);
/* Find its link */
const
struct
spart
*
spart
=
&
sparts
[
-
gparts
[
k
].
id_or_neg_offset
];
/* Check the reverse link */
if
(
spart
->
gpart
!=
&
gparts
[
k
])
error
(
"Linking problem !"
);
/* Check that the particles are at the same place */
if
(
gparts
[
k
].
x
[
0
]
!=
spart
->
x
[
0
]
||
gparts
[
k
].
x
[
1
]
!=
spart
->
x
[
1
]
||
gparts
[
k
].
x
[
2
]
!=
spart
->
x
[
2
])
error
(
"Linked particles are not at the same position !"
);
}
}
/* Now check that all parts are linked */
for
(
size_t
k
=
0
;
k
<
nr_parts
;
++
k
)
{
/* Ok, there is a link */
if
(
parts
[
k
].
gpart
!=
NULL
)
{
/* Check the link */
if
(
parts
[
k
].
gpart
->
id_or_neg_offset
!=
-
(
ptrdiff_t
)
k
)
{
error
(
"Linking problem !"
);
}
/* Check that the particles are at the same place */
if
(
parts
[
k
].
x
[
0
]
!=
parts
[
k
].
gpart
->
x
[
0
]
||
parts
[
k
].
x
[
1
]
!=
parts
[
k
].
gpart
->
x
[
1
]
||
parts
[
k
].
x
[
2
]
!=
parts
[
k
].
gpart
->
x
[
2
])
error
(
"Linked particles are not at the same position !"
);
}
}
/* Now check that all sparts are linked */
for
(
size_t
k
=
0
;
k
<
nr_sparts
;
++
k
)
{
/* Ok, there is a link */
if
(
sparts
[
k
].
gpart
!=
NULL
)
{
/* Check the link */
if
(
sparts
[
k
].
gpart
->
id_or_neg_offset
!=
-
(
ptrdiff_t
)
k
)
{
error
(
"Linking problem !"
);
/* Check that the particles are at the same place */
if
(
sparts
[
k
].
x
[
0
]
!=
sparts
[
k
].
gpart
->
x
[
0
]
||
sparts
[
k
].
x
[
1
]
!=
sparts
[
k
].
gpart
->
x
[
1
]
||
sparts
[
k
].
x
[
2
]
!=
sparts
[
k
].
gpart
->
x
[
2
])
error
(
"Linked particles are not at the same position !"
);
}
}
}
}
#ifdef WITH_MPI
/* MPI data type for the particle transfers */
MPI_Datatype
part_mpi_type
;
...
...
src/part.h
View file @
adb3382b
...
...
@@ -76,6 +76,10 @@ void part_relink_parts_to_gparts(struct gpart *gparts, size_t N,
struct
part
*
parts
);
void
part_relink_sparts_to_gparts
(
struct
gpart
*
gparts
,
size_t
N
,
struct
spart
*
sparts
);
void
part_verify_links
(
struct
part
*
parts
,
struct
gpart
*
gparts
,
struct
spart
*
sparts
,
size_t
nr_parts
,
size_t
nr_gparts
,
size_t
nr_sparts
);
#ifdef WITH_MPI
/* MPI data type for the particle transfers */
extern
MPI_Datatype
part_mpi_type
;
...
...
src/space.c
View file @
adb3382b
...
...
@@ -738,26 +738,8 @@ void space_rebuild(struct space *s, int verbose) {
#ifdef SWIFT_DEBUG_CHECKS
/* Verify that the links are correct */
for
(
size_t
k
=
0
;
k
<
nr_gparts
;
++
k
)
{
if
(
s
->
gparts
[
k
].
id_or_neg_offset
<
0
)
{
const
struct
part
*
part
=
&
s
->
parts
[
-
s
->
gparts
[
k
].
id_or_neg_offset
];
if
(
part
->
gpart
!=
&
s
->
gparts
[
k
])
error
(
"Linking problem !"
);
if
(
s
->
gparts
[
k
].
x
[
0
]
!=
part
->
x
[
0
]
||
s
->
gparts
[
k
].
x
[
1
]
!=
part
->
x
[
1
]
||
s
->
gparts
[
k
].
x
[
2
]
!=
part
->
x
[
2
])
error
(
"Linked particles are not at the same position !"
);
}
}
for
(
size_t
k
=
0
;
k
<
nr_parts
;
++
k
)
{
if
(
s
->
parts
[
k
].
gpart
!=
NULL
&&
s
->
parts
[
k
].
gpart
->
id_or_neg_offset
!=
-
(
ptrdiff_t
)
k
)
{
error
(
"Linking problem !"
);
}
}
part_verify_links
(
s
->
parts
,
s
->
gparts
,
s
->
sparts
,
nr_parts
,
nr_gparts
,
nr_sparts
);
#endif
/* Hook the cells up to the parts. */
...
...
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