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-------------------------------------------------------------------------------
10License
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
43namespace Foam
44{
47 (
51 );
53 (
56 doInit
57 );
58}
59
60
61// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62
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
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
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
void correctBoundaryConditions()
Correct boundary field.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:63
Abstract base class for geometry and/or topology changing fvMesh.
Definition: dynamicFvMesh.H:81
The dynamicMotionSolverFvMeshAMI.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
virtual bool update()
Update the mesh for both mesh motion and topology change.
const motionSolver & motion() const
Return the motionSolver.
virtual bool movePoints()
Avoid masking surfaceInterpolation method.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
Virtual base class for mesh motion solver.
Definition: motionSolver.H:61
const word & name() const noexcept
The patch name.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
label nNonProcessor() const
The number of patches before the first processor patch.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
const vectorField::subField faceAreas() const
Return face normals.
Definition: polyPatch.C:327
virtual bool changeTopology() const
Definition: polyPatch.H:476
Direct mesh changes based on v1.3 polyTopoChange syntax.
void movePoints(const pointField &newPoints)
Move all points. Incompatible with other topology changes.
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.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
faceListList boundary
const pointField & points
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#define DebugInfo
Report an information message using Foam::Info.
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.
Namespace for OpenFOAM.
Type gSum(const FieldField< Field, Type > &f)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
Foam::surfaceFields.