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);
102  writer.writeTimeValue();
103  writer.writeGeometry();
104 
105  writer.beginCellData(1);
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 // ************************************************************************* //
Foam::solutionControl::dict
virtual const dictionary dict() const
Definition: solutionControl.C:293
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::pimpleControl
PIMPLE control class to supply convergence information/checks for the PIMPLE loop.
Definition: pimpleControl.H:51
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Foam::globalPoints
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:98
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::fileName
A class for handling file names.
Definition: fileName.H:71
Foam::dynamicFvMesh::update
virtual bool update()=0
Foam::primitiveMesh::checkMesh
virtual bool checkMesh(const bool report=false) const
Definition: primitiveMeshCheck.C:1818
PatchTools.H
Foam::PatchTools::gatherAndMerge
static void gatherAndMerge(const scalar mergeDist, const PrimitivePatch< FaceList, PointField > &p, Field< typename PrimitivePatch< FaceList, PointField >::point_type > &mergedPoints, List< typename PrimitivePatch< FaceList, PointField >::face_type > &mergedFaces, labelList &pointMergeMap)
Definition: PatchToolsGatherAndMerge.C:31
addOverwriteOption.H
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:773
Foam::writer::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const =0
Foam::argList::addNote
static void addNote(const string &note)
Definition: argList.C:405
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Definition: UPstream.H:453
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Definition: polyMesh.H:440
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::dimensioned::value
const Type & value() const
Definition: dimensionedType.C:427
foamVtkSurfaceWriter.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
pimpleControl.H
Foam::Time::printExecutionTime
Ostream & printExecutionTime(OSstream &os) const
Definition: TimeIO.C:611
Foam::polyMesh::pointsInstance
const fileName & pointsInstance() const
Definition: polyMesh.C:839
pimple
pimpleControl & pimple
Definition: setRegionFluidFields.H:56
Foam::Field
Generic templated field type.
Definition: Field.H:59
Foam::regIOobject::write
virtual bool write(const bool valid=true) const
Definition: regIOobjectWrite.C:125
Foam::Info
messageStream Info
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:64
argList.H
Foam::AMIInterpolation::srcWeightsSum
const scalarField & srcWeightsSum() const
Definition: AMIInterpolationI.H:146
addRegionOption.H
Foam::functionObject::outputPrefix
static word outputPrefix
Definition: functionObject.H:373
Foam::Time::loop
virtual bool loop()
Definition: Time.C:950
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:77
Foam::pimpleControl::loop
virtual bool loop()
Definition: pimpleControl.C:193
Foam
Definition: atmBoundaryLayer.C:26
cyclicAMIPolyPatch.H
Foam::pimpleControl::firstIter
bool firstIter() const
Definition: pimpleControlI.H:79
Foam::argList::addBoolOption
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Definition: argList.C:317
Time.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:49
setRootCase.H
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::vtk::surfaceWriter
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
Definition: foamVtkSurfaceWriter.H:61
Foam::foamVersion::patch
const std::string patch
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:58
createNamedDynamicFvMesh.H
Foam::AMIInterpolation
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
Definition: AMIInterpolation.H:75
createTime.H
dynamicFvMesh.H
Foam::TimePaths::globalPath
fileName globalPath() const
Definition: TimePathsI.H:73
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::fvMesh::time
const Time & time() const
Definition: fvMesh.H:276
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:48
moveMeshOuterCorrectors
moveMeshOuterCorrectors
Definition: readDyMControls.H:15
functionObject.H
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:141
args
Foam::argList args(argc, argv)
writer
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
Foam::AMIInterpolation::tgtWeightsSum
const scalarField & tgtWeightsSum() const
Definition: AMIInterpolationI.H:212
Foam::polyMesh::setInstance
void setInstance(const fileName &instance, const IOobject::writeOption wOpt=IOobject::AUTO_WRITE)
Definition: polyMeshIO.C:29
Foam::argList::found
bool found(const word &optName) const
Definition: argListI.H:171
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:75