extendedCellToFaceStencilTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 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 
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const distributionMap& map,
34  const labelListList& stencil,
35  const VolField<Type>& fld,
36  List<List<Type>>& stencilFld
37 )
38 {
39  // 1. Construct cell data in compact addressing
40  List<Type> flatFld(map.constructSize(), Zero);
41 
42  // Insert my internal values
43  forAll(fld, celli)
44  {
45  flatFld[celli] = fld[celli];
46  }
47  // Insert my boundary values
48  forAll(fld.boundaryField(), patchi)
49  {
50  const fvPatchField<Type>& pfld = fld.boundaryField()[patchi];
51 
52  label nCompact =
53  pfld.patch().start()
54  -fld.mesh().nInternalFaces()
55  +fld.mesh().nCells();
56 
57  forAll(pfld, i)
58  {
59  flatFld[nCompact++] = pfld[i];
60  }
61  }
62 
63  // Do all swapping
64  map.distribute(flatFld);
65 
66  // 2. Pull to stencil
67  stencilFld.setSize(stencil.size());
68 
69  forAll(stencil, facei)
70  {
71  const labelList& compactCells = stencil[facei];
72 
73  stencilFld[facei].setSize(compactCells.size());
74 
75  forAll(compactCells, i)
76  {
77  stencilFld[facei][i] = flatFld[compactCells[i]];
78  }
79  }
80 }
81 
82 
83 template<class Type>
86 (
87  const distributionMap& map,
88  const labelListList& stencil,
89  const VolField<Type>& fld,
90  const List<List<scalar>>& stencilWeights
91 )
92 {
93  const fvMesh& mesh = fld.mesh();
94 
95  // Collect internal and boundary values
96  List<List<Type>> stencilFld;
97  collectData(map, stencil, fld, stencilFld);
98 
99  tmp<SurfaceField<Type>> tsfCorr
100  (
102  (
103  fld.name(),
104  mesh,
106  (
107  fld.name(),
108  fld.dimensions(),
109  Zero
110  )
111  )
112  );
113  SurfaceField<Type>& sf = tsfCorr.ref();
114 
115  // Internal faces
116  for (label facei = 0; facei < mesh.nInternalFaces(); facei++)
117  {
118  const List<Type>& stField = stencilFld[facei];
119  const List<scalar>& stWeight = stencilWeights[facei];
120 
121  forAll(stField, i)
122  {
123  sf[facei] += stField[i]*stWeight[i];
124  }
125  }
126 
127  // Boundaries. Either constrained or calculated so assign value
128  // directly (instead of nicely using operator==)
129  typename SurfaceField<Type>::
130  Boundary& bSfCorr = sf.boundaryFieldRef();
131 
132  forAll(bSfCorr, patchi)
133  {
134  fvsPatchField<Type>& pSfCorr = bSfCorr[patchi];
135 
136  if (pSfCorr.coupled())
137  {
138  label facei = pSfCorr.patch().start();
139 
140  forAll(pSfCorr, i)
141  {
142  const List<Type>& stField = stencilFld[facei];
143  const List<scalar>& stWeight = stencilWeights[facei];
144 
145  forAll(stField, j)
146  {
147  pSfCorr[i] += stField[j]*stWeight[j];
148  }
149 
150  facei++;
151  }
152  }
153  }
154 
155  return tsfCorr;
156 }
157 
158 
159 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Generic GeometricField class.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void setSize(const label)
Reset size of List.
Definition: List.C:281
Generic dimensioned Type class.
label constructSize() const
Constructed data size.
Class containing processor-to-processor mapping information.
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
static void collectData(const distributionMap &map, const labelListList &stencil, const VolField< Type > &fld, List< List< Type >> &stencilFld)
Use map to get the data into stencil order.
static tmp< SurfaceField< Type > > weightedSum(const distributionMap &map, const labelListList &stencil, const VolField< Type > &fld, const List< List< scalar >> &stencilWeights)
Sum vol field contributions to create face values.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:88
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:356
virtual label start() const
Return start label of this patch in the polyMesh face list.
Definition: fvPatch.H:132
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:83
virtual bool coupled() const
Return true if this patch field is coupled.
const fvPatch & patch() const
Return patch.
label nInternalFaces() const
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
label patchi
volScalarField sf(fieldObject, mesh)
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
static const zero Zero
Definition: zero.H:97
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