sectionalForceGraph.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 
26 #include "sectionalForceGraph.H"
27 #include "fvMesh.H"
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 }
42 }
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
47 void Foam::functionObjects::sectionalForceGraph::clear()
48 {
50 
51  distancesPtr_.clear();
52 }
53 
54 
55 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
56 
58 {
59  return normal_;
60 }
61 
62 
64 {
65  return origin_;
66 }
67 
68 
71 {
72  if (!distancesPtr_.valid())
73  {
74  distancesPtr_.set
75  (
77  (
78  patch(),
79  patchPointDistances(),
80  false,
81  nPoints_,
82  nOptimiseIter_,
83  debug,
84  name(),
85  mesh(),
86  formatter_()
87  ).ptr()
88  );
89  }
90 
91  return distancesPtr_();
92 }
93 
94 
95 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96 
98 (
99  const word& name,
100  const Time& runTime,
101  const dictionary& dict
102 )
103 :
104  sectionalForcesBase(name, runTime, dict),
105  origin_(vector::uniform(NaN)),
106  distancesPtr_(nullptr),
107  nPoints_(-1),
108  formatter_(nullptr),
109  nOptimiseIter_(-1)
110 {
111  read(dict);
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
116 
118 {}
119 
120 
121 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122 
124 {
126 
127  normal_ = normalised(dict.lookup<vector>("normal"));
128  origin_ = dict.lookupBackwardsCompatible<vector>({"origin", "CofR"});
129 
130  nPoints_ = dict.lookup<label>("nPoints");
131 
132  axis_ =
134  [
135  dict.lookupOrDefault<word>
136  (
137  "axis",
139  )
140  ];
141  formatter_ = setWriter::New(dict.lookup("setFormat"), dict);
142 
143  nOptimiseIter_ = dict.lookupOrDefault<label>("nOptimiseIter", 2);
144 
145  return true;
146 }
147 
148 
150 {
151  // Get the coordinates
152  tmp<scalarField> tdistances = this->distances();
153  const scalarField& distances = tdistances();
154 
155  // Construct result fields
156  wordList fieldNames({"force", "moment"});
157 
158  #define DeclareTypeFieldValues(Type, nullArg) \
159  PtrList<Field<Type>> Type##FieldValues(2);
161  #undef DeclareTypeFieldValues
162 
163  vectorFieldValues.set(0, new vectorField(distances.size(), vector::zero));
164  vectorFieldValues.set(1, new vectorField(distances.size(), vector::zero));
165 
166  vectorField& force = vectorFieldValues[0];
167  vectorField& moment = vectorFieldValues[1];
168 
169  // Add the fluid contribution
171 
172  // Write out the graph
173  if (Pstream::master())
174  {
175  mkDir(outputPath());
176 
177  formatter_->write
178  (
179  outputPath(),
180  typeName,
181  coordSet
182  (
183  identityMap(distances.size()),
184  word::null,
185  origin() + distances*normal_,
187  distances,
189  ),
190  fieldNames
191  #define TypeFieldValuesParameter(Type, nullArg) , Type##FieldValues
194  );
195  }
196 
197  return true;
198 }
199 
200 
201 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
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.
This function calculates the fluid forces and moments at a series of section-planes through a given s...
sectionalForceGraph(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual tmp< scalarField > distances() const
Return the distances from the origin to the section planes.
virtual point origin() const
Return the origin of the plot.
virtual vector normal() const
Return the normal to the section planes.
virtual bool write()
Write the sectionalForceGraph.
virtual bool read(const dictionary &)
Read the sectionalForceGraph data.
Base class for sectional forces function objects.
void addFluid(vectorField &force, vectorField &moment) const
Calculate the forces and moments at the cuts.
virtual void clear()
Clear the cached weights.
virtual bool read(const dictionary &)
Read the sectionalForcesBase data.
Generate a uniform field.
Definition: uniform.H:58
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
static const word null
An empty word.
Definition: word.H:78
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
static List< word > fieldNames
Definition: globalFoam.H:46
const dimensionSet force
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)
dimensionSet normalised(const dimensionSet &)
Definition: dimensionSet.C:509
Field< vector > vectorField
Specialisation of Field<T> for vector.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
dictionary dict
#define TypeFieldValuesParameter(Type, nullArg)
#define DeclareTypeFieldValues(Type, nullArg)