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 public:
71 
72  //- Runtime type information
73  TypeName("leastSquares");
74 
75 
76  // Generated Methods
77 
78  //- No copy construct
80  = delete;
81 
82  //- No copy assignment
83  void operator=(const leastSquaresEdgeInterpolation&) = delete;
84 
85 
86  // Constructors
87 
88  //- Construct from mesh
90  :
92  {}
93 
94  //- Construct from Istream
96  :
98  {}
99 
100  //- Construct from faceFlux and Istream
102  (
103  const faMesh& mesh,
104  const edgeScalarField&,
105  Istream&
106  )
107  :
109  {}
110 
111 
112  // Member Functions
113 
114  //- Return the edge-interpolate of the given face field
117  (
119  ) const;
120 
121  //- Return the interpolation weighting factors
123  (
125  ) const
126  {
127  return this->mesh().edgeInterpolation::weights();
128  }
129 };
130 
131 
132 template<class Type>
133 tmp<GeometricField<Type, faePatchField, edgeMesh>>
135 (
137 ) const
138 {
139  typedef typename outerProduct<vector, Type>::type GradType;
141  typedef GeometricField<Type, faePatchField, edgeMesh> EdgeFieldType;
142  typedef Field<Type> FieldType;
143 
144  const faMesh& mesh = af.mesh();
145 
146  const labelList& meshPts = mesh.patch().meshPoints();
147  const labelListList& pointFaceAddr = mesh.patch().pointFaces();
148  const areaVectorField& C = mesh.areaCentres();
149 
151  const GradFieldType& gradAf = tgradAf.cref();
152 
153  // Field at surface points, Pi (P:p. 29-30)
154  auto tPi = tmp<FieldType>::New(meshPts.size(), Zero);
155  FieldType& Pi = tPi.ref();
156 
157  forAll(meshPts, i)
158  {
159  const label nFaces = pointFaceAddr[i].size();
160 
161  FieldType Pij(nFaces);
162  vectorField dPC(nFaces);
163 
164  for (label facei = 0; facei < nFaces; ++facei)
165  {
166  const label j = pointFaceAddr[i][facei];
167 
168  // Euclidean distance between a point and face centres (P:Fig. 3.3)
169  dPC[facei] = mesh.points()[i] - C[j];
170 
171  // (P:Eq. 3.14)
172  Pij[facei] = af[j] + (dPC[facei] & gradAf[j]);
173  }
174 
175  const scalarField magdPC(max(mag(dPC), SMALL));
176 
177  // (P:Eq. 3.15)
178  Pi[i] = sum(Pij/magdPC)/sum(scalar(1)/magdPC);
179  }
180 
181  tgradAf.clear();
182 
183 
184  auto tinterp = tmp<EdgeFieldType>::New
185  (
186  IOobject
187  (
188  "interpolate(" + af.name() + ')',
189  af.instance(),
190  af.db()
191  ),
192  af.mesh(),
193  af.dimensions()
194  );
195  EdgeFieldType& interp = tinterp.ref();
196  FieldType& interpEdges = interp.primitiveFieldRef();
197 
198 
199  const edgeList& faEdges = mesh.edges();
200  const label nInternalEdges = mesh.nInternalEdges();
201 
202  // Internal field
203  for (label edgei = 0; edgei < nInternalEdges; ++edgei)
204  {
205  // (P:Eq. 3.16)
206  interpEdges[edgei] =
207  0.5*
208  (
209  Pi[faEdges[edgei].start()]
210  + Pi[faEdges[edgei].end()]
211  );
212  }
213 
214  // Boundary field from boundary condition [fixedValue]
215  // Coupled boundary fields are not handled
216  forAll(interp.boundaryField(), patchi)
217  {
218  interp.boundaryFieldRef()[patchi] = af.boundaryField()[patchi];
219  }
220 
221  return tinterp;
222 }
223 
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 } // End namespace Foam
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 #endif
232 
233 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:133
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.
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.
leastSquaresEdgeInterpolation(const leastSquaresEdgeInterpolation &)=delete
No copy construct.
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
void operator=(const leastSquaresEdgeInterpolation &)=delete
No copy assignment.