interfaceHeight.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) 2017-2025 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 "interfaceHeight.H"
27 #include "fvMesh.H"
28 #include "interpolation.H"
29 #include "IOmanip.H"
30 #include "lineCellFace.H"
31 #include "Time.H"
33 #include "volFields.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 namespace functionObjects
41 {
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::functionObjects::interfaceHeight::writePositions()
51 {
52  const uniformDimensionedVectorField& g =
53  mesh_.lookupObject<uniformDimensionedVectorField>("g");
54  const vector gHat = g.value()/mag(g.value());
55 
56  const volScalarField& alpha =
57  mesh_.lookupObject<volScalarField>(alphaName_);
58 
59  autoPtr<interpolation<scalar>>
60  interpolator
61  (
62  interpolation<scalar>::New(interpolationScheme_, alpha)
63  );
64 
65  if (Pstream::master())
66  {
67  writeTime(file(fileID::heightFile));
68  writeTime(file(fileID::positionFile));
69  }
70 
71  forAll(locations_, li)
72  {
73  // Create a set along a ray projected in the direction of gravity
74  const sampledSets::lineCellFace set
75  (
76  "",
77  mesh_,
79  locations_[li] + gHat*mesh_.bounds().mag(),
80  locations_[li] - gHat*mesh_.bounds().mag()
81  );
82 
83  // Find the height of the location above the boundary
84  scalar hLB =
85  set.size()
86  ? - gHat & (locations_[li] - set.coords().pointCoord(0))
87  : - vGreat;
88  reduce(hLB, maxOp<scalar>());
89 
90  // Calculate the integrals of length and length*alpha along the sampling
91  // line. The latter is equal to the equivalent length with alpha equal
92  // to one.
93  scalar sumLength = 0, sumLengthAlpha = 0;
94  for (label si = 0; si < set.size() - 1; ++ si)
95  {
96  if (set.segments()[si] != set.segments()[si+1]) continue;
97 
98  const vector& p0 = set.coords().pointCoord(si);
99  const vector& p1 = set.coords().pointCoord(si+1);
100  const label c0 = set.cells()[si], c1 = set.cells()[si+1];
101  const label f0 = set.faces()[si], f1 = set.faces()[si+1];
102 
103  if (f0 != -1 && f1 != -1) continue;
104 
105  const scalar a0 = interpolator->interpolate(p0, c0, f0);
106  const scalar a1 = interpolator->interpolate(p1, c1, f1);
107 
108  const scalar l = - gHat & (p1 - p0);
109  sumLength += l;
110  sumLengthAlpha += l*(a0 + a1)/2;
111  }
112 
113  reduce(sumLength, sumOp<scalar>());
114  reduce(sumLengthAlpha, sumOp<scalar>());
115 
116  // Write out
117  if (Pstream::master())
118  {
119  // Interface heights above the boundary and location
120  const scalar hIB =
121  liquid_ ? sumLengthAlpha : sumLength - sumLengthAlpha;
122  const scalar hIL = hIB - hLB;
123 
124  // Position of the interface
125  const point p = locations_[li] - gHat*hIL;
126 
127  const Foam::Omanip<int> w = valueWidth(1);
128 
129  file(fileID::heightFile) << w << hIB << w << hIL;
130  file(fileID::positionFile) << '(' << w << p.x() << w << p.y()
131  << valueWidth() << p.z() << ") ";
132  }
133  }
134 
135  if (Pstream::master())
136  {
137  file(fileID::heightFile).endl();
138  file(fileID::positionFile).endl();
139  }
140 }
141 
142 
143 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
144 
146 {
147  forAll(locations_, li)
148  {
149  writeHeaderValue
150  (
151  file(i),
152  "Location " + Foam::name(li),
153  locations_[li]
154  );
155  }
156 
157  switch (fileID(i))
158  {
159  case fileID::heightFile:
160  writeHeaderValue
161  (
162  file(i),
163  "hB",
164  "Interface height above the boundary"
165  );
166  writeHeaderValue
167  (
168  file(i),
169  "hL",
170  "Interface height above the location"
171  );
172  break;
173  case fileID::positionFile:
174  writeHeaderValue(file(i), "p", "Interface position");
175  break;
176  }
177 
178  const Foam::Omanip<int> w = valueWidth(1);
179 
180  writeCommented(file(i), "Location");
181  forAll(locations_, li)
182  {
183  switch (fileID(i))
184  {
185  case fileID::heightFile:
186  file(i) << w << li << w << ' ';
187  break;
188  case fileID::positionFile:
189  file(i) << w << li << w << ' ' << w << ' ' << " ";
190  break;
191  }
192  }
193  file(i).endl();
194 
195  writeCommented(file(i), "Time");
196  forAll(locations_, li)
197  {
198  switch (fileID(i))
199  {
200  case fileID::heightFile:
201  file(i) << w << "hB" << w << "hL";
202  break;
203  case fileID::positionFile:
204  file(i) << w << "p" << w << ' ' << w << ' ' << " ";
205  break;
206  }
207  }
208  file(i).endl();
209 }
210 
211 
212 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
213 
215 (
216  const word& name,
217  const Time& runTime,
218  const dictionary& dict
219 )
220 :
221  fvMeshFunctionObject(name, runTime, dict),
222  logFiles(mesh_, name),
223  alphaName_("alpha"),
224  liquid_(true),
225  locations_(),
226  interpolationScheme_("cellPoint")
227 {
228  read(dict);
229 }
230 
231 
232 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
233 
235 {}
236 
237 
238 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
239 
241 {
243 
244  dict.readIfPresent("alpha", alphaName_);
245  dict.readIfPresent("liquid", liquid_);
246  dict.lookup("locations") >> locations_;
247  dict.readIfPresent("interpolationScheme", interpolationScheme_);
248 
249  resetNames({"height", "position"});
250 
251  return true;
252 }
253 
254 
256 {
257  return wordList(alphaName_);
258 }
259 
260 
262 {
263  return true;
264 }
265 
266 
268 {
269  return true;
270 }
271 
272 
274 {
275  logFiles::write();
276 
277  writePositions();
278 
279  return true;
280 }
281 
282 
283 // ************************************************************************* //
Istream and Ostream manipulators taking arguments.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
virtual void endl()=0
Add newline and flush stream.
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
scalar mag() const
The magnitude of the bounding box span.
Definition: boundBoxI.H:124
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.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const fvMesh & mesh_
Reference to the fvMesh.
This function object reports the height of the interface above a set of locations....
interfaceHeight(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual wordList fields() const
Return the list of fields required.
virtual void writeFileHeader(const label i=0)
Output file header information.
virtual bool end()
Execute at the final time-loop.
virtual bool read(const dictionary &)
Read.
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:60
virtual bool write()
Write function.
Definition: logFiles.C:173
virtual bool read(const dictionary &)
Read optional controls.
void writeTime(Ostream &os) const
Write the current time to stream.
Definition: writeFile.C:141
Omanip< int > valueWidth(const label offset=0) const
Return the value width when writing to stream with optional offset.
Definition: writeFile.C:74
static autoPtr< interpolation< Type > > New(const word &interpolationType, const VolField< Type > &psi)
Return a reference to the specified interpolation scheme.
Definition: interpolation.C:53
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:399
A class for handling words, derived from string.
Definition: word.H:63
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
const dimensionedScalar a0
Bohr radius: default SI units: [m].
const dimensionedScalar c1
First radiation constant: default SI units: [W/m^2].
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, dictionary)
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
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
vector point
Point is a vector.
Definition: point.H:41
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:62
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dictionary dict
volScalarField & p
Typedefs for UniformDimensionedField.