componentsImpl.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) 2016 OpenFOAM Foundation
9  Copyright (C) 2019-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "volFields.H"
30 #include "surfaceFields.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
34 template<class GeoFieldType>
35 bool Foam::functionObjects::components::calcComponents
36 (
37  const GeoFieldType& field
38 )
39 {
40  typedef typename GeoFieldType::value_type Type;
41 
42  resultNames_.resize(pTraits<Type>::nComponents);
43 
44  bool stored = true;
45 
47  {
48  resultName_ = fieldName_ + word(pTraits<Type>::componentNames[i]);
49  resultNames_[i] = resultName_;
50 
51  stored = stored && store(resultName_, field.component(i));
52  }
53 
54  return stored;
55 }
56 
57 
58 template<class Type>
59 bool Foam::functionObjects::components::calcComponents()
60 {
61  const auto* vfield = cfindObject<VolumeField<Type>>(fieldName_);
62  if (vfield)
63  {
64  return calcComponents(*vfield);
65  }
66 
67  const auto* sfield = cfindObject<SurfaceField<Type>>(fieldName_);
68  if (sfield)
69  {
70  return calcComponents(*sfield);
71  }
72 
73  return false;
74 }
75 
76 
77 // ************************************************************************* //
Foam::surfaceFields.
rDeltaTY field()
uint8_t direction
Definition: direction.H:46
word resultName_
Name of result field.
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
word fieldName_
Name of field to process.
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
bool store(word &fieldName, const tmp< ObjectType > &tfield, bool cacheable=false)
Store the field in the (sub) objectRegistry under the given name.