00001 /* 00002 * Copyright (C) 2004-2005 by David J. Hardy. All rights reserved. 00003 */ 00004 00040 #ifndef MGRID_H 00041 #define MGRID_H 00042 00043 #include "mdapi/mdtypes.h" 00044 #include "mgrid/lattice.h" 00045 00046 #ifdef __cplusplus 00047 extern "C" { 00048 #endif 00049 00050 /**************************************************************************** 00051 * internal definitions 00052 ****************************************************************************/ 00053 00056 typedef struct MgridCell_tag { 00057 /* cells for geometric hashing, implement as cursor linked list */ 00058 int32 head; /* index of first atom in this cell */ 00059 int32 cnt; /* count number of atoms in this cell */ 00060 int32 nnbrs; /* length of neighbor cell list */ 00061 int32 nbr[14]; /* up to half-shell of neighbors, including self */ 00062 MD_Dvec offset[14]; /* offset for neighbors that are periodic images */ 00063 } MgridCell; 00064 00065 00066 /**************************************************************************** 00067 * user interface 00068 ****************************************************************************/ 00069 00070 /* error return value */ 00071 enum { 00072 MGRID_FAIL = -1 00073 }; 00074 00075 00076 /* boundary */ 00081 enum MgridBoundary_tag { 00082 MGRID_BOUNDARY_BEGIN = 0, 00083 MGRID_PERIODIC, 00084 MGRID_NONPERIODIC, 00085 MGRID_BOUNDARY_END 00086 }; 00087 00088 00089 /* choice of grid approximation */ 00095 enum MgridApprox_tag { 00096 MGRID_APPROX_BEGIN = 0, 00097 MGRID_CUBIC, 00099 MGRID_BSPLINE, 00101 MGRID_QUINTIC1, 00103 MGRID_QUINTIC2, 00105 MGRID_HEPTIC1, 00108 MGRID_HEPTIC3, 00111 MGRID_NONIC1, 00114 MGRID_NONIC4, 00117 MGRID_HERMITE, 00119 MGRID_APPROX_END 00120 }; 00121 00122 00123 /* choice of splitting */ 00129 enum MgridSplit_tag { 00130 MGRID_SPLIT_BEGIN = 0, 00131 MGRID_TAYLOR1, 00134 MGRID_TAYLOR2, 00137 MGRID_TAYLOR3, 00140 MGRID_TAYLOR4, 00143 MGRID_TAYLOR5, 00146 MGRID_TAYLOR6, 00149 MGRID_TAYLOR7, 00152 MGRID_TAYLOR8, 00155 MGRID_ERRMIN3, 00159 MGRID_EXSELF1, 00163 MGRID_EXSELF2, 00167 MGRID_EXSELF3, 00171 MGRID_EXSELF7, 00176 MGRID_ODDPR1, 00179 MGRID_ODDPR2, 00182 MGRID_ODDPR3, 00185 MGRID_ODDPR4, 00188 MGRID_ODDPR5, 00191 MGRID_ODDPR6, 00194 MGRID_ODDPR7, 00197 MGRID_ODDPR8, 00200 MGRID_SPLIT_END 00201 }; 00202 00203 00229 typedef struct MgridParam_tag { 00230 MD_Dvec center; 00231 double length; 00232 double cutoff; 00233 double spacing; 00234 int32 nspacings; 00236 int32 nlevels; 00237 int32 boundary; 00238 int32 natoms; 00239 int32 approx; 00240 int32 split; 00241 } MgridParam; 00242 00243 00244 /* compute forces using system data */ 00278 typedef struct MgridSystem_tag { 00279 00280 /* output, user supplies arrays */ 00281 double u_elec; 00283 double u_short; 00285 double u_long; 00287 MD_Dvec *f_elec; 00289 MD_Dvec *f_short; 00292 MD_Dvec *f_long; 00296 /* input */ 00297 MD_Dvec *pos; 00299 double *charge; 00303 /* input, have mgrid process exclusions */ 00304 int32 **excl_list; 00308 int32 **scaled14_list; 00312 double scaling14; 00316 } MgridSystem; 00317 00318 00319 /* contents opaque to user */ 00324 typedef struct Mgrid_tag { 00325 MgridParam param; /* copy user parameters */ 00326 00327 00330 int (*short_force)(struct Mgrid_tag *, MgridSystem *); 00331 /* short range force evaluation "virtual" method */ 00332 00333 void (*short_done)(struct Mgrid_tag *); 00334 /* short range destructor "virtual" method */ 00335 00336 MD_Dvec lo; /* lowest corner of grid cell lattice */ 00337 double inv_cellsize; /* inv_cellsize=(1/cellsize) */ 00338 double inv_cutoff; /* inv_cutoff=(1/cutoff) */ 00339 00340 int32 *next; /* next "pointer" for cursor linked list */ 00341 /* length is natoms, points to next atom within this grid cell */ 00342 00343 MgridCell *cell; /* lattice of grid cells */ 00344 int32 ncells; /* total number of grid cells */ 00345 int32 ndimcells; /* number of grid cells in each dimension */ 00346 /* (ncells == ndimcells * ndimcells * ndimcells) */ 00347 00348 int32 is_split_even_powers; 00349 /* splitting has even powers of r/a, for choosing evaluation routine */ 00350 00351 int (*cell_interactions)(struct Mgrid_tag *, MgridSystem *); 00352 /* evaluation routine for short range part */ 00353 00354 00355 /*** long range force contribution ***/ 00356 00357 int (*long_force)(struct Mgrid_tag *, MgridSystem *); 00358 /* long range force evaluation "virtual" method */ 00359 00360 void (*long_done)(struct Mgrid_tag *); 00361 /* long range destructor "virtual" method */ 00362 00363 MD_Dvec origin; /* lowest corner of domain, (0,0,0) of lattice */ 00364 double inv_spacing; /* 1/h, where h = lattice spacing */ 00365 double u_self; /* self potential */ 00366 double g_zero; /* smoothing g(r) evaluated at r=0 */ 00367 00368 MgridLattice *qgrid; /* array of lattice of charge, length nlevels */ 00369 00370 MgridLattice *egrid; /* array of lattice of potential, length nlevels */ 00371 00372 /* for interpolation schemes using only function values */ 00373 double *scaling; /* array of scaling for direct sum, length nlevels */ 00374 00375 MgridLattice gdsum; /* direct sum weights for lattice cutoff parts */ 00376 int32 gdsum_radius; /* radius of lattice point "sphere" */ 00377 00378 MgridLattice glast; /* last level direct sum weights */ 00379 int32 glast_radius; /* radius of lattice point "sphere" */ 00380 00381 /* for interpolation schemes using function values and derivatives */ 00382 MgridLattice *gdsum_list; /* direct sum weights, for each level */ 00383 int32 *gdsum_radius_list; /* radius of "sphere", for each level */ 00384 00385 } Mgrid; 00386 00387 00388 /* help user choose suitable params */ 00389 00424 int mgrid_param_config(MgridParam *p); 00425 00426 00427 /* convert between types and strings */ 00428 00436 int mgrid_string_to_boundary(const char *); 00437 00445 const char *mgrid_boundary_to_string(int); 00446 00455 int mgrid_string_to_approx(const char *); 00456 00464 const char *mgrid_approx_to_string(int); 00465 00474 int mgrid_string_to_split(const char *); 00475 00483 const char *mgrid_split_to_string(int); 00484 00485 00486 /* methods for Mgrid */ 00487 00495 int mgrid_init(Mgrid *); 00496 00514 int mgrid_setup(Mgrid *, const MgridSystem *s, const MgridParam *p); 00515 00529 int mgrid_force(Mgrid *, MgridSystem *s); 00530 00536 void mgrid_done(Mgrid *); 00537 00538 00539 /* validate atom positions within bounding cell */ 00540 00553 int mgrid_system_validate(const Mgrid *, const MgridSystem *s); 00554 00555 00556 /* compute exact smoothed part (for nonperiodic boundaries) */ 00557 00566 int mgrid_exact_smooth(Mgrid *, MgridSystem *s); 00567 00568 00569 /* internal methods for Mgrid */ 00570 int mgrid_short_setup(Mgrid *); 00571 int mgrid_ncubic_setup(Mgrid *, const MgridSystem *); 00572 int mgrid_pcubic_setup(Mgrid *, const MgridSystem *); 00573 int mgrid_nbspline_setup(Mgrid *, const MgridSystem *); 00574 int mgrid_pbspline_setup(Mgrid *, const MgridSystem *); 00575 int mgrid_nquintic1_setup(Mgrid *, const MgridSystem *); 00576 int mgrid_pquintic1_setup(Mgrid *, const MgridSystem *); 00577 int mgrid_nquintic2_setup(Mgrid *, const MgridSystem *); 00578 int mgrid_pquintic2_setup(Mgrid *, const MgridSystem *); 00579 int mgrid_nheptic1_setup(Mgrid *, const MgridSystem *); 00580 int mgrid_pheptic1_setup(Mgrid *, const MgridSystem *); 00581 int mgrid_nheptic3_setup(Mgrid *, const MgridSystem *); 00582 int mgrid_pheptic3_setup(Mgrid *, const MgridSystem *); 00583 int mgrid_nnonic1_setup(Mgrid *, const MgridSystem *); 00584 int mgrid_pnonic1_setup(Mgrid *, const MgridSystem *); 00585 int mgrid_nnonic4_setup(Mgrid *, const MgridSystem *); 00586 int mgrid_pnonic4_setup(Mgrid *, const MgridSystem *); 00587 int mgrid_nhermite_setup(Mgrid *, const MgridSystem *); 00588 int mgrid_phermite_setup(Mgrid *, const MgridSystem *); 00589 int mgrid_setup_longrange(Mgrid *, const MgridSystem *); 00590 00591 #ifdef __cplusplus 00592 } 00593 #endif 00594 00595 #endif /* MGRID_H */