flattenMesh.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Application
27  flattenMesh
28 
29 Group
30  grpMeshManipulationUtilities
31 
32 Description
33  Flattens the front and back planes of a 2D cartesian mesh.
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #include "argList.H"
38 #include "Time.H"
39 #include "polyMesh.H"
40 #include "emptyPolyPatch.H"
41 #include "twoDPointCorrector.H"
42 
43 using namespace Foam;
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 int main(int argc, char *argv[])
48 {
50  (
51  "Flattens the front and back planes of a 2D cartesian mesh"
52  );
53 
54  #include "setRootCase.H"
55  #include "createTime.H"
56  #include "createPolyMesh.H"
57 
59  (
60  IOobject
61  (
62  "points",
65  runTime,
68  false
69  )
70  );
71 
72  boundBox bb(points);
73 
74  Info<< "bounding box: min = " << bb.min()
75  << " max = " << bb.max() << " metres."
76  << endl;
77 
78 
80 
81  twoDPointCorrector twoDCorr(mesh);
82 
83  direction planeNormalCmpt = twoDCorr.normalDir();
84 
85  scalar midCmptVal = midPoint[planeNormalCmpt];
86  scalar minCmptVal = bb.min()[planeNormalCmpt];
87  scalar maxCmptVal = bb.max()[planeNormalCmpt];
88 
89  forAll(points, pointi)
90  {
91  if (points[pointi][planeNormalCmpt] < midCmptVal)
92  {
93  points[pointi][planeNormalCmpt] = minCmptVal;
94  }
95  else
96  {
97  points[pointi][planeNormalCmpt] = maxCmptVal;
98  }
99  }
100 
101  twoDCorr.correctPoints(points);
102 
103  // Set the precision of the points data to 10
105 
106  Info<< "Writing points into directory " << points.path() << nl << endl;
107  points.write();
108 
109  Info<< nl << "End" << nl << endl;
110 
111  return 0;
112 }
113 
114 
115 // ************************************************************************* //
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:453
Required Variables.
uint8_t direction
Definition: direction.H:46
word findInstance(const fileName &dir, const word &name=word::null, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, const word &stopInstance=word::null) const
Return time instance (location) of dir that contains the file name (eg, used in reading mesh data)...
Definition: Time.C:777
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:402
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:416
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Ignore writing from objectRegistry::writeObject()
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
dynamicFvMesh & mesh
const pointField & points
Mid-point interpolation (weighting factors = 0.5) scheme class.
Definition: midPoint.H:51
Class applies a two-dimensional correction to mesh motion point field.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Type gAverage(const FieldField< Field, Type > &f)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
A primitive field of type <T> with automated input and output.
Namespace for OpenFOAM.