ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/math/randomSPRNG.cpp
Revision: 1725
Committed: Wed Nov 10 22:01:06 2004 UTC (19 years, 8 months ago) by tim
File size: 1320 byte(s)
Log Message:
another painful day
(1) SimCreator, SimInfo, mpiSimulation
(2) DumpReader, DumpWriter (InitializeFrom File will be removed)
(3) ForceField (at least LJ) and BondType, BendType, TorsionType
(4)Integrator
(5)oopse.cpp
(6)visitors & Dump2XYZ
(7)SimpleBuilder
(8)Constraint & ZConstraint

File Contents

# Content
1 #include <iostream>
2 #include <math.h>
3
4 #include "math/randomSPRNG.hpp"
5 #include "utils/simError.h"
6 #include <sprng.h>
7
8 #ifdef IS_MPI
9
10 #include <mpi.h>
11 #endif
12
13 using namespace std;
14
15 /* randomStreamSPRNF creates a new SPRNG stream for random numbers
16 */
17
18 int randomSPRNG::nStreamsInitialized = 0;
19
20 randomSPRNG::randomSPRNG( int iseed ) {
21 int newSeed;
22 nStreamsInitialized++;
23 newSeed = abs(iseed) + nStreamsInitialized;
24
25 if (newSeed < 0)
26 newSeed = abs(newSeed);
27
28 #ifdef IS_MPI
29
30 //random number generator should not depend on MpiSimulation
31 MPI_Comm_size(MPI_COMM_WORLD, &nSPRNGStreams);
32 myStreamNumber = worldRank;
33
34 #else
35
36 nSPRNGStreams = 1;
37 myStreamNumber = 0;
38
39 #endif
40
41 thisStream = init_sprng(GTYPE, myStreamNumber, nSPRNGStreams, newSeed,
42 SPRNG_DEFAULT);
43 }
44
45 randomSPRNG::~randomSPRNG() {
46 if (thisStream != NULL) {
47 free_sprng(thisStream);
48 nStreamsInitialized--;
49 }
50 }
51
52 double randomSPRNG::getRandom() { return sprng(thisStream); }
53
54 // Gaussian SPRNG class...
55
56 double gaussianSPRNG::getGaussian() {
57 double ranNum1;
58 double ranNum2;
59 double gaussianNumber;
60
61 ranNum1 = getRandom();
62 ranNum2 = getRandom();
63
64 gaussianNumber = sqrt(-2.0 * log(ranNum1)) * cos(2 * M_PI * ranNum2);
65
66 return gaussianNumber;
67 }