dynamicMotionSolverFvMeshAMI.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) 2019-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
30 #include "motionSolver.H"
31 #include "volFields.H"
32 #include "surfaceFields.H"
33 #include "cyclicAMIPolyPatch.H"
34 #include "polyTopoChange.H"
35 #include "MeshObject.H"
36 #include "lduMesh.H"
37 #include "surfaceInterpolate.H"
38 
39 #include "processorFvPatch.H"
40 
41 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45  defineTypeNameAndDebug(dynamicMotionSolverFvMeshAMI, 0);
47  (
48  dynamicFvMesh,
49  dynamicMotionSolverFvMeshAMI,
50  IOobject
51  );
53  (
54  dynamicFvMesh,
55  dynamicMotionSolverFvMeshAMI,
56  doInit
57  );
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 
63 Foam::dynamicMotionSolverFvMeshAMI::dynamicMotionSolverFvMeshAMI
64 (
65  const IOobject& io,
66  const bool doInit
67 )
68 :
69  dynamicFvMesh(io, doInit)
70 {
71  if (doInit)
72  {
73  init(false); // do not initialise lower levels
74  }
75 }
76 
77 
79 {
80  if (doInit)
81  {
82  dynamicFvMesh::init(doInit);
83  }
84 
85  motionPtr_ = motionSolver::New(*this);
86  return true;
87 }
88 
89 
90 Foam::dynamicMotionSolverFvMeshAMI::dynamicMotionSolverFvMeshAMI
91 (
92  const IOobject& io,
94  faceList&& faces,
95  labelList&& allOwner,
96  labelList&& allNeighbour,
97  const bool syncPar
98 )
99 :
101  (
102  io,
103  std::move(points),
104  std::move(faces),
105  std::move(allOwner),
106  std::move(allNeighbour),
107  syncPar
108  ),
109  motionPtr_(motionSolver::New(*this))
110 {}
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
116 {
117  return *motionPtr_;
118 }
119 
120 
122 {
123  // Mesh not moved/changed yet
124  moving(false);
125  topoChanging(false);
126 
127  if (debug)
128  {
129  for (const fvPatch& fvp : boundary())
130  {
131  if (!isA<processorFvPatch>(fvp))
132  {
133  Info<< "1 --- patch:" << fvp.patch().name()
134  << " area:" << gSum(fvp.magSf()) << endl;
135  }
136  }
137  }
138 
139  pointField newPoints(motionPtr_->curPoints());
140 
141  polyBoundaryMesh& pbm = const_cast<polyBoundaryMesh&>(boundaryMesh());
142 
143  // Scan all patches and see if we want to apply a mesh topology update
144  bool changeRequired = false;
145  for (label patchi = 0; patchi < pbm.nNonProcessor(); ++patchi)
146  {
147  const polyPatch& pp = pbm[patchi];
148 
149  DebugInfo
150  << "pre-topology change: patch " << pp.name()
151  << " size:" << returnReduce(pp.size(), sumOp<label>())
152  << " mag(faceAreas):" << gSum(mag(pp.faceAreas())) << endl;
153 
154  //changeRequired = pp.changeTopology(newPoints) || changeRequired;
155  changeRequired = pp.changeTopology() || changeRequired;
156  }
157 
158  reduce(changeRequired, orOp<bool>());
159 
160  if (changeRequired)
161  {
162  polyTopoChange polyTopo(*this);
163 
164  // Set new point positions in polyTopo object
165  polyTopo.movePoints(newPoints);
166 
167  // Accumulate the patch-based mesh changes on the current mesh
168  // Note:
169  // - updates the AMIs using the new points
170  // - creates a topo change object that removes old added faces and
171  // adds the new faces
172  for (polyPatch& pp : pbm)
173  {
174  pp.setTopology(polyTopo);
175  }
176 
177  // Update geometry
178  // Note
179  // - changeMesh leads to polyMesh::resetPrimitives which will also
180  // trigger polyBoundaryMesh::updateMesh (init and update) and
181  // ::calcGeometry (with topoChanging = false)
182  // - BUT: mesh still corresponds to original (non-extended mesh) so
183  // we want to bypass these calls...
184  // - after changes topoChanging = true
186  polyTopo.changeMesh
187  (
188  *this,
189  true // We will be calling movePoints after this update
190  );
191 
192  // Apply topology change - update fv geometry and map fields
193  // - polyMesh::updateMesh
194  // - fires initUpdateMesh and updateMesh in AMI BCs - called before
195  // mapFields
196  // - AMI addressing must be up-to-date - used by, e.g. FaceCellWave
197  // - will trigger (again) polyBoundaryMesh::updateMesh (init and update)
198  updateMesh(map());
199 
200  // Move points and update derived properties
201  // Note:
202  // - resets face areas based on raw point locations!
203  // - polyBoundaryMesh::updateMesh (init and update)
204  // Note:
205  // - processorPolyPatches will trigger calculation of faceCentres
206  // (and therefore cell volumes), so need to update faceAreas in
207  // initMovePoints since proc patches will be evaluated later than
208  // AMI patches
209  if (map().hasMotionPoints())
210  {
211  movePoints(map().preMotionPoints());
212  }
213  }
214  else
215  {
216  fvMesh::movePoints(newPoints);
217  }
218 
219  volVectorField* Uptr = getObjectPtr<volVectorField>("U");
220 
221  if (Uptr)
222  {
224 
225  surfaceVectorField* UfPtr = getObjectPtr<surfaceVectorField>("Uf");
226  if (UfPtr)
227  {
228  *UfPtr = fvc::interpolate(*Uptr);
229  }
230  }
231 
232  if (debug)
233  {
234  for (const fvPatch& fvp : boundary())
235  {
236  if (!isA<processorFvPatch>(fvp))
237  {
238  Info<< "2 --- patch:" << fvp.patch().name()
239  << " area:" << gSum(fvp.magSf()) << endl;
240  }
241  }
242  }
243 
244  return true;
245 }
246 
247 
248 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::motionSolver::New
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Definition: motionSolver.C:150
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
processorFvPatch.H
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
motionSolver.H
Foam::polyPatch::changeTopology
virtual bool changeTopology() const
Definition: polyPatch.H:473
polyTopoChange.H
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:99
Foam::dynamicFvMesh::init
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Definition: dynamicFvMesh.C:90
Foam::dynamicFvMesh
Abstract base class for geometry and/or topology changing fvMesh.
Definition: dynamicFvMesh.H:78
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
surfaceFields.H
Foam::surfaceFields.
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:594
Foam::sumOp
Definition: ops.H:213
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
init
mesh init(true)
dynamicMotionSolverFvMeshAMI.H
Foam::polyTopoChange::changeMesh
autoPtr< mapPolyMesh > changeMesh(polyMesh &mesh, const labelUList &patchMap, const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Inplace changes mesh without change of patches.
Definition: polyTopoChange.C:2980
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::surfaceInterpolation::movePoints
virtual bool movePoints()
Do what is necessary if the mesh has moved.
Definition: surfaceInterpolation.C:151
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fvc::interpolate
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
Foam::dynamicMotionSolverFvMeshAMI::motion
const motionSolver & motion() const
Return the motionSolver.
Definition: dynamicMotionSolverFvMeshAMI.C:115
cyclicAMIPolyPatch.H
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:940
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::motionSolver
Virtual base class for mesh motion solver.
Definition: motionSolver.H:58
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:382
Foam::dynamicMotionSolverFvMeshAMI::update
virtual bool update()
Update the mesh for both mesh motion and topology change.
Definition: dynamicMotionSolverFvMeshAMI.C:121
Foam::List< face >
Foam::polyPatch::faceAreas
const vectorField::subField faceAreas() const
Return face normals.
Definition: polyPatch.C:327
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
points
const pointField & points
Definition: gmvOutputHeader.H:1
MeshObject.H
Foam::boundaryMesh
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:62
Foam::patchIdentifier::name
const word & name() const noexcept
The patch name.
Definition: patchIdentifier.H:135
Foam::GeometricField< vector, fvPatchField, volMesh >
lduMesh.H
Foam::orOp
Definition: ops.H:234
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
boundary
faceListList boundary
Definition: createBlockMesh.H:4
Foam::polyTopoChange::movePoints
void movePoints(const pointField &newPoints)
Move all points. Incompatible with other topology changes.
Definition: polyTopoChange.C:2680
Foam::dynamicMotionSolverFvMeshAMI::init
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Definition: dynamicMotionSolverFvMeshAMI.C:78