automatic.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) 2012-2017 OpenFOAM Foundation
9  Copyright (C) 2016-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "automatic.H"
31 #include "triSurfaceMesh.H"
32 #include "foamVtkSurfaceWriter.H"
34 #include "Time.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(automatic, 0);
41  addToRunTimeSelectionTable(cellSizeCalculationType, automatic, dictionary);
42 }
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
47 void Foam::automatic::smoothField(triSurfaceScalarField& surf)
48 {
49  label nSmoothingIterations = 10;
50 
51  for (label iter = 0; iter < nSmoothingIterations; ++iter)
52  {
53  const pointField& faceCentres = surface_.faceCentres();
54 
55  forAll(surf, sI)
56  {
57  const labelList& faceFaces = surface_.faceFaces()[sI];
58 
59  const point& fC = faceCentres[sI];
60  const scalar value = surf[sI];
61 
62  scalar newValue = 0;
63  scalar totalDist = 0;
64 
65  label nFaces = 0;
66 
67  forAll(faceFaces, fI)
68  {
69  const label faceLabel = faceFaces[fI];
70  const point& faceCentre = faceCentres[faceLabel];
71 
72  const scalar faceValue = surf[faceLabel];
73  const scalar distance = mag(faceCentre - fC);
74 
75  newValue += faceValue/(distance + SMALL);
76 
77  totalDist += 1.0/(distance + SMALL);
78 
79  if (value < faceValue)
80  {
81  nFaces++;
82  }
83  }
84 
85  // Do not smooth out the peak values
86  if (nFaces == faceFaces.size())
87  {
88  continue;
89  }
90 
91  surf[sI] = newValue/totalDist;
92  }
93  }
94 }
95 
96 
97 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
98 
100 (
101  const dictionary& cellSizeCalcTypeDict,
102  const triSurfaceMesh& surface,
103  const scalar defaultCellSize
104 )
105 :
106  cellSizeCalculationType
107  (
108  typeName,
109  cellSizeCalcTypeDict,
110  surface,
111  defaultCellSize
112  ),
113  coeffsDict_(cellSizeCalcTypeDict.optionalSubDict(typeName + "Coeffs")),
114  surfaceName_(surface.searchableSurface::name()),
115 
116  readCurvature_(coeffsDict_.get<bool>("curvature")),
117  readFeatureProximity_(coeffsDict_.get<bool>("featureProximity")),
118  readInternalCloseness_(coeffsDict_.get<bool>("internalCloseness")),
119 
120  curvatureFile_(coeffsDict_.get<word>("curvatureFile")),
121  featureProximityFile_(coeffsDict_.get<word>("featureProximityFile")),
122  internalClosenessFile_(coeffsDict_.get<word>("internalClosenessFile")),
123 
124  curvatureCellSizeCoeff_
125  (
126  coeffsDict_.get<scalar>("curvatureCellSizeCoeff")
127  ),
128  maximumCellSize_
129  (
130  coeffsDict_.get<scalar>("maximumCellSizeCoeff") * defaultCellSize
131  )
132 {}
133 
134 
135 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
136 
138 {
139  Info<< indent
140  << "Calculating cell size on surface: " << surfaceName_ << endl;
141 
142  tmp<triSurfacePointScalarField> tPointCellSize
143  (
145  (
146  IOobject
147  (
148  surfaceName_ + ".cellSize",
149  surface_.searchableSurface::time().constant(),
150  "triSurface",
151  surface_.searchableSurface::time(),
154  ),
155  surface_,
156  dimLength,
157  scalarField(surface_.nPoints(), maximumCellSize_)
158  )
159  );
160 
161  triSurfacePointScalarField& pointCellSize = tPointCellSize.ref();
162 
163  if (readCurvature_)
164  {
165  Info<< indent
166  << "Reading curvature : " << curvatureFile_ << endl;
167 
169  (
170  IOobject
171  (
172  curvatureFile_,
173  surface_.searchableSurface::time().constant(),
174  "triSurface",
175  surface_.searchableSurface::time(),
178  ),
179  surface_,
180  dimLength,
181  true
182  );
183 
184  forAll(pointCellSize, pI)
185  {
186  pointCellSize[pI] =
187  min
188  (
189  1.0
190  /max
191  (
192  (1.0/curvatureCellSizeCoeff_)*mag(curvature[pI]),
193  1.0/maximumCellSize_
194  ),
195  pointCellSize[pI]
196  );
197  }
198  }
199 
200  PrimitivePatchInterpolation
201  <
202  PrimitivePatch<::Foam::List<labelledTri>, pointField>
203  > patchInterpolate(surface_);
204 
205  const Map<label>& meshPointMap = surface_.meshPointMap();
206 
207  if (readInternalCloseness_)
208  {
209  Info<< indent
210  << "Reading internal closeness: " << internalClosenessFile_ << endl;
211 
212  triSurfaceScalarField internalCloseness
213  (
214  IOobject
215  (
216  internalClosenessFile_,
217  surface_.searchableSurface::time().constant(),
218  "triSurface",
219  surface_.searchableSurface::time(),
222  ),
223  surface_,
224  dimLength,
225  true
226  );
227 
228  scalarField internalClosenessPointField
229  (
230  patchInterpolate.faceToPointInterpolate(internalCloseness)
231  );
232 
233  forAll(pointCellSize, pI)
234  {
235  pointCellSize[pI] =
236  min
237  (
238  internalClosenessPointField[meshPointMap[pI]],
239  pointCellSize[pI]
240  );
241  }
242  }
243 
244  if (readFeatureProximity_)
245  {
246  Info<< indent
247  << "Reading feature proximity : " << featureProximityFile_ << endl;
248 
250  (
251  IOobject
252  (
253  featureProximityFile_,
254  surface_.searchableSurface::time().constant(),
255  "triSurface",
256  surface_.searchableSurface::time(),
259  ),
260  surface_,
261  dimLength,
262  true
263  );
264 
265  scalarField featureProximityPointField
266  (
267  patchInterpolate.faceToPointInterpolate(featureProximity)
268  );
269 
270  forAll(pointCellSize, pI)
271  {
272  pointCellSize[pI] =
273  min
274  (
275  featureProximityPointField[meshPointMap[pI]],
276  pointCellSize[pI]
277  );
278  }
279  }
280 
281  //smoothField(surfaceCellSize);
282 
283  pointCellSize.write();
284 
285  if (debug)
286  {
287  faceList faces(surface_.size());
288 
289  forAll(surface_, fI)
290  {
291  faces[fI] = surface_.triSurface::operator[](fI);
292  }
293 
294  vtk::surfaceWriter vtkWriter
295  (
296  surface_.points(),
297  faces,
298  (
299  surface_.searchableSurface::time().constant()
300  / "triSurface"
301  / surfaceName_.stem() + "_cellSize"
302  )
303  );
304 
305 
306  vtkWriter.writeGeometry();
307 
308  vtkWriter.beginPointData(1);
309 
310  vtkWriter.write("cellSize", pointCellSize);
311  }
312 
313  return tPointCellSize;
314 }
315 
316 
317 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:493
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
automatic(const dictionary &cellSizeCalcTypeDict, const triSurfaceMesh &surface, const scalar defaultCellSize)
Construct from components.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
DimensionedField< scalar, triSurfacePointGeoMesh > triSurfacePointScalarField
scalar distance(const vector &p1, const vector &p2)
Definition: curveTools.C:12
Ignore writing from objectRegistry::writeObject()
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
List< face > faceList
List of faces.
Definition: faceListFwd.H:39
const labelListList & faceFaces() const
Return face-face addressing.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const Field< point_type > & faceCentres() const
Return face centres for patch.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
const wordList surface
Standard surface field types (scalar, vector, tensor, etc)
const triSurfaceMesh & surface_
Reference to the triSurfaceMesh.
virtual tmp< triSurfacePointScalarField > load()
Load the cell size field.
int debug
Static debugging option.
DimensionedField< scalar, triSurfaceGeoMesh > triSurfaceScalarField
defineTypeNameAndDebug(combustionModel, 0)
vector point
Point is a vector.
Definition: point.H:37
tmp< scalarField > featureProximity(const extendedEdgeMesh &emesh, const triSurface &surf, const scalar searchDistance)
Calculate proximity of the features to the surface.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
Nothing to be read.
messageStream Info
Information stream (stdout output on master, null elsewhere)
List< label > labelList
A List of labels.
Definition: List.H:62
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)