CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ConfigIOStrain.cc
Go to the documentation of this file.
2 
3 #include <functional>
4 
5 #include "casm/clex/ConfigIO.hh"
7 #include "casm/clex/Supercell.hh"
9 
10 namespace CASM {
11 
12 namespace ConfigIO {
13 bool RelaxationStrain::parse_args(const std::string &args) {
14  std::vector<std::string> splt_vec;
15  boost::split(splt_vec, args, boost::is_any_of(","), boost::token_compress_on);
16  std::string tmetric_name = "GL";
17  std::string index_expr;
18 
19  if (splt_vec.size()) {
20  tmetric_name = splt_vec[0];
21  }
22  if (splt_vec.size() >= 2) {
23  index_expr = splt_vec[1];
24  }
25  if (splt_vec.size() == 3) {
26  m_calctype = splt_vec[2];
27  }
28  if (splt_vec.size() > 3) {
29  std::stringstream ss;
30  ss << "Too many arguments for 'relaxation_strain'. Received: " << args
31  << "\n";
32  throw std::runtime_error(ss.str());
33  }
34  // if(m_metric_name.size() > 0 && tmetric_name != m_metric_name) {
35  // return false;
36  // }
37  m_metric_name = tmetric_name;
38  if (index_expr.size() > 0) {
39  _parse_index_expression(index_expr);
40  }
41 
42  return false;
43 }
44 
45 //****************************************************************************************
46 
47 bool RelaxationStrain::init(const Configuration &_tmplt) const {
48  if (m_metric_name.size() == 0) m_metric_name = "GL";
50  if (_index_rules().size() > 0) return true;
51 
52  for (Index i = 0; i < 6; i++) _add_rule(std::vector<Index>({i}));
53  return true;
54 }
55 //****************************************************************************************
56 
57 bool RelaxationStrain::validate(const Configuration &_config) const {
58  return _config.calc_properties(m_calctype).global.count("Ustrain");
59 }
60 
61 //****************************************************************************************
62 
63 std::vector<std::string> RelaxationStrain::col_header(
64  const Configuration &_tmplt) const {
65  std::vector<std::string> col;
66  auto it(_index_rules().cbegin()), end_it(_index_rules().cend());
67  // Index s = max(8 - int(name().size()), 0);
68  for (; it != end_it; ++it) {
69  std::stringstream t_ss;
70  t_ss << " " << name() << '(' << m_metric_name << ',' << (*it)[0] << ','
71  << m_calctype << ')';
72  col.push_back(t_ss.str());
73  }
74  return col;
75 }
76 
77 //****************************************************************************************
78 
79 std::string RelaxationStrain::short_header(const Configuration &_tmplt) const {
80  return name() + "(" + m_metric_name + ")";
81 }
82 
83 //****************************************************************************************
86  _config.calc_properties(m_calctype).global.at("Ustrain")));
87 }
88 
89 //****************************************************************************************
90 
91 bool DoFStrain::parse_args(const std::string &args) {
92  std::vector<std::string> splt_vec;
93  boost::split(splt_vec, args, boost::is_any_of(","), boost::token_compress_on);
94  std::string tmetric_name = "GL";
95  std::string index_expr;
96 
97  if (splt_vec.size()) {
98  tmetric_name = splt_vec[0];
99  }
100  if (splt_vec.size() == 2) {
101  index_expr = splt_vec[1];
102  }
103  if (splt_vec.size() > 2) {
104  std::stringstream ss;
105  ss << "Too many arguments for 'dof_strain'. Received: " << args << "\n";
106  throw std::runtime_error(ss.str());
107  }
108  // if(m_metric_name.size() > 0 && tmetric_name != m_metric_name) {
109  // return false;
110  // }
111  m_metric_name = tmetric_name;
112  if (index_expr.size() > 0) {
113  _parse_index_expression(index_expr);
114  }
115 
116  return false;
117 }
118 
119 bool DoFStrain::init(const Configuration &_tmplt) const {
120  if (m_metric_name.size() == 0) m_metric_name = "GL";
122  if (_index_rules().size() > 0) return true;
123 
124  Index size = evaluate(_tmplt).size();
125  for (Index i = 0; i < size; i++) _add_rule(std::vector<Index>({i}));
126  return true;
127 }
128 
129 std::vector<std::string> DoFStrain::col_header(
130  const Configuration &_tmplt) const {
131  std::vector<std::string> col;
132  auto it(_index_rules().cbegin()), end_it(_index_rules().cend());
133  // Index s = max(8 - int(name().size()), 0);
134  for (; it != end_it; ++it) {
135  std::stringstream t_ss;
136  t_ss << name() << '(' << m_metric_name << ',' << (*it)[0] << ')';
137  col.push_back(t_ss.str());
138  }
139  return col;
140 }
141 
142 std::string DoFStrain::short_header(const Configuration &_tmplt) const {
143  return name() + "(" + m_metric_name + ")";
144 }
145 
147  if (!m_prim_straincalc ||
148  (_config.supercell().shared_prim() != m_shared_prim)) {
149  m_shared_prim = _config.supercell().shared_prim();
150  if (!has_strain_dof(m_shared_prim->structure())) {
151  std::stringstream msg;
152  msg << "Error in DoFStrain: Prim does not have strain DoF.";
153  throw std::runtime_error(msg.str());
154  }
156  m_prim_straincalc = notstd::make_unique<StrainConverter>(
158  }
159  Eigen::VectorXd unrolled_metric =
161  Eigen::Matrix3d F =
162  m_prim_straincalc->unrolled_strain_metric_to_F(unrolled_metric);
164 }
165 
166 } // namespace ConfigIO
167 
168 } // namespace CASM
void _parse_index_expression(const std::string &_expr)
const IndexContainer & _index_rules() const
const std::string & name() const
Returns a name for the formatter, which becomes the tag used for parsing.
GlobalContinuousConfigDoFValues const & global_dof(DoFKey const &_key) const
Definition: ConfigDoF.cc:69
StrainConverter m_straincalc
std::vector< std::string > col_header(const Configuration &_config) const override
bool init(const Configuration &_tmplt) const override
notstd::cloneable_ptr< StrainConverter > m_prim_straincalc
Eigen::VectorXd evaluate(const Configuration &_config) const override
bool parse_args(const std::string &args) override
Default implementation calls _parse_index_expression.
std::string short_header(const Configuration &_config) const override
std::shared_ptr< Structure const > m_shared_prim
bool parse_args(const std::string &args) override
Default implementation calls _parse_index_expression.
std::string short_header(const Configuration &_config) const override
bool validate(const Configuration &_config) const override
Eigen::VectorXd evaluate(const Configuration &_config) const override
std::vector< std::string > col_header(const Configuration &_config) const override
bool init(const Configuration &_tmplt) const override
const ConfigDoF & configdof() const
const Access the DoF
const Supercell & supercell() const
Get the Supercell for this Configuration.
Eigen::MatrixXd standard_values() const
Get global DoF values as standard DoF values.
Matrix3d rollup_E(Eigen::Ref< const VectorXd > const &_unrolled_E) const
VectorXd unrolled_strain_metric(Eigen::Ref< const Matrix3d > const &F) const
void set_mode(const std::string &mode_name)
std::shared_ptr< Structure const > const & shared_prim() const
Definition: Supercell.cc:115
bool has_strain_dof(BasicStructure const &structure)
DoFKey get_strain_dof_key(BasicStructure const &structure)
std::string get_strain_metric(DoFKey strain_dof_key)
Main CASM namespace.
Definition: APICommand.hh:8
Eigen::Matrix3d Matrix3d
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Eigen::VectorXd VectorXd