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-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  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 "polyMesh.H"
34 #include "twoDPointCorrector.H"
35 
36 using namespace Foam;
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 int main(int argc, char *argv[])
41 {
42  #include "addRegionOption.H"
43  #include "addMeshOption.H"
44 
45  #include "setRootCase.H"
46  #include "createTime.H"
47  #include "createSpecifiedPolyMesh.H"
48 
50 
51  const point midPoint = gAverage(points);
52 
54 
55  const direction planeNormalCmpt = twoDCorr.normalDir();
56 
57  const scalar midCmptVal = midPoint[planeNormalCmpt];
58  const scalar minCmptVal = mesh.bounds().min()[planeNormalCmpt];
59  const scalar maxCmptVal = mesh.bounds().max()[planeNormalCmpt];
60 
61  forAll(points, pointi)
62  {
63  if (points[pointi][planeNormalCmpt] < midCmptVal)
64  {
65  points[pointi][planeNormalCmpt] = minCmptVal;
66  }
67  else
68  {
69  points[pointi][planeNormalCmpt] = maxCmptVal;
70  }
71  }
72 
73  twoDCorr.correctPoints(points);
74 
75  // Ensure the points are written to a sufficient precision
77 
78  Info<< "Writing points into directory " << points.path() << nl << endl;
79 
80  points.write();
81 
82  Info<< "End\n" << endl;
83 
84  return 0;
85 }
86 
87 
88 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
static twoDPointCorrector & New(const word &name, const polyMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
A primitive field of type <Type> with automated input and output.
Definition: IOField.H:53
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:473
static unsigned int highPrecision()
Return a high precision for writing data that is.
Definition: IOstream.C:90
const point & min() const
Minimum point defining the bounding box.
Definition: boundBoxI.H:88
const point & max() const
Maximum point defining the bounding box.
Definition: boundBoxI.H:94
Mid-point interpolation (weighting factors = 0.5) scheme class.
Definition: midPoint.H:53
Type & lookupObjectRef(const word &name) const
Lookup and return the object reference of the given Type.
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:399
Class applies a two-dimensional correction to mesh motion point field.
direction normalDir() const
Return direction normal to plane.
void correctPoints(pointField &p) const
Correct motion points.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
int main(int argc, char *argv[])
Definition: financialFoam.C:44
const pointField & points
Namespace for OpenFOAM.
Type gAverage(const UList< Type > &f, const label comm)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
static const char nl
Definition: Ostream.H:297
uint8_t direction
Definition: direction.H:45