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  );
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
57 Foam::dynamicMotionSolverFvMeshAMI::dynamicMotionSolverFvMeshAMI
58 (
59  const IOobject& io
60 )
61 :
62  dynamicFvMesh(io),
63  motionPtr_(motionSolver::New(*this))
64 {}
65 
66 
67 Foam::dynamicMotionSolverFvMeshAMI::dynamicMotionSolverFvMeshAMI
68 (
69  const IOobject& io,
71  faceList&& faces,
72  labelList&& allOwner,
73  labelList&& allNeighbour,
74  const bool syncPar
75 )
76 :
78  (
79  io,
80  std::move(points),
81  std::move(faces),
82  std::move(allOwner),
83  std::move(allNeighbour),
84  syncPar
85  ),
86  motionPtr_(motionSolver::New(*this))
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91 
93 {
94  return *motionPtr_;
95 }
96 
97 
99 {
100  // Mesh not moved/changed yet
101  moving(false);
102  topoChanging(false);
103 
104  if (debug)
105  {
106  for (const fvPatch& fvp : boundary())
107  {
108  if (!isA<processorFvPatch>(fvp))
109  {
110  Info<< "1 --- patch:" << fvp.patch().name()
111  << " area:" << gSum(fvp.magSf()) << endl;
112  }
113  }
114  }
115 
116  pointField newPoints(motionPtr_->curPoints());
117 
118  polyBoundaryMesh& pbm = const_cast<polyBoundaryMesh&>(boundaryMesh());
119 
120  // Scan all patches and see if we want to apply a mesh topology update
121  bool changeRequired = false;
122  for (polyPatch& pp : pbm)
123  {
124  DebugInfo
125  << "pre-topology change: patch " << pp.name()
126  << " size:" << returnReduce(pp.size(), sumOp<label>())
127  << " mag(faceAreas):" << gSum(mag(pp.faceAreas())) << endl;
128 
129  //changeRequired = pp.changeTopology(newPoints) || changeRequired;
130  changeRequired = pp.changeTopology() || changeRequired;
131  }
132 
133  reduce(changeRequired, orOp<bool>());
134 
135  if (changeRequired)
136  {
137  polyTopoChange polyTopo(*this);
138 
139  // Set new point positions in polyTopo object
140  polyTopo.movePoints(newPoints);
141 
142  // Accumulate the patch-based mesh changes on the current mesh
143  // Note:
144  // - updates the AMIs using the new points
145  // - creates a topo change object that removes old added faces and
146  // adds the new faces
147  for (polyPatch& pp : pbm)
148  {
149  pp.setTopology(polyTopo);
150  }
151 
152  // Update geometry
153  // Note
154  // - changeMesh leads to polyMesh::resetPrimitives which will also
155  // trigger polyBoundaryMesh::updateMesh (init and update) and
156  // ::calcGeometry (with topoChanging = false)
157  // - BUT: mesh still corresponds to original (non-extended mesh) so
158  // we want to bypass these calls...
159  // - after changes topoChanging = true
161  polyTopo.changeMesh
162  (
163  *this,
164  true // We will be calling movePoints after this update
165  );
166 
167  // Apply topology change - update fv geometry and map fields
168  // - polyMesh::updateMesh
169  // - fires initUpdateMesh and updateMesh in AMI BCs - called before
170  // mapFields
171  // - AMI addressing must be up-to-date - used by, e.g. FaceCellWave
172  // - will trigger (again) polyBoundaryMesh::updateMesh (init and update)
173  updateMesh(map());
174 
175  // Move points and update derived properties
176  // Note:
177  // - resets face areas based on raw point locations!
178  // - polyBoundaryMesh::updateMesh (init and update)
179  // Note:
180  // - processorPolyPatches will trigger calculation of faceCentres
181  // (and therefore cell volumes), so need to update faceAreas in
182  // initMovePoints since proc patches will be evaluated later than
183  // AMI patches
184  if (map().hasMotionPoints())
185  {
186  movePoints(map().preMotionPoints());
187  }
188  }
189  else
190  {
191  fvMesh::movePoints(newPoints);
192  }
193 
194  volVectorField* Uptr = getObjectPtr<volVectorField>("U");
195 
196  if (Uptr)
197  {
199 
200  surfaceVectorField* UfPtr = getObjectPtr<surfaceVectorField>("Uf");
201  if (UfPtr)
202  {
203  *UfPtr = fvc::interpolate(*Uptr);
204  }
205  }
206 
207  if (debug)
208  {
209  for (const fvPatch& fvp : boundary())
210  {
211  if (!isA<processorFvPatch>(fvp))
212  {
213  Info<< "2 --- patch:" << fvp.patch().name()
214  << " area:" << gSum(fvp.magSf()) << endl;
215  }
216  }
217  }
218 
219  return true;
220 }
221 
222 
223 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
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:62
motionSolver.H
Foam::polyTopoChange::changeMesh
autoPtr< mapPolyMesh > changeMesh(polyMesh &mesh, 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:2955
polyTopoChange.H
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:99
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:350
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 (uses stdout - output is on the master only)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:67
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
dynamicMotionSolverFvMeshAMI.H
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::surfaceInterpolation::movePoints
bool movePoints()
Do what is necessary if the mesh has moved.
Definition: surfaceInterpolation.C:125
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:92
cyclicAMIPolyPatch.H
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:940
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
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:354
Foam::dynamicMotionSolverFvMeshAMI::update
virtual bool update()
Update the mesh for both mesh motion and topology change.
Definition: dynamicMotionSolverFvMeshAMI.C:98
Foam::List< face >
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::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:2655