deformedGeom.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  deformedGeom
28 
29 Group
30  grpMeshManipulationUtilities
31 
32 Description
33  Deforms a polyMesh using a displacement field U and a scaling factor
34  supplied as an argument.
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #include "argList.H"
39 #include "fvMesh.H"
40 #include "pointFields.H"
41 #include "volPointInterpolation.H"
42 
43 using namespace Foam;
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 int main(int argc, char *argv[])
48 {
50  (
51  "Deforms a polyMesh using a displacement field U and a scaling factor"
52  " supplied as an argument"
53  );
54 
55  argList::addArgument("factor", "The deformation scaling factor");
56 
57  #include "setRootCase.H"
58 
59  const scalar scaleFactor = args.get<scalar>(1);
60 
61  #include "createTime.H"
62  #include "createNamedMesh.H"
63 
65 
66  // Get times list
67  instantList Times = runTime.times();
68 
69  pointField zeroPoints(mesh.points());
70 
71  // skip "constant" time
72  for (label timeI = 1; timeI < Times.size(); ++timeI)
73  {
74  runTime.setTime(Times[timeI], timeI);
75 
76  Info<< "Time = " << runTime.timeName() << endl;
77 
78  IOobject Uheader
79  (
80  "U",
81  runTime.timeName(),
82  mesh,
84  );
85 
86  // Check U exists
87  if (Uheader.typeHeaderOk<volVectorField>(true))
88  {
89  Info<< " Reading U" << endl;
90  volVectorField U(Uheader, mesh);
91 
92  pointField newPoints
93  (
94  zeroPoints
95  + scaleFactor*pInterp.interpolate(U)().primitiveField()
96  );
97 
98  mesh.polyMesh::movePoints(newPoints);
99  mesh.write();
100  }
101  else
102  {
103  Info<< " No U" << endl;
104  }
105 
106  Info<< endl;
107  }
108 
109  Info<< "End\n" << 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:462
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Required Classes.
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1078
dynamicFvMesh & mesh
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
Definition: Time.C:902
Interpolate from cell centres to points (vertices) using inverse distance weighting.
virtual bool write(const bool writeOnProc=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1113
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
U
Definition: pEqn.H:72
instantList times() const
Search the case for valid time directories.
Definition: TimePaths.C:118
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:351
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
Namespace for OpenFOAM.
autoPtr< volPointInterpolation > pInterp