git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@622 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp
2007-06-20 13:17:59 +00:00
parent bde732bced
commit aaed6ebc33
131 changed files with 4277 additions and 2222 deletions

View File

@ -15,6 +15,8 @@
#include "math.h"
#include "random_park.h"
#include "domain.h"
#include "error.h"
using namespace LAMMPS_NS;
@ -24,10 +26,21 @@ using namespace LAMMPS_NS;
#define IQ 127773
#define IR 2836
#define IA1 1366
#define IC1 150889
#define IM1 714025
#define IA2 8121
#define IC2 28411
#define IM2 134456
#define IA3 7141
#define IC3 54773
#define IM3 259200
/* ---------------------------------------------------------------------- */
RanPark::RanPark(LAMMPS *lmp, int seed_init) : Pointers(lmp)
{
if (seed_init == 0) error->all("Invalid seed for Park random # generator");
seed = seed_init;
save = 0;
}
@ -73,11 +86,52 @@ double RanPark::gaussian()
}
/* ----------------------------------------------------------------------
reset the seed to a fractional (0-1) value of the total IM
reset the seed based on atom position within box and ibase = caller seed
combine 3 RNGs based on fractional position in box into one new seed
------------------------------------------------------------------------- */
void RanPark::reset(double fraction)
void RanPark::reset(int ibase, double *coord)
{
// for orthogonal box, lamda = fractional position in box
// for triclinic box, convert to lamda coords
double lamda[3];
if (domain->triclinic == 0) {
lamda[0] = (coord[0] - domain->boxlo[0]) / domain->prd[0];
lamda[1] = (coord[1] - domain->boxlo[1]) / domain->prd[1];
lamda[2] = (coord[2] - domain->boxlo[2]) / domain->prd[2];
} else domain->x2lamda(coord,lamda);
// seed 1,2,3 = combination of atom coord in each dim and user-input seed
// map geometric extent into range of each of 3 RNGs
// warm-up each RNG by calling it twice
int seed1,seed2,seed3;
seed1 = static_cast<int> (lamda[0] * IM1);
seed1 = (seed1+ibase) % IM1;
seed1 = (seed1*IA1+IC1) % IM1;
seed1 = (seed1*IA1+IC1) % IM1;
seed2 = static_cast<int> (lamda[1] * IM2);
seed2 = (seed2+ibase) % IM2;
seed2 = (seed2*IA2+IC2) % IM2;
seed2 = (seed2*IA2+IC2) % IM2;
seed3 = static_cast<int> (lamda[2] * IM3);
seed3 = (seed3+ibase) % IM3;
seed3 = (seed3*IA3+IC3) % IM3;
seed3 = (seed3*IA3+IC3) % IM3;
// fraction = 0-1 with giving each dim an equal weighting
// use fraction to reset Park/Miller RNG seed
// warm-up master RNG with new seed by calling it twice
double fraction = 1.0*seed1/(3*IM1) + 1.0*seed2/(3*IM2) + 1.0*seed3/(3*IM3);
seed = static_cast<int> (fraction*IM) + 1;
if (seed >= IM) seed = IM-1;
uniform();
uniform();
}