moveDynamicMesh.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 | Copyright (C) 2011-2016 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  moveDynamicMesh
26 
27 Description
28  Mesh motion and topological mesh changes utility.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "argList.H"
33 #include "Time.H"
34 #include "dynamicFvMesh.H"
35 #include "pimpleControl.H"
36 #include "vtkSurfaceWriter.H"
37 #include "cyclicAMIPolyPatch.H"
38 
39 using namespace Foam;
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 // Dump patch + weights to vtk file
44 void writeWeights
45 (
46  const scalarField& wghtSum,
47  const primitivePatch& patch,
48  const fileName& directory,
49  const fileName& prefix,
50  const word& timeName
51 )
52 {
53  vtkSurfaceWriter writer;
54 
55  writer.write
56  (
57  directory,
58  prefix + "_proc" + Foam::name(Pstream::myProcNo()) + "_" + timeName,
59  patch.localPoints(),
60  patch.localFaces(),
61  "weightsSum",
62  wghtSum,
63  false
64  );
65 }
66 
67 
68 void writeWeights(const polyMesh& mesh)
69 {
70  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
71 
72  const word tmName(mesh.time().timeName());
73 
74  forAll(pbm, patchi)
75  {
76  if (isA<cyclicAMIPolyPatch>(pbm[patchi]))
77  {
78  const cyclicAMIPolyPatch& cpp =
79  refCast<const cyclicAMIPolyPatch>(pbm[patchi]);
80 
81  if (cpp.owner())
82  {
83  Info<< "Calculating AMI weights between owner patch: "
84  << cpp.name() << " and neighbour patch: "
85  << cpp.neighbPatch().name() << endl;
86 
87  const AMIPatchToPatchInterpolation& ami =
88  cpp.AMI();
89 
90  writeWeights
91  (
92  ami.tgtWeightsSum(),
93  cpp.neighbPatch(),
94  "postProcessing",
95  "tgt",
96  tmName
97  );
98  writeWeights
99  (
100  ami.srcWeightsSum(),
101  cpp,
102  "postProcessing",
103  "src",
104  tmName
105  );
106  }
107  }
108  }
109 }
110 
111 
112 
113 int main(int argc, char *argv[])
114 {
115  #include "addRegionOption.H"
117  (
118  "checkAMI",
119  "check AMI weights"
120  );
121 
122  #include "setRootCase.H"
123  #include "createTime.H"
124  #include "createNamedDynamicFvMesh.H"
125 
126  const bool checkAMI = args.optionFound("checkAMI");
127 
128  if (checkAMI)
129  {
130  Info<< "Writing VTK files with weights of AMI patches." << nl << endl;
131  }
132 
133  pimpleControl pimple(mesh);
134 
136  (
137  pimple.dict().lookupOrDefault<Switch>("moveMeshOuterCorrectors", false)
138  );
139 
140  while (runTime.loop())
141  {
142  Info<< "Time = " << runTime.timeName() << endl;
143 
144  while (pimple.loop())
145  {
146  if (pimple.firstIter() || moveMeshOuterCorrectors)
147  {
148  mesh.update();
149  }
150  }
151 
152  mesh.checkMesh(true);
153 
154  if (checkAMI)
155  {
156  writeWeights(mesh);
157  }
158 
159  runTime.write();
160 
161  Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
162  << " ClockTime = " << runTime.elapsedClockTime() << " s"
163  << nl << endl;
164  }
165 
166  Info<< "End\n" << endl;
167 
168  return 0;
169 }
170 
171 
172 // ************************************************************************* //
const Time & time() const
Return time.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
A class for handling file names.
Definition: fileName.H:69
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:417
const dictionary & pimple
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
Definition: Switch.H:60
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:715
virtual bool checkMesh(const bool report=false) const
Check mesh for correctness. Returns false for no error.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
virtual void write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const bool verbose=false) const
Write single surface geometry to file.
A list of faces which address into the list of points.
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
A class for handling words, derived from string.
Definition: word.H:59
virtual bool owner() const
Does this side own the patch?
Cyclic patch for Arbitrary Mesh Interface (AMI)
const word & name() const
Return name.
Foam::polyBoundaryMesh.
static const char nl
Definition: Ostream.H:262
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
moveMeshOuterCorrectors
Definition: readControls.H:8
label patchi
A surfaceWriter for VTK legacy format.
const scalarField & srcWeightsSum() const
Return const access to normalisation factor of source.
PIMPLE control class to supply convergence information/checks for the PIMPLE loop.
Definition: pimpleControl.H:52
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
const AMIPatchToPatchInterpolation & AMI() const
Return a reference to the AMI interpolator.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:83
const scalarField & tgtWeightsSum() const
Return const access to normalisation factor of target.
Foam::argList args(argc, argv)
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
const Field< PointType > & localPoints() const
Return pointField of points in patch.
virtual const cyclicAMIPolyPatch & neighbPatch() const
Return a reference to the neighbour patch.
Namespace for OpenFOAM.