FreeFOAM The Cross-Platform CFD Toolkit
forces.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
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 Class
25  Foam::forces
26 
27 Description
28  Calculates the forces and moments by integrating the pressure and
29  skin-friction forces over a given list of patches.
30 
31  Member function calcForcesMoment()calculates and returns the forces and
32  moments.
33 
34  Member function forces::write() calls calcForcesMoment() and writes the
35  forces and moments into the file <timeDir>/forces.dat
36 
37 SourceFiles
38  forces.C
39  IOforces.H
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef forces_H
44 #define forces_H
45 
48 #include <OpenFOAM/HashSet.H>
49 #include <OpenFOAM/Tuple2.H>
50 #include <OpenFOAM/OFstream.H>
51 #include <OpenFOAM/Switch.H>
52 #include <OpenFOAM/pointFieldFwd.H>
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 
59 // Forward declaration of classes
60 class objectRegistry;
61 class dictionary;
62 class mapPolyMesh;
63 
64 /*---------------------------------------------------------------------------*\
65  Class forces Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class forces
69 {
70 public:
71 
72  // Tuple which holds the pressure (.first()) and viscous (.second) forces
74 
75  // Tuple which holds the forces (.first()) and moment (.second)
76  // pressure/viscous forces Tuples.
78 
79  //- Sum operation class to accumulate the pressure, viscous forces and moments
80  class sumOp
81  {
82  public:
83 
84  forcesMoments operator()
85  (
86  const forcesMoments& fm1,
87  const forcesMoments& fm2
88  ) const
89  {
90  return forcesMoments
91  (
93  (
94  fm1.first().first() + fm2.first().first(),
95  fm1.first().second() + fm2.first().second()
96  ),
98  (
99  fm1.second().first() + fm2.second().first(),
100  fm1.second().second() + fm2.second().second()
101  )
102  );
103  }
104  };
105 
106 
107 protected:
108 
109  // Private data
110 
111  //- Name of this set of forces,
112  // Also used as the name of the probes directory.
114 
116 
117  //- on/off switch
118  bool active_;
119 
120  //- Switch to send output to Info as well as to file
122 
123  // Read from dictionary
124 
125  //- Patches to integrate forces over
127 
128  //- Name of pressure field
130 
131  //- Name of velocity field
133 
134  //- Name of density field (optional)
136 
137  //- Is the force density being supplied directly?
139 
140  //- The name of the force density (fD) field
142 
143  //- Reference density needed for incompressible calculations
144  scalar rhoRef_;
145 
146  //- Reference pressure
147  scalar pRef_;
148 
149  //- Centre of rotation
151 
152 
153  //- Forces/moment file ptr
155 
156 
157  // Private Member Functions
158 
159  //- If the forces file has not been created create it
160  void makeFile();
161 
162  //- Output file header information
163  virtual void writeFileHeader();
164 
165  //- Return the effective viscous stress (laminar + turbulent).
167 
168  //- Return rho if rhoName is specified otherwise rhoRef
169  tmp<volScalarField> rho() const;
170 
171  //- Return rhoRef if the pressure field is dynamic, i.e. p/rho
172  // otherwise return 1
173  scalar rho(const volScalarField& p) const;
174 
175  //- Disallow default bitwise copy construct
176  forces(const forces&);
177 
178  //- Disallow default bitwise assignment
179  void operator=(const forces&);
180 
181 
182 public:
183 
184  //- Runtime type information
185  TypeName("forces");
186 
187 
188  // Constructors
189 
190  //- Construct for given objectRegistry and dictionary.
191  // Allow the possibility to load fields from files
192  forces
193  (
194  const word& name,
195  const objectRegistry&,
196  const dictionary&,
197  const bool loadFromFiles = false
198  );
199 
200 
201  //- Destructor
202  virtual ~forces();
203 
204 
205  // Member Functions
206 
207  //- Return name of the set of forces
208  virtual const word& name() const
209  {
210  return name_;
211  }
212 
213  //- Read the forces data
214  virtual void read(const dictionary&);
215 
216  //- Execute, currently does nothing
217  virtual void execute();
218 
219  //- Execute at the final time-loop, currently does nothing
220  virtual void end();
221 
222  //- Write the forces
223  virtual void write();
224 
225  //- Calculate and return forces and moment
226  virtual forcesMoments calcForcesMoment() const;
227 
228  //- Update for changes of mesh
229  virtual void updateMesh(const mapPolyMesh&)
230  {}
231 
232  //- Update for changes of mesh
233  virtual void movePoints(const pointField&)
234  {}
235 };
236 
237 
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 
240 } // End namespace Foam
241 
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 
244 #endif
245 
246 // ************************ vim: set sw=4 sts=4 et: ************************ //