Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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/>.
26\*---------------------------------------------------------------------------*/
27
28// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29
30template<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
58template<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
129template<class VolField, class TransformOp>
130const 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// ************************************************************************* //
label n
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
static FOAM_NO_DANGLING_REFERENCE const wallDistAddressing & New(const fvMesh &mesh, Args &&... args)
A non-owning sub-view of a List (allocated or unallocated storage).
Definition SubList.H:61
A class for managing temporary objects.
Definition tmp.H:75
labelList untransformedPatchStarts_
Start of patches. Start of untransformedPatchStarts_[0] is end.
void extract(const Field< typename VolField::value_type > &patchFld, VolField &fld) const
Take collected/distributed patch field and fill volField.
const VolField & map(VolField &fld, const TransformOp &top=mapDistribute::transform()) const
Map nearest-patch information. Take wall patch values.
labelList untransformedSlots_
Corresponding slot in mapPtr distribution result.
autoPtr< mapDistribute > mapPtr_
Map to pull wall face info to cell or boundary face.
labelList untransformedItems_
Indices of cells followed by boundary faces.
tmp< Field< Type > > collectPatchFields(const Container &bfld) const
Collect patchFields from patchIDs into straight list.
const labelList patchIDs_
Set of patch IDs.
const char * end
Definition SVGTools.H:223
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:299