setTimeStepFunctionObject.C 3.48 KB
Newer Older
Henry's avatar
Henry committed
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
Henry Weller's avatar
Henry Weller committed
5
    \\  /    A nd           | Copyright (C) 2013-2016 OpenFOAM Foundation
6
     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
Henry's avatar
Henry committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "setTimeStepFunctionObject.H"
#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
32
33
{
namespace functionObjects
Henry's avatar
Henry committed
34
35
36
37
38
39
40
41
42
43
{
    defineTypeNameAndDebug(setTimeStepFunctionObject, 0);

    addToRunTimeSelectionTable
    (
        functionObject,
        setTimeStepFunctionObject,
        dictionary
    );
}
44
}
Henry's avatar
Henry committed
45
46
47
48


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

49
Foam::functionObjects::setTimeStepFunctionObject::setTimeStepFunctionObject
Henry's avatar
Henry committed
50
51
52
53
54
55
56
(
    const word& name,
    const Time& runTime,
    const dictionary& dict
)
:
    functionObject(name),
57
    time_(runTime)
Henry's avatar
Henry committed
58
59
60
61
62
{
    read(dict);
}


63
// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
Henry's avatar
Henry committed
64

65
66
Foam::functionObjects::setTimeStepFunctionObject::~setTimeStepFunctionObject()
{}
Henry's avatar
Henry committed
67
68


69
// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
Henry's avatar
Henry committed
70

71
72
const Foam::Time&
Foam::functionObjects::setTimeStepFunctionObject::time() const
Henry's avatar
Henry committed
73
{
74
    return time_;
Henry's avatar
Henry committed
75
76
77
}


78
bool Foam::functionObjects::setTimeStepFunctionObject::adjustTimeStep()
Henry's avatar
Henry committed
79
{
80
81
    // Wanted timestep
    scalar newDeltaT = timeStepPtr_().value(time_.timeOutputValue());
Henry's avatar
Henry committed
82

83
    static label index = -1;
Henry's avatar
Henry committed
84

85
86
87
88
89
    if (time_.timeIndex() != index)
    {
        // Store current time so we don't get infinite recursion (since
        // setDeltaT calls adjustTimeStep() again)
        index = time_.timeIndex();
Henry's avatar
Henry committed
90

91
        // Set time, allow deltaT to be adjusted for writeInterval purposes
mattijs's avatar
mattijs committed
92
        const_cast<Time&>(time_).setDeltaT(newDeltaT, false);
93
    }
Henry's avatar
Henry committed
94
95
96
97
98

    return true;
}


99
100
101
102
bool Foam::functionObjects::setTimeStepFunctionObject::read
(
    const dictionary& dict
)
Henry's avatar
Henry committed
103
{
104
    functionObject::read(dict);
Henry's avatar
Henry committed
105

106
    timeStepPtr_ = Function1<scalar>::New("deltaT", dict);
107

108
109
    // Ensure that adjustTimeStep is active
    if (!time_.controlDict().lookupOrDefault<bool>("adjustTimeStep", false))
Henry's avatar
Henry committed
110
    {
111
112
        FatalIOErrorInFunction(dict)
            << "Need to set 'adjustTimeStep' true to allow timestep control"
113
            << nl
114
            << exit(FatalIOError);
Henry's avatar
Henry committed
115
    }
116

Henry's avatar
Henry committed
117
118
119
120
    return true;
}


121
bool Foam::functionObjects::setTimeStepFunctionObject::execute()
Henry's avatar
Henry committed
122
123
124
125
126
{
    return true;
}


127
bool Foam::functionObjects::setTimeStepFunctionObject::write()
128
129
130
{
    return true;
}
Henry's avatar
Henry committed
131
132
133


// ************************************************************************* //