CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
ChemicalReference_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 
10 #include "Common.hh"
11 #include "FCCTernaryProj.hh"
12 
13 using namespace CASM;
14 
15 BOOST_AUTO_TEST_SUITE(ChemicalReferenceTest)
16 
18 
20  double tol = TOL;
21 
22  // initialize reference states, just using energies for the end members
23  std::vector<ChemicalReferenceState> ref_state(3);
24  ref_state[0].species_num["A"] = 1.0;
25  ref_state[0].energy_per_species = -1.0;
26 
27  ref_state[1].species_num["B"] = 1.0;
28  ref_state[1].energy_per_species = -2.0;
29 
30  ref_state[2].species_num["C"] = 1.0;
31  ref_state[2].energy_per_species = -4.0;
32 
33  // construct the ChemicalReference, providing only a global reference
34  ChemicalReference chem_ref(
35  prim,
36  ref_state.begin(),
37  ref_state.end(),
38  tol
39  );
40 
41  // check the global reference hyperplane
42  //std::cout << "global ref: " << chem_ref.global().transpose() << std::endl;
43  BOOST_CHECK_EQUAL(almost_equal(chem_ref.global(), Eigen::Vector3d(-1.0, -2.0, -4.0), tol), true);
44 
45  // this should not be allowed to compile:
46  //chem_ref.global() = Eigen::Vector3d::Zero();
47 
48  // try writing to json
49  jsonParser json;
50  to_json(chem_ref, json);
51  BOOST_CHECK_EQUAL(json.contains("global"), true);
52 
53  // try reading from json
54  ChemicalReference chem_ref2 = json.get<ChemicalReference>(prim, tol);
55  BOOST_CHECK_EQUAL(almost_equal(chem_ref2.global(), Eigen::Vector3d(-1.0, -2.0, -4.0), tol), true);
56 
57 
58  // try writing to json, as in project file
59  write_chemical_reference(chem_ref, json);
60  BOOST_CHECK_EQUAL(json.contains("chemical_reference"), true);
61 
62  // try reading from json, as in a project file
63  ChemicalReference chem_ref3 = read_chemical_reference(json, prim, tol);
64  BOOST_CHECK_EQUAL(almost_equal(chem_ref3.global(), Eigen::Vector3d(-1.0, -2.0, -4.0), tol), true);
65 
66 
67  // check the print formatting
68  std::stringstream ss;
69  ChemicalReferencePrinter p(ss, chem_ref);
70  p.print_all();
71  //std::cout << ss.str() << std::endl;
72 
73 }
74 
75 BOOST_AUTO_TEST_CASE(HyperplaneConstructor) {
76 
78 
79  // construct the ChemicalReference, providing only a global reference
80  ChemicalReference chem_ref(
81  prim,
82  Eigen::Vector3d(-1.0, -2.0, -4.0)
83  );
84 
85  // check the global reference hyperplane
86  //std::cout << "global ref: " << chem_ref.global().transpose() << std::endl;
87  BOOST_CHECK_EQUAL(almost_equal(chem_ref.global(), Eigen::Vector3d(-1.0, -2.0, -4.0), TOL), true);
88 
89  // this should not be allowed to compile:
90  //chem_ref.global() = Eigen::Vector3d::Zero();
91 
92  // try writing to json
93  jsonParser json;
94  to_json(chem_ref, json);
95  BOOST_CHECK_EQUAL(json.contains("global"), true);
96  //std::cout << json << std::endl;
97 
98  // try writing to json, as in project file
99  write_chemical_reference(chem_ref, json);
100  BOOST_CHECK_EQUAL(json.contains("chemical_reference"), true);
101  //std::cout << json << std::endl;
102 }
103 
104 BOOST_AUTO_TEST_SUITE_END()
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:29
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
void write_chemical_reference(const ChemicalReference &chem_ref, fs::path filename)
Definition: AppIO.cc:258
Main CASM namespace.
Definition: complete.cpp:8
const double TOL
T get(Args...args) const
Get data from json, using one of several alternatives.
Definition: jsonParser.hh:729
double tol
BasicStructure< Site > FCC_ternary_prim()
ChemicalReference read_chemical_reference(fs::path filename, const Structure &prim, double tol)
Read chemical reference states from JSON file.
Definition: AppIO.cc:212
Structure to help print ChemicalReference.
const Eigen::VectorXd & global() const
const Access the global reference
BOOST_AUTO_TEST_CASE(Basics)
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
Definition: jsonParser.cc:500
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)