All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ExchangePatterns.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 The plumed team
3  (see the PEOPLE file at the root of the distribution for a list of names)
4 
5  See http://www.plumed-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
8 
9  plumed is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  plumed is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 #include "ExchangePatterns.h"
23 #include "tools/Random.h"
24 
25 using namespace std;
26 
27 namespace PLMD{
28 
29 ExchangePatterns::ExchangePatterns():
30  PatternFlag(NONE),
31  NumberOfReplicas(1),
32  random(*new Random)
33 {}
34 
36 {
37  delete &random;
38 }
39 
40 void ExchangePatterns::setNofR(const int nrepl){
41  NumberOfReplicas=nrepl;
42 }
43 
44 void ExchangePatterns::setFlag(const int flag){
45  PatternFlag=flag;
46 }
47 
48 void ExchangePatterns::getFlag(int &flag){
49  flag=PatternFlag;
50 }
51 
52 void ExchangePatterns::setSeed(const int seed)
53 {
54  random.setSeed(seed);
55 }
56 
58 {
59  switch(PatternFlag)
60  {
61  case RANDOM:
62  for(int i=0;i<NumberOfReplicas;i++) {
63  int stat=1;
64  while(stat) {
65  stat=0;
66  ind[i] = (int) (random.U01()*NumberOfReplicas);
67  for(int j=0;j<i;j++) if(ind[i]==ind[j]) stat=1;
68  }
69  }
70  break;
71  case NEIGHBOR:
72  for(int i=0;i<NumberOfReplicas;i++) ind[i]=i;
73  break;
74  }
75 }
76 
77 }
STL namespace.
double U01()
Definition: Random.cpp:74
void setSeed(int idum)
Definition: Random.cpp:51