CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Configuration_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 
9 #include "Common.hh"
10 #include "FCCTernaryProj.hh"
11 #include "casm/symmetry/SymInfo.hh"
12 #include "casm/app/AppIO.hh"
13 
14 using namespace CASM;
15 
16 BOOST_AUTO_TEST_SUITE(ConfigurationTest)
17 
19 
21  proj.check_init();
22 
23  PrimClex primclex(proj.dir, null_log());
24 
25  Eigen::Vector3d a, b, c;
26  std::tie(a, b, c) = primclex.get_prim().lattice().vectors();
27 
28  Supercell scel {&primclex, Lattice(a, b, c)};
29 
30  Configuration config(scel);
31  BOOST_CHECK_EQUAL(config.size(), 1);
32 
33  // set occupation
34  BOOST_CHECK_EQUAL(config.has_occupation(), false);
35 
36  config.init_occupation();
37  BOOST_CHECK_EQUAL(config.has_occupation(), true);
38 
39  config.clear_occupation();
40  BOOST_CHECK_EQUAL(config.has_occupation(), false);
41 
42  config.set_occupation(Array<int>(1, 0));
43  BOOST_CHECK_EQUAL(config.has_occupation(), true);
44 
45  for(int i = 0; i < 3; ++i) {
46  config.set_occ(0, i);
47  BOOST_CHECK_EQUAL(config.occ(0), i);
48  }
49 
50  // set displacement
51  typedef Configuration::displacement_matrix_t disp_matrix_t;
52  BOOST_CHECK_EQUAL(config.has_displacement(), false);
53 
54  config.init_displacement();
55  BOOST_CHECK_EQUAL(config.has_displacement(), true);
56 
57  config.clear_displacement();
58  BOOST_CHECK_EQUAL(config.has_displacement(), false);
59 
60  config.set_displacement(disp_matrix_t::Zero(3, 1));
61  BOOST_CHECK_EQUAL(config.has_displacement(), true);
62 
63  for(int i = 0; i < 3; ++i) {
64  Eigen::Vector3d d = Eigen::Vector3d::Zero();
65  d(i) = 0.001;
66  config.set_disp(0, d);
67  BOOST_CHECK_EQUAL(almost_equal(config.disp(0), d), true);
68  }
69 
70  // set deformation
71  BOOST_CHECK_EQUAL(config.has_deformation(), false);
72 
73  config.init_deformation();
74  BOOST_CHECK_EQUAL(config.has_deformation(), true);
75 
76  config.clear_deformation();
77  BOOST_CHECK_EQUAL(config.has_deformation(), false);
78 
79  config.set_deformation(Eigen::Matrix3d::Zero());
80  BOOST_CHECK_EQUAL(config.has_deformation(), true);
81 
82 }
83 
85 
86  // test Configuration::fill_supercell
87 
89  proj.check_init();
90 
91  PrimClex primclex(proj.dir, null_log());
92 
93  Eigen::Vector3d a, b, c;
94  std::tie(a, b, c) = primclex.get_prim().lattice().vectors();
95 
96  Supercell scel {&primclex, Lattice(c, a - b, a + b - c)};
97 
98  Configuration config(scel);
99  BOOST_CHECK_EQUAL(config.size(), 2);
100 
101  // include occupation only
102  config.set_occupation({1, 0});
103 
104  {
105  // Identity op
106  Supercell scel {&primclex, Lattice(c, a - b, a + b - c)};
107  const SymGroup &fg = config.get_supercell().factor_group();
108  Configuration filled = config.fill_supercell(scel, fg[0]);
109 
110  Configuration check(scel);
111  check.set_occupation({1, 0});
112 
113  BOOST_CHECK_EQUAL(filled, check);
114  }
115 
116  {
117  // supercell
118  Supercell scel {&primclex, Lattice(c, a - b, 2.*(a + b - c))};
119  const SymGroup &fg = config.get_supercell().factor_group();
120  Configuration filled = config.fill_supercell(scel, fg[0]);
121 
122  Configuration check(scel);
123  check.set_occupation({1, 0, 1, 0});
124 
125  BOOST_CHECK_EQUAL(filled, check);
126  }
127 
128  {
129  // 90 deg rotation
130  Supercell scel {&primclex, Lattice(c, a - b, a + b - c)};
131  const SymGroup &fg = config.get_supercell().factor_group();
132  //std::cout << to_string(fg.info(1), CART) << std::endl;
133  Configuration filled = config.fill_supercell(scel, fg[1]);
134 
135  Configuration check(scel);
136  check.set_occupation({1, 0});
137 
138  BOOST_CHECK_EQUAL(filled, check);
139  }
140 
141 
142  // include occupation & displacements
143  Eigen::Vector3d dzero(0., 0., 0.);
144  Eigen::Vector3d dx(0.001, 0., 0.);
145  Eigen::Vector3d dy(0., 0.001, 0.);
146  Eigen::Vector3d dz(0., 0., 0.001);
147 
148  config.init_displacement();
149  config.set_disp(0, dx);
150 
151  {
152  // Identity op
153  Supercell scel {&primclex, Lattice(c, a - b, a + b - c)};
154  const SymGroup &fg = config.get_supercell().factor_group();
155  Configuration filled = config.fill_supercell(scel, fg[0]);
156 
157  Configuration check(scel);
158  check.set_occupation({1, 0});
159  check.init_displacement();
160  check.set_disp(0, dx);
161 
162 
163  BOOST_CHECK_EQUAL(filled, check);
164  }
165 
166  {
167  // supercell
168  Supercell scel {&primclex, Lattice(c, a - b, 2.*(a + b - c))};
169  const SymGroup &fg = config.get_supercell().factor_group();
170  Configuration filled = config.fill_supercell(scel, fg[0]);
171 
172  Configuration check(scel);
173  check.set_occupation({1, 0, 1, 0});
174  check.init_displacement();
175  check.set_disp(0, dx);
176  check.set_disp(2, dx);
177 
178  BOOST_CHECK_EQUAL(filled, check);
179  }
180 
181  {
182  // 90 deg rotation
183  Supercell scel {&primclex, Lattice(c, a - b, a + b - c)};
184  const SymGroup &fg = config.get_supercell().factor_group();
185  Configuration filled = config.fill_supercell(scel, fg[1]);
186 
187  Configuration check(scel);
188  check.set_occupation({1, 0});
189  check.init_displacement();
190  check.set_disp(0, dy);
191 
192  BOOST_CHECK_EQUAL(filled, check);
193  }
194 
195 }
196 
197 BOOST_AUTO_TEST_SUITE_END()
void clear_deformation()
Clear applied strain.
void clear_displacement()
Clear displacement.
Configuration fill_supercell(Supercell &scel, const SymOp &op) const
Fills supercell 'scel' with reoriented configuration, as if by apply(op,*this)
const_displacement_t disp(Index site_l) const
Occupant displacement.
fs::path dir
Definition: Proj.hh:34
void init_occupation()
Set occupant variables to background structure.
const int & occ(Index site_l) const
Occupant variable on site l.
void set_deformation(const Eigen::Matrix3d &_deformation)
Set applied strain.
PrimClex * primclex
Definition: settings.cc:101
void set_displacement(const displacement_matrix_t &_disp)
Set occupant displacements.
Main CASM namespace.
Definition: complete.cpp:8
void set_disp(Index site_l, const Eigen::VectorXd &_disp)
Set occupant displacements.
const Lattice & lattice() const
Log & null_log()
Definition: Log.hh:211
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:37
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:33
bool has_occupation() const
True if Configuration has occupation DoF.
BOOST_AUTO_TEST_CASE(Test1)
void set_occupation(const Array< int > &newoccupation)
Set occupant variables.
bool has_deformation() const
True if Configuration has strain DoF.
void clear_occupation()
Clear occupation.
const SymGroup & factor_group() const
Definition: Supercell.cc:132
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
Index size() const
Returns number of sites, NOT the number of primitives that fit in here.
std::tuple< LatVec, LatVec, LatVec > vectors()
Definition: Lattice.hh:65
bool check(std::string test, const jsonParser &expected, const jsonParser &calculated, fs::path test_cases_path, bool quiet, double tol=0.0)
Check expected JSON vs calculated JSON using BOOST_CHECK_EQUAL.
void set_occ(Index site_l, int val)
Set occupant variable on site l.
ConfigDoF::displacement_matrix_t displacement_matrix_t
Supercell & get_supercell() const
Get the Supercell for this Configuration.
void init_displacement()
Set all occupant displacements to (0.,0.,0.)
bool has_displacement() const
True if Configuration has displacement DoF.
virtual void check_init()
Check project initialization.
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)
A Configuration represents the values of all degrees of freedom in a Supercell.
const Structure & get_prim() const
const Access to primitive Structure
Definition: PrimClex.cc:260
void init_deformation()
Set applied strain to Eigen::Matrix3d::Zero()