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-2023 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  for (GeoField& fld : mesh.objectRegistry::sorted<GeoField>())
45  {
46  auto& bfld = fld.boundaryFieldRef();
47 
48  const label newPatchi = bfld.size();
49  bfld.resize(newPatchi+1);
50 
51  const dictionary* dict = patchFieldDict.findDict(fld.name());
52 
53  if (dict)
54  {
55  bfld.set
56  (
57  newPatchi,
59  (
60  mesh.boundary()[newPatchi],
61  fld.internalField(),
62  *dict
63  )
64  );
65  }
66  else
67  {
68  bfld.set
69  (
70  newPatchi,
72  (
73  defaultPatchFieldType,
74  mesh.boundary()[newPatchi],
75  fld.internalField()
76  )
77  );
78  bfld[newPatchi] == defaultPatchValue;
79  }
80  }
81 }
82 
83 
84 template<class GeoField>
85 void Foam::fvMeshTools::setPatchFields
86 (
87  fvMesh& mesh,
88  const label patchi,
89  const dictionary& patchFieldDict
90 )
91 {
92  for (GeoField& fld : mesh.objectRegistry::sorted<GeoField>())
93  {
94  auto& bfld = fld.boundaryFieldRef();
95 
96  const dictionary* dict = patchFieldDict.findDict(fld.name());
97 
98  if (dict)
99  {
100  bfld.set
101  (
102  patchi,
104  (
105  mesh.boundary()[patchi],
106  fld.internalField(),
107  *dict
108  )
109  );
110  }
111  }
112 }
113 
114 
115 template<class GeoField>
116 void Foam::fvMeshTools::setPatchFields
117 (
118  fvMesh& mesh,
119  const label patchi,
120  const typename GeoField::value_type& value
121 )
122 {
123  for (GeoField& fld : mesh.objectRegistry::sorted<GeoField>())
124  {
125  auto& bfld = fld.boundaryFieldRef();
126 
127  bfld[patchi] == value;
128  }
129 }
130 
131 
132 // Remove last patch field
133 template<class GeoField>
134 void Foam::fvMeshTools::trimPatchFields(fvMesh& mesh, const label nPatches)
135 {
136  for (GeoField& fld : mesh.objectRegistry::sorted<GeoField>())
137  {
138  auto& bfld = fld.boundaryFieldRef();
139 
140  bfld.resize(nPatches);
141  }
142 }
143 
144 
145 // Reorder patch field
146 template<class GeoField>
147 void Foam::fvMeshTools::reorderPatchFields
148 (
149  fvMesh& mesh,
150  const labelList& oldToNew
151 )
152 {
153  for (GeoField& fld : mesh.objectRegistry::sorted<GeoField>())
154  {
155  auto& bfld = fld.boundaryFieldRef();
156 
157  bfld.reorder(oldToNew);
158  }
159 }
160 
161 
162 // ************************************************************************* //
label nPatches
Definition: readKivaGrid.H:396
Foam::surfaceFields.
dictionary dict
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
dynamicFvMesh & mesh
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))
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition: fvMesh.H:395
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:765
List< label > labelList
A List of labels.
Definition: List.H:62
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and a sub-dictionary) otherwise return nullptr...
Definition: dictionaryI.H:124