meshRefinementTemplates.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 | Copyright (C) 2011-2015 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 "meshRefinement.H"
27 #include "fvMesh.H"
28 #include "globalIndex.H"
29 #include "syncTools.H"
30 
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 
33 // Add a T entry
34 template<class T> void Foam::meshRefinement::updateList
35 (
36  const labelList& newToOld,
37  const T& nullValue,
38  List<T>& elems
39 )
40 {
41  List<T> newElems(newToOld.size(), nullValue);
42 
43  forAll(newElems, i)
44  {
45  label oldI = newToOld[i];
46 
47  if (oldI >= 0)
48  {
49  newElems[i] = elems[oldI];
50  }
51  }
52 
53  elems.transfer(newElems);
54 }
55 
56 
57 template<class T>
59 (
60  const PackedBoolList& isMasterElem,
61  const UList<T>& values
62 )
63 {
64  if (values.size() != isMasterElem.size())
65  {
67  << "Number of elements in list " << values.size()
68  << " does not correspond to number of elements in isMasterElem "
69  << isMasterElem.size()
70  << exit(FatalError);
71  }
72 
74  label n = 0;
75 
76  forAll(values, i)
77  {
78  if (isMasterElem[i])
79  {
80  sum += values[i];
81  n++;
82  }
83  }
84 
85  reduce(sum, sumOp<T>());
86  reduce(n, sumOp<label>());
87 
88  if (n > 0)
89  {
90  return sum/n;
91  }
92  else
93  {
94  return pTraits<T>::max;
95  }
96 }
97 
98 
99 // Compare two lists over all boundary faces
100 template<class T>
102 (
103  const scalar tol,
104  const string& msg,
105  const UList<T>& faceData,
106  const UList<T>& syncedFaceData
107 ) const
108 {
109  label nBFaces = mesh_.nFaces() - mesh_.nInternalFaces();
110 
111  if (faceData.size() != nBFaces || syncedFaceData.size() != nBFaces)
112  {
114  << "Boundary faces:" << nBFaces
115  << " faceData:" << faceData.size()
116  << " syncedFaceData:" << syncedFaceData.size()
117  << abort(FatalError);
118  }
119 
120  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
121 
122  forAll(patches, patchI)
123  {
124  const polyPatch& pp = patches[patchI];
125 
126  label bFaceI = pp.start() - mesh_.nInternalFaces();
127 
128  forAll(pp, i)
129  {
130  const T& data = faceData[bFaceI];
131  const T& syncData = syncedFaceData[bFaceI];
132 
133  if (mag(data - syncData) > tol)
134  {
135  label faceI = pp.start()+i;
136 
138  << msg
139  << "patchFace:" << i
140  << " face:" << faceI
141  << " fc:" << mesh_.faceCentres()[faceI]
142  << " patch:" << pp.name()
143  << " faceData:" << data
144  << " syncedFaceData:" << syncData
145  << " diff:" << mag(data - syncData)
146  << abort(FatalError);
147  }
148 
149  bFaceI++;
150  }
151  }
152 }
153 
154 
155 // Print list sorted by coordinates. Used for comparing non-parallel v.s.
156 // parallel operation
157 template<class T>
159 (
160  const UList<point>& points,
161  const UList<T>& data
162 )
163 {
165 
167  globalPoints.gather
168  (
169  Pstream::worldComm,
170  identity(Pstream::nProcs()),
171  points,
172  allPoints,
173  UPstream::msgType(),
174  Pstream::blocking
175  );
176 
177  List<T> allData;
178  globalPoints.gather
179  (
180  Pstream::worldComm,
181  identity(Pstream::nProcs()),
182  data,
183  allData,
184  UPstream::msgType(),
185  Pstream::blocking
186  );
187 
188 
189  scalarField magAllPoints(mag(allPoints-point(-0.317, 0.117, 0.501)));
190 
191  labelList visitOrder;
192  sortedOrder(magAllPoints, visitOrder);
193  forAll(visitOrder, i)
194  {
195  label allPointI = visitOrder[i];
196  Info<< allPoints[allPointI] << " : " << allData[allPointI]
197  << endl;
198  }
199 }
200 
201 
202 //template<class T, class Mesh>
203 template<class GeoField>
205 (
206  fvMesh& mesh,
207  const word& patchFieldType
208 )
209 {
211  (
212  mesh.objectRegistry::lookupClass<GeoField>()
213  );
214 
215  forAllIter(typename HashTable<GeoField*>, flds, iter)
216  {
217  GeoField& fld = *iter();
218  typename GeoField::GeometricBoundaryField& bfld = fld.boundaryField();
219 
220  label sz = bfld.size();
221  bfld.setSize(sz+1);
222  bfld.set
223  (
224  sz,
226  (
227  patchFieldType,
228  mesh.boundary()[sz],
229  fld.dimensionedInternalField()
230  )
231  );
232  }
233 }
234 
235 
236 // Reorder patch field
237 template<class GeoField>
239 (
240  fvMesh& mesh,
241  const labelList& oldToNew
242 )
243 {
245  (
246  mesh.objectRegistry::lookupClass<GeoField>()
247  );
248 
249  forAllIter(typename HashTable<GeoField*>, flds, iter)
250  {
251  GeoField& fld = *iter();
252  typename GeoField::GeometricBoundaryField& bfld = fld.boundaryField();
253 
254  bfld.reorder(oldToNew);
255  }
256 }
257 
258 
259 template<class Enum>
261 (
262  const Enum& namedEnum,
263  const wordList& words
264 )
265 {
266  int flags = 0;
267 
268  forAll(words, i)
269  {
270  int index = namedEnum[words[i]];
271  int val = 1<<index;
272  flags |= val;
273  }
274  return flags;
275 }
276 
277 
278 template<class Type>
280 (
281  const polyMesh& mesh,
282  const PackedBoolList& isMasterEdge,
283  const labelList& meshPoints,
284  const edgeList& edges,
285  const scalarField& edgeWeights,
286  const Field<Type>& pointData,
288 )
289 {
290  if
291  (
292  edges.size() != isMasterEdge.size()
293  || edges.size() != edgeWeights.size()
294  || meshPoints.size() != pointData.size()
295  )
296  {
298  << "Inconsistent sizes for edge or point data:"
299  << " isMasterEdge:" << isMasterEdge.size()
300  << " edgeWeights:" << edgeWeights.size()
301  << " edges:" << edges.size()
302  << " pointData:" << pointData.size()
303  << " meshPoints:" << meshPoints.size()
304  << abort(FatalError);
305  }
306 
307  sum.setSize(meshPoints.size());
309 
310  forAll(edges, edgeI)
311  {
312  if (isMasterEdge[edgeI])
313  {
314  const edge& e = edges[edgeI];
315 
316  scalar eWeight = edgeWeights[edgeI];
317 
318  label v0 = e[0];
319  label v1 = e[1];
320 
321  sum[v0] += eWeight*pointData[v1];
322  sum[v1] += eWeight*pointData[v0];
323  }
324  }
325 
326  syncTools::syncPointList
327  (
328  mesh,
329  meshPoints,
330  sum,
331  plusEqOp<Type>(),
332  pTraits<Type>::zero // null value
333  );
334 }
335 
336 
337 // ************************************************************************* //
Foam::PackedBoolList
A bit-packed bool list.
Definition: PackedBoolList.H:63
Foam::globalPoints
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:100
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
forAllIter
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:431
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
globalIndex.H
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::pointData
Variant of pointEdgePoint with some transported additional data. WIP - should be templated on data li...
Definition: pointData.H:53
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
syncTools.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::meshRefinement::updateList
static void updateList(const labelList &newToOld, const T &nullValue, List< T > &elems)
Helper: reorder list according to map.
Definition: meshRefinementTemplates.C:35
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::sortedOrder
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
Definition: ListOpsTemplates.C:179
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::meshRefinement::reorderPatchFields
static void reorderPatchFields(fvMesh &, const labelList &oldToNew)
Reorder patchfields of all fields on mesh.
Definition: meshRefinementTemplates.C:239
Foam::meshRefinement::collectAndPrint
static void collectAndPrint(const UList< point > &points, const UList< T > &data)
Print list according to (collected and) sorted coordinate.
Definition: meshRefinementTemplates.C:159
Foam::identity
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
Foam::FatalError
error FatalError
Foam::meshRefinement::readFlags
static int readFlags(const Enum &namedEnum, const wordList &)
Helper: convert wordList into bit pattern using provided.
Definition: meshRefinementTemplates.C:261
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
fld
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
meshRefinement.H
Foam::plusEqOp
Definition: ops.H:71
Foam::meshRefinement::addPatchFields
static void addPatchFields(fvMesh &, const word &patchFieldType)
Add patchfield of given type to all fields on mesh.
Definition: meshRefinementTemplates.C:205
Foam::meshRefinement::testSyncBoundaryFaceList
void testSyncBoundaryFaceList(const scalar mergeDistance, const string &, const UList< T > &, const UList< T > &) const
Compare two lists over all boundary faces.
Definition: meshRefinementTemplates.C:102
Foam::meshRefinement::weightedSum
static void weightedSum(const polyMesh &mesh, const PackedBoolList &isMasterEdge, const labelList &meshPoints, const edgeList &edges, const scalarField &edgeWeights, const Field< Type > &data, Field< Type > &sum)
Helper: weighted sum (over all subset of mesh points) by.
Definition: meshRefinementTemplates.C:280
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
fvMesh.H
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::HashTable
An STL-conforming hash table.
Definition: HashTable.H:61
Foam::meshRefinement::gAverage
static T gAverage(const PackedBoolList &isMasterElem, const UList< T > &values)
Helper: calculate average.
Definition: meshRefinementTemplates.C:59
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
T
const volScalarField & T
Definition: createFields.H:25
Foam::sumOp
Definition: ops.H:162
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::UList< T >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: doubleFloat.H:94
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:333
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::DelaunayMeshTools::allPoints
tmp< pointField > allPoints(const Triangulation &t)
Extract all points in vertex-index order.
Foam::PackedList::size
label size() const
Number of entries.
Definition: PackedListI.H:714
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::point
vector point
Point is a vector.
Definition: point.H:41
Foam::UList::size
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
Foam::patchIdentifier::name
const word & name() const
Return name.
Definition: patchIdentifier.H:109
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:52