CASM  1.1.0
A Clusters Approach to Statistical Mechanics
Variable.hh
Go to the documentation of this file.
1 #ifndef VARIABLE_HH
2 #define VARIABLE_HH
3 
4 #include <iostream>
5 #include <sstream>
6 
10 
11 namespace CASM {
12 
13 class Function;
14 class FunctionVisitor;
15 class FunctionOperation;
16 class InnerProduct;
17 
18 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 // Function is a virtual class, which means you use it like this:
20 //
21 // Function* my_funct_ptr=new VariableArgument("x");
22 // my_funct_ptr->make_formula();
23 //
24 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 class Variable : public Function, public DerivedID<Variable, Function> {
26  //**Inherited from Function:**
27  // int func_ID;
28  // Array<Function*> m_argument;
29  // mutable std::string m_formula, m_tex_formula;
30  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
31 
32  // m_dof_set defines coordinate system of variables
34 
35  // coeffs defines linear combination (i.e., vector) of m_dof_set
37 
38  // Default construction not allowed
39  // Variable(){}
40 
41  // Copy construction is private.
42  // Copy construction should only occur in Variable::copy()
43  Variable(const Variable &old_var) = default;
44 
45  public:
46  Variable(const DoFSet &tvar, int var_ind);
47  Variable(const DoFSet &tvar, const Eigen::VectorXd &init_coeffs);
48 
49  static void fill_dispatch_table();
50 
51  std::string type_name() const override { return "Variable"; }
52 
53  Function *copy() const override { return new Variable(*this); }
54 
55  bool is_zero() const override;
56  void small_to_zero(double tol = TOL) override;
57  Index num_terms() const override;
58 
59  double leading_coefficient() const override;
60  double leading_coefficient(Index &index) const override;
61  double get_coefficient(Index i) const override;
62 
63  const DoFSet &dof_set() const { return m_dof_set; }
64 
65  SymGroupRepID symrep_ID() const { return dof_set().symrep_ID(); }
66 
67  const Eigen::VectorXd &coeffs() const { return m_coeffs; }
68 
69  void make_formula() const override;
70 
71  std::set<Index> dof_IDs() const override;
72 
73  int register_remotes(
74  const std::vector<DoF::RemoteHandle> &remote_handles) override;
75 
76  bool compare(const Variable *RHS) const;
77 
78  int class_ID() const override {
80  }
81  static int sclass_ID() {
83  }
84 
85  double dot(Function const *RHS) const;
86  void scale(double scale_factor) override;
87 
88  double remote_eval() const override;
89 
90  double remote_deval(const DoF::RemoteHandle &dvar) const override;
91 
92  double cache_eval() const override { return remote_eval(); }
93 
94  double cache_deval(const DoF::RemoteHandle &dvar) const override {
95  return remote_deval(dvar);
96  }
97 
98  Function *minus_equals(const Variable *RHS);
99  Function *plus_equals(const Variable *RHS);
100 
101  jsonParser &to_json(jsonParser &json) const override;
102  void from_json(const jsonParser &json);
103 
104  protected:
105  Function *_apply_sym(const SymOp &op) override;
106  bool _accept(const FunctionVisitor &visitor,
107  BasisSet const *home_basis_ptr = NULL) override;
108  bool _accept(const FunctionVisitor &visitor,
109  BasisSet const *home_basis_ptr = NULL) const override;
110 
111  bool _update_dof_IDs(const std::vector<Index> &before_IDs,
112  const std::vector<Index> &after_IDs) override;
113 };
114 
115 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116 
118  public:
119  double dot(Function const *LHS, Function const *RHS) const;
120 };
121 
122 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123 
125  public:
126  bool compare(Function const *LHS, Function const *RHS) const;
127 
128  Function *multiply(Function const *LHS, Function const *RHS) const;
129  Function *multiply_by(Function *LHS, Function const *RHS) const;
130 
131  Function *add(Function const *LHS, Function const *RHS) const;
132  Function *add_to(Function *LHS, Function const *RHS) const;
133 
134  Function *subtract(Function const *LHS, Function const *RHS) const;
135  Function *subtract_from(Function *LHS, Function const *RHS) const;
136 };
137 
138 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139 
140 jsonParser &to_json(const Variable &var, jsonParser &json);
141 void from_json(Variable &var, const jsonParser &json);
142 
143 } // namespace CASM
144 #endif
double dot(Function const *LHS, Function const *RHS) const
Definition: Variable.cc:319
static int get_class_ID()
Definition: HierarchyID.hh:30
SymGroupRepID const & symrep_ID() const
Definition: DoFSet.hh:276
Type-safe ID object for communicating and accessing Symmetry representation info.
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
Function * add(Function const *LHS, Function const *RHS) const
Definition: Variable.cc:403
bool compare(Function const *LHS, Function const *RHS) const
Definition: Variable.cc:327
Function * add_to(Function *LHS, Function const *RHS) const
Definition: Variable.cc:413
Function * multiply(Function const *LHS, Function const *RHS) const
Definition: Variable.cc:344
Function * multiply_by(Function *LHS, Function const *RHS) const
Definition: Variable.cc:333
Function * subtract_from(Function *LHS, Function const *RHS) const
Definition: Variable.cc:391
Function * subtract(Function const *LHS, Function const *RHS) const
Definition: Variable.cc:380
Variable(const Variable &old_var)=default
bool _accept(const FunctionVisitor &visitor, BasisSet const *home_basis_ptr=NULL) override
Definition: Variable.cc:38
bool is_zero() const override
Definition: Variable.cc:51
double cache_eval() const override
Definition: Variable.hh:92
void from_json(const jsonParser &json)
bool compare(const Variable *RHS) const
Definition: Variable.cc:262
const DoFSet & dof_set() const
Definition: Variable.hh:63
Function * minus_equals(const Variable *RHS)
Definition: Variable.cc:306
void small_to_zero(double tol=TOL) override
Definition: Variable.cc:64
static int sclass_ID()
Definition: Variable.hh:81
int class_ID() const override
Definition: Variable.hh:78
double remote_deval(const DoF::RemoteHandle &dvar) const override
Definition: Variable.cc:293
DoFSet m_dof_set
Definition: Variable.hh:33
Function * copy() const override
Definition: Variable.hh:53
double remote_eval() const override
Definition: Variable.cc:283
double dot(Function const *RHS) const
double cache_deval(const DoF::RemoteHandle &dvar) const override
Definition: Variable.hh:94
static void fill_dispatch_table()
Definition: Variable.cc:17
double get_coefficient(Index i) const override
Definition: Variable.cc:110
std::set< Index > dof_IDs() const override
Definition: Variable.cc:215
int register_remotes(const std::vector< DoF::RemoteHandle > &remote_handles) override
Definition: Variable.cc:224
bool _update_dof_IDs(const std::vector< Index > &before_IDs, const std::vector< Index > &after_IDs) override
Definition: Variable.cc:246
std::string type_name() const override
Definition: Variable.hh:51
Eigen::VectorXd m_coeffs
Definition: Variable.hh:36
const Eigen::VectorXd & coeffs() const
Definition: Variable.hh:67
Function * plus_equals(const Variable *RHS)
Definition: Variable.cc:313
jsonParser & to_json(jsonParser &json) const override
Definition: Variable.cc:428
Index num_terms() const override
Definition: Variable.cc:74
SymGroupRepID symrep_ID() const
Definition: Variable.hh:65
Function * _apply_sym(const SymOp &op) override
Definition: Variable.cc:200
void scale(double scale_factor) override
Definition: Variable.cc:274
void make_formula() const override
Definition: Variable.cc:117
double leading_coefficient() const override
Definition: Variable.cc:88
Main CASM namespace.
Definition: APICommand.hh:8
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
const double TOL
Definition: definitions.hh:30
void from_json(ClexDescription &desc, const jsonParser &json)
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Eigen::VectorXd VectorXd