setAtmBoundaryLayer.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2022-2023 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 Application
25  setAtmBoundaryLayer
26 
27 Description
28  Applies atmospheric boundary layer models to the entire domain for case
29  initialisation.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #include "argList.H"
34 #include "timeSelector.H"
35 #include "volFields.H"
36 #include "wallPolyPatch.H"
37 #include "atmBoundaryLayer.H"
38 #include "systemDict.H"
39 
40 using namespace Foam;
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 int main(int argc, char *argv[])
45 {
46  timeSelector::addOptions(false, false);
47 
48  #include "addDictOption.H"
49  #include "addRegionOption.H"
50  #include "setRootCase.H"
51  #include "createTime.H"
52 
54 
55  #include "createNamedMesh.H"
56 
57  const dictionary setAtmBoundaryLayerDict
58  (
59  systemDict("setAtmBoundaryLayerDict", args, mesh)
60  );
61 
62  // Parse options
63  const word UName = setAtmBoundaryLayerDict.lookupOrDefault<word>("U", "U");
64  const word kName = setAtmBoundaryLayerDict.lookupOrDefault<word>("k", "k");
65  const word epsilonName =
66  setAtmBoundaryLayerDict.lookupOrDefault<word>("epsilon", "epsilon");
67 
68  forAll(timeDirs, timeI)
69  {
70  runTime.setTime(timeDirs[timeI], timeI);
71 
72  Info<< "Time = " << runTime.userTimeName() << nl << endl;
73 
74  mesh.readUpdate();
75 
76  // Read the fields
78  (
79  IOobject
80  (
81  UName,
82  runTime.name(),
83  mesh,
85  ),
86  mesh
87  );
88  IOobject kIO
89  (
90  kName,
91  runTime.name(),
92  mesh,
94  );
96  (
97  kIO.headerOk() ? new volScalarField(kIO, mesh) : nullptr
98  );
99  IOobject epsilonIO
100  (
101  epsilonName,
102  runTime.name(),
103  mesh,
105  );
107  (
108  epsilonIO.headerOk() ? new volScalarField(epsilonIO, mesh) : nullptr
109  );
110 
111  // Set the internal fields
112  const atmBoundaryLayer atm(mesh.C(), setAtmBoundaryLayerDict);
113  U.primitiveFieldRef() = atm.U(mesh.C());
114  if (k.valid())
115  {
116  k.ref().primitiveFieldRef() = atm.k(mesh.C());
117  }
118  if (epsilon.valid())
119  {
120  epsilon.ref().primitiveFieldRef() = atm.epsilon(mesh.C());
121  }
122 
123  // Set all non-wall patch fields
124  forAll(mesh.boundary(), patchi)
125  {
126  const fvPatch& patch = mesh.boundary()[patchi];
127 
128  const atmBoundaryLayer atmp(patch.Cf(), setAtmBoundaryLayerDict);
129 
130  if (!isA<wallPolyPatch>(patch))
131  {
132  U.boundaryFieldRef()[patchi] == atmp.U(patch.Cf());
133  if (k.valid())
134  {
135  k.ref().boundaryFieldRef()[patchi] ==
136  atmp.k(patch.Cf());
137  }
138  if (epsilon.valid())
139  {
140  epsilon.ref().boundaryFieldRef()[patchi] ==
141  atmp.epsilon(patch.Cf());
142  }
143  }
144  }
145 
146  // Output
147  Info<< "Writing " << U.name() << nl << endl;
148  U.write();
149  if (k.valid())
150  {
151  Info<< "Writing " << k->name() << nl << endl;
152  k->write();
153  }
154  if (epsilon.valid())
155  {
156  Info<< "Writing " << epsilon->name() << nl << endl;
157  epsilon->write();
158  }
159  }
160 
161  Info<< "End\n" << endl;
162 
163  return 0;
164 }
165 
166 
167 // ************************************************************************* //
label k
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Generic GeometricField class.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
This class provides functions to evaluate the velocity and turbulence distributions appropriate for a...
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
const vectorField & Cf() const
Return face centres.
Definition: fvPatch.C:105
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
static instantList selectIfPresent(Time &runTime, const argList &args)
If any time option provided return the set of times (as select0)
Definition: timeSelector.C:283
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
const scalar epsilon
int main(int argc, char *argv[])
Definition: financialFoam.C:44
label patchi
static instantList timeDirs
Definition: globalFoam.H:44
U
Definition: pEqn.H:72
Namespace for OpenFOAM.
IOdictionary systemDict(const word &dictName, const argList &args, const objectRegistry &ob, const word &regionName=polyMesh::defaultRegion)
Definition: systemDict.C:92
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
static const char nl
Definition: Ostream.H:260
Foam::argList args(argc, argv)