![]() |
ESPResSo 3.2.0-167-g2c9ead1-git
Extensible Simulation Package for Soft Matter Research
|
00001 /* 00002 Copyright (C) 2010,2011,2012,2013 The ESPResSo project 00003 Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 00004 Max-Planck-Institute for Polymer Research, Theory Group 00005 00006 This file is part of ESPResSo. 00007 00008 ESPResSo is free software: you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation, either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 ESPResSo is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 */ 00021 #ifndef _CELLS_H 00022 #define _CELLS_H 00023 /** \file cells.h 00024 This file contains everything related to the cell structure / cell 00025 system. 00026 00027 The cell system (\ref Cell Structure) describes how particles are 00028 distributed on the cells and how particles of different cells 00029 (regardless if they reside on the same or different nodes) 00030 interact with each other. The following cell systems are implemented: 00031 00032 <ul> 00033 <li> domain decomposition: The simulation box is divided spatially 00034 ino cells (see \ref domain_decomposition.h). This is suitable for 00035 short range interctions. 00036 <li> nsquare: The particles are distributed equally on all nodes 00037 regardless their spatial position (see \ref nsquare.h). This is 00038 suitable for long range interactions that can not be treated by a 00039 special method like P3M (see \ref p3m.h). 00040 <li> layered: in x and y directions, it uses a nsquared type of interaction calculation, 00041 but in z it has a domain decomposition into layers. 00042 </ul> 00043 00044 One can switch between different cell systems with the tcl command 00045 cellsystem implemented in \ref cells.c . 00046 00047 Some structures are common to all cell systems: 00048 00049 <ul> 00050 <li> All cells, real cells as well as ghost cells, are stored in the array \ref cells::cells with size \ref 00051 n_cells. The size of this array has to be changed with \ref realloc_cells. 00052 <li> Their are two lists of cell pointers to acces particles and 00053 ghost particles on a node: \ref local_cells contains pointers to 00054 all cells containing the particles physically residing on that 00055 node. \ref ghost_cells contains pointers to all cells containing 00056 the ghost particles of that node. The size of these lists has to be 00057 changed with \ref realloc_cellplist 00058 <li> An example using the cell pointer lists to access particle data 00059 can be found in the function \ref 00060 print_local_particle_positions. DO NOT INVENT YOUR OWN WAY!!! 00061 </ul> 00062 */ 00063 00064 #include "particle_data.h" 00065 #include "ghosts.h" 00066 #include "verlet.h" 00067 00068 /** \name Cell Structure */ 00069 /** Flag telling which cell structure is used at the moment. */ 00070 /*@{*/ 00071 /** Flag indicating that there is no cell system yet. Only at the 00072 VERY beginning of the code startup. */ 00073 #define CELL_STRUCTURE_NONEYET -1 00074 /** Flag indicating that the current cell structure will be used furthor on */ 00075 #define CELL_STRUCTURE_CURRENT 0 00076 /** cell structure domain decomposition */ 00077 #define CELL_STRUCTURE_DOMDEC 1 00078 /** cell structure n square */ 00079 #define CELL_STRUCTURE_NSQUARE 2 00080 /** cell structure layered */ 00081 #define CELL_STRUCTURE_LAYERED 3 00082 /*@}*/ 00083 00084 /** \name Flags for exchange_and_sort_particles: wether to do a global exchange 00085 or assume that particles did not move much (faster, used during integration, 00086 where moving far is a catastrophe anyways). */ 00087 /*@{*/ 00088 00089 /** Flag for exchange_and_sort_particles : Do global exchange. */ 00090 #define CELL_GLOBAL_EXCHANGE 1 00091 /** Flag for exchange_and_sort_particles : Do neighbor exchange. */ 00092 #define CELL_NEIGHBOR_EXCHANGE 0 00093 00094 /** \name Flags for cells_on_geometry_change */ 00095 /*@{*/ 00096 00097 /** Flag for cells_on_geometry_change: the processor grid has changed. */ 00098 #define CELL_FLAG_GRIDCHANGED 1 00099 /** Flag for cells_on_geometry_change: skip shrinking of cells. */ 00100 #define CELL_FLAG_FAST 2 00101 00102 /*@}*/ 00103 00104 00105 /************************************************/ 00106 /** \name Data Types */ 00107 /************************************************/ 00108 /*@{*/ 00109 00110 /** A cell is a \ref ParticleList representing a particle group with 00111 respect to the integration algorithm. 00112 */ 00113 typedef ParticleList Cell; 00114 00115 /** List of cell pointers. */ 00116 typedef struct { 00117 Cell **cell; 00118 int n; 00119 int max; 00120 } CellPList; 00121 00122 /** Describes a cell structure / cell system. Contains information 00123 about the communication of cell contents (particles, ghosts, ...) 00124 between different nodes and the relation between particle 00125 positions and the cell system. All other properties of the cell 00126 system which are not common between different cell systems have to 00127 be stored in seperate structures. */ 00128 typedef struct { 00129 /** type descriptor */ 00130 int type; 00131 00132 /** Communicator to exchange ghost cell information. */ 00133 GhostCommunicator ghost_cells_comm; 00134 /** Communicator to exchange ghost particles. */ 00135 GhostCommunicator exchange_ghosts_comm; 00136 /** Communicator to update ghost positions. */ 00137 GhostCommunicator update_ghost_pos_comm; 00138 /** Communicator to collect ghost forces. */ 00139 GhostCommunicator collect_ghost_force_comm; 00140 #ifdef LB 00141 /** Communicator for particle data used by lattice Boltzmann */ 00142 GhostCommunicator ghost_lbcoupling_comm; 00143 #endif 00144 00145 /** Cell system dependent function to find the right node for a 00146 particle at position pos. 00147 \param pos Position of a particle. 00148 \return number of the node where to put the particle. 00149 */ 00150 int (*position_to_node)(double pos[3]); 00151 /** Cell system dependent function to find the right cell for a 00152 particle at position pos. 00153 \param pos Position of a particle. 00154 \return pointer to cell where to put the particle. 00155 */ 00156 Cell *(*position_to_cell)(double pos[3]); 00157 } CellStructure; 00158 00159 /*@}*/ 00160 00161 /************************************************************/ 00162 /** \name Exported Variables */ 00163 /************************************************************/ 00164 /*@{*/ 00165 00166 /** list of all cells. */ 00167 extern Cell *cells; 00168 /** size of \ref cells::cells */ 00169 extern int n_cells; 00170 /** list of all cells containing particles physically on the local 00171 node */ 00172 extern CellPList local_cells; 00173 /** list of all cells containing ghosts */ 00174 extern CellPList ghost_cells; 00175 00176 /** Type of cell structure in use ( \ref Cell Structure ). */ 00177 extern CellStructure cell_structure; 00178 00179 /** Maximal interaction range - also the minimum cell size. Any 00180 cellsystem makes sure that the particle pair loop visits all pairs 00181 of particles that are closer than this. */ 00182 extern double max_range; 00183 00184 /** If non-zero, cell systems should reset the position for checking 00185 the Verlet criterion. Moreover, the Verlet list has to be 00186 rebuilt. */ 00187 extern int rebuild_verletlist; 00188 00189 /*@}*/ 00190 00191 /************************************************************/ 00192 /** \name Exported Functions */ 00193 /************************************************************/ 00194 /*@{*/ 00195 00196 /** Reinitialize the cell structures. 00197 @param new_cs gives the new topology to use afterwards. May be set to 00198 \ref CELL_STRUCTURE_CURRENT for not changing it. 00199 */ 00200 void cells_re_init(int new_cs); 00201 00202 /** Reallocate the list of all cells (\ref cells::cells). */ 00203 void realloc_cells(int size); 00204 00205 /** Initialize a list of cell pointers */ 00206 MDINLINE void init_cellplist(CellPList *cpl) { 00207 cpl->n = 0; 00208 cpl->max = 0; 00209 cpl->cell = NULL; 00210 } 00211 00212 /** Reallocate a list of cell pointers */ 00213 MDINLINE void realloc_cellplist(CellPList *cpl, int size) 00214 { 00215 if(size != cpl->max) { 00216 cpl->max = size; 00217 cpl->cell = (Cell **) realloc(cpl->cell, sizeof(Cell *)*cpl->max); 00218 } 00219 } 00220 00221 /** sort the particles into the cells and initialize the ghost particle structures. 00222 @param global_flag if this is CELLS_GLOBAL_EXCHANGE, particle positions can have changed 00223 arbitrarly, otherwise the change should have been smaller then skin. */ 00224 void cells_resort_particles(int global_flag); 00225 00226 /** this function is called whenever the cell system has to be 00227 reinitialized, e.g. if cutoffs have changed, or the skin, grid, 00228 .... It calculates the maximal interaction range, and 00229 as said reinitializes the cells structure if something significant 00230 has changed. 00231 00232 If bit CELL_FLAG_FAST is set, the routine should try to save time. 00233 Currently this means that if the maximal range decreased, it does 00234 not reorganize the particles. This is used in the NpT algorithm to 00235 avoid frequent reorganizaion of particles. 00236 00237 If bit CELL_FLAG_GRIDCHANGED is set, it means the nodes' topology 00238 has changed, i. e. the grid or periodicity. In this case a full 00239 reorganization is due. 00240 00241 @param flags a combination of CELL_FLAG_GRIDCHANGED and 00242 CELL_FLAG_FAST, see above. 00243 00244 */ 00245 void cells_on_geometry_change(int flags); 00246 00247 /** update ghost information. If \ref resort_particles == 1, 00248 also a resorting of the particles takes place. */ 00249 void cells_update_ghosts(); 00250 00251 /** Calculate and return the total number of particles on this 00252 node. */ 00253 int cells_get_n_particles(); 00254 00255 /** Debug function to print particle positions. */ 00256 void print_local_particle_positions(); 00257 00258 /** Debug function to print ghost positions. */ 00259 void print_ghost_positions(); 00260 00261 /** spread the particle resorting criterion across the nodes. */ 00262 void announce_resort_particles(); 00263 00264 /* Checks if a particle resorting is required.*/ 00265 void check_resort_particles(); 00266 /*@}*/ 00267 00268 #endif
1.7.5.1