Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2016-2018 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_SINE
32 : /*
33 : Fourier sine basis functions.
34 :
35 : Use as basis functions Fourier sine series defined on a periodic interval.
36 : You need to provide the periodic interval \f$[a,b]\f$
37 : on which the basis functions are to be used, and the order of the
38 : expansion \f$N\f$ (i.e. the highest Fourier sine mode used).
39 : The total number of basis functions is \f$N+1\f$ as
40 : the constant \f$f_{0}(x)=1\f$ is also included.
41 : These basis functions should only be used for periodic CVs.
42 : They can be useful if the periodic function being expanded is an
43 : odd function, i.e. \f$F(-x)=-F(x)\f$.
44 :
45 : The Fourier sine basis functions are given by
46 : \f{align}{
47 : f_{0}(x) &= 1 \\
48 : f_{1}(x) &= sin(\frac{2\pi }{P} x) \\
49 : f_{2}(x) &= sin(2 \cdot \frac{2\pi}{P} x) \\
50 : f_{3}(x) &= sin(3 \cdot \frac{2\pi}{P} x) \\
51 : & \vdots \\
52 : f_{n}(x) &= sin(n \cdot \frac{2\pi}{P} x) \\
53 : & \vdots \\
54 : f_{N}(x) &= sin(N \cdot \frac{2\pi}{P} x) \\
55 : \f}
56 : where \f$P=(b-a)\f$ is the periodicity of the interval.
57 : They are orthogonal over the interval \f$[a,b]\f$
58 : \f[
59 : \int_{a}^{b} dx \, f_{n}(x)\, f_{m}(x) =
60 : \begin{cases}
61 : 0 & n \neq m \\
62 : (b-a) & n = m = 0 \\
63 : (b-a)/2 & n = m \neq 0
64 : \end{cases}.
65 : \f]
66 :
67 : \par Examples
68 :
69 : Here we employ a Fourier sine expansion of order 10 over the periodic interval
70 : \f$-\pi\f$ to \f$+\pi\f$.
71 : This results in a total number of 11 basis functions.
72 : The label used to identify the basis function action can then be
73 : referenced later on in the input file.
74 : \plumedfile
75 : BF_SINE MINIMUM=-pi MAXIMUM=+pi ORDER=10 LABEL=bfS
76 : \endplumedfile
77 :
78 : \par Examples
79 :
80 : */
81 : //+ENDPLUMEDOC
82 :
83 4 : class BF_Sine : public BasisFunctions {
84 : virtual void setupLabels();
85 : virtual void setupUniformIntegrals();
86 : public:
87 : static void registerKeywords(Keywords&);
88 : explicit BF_Sine(const ActionOptions&);
89 : void getAllValues(const double, double&, bool&, std::vector<double>&, std::vector<double>&) const;
90 : };
91 :
92 :
93 6456 : PLUMED_REGISTER_ACTION(BF_Sine,"BF_SINE")
94 :
95 :
96 5 : void BF_Sine::registerKeywords(Keywords& keys) {
97 5 : BasisFunctions::registerKeywords(keys);
98 5 : }
99 :
100 :
101 4 : BF_Sine::BF_Sine(const ActionOptions&ao):
102 4 : PLUMED_VES_BASISFUNCTIONS_INIT(ao)
103 : {
104 4 : setNumberOfBasisFunctions(getOrder()+1);
105 12 : setIntrinsicInterval("-pi","+pi");
106 : setPeriodic();
107 : setIntervalBounded();
108 8 : setType("trigonometric_sin");
109 8 : setDescription("Sine");
110 4 : setupBF();
111 4 : checkRead();
112 4 : }
113 :
114 :
115 9829 : void BF_Sine::getAllValues(const double arg, double& argT, bool& inside_range, std::vector<double>& values, std::vector<double>& derivs) const {
116 : // plumed_assert(values.size()==numberOfBasisFunctions());
117 : // plumed_assert(derivs.size()==numberOfBasisFunctions());
118 9829 : inside_range=true;
119 9829 : argT=translateArgument(arg, inside_range);
120 9829 : values[0]=1.0;
121 9829 : derivs[0]=0.0;
122 206409 : for(unsigned int i=1; i < getOrder()+1; i++) {
123 98290 : double io = i;
124 98290 : double cos_tmp = cos(io*argT);
125 98290 : double sin_tmp = sin(io*argT);
126 196580 : values[i] = sin_tmp;
127 196580 : derivs[i] = io*cos_tmp*intervalDerivf();
128 : }
129 9829 : if(!inside_range) {
130 2800 : for(unsigned int i=0; i<derivs.size(); i++) {derivs[i]=0.0;}
131 : }
132 9829 : }
133 :
134 :
135 4 : void BF_Sine::setupLabels() {
136 8 : setLabel(0,"1");
137 84 : for(unsigned int i=1; i < getOrder()+1; i++) {
138 40 : std::string is; Tools::convert(i,is);
139 120 : setLabel(i,"sin("+is+"*s)");
140 : }
141 4 : }
142 :
143 :
144 3 : void BF_Sine::setupUniformIntegrals() {
145 : setAllUniformIntegralsToZero();
146 : setUniformIntegral(0,1.0);
147 3 : }
148 :
149 :
150 : }
151 4839 : }
|