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-2021 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 
87  const labelList& faceCells = patch_.faceCells();
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_.patch().localPoints();
174 }
175 
176 
179 (
180  label seed,
181  bool gaussian
182 ) const
183 {
184  auto tfld = tmp<scalarField>::New(this->size());
185 
186  exprDriver::fill_random(tfld.ref(), seed, gaussian);
187 
188  return tfld;
189 }
190 
191 
192 // ************************************************************************* //
Foam::topoSetSource::sourceType
sourceType
Enumeration defining the types of sources.
Definition: topoSetSource.H:74
Foam::expressions::patchExpr::parseDriver::field_pointField
tmp< vectorField > field_pointField() const
The patch point locations - (swak = pts)
Definition: patchExprDriverFields.C:171
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
patchExprDriver.H
Foam::expressions::patchExpr::parseDriver::field_faceSelection
tmp< boolField > field_faceSelection(const word &name, enum topoSetSource::sourceType setType) const
Face selections (as logical)
Definition: patchExprDriverFields.C:105
Foam::expressions::patchExpr::parseDriver::field_faceArea
tmp< scalarField > field_faceArea() const
The face area magnitudes [magSf] - (swak = area)
Definition: patchExprDriverFields.C:150
Foam::HashSet< label, Hash< label > >
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
error.H
Foam::expressions::patchExpr::parseDriver::field_areaNormal
tmp< vectorField > field_areaNormal() const
The face areas with their vector direction [Sf] - (swak = face)
Definition: patchExprDriverFields.C:164
Foam::expressions::exprDriver::fill_random
void fill_random(scalarField &field, label seed=0, const bool gaussian=false) const
Fill a random field.
Definition: exprDriverFields.C:36
Foam::expressions::patchExpr::parseDriver::field_rand
tmp< scalarField > field_rand(label seed=0, bool gaussian=false) const
A uniform random field.
Definition: patchExprDriverFields.C:179
Foam::FatalError
error FatalError
Foam::expressions::patchExpr::parseDriver::field_faceCentre
tmp< vectorField > field_faceCentre() const
The face centres - (swak = pos)
Definition: patchExprDriverFields.C:157
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::expressions::patchExpr::parseDriver::field_cellSelection
tmp< boolField > field_cellSelection(const word &name, enum topoSetSource::sourceType setType) const
Cell selections (as logical)
Definition: patchExprDriverFields.C:60
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< label >
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
fvPatch.H
Foam::fvPatch::magSf
const scalarField & magSf() const
Return face area magnitudes.
Definition: fvPatch.C:156
Foam::expressions::patchExpr::parseDriver::patch_
const fvPatch & patch_
The referenced patch.
Definition: patchExprDriver.H:178
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56
Foam::refPtr
A class for managing references or pointers (no reference counting)
Definition: PtrList.H:60