Skip to content

Commit

Permalink
Adjust colloid I/O to ensure backward compatability; use reference in…
Browse files Browse the repository at this point in the history
… write calls
  • Loading branch information
kevinstratford committed Mar 4, 2020
1 parent b049f54 commit f3f22de
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 93 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

### Changes
version 0.10.0
- Added an option to fix colloid position or velocity on a per-direction
basis, e.g.
colloid_isfixedrxyz 1_1_0
allows movement in z-direction only. Any value is overridden by
colloid_isfixedr. An analogous option colloid_isfixedvxyz is available.
- Added target thread model information to output
- Refactored d_ij and e_ijk from char to int8_t to avoid potential
pitfalls with default unsigned char.
Expand Down
102 changes: 57 additions & 45 deletions src/colloid.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Edinburgh Parallel Computing Centre
*
* Kevin Stratford ([email protected])
* (c) 2010-2014 The University of Edinburgh
* (c) 2010-2020 The University of Edinburgh
*
*****************************************************************************/

Expand All @@ -33,7 +33,6 @@ int colloid_state_read_ascii(colloid_state_t * ps, FILE * fp) {
int ifail = 0;

const char * isformat = "%24d\n";
const char * ivformat = "%24d %24d %24d\n";
const char * sformat = "%24le\n";
const char * vformat = "%24le %24le %24le\n";

Expand All @@ -45,9 +44,7 @@ int colloid_state_read_ascii(colloid_state_t * ps, FILE * fp) {
nread += fscanf(fp, isformat, &ps->nbonds);
nread += fscanf(fp, isformat, &ps->nangles);
nread += fscanf(fp, isformat, &ps->isfixedr);
nread += fscanf(fp, ivformat, &ps->isfixedrxyz[0], &ps->isfixedrxyz[1], &ps->isfixedrxyz[2]);
nread += fscanf(fp, isformat, &ps->isfixedv);
nread += fscanf(fp, ivformat, &ps->isfixedvxyz[0], &ps->isfixedvxyz[1], &ps->isfixedvxyz[2]);
nread += fscanf(fp, isformat, &ps->isfixedw);
nread += fscanf(fp, isformat, &ps->isfixeds);
nread += fscanf(fp, isformat, &ps->type);
Expand All @@ -58,6 +55,12 @@ int colloid_state_read_ascii(colloid_state_t * ps, FILE * fp) {

nread += fscanf(fp, isformat, &ps->rng);

for (n = 0; n < 3; n++) {
nread += fscanf(fp, isformat, ps->isfixedrxyz + n);
}
for (n = 0; n < 3; n++) {
nread += fscanf(fp, isformat, ps->isfixedvxyz + n);
}
for (n = 0; n < NPAD_INT; n++) {
nread += fscanf(fp, isformat, &ps->intpad[n]);
}
Expand Down Expand Up @@ -133,66 +136,74 @@ int colloid_state_read_binary(colloid_state_t * ps, FILE * fp) {
*
*****************************************************************************/

int colloid_state_write_ascii(colloid_state_t s, FILE * fp) {
int colloid_state_write_ascii(const colloid_state_t * s, FILE * fp) {

int n;
int nwrite = 0;
int ifail = 0;

const char * isformat = "%24d\n";
const char * ivformat = "%24d %24d %24d\n";
const char * sformat = "%24.15e\n";
const char * vformat = "%24.15e %24.15e %24.15e\n";

assert(s);
assert(fp);

nwrite += fprintf(fp, isformat, s.index);
nwrite += fprintf(fp, isformat, s.rebuild);
nwrite += fprintf(fp, isformat, s.nbonds);
nwrite += fprintf(fp, isformat, s.nangles);
nwrite += fprintf(fp, isformat, s.isfixedr);
nwrite += fprintf(fp, ivformat, s.isfixedrxyz[0], s.isfixedrxyz[1], s.isfixedrxyz[2]);
nwrite += fprintf(fp, isformat, s.isfixedv);
nwrite += fprintf(fp, ivformat, s.isfixedvxyz[0], s.isfixedvxyz[1], s.isfixedvxyz[2]);
nwrite += fprintf(fp, isformat, s.isfixedw);
nwrite += fprintf(fp, isformat, s.isfixeds);
nwrite += fprintf(fp, isformat, s.type);
nwrite += fprintf(fp, isformat, s->index);
nwrite += fprintf(fp, isformat, s->rebuild);
nwrite += fprintf(fp, isformat, s->nbonds);
nwrite += fprintf(fp, isformat, s->nangles);
nwrite += fprintf(fp, isformat, s->isfixedr);
nwrite += fprintf(fp, isformat, s->isfixedv);
nwrite += fprintf(fp, isformat, s->isfixedw);
nwrite += fprintf(fp, isformat, s->isfixeds);
nwrite += fprintf(fp, isformat, s->type);

for (n = 0; n < NBOND_MAX; n++) {
nwrite += fprintf(fp, isformat, s.bond[n]);
nwrite += fprintf(fp, isformat, s->bond[n]);
}

nwrite += fprintf(fp, isformat, s.rng);
nwrite += fprintf(fp, isformat, s->rng);

/* isfixedrxyz and isfixedvxyz are writen as 3 x scalars as they
* have replaced padding */

for (n = 0; n < 3; n++) {
nwrite += fprintf(fp, isformat, s->isfixedrxyz[n]);
}
for (n = 0; n < 3; n++) {
nwrite += fprintf(fp, isformat, s->isfixedvxyz[n]);
}

for (n = 0; n < NPAD_INT; n++) {
nwrite += fprintf(fp, isformat, s.intpad[n]);
nwrite += fprintf(fp, isformat, s->intpad[n]);
}

nwrite += fprintf(fp, sformat, s.a0);
nwrite += fprintf(fp, sformat, s.ah);
nwrite += fprintf(fp, vformat, s.r[0], s.r[1], s.r[2]);
nwrite += fprintf(fp, vformat, s.v[0], s.v[1], s.v[2]);
nwrite += fprintf(fp, vformat, s.w[0], s.w[1], s.w[2]);
nwrite += fprintf(fp, vformat, s.s[0], s.s[1], s.s[2]);
nwrite += fprintf(fp, vformat, s.m[0], s.m[1], s.m[2]);
nwrite += fprintf(fp, sformat, s.b1);
nwrite += fprintf(fp, sformat, s.b2);
nwrite += fprintf(fp, sformat, s.c);
nwrite += fprintf(fp, sformat, s.h);
nwrite += fprintf(fp, vformat, s.dr[0], s.dr[1], s.dr[2]);
nwrite += fprintf(fp, sformat, s.deltaphi);

nwrite += fprintf(fp, sformat, s.q0);
nwrite += fprintf(fp, sformat, s.q1);
nwrite += fprintf(fp, sformat, s.epsilon);

nwrite += fprintf(fp, sformat, s.deltaq0);
nwrite += fprintf(fp, sformat, s.deltaq1);
nwrite += fprintf(fp, sformat, s.sa);
nwrite += fprintf(fp, sformat, s.saf);
nwrite += fprintf(fp, sformat, s->a0);
nwrite += fprintf(fp, sformat, s->ah);
nwrite += fprintf(fp, vformat, s->r[0], s->r[1], s->r[2]);
nwrite += fprintf(fp, vformat, s->v[0], s->v[1], s->v[2]);
nwrite += fprintf(fp, vformat, s->w[0], s->w[1], s->w[2]);
nwrite += fprintf(fp, vformat, s->s[0], s->s[1], s->s[2]);
nwrite += fprintf(fp, vformat, s->m[0], s->m[1], s->m[2]);
nwrite += fprintf(fp, sformat, s->b1);
nwrite += fprintf(fp, sformat, s->b2);
nwrite += fprintf(fp, sformat, s->c);
nwrite += fprintf(fp, sformat, s->h);
nwrite += fprintf(fp, vformat, s->dr[0], s->dr[1], s->dr[2]);
nwrite += fprintf(fp, sformat, s->deltaphi);

nwrite += fprintf(fp, sformat, s->q0);
nwrite += fprintf(fp, sformat, s->q1);
nwrite += fprintf(fp, sformat, s->epsilon);

nwrite += fprintf(fp, sformat, s->deltaq0);
nwrite += fprintf(fp, sformat, s->deltaq1);
nwrite += fprintf(fp, sformat, s->sa);
nwrite += fprintf(fp, sformat, s->saf);

for (n = 0; n < NPAD_DBL; n++) {
nwrite += fprintf(fp, sformat, s.dpad[n]);
nwrite += fprintf(fp, sformat, s->dpad[n]);
}

/* ... should be NTOT_VAR items of format + 1 characters */
Expand All @@ -213,13 +224,14 @@ int colloid_state_write_ascii(colloid_state_t s, FILE * fp) {
*
*****************************************************************************/

int colloid_state_write_binary(colloid_state_t s, FILE * fp) {
int colloid_state_write_binary(const colloid_state_t * s, FILE * fp) {

int nwrite;

assert(s);
assert(fp);

nwrite = fwrite(&s, sizeof(colloid_state_t), 1, fp);
nwrite = fwrite(s, sizeof(colloid_state_t), 1, fp);

return (1 - nwrite);
}
16 changes: 10 additions & 6 deletions src/colloid.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ struct colloid_state_type {
int nbonds; /* Number of bonds e.g. fene (to NBOND_MAX) */
int nangles; /* Number of angles, e.g., fene (1 at the moment) */

int isfixedr; /* Set to 1 for no position update in all coordinate directions */
int isfixedrxyz[3]; /* Set vector for no position update in specific coordinate directions */
int isfixedv; /* Set to 1 for no velocity update in all coordinate directions */
int isfixedvxyz[3]; /* Set vector for no velocity update in specific coordinate directions */
int isfixedr; /* Set to 1 for no position update */
int isfixedv; /* Set to 1 for no velocity update */
int isfixedw; /* Set to 1 for no angular velocity update */
int isfixeds; /* Set to zero for no s, m update */

Expand All @@ -60,6 +58,12 @@ struct colloid_state_type {

int rng; /* Random number state */

int isfixedrxyz[3]; /* Position update in specific coordinate directions */
int isfixedvxyz[3]; /* Velocity update in specific coordinate directions */

/* New integer additions can be immediately before the padding */
/* This should allow existing binary files to be read correctly */

int intpad[NPAD_INT]; /* I'm going to pad to 32 ints to allow for future
* expansion. Additions should be appended here,
* and the padding reduced appropriately. */
Expand Down Expand Up @@ -100,7 +104,7 @@ struct colloid_state_type {

int colloid_state_read_ascii(colloid_state_t * ps, FILE * fp);
int colloid_state_read_binary(colloid_state_t * ps, FILE * fp);
int colloid_state_write_ascii(colloid_state_t ps, FILE * fp);
int colloid_state_write_binary(colloid_state_t ps, FILE * fp);
int colloid_state_write_ascii(const colloid_state_t * ps, FILE * fp);
int colloid_state_write_binary(const colloid_state_t * ps, FILE * fp);

#endif
8 changes: 4 additions & 4 deletions src/colloid_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Edinburgh Soft Matter and Statistical Physics Group and
* Edinburgh Parallel Computing Centre
*
* (c) 2010-2018 The University of Edinburgh
* (c) 2010-2020 The University of Edinburgh
*
* Contributing authors:
* Kevin Stratford ([email protected])
Expand Down Expand Up @@ -391,7 +391,7 @@ int colloid_io_write_buffer_ascii(FILE * fp, int nc, colloid_state_t * buf) {
assert(buf);

for (n = 0; n < nc; n++) {
ifail += colloid_state_write_ascii(buf[n], fp);
ifail += colloid_state_write_ascii(buf + n, fp);
}

return ifail;
Expand Down Expand Up @@ -556,7 +556,7 @@ static int colloid_io_write_list_ascii(colloid_io_t * cio,
colloids_info_cell_list_head(cio->info, ic, jc, kc, &pc);

while (pc) {
ifail += colloid_state_write_ascii(pc->s, fp);
ifail += colloid_state_write_ascii(&pc->s, fp);
pc = pc->next;
}

Expand Down Expand Up @@ -614,7 +614,7 @@ static int colloid_io_write_list_binary(colloid_io_t * cio,
colloids_info_cell_list_head(cio->info, ic, jc, kc, &pc);

while (pc) {
colloid_state_write_binary(pc->s, fp);
colloid_state_write_binary(&pc->s, fp);
pc = pc->next;
}

Expand Down
4 changes: 2 additions & 2 deletions src/colloids.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Edinburgh Soft Matter and Statistical Physics Group and
* Edinburgh Parallel Computing Centre
*
* (c) 2010-2018 The University of Edinburgh
* (c) 2010-2020 The University of Edinburgh
*
* Contributing authors:
* Kevin Stratford ([email protected])
Expand Down Expand Up @@ -1059,7 +1059,7 @@ __host__ int colloids_info_position_update(colloids_info_t * cinfo) {
if (ifail == 1) {
pe_verbose(cinfo->pe, "Colloid velocity exceeded max %14.7e\n",
cinfo->drmax);
colloid_state_write_ascii(coll->s, stdout);
colloid_state_write_ascii(&coll->s, stdout);
pe_fatal(cinfo->pe, "Stopping\n");
}
}
Expand Down
Loading

0 comments on commit f3f22de

Please sign in to comment.