periodic.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "periodic.H"
27 #include "polyMesh.H"
28 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  namespace zoneGenerators
36  {
39  (
41  periodic,
43  );
44  }
45 }
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 bool Foam::zoneGenerators::periodic::activate() const
51 {
52  const scalar t =
53  repeat_ > 0
54  ? begin_ + fmod(mesh_.time().userTimeValue() - begin_, repeat_)
55  : mesh_.time().userTimeValue();
56 
57  const bool active = t >= begin_ && t < end_;
58 
59  return deactivate_ ? !active : active;
60 }
61 
62 
63 bool Foam::zoneGenerators::periodic::stateChanged() const
64 {
65  if (activate())
66  {
67  return !active_;
68  }
69  else
70  {
71  return active_;
72  }
73 }
74 
75 
76 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
77 
79 (
80  const word& name,
81  const polyMesh& mesh,
82  const dictionary& dict
83 )
84 :
86  zoneGenerator_(zoneGenerator::New(mesh, dict)),
87  begin_
88  (
89  dict.lookupOrDefault<scalar>
90  (
91  "begin",
92  unitNone,
93  mesh.time().beginTime().value()
94  )
95 
96  ),
97  end_
98  (
99  dict.lookupOrDefault<scalar>
100  (
101  "end",
102  unitNone,
103  mesh.time().endTime().value()
104  )
105 
106  ),
107  repeat_(dict.lookupOrDefault<scalar>("repeat", unitNone, 0)),
108  deactivate_(dict.lookupOrDefault<Switch>("deactivate", false)),
109  active_(false)
110 {
111  moveUpdate_ = true;
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
116 
118 {}
119 
120 
121 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122 
124 {
125  if (activate())
126  {
127  active_ = true;
128  return zoneGenerator_->generate().clone(zoneName_);
129  }
130  else
131  {
132  active_ = false;
133 
134  if (!nullZoneSet_.valid())
135  {
136  zoneSet zs(zoneGenerator_->generate());
137 
138  nullZoneSet_ = zoneSet
139  (
140  zs.pValid()
141  ? new pointZone
142  (
143  zoneName_,
144  labelList::null(),
145  mesh_.pointZones(),
146  moveUpdate_,
147  true
148  )
149  : nullptr,
150  zs.cValid()
151  ? new cellZone
152  (
153  zoneName_,
154  labelList::null(),
155  mesh_.cellZones(),
156  moveUpdate_,
157  true
158  )
159  : nullptr,
160  zs.fValid()
161  ? new faceZone
162  (
163  zoneName_,
164  labelList::null(),
165  boolList::null(),
166  mesh_.faceZones(),
167  moveUpdate_,
168  true
169  )
170  : nullptr
171  );
172  }
173 
174  // Return a zoneSet of references to nullZoneSet_
175  return zoneSet(nullZoneSet_, false);
176  }
177 }
178 
179 
181 {
182  // Regenerate the zones if they update on move or the state has changed
183  if (zoneGenerator_->moveUpdate() || stateChanged())
184  {
185  return generate();
186  }
187  else
188  {
189  return zoneSet();
190  }
191 }
192 
193 
194 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
static const List< label > & null()
Return a null List.
Definition: ListI.H:118
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
scalar userTimeValue() const
Return current user time value.
Definition: Time.C:819
Named list of cell indices representing a sub-set of the mesh.
Definition: cellZone.H:61
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Named list of face indices representing a sub-set of the mesh faces.
Definition: faceZone.H:66
const Time & time() const
Return time.
Named list of point indices representing a sub-set of the mesh faces.
Definition: pointZone.H:60
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
A class for handling words, derived from string.
Definition: word.H:62
Abstract base class for all zoneGenerators, providing runtime selection.
Definition: zoneGenerator.H:57
bool moveUpdate_
Switch to update the zones if the mesh points are moved.
Definition: zoneGenerator.H:75
const polyMesh & mesh_
Reference to the polyMesh.
Definition: zoneGenerator.H:72
A zoneGenerator which activates the zoneSet returned by the given zoneGenerator for a given period wi...
Definition: periodic.H:119
virtual ~periodic()
Destructor.
Definition: periodic.C:117
virtual zoneSet generate() const
Generate and return the zoneSet.
Definition: periodic.C:123
periodic(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: periodic.C:79
virtual zoneSet movePoints() const
Regenerate the zoneSet following mesh point motion.
Definition: periodic.C:180
Zone container returned by zoneGenerator::generate.
Definition: zoneSet.H:94
bool pValid() const
Return true if the pointZone is allocated.
Definition: zoneSetI.H:167
bool fValid() const
Return true if the faceZone is allocated.
Definition: zoneSetI.H:181
zoneSet clone(const word &name) const
Construct and return a clone with a new name.
Definition: zoneSetI.H:146
bool cValid() const
Return true if the cellZone is allocated.
Definition: zoneSetI.H:174
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
defineTypeNameAndDebug(cylinderHeadPoints, 0)
addToRunTimeSelectionTable(zoneGenerator, cylinderHeadPoints, dictionary)
Namespace for OpenFOAM.
const unitConversion unitNone
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
dictionary dict