volumeExprDriverFields.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 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 "volumeExprDriver.H"
29 #include "fvPatch.H"
30 #include "error.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
36 (
37  const word& name,
38  enum topoSetSource::sourceType setType
39 ) const
40 {
41  auto tresult = volScalarField::New
42  (
43  "selected",
44  mesh(),
46  );
47 
48  labelList selected;
49  switch (setType)
50  {
51  case topoSetSource::sourceType::CELLZONE_SOURCE:
52  case topoSetSource::sourceType::CELLSET_SOURCE:
53  {
54  selected = getTopoSetLabels(name, setType);
55  break;
56  }
57 
58  default:
59  {
61  << "Unexpected sourceType: " << int(setType) << nl
62  << exit(FatalError);
63  break;
64  }
65  }
66 
67  auto& fld = tresult.ref().primitiveFieldRef();
68  UIndirectList<scalar>(fld, selected) = scalar(1);
69 
70  return tresult;
71 }
72 
73 
76 (
77  const word& name,
78  enum topoSetSource::sourceType setType
79 ) const
80 {
81  auto tresult = surfaceScalarField::New
82  (
83  "selected",
84  mesh(),
86  );
87 
88  labelList selected;
89  switch (setType)
90  {
91  case topoSetSource::sourceType::FACESET_SOURCE:
92  case topoSetSource::sourceType::FACEZONE_SOURCE:
93  {
94  selected = getTopoSetLabels(name, setType);
95  break;
96  }
97 
98  default:
99  {
101  << "Unexpected sourceType: " << int(setType) << nl
102  << exit(FatalError);
103  break;
104  }
105  }
106 
107  const auto& bmesh = mesh().boundaryMesh();
108 
109  auto& result = tresult.ref();
110  auto& fld = result.primitiveFieldRef();
111  auto& bfld = result.boundaryFieldRef();
112 
113  label nErrors = 0;
114 
115  for (const label facei : selected)
116  {
117  if (facei < mesh().nInternalFaces())
118  {
119  fld[facei] = scalar(1);
120  }
121  else
122  {
123  const label patchi = bmesh.whichPatch(facei);
124 
125  if (patchi < 0)
126  {
127  ++nErrors;
128  }
129  else
130  {
131  bfld[patchi][facei-bmesh[patchi].start()] = scalar(1);
132  }
133  }
134  }
135 
136  if (nErrors)
137  {
139  << "The faceSet/faceZone " << name << " contained "
140  << nErrors << " faces outside of the addressing range" << nl
141  << nl;
142  }
143 
144 
145  return tresult;
146 }
147 
148 
151 (
152  const word& name,
153  enum topoSetSource::sourceType setType
154 ) const
155 {
156  auto tresult = pointScalarField::New
157  (
158  "selected",
159  pointMesh::New(mesh()),
161  );
162 
163  labelList selected;
164  switch (setType)
165  {
166  case topoSetSource::sourceType::POINTSET_SOURCE:
167  case topoSetSource::sourceType::POINTZONE_SOURCE:
168  {
169  selected = getTopoSetLabels(name, setType);
170  break;
171  }
172 
173  default:
174  {
176  << "Unexpected sourceType: " << int(setType) << nl
177  << exit(FatalError);
178  break;
179  }
180  }
181 
182  auto& fld = tresult.ref().primitiveFieldRef();
183  UIndirectList<scalar>(fld, selected) = scalar(1);
184 
185  return tresult;
186 }
187 
188 
189 
192 {
193  return volScalarField::New
194  (
195  "vol",
196  mesh(),
197  dimVol,
198  mesh().V()
199  );
200 }
201 
202 
205 {
206  return tmp<volVectorField>::New(mesh().C());
207 }
208 
209 
212 {
214  (
215  "face",
216  mesh(),
217  dimless,
218  mesh().magSf()
219  );
220 }
221 
222 
225 {
227  (
228  "fpos",
229  mesh(),
230  dimless,
231  mesh().Cf()
232  );
233 }
234 
235 
238 {
240  (
241  "face",
242  mesh(),
243  dimless,
244  mesh().Sf()
245  );
246 }
247 
248 
251 {
252  return pointVectorField::New
253  (
254  "pts",
255  pointMesh::New(mesh()),
256  dimless,
257  mesh().points()
258  );
259 }
260 
261 
264 (
265  label seed,
266  bool gaussian
267 ) const
268 {
269  auto tresult = volScalarField::New
270  (
271  "rand",
272  mesh(),
273  dimless
274  );
275  auto& fld = tresult.ref().primitiveFieldRef();
276 
277  fill_random(fld, seed, gaussian);
278 
279  return tresult;
280 }
281 
282 
283 // ************************************************************************* //
Foam::topoSetSource::sourceType
sourceType
Enumeration defining the types of sources.
Definition: topoSetSource.H:73
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::MeshObject< polyMesh, UpdateableMeshObject, pointMesh >::New
static const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new MeshObject.
Definition: MeshObject.C:48
Foam::expressions::volumeExpr::parseDriver::mesh
virtual const fvMesh & mesh() const
The mesh we are attached to.
Definition: volumeExprDriver.H:340
Foam::expressions::volumeExpr::parseDriver::field_rand
tmp< volScalarField > field_rand(label seed=0, bool gaussian=false) const
A uniform random field.
Definition: volumeExprDriverFields.C:264
C
volScalarField & C
Definition: readThermalProperties.H:102
Foam::expressions::volumeExpr::parseDriver::field_cellVolume
tmp< volScalarField > field_cellVolume() const
The cell volumes - (swak = vol)
Definition: volumeExprDriverFields.C:191
Foam::GeometricField< scalar, fvPatchField, volMesh >::New
static tmp< GeometricField< scalar, fvPatchField, volMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &ds, const word &patchFieldType=fvPatchField< scalar >::calculatedType())
Return tmp field from name, mesh, dimensions and patch type.
Definition: GeometricFieldNew.C:34
error.H
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::expressions::volumeExpr::parseDriver::field_faceCentre
tmp< surfaceVectorField > field_faceCentre() const
The face centres - (swak = fpos)
Definition: volumeExprDriverFields.C:224
volumeExprDriver.H
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::expressions::volumeExpr::parseDriver::field_pointField
tmp< pointVectorField > field_pointField() const
The mesh point locations - (swak = pts)
Definition: volumeExprDriverFields.C:250
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::volumeExpr::parseDriver::field_faceArea
tmp< surfaceScalarField > field_faceArea() const
The face area magnitudes [magSf] - (swak = area)
Definition: volumeExprDriverFields.C:211
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::expressions::volumeExpr::parseDriver::field_areaNormal
tmp< surfaceVectorField > field_areaNormal() const
The face areas with their vector direction [Sf] - (swak = face)
Definition: volumeExprDriverFields.C:237
Foam::List< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::expressions::volumeExpr::parseDriver::field_cellSelection
tmp< volScalarField > field_cellSelection(const word &name, enum topoSetSource::sourceType setType) const
Cell selections (as logical)
Definition: volumeExprDriverFields.C:36
Foam::expressions::volumeExpr::parseDriver::field_cellCentre
tmp< volVectorField > field_cellCentre() const
The cell centres - (swak = pos)
Definition: volumeExprDriverFields.C:204
Foam::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:60
Foam::dimVol
const dimensionSet dimVol(dimVolume)
Older spelling for dimVolume.
Definition: dimensionSets.H:65
Foam::expressions::volumeExpr::parseDriver::field_pointSelection
tmp< pointScalarField > field_pointSelection(const word &name, enum topoSetSource::sourceType setType) const
Point selections (as logical)
Definition: volumeExprDriverFields.C:151
fvPatch.H
Foam::expressions::volumeExpr::parseDriver::field_faceSelection
tmp< surfaceScalarField > field_faceSelection(const word &name, enum topoSetSource::sourceType setType) const
Face selections (as logical)
Definition: volumeExprDriverFields.C:76
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303