fieldSmootherTemplates.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) 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 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
27 
28 template <class Type>
30 (
31  const label nIter,
32  const PackedBoolList& isPatchMasterPoint,
33  const PackedBoolList& isPatchMasterEdge,
34  const indirectPrimitivePatch& adaptPatch,
35  const scalarField& fieldMinMag,
36  Field<Type>& field
37 ) const
38 {
39  const edgeList& edges = adaptPatch.edges();
40  const labelList& meshPoints = adaptPatch.meshPoints();
41 
42  scalarField edgeWeights(edges.size());
43  scalarField invSumWeight(meshPoints.size());
44  meshRefinement::calculateEdgeWeights
45  (
46  mesh_,
47  isPatchMasterEdge,
48  meshPoints,
49  edges,
50  edgeWeights,
51  invSumWeight
52  );
53 
54  // Get smoothly varying patch field.
55  Info<< typeName << " : Smoothing field ..." << endl;
56 
57  for (label iter = 0; iter < nIter; iter++)
58  {
59  Field<Type> average(adaptPatch.nPoints());
60  meshRefinement::weightedSum
61  (
62  mesh_,
63  isPatchMasterEdge,
64  meshPoints,
65  edges,
66  edgeWeights,
67  field,
68  average
69  );
70  average *= invSumWeight;
71 
72  // Transfer to field
73  forAll(field, pointI)
74  {
75  //full smoothing neighbours + point value
76  average[pointI] = 0.5*(field[pointI]+average[pointI]);
77 
78  // perform monotonic smoothing
79  if
80  (
81  mag(average[pointI]) < mag(field[pointI])
82  && mag(average[pointI]) >= mag(fieldMinMag[pointI])
83  )
84  {
85  field[pointI] = average[pointI];
86  }
87  }
88 
89  // Do residual calculation every so often.
90  if ((iter % 10) == 0)
91  {
92  scalar resid = meshRefinement::gAverage
93  (
94  isPatchMasterPoint,
95  mag(field-average)()
96  );
97  Info<< " Iteration " << iter << " residual " << resid << endl;
98  }
99  }
100 }
101 
102 
103 // ************************************************************************* //
Foam::PackedBoolList
A bit-packed bool list.
Definition: PackedBoolList.H:63
Foam::PrimitivePatch::edges
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
Definition: PrimitivePatchTemplate.C:212
Foam::fieldSmoother::minSmoothField
void minSmoothField(const label nIter, const PackedBoolList &isPatchMasterPoint, const PackedBoolList &isPatchMasterEdge, const indirectPrimitivePatch &adaptPatch, const scalarField &fieldMin, Field< Type > &field) const
Smooth a scalar field towards, but not beyond, a minimum value.
Definition: fieldSmootherTemplates.C:30
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::gAverage
Type gAverage(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:571
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::fvc::average
tmp< GeometricField< Type, fvPatchField, volMesh > > average(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Area-weighted average a surfaceField creating a volField.
Definition: fvcAverage.C:46
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::PrimitivePatch::nPoints
label nPoints() const
Return number of points supporting patch faces.
Definition: PrimitivePatchTemplate.H:293
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::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::PrimitivePatch::meshPoints
const labelList & meshPoints() const
Return labelList of mesh points in patch.
Definition: PrimitivePatchTemplate.C:392
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88