CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
OccLocation_test.cpp
Go to the documentation of this file.
1 #define BOOST_TEST_DYN_LINK
2 #include <boost/test/unit_test.hpp>
3 
6 
8 #include <boost/filesystem.hpp>
9 
10 #include "Common.hh"
12 #include "casm/external/MersenneTwister/MersenneTwister.h"
16 
17 using namespace CASM;
18 
19 BOOST_AUTO_TEST_SUITE(OccLocationTest)
20 
21 void random_config(Configuration &config, Monte::Conversions &convert, MTRand &mtrand) {
22  config.init_occupation();
23  for(Index l = 0; l < config.size(); ++l) {
24  int Nocc = convert.occ_size(convert.l_to_asym(l));
25  config.set_occ(l, mtrand.randInt(Nocc - 1));
26  }
27 }
28 
29 void dilute_config(Configuration &config, Monte::Conversions &convert, MTRand &mtrand) {
30  config.init_occupation();
31  for(Index i = 0; i < convert.species_size(); ++i) {
32  for(Index l = 0; l < config.size(); ++l) {
33  Index asym = convert.l_to_asym(l);
34  if(config.occ(l) == 0 &&
35  convert.species_allowed(asym, i)) {
36  config.set_occ(l, convert.occ_index(asym, i));
37  break;
38  }
39  }
40  }
41 }
42 
44  // check OccLocation initialization
45  for(Index mol_id = 0; mol_id < occ_loc.size(); ++mol_id) {
46  BOOST_REQUIRE_EQUAL(mol_id, occ_loc.mol(mol_id).id);
47  }
48 
49  for(Index l = 0; l < config.size(); ++l) {
50  Index mol_id = occ_loc.l_to_mol_id(l);
51  if(mol_id == occ_loc.size()) { // non-variable site
52  continue;
53  }
54  auto &mol = occ_loc.mol(mol_id);
55 
56  BOOST_REQUIRE_EQUAL(mol.l, l);
57  BOOST_REQUIRE_EQUAL(mol.id, mol_id);
58 
59  Index asym = convert.l_to_asym(l);
60  BOOST_REQUIRE_EQUAL(asym, mol.asym);
61 
62  BOOST_REQUIRE_EQUAL(config.occ(l), convert.occ_index(asym, mol.species_index));
63  BOOST_REQUIRE_EQUAL(convert.species_index(asym, config.occ(l)), mol.species_index);
64 
65  Index cand_index = cand_list.index(mol.asym, mol.species_index);
66  BOOST_REQUIRE_EQUAL(mol.id, occ_loc.mol_id(cand_index, mol.loc));
67  }
68 }
69 
71  // check that occ_loc / config / mol are consistent for initial state of config
72  for(const auto &occ : e.occ_transform) {
73  Index l = occ.l;
74  Index mol_id = occ_loc.l_to_mol_id(l);
75  auto &mol = occ_loc.mol(mol_id);
76 
77  BOOST_REQUIRE_EQUAL(mol.l, l);
78  BOOST_REQUIRE_EQUAL(mol.id, mol_id);
79  BOOST_REQUIRE_EQUAL(occ.mol_id, mol_id);
80 
81  Index asym = convert.l_to_asym(l);
82  BOOST_REQUIRE_EQUAL(asym, mol.asym);
83 
84  BOOST_REQUIRE_EQUAL(config.occ(l), convert.occ_index(asym, mol.species_index));
85  BOOST_REQUIRE_EQUAL(convert.species_index(asym, config.occ(l)), mol.species_index);
86 
87  Index cand_index = cand_list.index(mol.asym, mol.species_index);
88  BOOST_REQUIRE_EQUAL(mol.id, occ_loc.mol_id(cand_index, mol.loc));
89  }
90 }
91 
92 template<typename ProjType, typename ConfigInit>
93 void run_case(ProjType &proj, ConfigInit f, MTRand &mtrand) {
94  proj.check_init();
95  proj.check_composition();
96 
97  Logging logging = Logging::null();
98  //Logging logging;
99  PrimClex primclex(proj.dir, logging);
100 
101  Eigen::Matrix3i T;
102  T << 9, 0, 0,
103  0, 9, 0,
104  0, 0, 9;
105  Supercell scel(&primclex, T);
106  Monte::Conversions convert(scel);
107 
108  // config with random occupation
109  Configuration config(scel);
110  f(config, convert, mtrand);
111 
112  // construct OccCandidateList
113  Monte::OccCandidateList cand_list(convert);
114  //std::cout << std::make_pair(cand_list, convert) << std::endl;
115 
116  // construct OccLocation
117  Monte::OccLocation occ_loc(convert, cand_list);
118  occ_loc.initialize(config);
119 
120  check_occ_init(config, occ_loc, convert, cand_list);
121 
122  Index count = 0;
123  Monte::OccEvent e;
124  ConfigDoF &configdof = config.configdof();
125  while(count < 1000000) {
126  //if(count % 100000 == 0) { std::cout << "count: " << count << std::endl; }
127  occ_loc.propose_canonical(e, cand_list.canonical_swap(), mtrand);
128  check_occ(config, e, occ_loc, convert, cand_list);
129  occ_loc.apply(e, configdof);
130  check_occ(config, e, occ_loc, convert, cand_list);
131  ++count;
132  }
133 }
134 
135 
136 BOOST_AUTO_TEST_CASE(ZrO_RandomConfig) {
137 
138  MTRand mtrand;
139  test::ZrOProj proj;
140  run_case(proj, random_config, mtrand);
141 }
142 
143 BOOST_AUTO_TEST_CASE(ZrO_DiluteConfig) {
144 
145  MTRand mtrand;
146  test::ZrOProj proj;
147  run_case(proj, dilute_config, mtrand);
148 }
149 BOOST_AUTO_TEST_CASE(FCCTernary_RandomConfig) {
150 
151  MTRand mtrand;
153  run_case(proj, random_config, mtrand);
154 }
155 
156 BOOST_AUTO_TEST_CASE(FCCTernary_DiluteConfig) {
157 
158  MTRand mtrand;
160  run_case(proj, dilute_config, mtrand);
161 }
162 
163 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(ZrO_RandomConfig)
void initialize(const Configuration &config)
Fill tables with occupation info.
Definition: OccLocation.cc:18
void init_occupation()
Set occupant variables to background structure.
Mol & mol(Index mol_id)
Definition: OccLocation.cc:82
bool species_allowed(Index asym, Index species_index) const
Definition: Conversions.cc:134
const int & occ(Index site_l) const
Occupant variable on site l.
PrimClex * primclex
Definition: settings.cc:101
void random_config(Configuration &config, Monte::Conversions &convert, MTRand &mtrand)
const std::vector< OccSwap > & canonical_swap() const
const ConfigDoF & configdof() const
const Access the DoF
Index species_size() const
Definition: Conversions.cc:138
void check_occ_init(Configuration &config, Monte::OccLocation &occ_loc, Monte::Conversions &convert, Monte::OccCandidateList &cand_list)
Index l_to_mol_id(Index l) const
Convert from config index to variable site index.
Definition: OccLocation.cc:111
Main CASM namespace.
Definition: complete.cpp:8
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:37
Index mol_id(Index cand_index, Index loc) const
Mol.id of a particular OccCandidate type.
Definition: OccLocation.cc:101
std::vector< OccTransform > occ_transform
Definition: OccLocation.hh:62
Index l_to_asym(Index l) const
Definition: Conversions.cc:83
EigenIndex Index
For long integer indexing:
A container class for the different degrees of freedom a Configuration might have.
Definition: ConfigDoF.hh:27
void apply(const OccEvent &e, ConfigDoF &configdof)
Update configdof and this to reflect that event 'e' occurred.
Definition: OccLocation.cc:161
Index id
Location in OccLocation.m_mol.
Definition: OccLocation.hh:34
static Logging null()
Definition: Log.hh:267
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
Index occ_index(Index asym, Index species_index) const
Definition: Conversions.cc:130
Index size() const
Returns number of sites, NOT the number of primitives that fit in here.
List of asym / species_index pairs indicating allowed variable occupation dof.
void dilute_config(Configuration &config, Monte::Conversions &convert, MTRand &mtrand)
OccEvent & propose_canonical(OccEvent &e, const std::vector< OccSwap > &canonical_swap, MTRand &mtrand) const
Propose canonical OccEvent.
Definition: OccLocation.cc:116
void set_occ(Index site_l, int val)
Set occupant variable on site l.
void run_case(ProjType &proj, ConfigInit f, MTRand &mtrand)
size_type size() const
Total number of mutating sites.
Definition: OccLocation.cc:78
Index index(const OccCandidate &cand) const
Return index into std::vector, or _candidate.size() if not allowed. ...
Index species_index(Index asym, Index occ_index) const
Definition: Conversions.cc:127
Stores data to enable efficient proposal and update of occupation mutation.
Definition: OccLocation.hh:68
void check_occ(Configuration &config, Monte::OccEvent &e, Monte::OccLocation &occ_loc, Monte::Conversions &convert, Monte::OccCandidateList &cand_list)
A Configuration represents the values of all degrees of freedom in a Supercell.