FreeFOAM The Cross-Platform CFD Toolkit
backwardsCompatibilityWallFunctionsTemplates.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 | Copyright (C) 2008-2010 OpenCFD Ltd.
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 
27 #include <OpenFOAM/Time.H>
28 #include <OpenFOAM/OSspecific.H>
29 
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace incompressible
37 {
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 template<class Type, class PatchType>
42 tmp<GeometricField<Type, fvPatchField, volMesh> >
44 (
45  const word& fieldName,
46  const fvMesh& mesh
47 )
48 {
49  IOobject nutHeader
50  (
51  "nut",
52  mesh.time().timeName(),
53  mesh,
55  );
56 
57  typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
58 
59  if (nutHeader.headerOk())
60  {
61  return tmp<fieldType>
62  (
63  new fieldType
64  (
65  IOobject
66  (
67  fieldName,
68  mesh.time().timeName(),
69  mesh,
72  false
73  ),
74  mesh
75  )
76  );
77  }
78  else
79  {
80  Info<< "--> Upgrading " << fieldName
81  << " to employ run-time selectable wall functions" << endl;
82 
83  // Read existing field
84  IOobject ioObj
85  (
86  fieldName,
87  mesh.time().timeName(),
88  mesh,
91  false
92  );
93 
94  tmp<fieldType> fieldOrig
95  (
96  new fieldType
97  (
98  ioObj,
99  mesh
100  )
101  );
102 
103  // rename file
104  Info<< " Backup original " << fieldName << " to "
105  << fieldName << ".old" << endl;
106  mvBak(ioObj.objectPath(), "old");
107 
108 
109  PtrList<fvPatchField<Type> > newPatchFields(mesh.boundary().size());
110 
111  forAll(newPatchFields, patchI)
112  {
113  if (isA<wallFvPatch>(mesh.boundary()[patchI]))
114  {
115  newPatchFields.set
116  (
117  patchI,
118  new PatchType
119  (
120  mesh.boundary()[patchI],
121  fieldOrig().dimensionedInternalField()
122  )
123  );
124  newPatchFields[patchI] == fieldOrig().boundaryField()[patchI];
125  }
126  else
127  {
128  newPatchFields.set
129  (
130  patchI,
131  fieldOrig().boundaryField()[patchI].clone()
132  );
133  }
134  }
135 
136  tmp<fieldType> fieldNew
137  (
138  new fieldType
139  (
140  IOobject
141  (
142  fieldName,
143  mesh.time().timeName(),
144  mesh,
146  IOobject::NO_WRITE,
147  false
148  ),
149  mesh,
150  fieldOrig().dimensions(),
151  fieldOrig().internalField(),
152  newPatchFields
153  )
154  );
155 
156  Info<< " Writing updated " << fieldName << endl;
157  fieldNew().write();
158 
159  return fieldNew;
160  }
161 }
162 
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 } // End namespace incompressible
167 } // End namespace Foam
168 
169 // ************************ vim: set sw=4 sts=4 et: ************************ //