initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / lagrangian / molecularDynamics / potential / tetherPotential / derived / restrainedHarmonicSpring / restrainedHarmonicSpring.C
blob5396013a173a973aa7302f5cc07e69889ff61b54
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 "restrainedHarmonicSpring.H"
28 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 namespace Foam
34 namespace tetherPotentials
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(restrainedHarmonicSpring, 0);
41 addToRunTimeSelectionTable
43     tetherPotential,
44     restrainedHarmonicSpring,
45     dictionary
49 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
51 restrainedHarmonicSpring::restrainedHarmonicSpring
53     const word& name,
54     const dictionary& tetherPotentialProperties
57     tetherPotential(name, tetherPotentialProperties),
58     restrainedHarmonicSpringCoeffs_
59     (
60         tetherPotentialProperties.subDict(typeName + "Coeffs")
61     ),
62     springConstant_
63     (
64         readScalar(restrainedHarmonicSpringCoeffs_.lookup("springConstant"))
65     ),
66     rR_
67     (
68         readScalar(restrainedHarmonicSpringCoeffs_.lookup("rR"))
69     )
72 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
74 scalar restrainedHarmonicSpring::energy(const vector r) const
76     scalar magR = mag(r);
78     if (magR < rR_)
79     {
80         return 0.5 * springConstant_ * magSqr(r);
81     }
82     else
83     {
84         return 0.5 * springConstant_ * rR_ * rR_
85           + springConstant_ * rR_ * (magR - rR_);
86     }
90 vector restrainedHarmonicSpring::force(const vector r) const
92     scalar magR = mag(r);
94     if (magR < rR_)
95     {
96         return -springConstant_ * r;
97     }
98     else
99     {
100         return -springConstant_ * rR_ * r / magR;
101     }
105 bool restrainedHarmonicSpring::read
107     const dictionary& tetherPotentialProperties
110     tetherPotential::read(tetherPotentialProperties);
112     restrainedHarmonicSpringCoeffs_ =
113         tetherPotentialProperties.subDict(typeName + "Coeffs");
115     restrainedHarmonicSpringCoeffs_.lookup("springConstant") >> springConstant_;
116     restrainedHarmonicSpringCoeffs_.lookup("rR") >> rR_;
118     return true;
122 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 } // End namespace tetherPotentials
125 } // End namespace Foam
127 // ************************************************************************* //