surfaceToVolVelocity.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) 2022-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 "surfaceToVolVelocity.H"
27 
28 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
29 
31 (
32  const surfaceVectorField& Uf
33 )
34 {
35  if
36  (
37  Uf.dimensions() != dimVelocity
39  && Uf.dimensions() != dimVelocity/dimTime
41  )
42  {
43  return volVectorField::null();
44  }
45 
46  const word& surfaceName = Uf.name();
47 
48  // Split the name based on non-alphanumeric (and then some) separators
49  DynamicList<word> parts;
50  DynamicList<char> separators;
51  {
52  string::size_type i0 = 0;
53 
54  for (string::size_type i = 0; i < surfaceName.size(); ++ i)
55  {
56  const char c = surfaceName[i];
57 
58  if (isalnum(c) || c == '_' || c == '.') continue;
59 
60  parts.append(surfaceName(i0, i - i0));
61  separators.append(c);
62 
63  i0 = i + 1;
64  }
65 
66  parts.append(surfaceName(i0, surfaceName.size() - i0));
67  }
68 
69  // Convert every part to its equivalent vol name
70  forAll(parts, parti)
71  {
72  word& part = parts[parti];
73 
74  // Find where the groups start
75  word::size_type i = part.find_first_of('.');
76  if (i == word::npos) i = part.size();
77 
78  // Find where the old-time suffixes start
79  while (i > 0 && part(i - 2, 2) == "_0") i -= 2;
80 
81  // We are back to the end of the core field name. If this ends with an
82  // 'f' then this should be removed to form the equivalent vol name.
83  if (i > 0 && part[i - 1] == 'f')
84  {
85  part = word(part(i - 1) + part(i, word::npos));
86  }
87  }
88 
89  // Put the parts back together and return
90  word volName;
91  forAll(separators, parti)
92  {
93  volName += parts[parti] + separators[parti];
94  }
95  volName += parts.last();
96 
97  // If no 'f' suffixes were removed then there is no corresponding vol name
98  if (volName == surfaceName)
99  {
100  return volVectorField::null();
101  }
102 
103  // Return the vol field if it can be found
104  return
105  Uf.mesh().foundObject<volVectorField>(volName)
106  ? Uf.mesh().lookupObject<volVectorField>(volName)
107  : volVectorField::null();
108 }
109 
110 
111 // ************************************************************************* //
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
const dimensionSet & dimensions() const
Return dimensions.
const Mesh & mesh() const
Return mesh.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
Generic GeometricField class.
const word & name() const
Return name.
Definition: IOobject.H:307
T & last()
Return the last element of the list.
Definition: UListI.H:128
A class for handling words, derived from string.
Definition: word.H:62
const dimensionedScalar c
Speed of light in a vacuum.
const dimensionSet dimTime
const dimensionSet dimDensity
const dimensionSet dimVelocity
const volVectorField & surfaceToVolVelocity(const surfaceVectorField &Uf)
Get the cell velocity field corresponding to a given face velocity, or a.
Return the vol-field velocity corresponding to a given surface-field velocity.