Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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/>.
Application
createZeroDirectory
Description
Creates a zero directory with fields appropriate for the chosen solver and
turbulence model. Operates on both single and multi-region cases.
Usage
The set-up is configured using a 'caseProperties' dictionary, located under
the $FOAM_CASE/system (or system/regionName if multi-region) directory.
This consists of a lists of initial and boundary conditions, e.g.
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
initialConditions
{
U uniform (0 0 0);
p uniform 0;
}
boundaryConditions
{
topWall
{
category wall;
patches (movingWall);
type noSlip;
options
{
wallFunction highReynolds;
motion moving;
};
values
{
U uniform (1 0 0);
}
}
walls
{
category wall;
patches (fixedWalls);
type noSlip;
options
{
wallFunction highReynolds;
motion stationary;
};
}
}
\endverbatim
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "volFields.H"
#include "IOdictionary.H"
#include "boundaryInfo.H"
#include "caseInfo.H"
#include "boundaryTemplates.H"
#include "solverTemplate.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
const word getClassType(const word& pType)
{
if (pType == pTraits<scalar>::typeName)
{
return GeometricField<scalar, fvPatchField, volMesh>::typeName;
}
else if (pType == pTraits<vector>::typeName)
{
return GeometricField<vector, fvPatchField, volMesh>::typeName;
}
else if (pType == pTraits<sphericalTensor>::typeName)
{
return GeometricField<sphericalTensor, fvPatchField, volMesh>::typeName;
}
else if (pType == pTraits<symmTensor>::typeName)
{
return GeometricField<symmTensor, fvPatchField, volMesh>::typeName;
}
else if (pType == pTraits<tensor>::typeName)
{
return GeometricField<tensor, fvPatchField, volMesh>::typeName;
}
else
{
// error
return word::null;
}
}
void createFieldFiles
(
const Time& runTime,
const word& regionName,
const word& regionPrefix,
const wordList& fieldNames,
const wordList& fieldTypes,
const PtrList<dimensionSet>& fieldDimensions,
const caseInfo& cInfo,
const boundaryTemplates& bcTemplates
)
{
Info<< " Generating field files" << nl << endl;
// create files
mkDir(runTime.path()/"0"/regionName);
forAll(fieldNames, i)
{
const_cast<word&>(IOdictionary::typeName) =
getClassType(fieldTypes[i]);
// IOdictionary field
// (
// IOobject
// (
// fieldNames[i],
// "0",
// regionName,
// runTime,
// IOobject::NO_READ
// )
// );
dictionary field;
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
word regionPath = "/";
if (regionName != word::null)
{
regionPath += regionName + '/';
}
field.add
(
"#include",
string
(
"${FOAM_CASE}/system" + regionPath + "caseProperties"
)
);
field.add("dimensions", fieldDimensions[i]);
string iField("${:initialConditions." + fieldNames[i] + '}');
field.add("internalField", iField.c_str());
dictionary boundaryField =
cInfo.generateBoundaryField
(
regionPrefix,
fieldNames[i],
bcTemplates
);
field.add("boundaryField", boundaryField);
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// expand all of the dictionary redirections and remove unnecessary
// entries
OStringStream os;
os << field;
entry::disableFunctionEntries = 0;
dictionary field2(IStringStream(os.str())());
entry::disableFunctionEntries = 1;
field2.remove("#include");
field2.remove("initialConditions");
field2.remove("boundaryConditions");
// construct and write field dictionary
IOdictionary fieldOut
(
IOobject
(
fieldNames[i],
"0",
regionName,
runTime,
IOobject::NO_READ
),
field2
);
fieldOut.regIOobject::writeObject
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
(
IOstream::ASCII,
IOstream::currentVersion,
IOstream::UNCOMPRESSED
);
}
}
// Main program:
int main(int argc, char *argv[])
{
// keep variable substitutions
entry::disableFunctionEntries = 1;
#include "setRootCase.H"
#include "createTime.H"
Info<< "Reading controlDict" << nl << endl;
IOdictionary controlDict
(
IOobject
(
"controlDict",
runTime.system(),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
fileName baseDir("${WM_PROJECT_DIR}/etc/templates");
baseDir.expand();
// read the solver
const word& solverName = controlDict.lookup("application");
// generate solver template
const solverTemplate solver(baseDir, runTime, solverName);
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// read the boundary condition templates
const boundaryTemplates bcTemplates
(
baseDir,
runTime,
solver.type()
);
Info<< endl;
const label nRegion = solver.nRegion();
for (label regionI = 0; regionI < nRegion; regionI++)
{
const word& regionName = solver.regionName(regionI);
if (regionName == word::null)
{
Info<< "Region: " << polyMesh::defaultRegion << " (default)"
<< endl;
}
else
{
Info<< "Region: " << regionName << endl;
}
// read the case set-up info for the current region
const caseInfo cInfo(runTime, regionName);
cInfo.checkPatches(solver.regionType(regionI), bcTemplates);
createFieldFiles
(
runTime,
regionName,
solver.regionType(regionI),
solver.fieldNames(regionI),
solver.fieldTypes(regionI),
solver.fieldDimensions(regionI),
cInfo,
bcTemplates
);
}
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //