lagrangianReconstructor.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) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2018-2022 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
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
35
36
37// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38
40(
41 const fvMesh& mesh,
42 const PtrList<fvMesh>& procMeshes,
43 const PtrList<labelIOList>& faceProcAddressing,
44 const PtrList<labelIOList>& cellProcAddressing
45)
46:
47 mesh_(mesh),
48 procMeshes_(procMeshes),
49 faceProcAddressing_(faceProcAddressing),
50 cellProcAddressing_(cellProcAddressing)
51{}
52
53
54// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55
57(
58 const word& cloudName
59) const
60{
61 passivePositionParticleCloud lagrangianPositions
62 (
63 mesh_,
66 );
67
68 forAll(procMeshes_, meshi)
69 {
70 const labelList& cellMap = cellProcAddressing_[meshi];
71 const labelList& faceMap = faceProcAddressing_[meshi];
72
73 // Use a special particle that does not try to find the particle on
74 // the mesh. This is to be able to handle particles originating
75 // from a different processor. This can happen with some
76 // functionObjects - e.g. extractEulerianParticles.
77 // These particles should be
78 // - written in the old format
79 passivePositionParticleCloud lpi(procMeshes_[meshi], cloudName, false);
80
81 forAllConstIters(lpi, iter)
82 {
83 const passivePositionParticle& ppi = *iter;
84
85 const label mappedCell =
86 (
87 (ppi.cell() >= 0)
88 ? cellMap[ppi.cell()]
89 : -1
90 );
91
92 // Inverting sign if necessary and subtracting 1 from
93 // faceProcAddressing
94 const label mappedTetFace =
95 (
96 (ppi.tetFace() >= 0)
97 ? mag(faceMap[ppi.tetFace()]) - 1
98 : -1
99 );
100
101 if ((ppi.cell() >= 0) && (ppi.tetFace() >= 0))
102 {
103 // cell,face succesfully mapped. Coordinates inside the cell
104 // should be same
105 lagrangianPositions.append
106 (
108 (
109 mesh_,
110 ppi.coordinates(),
111 mappedCell,
112 mappedTetFace,
113 ppi.procTetPt(mesh_, mappedCell, mappedTetFace)
114 )
115 );
116 }
117 else
118 {
119 // No valid coordinates. Two choices:
120 // - assume reconstructed mesh contains the position so do
121 // a locate with the (reconstructed) mesh
122 // - preserve -1 as cell id, maintain the read location
123 lagrangianPositions.append
124 (
125
126 //- Option 1: locate on reconstructed mesh
127 //new passivePositionParticle
128 //(
129 // mesh_,
130 // ppi.location(),
131 // mappedCell
132 //)
133
134 //- Option 2: maintain read location
136 (
137 mesh_,
138 Zero, // position
139 -1, // celli
140 -1, // tetFacei
141 -1, // tetPti
142 ppi.location()
143 )
144 );
145 }
146 }
147 }
148
149
150 IOPosition<passivePositionParticleCloud>(lagrangianPositions).write();
151
152 // Force writing of "positions" too, if specified via the InfoSwitch
154 {
156 (
157 lagrangianPositions,
159 ).write();
160 }
161
162 return lagrangianPositions.size();
163}
164
165
167(
168 const word& cloudName,
169 const IOobjectList& cloudObjs,
170 const wordRes& selectedFields
171)
172{
173 do
174 {
175 #undef doLocalCode
176 #define doLocalCode(Type) \
177 { \
178 this->reconstructFields<Type> \
179 ( \
180 cloudName, \
181 cloudObjs, \
182 selectedFields \
183 ); \
184 \
185 this->reconstructFieldFields<Type> \
186 ( \
187 cloudName, \
188 cloudObjs, \
189 selectedFields \
190 ); \
191 }
192
193 doLocalCode(label);
194 doLocalCode(scalar);
199
200 #undef doLocalCode
201 }
202 while (false);
203}
204
205
206// ************************************************************************* //
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
Template class for intrusive linked lists.
Definition: ILList.H:69
Helper IO class to read and write particle coordinates (positions).
Definition: IOPosition.H:56
virtual bool write(const bool valid=true) const
Write using setting from DB.
Definition: IOPosition.C:57
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Reconstructor for lagrangian positions and fields.
void reconstructAllFields(const word &cloudName, const IOobjectList &cloudObjs, const wordRes &selectedFields=wordRes())
Reconstruct all fields for known cloud field types.
label reconstructPositions(const word &cloudName) const
Reconstruct positions for given cloud.
static int verbose_
Output verbosity when writing.
label procTetPt(const polyMesh &procMesh, const label procCell, const label procTetFace) const
Return the tet point appropriate for decomposition or reconstruction.
Definition: particle.C:1200
label tetFace() const noexcept
Return current tet face particle is in.
Definition: particleI.H:161
const barycentric & coordinates() const noexcept
Return current particle coordinates.
Definition: particleI.H:143
static bool writeLagrangianPositions
Definition: particle.H:383
label cell() const noexcept
Return current cell particle is in.
Definition: particleI.H:149
Copy of base particle but without particle locating and preserving read location.
const point & location() const
Return current particle position.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278
const word cloudName(propsDict.get< word >("cloud"))
#define doLocalCode(GeoField)