tetherPotentialList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "tetherPotentialList.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 void Foam::tetherPotentialList::readTetherPotentialDict
31 (
32  const List<word>& siteIdList,
33  const dictionary& tetherPotentialDict,
34  const List<word>& tetherSiteIdList
35 )
36 {
37 
38  Info<< nl << "Building tether potentials." << endl;
39 
40  idMap_ = List<label>(siteIdList.size(), -1);
41 
42  label tetherMapIndex = 0;
43 
44  forAll(tetherSiteIdList, t)
45  {
46  word tetherPotentialName = tetherSiteIdList[t];
47 
48  label tetherId = findIndex(siteIdList, tetherPotentialName);
49 
50  if (tetherId == -1)
51  {
53  << nl
54  << "No matching entry found in siteIdList for tether name "
55  << tetherPotentialName
56  << abort(FatalError);
57  }
58  else if (!tetherPotentialDict.found(tetherPotentialName))
59  {
61  << nl << "tether potential specification subDict "
62  << tetherPotentialName << " not found"
63  << abort(FatalError);
64  }
65  else
66  {
67  this->set
68  (
69  tetherMapIndex,
71  (
72  tetherPotentialName,
73  tetherPotentialDict.subDict(tetherPotentialName)
74  )
75  );
76  }
77 
78  idMap_[tetherId] = tetherMapIndex;
79 
80  tetherMapIndex++;
81  }
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
88 :
90  idMap_()
91 {}
92 
93 
95 (
96  const List<word>& siteIdList,
97  const dictionary& tetherPotentialDict,
98  const List<word>& tetherSiteIdList
99 )
100 :
102  idMap_()
103 {
104  buildPotentials(siteIdList, tetherPotentialDict, tetherSiteIdList);
105 }
106 
107 
108 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
109 
111 {}
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
117 (
118  const List<word>& siteIdList,
119  const dictionary& tetherPotentialDict,
120  const List<word>& tetherSiteIdList
121 )
122 {
123  setSize(tetherSiteIdList.size());
124 
125  readTetherPotentialDict(siteIdList, tetherPotentialDict, tetherSiteIdList);
126 }
127 
128 
130 (
131  const label a
132 ) const
133 {
134  return (*this)[tetherPotentialIndex(a)];
135 }
136 
137 
139 (
140  const label a,
141  const vector rIT
142 ) const
143 {
144  return (*this)[tetherPotentialIndex(a)].force(rIT);
145 }
146 
147 
149 (
150  const label a,
151  const vector rIT
152 ) const
153 {
154  return (*this)[tetherPotentialIndex(a)].energy(rIT);
155 }
156 
157 
158 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
scalar energy(const label a, const vector rIT) const
vector force(const label a, const vector rIT) const
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
static autoPtr< tetherPotential > New(const word &name, const dictionary &tetherPotentialProperties)
Return a reference to the selected viscosity model.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
const tetherPotential & tetherPotentialFunction(const label a) const
static const char nl
Definition: Ostream.H:265
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
void buildPotentials(const List< word > &siteIdList, const dictionary &tetherPotentialDict, const List< word > &tetherSiteIdList)
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
messageStream Info