Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2016-2021 The VES code team 3 : (see the PEOPLE-VES file at the root of this folder for a list of names) 4 : 5 : See http://www.ves-code.org for more information. 6 : 7 : This file is part of VES code module. 8 : 9 : The VES code module is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : The VES code module is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU Lesser General Public License for more details. 18 : 19 : You should have received a copy of the GNU Lesser General Public License 20 : along with the VES code module. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : 23 : #include "BasisFunctions.h" 24 : 25 : #include "core/ActionRegister.h" 26 : 27 : 28 : namespace PLMD { 29 : namespace ves { 30 : 31 : //+PLUMEDOC VES_BASISF BF_CHEBYSHEV 32 : /* 33 : Chebyshev polynomial basis functions. 34 : 35 : Use as basis functions [Chebyshev polynomials](https://en.wikipedia.org/wiki/Chebyshev_polynomials) 36 : of the first kind $T_{n}(x)$ defined on a bounded interval. 37 : You need to provide the interval $[a,b]$ 38 : on which the basis functions are to be used, and the order of the 39 : expansion $N$ (i.e. the highest order polynomial used). 40 : The total number of basis functions is $N+1$ as the constant $T_{0}(x)=1$ 41 : is also included. 42 : These basis functions should not be used for periodic CVs. 43 : 44 : Intrinsically the Chebyshev polynomials are defined on the interval $[-1,1]$. 45 : A variable $t$ in the interval $[a,b]$ is transformed to a variable $x$ 46 : in the intrinsic interval $[-1,1]$ by using the transform function 47 : 48 : $$ 49 : x(t) = \frac{t-(a+b)/2} 50 : {(b-a)/2} 51 : $$ 52 : 53 : The Chebyshev polynomials are given by the recurrence relation 54 : 55 : $$ 56 : \begin{aligned} 57 : T_{0}(x) &= 1 \\ 58 : T_{1}(x) &= x \\ 59 : T_{n+1}(x) &= 2 \, x \, T_{n}(x) - T_{n-1}(x) 60 : \end{aligned} 61 : $$ 62 : 63 : The first 6 polynomials are shown below 64 : 65 :  66 : 67 : The Chebyshev polynomial are orthogonal over the interval $[-1,1]$ 68 : with respect to the weight $\frac{1}{\sqrt{1-x^2}}$ 69 : 70 : $$ 71 : \int_{-1}^{1} dx \, T_{n}(x)\, T_{m}(x) \, \frac{1}{\sqrt{1-x^2}} = 72 : \begin{cases} 73 : 0 & n \neq m \\ 74 : \pi & n = m = 0 \\ 75 : \pi/2 & n = m \neq 0 76 : \end{cases} 77 : $$ 78 : 79 : For further mathematical properties of the Chebyshev polynomials see for example 80 : the [Wikipedia page](https://en.wikipedia.org/wiki/Chebyshev_polynomials). 81 : 82 : ## Examples 83 : 84 : Here we employ a Chebyshev expansion of order 20 over the interval 0.0 to 10.0. 85 : This results in a total number of 21 basis functions. 86 : The label used to identify the basis function action can then be 87 : referenced later on in the input file. 88 : 89 : ```plumed 90 : bfC: BF_CHEBYSHEV MINIMUM=0.0 MAXIMUM=10.0 ORDER=20 91 : ``` 92 : 93 : */ 94 : //+ENDPLUMEDOC 95 : 96 : 97 : class BF_Chebyshev : public BasisFunctions { 98 : void setupUniformIntegrals() override; 99 : public: 100 : static void registerKeywords(Keywords&); 101 : explicit BF_Chebyshev(const ActionOptions&); 102 : void getAllValues(const double, double&, bool&, std::vector<double>&, std::vector<double>&) const override; 103 : }; 104 : 105 : 106 : PLUMED_REGISTER_ACTION(BF_Chebyshev,"BF_CHEBYSHEV") 107 : 108 : 109 6 : void BF_Chebyshev::registerKeywords(Keywords& keys) { 110 6 : BasisFunctions::registerKeywords(keys); 111 6 : } 112 : 113 4 : BF_Chebyshev::BF_Chebyshev(const ActionOptions&ao): 114 4 : PLUMED_VES_BASISFUNCTIONS_INIT(ao) { 115 4 : setNumberOfBasisFunctions(getOrder()+1); 116 8 : setIntrinsicInterval("-1.0","+1.0"); 117 : setNonPeriodic(); 118 : setIntervalBounded(); 119 4 : setType("chebyshev-1st-kind"); 120 4 : setDescription("Chebyshev polynomials of the first kind"); 121 4 : setLabelPrefix("T"); 122 4 : setupBF(); 123 4 : checkRead(); 124 4 : } 125 : 126 : 127 7882 : void BF_Chebyshev::getAllValues(const double arg, double& argT, bool& inside_range, std::vector<double>& values, std::vector<double>& derivs) const { 128 : // plumed_assert(values.size()==numberOfBasisFunctions()); 129 : // plumed_assert(derivs.size()==numberOfBasisFunctions()); 130 7882 : inside_range=true; 131 7882 : argT=translateArgument(arg, inside_range); 132 7882 : std::vector<double> derivsT(derivs.size()); 133 : // 134 7882 : values[0]=1.0; 135 7882 : derivsT[0]=0.0; 136 7882 : derivs[0]=0.0; 137 7882 : values[1]=argT; 138 7882 : derivsT[1]=1.0; 139 7882 : derivs[1]=intervalDerivf(); 140 135100 : for(unsigned int i=1; i < getOrder(); i++) { 141 127218 : values[i+1] = 2.0*argT*values[i]-values[i-1]; 142 127218 : derivsT[i+1] = 2.0*values[i]+2.0*argT*derivsT[i]-derivsT[i-1]; 143 127218 : derivs[i+1] = intervalDerivf()*derivsT[i+1]; 144 : } 145 7882 : if(!inside_range) { 146 2024 : for(unsigned int i=0; i<derivs.size(); i++) { 147 1922 : derivs[i]=0.0; 148 : } 149 : } 150 7882 : } 151 : 152 : 153 3 : void BF_Chebyshev::setupUniformIntegrals() { 154 56 : for(unsigned int i=0; i<numberOfBasisFunctions(); i++) { 155 53 : double io = i; 156 : double value = 0.0; 157 53 : if(i % 2 == 0) { 158 28 : value = -2.0/( pow(io,2.0)-1.0)*0.5; 159 : } 160 : setUniformIntegral(i,value); 161 : } 162 3 : } 163 : 164 : 165 : } 166 : }