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-------------------------------------------------------------------------------
11License
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
27Application
28 moveDynamicMesh
29
30Group
31 grpMeshManipulationUtilities
32
33Description
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"
45#include "functionObject.H"
46
47using namespace Foam;
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51// Dump patch + weights to vtk file
52void 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
89 instant inst(runTime.value(), runTime.timeName());
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
111void writeWeights(const polyMesh& mesh)
112{
113 const fileName outputDir
114 (
115 mesh.time().globalPath()/functionObject::outputPrefix/"checkAMI"
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
157int main(int argc, char *argv[])
158{
159 argList::addNote
160 (
161 "Mesh motion and topological mesh changes utility"
162 );
163
164 #include "addOverwriteOption.H"
165 #include "addRegionOption.H"
166 argList::addBoolOption
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"
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 {
200 if (pimple.firstIter() || moveMeshOuterCorrectors)
201 {
202 mesh.update();
203 }
204 }
205
206 if (overwrite)
207 {
208 mesh.setInstance(oldInstance);
209 runTime.write();
210 runTime.printExecutionTime(Info);
211 break;
212 }
213
214
215 mesh.checkMesh(true);
216
217 if (checkAMI)
218 {
219 writeWeights(mesh);
220 }
221
222 runTime.write();
223
224 runTime.printExecutionTime(Info);
225 }
226
227 Info<< "End\n" << endl;
228
229 return 0;
230}
231
232
233// ************************************************************************* //
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
pimpleControl & pimple
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
const scalarField & srcWeightsSum() const
const scalarField & tgtWeightsSum() const
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, labelList &pointMergeMap, 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.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A class for handling file names.
Definition: fileName.H:76
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:103
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
Definition: instant.H:56
PIMPLE control class to supply convergence information/checks for the PIMPLE loop.
Definition: pimpleControl.H:58
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
engineTime & runTime
Required Variables.
const std::string patch
OpenFOAM patch number as a std::string.
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
moveMeshOuterCorrectors
Foam::argList args(argc, argv)