patchExprDriverFields.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) 2019-2023 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 \*---------------------------------------------------------------------------*/
27 
28 #include "patchExprDriver.H"
29 #include "fvPatch.H"
30 #include "error.H"
31 
32 // * * * * * * * * * * * * Template Specializations * * * * * * * * * * * * //
33 
34 template<>
36 Foam::expressions::patchExpr::parseDriver::getSurfaceField<bool>
37 (
38  const word& name
39 )
40 {
41  return getVariable<bool>(name, this->size());
42 }
43 
44 
45 template<>
47 Foam::expressions::patchExpr::parseDriver::getPointField<bool>
48 (
49  const word& name
50 )
51 {
52  return getVariable<bool>(name, this->pointSize());
53 }
54 
55 
56 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 
60 (
61  const word& name,
62  enum topoSetSource::sourceType setType
63 ) const
64 {
65  refPtr<labelList> tselected;
66  switch (setType)
67  {
68  case topoSetSource::sourceType::CELLZONE_SOURCE:
69  case topoSetSource::sourceType::CELLSET_SOURCE:
70  {
71  tselected = getTopoSetLabels(name, setType);
72  break;
73  }
74 
75  default:
76  {
78  << "Unexpected sourceType: " << int(setType) << nl
79  << exit(FatalError);
80  break;
81  }
82  }
83 
84  // Not particularly efficient...
85  labelHashSet inSelection(tselected());
86 
88  auto tresult = tmp<boolField>::New(this->size(), false);
89  auto& result = tresult.ref();
90 
91  forAll(result, facei)
92  {
93  if (inSelection.found(faceCells[facei]))
94  {
95  result[facei] = true;
96  }
97  }
98 
99  return tresult;
100 }
101 
102 
105 (
106  const word& name,
107  enum topoSetSource::sourceType setType
108 ) const
109 {
110  refPtr<labelList> tselected;
111  switch (setType)
112  {
113  case topoSetSource::sourceType::FACESET_SOURCE:
114  case topoSetSource::sourceType::FACEZONE_SOURCE:
115  {
116  tselected = getTopoSetLabels(name, setType);
117  break;
118  }
119 
120  default:
121  {
123  << "Unexpected sourceType: " << int(setType) << nl
124  << exit(FatalError);
125  break;
126  }
127  }
128 
129  // Not particularly efficient...
130  labelHashSet inSelection(tselected());
131 
132  const label patchStart = patch_.start();
133 
134  auto tresult = tmp<boolField>::New(this->size(), false);
135  auto& result = tresult.ref();
136 
137  forAll(result, facei)
138  {
139  if (inSelection.found(facei + patchStart))
140  {
141  result[facei] = true;
142  }
143  }
144 
145  return tresult;
146 }
147 
148 
151 {
152  return patch_.magSf();
153 }
154 
155 
158 {
159  return patch_.Cf();
160 }
161 
162 
165 {
166  return patch_.Sf();
167 }
168 
169 
172 {
173  return patch_.nf();
174 }
175 
176 
179 {
180  return patch_.patch().localPoints();
181 }
182 
183 
186 (
187  label seed,
188  bool gaussian
189 ) const
190 {
191  auto tfld = tmp<scalarField>::New(this->size());
192 
193  exprDriver::fill_random(tfld.ref(), seed, gaussian);
194 
195  return tfld;
196 }
197 
198 
199 // ************************************************************************* //
void fill_random(scalarField &field, label seed=0, const bool gaussian=false) const
Fill a random field.
Field< Type > & ref()
Return non-const reference to the field.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
refPtr< labelList > getTopoSetLabels(const word &name, enum topoSetSource::sourceType setType) const
Get the labels associated with the topo set.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
tmp< vectorField > field_pointField() const
The patch point locations - (swak = pts)
tmp< vectorField > field_unitNormal() const
The face unit normal direction [nf] - (expression: normal)
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:52
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
tmp< scalarField > field_faceArea() const
The face area magnitudes [magSf] - (swak = area)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual const labelUList & faceCells() const
Return faceCells.
Definition: fvPatch.C:107
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
const exprResult & result() const noexcept
Const access to expression result.
Definition: exprDriver.H:483
virtual label size() const
The natural field size for the expression.
tmp< vectorField > field_areaNormal() const
The face areas with their vector direction [Sf] - (swak = face)
const fvPatch & patch_
The referenced patch.
sourceType
Enumeration defining the types of sources.
Definition: topoSetSource.H:72
tmp< vectorField > field_faceCentre() const
The face centres - (swak = pos)
tmp< scalarField > field_rand(label seed=0, bool gaussian=false) const
A uniform random field.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
tmp< boolField > field_cellSelection(const word &name, enum topoSetSource::sourceType setType) const
Cell selections (as logical)
tmp< boolField > field_faceSelection(const word &name, enum topoSetSource::sourceType setType) const
Face selections (as logical)