CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
PolynomialFunction.hh
Go to the documentation of this file.
1 #ifndef POLYNOMIALFUNCTION_HH
2 #define POLYNOMIALFUNCTION_HH
3 
4 #include <iostream>
5 #include <sstream>
6 #include <map>
7 #include <memory>
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 Function, 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, const PolyTrie<double> &_coeffs);
28 
30  PolynomialFunction(const PolynomialFunction &RHS, const PolyTrie<double> &_coeffs);
31 
32  //Create new polynomial function that is product of two others.
34 
35 
36  static void fill_dispatch_table();
37  SparseTensor<double> const *get_coeffs()const;
38 
39  const PolyTrie<double> &poly_coeffs()const {
40  return m_coeffs;
41  };
42 
43  std::string type_name()const {
44  return "PolynomialFunction";
45  };
46 
47  Function *copy()const;
48  //PolynomialFunction *copy(const PolyTrie<double> &new_coeffs)const;
49 
50  Function *copy(const PolyTrie<double> &new_coeffs)const;
51 
52  bool depends_on(const Function *test_func) const;
53  bool is_zero() const;
54  void small_to_zero(double tol = TOL);
55  Index num_terms() const;
56 
57  double leading_coefficient() const;
58  double leading_coefficient(Index &index) const;
59  double get_coefficient(Index i) const;
60 
61  void make_formula() const;
62  void make_formula(double prefactor) const;
63  int class_ID() const {
65  };
66  static int sclass_ID() {
68  };
69 
70  Function *transform_monomial_and_add_new(double prefactor, const Array<Index> &ind, const SymOp &op, const std::vector<bool> &transform_flags);
71  Function *transform_monomial_and_add(double prefactor, const Array<Index> &ind, const SymOp &op);
72  void scale(double scale_factor);
73 
74  double frobenius_scalar_prod(const PolynomialFunction &RHS)const;
75  double box_integral_scalar_prod(const PolynomialFunction &RHS, double edge_length)const;
76  double gaussian_integral_scalar_prod(const PolynomialFunction &RHS, double std_dev)const;
77 
78  bool compare(const PolynomialFunction *RHS)const;
79  bool prune_zeros();
80 
83 
84  double remote_eval() const;
85  double remote_deval(const DoF::RemoteHandle &dvar) const;
86 
87  double cache_eval() const;
88  double cache_deval(const DoF::RemoteHandle &dvar) const;
89 
90  double eval(const Array<Index> &dof_IDs, const Array<Index> &var_states) const;
91  double eval(const Array<Index> &dof_IDs, const Array<double> &arg_states) const;
92  double poly_eval(const Array<double> &arg_states) const;
93 
94  Function *apply_sym_coeffs(const SymOp &op, int dependency_layer);
95 
96  Function *poly_quotient(const Variable *RHS) const;
97  Function *poly_remainder(const Variable *RHS) const;
98 
99 
100  Function *poly_quotient(const OccupantFunction *RHS) const;
101  Function *poly_remainder(const OccupantFunction *RHS) const;
102 
103  protected:
104 
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  Function *_apply_sym(const SymOp &op);
130  Function *_apply_sym(const SymOp &op, const std::vector<bool> &transform_flags);
131  bool _accept(const FunctionVisitor &visitor, BasisSet const *home_basis_ptr = NULL);
132  };
133 
134  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135 
137  public:
138  double dot(Function const *LHS, Function const *RHS) const;
139  };
140 
141  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142 
144  public:
145  bool compare(Function const *LHS, Function const *RHS) const;
146 
147  Function *multiply(Function const *LHS, Function const *RHS) const;
148  Function *multiply_by(Function *LHS, Function const *RHS) const;
149 
150  Function *add(Function const *LHS, Function const *RHS) const;
151  Function *add_to(Function *LHS, Function const *RHS) const;
152 
153  Function *subtract(Function const *LHS, Function const *RHS) const;
154  Function *subtract_from(Function *LHS, Function const *RHS) const;
155  };
156 
157  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
158 
160  Function *poly_quotient(Function const *LHS, Function const *RHS) const;
161  Function *poly_remainder(Function const *LHS, Function const *RHS) const;
162  };
163 
164  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165 
167  Function *poly_quotient(Function const *LHS, Function const *RHS) const;
168  Function *poly_remainder(Function const *LHS, Function const *RHS) const;
169  };
170 
171  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
172  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173 
174 
175 }
176 #endif
void small_to_zero(double tol=TOL)
void scale(double scale_factor)
static int get_class_ID()
Definition: HierarchyID.hh:32
bool compare(Function const *LHS, Function const *RHS) const
Function * transform_monomial_and_add_new(double prefactor, const Array< Index > &ind, const SymOp &op, const std::vector< bool > &transform_flags)
double eval(const Array< Index > &dof_IDs, const Array< Index > &var_states) const
Function * subtract(Function const *LHS, Function const *RHS) const
Function * poly_remainder(Function const *LHS, Function const *RHS) const
double cache_deval(const DoF::RemoteHandle &dvar) const
double dot(Function const *LHS, Function const *RHS) const
double get_coefficient(Index i) const
Main CASM namespace.
Definition: complete.cpp:8
const double TOL
double frobenius_scalar_prod(const PolynomialFunction &RHS) const
Function * poly_remainder(const Variable *RHS) const
double leading_coefficient() const
Function * add_to(Function *LHS, Function const *RHS) const
double remote_deval(const DoF::RemoteHandle &dvar) const
Function * add(Function const *LHS, Function const *RHS) const
bool _accept(const FunctionVisitor &visitor, BasisSet const *home_basis_ptr=NULL)
double tol
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
double gaussian_integral_scalar_prod(const PolynomialFunction &RHS, double std_dev) const
Function * poly_quotient(Function const *LHS, Function const *RHS) const
Function * multiply_by(Function *LHS, Function const *RHS) const
EigenIndex Index
For long integer indexing:
const PolyTrie< double > & poly_coeffs() const
Function * poly_remainder(Function const *LHS, Function const *RHS) const
Function * _apply_sym(const SymOp &op)
Function * transform_monomial_and_add(double prefactor, const Array< Index > &ind, const SymOp &op)
Function * minus_equals(const PolynomialFunction *RHS)
Function * plus_equals(const PolynomialFunction *RHS)
bool compare(const PolynomialFunction *RHS) const
SparseTensor< double > const * get_coeffs() const
Function * poly_quotient(const Variable *RHS) const
double poly_eval(const Array< double > &arg_states) const
Function * apply_sym_coeffs(const SymOp &op, int dependency_layer)
bool depends_on(const Function *test_func) const
Function * multiply(Function const *LHS, Function const *RHS) const
Function * subtract_from(Function *LHS, Function const *RHS) const
Function * poly_quotient(Function const *LHS, Function const *RHS) const
double box_integral_scalar_prod(const PolynomialFunction &RHS, double edge_length) const
std::string type_name() const