Repeat.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) 2024 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 "Repeat.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const unitConversions& units,
34  const dictionary& dict
35 )
36 {
37  const bool havePeriod = dict.found("period");
38  const bool haveFrequency = dict.found("frequency");
39 
40  if (havePeriod == haveFrequency)
41  {
43  << (havePeriod ? "both" : "neither") << " of keywords "
44  << "period " << (havePeriod ? "and" : "or")
45  << " frequency defined in dictionary " << dict.name()
46  << exit(FatalIOError);
47  }
48 
49  return
50  havePeriod
51  ? dict.lookupOrDefault<scalar>("period", units.x, 0)
52  : 1/dict.lookupOrDefault<scalar>("frequency", unitless/units.x, 0);
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 
58 template<class Type>
60 (
61  const word& name,
62  const unitConversions& units,
63  const dictionary& dict
64 )
65 :
66  FieldFunction1<Type, Repeat<Type>>(name),
67  period_(readPeriod(units, dict)),
68  start_(dict.lookupOrDefault<scalar>("start", units.x, scalar(0))),
69  value_(Function1<Type>::New("value", units, dict))
70 {}
71 
72 
73 template<class Type>
75 :
76  FieldFunction1<Type, Repeat<Type>>(se),
77  period_(se.period_),
78  start_(se.start_),
79  value_(se.value_, false)
80 {}
81 
82 
83 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
84 
85 template<class Type>
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91 
92 template<class Type>
94 (
95  Ostream& os,
96  const unitConversions& units
97 ) const
98 {
99  writeEntry(os, "period", units.x, period_);
100  writeEntryIfDifferent(os, "start", units.x, scalar(0), start_);
101  writeEntry(os, units, value_());
102 }
103 
104 
105 // ************************************************************************* //
Run-time selectable general function of one variable.
Definition: Function1.H:125
Function1 which repeats a given 'value' function with a given period or frequency,...
Definition: Repeat.H:117
virtual void write(Ostream &os, const unitConversions &units) const
Write data to dictionary stream.
Definition: Repeat.C:94
virtual ~Repeat()
Destructor.
Definition: Repeat.C:86
Repeat(const word &name, const unitConversions &units, const dictionary &dict)
Construct from name and dictionary.
Definition: Repeat.C:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
void writeEntry(Ostream &os, const omega &a)
Definition: omega1.C:97
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void writeEntryIfDifferent(Ostream &os, const word &entryName, const EntryType &value1, const EntryType &value2)
Helper function to write the keyword and entry only if the.
const HashTable< unitConversion > & units()
Get the table of unit conversions.
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
const unitConversion unitless
dictionary dict