flattenMesh.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) 2011-2018 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  flattenMesh
26 
27 Description
28  Flattens the front and back planes of a 2D cartesian mesh.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "argList.H"
33 #include "Time.H"
34 #include "polyMesh.H"
35 #include "emptyPolyPatch.H"
36 #include "twoDPointCorrector.H"
37 
38 using namespace Foam;
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 int main(int argc, char *argv[])
43 {
44  #include "setRootCase.H"
45  #include "createTime.H"
46  #include "createPolyMesh.H"
47 
49  (
50  IOobject
51  (
52  "points",
55  runTime,
58  false
59  )
60  );
61 
62  boundBox bb(points);
63 
64  Info<< "bounding box: min = " << bb.min()
65  << " max = " << bb.max() << " meters."
66  << endl;
67 
68 
69  point midPoint = gAverage(points);
70 
71  twoDPointCorrector twoDCorr(mesh);
72 
73  direction planeNormalCmpt = twoDCorr.normalDir();
74 
75  scalar midCmptVal = midPoint[planeNormalCmpt];
76  scalar minCmptVal = bb.min()[planeNormalCmpt];
77  scalar maxCmptVal = bb.max()[planeNormalCmpt];
78 
79  forAll(points, pointi)
80  {
81  if (points[pointi][planeNormalCmpt] < midCmptVal)
82  {
83  points[pointi][planeNormalCmpt] = minCmptVal;
84  }
85  else
86  {
87  points[pointi][planeNormalCmpt] = maxCmptVal;
88  }
89  }
90 
91  twoDCorr.correctPoints(points);
92 
93  // Set the precision of the points data to 10
95 
96  Info<< "Writing points into directory " << points.path() << nl << endl;
97  points.write();
98 
99  Info<< "End\n" << endl;
100 
101  return 0;
102 }
103 
104 
105 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
static const Form max
Definition: VectorSpace.H:115
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
uint8_t direction
Definition: direction.H:45
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:312
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:461
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
Return the location of "dir" containing the file "name".
Definition: Time.C:649
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
static const Form min
Definition: VectorSpace.H:116
dynamicFvMesh & mesh
const pointField & points
Class applies a two-dimensional correction to mesh motion point field.
static const char nl
Definition: Ostream.H:265
Type gAverage(const FieldField< Field, Type > &f)
messageStream Info
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50
Namespace for OpenFOAM.