DMDTemplates.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) 2020-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 "volFields.H"
29 #include "surfaceFields.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 template<class Type>
34 bool Foam::functionObjects::DMD::getSnapshot()
35 {
36  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
37  typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
38 
39  if (foundObject<VolFieldType>(fieldName_))
40  {
41  return storeSnapshot<VolFieldType>();
42  }
43  else if (foundObject<SurfaceFieldType>(fieldName_))
44  {
45  return storeSnapshot<SurfaceFieldType>();
46  }
47 
48  return false;
49 }
50 
51 
52 template<class GeoFieldType>
53 bool Foam::functionObjects::DMD::storeSnapshot()
54 {
55  if (step_ == 0)
56  {
57  initialise();
58  }
59 
60  if (z_.size() == 1)
61  {
62  return true;
63  }
64 
65  // Move previous-time snapshot into previous-time slot in "z"
66  // Effectively moves the lower half of "z" to its upper half
67  std::rotate(z_.begin(), z_.begin() + nSnap_, z_.end());
68 
69  // Copy new current-time snapshot into current-time slot in "z"
70  // Effectively copies the new field elements into the lower half of "z"
71  const label nComps =
73 
74  const GeoFieldType& field = lookupObject<GeoFieldType>(fieldName_);
75 
76  label rowi = nSnap_;
77  if (patches_.empty())
78  {
79  const label nField = field.size();
80 
81  for (direction dir = 0; dir < nComps; ++dir)
82  {
83  z_.subColumn(0, rowi, nField) = field.component(dir);
84  rowi += nField;
85  }
86  }
87  else
88  {
89  const labelList patchis
90  (
91  mesh_.boundaryMesh().patchSet(patches_).sortedToc()
92  );
93 
94  for (const label patchi : patchis)
95  {
96  const typename GeoFieldType::Boundary& bf = field.boundaryField();
97 
98  const Field<typename GeoFieldType::value_type>& pbf = bf[patchi];
99 
100  const label nField = pbf.size();
101 
102  if (nField > 0)
103  {
104  for (direction dir = 0; dir < nComps; ++dir)
105  {
106  z_.subColumn(0, rowi, nField) = pbf.component(dir);
107  rowi += nField;
108  }
109  }
110  }
111  }
112 
113  return true;
114 }
115 
116 
117 template<class Type>
118 bool Foam::functionObjects::DMD::nComponents
119 (
120  const word& fieldName,
121  label& nComps
122 ) const
123 {
124  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
125  typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
126 
127  if (mesh_.foundObject<VolFieldType>(fieldName))
128  {
130  return true;
131  }
132  else if (mesh_.foundObject<SurfaceFieldType>(fieldName))
133  {
135  return true;
136  }
137 
138  return false;
139 }
140 
141 
142 // ************************************************************************* //
Foam::surfaceFields.
rDeltaTY field()
uint8_t direction
Definition: direction.H:46
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
List< label > labelList
A List of labels.
Definition: List.H:62