Skip to content

Commit 745572e

Browse files
author
Henry Weller
committed
controlIOdictionary: controlDict specific IOdictionary to provide automatic read-update for Time
1 parent d8f2d58 commit 745572e

File tree

6 files changed

+194
-25
lines changed

6 files changed

+194
-25
lines changed

src/OpenFOAM/Make/files

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ db/functionObjects/timeControl/timeControlFunctionObject.C
283283
db/functionObjects/regionFunctionObject/regionFunctionObject.C
284284

285285
Time = db/Time
286+
$(Time)/controlIOdictionary/controlIOdictionary.C
286287
$(Time)/TimePaths.C
287288
$(Time)/TimeState.C
288289
$(Time)/Time.C

src/OpenFOAM/db/Time/Time.C

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ Foam::Time::Time
361361
*this,
362362
IOobject::MUST_READ_IF_MODIFIED,
363363
IOobject::NO_WRITE
364-
)
364+
),
365+
*this
365366
),
366367

367368
startTimeIndex_(0),
@@ -461,7 +462,8 @@ Foam::Time::Time
461462
*this,
462463
IOobject::MUST_READ_IF_MODIFIED,
463464
IOobject::NO_WRITE
464-
)
465+
),
466+
*this
465467
),
466468

467469
startTimeIndex_(0),
@@ -528,7 +530,8 @@ Foam::Time::Time
528530
IOobject::MUST_READ_IF_MODIFIED,
529531
IOobject::NO_WRITE
530532
),
531-
dict
533+
dict,
534+
*this
532535
),
533536

534537
startTimeIndex_(0),
@@ -593,7 +596,8 @@ Foam::Time::Time
593596
*this,
594597
IOobject::NO_READ,
595598
IOobject::NO_WRITE
596-
)
599+
),
600+
*this
597601
),
598602

599603
startTimeIndex_(0),

src/OpenFOAM/db/Time/Time.H

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
========= |
33
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
44
\\ / O peration | Website: https://openfoam.org
5-
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
5+
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
66
\\/ M anipulation |
77
-------------------------------------------------------------------------------
88
License
@@ -40,7 +40,7 @@ SourceFiles
4040

4141
#include "TimePaths.H"
4242
#include "objectRegistry.H"
43-
#include "IOdictionary.H"
43+
#include "controlIOdictionary.H"
4444
#include "FIFOStack.H"
4545
#include "clock.H"
4646
#include "cpuTime.H"
@@ -80,8 +80,10 @@ class Time
8080
//- Is runtime modification of dictionaries allowed?
8181
Switch runTimeModifiable_;
8282

83+
friend class controlIOdictionary;
84+
8385
//- The controlDict
84-
IOdictionary controlDict_;
86+
controlIOdictionary controlDict_;
8587

8688

8789
public:
@@ -306,9 +308,6 @@ public:
306308
return runTimeModifiable_;
307309
}
308310

309-
//- Read control dictionary, update controls and time
310-
virtual bool read();
311-
312311
//- Read the objects that have been modified
313312
void readModifiedObjects();
314313

src/OpenFOAM/db/Time/TimeIO.C

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,6 @@ void Foam::Time::readDict()
208208
}
209209

210210

211-
bool Foam::Time::read()
212-
{
213-
if (controlDict_.regIOobject::read())
214-
{
215-
readDict();
216-
217-
return true;
218-
}
219-
else
220-
{
221-
return false;
222-
}
223-
}
224-
225-
226211
void Foam::Time::readModifiedObjects()
227212
{
228213
if (runTimeModifiable_)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 "controlIOdictionary.H"
27+
#include "Time.H"
28+
29+
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30+
31+
Foam::controlIOdictionary::controlIOdictionary
32+
(
33+
const IOobject& io,
34+
Time& time
35+
)
36+
:
37+
IOdictionary(io),
38+
time_(time)
39+
{}
40+
41+
42+
Foam::controlIOdictionary::controlIOdictionary
43+
(
44+
const IOobject& io,
45+
const dictionary& dict,
46+
Time& time
47+
)
48+
:
49+
IOdictionary(io, dict),
50+
time_(time)
51+
{}
52+
53+
54+
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55+
56+
bool Foam::controlIOdictionary::read()
57+
{
58+
if (regIOobject::read())
59+
{
60+
time_.readDict();
61+
62+
return true;
63+
}
64+
else
65+
{
66+
return false;
67+
}
68+
}
69+
70+
71+
// ************************************************************************* //
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
Class
25+
Foam::controlIOdictionary
26+
27+
Description
28+
controlDict specific IOdictionary to provide automatic read-update for Time
29+
30+
SourceFiles
31+
controlIOdictionary.C
32+
33+
\*---------------------------------------------------------------------------*/
34+
35+
#ifndef controlIOdictionary_H
36+
#define controlIOdictionary_H
37+
38+
#include "IOdictionary.H"
39+
40+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41+
42+
namespace Foam
43+
{
44+
45+
// Forward declaration of classes
46+
class Time;
47+
48+
/*---------------------------------------------------------------------------*\
49+
Class controlIOdictionary Declaration
50+
\*---------------------------------------------------------------------------*/
51+
52+
class controlIOdictionary
53+
:
54+
public IOdictionary
55+
{
56+
// Private Data
57+
58+
//- Reference to Time to allow readDict() to be called
59+
// if the controlDict file changes
60+
Time& time_;
61+
62+
63+
public:
64+
65+
// Constructors
66+
67+
//- Construct for Time
68+
controlIOdictionary
69+
(
70+
const IOobject& io,
71+
Time& time
72+
);
73+
74+
//- Construct for Time
75+
controlIOdictionary
76+
(
77+
const IOobject& io,
78+
const dictionary& dict,
79+
Time& time
80+
);
81+
82+
//- Disallow default bitwise copy construction
83+
controlIOdictionary(const controlIOdictionary&) = delete;
84+
85+
86+
// Member Functions
87+
88+
// Read
89+
90+
//- Read the controlDict and update Time
91+
bool read();
92+
93+
94+
// Member Operators
95+
96+
//- Disallow default bitwise assignment
97+
void operator=(const controlIOdictionary&) = delete;
98+
};
99+
100+
101+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
102+
103+
} // End namespace Foam
104+
105+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106+
107+
#endif
108+
109+
// ************************************************************************* //

0 commit comments

Comments
 (0)