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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Application
28  moveDynamicMesh
29 
30 Group
31  grpMeshManipulationUtilities
32 
33 Description
34  Mesh motion and topological mesh changes utility.
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #include "argList.H"
39 #include "Time.H"
40 #include "dynamicFvMesh.H"
41 #include "pimpleControl.H"
42 #include "cyclicAMIPolyPatch.H"
43 #include "PatchTools.H"
44 #include "foamVtkSurfaceWriter.H"
45 #include "functionObject.H"
46 
47 using namespace Foam;
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 // Dump patch + weights to vtk file
52 void writeWeights
53 (
54  const polyMesh& mesh,
55  const scalarField& wghtSum,
56  const primitivePatch& patch,
57  const fileName& directory,
58  const fileName& prefix,
59  const Time& runTime
60 )
61 {
62  // Collect geometry
63  labelList pointToGlobal;
64  labelList uniqueMeshPointLabels;
66  autoPtr<globalIndex> globalFaces;
67  faceList mergedFaces;
68  pointField mergedPoints;
70  (
71  mesh,
72  patch.localFaces(),
73  patch.meshPoints(),
74  patch.meshPointMap(),
75 
76  pointToGlobal,
77  uniqueMeshPointLabels,
79  globalFaces,
80 
81  mergedFaces,
82  mergedPoints
83  );
84 
85  // Collect field
86  scalarField mergedWeights;
87  globalFaces().gather(wghtSum, mergedWeights);
88 
90 
91  if (Pstream::master())
92  {
94  (
95  mergedPoints,
96  mergedFaces,
97  (directory/prefix + "_" + inst.name()),
98  false // serial: master-only
99  );
100 
101  writer.setTime(inst);
104 
106  writer.write("weightsSum", mergedWeights);
107  }
108 }
109 
110 
111 void writeWeights(const polyMesh& mesh)
112 {
113  const fileName outputDir
114  (
116  );
117 
118  for (const polyPatch& pp : mesh.boundaryMesh())
119  {
120  const auto* cpp = isA<cyclicAMIPolyPatch>(pp);
121 
122  if (cpp && cpp->owner())
123  {
124  const auto& cycPatch = *cpp;
125  const auto& nbrPatch = cycPatch.neighbPatch();
126 
127  const AMIPatchToPatchInterpolation& ami = cycPatch.AMI();
128 
129  Info<< "Calculating AMI weights between owner patch: "
130  << cycPatch.name() << " and neighbour patch: "
131  << nbrPatch.name() << endl;
132 
133  writeWeights
134  (
135  mesh,
136  ami.tgtWeightsSum(),
137  nbrPatch,
138  outputDir,
139  "patch" + Foam::name(pp.index()) + "-tgt",
140  mesh.time()
141  );
142  writeWeights
143  (
144  mesh,
145  ami.srcWeightsSum(),
146  cycPatch,
147  outputDir,
148  "patch" + Foam::name(pp.index()) + "-src",
149  mesh.time()
150  );
151  }
152  }
153 }
154 
155 
156 
157 int main(int argc, char *argv[])
158 {
160  (
161  "Mesh motion and topological mesh changes utility"
162  );
163 
164  #include "addOverwriteOption.H"
165  #include "addRegionOption.H"
167  (
168  "checkAMI",
169  "Check AMI weights and write VTK files of the AMI patches"
170  );
171 
172  #include "setRootCase.H"
173  #include "createTime.H"
174  #include "createNamedDynamicFvMesh.H"
175 
176  const bool checkAMI = args.found("checkAMI");
177 
178  if (checkAMI)
179  {
180  Info<< "Writing VTK files with weights of AMI patches." << nl << endl;
181  }
182 
183  const bool overwrite = args.found("overwrite");
184  const word oldInstance = mesh.pointsInstance();
185 
186 
188 
190  (
191  pimple.dict().getOrDefault("moveMeshOuterCorrectors", false)
192  );
193 
194  while (runTime.loop())
195  {
196  Info<< "Time = " << runTime.timeName() << endl;
197 
198  while (pimple.loop())
199  {
201  {
202  mesh.update();
203  }
204  }
205 
206  if (overwrite)
207  {
208  mesh.setInstance(oldInstance);
209  runTime.write();
211  break;
212  }
213 
214 
215  mesh.checkMesh(true);
216 
217  if (checkAMI)
218  {
219  writeWeights(mesh);
220  }
221 
222  runTime.write();
223 
225  }
226 
227  Info<< "End\n" << endl;
228 
229  return 0;
230 }
231 
232 
233 // ************************************************************************* //
const Type & value() const noexcept
Return const reference to value.
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
A class for handling file names.
Definition: fileName.H:71
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
virtual bool loop()
Return true if run should continue and if so increment time.
Definition: Time.C:951
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:374
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:362
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
void write(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData (Poly or Line) or PointData values.
static void gatherAndMerge(const scalar mergeDist, const PrimitivePatch< FaceList, PointField > &pp, Field< typename PrimitivePatch< FaceList, PointField >::point_type > &mergedPoints, List< typename PrimitivePatch< FaceList, PointField >::face_type > &mergedFaces, globalIndex &pointAddr, globalIndex &faceAddr, labelList &pointMergeMap=const_cast< labelList &>(labelList::null()), const bool useLocal=false)
Gather points and faces onto master and merge into single patch.
A list of faces which address into the list of points.
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: polyMesh.C:848
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:584
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool loop()
PIMPLE loop.
virtual bool checkMesh(const bool report=false) const
Check mesh for correctness. Returns false for no error.
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
const scalarField & tgtWeightsSum() const
Return const access to normalisation factor of target patch weights (i.e. the sum before normalisatio...
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
Required Variables.
virtual bool update()=0
Update the mesh for both mesh motion and topology change.
static word timeName(const scalar t, const int precision=precision_)
Return time name of given scalar time formatted with the given precision.
Definition: Time.C:770
pimpleControl & pimple
virtual const dictionary dict() const
Return the solution dictionary.
Ostream & printExecutionTime(OSstream &os) const
Print the elapsed ExecutionTime (cpu-time), ClockTime.
Definition: TimeIO.C:620
moveMeshOuterCorrectors
const scalarField & srcWeightsSum() const
Return const access to normalisation factor of source patch weights (i.e. the sum before normalisatio...
virtual void setTime(const instant &inst)
Define a time name/value for the output.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
Definition: instant.H:53
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:98
void setInstance(const fileName &instance, const IOobjectOption::writeOption wOpt=IOobject::AUTO_WRITE)
Set the instance for mesh files.
Definition: polyMeshIO.C:29
bool firstIter() const
Return true for first PIMPLE (outer) iteration.
PIMPLE control class to supply convergence information/checks for the PIMPLE loop.
Definition: pimpleControl.H:51
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1037
static word outputPrefix
Directory prefix.
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
const std::string patch
OpenFOAM patch number as a std::string.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool writeGeometry()
Write patch topology.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
void writeTimeValue()
Write the currently set time as "TimeValue" FieldData.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
Foam::argList args(argc, argv)
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
fileName globalPath() const
Return global path for the case.
Definition: TimePathsI.H:73