leastSquaresEdgeInterpolation.H
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) 2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 Class
27  Foam::leastSquaresEdgeInterpolation
28 
29 Description
30  Least-squares edge interpolation scheme class, from
31  face centers to points then from points to edges.
32 
33  References:
34  \verbatim
35  Governing equations (tag:P):
36  Pesci, C. (2019).
37  Computational analysis of fluid interfaces
38  influenced by soluble surfactant.
39  Darmstadt, Technische Universität. PhD thesis.
40  URI:https://tuprints.ulb.tu-darmstadt.de/id/eprint/9303
41  \endverbatim
42 
43 SourceFiles
44  leastSquaresEdgeInterpolationMake.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef Foam_leastSquaresEdgeInterpolation_H
49 #define Foam_leastSquaresEdgeInterpolation_H
50 
52 #include "areaFields.H"
53 #include "edgeFields.H"
54 #include "leastSquaresFaGrad.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 /*---------------------------------------------------------------------------*\
62  Class leastSquaresEdgeInterpolation Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 template<class Type>
67 :
68  virtual public edgeInterpolationScheme<Type>
69 {
70  // Private Member Functions
71 
72  //- No copy assignment
73  void operator=(const leastSquaresEdgeInterpolation&) = delete;
74 
75 
76 public:
77 
78  //- Runtime type information
79  TypeName("leastSquares");
80 
81 
82  // Constructors
83 
84  //- Construct from mesh
86  :
88  {}
89 
90  //- Construct from Istream
92  :
94  {}
95 
96  //- Construct from faceFlux and Istream
98  (
99  const faMesh& mesh,
100  const edgeScalarField&,
101  Istream&
102  )
103  :
105  {}
106 
107 
108  // Member Functions
109 
110  //- Return the edge-interpolate of the given face field
113  (
115  ) const;
116 
117  //- Return the interpolation weighting factors
119  (
121  ) const
122  {
123  return this->mesh().edgeInterpolation::weights();
124  }
125 };
126 
127 
128 template<class Type>
131 (
133 ) const
134 {
135  typedef typename outerProduct<vector, Type>::type GradType;
137  typedef GeometricField<Type, faePatchField, edgeMesh> EdgeFieldType;
138  typedef Field<Type> FieldType;
139 
140  const faMesh& mesh = af.mesh();
141 
142  const labelList& meshPts = mesh.patch().meshPoints();
143  const labelListList& pointFaceAddr = mesh.patch().pointFaces();
144  const areaVectorField& C = mesh.areaCentres();
145 
147  const GradFieldType& gradAf = tgradAf.cref();
148 
149  // Field at surface points, Pi (P:p. 29-30)
150  auto tPi = tmp<FieldType>::New(meshPts.size(), Zero);
151  FieldType& Pi = tPi.ref();
152 
153  forAll(meshPts, i)
154  {
155  const label nFaces = pointFaceAddr[i].size();
156 
157  FieldType Pij(nFaces);
158  vectorField dPC(nFaces);
159 
160  for (label facei = 0; facei < nFaces; ++facei)
161  {
162  const label j = pointFaceAddr[i][facei];
163 
164  // Euclidean distance between a point and face centres (P:Fig. 3.3)
165  dPC[facei] = mesh.points()[i] - C[j];
166 
167  // (P:Eq. 3.14)
168  Pij[facei] = af[j] + (dPC[facei] & gradAf[j]);
169  }
170 
171  const scalarField magdPC(max(mag(dPC), SMALL));
172 
173  // (P:Eq. 3.15)
174  Pi[i] = sum(Pij/magdPC)/sum(scalar(1)/magdPC);
175  }
176 
177  tgradAf.clear();
178 
179 
180  auto tinterp = tmp<EdgeFieldType>::New
181  (
182  IOobject
183  (
184  "interpolate(" + af.name() + ')',
185  af.instance(),
186  af.db()
187  ),
188  af.mesh(),
189  af.dimensions()
190  );
191  EdgeFieldType& interp = tinterp.ref();
192  FieldType& interpEdges = interp.primitiveFieldRef();
193 
194 
195  const edgeList& faEdges = mesh.edges();
196  const label nInternalEdges = mesh.nInternalEdges();
197 
198  // Internal field
199  for (label edgei = 0; edgei < nInternalEdges; ++edgei)
200  {
201  // (P:Eq. 3.16)
202  interpEdges[edgei] =
203  0.5*
204  (
205  Pi[faEdges[edgei].start()]
206  + Pi[faEdges[edgei].end()]
207  );
208  }
209 
210  // Boundary field from boundary condition [fixedValue]
211  // Coupled boundary fields are not handled
212  forAll(interp.boundaryField(), patchi)
213  {
214  interp.boundaryFieldRef()[patchi] = af.boundaryField()[patchi];
215  }
216 
217  return tinterp;
218 }
219 
220 
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 
223 } // End namespace Foam
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 #endif
228 
229 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:87
Graphite solid properties.
Definition: C.H:46
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
TypeName("leastSquares")
Runtime type information.
List< edge > edgeList
List of edge.
Definition: edgeList.H:32
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Abstract base class for edge interpolation schemes.
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
Definition: tmpI.H:221
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
tmp< GeometricField< Type, faePatchField, edgeMesh > > interpolate(const GeometricField< Type, faPatchField, areaMesh > &) const
Return the edge-interpolate of the given face field.
leastSquaresEdgeInterpolation(const faMesh &mesh)
Construct from mesh.
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1078
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
dynamicFvMesh & mesh
Generic templated field type.
Definition: Field.H:62
const objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition: IOobject.C:450
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
Second-order gradient scheme using least-squares.
label nInternalEdges() const
Internal edges using 0,1 or 2 boundary points.
Least-squares edge interpolation scheme class, from face centers to points then from points to edges...
const Mesh & mesh() const noexcept
Return mesh.
tmp< edgeScalarField > weights(const GeometricField< Type, faPatchField, areaMesh > &) const
Return the interpolation weighting factors.
const fileName & instance() const noexcept
Read access to instance path component.
Definition: IOobjectI.H:266
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
const faMesh & mesh() const
Return mesh reference.
const labelListList & pointFaces() const
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
Definition: tmpI.H:289
A class for managing temporary objects.
Definition: HashPtrTable.H:50
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
Namespace for OpenFOAM.
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh >> grad(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facGrad.C:51
const dimensionSet & dimensions() const noexcept
Return dimensions.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127