rigidBodySectionalForceGraph.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) 2026 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 
28 #include "OSspecific.H"
29 #include "patchCutPlot.H"
30 #include "setWriter.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
41  (
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 void Foam::functionObjects::rigidBodySectionalForceGraph::clear()
53 {
55 
56  distancesPtr_.clear();
57 }
58 
59 
61 Foam::functionObjects::rigidBodySectionalForceGraph::distances() const
62 {
63  if (!distancesPtr_.valid())
64  {
65  distancesPtr_.set
66  (
68  (
69  patch(),
70  patchPointDistances(),
71  false,
72  nPoints_,
73  nOptimiseIter_,
74  debug,
75  name(),
76  mesh(),
77  formatter_()
78  ).ptr()
79  );
80  }
81 
82  return distancesPtr_();
83 }
84 
85 
86 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
87 
90 (
91  const word& name,
92  const Time& runTime,
93  const dictionary& dict
94 )
95 :
97  distancesPtr_(nullptr),
98  nPoints_(-1),
99  formatter_(nullptr),
100  nOptimiseIter_(-1)
101 {
102  read(dict);
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
107 
110 {}
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
116 (
117  const dictionary& dict
118 )
119 {
121 
122  nPoints_ = dict.lookup<label>("nPoints");
123 
124  formatter_ = setWriter::New(dict.lookup("setFormat"), dict);
125 
126  nOptimiseIter_ = dict.lookupOrDefault<label>("nOptimiseIter", 2);
127 
128  return true;
129 }
130 
131 
133 {
134  // Get the coordinates
135  tmp<scalarField> tdistances = this->distances();
136  const scalarField& distances = tdistances();
137 
138  // Construct result fields
140  ({
141  "fluidForce",
142  "bodyForce",
143  "totalForce",
144  "fluidMoment",
145  "bodyMoment",
146  "totalMoment"
147  });
148 
149  #define DeclareTypeFieldValues(Type, nullArg) \
150  PtrList<Field<Type>> Type##FieldValues(fieldNames.size());
152  #undef DeclareTypeFieldValues
153 
154  forAll(vectorFieldValues, i)
155  {
156  vectorFieldValues.set
157  (
158  i,
159  new vectorField(distances.size(), vector::zero)
160  );
161  }
162 
163  vectorField& fluidForce = vectorFieldValues[0];
164  vectorField& bodyForce = vectorFieldValues[1];
165  vectorField& totalForce = vectorFieldValues[2];
166  vectorField& fluidMoment = vectorFieldValues[3];
167  vectorField& bodyMoment = vectorFieldValues[4];
168  vectorField& totalMoment = vectorFieldValues[5];
169 
170  // Calculate the fluid contribution
171  rigidBodySectionalForcesBase::addFluid(fluidForce, fluidMoment);
172 
173  // Calculate the body contribution
174  rigidBodySectionalForcesBase::addBody(bodyForce, bodyMoment);
175 
176  // Sum to create total sectional forces and moments
177  totalForce = fluidForce + bodyForce;
178  totalMoment = fluidMoment + bodyMoment;
179 
180  // Write out the graph
181  if (Pstream::master())
182  {
183  mkDir(outputPath());
184 
185  formatter_->write
186  (
187  outputPath(),
188  typeName,
189  coordSet
190  (
191  true,
192  axisName(),
193  distances + localOrigin()[axisi()],
195  ),
196  fieldNames
197  #define TypeFieldValuesParameter(Type, nullArg) , Type##FieldValues
200  );
201  }
202 
203  return true;
204 }
205 
206 
207 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
static const Form zero
Definition: VectorSpace.H:118
Holds list of sampling positions.
Definition: coordSet.H:51
static const NamedEnum< axisType, 6 > axisTypeNames_
String representation of axis enums.
Definition: coordSet.H:69
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
rigidBodySectionalForceGraph(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual bool write()
Write the rigidBodySectionalForceGraph.
virtual bool read(const dictionary &)
Read the rigidBodySectionalForceGraph data.
Base class for rigid-body sectional forces function objects.
void addFluid(vectorField &force, vectorField &moment) const
Calculate the forces and moments at the cuts.
void addBody(vectorField &force, vectorField &moment) const
Calculate the forces and moments at the cuts.
virtual bool read(const dictionary &)
Read the rigidBodySectionalForcesBase data.
virtual void clear()
Clear the cached weights.
static autoPtr< setWriter > New(const word &writeType, const IOstream::streamFormat writeFormat=IOstream::ASCII, const IOstream::compressionType writeCompression=IOstream::UNCOMPRESSED)
Select given write options.
Definition: setWriter.C:286
A class for managing temporary objects.
Definition: tmp.H:55
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
static List< word > fieldNames
Definition: globalFoam.H:46
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, dictionary)
tmp< scalarField > calcCutXs(const faceList &faces, const Field< vector > &faceAreas, const Field< vector > &faceNormals, const pointField &points, const scalarField &pointXs, const bool interpolate, const label nCuts, const label nIter, const bool debug=false, const word &functionName=word::null, const polyMesh &functionMesh=NullObjectRef< polyMesh >(), const setWriter &functionFormatter=NullObjectRef< setWriter >())
Compute and return evenly-spaced cut coordinates.
Definition: patchCutPlot.C:488
Namespace for OpenFOAM.
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
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:290
FOR_ALL_FIELD_TYPES(makeDimensionedPointFieldFunctions)
Field< vector > vectorField
Specialisation of Field<T> for vector.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
#define TypeFieldValuesParameter(Type, nullArg)
#define DeclareTypeFieldValues(Type, nullArg)
dictionary dict