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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2015 OpenFOAM Foundation
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
28// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
29
30template <class Type>
32(
33 const label nIter,
34 const bitSet& isPatchMasterPoint,
35 const bitSet& isPatchMasterEdge,
36 const indirectPrimitivePatch& adaptPatch,
37 const scalarField& fieldMinMag,
39) const
40{
41 const edgeList& edges = adaptPatch.edges();
42 const labelList& meshPoints = adaptPatch.meshPoints();
43
44 scalarField edgeWeights(edges.size());
45 scalarField invSumWeight(meshPoints.size());
47 (
48 mesh_,
49 isPatchMasterEdge,
50 meshPoints,
51 edges,
52 edgeWeights,
53 invSumWeight
54 );
55
56 // Get smoothly varying patch field.
57 Info<< typeName << " : Smoothing field ..." << endl;
58
59 for (label iter = 0; iter < nIter; iter++)
60 {
61 Field<Type> average(adaptPatch.nPoints());
63 (
64 mesh_,
65 isPatchMasterEdge,
66 meshPoints,
67 edges,
68 edgeWeights,
69 field,
71 );
72 average *= invSumWeight;
73
74 // Transfer to field
75 forAll(field, pointI)
76 {
77 //full smoothing neighbours + point value
78 average[pointI] = 0.5*(field[pointI]+average[pointI]);
79
80 // perform monotonic smoothing
81 if
82 (
83 mag(average[pointI]) < mag(field[pointI])
84 && mag(average[pointI]) >= mag(fieldMinMag[pointI])
85 )
86 {
87 field[pointI] = average[pointI];
88 }
89 }
90
91 // Do residual calculation every so often.
92 if ((iter % 10) == 0)
93 {
94 scalar resid = meshRefinement::gAverage
95 (
96 isPatchMasterPoint,
98 );
99 Info<< " Iteration " << iter << " residual " << resid << endl;
100 }
101 }
102}
103
104
105// ************************************************************************* //
A list of faces which address into the list of points.
label nPoints() const
Number of points supporting patch faces.
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
const labelList & meshPoints() const
Return labelList of mesh points in patch.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
void minSmoothField(const label nIter, const bitSet &isPatchMasterPoint, const bitSet &isPatchMasterEdge, const indirectPrimitivePatch &adaptPatch, const scalarField &fieldMin, Field< Type > &field) const
Smooth a scalar field towards, but not beyond, a minimum value.
static void calculateEdgeWeights(const polyMesh &mesh, const bitSet &isMasterEdge, const labelList &meshPoints, const edgeList &edges, scalarField &edgeWeights, scalarField &invSumWeight)
Helper: calculate edge weights (1/length)
static T gAverage(const bitSet &isMasterElem, const UList< T > &values)
Helper: calculate average.
static void weightedSum(const polyMesh &mesh, const bitSet &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.
rDeltaTY field()
messageStream Info
Information stream (stdout output on master, null elsewhere)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333