lumpedPointForces.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2016-2020 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Application
27 lumpedPointForces
28
29Description
30 Extract force/moment information from simulation results that
31 use the lumped points movement description.
32
33\*---------------------------------------------------------------------------*/
34
35#include "argList.H"
36#include "Time.H"
37#include "timeSelector.H"
38#include "volFields.H"
39#include "IOobjectList.H"
40#include "foamVtkSeriesWriter.H"
41#include "lumpedPointTools.H"
43
44using namespace Foam;
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48template<class GeoFieldType>
50(
51 const volMesh::Mesh& mesh,
52 const IOobject* io
53)
54{
55 if (io && io->headerClassName() == GeoFieldType::typeName)
56 {
57 Info<< "Reading " << GeoFieldType::typeName
58 << ' ' << io->name() << endl;
59
61 (
63 (
64 io->name(),
65 io->instance(),
66 io->local(),
67 io->db(),
68 IOobject::MUST_READ,
69 IOobject::AUTO_WRITE,
70 io->registerObject()
71 ),
72 mesh
73 );
74 }
75
76 return nullptr;
77}
78
79
80// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81
82int main(int argc, char *argv[])
83{
84 argList::addNote
85 (
86 "Extract force/moment information from simulation results that"
87 " use the lumped points movement description."
88 );
89
90 argList::addBoolOption
91 (
92 "vtk",
93 "Create visualization files of the forces"
94 );
95
96 timeSelector::addOptions(true, false);
97 argList::noFunctionObjects(); // Never use function objects
98
99 #include "addRegionOption.H"
100 #include "setRootCase.H"
101
102 const bool withVTK = args.found("vtk");
103
104 #include "createTime.H"
105
106 instantList timeDirs = timeSelector::select0(runTime, args);
107
108 #include "createNamedMesh.H"
109
110 autoPtr<lumpedPointIOMovement> movement = lumpedPointIOMovement::New(mesh);
111
112 if (!movement)
113 {
114 Info<< "No valid movement found" << endl;
115 return 1;
116 }
117
118 const label nPatches = lumpedPointTools::setPatchControls(mesh);
119 if (!nPatches)
120 {
121 Info<< "No point patches with lumped movement found" << endl;
122 return 2;
123 }
124
125 Info<<"Lumped point patch controls set on " << nPatches
126 << " patches" << nl;
127
128
129 vtk::seriesWriter forceSeries;
130 List<vector> forces, moments;
131
132 forAll(timeDirs, timei)
133 {
134 runTime.setTime(timeDirs[timei], timei);
135
136 Info<< "Time = " << runTime.timeName() << endl;
137
138 if (mesh.readUpdate())
139 {
140 Info<< " Read new mesh" << nl;
141 }
142
143 // Search for list of objects for this time
144 IOobjectList objects(mesh, runTime.timeName());
145
146 // Pressure field
148 = loadField<volScalarField>(mesh, objects.findObject("p"));
149
150 // The forces per zone
151 if (movement().forcesAndMoments(mesh, forces, moments))
152 {
153 Info<<"forces per zone: " << forces << endl;
154 Info<<"moments per zone: " << moments << endl;
155
156 if (withVTK && Pstream::master())
157 {
158 const word outputName =
159 word::printf("forces_%06d.vtp", runTime.timeIndex());
160
161 Info<<" " << outputName << endl;
162
163 movement().writeForcesAndMomentsVTP
164 (
166 forces,
167 moments
168 );
169
170 forceSeries.append(runTime.timeIndex(), outputName);
171 }
172 }
173 }
174
175
176 // Create file series
177
178 if (forceSeries.size())
179 {
180 forceSeries.write("forces.vtp");
181 }
182
183 Info<< "\nEnd\n" << endl;
184
185 return 0;
186}
187
188// ************************************************************************* //
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:100
Provides a means of accumulating and generating VTK file series.
bool append(const fileNameInstant &inst)
Append the specified file instant.
label size() const noexcept
The number of data sets.
static void write(const fileName &base, const UList< instant > &series, const char sep='_')
Write file series (JSON format) to disk, for specified instances.
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
engineTime & runTime
Required Variables.
word outputName("finiteArea-edges.obj")
const label nPatches
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333