deltaBoundaryTemplates.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) 2007-2019 PCOpt/NTUA
9  Copyright (C) 2013-2019 FOSS GP
10  Copyright (C) 2019 OpenCFD Ltd.
11 -------------------------------------------------------------------------------
12 License
13  This file is part of OpenFOAM.
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "deltaBoundary.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
38 
39 template<class pT>
41 (
42  const vectorField& fAreas,
43  const vectorField& fCtrs,
44  const Field<pT>& fAreas_d,
45  const Field<pT>& fCtrs_d
46 )
47 {
48  // Define type that in an order smaller than pT. Used for volume-related
49  // variations
50  typedef typename innerProduct<vector, pT>::type vT;
51 
52  // First estimate the approximate cell centre as the average of
53  // face centres
54  vector cEst(Zero);
55  vector cellCtrs(Zero);
56  scalar cellVols(Zero);
57  pT cEst_d(pTraits<pT>::zero);
58  pT cellCtrs_d(pTraits<pT>::zero);
59  vT cellVols_d(pTraits<vT>::zero);
60 
61  forAll(fAreas, facei)
62  {
63  cEst += fCtrs[facei];
64  cEst_d += fCtrs_d[facei];
65  }
66 
67  cEst /= fAreas.size();
68  cEst_d /= fAreas.size();
69 
70  forAll(fAreas, facei)
71  {
72  // Calculate 3*face-pyramid volume
73  scalar pyr3Vol =
74  mag(fAreas[facei] & (fCtrs[facei] - cEst));
75 
76  vT pyr3Vol_d =
77  (fAreas[facei] & (fCtrs[facei] - cEst))
78  *(
79  ((fCtrs[facei] - cEst) & fAreas_d[facei])
80  // Reverse order to get the correct inner product
81  + (fAreas[facei] & (fCtrs_d[facei] - cEst_d))
82  )/pyr3Vol;
83 
84  // Calculate face-pyramid centre
85  vector pc = (3.0/4.0)*fCtrs[facei] + (1.0/4.0)*cEst;
86  pT pc_d = (3.0/4.0)*fCtrs_d[facei] + (1.0/4.0)*cEst_d;
87 
88  // Accumulate volume-weighted face-pyramid centre
89  cellCtrs += pyr3Vol*pc;
90 
91  // Reverse order to get the correct outer product
92  cellCtrs_d += (pc*pyr3Vol_d + pyr3Vol*pc_d);
93 
94  // Accumulate face-pyramid volume
95  cellVols += pyr3Vol;
96  cellVols_d += pyr3Vol_d;
97  }
98 
99  cellCtrs /= cellVols;
100  cellCtrs_d = cellCtrs_d/cellVols - cellCtrs*cellVols_d/cellVols;
101  cellVols *= (1.0/3.0);
102  cellVols_d *= (1.0/3.0);
103 
104  return cellCtrs_d;
105 }
106 
107 
108 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
109 
110 } // End namespace Foam
111 
112 // ************************************************************************* //
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Field< vector >
Foam::deltaBoundary::makeCellCentres_d
pT makeCellCentres_d(const vectorField &fAreas, const vectorField &fCtrs, const Field< pT > &fAreas_d, const Field< pT > &fCtrs_d)
Definition: deltaBoundaryTemplates.C:41
cellVols
const scalarField & cellVols
Definition: temperatureAndPressureVariables.H:51
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
deltaBoundary.H
Foam::Vector< scalar >
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::innerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) - 2 >::type type
Definition: products.H:149