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 | Copyright (C) 2012-2016 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 
26 #include "fvMeshTools.H"
27 #include "volFields.H"
28 #include "surfaceFields.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 template<class GeoField>
33 void Foam::fvMeshTools::addPatchFields
34 (
35  fvMesh& mesh,
36  const dictionary& patchFieldDict,
37  const word& defaultPatchFieldType,
38  const typename GeoField::value_type& defaultPatchValue
39 )
40 {
41  HashTable<GeoField*> flds
42  (
43  mesh.objectRegistry::lookupClass<GeoField>()
44  );
45 
46  forAllIter(typename HashTable<GeoField*>, flds, iter)
47  {
48  GeoField& fld = *iter();
49 
50  typename GeoField::Boundary& bfld =
51  fld.boundaryFieldRef();
52 
53  label sz = bfld.size();
54  bfld.setSize(sz+1);
55 
56  if (patchFieldDict.found(fld.name()))
57  {
58  bfld.set
59  (
60  sz,
62  (
63  mesh.boundary()[sz],
64  fld(),
65  patchFieldDict.subDict(fld.name())
66  )
67  );
68  }
69  else
70  {
71  bfld.set
72  (
73  sz,
75  (
76  defaultPatchFieldType,
77  mesh.boundary()[sz],
78  fld()
79  )
80  );
81  bfld[sz] == defaultPatchValue;
82  }
83  }
84 }
85 
86 
87 template<class GeoField>
88 void Foam::fvMeshTools::setPatchFields
89 (
90  fvMesh& mesh,
91  const label patchi,
92  const dictionary& patchFieldDict
93 )
94 {
95  HashTable<GeoField*> flds
96  (
97  mesh.objectRegistry::lookupClass<GeoField>()
98  );
99 
100  forAllIter(typename HashTable<GeoField*>, flds, iter)
101  {
102  GeoField& fld = *iter();
103 
104  typename GeoField::Boundary& bfld =
105  fld.boundaryFieldRef();
106 
107  if (patchFieldDict.found(fld.name()))
108  {
109  bfld.set
110  (
111  patchi,
113  (
114  mesh.boundary()[patchi],
115  fld(),
116  patchFieldDict.subDict(fld.name())
117  )
118  );
119  }
120  }
121 }
122 
123 
124 
125 
126 template<class GeoField>
127 void Foam::fvMeshTools::setPatchFields
128 (
129  fvMesh& mesh,
130  const label patchi,
131  const typename GeoField::value_type& value
132 )
133 {
134  HashTable<GeoField*> flds
135  (
136  mesh.objectRegistry::lookupClass<GeoField>()
137  );
138 
139  forAllIter(typename HashTable<GeoField*>, flds, iter)
140  {
141  GeoField& fld = *iter();
142 
143  typename GeoField::Boundary& bfld =
144  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  forAllIter(typename HashTable<GeoField*>, 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  forAllIter(typename HashTable<GeoField*>, flds, iter)
182  {
183  GeoField& fld = *iter();
184 
185  typename GeoField::Boundary& bfld =
186  fld.boundaryFieldRef();
187 
188  bfld.reorder(oldToNew);
189  }
190 }
191 
192 
193 // ************************************************************************* //
Foam::surfaceFields.
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
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:453
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
List< label > labelList
A List of labels.
Definition: labelList.H:56
label patchi