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 getSnapshotField<VolFieldType>();
42  }
43  else if (foundObject<SurfaceFieldType>(fieldName_))
44  {
45  return getSnapshotField<SurfaceFieldType>();
46  }
47 
48  return false;
49 }
50 
51 
52 template<class GeoFieldType>
53 bool Foam::functionObjects::DMD::getSnapshotField()
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 =
72  pTraits<typename GeoFieldType::value_type>::nComponents;
73 
74  const GeoFieldType& field = lookupObject<GeoFieldType>(fieldName_);
75 
76  if (patch_.empty())
77  {
78  const label nField = field.size();
79 
80  for (direction dir = 0; dir < nComps; ++dir)
81  {
82  z_.subColumn(0, nSnap_ + dir*nField, nField) = field.component(dir);
83  }
84  }
85  else
86  {
87  const label patchi = mesh_.boundaryMesh().findPatchID(patch_);
88 
89  if (patchi < 0)
90  {
92  << "Cannot find patch " << patch_
93  << exit(FatalError);
94  }
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  for (direction dir = 0; dir < nComps; ++dir)
103  {
104  z_.subColumn(0, nSnap_ + dir*nField, nField) = pbf.component(dir);
105  }
106  }
107 
108  return true;
109 }
110 
111 
112 // ************************************************************************* //
volFields.H
surfaceFields.H
Foam::surfaceFields.
field
rDeltaTY field()
Foam::FatalError
error FatalError
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::direction
uint8_t direction
Definition: direction.H:52