Commit 213dd87e authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

The printParticle() routine does not crash anymore if the ID requested is not...

The printParticle() routine does not crash anymore if the ID requested is not found within the array of particles. Instead a message is written to stdout.



Former-commit-id: 7f2eca9ac1b3f59aee1999c8bd7b35c26f7dc5bc
parent caceec16
......@@ -886,7 +886,7 @@ int main ( int argc , char *argv[] ) {
/* Dump the first few particles. */
for(k=0; k<10; ++k)
printParticle(parts, k);
printParticle(parts, k, N);
tic = getticks();
write_output("output.hdf5", dim, parts, N, periodic);
......@@ -969,8 +969,8 @@ int main ( int argc , char *argv[] ) {
/* Dump the first few particles. */
for(k=0; k<10; ++k)
printParticle(parts, k);
printParticle( parts , 113531 );
printParticle(parts, k, N );
printParticle( parts , 113531, N );
/* Get the particle with the lowest h. */
p = &s.parts[0];
......@@ -1053,7 +1053,7 @@ int main ( int argc , char *argv[] ) {
/* Dump the first few particles. */
for(k=0; k<10; ++k)
printParticle(parts, k);
printParticle(parts, k, N);
/* Get all the cells of a certain depth. */
// icount = 1;
......
......@@ -23,13 +23,24 @@
#include "part.h"
void printParticle ( struct part *parts , long long int id ) {
/**
* @brief Looks for the particle with the given id and prints its information to the standard output.
*
* @param parts The array of particles.
* @param id The id too look for.
* @param N The size of the array of particles.
*
* (Should be used for debugging only as it runs in O(N).)
*/
void printParticle ( struct part *parts , long long int id, int N ) {
int i;
/* Look for the particle. */
for ( i = 0 ; parts[i].id != id ; i++ );
for ( i = 0 ; i < N && parts[i].id != id; i++ );
if(i < N)
printf("## Particle[%d]: id=%lld, x=[%.3e,%.3e,%.3e], v=[%.3e,%.3e,%.3e], a=[%.3e,%.3e,%.3e], h=%.3e, h_dt=%.3e, wcount=%.3e, m=%.3e, rho=%.3e, rho_dh=%.3e, div_v=%.3e, u=%.3e, dudt=%.3e, bals=%.3e, POrho2=%.3e, v_sig=%.3e, dt=%.3e\n",
i,
parts[i].id,
......@@ -49,5 +60,7 @@ void printParticle ( struct part *parts , long long int id ) {
parts[i].force.v_sig,
parts[i].dt
);
else
printf("## Particles[???] id=%lld not found\n", id);
}
......@@ -20,4 +20,4 @@
void printParticle(struct part *parts, long long int i);
void printParticle(struct part *parts, long long int i, int N);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment