mdcore  0.1.5
Data Structures | Defines | Functions | Variables
/home/pedro/work/mdcore/src/space.h File Reference

Go to the source code of this file.

Data Structures

struct  space
struct  cellpair
struct  celltuple
struct  verlet_entry

Defines

#define space_err_ok   0
#define space_err_null   -1
#define space_err_malloc   -2
#define space_err_cell   -3
#define space_err_pthread   -4
#define space_err_range   -5
#define space_err_maxpairs   -6
#define space_periodic_none   0
#define space_periodic_x   1
#define space_periodic_y   2
#define space_periodic_z   4
#define space_periodic_full   7
#define space_periodic_ghost_x   8
#define space_periodic_ghost_y   16
#define space_periodic_ghost_z   32
#define space_periodic_ghost_full   56
#define space_partlist_incr   100
#define space_maxtuples   4
#define space_verlet_maxpairs   800
#define space_cellid(s, i, j, k)   ( ((i)*(s)->cdim[1] + (j)) * (s)->cdim[2] + (k) )
#define space_pairind(i, j)   ( space_maxtuples*(i) - (i)*((i)+1)/2 + (j) )

Functions

int space_init (struct space *s, const double *origin, const double *dim, double *L, double cutoff, unsigned int period)
 Initialize the space with the given dimensions.
struct cellpairspace_getpair (struct space *s, int owner, int count, struct cellpair *old, int *err, int wait)
 Get a set of cellpair from the space.
struct cellpairspace_getpair_spin (struct space *s, int owner, int count, struct cellpair *old, int *err, int wait)
int space_releasepair (struct space *s, int ci, int cj)
 Free the cells involved in the current pair.
int space_releasepair_spin (struct space *s, int ci, int cj)
 Free the cells involved in the current pair.
int space_shuffle (struct space *s)
 Run through the cells of a space and make sure every particle is in its place.
int space_shuffle_local (struct space *s)
 Run through the non-ghost cells of a space and make sure every particle is in its place.
int space_addpart (struct space *s, struct part *p, double *x)
 Add a part to a space at the given coordinates.
int space_pairs_sort (struct space *s)
 Sort the cell pairs in a space according to their direction.
int space_prepare (struct space *s)
 Prepare the space before a time step.
int space_maketuples (struct space *s)
 Generate the list of celltuple.
int space_gettuple (struct space *s, struct celltuple **out, int wait)
 Get the next free celltuple from the space.
int space_gettuple_spin (struct space *s, struct celltuple **out, int wait)
 Get the next free celltuple from the space.
int space_getpos (struct space *s, int id, double *x)
 Get the absolute position of a particle.
int space_setpos (struct space *s, int id, double *x)
int space_flush (struct space *s)
 Clear all particles from this space.
int space_verlet_init (struct space *s, int list_global)
 Initialize the Verlet-list data structures.
int space_verlet_get (struct space *s, int maxcount, int *from)
 Get a chunk of Verlet list entries.
int space_verlet_force (struct space *s, FPTYPE *f, double epot)
 Collect forces and potential energies.
int space_flush_ghosts (struct space *s)
 Clear all particles from the ghost cells in this space.
int space_getcell (struct space *s, struct cell **out)
 Get the next unprocessed cell from the spaece.

Variables

int space_err

Define Documentation

#define space_cellid (   s,
  i,
  j,
 
)    ( ((i)*(s)->cdim[1] + (j)) * (s)->cdim[2] + (k) )

Converts the index triplet (i, j, k) to the cell id in the space s.

#define space_err_cell   -3
#define space_err_malloc   -2
#define space_err_maxpairs   -6
#define space_err_null   -1
#define space_err_ok   0
#define space_err_pthread   -4
#define space_err_range   -5
#define space_maxtuples   4

Maximum number of cells per tuple.

#define space_pairind (   i,
 
)    ( space_maxtuples*(i) - (i)*((i)+1)/2 + (j) )

Convert tuple ids into the pairid index.

#define space_partlist_incr   100
#define space_periodic_full   7
#define space_periodic_ghost_full   56
#define space_periodic_ghost_x   8
#define space_periodic_ghost_y   16
#define space_periodic_ghost_z   32
#define space_periodic_none   0
#define space_periodic_x   1
#define space_periodic_y   2
#define space_periodic_z   4
#define space_verlet_maxpairs   800

Maximum number of interactions per particle in the Verlet list.


Function Documentation

int space_addpart ( struct space s,
struct part p,
double *  x 
)

Add a part to a space at the given coordinates.

Parameters:
sThe space to which p should be added.
pThe part to be added.
xA pointer to an array of three doubles containing the particle position.
Returns:
space_err_ok or < 0 on error (see space_err).

Inserts a part p into the space s at the position x. Note that since particle positions in part are relative to the cell, that data in p is overwritten and x is used.

int space_flush ( struct space s)

Clear all particles from this space.

Parameters:
sThe space to flush.
Returns:
space_err_ok or < 0 on error (see space_err).
int space_flush_ghosts ( struct space s)

Clear all particles from the ghost cells in this space.

Parameters:
sThe space to flush.
Returns:
space_err_ok or < 0 on error (see space_err).
int space_getcell ( struct space s,
struct cell **  out 
)

Get the next unprocessed cell from the spaece.

Parameters:
sThe space.
outPointer to a pointer to cell in which to store the results.
Returns:
1 if a cell was found, space_err_ok if the list is empty or < 0 on error (see space_err).
struct cellpair* space_getpair ( struct space s,
int  owner,
int  count,
struct cellpair old,
int *  err,
int  wait 
) [read]

Get a set of cellpair from the space.

Parameters:
sThe space from which to get pairs.
ownerThe id of the calling runner.
countThe maximum number of cellpair to return.
oldA list of cellpair that have been processed and may be released, can also be NULL.
errA pointer to an integer in which to store the error code.
waitA boolean integer specifying if to wait or not if no pairs are available.
Returns:
A pointer to a linked list of cellpair. If none were available, NULL is returned. If an error occurs, NULL is returned and err is set to the respective error code.

The returned cellpair are linked through the field next. The value of next in the last cellpair is NULL.

The routine starts by blocking the cellpair_mutex of the space s and searches for available pairs in the space pair-list until either count pairs have been found or the list has been exhausted.

For each pair found, the space s counters in cells_taboo are incremented.

If no pairs are available and wait is not 0, the routines waits for a signal on the space s condition variable cellpairs_avail. If wait is 0 and no cellpair have been found, the routine returns NULL and sets err to 0.

If the last cellpair has been taken, the routine broadcasts a signal on the space s condition variable cellpairs_avail to release any other runners waiting for pairs.

struct cellpair* space_getpair_spin ( struct space s,
int  owner,
int  count,
struct cellpair old,
int *  err,
int  wait 
) [read]
int space_getpos ( struct space s,
int  id,
double *  x 
)

Get the absolute position of a particle.

Parameters:
sThe space in which the particle resides.
idThe local id of the part.
xA pointer to a vector of at least three doubles in which to store the particle position.
int space_gettuple ( struct space s,
struct celltuple **  out,
int  wait 
)

Get the next free celltuple from the space.

Parameters:
sThe space in which to look for tuples.
outA pointer to a celltuple in which to copy the result.
waitA boolean value specifying if to wait for free tuples or not.
Returns:
The number of celltuple found or 0 if the list is empty and < 0 on error (see space_err).
int space_gettuple_spin ( struct space s,
struct celltuple **  out,
int  wait 
)

Get the next free celltuple from the space.

Parameters:
sThe space in which to look for tuples.
outA pointer to a celltuple in which to copy the result.
waitA boolean value specifying if to wait for free tuples or not.
Returns:
The number of celltuple found or 0 if the list is empty and < 0 on error (see space_err).
int space_init ( struct space s,
const double *  origin,
const double *  dim,
double *  L,
double  cutoff,
unsigned int  period 
)

Initialize the space with the given dimensions.

Parameters:
sThe space to initialize.
originPointer to an array of three doubles specifying the origin of the rectangular domain.
dimPointer to an array of three doubles specifying the length of the rectangular domain along each dimension.
LThe minimum cell edge length, in each dimension.
cutoffA double-precision value containing the maximum cutoff lenght that will be used in the potentials.
periodUnsigned integer containing the flags space_periodic_x, space_periodic_y and/or space_periodic_z or space_periodic_full.
Returns:
space_err_ok or <0 on error (see space_err).

This routine initializes the fields of the space s, creates the cells and generates the cell-pair list.

int space_maketuples ( struct space s)

Generate the list of celltuple.

Parameters:
sPointer to the space to make tuples for.
Returns:
space_err_ok or < 0 on error (see space_err).
int space_pairs_sort ( struct space s)

Sort the cell pairs in a space according to their direction.

Parameters:
sThe space.
Returns:
engine_err_ok or < 0 on error (see space_err).
int space_prepare ( struct space s)

Prepare the space before a time step.

Parameters:
sA pointer to the space to prepare.
Returns:
space_err_ok or < 0 on error (see space_err)

Initializes a space for a single time step. This routine runs through the particles and sets their forces to zero.

int space_releasepair ( struct space s,
int  ci,
int  cj 
)

Free the cells involved in the current pair.

Parameters:
sThe space to operate on.
ciID of the first cell.
cjID of the second cell.
Returns:
space_err_ok or < 0 on error (see space_err).

Decreases the taboo-counter of the cells involved in the pair and signals any runner that might be waiting. Note that only a single waiting runner is released per released cell and therefore, if two different cells become free, the condition cellpairs_avail is signaled twice.

int space_releasepair_spin ( struct space s,
int  ci,
int  cj 
)

Free the cells involved in the current pair.

Parameters:
sThe space to operate on.
ciID of the first cell.
cjID of the second cell.
Returns:
space_err_ok or < 0 on error (see space_err).

Decreases the taboo-counter of the cells involved in the pair and signals any runner that might be waiting. Note that only a single waiting runner is released per released cell and therefore, if two different cells become free, the condition cellpairs_avail is signaled twice.

int space_setpos ( struct space s,
int  id,
double *  x 
)
int space_shuffle ( struct space s)

Run through the cells of a space and make sure every particle is in its place.

Parameters:
sThe space on which to operate.
Returns:
space_err_ok or < 0 on error.

Runs through the cells of s and if a particle has stepped outside the cell bounds, moves it to the correct cell.

int space_shuffle_local ( struct space s)

Run through the non-ghost cells of a space and make sure every particle is in its place.

Parameters:
sThe space on which to operate.
Returns:
space_err_ok or < 0 on error.

Runs through the cells of s and if a particle has stepped outside the cell bounds, moves it to the correct cell.

int space_verlet_force ( struct space s,
FPTYPE *  f,
double  epot 
)

Collect forces and potential energies.

Parameters:
sThe space.
maxcountThe maximum number of entries.
fromPointer to an integer which will contain the index to the first entry on success.
toPointer to an integer which will contain the index to the last entry on success.
Returns:
The number of entries returned or < 0 on error (see space_err).
int space_verlet_get ( struct space s,
int  maxcount,
int *  from 
)

Get a chunk of Verlet list entries.

Parameters:
sThe space.
maxcountThe maximum number of entries.
fromPointer to an integer which will contain the index to the first entry on success.
toPointer to an integer which will contain the index to the last entry on success.
Returns:
The number of entries returned or < 0 on error (see space_err).
int space_verlet_init ( struct space s,
int  list_global 
)

Initialize the Verlet-list data structures.

Parameters:
sThe space.
Returns:
space_err_ok or < 0 on error (see space_err).

Variable Documentation

int space_err

ID of the last error

 All Data Structures Files Functions Variables Typedefs Enumerator Defines