1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "pairPotential.H"
27 #include "energyScalingFunction.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(pairPotential, 0);
34 defineRunTimeSelectionTable(pairPotential, dictionary);
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 void Foam::pairPotential::scaleEnergy(scalar& e, const scalar r) const
45 esfPtr_ = energyScalingFunction::New
47 name_, pairPotentialProperties_, *this
51 esfPtr_->scaleEnergy(e, r);
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 Foam::pairPotential::pairPotential
60 const dictionary& pairPotentialProperties
64 pairPotentialProperties_(pairPotentialProperties),
65 rCut_(readScalar(pairPotentialProperties_.lookup("rCut"))),
66 rCutSqr_(rCut_*rCut_),
67 rMin_(readScalar(pairPotentialProperties_.lookup("rMin"))),
68 dr_(readScalar(pairPotentialProperties_.lookup("dr"))),
72 writeTables_(Switch(pairPotentialProperties_.lookup("writeTables")))
76 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
78 void Foam::pairPotential::setLookupTables()
80 label N = label((rCut_ - rMin_)/dr_) + 1;
82 forceLookup_.setSize(N);
84 energyLookup_.setSize(N);
86 forAll(forceLookup_, k)
88 energyLookup_[k] = scaledEnergy(k*dr_ + rMin_);
90 forceLookup_[k] = -energyDerivative((k*dr_ + rMin_), true);
95 Foam::scalar Foam::pairPotential::force(const scalar r) const
97 scalar k_rIJ = (r - rMin_)/dr_;
99 label k = label(k_rIJ);
103 FatalErrorIn("pairPotential.C") << nl
104 << "r less than rMin in pair potential " << name_ << nl
105 << abort(FatalError);
109 (k_rIJ - k)*forceLookup_[k+1]
110 + (k + 1 - k_rIJ)*forceLookup_[k];
116 Foam::List< Foam::Pair< Foam::scalar > >
117 Foam::pairPotential::forceTable() const
119 List<Pair<scalar> > forceTab(forceLookup_.size());
121 forAll(forceLookup_,k)
123 forceTab[k].first() = rMin_ + k*dr_;
125 forceTab[k].second() = forceLookup_[k];
132 Foam::scalar Foam::pairPotential::energy(const scalar r) const
134 scalar k_rIJ = (r - rMin_)/dr_;
136 label k = label(k_rIJ);
140 FatalErrorIn("pairPotential.C") << nl
141 << "r less than rMin in pair potential " << name_ << nl
142 << abort(FatalError);
146 (k_rIJ - k)*energyLookup_[k+1]
147 + (k + 1 - k_rIJ)*energyLookup_[k];
153 Foam::List< Foam::Pair< Foam::scalar > >
154 Foam::pairPotential::energyTable() const
156 List<Pair<scalar> > energyTab(energyLookup_.size());
158 forAll(energyLookup_,k)
160 energyTab[k].first() = rMin_ + k*dr_;
162 energyTab[k].second() = energyLookup_[k];
169 Foam::scalar Foam::pairPotential::scaledEnergy(const scalar r) const
171 scalar e = unscaledEnergy(r);
179 Foam::scalar Foam::pairPotential::energyDerivative
182 const bool scaledEnergyDerivative
185 // Local quadratic fit to energy: E = a0 + a1*r + a2*r^2
186 // Differentiate to give f = -dE/dr = -a1 - 2*a2*r
194 if (scaledEnergyDerivative)
196 Ea = scaledEnergy(ra);
197 Ef = scaledEnergy(rf);
198 Eb = scaledEnergy(rb);
202 Ea = unscaledEnergy(ra);
203 Ef = unscaledEnergy(rf);
204 Eb = unscaledEnergy(rb);
207 scalar denominator = (ra - rf)*(ra - rb)*(rf - rb);
211 rb*rb*(Ea - Ef) + ra*ra*(Ef - Eb) + rf*rf*(Eb - Ea)
216 rb*(Ef - Ea) + rf*(Ea - Eb) + ra*(Eb - Ef)
219 return a1 + 2.0*a2*r;
223 bool Foam::pairPotential::read(const dictionary& pairPotentialProperties)
225 pairPotentialProperties_ = pairPotentialProperties;
231 // ************************************************************************* //