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 #include "PatchTools.H"
39 
40 using namespace Foam;
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 // Dump patch + weights to vtk file
45 void writeWeights
46 (
47  const polyMesh& mesh,
48  const scalarField& wghtSum,
49  const primitivePatch& patch,
50  const fileName& directory,
51  const fileName& prefix,
52  const word& timeName
53 )
54 {
55  vtkSurfaceWriter writer;
56 
57  // Collect geometry
58  labelList pointToGlobal;
59  labelList uniqueMeshPointLabels;
60  autoPtr<globalIndex> globalPoints;
61  autoPtr<globalIndex> globalFaces;
62  faceList mergedFaces;
63  pointField mergedPoints;
65  (
66  mesh,
67  patch.localFaces(),
68  patch.meshPoints(),
69  patch.meshPointMap(),
70 
71  pointToGlobal,
72  uniqueMeshPointLabels,
73  globalPoints,
74  globalFaces,
75 
76  mergedFaces,
77  mergedPoints
78  );
79  // Collect field
80  scalarField mergedWeights;
81  globalFaces().gather
82  (
85  wghtSum,
86  mergedWeights
87  );
88 
89  if (Pstream::master())
90  {
91  writer.write
92  (
93  directory,
94  prefix + "_" + timeName,
95  mergedPoints,
96  mergedFaces,
97  "weightsSum",
98  mergedWeights,
99  false
100  );
101  }
102 }
103 
104 
105 void writeWeights(const polyMesh& mesh)
106 {
107  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
108 
109  const word tmName(mesh.time().timeName());
110 
111  forAll(pbm, patchi)
112  {
113  if (isA<cyclicAMIPolyPatch>(pbm[patchi]))
114  {
115  const cyclicAMIPolyPatch& cpp =
116  refCast<const cyclicAMIPolyPatch>(pbm[patchi]);
117 
118  if (cpp.owner())
119  {
120  Info<< "Calculating AMI weights between owner patch: "
121  << cpp.name() << " and neighbour patch: "
122  << cpp.neighbPatch().name() << endl;
123 
124  const AMIPatchToPatchInterpolation& ami =
125  cpp.AMI();
126 
127  writeWeights
128  (
129  mesh,
130  ami.tgtWeightsSum(),
131  cpp.neighbPatch(),
132  "postProcessing",
133  "tgt",
134  tmName
135  );
136  writeWeights
137  (
138  mesh,
139  ami.srcWeightsSum(),
140  cpp,
141  "postProcessing",
142  "src",
143  tmName
144  );
145  }
146  }
147  }
148 }
149 
150 
151 
152 int main(int argc, char *argv[])
153 {
154  #include "addRegionOption.H"
156  (
157  "checkAMI",
158  "check AMI weights"
159  );
160 
161  #include "setRootCase.H"
162  #include "createTime.H"
163  #include "createNamedDynamicFvMesh.H"
164 
165  const bool checkAMI = args.optionFound("checkAMI");
166 
167  if (checkAMI)
168  {
169  Info<< "Writing VTK files with weights of AMI patches." << nl << endl;
170  }
171 
172  pimpleControl pimple(mesh);
173 
175  (
176  pimple.dict().lookupOrDefault<Switch>("moveMeshOuterCorrectors", false)
177  );
178 
179  while (runTime.loop())
180  {
181  Info<< "Time = " << runTime.timeName() << endl;
182 
183  while (pimple.loop())
184  {
185  if (pimple.firstIter() || moveMeshOuterCorrectors)
186  {
187  mesh.update();
188  }
189  }
190 
191  mesh.checkMesh(true);
192 
193  if (checkAMI)
194  {
195  writeWeights(mesh);
196  }
197 
198  runTime.write();
199 
200  Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
201  << " ClockTime = " << runTime.elapsedClockTime() << " s"
202  << nl << endl;
203  }
204 
205  Info<< "End\n" << endl;
206 
207  return 0;
208 }
209 
210 
211 // ************************************************************************* //
static void gatherAndMerge(const scalar mergeDist, const PrimitivePatch< Face, FaceList, PointField, PointType > &p, Field< PointType > &mergedPoints, List< Face > &mergedFaces, labelList &pointMergeMap)
Gather points and faces onto master and merge into single patch.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:424
moveMeshOuterCorrectors
Definition: readControls.H:8
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
const AMIPatchToPatchInterpolation & AMI() const
Return a reference to the AMI interpolator.
const word & name() const
Return name.
A class for handling file names.
Definition: fileName.H:69
const dictionary & pimple
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
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 bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:412
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:644
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:275
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
A list of faces which address into the list of points.
const Map< label > & meshPointMap() const
Mesh point map. Given the global point index find its.
A class for handling words, derived from string.
Definition: word.H:59
virtual bool checkMesh(const bool report=false) const
Check mesh for correctness. Returns false for no error.
const scalarField & tgtWeightsSum() const
Return const access to normalisation factor of target.
List< label > labelList
A List of labels.
Definition: labelList.H:56
Cyclic patch for Arbitrary Mesh Interface (AMI)
Foam::polyBoundaryMesh.
static const char nl
Definition: Ostream.H:262
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.
const Time & time() const
Return time.
const scalarField & srcWeightsSum() const
Return const access to normalisation factor of source.
label patchi
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
A surfaceWriter for VTK legacy format.
virtual const cyclicAMIPolyPatch & neighbPatch() const
Return a reference to the neighbour patch.
PIMPLE control class to supply convergence information/checks for the PIMPLE loop.
Definition: pimpleControl.H:52
virtual bool owner() const
Does this side own the patch?
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
messageStream Info
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
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:85
Foam::argList args(argc, argv)
static List< int > & procID(label communicator)
Process ID of given process index.
Definition: UPstream.H:429
Namespace for OpenFOAM.