wallDistAddressingTemplates.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) 2023 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 \*---------------------------------------------------------------------------*/
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 template<class Container, class Type>
33 (
34  const Container& bfld
35 ) const
36 {
37  label n = 0;
38  for (const auto& patchi : patchIDs_)
39  {
40  n += bfld[patchi].size();
41  }
42 
43  auto tresult(tmp<Field<Type>>::New(n));
44  auto& result = tresult.ref();
45 
46  n = 0;
47  for (const auto& patchi : patchIDs_)
48  {
49  const auto& pfld = bfld[patchi];
50 
51  SubList<Type>(result, pfld.size(), n) = pfld;
52  n += pfld.size();
53  }
54  return tresult;
55 }
56 
57 
58 template<class VolField>
60 (
61  const Field<typename VolField::value_type>& wallFld,
62  VolField& fld
63 ) const
64 {
65  {
66  const label nUntrafoCells =
67  (
68  untransformedPatchStarts_.size()
69  ? untransformedPatchStarts_[0]
70  : untransformedItems_.size()
71  );
72  for (label i = 0; i < nUntrafoCells; i++)
73  {
74  const label celli = untransformedItems_[i];
75  const label sloti = untransformedSlots_[i];
76  fld[celli] = wallFld[sloti];
77  }
78  }
79  {
80  const label nTrafoCells =
81  (
82  transformedPatchStarts_.size()
83  ? transformedPatchStarts_[0]
84  : transformedItems_.size()
85  );
86  for (label i = 0; i < nTrafoCells; i++)
87  {
88  const label celli = transformedItems_[i];
89  const label sloti = transformedSlots_[i];
90  fld[celli] = wallFld[sloti];
91  }
92  }
93 
94  forAll(fld.boundaryField(), patchi)
95  {
96  const auto& pfld = fld.boundaryField()[patchi];
97  Field<typename VolField::value_type> patchField(pfld.size());
98 
99  {
100  const label start = untransformedPatchStarts_[patchi];
101  const label end = untransformedPatchStarts_[patchi+1];
102 
103  for (label i = start; i < end; i++)
104  {
105  const label facei = untransformedItems_[i];
106  const label sloti = untransformedSlots_[i];
107  patchField[facei-pfld.patch().start()] = wallFld[sloti];
108  }
109  }
110 
111  {
112  const label start = transformedPatchStarts_[patchi];
113  const label end = transformedPatchStarts_[patchi+1];
114 
115  for (label i = start; i < end; i++)
116  {
117  const label facei = transformedItems_[i];
118  const label sloti = transformedSlots_[i];
119  patchField[facei-pfld.patch().start()] = wallFld[sloti];
120  }
121  }
122 
123  fld.boundaryFieldRef()[patchi] = patchField;
124  }
125  fld.correctBoundaryConditions();
126 }
127 
128 
129 template<class VolField, class TransformOp>
130 const VolField& Foam::wallDistAddressing::map
131 (
132  VolField& fld,
133  const TransformOp& top
134 ) const
135 {
136  const auto patchFld
137  (
138  collectPatchFields
139  <
140  typename VolField::Boundary,
141  typename VolField::value_type
142  >
143  (
144  fld.boundaryField()
145  )
146  );
147 
148  // Distribute and transform
149  mapPtr_().distribute
150  (
151  mesh_.globalData().globalTransforms(),
152  patchFld.ref(),
153  top
154  );
155 
156  // Extract into volField
157  extract(patchFld(), fld);
158 
159  return fld;
160 }
161 
162 
163 // ************************************************************************* //
const labelList patchIDs_
Set of patch IDs.
static const wallDistAddressing & New(const fvMesh &mesh, Args &&... args)
Get existing or create a new MeshObject. Registered with typeName.
Definition: MeshObject.C:53
static List< T > extract(const word &key, const UPtrList< entry > &entries, const T &initValue)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
void extract(const Field< typename VolField::value_type > &patchFld, VolField &fld) const
Take collected/distributed patch field and fill volField.
tmp< Field< Type > > collectPatchFields(const Container &bfld) const
Collect patchFields from patchIDs into straight list.
Generic templated field type.
Definition: Field.H:62
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:201
const VolField & map(VolField &fld, const TransformOp &top=mapDistribute::transform()) const
Map nearest-patch information. Take wall patch values.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
label n
A class for managing temporary objects.
Definition: HashPtrTable.H:50