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 -------------------------------------------------------------------------------
10 License
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 
26 Application
27  lumpedPointForces
28 
29 Description
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"
42 #include "lumpedPointIOMovement.H"
43 
44 using namespace Foam;
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 template<class GeoFieldType>
49 autoPtr<GeoFieldType> loadField
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  (
62  IOobject
63  (
64  io->name(),
65  io->instance(),
66  io->local(),
67  io->db(),
70  io->registerObject()
71  ),
72  mesh
73  );
74  }
75 
76  return nullptr;
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 
82 int main(int argc, char *argv[])
83 {
85  (
86  "Extract force/moment information from simulation results that"
87  " use the lumped points movement description."
88  );
89 
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 
107 
108  #include "createNamedMesh.H"
109 
111 
112  if (!movement)
113  {
114  Info<< "No valid movement found" << endl;
115  return 1;
116  }
117 
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  (
165  outputName,
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 // ************************************************************************* //
Foam::autoPtr::New
static autoPtr< T > New(Args &&... args)
volFields.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:165
Foam::IOobject::AUTO_WRITE
@ AUTO_WRITE
Definition: IOobject.H:190
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::lumpedPointTools::setPatchControls
label setPatchControls(const pointVectorField &pvf, const pointField &points0)
Definition: lumpedPointTools.C:172
Foam::IOobject::registerObject
bool registerObject() const noexcept
Definition: IOobjectI.H:100
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:773
Foam::argList::addNote
static void addNote(const string &note)
Definition: argList.C:405
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Definition: UPstream.H:453
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
Foam::fvMesh::readUpdate
virtual readUpdateState readUpdate()
Definition: fvMesh.C:641
outputName
word outputName("finiteArea-edges.obj")
Foam::argList::noFunctionObjects
static void noFunctionObjects(bool addWithOption=false)
Definition: argList.C:466
nPatches
const label nPatches
Definition: printMeshSummary.H:24
Foam::TimeState::timeIndex
label timeIndex() const noexcept
Definition: TimeStateI.H:30
lumpedPointTools.H
Foam::Info
messageStream Info
Foam::IOobject::local
const fileName & local() const noexcept
Definition: IOobjectI.H:201
argList.H
addRegionOption.H
foamVtkSeriesWriter.H
Foam::IOobject::headerClassName
const word & headerClassName() const noexcept
Definition: IOobjectI.H:76
createNamedMesh.H
Required Variables.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::vtk::seriesWriter
Provides a means of accumulating and generating VTK file series.
Definition: foamVtkSeriesWriter.H:71
Foam::vtk::seriesWriter::write
static void write(const fileName &base, const UList< instant > &series, const char sep='_')
Definition: foamVtkSeriesWriter.C:226
Foam
Definition: atmBoundaryLayer.C:26
lumpedPointIOMovement.H
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:51
Foam::IOobject::name
const word & name() const noexcept
Definition: IOobjectI.H:58
Foam::argList::addBoolOption
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Definition: argList.C:317
Time.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:49
setRootCase.H
Foam::objectRegistry::findObject
const Type * findObject(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:394
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::vtk::seriesWriter::size
label size() const noexcept
Definition: foamVtkSeriesWriterI.H:29
Foam::timeSelector::addOptions
static void addOptions(const bool constant=true, const bool withZero=false)
Definition: timeSelector.C:95
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:58
Foam::Time::setTime
virtual void setTime(const Time &t)
Definition: Time.C:996
timeSelector.H
createTime.H
Foam::IOobject::instance
const fileName & instance() const noexcept
Definition: IOobjectI.H:189
Foam::word::printf
static word printf(const char *fmt, const PrimitiveType &val)
Foam::vtk::seriesWriter::append
bool append(const fileNameInstant &inst)
Definition: foamVtkSeriesWriterI.H:42
Foam::timeSelector::select0
static instantList select0(Time &runTime, const argList &args)
Definition: timeSelector.C:228
args
Foam::argList args(argc, argv)
Foam::GeoMesh< fvMesh >::Mesh
fvMesh Mesh
Definition: GeoMesh.H:56
Foam::lumpedPointIOMovement::New
static autoPtr< lumpedPointIOMovement > New(const objectRegistry &obr, label ownerId=-1)
Definition: lumpedPointIOMovement.C:46
Foam::argList::found
bool found(const word &optName) const
Definition: argListI.H:171
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:181
Foam::IOobject::db
const objectRegistry & db() const noexcept
Definition: IOobject.C:480