blockMeshFunctions.H
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) 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 InNamespace
25  Foam
26 
27 Description
28  Functions for calculating the bounds and number of cells of a background
29  mesh configured within a blockMeshDict file
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #ifndef blockMeshFunctions_H
34 #define blockMeshFunctions_H
35 
36 #include "vector.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 inline bool isEven(const label l)
46 {
47  return (l % 2 == 0) ? true : false;
48 }
49 
50 
51 inline bool isEven(const Vector<label>& vl)
52 {
53  return isEven(vl.x()) && isEven(vl.y()) && isEven(vl.z());
54 }
55 
56 
57 inline int order(const scalar s)
58 {
59  return std::round(Foam::log10(mag(s)));
60 }
61 
62 
63 inline scalar roundingScale(const scalar s)
64 {
65  return (s == 0) ? 0 : Foam::pow(10.0, order(s) - 1);
66 }
67 
68 
69 inline scalar roundDown(const scalar x, const scalar s)
70 {
71  return floor(x/s)*s;
72 }
73 
74 
75 inline scalar roundUp(const scalar x, const scalar s)
76 {
77  return ceil(x/s)*s;
78 }
79 
80 
81 inline vector roundDown(const vector& v, const scalar s)
82 {
83  return vector
84  (
85  roundDown(v.x(), s),
86  roundDown(v.y(), s),
87  roundDown(v.z(), s)
88  );
89 }
90 
91 
92 inline vector roundUp(const vector& v, const scalar s)
93 {
94  return vector
95  (
96  roundUp(v.x(), s),
97  roundUp(v.y(), s),
98  roundUp(v.z(), s)
99  );
100 }
101 
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103 
104 } // End namespace Foam
105 
106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
107 
108 #endif
109 
110 // ************************************************************************* //
const Cmpt & z() const
Definition: VectorI.H:87
const Cmpt & y() const
Definition: VectorI.H:81
const Cmpt & x() const
Definition: VectorI.H:75
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
bool isEven(const label l)
scalar roundDown(const scalar x, const scalar s)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
int order(const scalar s)
dimensionedScalar log10(const dimensionedScalar &ds)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
scalar roundUp(const scalar x, const scalar s)
dimensioned< scalar > mag(const dimensioned< Type > &)
scalar roundingScale(const scalar s)