CASM  1.1.0
A Clusters Approach to Statistical Mechanics
PolynomialFunction.hh
Go to the documentation of this file.
1 #ifndef POLYNOMIALFUNCTION_HH
2 #define POLYNOMIALFUNCTION_HH
3 
4 #include <iostream>
5 #include <map>
6 #include <memory>
7 #include <sstream>
8 #include <vector>
9 
12 
13 namespace CASM {
14 
15 class Function;
16 class InnerProduct;
17 class FunctionOperation;
18 class PolynomialFunction;
19 class OccupantFunction;
20 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 
23  public DerivedID<PolynomialFunction, Function> {
24  public:
26  PolynomialFunction(const std::vector<std::shared_ptr<BasisSet> > &_args);
27  PolynomialFunction(const std::vector<std::shared_ptr<BasisSet> > &_args,
28  const PolyTrie<double> &_coeffs);
29 
32  const PolyTrie<double> &_coeffs);
33 
34  // Create new polynomial function that is product of two others.
36  const PolynomialFunction &RHS);
37 
38  static void fill_dispatch_table();
39  SparseTensor<double> const *get_coeffs() const override;
40 
41  const PolyTrie<double> &poly_coeffs() const { return m_coeffs; };
42 
43  std::string type_name() const override { return "PolynomialFunction"; };
44 
45  Function *copy() const override;
46  // PolynomialFunction *copy(const PolyTrie<double> &new_coeffs)const;
47 
48  Function *copy(const PolyTrie<double> &new_coeffs) const;
49 
50  bool depends_on(const Function *test_func) const override;
51  bool is_zero() const override;
52  void small_to_zero(double tol = TOL) override;
53  Index num_terms() const override;
54 
55  double leading_coefficient() const override;
56  double leading_coefficient(Index &index) const override;
57  double get_coefficient(Index i) const override;
58 
59  void make_formula() const override;
60  void make_formula(double prefactor) const;
61 
62  std::set<Index> dof_IDs() const override;
63  int class_ID() const override {
65  };
66  static int sclass_ID() {
68  };
69 
71  double prefactor, const Array<Index> &ind, const SymOp &op,
72  const std::vector<bool> &transform_flags);
73  Function *transform_monomial_and_add(double prefactor,
74  const Array<Index> &ind,
75  const SymOp &op);
76  void scale(double scale_factor) override;
77 
78  double frobenius_scalar_prod(const PolynomialFunction &RHS) const;
80  double edge_length) const;
82  double std_dev) const;
83 
84  bool compare(const PolynomialFunction *RHS) const;
85  bool prune_zeros();
86 
89 
90  double remote_eval() const override;
91  double remote_deval(const DoF::RemoteHandle &dvar) const override;
92 
93  double cache_eval() const override;
94  double cache_deval(const DoF::RemoteHandle &dvar) const override;
95 
96  Function *apply_sym_coeffs(const SymOp &op, int dependency_layer) override;
97 
98  Function *poly_quotient(const Variable *RHS) const;
99  Function *poly_remainder(const Variable *RHS) const;
100 
101  Function *poly_quotient(const OccupantFunction *RHS) const;
102  Function *poly_remainder(const OccupantFunction *RHS) const;
103 
104  protected:
105  //**Inherited from Function:**
106  // Array<std::shared_ptr<BasisSet> > m_argument;
107  // mutable std::string m_formula, m_tex_formula;
108  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
109 
110  // sub_sym_reps has sym_rep index of each subspace
111  // Array<Index> m_sub_sym_reps;
112 
113  // subspace_array specifies how Functions in 'argument'
114  // are divided into subspaces that transform distinctly
115  // under symmetry. There is one interior array for each subspace
116  // e.g.: if argument contains {x, y, v, w}
117  // and {x,y} transforms separately from {v,w}, then
118  // dim2arg_array is {{0,1},{2,3}}
119  // Array<Array<Index> > m_subspaces;
120 
121  // arg2sub tells which subspace each argument belongs to
122  // in example above for polynomials of {x, y, v, w}
123  // arg2sub will be {0,0,1,1}
124  // Array<Index> m_arg2sub;
125  // Array<Index> m_arg2fun;
126 
128 
129  void _set_arguments(const ArgumentContainer &new_arg,
130  std::vector<Index> const &compatibility_map) override;
131 
132  Function *_apply_sym(const SymOp &op) override;
133  Function *_apply_sym(const SymOp &op,
134  const std::vector<bool> &transform_flags);
135 
136  bool _accept(const FunctionVisitor &visitor,
137  BasisSet const *home_basis_ptr = NULL) override;
138 
139  bool _accept(const FunctionVisitor &visitor,
140  BasisSet const *home_basis_ptr = NULL) const override;
141 };
142 
143 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144 
146  public:
147  double dot(Function const *LHS, Function const *RHS) const;
148 };
149 
150 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151 
153  public:
154  bool compare(Function const *LHS, Function const *RHS) const;
155 
156  Function *multiply(Function const *LHS, Function const *RHS) const;
157  Function *multiply_by(Function *LHS, Function const *RHS) const;
158 
159  Function *add(Function const *LHS, Function const *RHS) const;
160  Function *add_to(Function *LHS, Function const *RHS) const;
161 
162  Function *subtract(Function const *LHS, Function const *RHS) const;
163  Function *subtract_from(Function *LHS, Function const *RHS) const;
164 };
165 
166 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167 
169  Function *poly_quotient(Function const *LHS, Function const *RHS) const;
170  Function *poly_remainder(Function const *LHS, Function const *RHS) const;
171 };
172 
173 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174 
176  Function *poly_quotient(Function const *LHS, Function const *RHS) const;
177  Function *poly_remainder(Function const *LHS, Function const *RHS) const;
178 };
179 
180 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
181 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182 
183 } // namespace CASM
184 #endif
double dot(Function const *LHS, Function const *RHS) const
static int get_class_ID()
Definition: HierarchyID.hh:30
std::vector< std::shared_ptr< BasisSet > > ArgumentContainer
Function * poly_quotient(Function const *LHS, Function const *RHS) const
Function * poly_remainder(Function const *LHS, Function const *RHS) const
Function * subtract(Function const *LHS, Function const *RHS) const
Function * add(Function const *LHS, Function const *RHS) const
Function * add_to(Function *LHS, Function const *RHS) const
Function * multiply(Function const *LHS, Function const *RHS) const
bool compare(Function const *LHS, Function const *RHS) const
Function * subtract_from(Function *LHS, Function const *RHS) const
Function * multiply_by(Function *LHS, Function const *RHS) const
Function * poly_remainder(Function const *LHS, Function const *RHS) const
Function * poly_quotient(Function const *LHS, Function const *RHS) const
void scale(double scale_factor) override
void make_formula(double prefactor) const
bool depends_on(const Function *test_func) const override
void make_formula() const override
double remote_deval(const DoF::RemoteHandle &dvar) const override
SparseTensor< double > const * get_coeffs() const override
std::set< Index > dof_IDs() const override
double cache_deval(const DoF::RemoteHandle &dvar) const override
Function * copy() const override
void _set_arguments(const ArgumentContainer &new_arg, std::vector< Index > const &compatibility_map) override
double frobenius_scalar_prod(const PolynomialFunction &RHS) const
Index num_terms() const override
double gaussian_integral_scalar_prod(const PolynomialFunction &RHS, double std_dev) const
Function * apply_sym_coeffs(const SymOp &op, int dependency_layer) override
double get_coefficient(Index i) const override
Function * poly_quotient(const Variable *RHS) const
double remote_eval() const override
double leading_coefficient() const override
double cache_eval() const override
double box_integral_scalar_prod(const PolynomialFunction &RHS, double edge_length) const
Function * _apply_sym(const SymOp &op) override
const PolyTrie< double > & poly_coeffs() const
Function * transform_monomial_and_add(double prefactor, const Array< Index > &ind, const SymOp &op)
Function * poly_remainder(const Variable *RHS) const
Function * plus_equals(const PolynomialFunction *RHS)
std::string type_name() const override
bool compare(const PolynomialFunction *RHS) const
void small_to_zero(double tol=TOL) override
Function * minus_equals(const PolynomialFunction *RHS)
int class_ID() const override
Function * transform_monomial_and_add_new(double prefactor, const Array< Index > &ind, const SymOp &op, const std::vector< bool > &transform_flags)
bool _accept(const FunctionVisitor &visitor, BasisSet const *home_basis_ptr=NULL) override
bool is_zero() const override
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
Main CASM namespace.
Definition: APICommand.hh:8
const double TOL
Definition: definitions.hh:30
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39