postProcess.H 4.79 KB
Newer Older
1
2
3
4
5
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2016 OpenFOAM Foundation
6
     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
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
32
33
34
35
36
37
38
39
40
-------------------------------------------------------------------------------
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/>.

Global
    postProcess

Description
    Execute application functionObjects to post-process existing results.

    If the "dict" argument is specified the functionObjectList is constructed
    from that dictionary otherwise the functionObjectList is constructed from
    the "functions" sub-dictionary of "system/controlDict"

    Multiple time-steps may be processed and the standard utility time
    controls are provided.

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

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

41
42
43
44
#ifndef CREATE_TIME
    #define CREATE_TIME createTime.H
#endif

45
#ifndef CREATE_MESH
46
    #define CREATE_MESH createMesh.H
47
48
#endif

49
#ifndef CREATE_FIELDS
50
    #define CREATE_FIELDS createFields.H
51
52
#endif

53
#ifndef CREATE_CONTROL
54
    #define CREATE_CONTROL createControl.H
55
56
57
58
59
60
61
#endif

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

#define INCLUDE_FILE(X) INCLUDE_FILE2(X)
#define INCLUDE_FILE2(X) #X

62
63
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

64
65
66
67
68
69
70
71
72
73
Foam::argList::addBoolOption
(
    argList::postProcessOptionName,
    "Execute functionObjects only"
);

if (argList::postProcess(argc, argv))
{
    Foam::timeSelector::addOptions();
    #include "addRegionOption.H"
74
    #include "addFunctionObjectOptions.H"
75

76
77
78
    // Set functionObject post-processing mode
    functionObject::postProcess = true;

79
    #include "setRootCase.H"
80

81
    if (args.found("list"))
82
83
84
85
86
    {
        functionObjectList::list();
        return 0;
    }

87
    #include INCLUDE_FILE(CREATE_TIME)
88
89
    Foam::instantList timeDirs = Foam::timeSelector::select0(runTime, args);
    #include INCLUDE_FILE(CREATE_MESH)
90
91

    #ifndef NO_CONTROL
92
    #include INCLUDE_FILE(CREATE_CONTROL)
93
    #endif
94
95
96

    // Externally stored dictionary for functionObjectList
    // if not constructed from runTime
97
98
    dictionary functionsDict;

99
    HashSet<wordRe> selectedFields;
100
101

    // Construct functionObjectList
102
    autoPtr<functionObjectList> functionsPtr
103
    (
104
        functionObjectList::New(args, runTime, functionsDict, selectedFields)
105
106
    );

107
    forAll(timeDirs, timei)
108
    {
109
        runTime.setTime(timeDirs[timei], timei);
110
111
112
113
114
115

        Info<< "Time = " << runTime.timeName() << endl;

        if (mesh.readUpdate() != polyMesh::UNCHANGED)
        {
            // Update functionObjects if mesh changes
116
117
            // Note clearing the dictionary to avoid merge warning
            functionsDict.clear();
118
119
120
121
122
123
124
            functionsPtr = functionObjectList::New
            (
                args,
                runTime,
                functionsDict,
                selectedFields
            );
125
126
127
128
129
130
        }

        FatalIOError.throwExceptions();

        try
        {
131
132
133
134
135
136
137
138
139
140
            #include INCLUDE_FILE(CREATE_FIELDS)

            #ifdef CREATE_FIELDS_2
            #include INCLUDE_FILE(CREATE_FIELDS_2)
            #endif

            #ifdef CREATE_FIELDS_3
            #include INCLUDE_FILE(CREATE_FIELDS_3)
            #endif

141
            functionsPtr->execute();
142
143
144
145
146
147

            // Execute the functionObject 'end()' function for the last time
            if (timei == timeDirs.size()-1)
            {
                functionsPtr->end();
            }
148
149
150

            // Report to output (avoid overwriting values from simulation)
            profiling::print(Info);
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
        }
        catch (IOerror& err)
        {
            Warning<< err << endl;
        }

        Info<< endl;
    }

    Info<< "End\n" << endl;

    return 0;
}


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

#undef INCLUDE_FILE
#undef INCLUDE_FILE2

#undef CREATE_MESH
172
173
#undef CREATE_FIELDS
#undef CREATE_CONTROL
174
175

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