mdcore  0.1.5
Defines | Functions | Variables
/home/pedro/work/mdcore/src/space.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <alloca.h>
#include <pthread.h>
#include <math.h>
#include "../config.h"
#include <omp.h>
#include "errs.h"
#include "fptype.h"
#include "lock.h"
#include "part.h"
#include "cell.h"
#include "fifo.h"
#include "space.h"

Defines

#define error(id)   ( space_err = errs_register( id , space_err_msg[-(id)] , __LINE__ , __FUNCTION__ , __FILE__ ) )

Functions

int space_pairs_sort (struct space *s)
 Sort the cell pairs in a space according to their direction.
int space_verlet_force (struct space *s, FPTYPE *f, double epot)
 Collect forces and potential energies.
int space_verlet_get (struct space *s, int maxcount, int *from)
 Get a chunk of Verlet list entries.
int space_verlet_init (struct space *s, int list_global)
 Initialize the Verlet-list data structures.
int space_flush_ghosts (struct space *s)
 Clear all particles from the ghost cells in this space.
int space_flush (struct space *s)
 Clear all particles from this space.
int space_getcell (struct space *s, struct cell **out)
 Get the next unprocessed cell from the spaece.
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_maketuples (struct space *s)
 Generate the list of celltuple.
int space_prepare (struct space *s)
 Prepare the space before a time step.
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_getpos (struct space *s, int id, double *x)
 Get the absolute position of a particle.
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.
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_init (struct space *s, const double *origin, const double *dim, double *L, double cutoff, unsigned int period)
 Initialize the space with the given dimensions.

Variables

int space_err = space_err_ok
char * space_err_msg [7]

Define Documentation

#define error (   id)    ( space_err = errs_register( id , space_err_msg[-(id)] , __LINE__ , __FUNCTION__ , __FILE__ ) )

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_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

ID of the last error

char* space_err_msg[7]
Initial value:
 {
        "Nothing bad happened.",
    "An unexpected NULL pointer was encountered.",
    "A call to malloc failed, probably due to insufficient memory.",
    "An error occured when calling a cell function.",
    "A call to a pthread routine failed.",
    "One or more values were outside of the allowed range.",
    "Too many pairs associated with a single particle in Verlet list.",
        }
 All Data Structures Files Functions Variables Typedefs Enumerator Defines