Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
35template<class GeoField>
36void 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,
58 GeoField::Patch::New
59 (
60 mesh.boundary()[newPatchi],
61 fld.internalField(),
62 *dict
63 )
64 );
65 }
66 else
67 {
68 bfld.set
69 (
70 newPatchi,
71 GeoField::Patch::New
72 (
73 defaultPatchFieldType,
74 mesh.boundary()[newPatchi],
75 fld.internalField()
76 )
77 );
78 bfld[newPatchi] == defaultPatchValue;
79 }
80 }
81}
82
83
84template<class GeoField>
85void 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,
103 GeoField::Patch::New
104 (
105 mesh.boundary()[patchi],
106 fld.internalField(),
107 *dict
108 )
109 );
110 }
111 }
112}
113
114
115template<class GeoField>
116void 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
133template<class GeoField>
134void 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
146template<class GeoField>
147void 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// ************************************************************************* //
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))
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and it is a dictionary) otherwise return nullptr...
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition fvMesh.H:395
dynamicFvMesh & mesh
List< label > labelList
A List of labels.
Definition List.H:62
label nPatches
dictionary dict
Foam::surfaceFields.