1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "pairPotential.H"
28 #include "energyScalingFunction.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(pairPotential, 0);
38 defineRunTimeSelectionTable(pairPotential, dictionary);
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 void Foam::pairPotential::scaleEnergy(scalar& e, const scalar r) const
47 esfPtr_ = energyScalingFunction::New
49 name_, pairPotentialProperties_, *this
53 esfPtr_->scaleEnergy(e, r);
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 Foam::pairPotential::pairPotential
62 const dictionary& pairPotentialProperties
66 pairPotentialProperties_(pairPotentialProperties),
67 rCut_(readScalar(pairPotentialProperties_.lookup("rCut"))),
68 rCutSqr_(rCut_*rCut_),
69 rMin_(readScalar(pairPotentialProperties_.lookup("rMin"))),
70 dr_(readScalar(pairPotentialProperties_.lookup("dr"))),
74 writeTables_(Switch(pairPotentialProperties_.lookup("writeTables")))
78 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
80 void Foam::pairPotential::setLookupTables()
82 label N = label((rCut_ - rMin_)/dr_) + 1;
84 forceLookup_.setSize(N);
86 energyLookup_.setSize(N);
88 forAll(forceLookup_, k)
90 energyLookup_[k] = scaledEnergy(k*dr_ + rMin_);
92 forceLookup_[k] = -energyDerivative((k*dr_ + rMin_), true);
97 Foam::scalar Foam::pairPotential::forceLookup(const scalar r) const
99 scalar k_rIJ = (r - rMin_)/dr_;
105 FatalErrorIn("pairPotential.C") << nl
106 << "r less than rMin" << nl
107 << abort(FatalError);
111 (k_rIJ - k)*forceLookup_[k+1]
112 + (k + 1 - k_rIJ)*forceLookup_[k];
118 Foam::List< Foam::Pair< Foam::scalar > >
119 Foam::pairPotential::forceTable() const
121 List<Pair<scalar> > forceTab(forceLookup_.size());
123 forAll(forceLookup_,k)
125 forceTab[k].first() = rMin_ + k*dr_;
127 forceTab[k].second() = forceLookup_[k];
134 Foam::scalar Foam::pairPotential::energyLookup(const scalar r) const
136 scalar k_rIJ = (r - rMin_)/dr_;
142 FatalErrorIn("pairPotential.C") << nl
143 << "r less than rMin" << nl
144 << abort(FatalError);
148 (k_rIJ - k)*energyLookup_[k+1]
149 + (k + 1 - k_rIJ)*energyLookup_[k];
155 Foam::List< Foam::Pair< Foam::scalar > >
156 Foam::pairPotential::energyTable() const
158 List<Pair<scalar> > energyTab(energyLookup_.size());
160 forAll(energyLookup_,k)
162 energyTab[k].first() = rMin_ + k*dr_;
164 energyTab[k].second() = energyLookup_[k];
171 Foam::scalar Foam::pairPotential::scaledEnergy(const scalar r) const
173 scalar e = unscaledEnergy(r);
181 Foam::scalar Foam::pairPotential::energyDerivative
184 const bool scaledEnergyDerivative
187 // Local quadratic fit to energy: E = a0 + a1*r + a2*r^2
188 // Differentiate to give f = -dE/dr = -a1 - 2*a2*r
196 if (scaledEnergyDerivative)
198 Ea = scaledEnergy(ra);
199 Ef = scaledEnergy(rf);
200 Eb = scaledEnergy(rb);
204 Ea = unscaledEnergy(ra);
205 Ef = unscaledEnergy(rf);
206 Eb = unscaledEnergy(rb);
209 scalar denominator = (ra - rf)*(ra - rb)*(rf - rb);
213 rb*rb*(Ea - Ef) + ra*ra*(Ef - Eb) + rf*rf*(Eb - Ea)
218 rb*(Ef - Ea) + rf*(Ea - Eb) + ra*(Eb - Ef)
221 return a1 + 2.0*a2*r;
225 bool Foam::pairPotential::read(const dictionary& pairPotentialProperties)
227 pairPotentialProperties_ = pairPotentialProperties;
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 } // End namespace Foam
237 // ************************************************************************* //