fvMeshToolsTemplates.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) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "fvMeshTools.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 template<class GeoField>
36 void Foam::fvMeshTools::addPatchFields
37 (
38  fvMesh& mesh,
39  const dictionary& patchFieldDict,
40  const word& defaultPatchFieldType,
41  const typename GeoField::value_type& defaultPatchValue
42 )
43 {
44  HashTable<GeoField*> flds
45  (
46  mesh.objectRegistry::lookupClass<GeoField>()
47  );
48 
49  forAllIters(flds, iter)
50  {
51  GeoField& fld = *iter();
52 
53  auto& bfld = fld.boundaryFieldRef();
54 
55  label sz = bfld.size();
56  bfld.setSize(sz+1);
57 
58  if (patchFieldDict.found(fld.name()))
59  {
60  bfld.set
61  (
62  sz,
64  (
65  mesh.boundary()[sz],
66  fld(),
67  patchFieldDict.subDict(fld.name())
68  )
69  );
70  }
71  else
72  {
73  bfld.set
74  (
75  sz,
77  (
78  defaultPatchFieldType,
79  mesh.boundary()[sz],
80  fld()
81  )
82  );
83  bfld[sz] == defaultPatchValue;
84  }
85  }
86 }
87 
88 
89 template<class GeoField>
90 void Foam::fvMeshTools::setPatchFields
91 (
92  fvMesh& mesh,
93  const label patchi,
94  const dictionary& patchFieldDict
95 )
96 {
97  HashTable<GeoField*> flds
98  (
99  mesh.objectRegistry::lookupClass<GeoField>()
100  );
101 
102  forAllIters(flds, iter)
103  {
104  GeoField& fld = *iter();
105 
106  auto& bfld = fld.boundaryFieldRef();
107 
108  if (patchFieldDict.found(fld.name()))
109  {
110  bfld.set
111  (
112  patchi,
114  (
115  mesh.boundary()[patchi],
116  fld(),
117  patchFieldDict.subDict(fld.name())
118  )
119  );
120  }
121  }
122 }
123 
124 
125 
126 
127 template<class GeoField>
128 void Foam::fvMeshTools::setPatchFields
129 (
130  fvMesh& mesh,
131  const label patchi,
132  const typename GeoField::value_type& value
133 )
134 {
135  HashTable<GeoField*> flds
136  (
137  mesh.objectRegistry::lookupClass<GeoField>()
138  );
139 
140  forAllIters(flds, iter)
141  {
142  GeoField& fld = *iter();
143 
144  auto& bfld = fld.boundaryFieldRef();
145 
146  bfld[patchi] == value;
147  }
148 }
149 
150 
151 // Remove last patch field
152 template<class GeoField>
153 void Foam::fvMeshTools::trimPatchFields(fvMesh& mesh, const label nPatches)
154 {
155  HashTable<GeoField*> flds
156  (
157  mesh.objectRegistry::lookupClass<GeoField>()
158  );
159 
160  forAllIters(flds, iter)
161  {
162  GeoField& fld = *iter();
163  fld.boundaryFieldRef().setSize(nPatches);
164  }
165 }
166 
167 
168 // Reorder patch field
169 template<class GeoField>
170 void Foam::fvMeshTools::reorderPatchFields
171 (
172  fvMesh& mesh,
173  const labelList& oldToNew
174 )
175 {
176  HashTable<GeoField*> flds
177  (
178  mesh.objectRegistry::lookupClass<GeoField>()
179  );
180 
181  forAllIters(flds, iter)
182  {
183  GeoField& fld = *iter();
184 
185  auto& bfld = fld.boundaryFieldRef();
186 
187  bfld.reorder(oldToNew);
188  }
189 }
190 
191 
192 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
volFields.H
surfaceFields.H
Foam::surfaceFields.
nPatches
const label nPatches
Definition: printMeshSummary.H:30
fld
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))
Definition: gmvOutputLagrangian.H:23
forAllIters
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:223
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::fvMesh::boundary
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:685
fvMeshTools.H