Main Page | Class List | File List | Class Members | File Members

mgrid.h

Go to the documentation of this file.
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_LOWDEG1,
00201     MGRID_LOWDEG2,
00202     MGRID_LOWDEG3,
00203     MGRID_LOWDEG4,
00204     MGRID_LOWDEG5,
00205     MGRID_LOWDEG6,
00206     MGRID_LOWDEG7,
00207     MGRID_LOWDEG8,
00208     MGRID_LOWALT5_1,
00209     MGRID_LOWALT6_1,
00210     MGRID_LOWALT7_1,
00211     MGRID_LOWALT8_1,
00212     MGRID_LOWALT8_2,
00213     MGRID_EXSFPC2,
00216     MGRID_EXSFPQ2,
00219     MGRID_EXSFRC2,
00222     MGRID_EXSFRQ2,
00225     MGRID_EXACT3,
00226     MGRID_EXACT2,
00227     MGRID_EXACT1,
00228     MGRID_EXACT0,
00229     MGRID_SPLIT_END
00230   };
00231 
00232 
00258   typedef struct MgridParam_tag {
00259     MD_Dvec center;  
00260     double length;   
00261     double cutoff;   
00262     double spacing;  
00263     int32 nspacings; 
00265     int32 nlevels;   
00266     int32 boundary;  
00267     int32 natoms;    
00268     int32 approx;    
00269     int32 split;     
00270   } MgridParam;
00271 
00272 
00273   /* compute forces using system data */
00307   typedef struct MgridSystem_tag {
00308 
00309   /* output, user supplies arrays */
00310     double u_elec;
00312     double u_short;
00314     double u_long;
00316     MD_Dvec *f_elec;
00318     MD_Dvec *f_short;
00321     MD_Dvec *f_long;
00325   /* input */
00326     MD_Dvec *pos;
00328     double *charge;
00332   /* input, have mgrid process exclusions */
00333     int32 **excl_list;
00337     int32 **scaled14_list;
00341     double scaling14;
00345   } MgridSystem;
00346 
00347 
00348   /* contents opaque to user */
00353   typedef struct Mgrid_tag {
00354     MgridParam param;     /* copy user parameters */
00355 
00356 
00359     int (*short_force)(struct Mgrid_tag *, MgridSystem *);
00360       /* short range force evaluation "virtual" method */
00361 
00362     void (*short_done)(struct Mgrid_tag *);
00363       /* short range destructor "virtual" method */
00364 
00365     MD_Dvec lo;           /* lowest corner of grid cell lattice */
00366     double inv_cellsize;  /* inv_cellsize=(1/cellsize) */
00367     double inv_cutoff;    /* inv_cutoff=(1/cutoff) */
00368 
00369     int32 *next;          /* next "pointer" for cursor linked list */
00370       /* length is natoms, points to next atom within this grid cell */
00371 
00372     MgridCell *cell;      /* lattice of grid cells */
00373     int32 ncells;         /* total number of grid cells */
00374     int32 ndimcells;      /* number of grid cells in each dimension */
00375       /* (ncells == ndimcells * ndimcells * ndimcells) */
00376 
00377     int32 is_split_even_powers;
00378       /* splitting has even powers of r/a, for choosing evaluation routine */
00379 
00380     int (*cell_interactions)(struct Mgrid_tag *, MgridSystem *);
00381       /* evaluation routine for short range part */
00382 
00383 
00384     /*** long range force contribution ***/
00385 
00386     int (*long_force)(struct Mgrid_tag *, MgridSystem *);
00387       /* long range force evaluation "virtual" method */
00388 
00389     void (*long_done)(struct Mgrid_tag *);
00390       /* long range destructor "virtual" method */
00391 
00392     MD_Dvec origin;       /* lowest corner of domain, (0,0,0) of lattice */
00393     double inv_spacing;   /* 1/h, where h = lattice spacing */
00394     double u_self;        /* self potential */
00395     double g_zero;        /* smoothing g(r) evaluated at r=0 */
00396 
00397     MgridLattice *qgrid;  /* array of lattice of charge, length nlevels */
00398 
00399     MgridLattice *egrid;  /* array of lattice of potential, length nlevels */
00400 
00401     /* for interpolation schemes using only function values */
00402     double *scaling;      /* array of scaling for direct sum, length nlevels */
00403 
00404     MgridLattice gdsum;   /* direct sum weights for lattice cutoff parts */
00405     int32 gdsum_radius;   /* radius of lattice point "sphere" */
00406 
00407     MgridLattice glast;   /* last level direct sum weights */
00408     int32 glast_radius;   /* radius of lattice point "sphere" */
00409 
00410     /* for interpolation schemes using function values and derivatives */
00411     MgridLattice *gdsum_list;  /* direct sum weights, for each level */
00412     int32 *gdsum_radius_list;  /* radius of "sphere", for each level */
00413 
00414     /* for interpolation schemes using function values and derivatives */
00415     MgridLattice *opres_list;  /* restriction operator, indexed by level */
00416     MgridLattice *oppro_list;  /* prolongation operator, indexed by level */
00417 
00418     /* for interpolation schemes using function values and derivatives */
00419     MgridLattice *is_zero;     /* flag telling if matrix is all zeros */
00420 
00421   } Mgrid;
00422 
00423 
00424   /* help user choose suitable params */
00425 
00460   int mgrid_param_config(MgridParam *p);
00461 
00462 
00463   /* convert between types and strings */
00464 
00472   int mgrid_string_to_boundary(const char *);
00473 
00481   const char *mgrid_boundary_to_string(int);
00482 
00491   int mgrid_string_to_approx(const char *);
00492 
00500   const char *mgrid_approx_to_string(int);
00501 
00510   int mgrid_string_to_split(const char *);
00511 
00519   const char *mgrid_split_to_string(int);
00520 
00521 
00522   /* methods for Mgrid */
00523 
00531   int mgrid_init(Mgrid *);
00532 
00550   int mgrid_setup(Mgrid *, const MgridSystem *s, const MgridParam *p);
00551 
00565   int mgrid_force(Mgrid *, MgridSystem *s);
00566 
00572   void mgrid_done(Mgrid *);
00573 
00574 
00575   /* validate atom positions within bounding cell */
00576 
00589   int mgrid_system_validate(const Mgrid *, const MgridSystem *s);
00590 
00591 
00592   /* compute exact smoothed part (for nonperiodic boundaries) */
00593 
00602   int mgrid_exact_smooth(Mgrid *, MgridSystem *s);
00603 
00604 
00605   /* internal methods for Mgrid */
00606   int mgrid_short_setup(Mgrid *);
00607   int mgrid_ncubic_setup(Mgrid *, const MgridSystem *);
00608   int mgrid_pcubic_setup(Mgrid *, const MgridSystem *);
00609   int mgrid_nbspline_setup(Mgrid *, const MgridSystem *);
00610   int mgrid_pbspline_setup(Mgrid *, const MgridSystem *);
00611   int mgrid_nquintic1_setup(Mgrid *, const MgridSystem *);
00612   int mgrid_pquintic1_setup(Mgrid *, const MgridSystem *);
00613   int mgrid_nquintic2_setup(Mgrid *, const MgridSystem *);
00614   int mgrid_pquintic2_setup(Mgrid *, const MgridSystem *);
00615   int mgrid_nheptic1_setup(Mgrid *, const MgridSystem *);
00616   int mgrid_pheptic1_setup(Mgrid *, const MgridSystem *);
00617   int mgrid_nheptic3_setup(Mgrid *, const MgridSystem *);
00618   int mgrid_pheptic3_setup(Mgrid *, const MgridSystem *);
00619   int mgrid_nnonic1_setup(Mgrid *, const MgridSystem *);
00620   int mgrid_pnonic1_setup(Mgrid *, const MgridSystem *);
00621   int mgrid_nnonic4_setup(Mgrid *, const MgridSystem *);
00622   int mgrid_pnonic4_setup(Mgrid *, const MgridSystem *);
00623   int mgrid_nhermite_setup(Mgrid *, const MgridSystem *);
00624   int mgrid_phermite_setup(Mgrid *, const MgridSystem *);
00625   int mgrid_setup_longrange(Mgrid *, const MgridSystem *);
00626 
00627 #ifdef __cplusplus
00628 }
00629 #endif
00630 
00631 #endif /* MGRID_H */

Generated on Thu Feb 7 18:11:40 2008 for MDX by  doxygen 1.3.9.1