createZeroDirectory.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2015 OpenFOAM Foundation
9 Copyright (C) 2015-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Application
28 createZeroDirectory
29
30Group
31 grpPreProcessingUtilities
32
33Description
34 Creates a zero directory with fields appropriate for the chosen solver and
35 turbulence model. Operates on both single and multi-region cases.
36
37Usage
38 The set-up is configured using a 'caseProperties' dictionary, located under
39 the $FOAM_CASE/system (or system/regionName if multi-region) directory.
40 This consists of a lists of initial and boundary conditions, e.g.
41
42 \verbatim
43 initialConditions
44 {
45 U uniform (0 0 0);
46 p uniform 0;
47 }
48
49 boundaryConditions
50 {
51 topWall
52 {
53 category wall;
54 patches (movingWall);
55 type noSlip;
56 options
57 {
58 wallFunction highReynolds;
59 motion moving;
60 };
61 values
62 {
63 U uniform (1 0 0);
64 }
65 }
66
67 walls
68 {
69 category wall;
70 patches (fixedWalls);
71 type noSlip;
72 options
73 {
74 wallFunction highReynolds;
75 motion stationary;
76 };
77 }
78 }
79 \endverbatim
80
81\*---------------------------------------------------------------------------*/
82
83#include "argList.H"
84#include "volFields.H"
85#include "IOdictionary.H"
86#include "caseInfo.H"
87#include "boundaryTemplates.H"
88#include "solverTemplate.H"
89
90using namespace Foam;
91
92// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93
94const word getClassType(const word& pType)
95{
96 if (pType == pTraits<scalar>::typeName)
97 {
99 }
100 else if (pType == pTraits<vector>::typeName)
101 {
103 }
104 else if (pType == pTraits<sphericalTensor>::typeName)
105 {
107 }
108 else if (pType == pTraits<symmTensor>::typeName)
109 {
111 }
112 else if (pType == pTraits<tensor>::typeName)
113 {
115 }
116 else
117 {
118 // Error
119 return word::null;
120 }
121}
122
123
124void createFieldFiles
125(
126 const Time& runTime,
127 const word& regionName,
128 const word& regionPrefix,
129 const wordList& fieldNames,
130 const wordList& fieldTypes,
131 const PtrList<dimensionSet>& fieldDimensions,
132 const caseInfo& cInfo,
133 const boundaryTemplates& bcTemplates
134)
135{
136 Info<< " Generating field files" << nl << endl;
137
138 // Create files
139 forAll(fieldNames, i)
140 {
141 const_cast<word&>(IOdictionary::typeName) =
142 getClassType(fieldTypes[i]);
143
145
146 fileName regionPath = "/";
147
148 if (!regionName.empty())
149 {
150 regionPath += regionName + '/';
151 }
152
153 field.add
154 (
155 "#include",
156 "$FOAM_CASE/system" + regionPath + "caseProperties"
157 );
158
159 field.add("dimensions", fieldDimensions[i]);
160
161 string iField("${:initialConditions." + fieldNames[i] + '}');
162 field.add("internalField", iField.c_str());
163
164 dictionary boundaryField =
166 (
167 regionPrefix,
168 fieldNames[i],
169 bcTemplates
170 );
171
172 field.add("boundaryField", boundaryField);
173
174 // Expand all of the dictionary redirections and remove unnecessary
175 // entries
177 os << field;
178
179 entry::disableFunctionEntries = 0;
180 dictionary field2(IStringStream(os.str())());
181 entry::disableFunctionEntries = 1;
182 field2.remove("#include");
183 field2.remove("initialConditions");
184 field2.remove("boundaryConditions");
185
186 // Construct and write field dictionary. Note use of localIOdictionary
187 localIOdictionary fieldOut
188 (
190 (
191 fieldNames[i],
192 "0",
194 runTime,
195 IOobject::NO_READ
196 ),
197 field2
198 );
199
200 fieldOut.regIOobject::writeObject
201 (
202 IOstreamOption(IOstream::ASCII),
203 true
204 );
205 }
206}
207
208
209// Main program:
210int main(int argc, char *argv[])
211{
212 argList::addNote
213 (
214 "Create a 0/ directory with fields appropriate for the chosen"
215 " solver and turbulence model."
216 );
217
218 argList::addOption
219 (
220 "templateDir",
221 "dir",
222 "Read case set-up templates from specified location"
223 );
224
225 #include "setRootCase.H"
226 #include "createTime.H"
227
228 Info<< "Reading controlDict" << nl << endl;
229
231 (
233 (
234 "controlDict",
235 runTime.system(),
236 runTime,
237 IOobject::MUST_READ,
238 IOobject::NO_WRITE
239 )
240 );
241
242 // Template directory: default is from PROJECT/etc directory
243 //
244 // Can use
245 // - foamEtcDir("caseDicts/createZeroDirectory", 0007);
246 // - expand "<etc:o>/caseDicts/createZeroDirectory"
247 // - expand "${WM_PROJECT_DIR}/etc/caseDicts/createZeroDirectory"
248 //
249 // Use "${WM_PROJECT_DIR}/" version for nicer error message
250
251 fileName baseDir
252 (
254 (
255 "templateDir",
256 "${WM_PROJECT_DIR}/etc/caseDicts/createZeroDirectoryTemplates"
257 )
258 );
259
260 baseDir.expand();
261 baseDir.toAbsolute();
262
263 if (!Foam::isDir(baseDir))
264 {
266 << "templateDir " << baseDir << nl
267 << "Does not point to a folder containing case set-up templates"
268 << nl
269 << exit(FatalError);
270 }
271
272 // Keep variable substitutions - delay until after creation of controlDict
273 // to allow #include files to be processed
274 entry::disableFunctionEntries = 1;
275
276 // Read the solver
277 const word solverName(controlDict.get<word>("application"));
278
279 // Generate solver template
280 const solverTemplate solver(baseDir, runTime, solverName);
281
282 // Read the boundary condition templates
283 const boundaryTemplates bcTemplates
284 (
285 baseDir,
286 runTime,
287 solver.type()
288 );
289
290 Info<< endl;
291
292 const label nRegion = solver.nRegion();
293 for (label regionI = 0; regionI < nRegion; regionI++)
294 {
295 const word& regionName = solver.regionName(regionI);
296
297 if (regionName.empty())
298 {
299 Info<< "Region: " << polyMesh::defaultRegion << " (default)"
300 << endl;
301 }
302 else
303 {
304 Info<< "Region: " << regionName << endl;
305 }
306
307 // Read the case set-up info for the current region
308 const caseInfo cInfo(runTime, regionName);
309
310 cInfo.checkPatches(solver.regionType(regionI), bcTemplates);
311
312 createFieldFiles
313 (
314 runTime,
316 solver.regionType(regionI),
317 solver.fieldNames(regionI),
318 solver.fieldTypes(regionI),
319 solver.fieldDimensions(regionI),
320 cInfo,
321 bcTemplates
322 );
323 }
324
325 Info<< "End\n" << endl;
326
327 return 0;
328}
329
330
331// ************************************************************************* //
Generic GeometricField class.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
The IOstreamOption is a simple container for options an IOstream can normally have.
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
Definition: StringStream.H:112
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:231
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Definition: argListI.H:307
Class to store boundary template specifications.
Class to hold information related to the simaulation case.
Definition: caseInfo.H:57
void checkPatches(const word &regionPrefix, const boundaryTemplates &bcTemplates) const
Check patches.
dictionary generateBoundaryField(const word &regionPrefix, const word &fieldName, const boundaryTemplates &bcTemplates) const
Generate boundary field (dictionary)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
Class to store solver template specifications.
Base class for solution control classes.
Definition: solver.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
runTime controlDict().readEntry("adjustTimeStep"
rDeltaTY field()
engineTime & runTime
Foam::word regionName(Foam::polyMesh::defaultRegion)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: MSwindows.C:651
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333