pointMesh.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "pointMesh.H"
27 #include "globalMeshData.H"
28 #include "pointMeshMapper.H"
29 #include "pointFields.H"
30 #include "MapGeometricFields.H"
31 #include "MapPointField.H"
32 #include "facePointPatch.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 defineTypeNameAndDebug(pointMesh, 0);
40 
41 }
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
45 void Foam::pointMesh::mapFields(const mapPolyMesh& mpm)
46 {
47  if (debug)
48  {
49  Pout<< "void pointMesh::mapFields(const mapPolyMesh&): "
50  << "Mapping all registered pointFields."
51  << endl;
52  }
53  // Create a mapper
54  const pointMeshMapper m(*this, mpm);
55 
56  MapGeometricFields<scalar, pointPatchField, pointMeshMapper, pointMesh>(m);
57  MapGeometricFields<vector, pointPatchField, pointMeshMapper, pointMesh>(m);
59  <
61  pointPatchField,
62  pointMeshMapper,
63  pointMesh
64  >(m);
65  MapGeometricFields<symmTensor, pointPatchField, pointMeshMapper, pointMesh>
66  (m);
67  MapGeometricFields<tensor, pointPatchField, pointMeshMapper, pointMesh>(m);
68 }
69 
70 
71 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
72 
74 :
76  GeoMesh<polyMesh>(pMesh),
77  boundary_(*this, pMesh.boundaryMesh())
78 {
79  if (debug)
80  {
81  Pout<< "pointMesh::pointMesh(const polyMesh&): "
82  << "Constructing from polyMesh " << pMesh.name()
83  << endl;
84  }
85 
86  // Calculate the geometry for the patches (transformation tensors etc.)
87  boundary_.calcGeometry();
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
92 
94 {
95  if (debug)
96  {
97  Pout<< "~pointMesh::pointMesh()"
98  << endl;
100  }
101 }
102 
103 
104 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
105 
106 void Foam::pointMesh::reset(const bool validBoundary)
107 {
108  const polyMesh& pm = operator()();
109  if (debug)
110  {
111  Pout<< "pointMesh::reset(const bool validBoundary): "
112  << "Resetting from polyMesh " << pm.name() << endl;
113  }
114 
115  boundary_.reset(pm.boundaryMesh());
116  if (validBoundary)
117  {
118  // Calculate the geometry for the patches (transformation tensors etc.)
119  boundary_.calcGeometry();
120  }
121 }
122 
123 
125 {
126  if (debug)
127  {
128  Pout<< "pointMesh::movePoints(const pointField&): "
129  << "Moving points." << endl;
130  }
131 
133 
134  return true;
135 }
136 
137 
139 {
140  if (debug)
141  {
142  Pout<< "pointMesh::updateMesh(const mapPolyMesh&): "
143  << "Updating for topology changes." << endl;
144  Pout<< endl;
145  }
146  boundary_.updateMesh();
147 
148  // Map all registered point fields
149  mapFields(mpm);
150 }
151 
152 
154 (
155  const labelUList& newToOld,
156  const bool validBoundary
157 )
158 {
159  if (debug)
160  {
161  Pout<< "pointMesh::reorderPatches( const labelUList&, const bool): "
162  << "Updating for reordered patches." << endl;
163  Pout<< endl;
164  }
165 
166  boundary_.shuffle(newToOld, validBoundary);
167 
168  objectRegistry& db = const_cast<objectRegistry&>(thisDb());
169  ReorderPatchFields<pointScalarField>(db, newToOld);
170  ReorderPatchFields<pointVectorField>(db, newToOld);
171  ReorderPatchFields<pointSphericalTensorField>(db, newToOld);
172  ReorderPatchFields<pointSymmTensorField>(db, newToOld);
173  ReorderPatchFields<pointTensorField>(db, newToOld);
174 }
175 
176 
178 {
179  if (debug)
180  {
181  Pout<< "pointMesh::addPatch(const label): "
182  << "Adding patch at " << patchi << endl;
183  Pout<< endl;
184  }
185 
186  const polyBoundaryMesh& pbm = mesh().boundaryMesh();
187  if (pbm.size() != boundary_.size())
188  {
189  FatalErrorInFunction << "Problem :"
190  << " pointBoundaryMesh size :" << boundary_.size()
191  << " polyBoundaryMesh size :" << pbm.size()
192  << exit(FatalError);
193  }
194 
195  boundary_.set(patchi, facePointPatch::New(pbm[patchi], boundary_).ptr());
196 
197  objectRegistry& db = const_cast<objectRegistry&>(thisDb());
198  const dictionary d;
199  const word patchFieldType("calculated");
200 
201  AddPatchFields<pointScalarField>(db, patchi, d, patchFieldType, Zero);
202  AddPatchFields<pointVectorField>(db, patchi, d, patchFieldType, Zero);
203  AddPatchFields<pointSphericalTensorField>
204  (
205  db,
206  patchi,
207  d,
209  Zero
210  );
211  AddPatchFields<pointSymmTensorField>(db, patchi, d, patchFieldType, Zero);
212  AddPatchFields<pointTensorField>(db, patchi, d, patchFieldType, Zero);
213 }
214 
215 
216 // ************************************************************************* //
virtual bool movePoints()
Move points.
Definition: pointMesh.C:124
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:434
static void printStack(Ostream &)
Helper function to print a stack.
virtual void reorderPatches(const labelUList &newToOld, const bool validBoundary)
Reordered/removed trailing patches. If validBoundary call is.
Definition: pointMesh.C:154
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const word & name() const
Return name.
Definition: IOobject.H:303
bool set(const label) const
Is element set.
Definition: PtrListI.H:65
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void reset(const bool validBoundary)
Reset for changed polyMesh.
Definition: pointMesh.C:106
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
void movePoints(const pointField &)
Correct pointBoundaryMesh after moving points.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
void shuffle(const labelUList &newToOld, const bool validBoundary)
Reorders patches. Ordering does not have to be done in.
virtual void addPatch(const label patchi)
Inserted patch at patchi.
Definition: pointMesh.C:177
virtual void updateMesh(const mapPolyMesh &mpm)
Update the mesh corresponding to given map.
Definition: pointMesh.C:138
void updateMesh()
Correct pointBoundaryMesh after topology update.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
static autoPtr< facePointPatch > New(const polyPatch &, const pointBoundaryMesh &)
Return a pointer to a new patch created on freestore from polyPatch.
void MapGeometricFields(const MeshMapper &mapper)
Generic Geometric field mapper.
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:48
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:85
const pointField & points
A class for handling words, derived from string.
Definition: word.H:59
const objectRegistry & thisDb() const
Return database. For now is its polyMesh.
Definition: pointMesh.H:115
~pointMesh()
Destructor.
Definition: pointMesh.C:93
static const zero Zero
Definition: zero.H:97
void reset(const polyBoundaryMesh &)
Create pointBoundaryMesh from polyBoundaryMesh.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
Foam::polyBoundaryMesh.
defineTypeNameAndDebug(combustionModel, 0)
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
label patchi
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
pointMesh(const polyMesh &pMesh)
Construct from polyMesh.
Definition: pointMesh.C:73
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars.
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:46
Registry of regIOobjects.
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:312
word patchFieldType(const PatchField &pf)
const polyMesh & operator()() const
Return reference to polyMesh.
Definition: GeoMesh.H:86
Namespace for OpenFOAM.