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-2026 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 "wallFvPatch.H"
38 
39 using namespace Foam;
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 int main(int argc, char *argv[])
44 {
45  timeSelector::addOptions(false, false);
46 
47  #include "addDictOption.H"
48  #include "addRegionOption.H"
49  #include "setRootCase.H"
50  #include "createTime.H"
51 
53 
55 
56  const atmosphericBoundaryLayer& atm =
58 
59  // Set field names if specified
60  const word UName = atm.lookupOrDefault<word>("U", "U");
61  const word kName = atm.lookupOrDefault<word>("k", "k");
62  const word epsilonName = atm.lookupOrDefault<word>("epsilon", "epsilon");
63 
64  forAll(timeDirs, timeI)
65  {
66  runTime.setTime(timeDirs[timeI], timeI);
67 
68  Info<< "Time = " << runTime.userTimeName() << nl << endl;
69 
70  mesh.readUpdate();
71 
72  // Read the fields
74  (
75  IOobject
76  (
77  UName,
78  runTime.name(),
79  mesh,
81  ),
82  mesh
83  );
84  IOobject kIO
85  (
86  kName,
87  runTime.name(),
88  mesh,
90  );
92  (
93  kIO.headerOk() ? new volScalarField(kIO, mesh) : nullptr
94  );
95  IOobject epsilonIO
96  (
97  epsilonName,
98  runTime.name(),
99  mesh,
101  );
103  (
104  epsilonIO.headerOk() ? new volScalarField(epsilonIO, mesh) : nullptr
105  );
106 
107  // Set the internal fields
108 
109  U.primitiveFieldRef() = atm.U(mesh.C());
110  if (k.valid())
111  {
112  k.ref().primitiveFieldRef() = atm.k(mesh.C());
113  }
114  if (epsilon.valid())
115  {
116  epsilon.ref().primitiveFieldRef() = atm.epsilon(mesh.C());
117  }
118 
119  // Set all non-wall patch fields
121  {
122  const fvPatch& patch = mesh.boundary()[patchi];
123 
124  if (!isA<wallFvPatch>(patch))
125  {
126  U.boundaryFieldRef()[patchi] == atm.U(patch.Cf());
127  if (k.valid())
128  {
129  k.ref().boundaryFieldRef()[patchi] ==
130  atm.k(patch.Cf());
131  }
132  if (epsilon.valid())
133  {
134  epsilon.ref().boundaryFieldRef()[patchi] ==
135  atm.epsilon(patch.Cf());
136  }
137  }
138  }
139 
140  // Output
141  Info<< "Writing " << U.name() << nl << endl;
142  U.write();
143  if (k.valid())
144  {
145  Info<< "Writing " << k->name() << nl << endl;
146  k->write();
147  }
148  if (epsilon.valid())
149  {
150  Info<< "Writing " << epsilon->name() << nl << endl;
151  epsilon->write();
152  }
153  }
154 
155  Info<< "End\n" << endl;
156 
157  return 0;
158 }
159 
160 
161 // ************************************************************************* //
label k
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
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...
static const atmosphericBoundaryLayer & New(const objectRegistry &db)
Return a reference to the atmosphericBoundaryLayer.
tmp< vectorField > U(const vectorField &p) const
Return the velocity field.
tmp< scalarField > k(const vectorField &p) const
Return the turbulent kinetic energy field.
tmp< scalarField > epsilon(const vectorField &p) const
Return the turbulent dissipation rate field.
T lookupOrDefault(const word &, const T &) const
Find and return a T, if not found return the given default.
const volVectorField & C() const
Return cell centres.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:932
readUpdateState readUpdate(const stitchType stitch=stitchType::geometric)
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:836
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:58
const vectorField & Cf() const
Return face centres.
Definition: fvPatch.C:85
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:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
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.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
static const char nl
Definition: Ostream.H:297
Foam::argList args(argc, argv)