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-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 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
39 Foam::lagrangianReconstructor::lagrangianReconstructor
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  // Start with empty cloud
62  passivePositionParticleCloud lagrangianPositions
63  (
64  mesh_,
65  Foam::zero{},
66  cloudName
67  );
68 
69  forAll(procMeshes_, meshi)
70  {
71  const labelList& cellMap = cellProcAddressing_[meshi];
72  const labelList& faceMap = faceProcAddressing_[meshi];
73 
74  // Use a special particle that does not try to find the particle on
75  // the mesh. This is to be able to handle particles originating
76  // from a different processor. This can happen with some
77  // functionObjects - e.g. extractEulerianParticles.
78  // These particles should be
79  // - written in the old format
80  passivePositionParticleCloud lpi(procMeshes_[meshi], cloudName, false);
81 
82  for (const passivePositionParticle& ppi : lpi)
83  {
84  const label mappedCell =
85  (
86  (ppi.cell() >= 0)
87  ? cellMap[ppi.cell()]
88  : -1
89  );
90 
91  // Inverting sign if necessary and subtracting 1 from
92  // faceProcAddressing
93  const label mappedTetFace =
94  (
95  (ppi.tetFace() >= 0)
96  ? mag(faceMap[ppi.tetFace()]) - 1
97  : -1
98  );
99 
100  if ((ppi.cell() >= 0) && (ppi.tetFace() >= 0))
101  {
102  // cell,face succesfully mapped. Coordinates inside the cell
103  // should be same
104  lagrangianPositions.append
105  (
106  new passivePositionParticle
107  (
108  mesh_,
109  ppi.coordinates(),
110  mappedCell,
111  mappedTetFace,
112  ppi.procTetPt(mesh_, mappedCell, mappedTetFace)
113  )
114  );
115  }
116  else
117  {
118  // No valid coordinates. Two choices:
119  // - assume reconstructed mesh contains the position so do
120  // a locate with the (reconstructed) mesh
121  // - preserve -1 as cell id, maintain the read location
122  lagrangianPositions.append
123  (
124 
125  //- Option 1: locate on reconstructed mesh
126  //new passivePositionParticle
127  //(
128  // mesh_,
129  // ppi.location(),
130  // mappedCell
131  //)
132 
133  //- Option 2: maintain read location
134  new passivePositionParticle
135  (
136  mesh_,
137  Zero, // position
138  -1, // celli
139  -1, // tetFacei
140  -1, // tetPti
141  ppi.location()
142  )
143  );
144  }
145  }
146  }
147 
148 
149  IOPosition<passivePositionParticleCloud>(lagrangianPositions).write();
150 
151  // Force writing of "positions" too, if specified via the InfoSwitch
153  {
154  IOPosition<passivePositionParticleCloud>
155  (
156  lagrangianPositions,
158  ).write();
159  }
160 
161  return lagrangianPositions.size();
162 }
163 
166 (
167  const word& cloudName,
168  const IOobjectList& cloudObjs,
169  const wordRes& selectedFields
170 )
171 {
172  do
173  {
174  #undef doLocalCode
175  #define doLocalCode(Type) \
176  { \
177  this->reconstructFields<Type> \
178  ( \
179  cloudName, \
180  cloudObjs, \
181  selectedFields \
182  ); \
183  \
184  this->reconstructFieldFields<Type> \
185  ( \
186  cloudName, \
187  cloudObjs, \
188  selectedFields \
189  ); \
190  }
191 
192  doLocalCode(label);
193  doLocalCode(scalar);
198 
199  #undef doLocalCode
200  }
201  while (false);
202 }
203 
204 
205 // ************************************************************************* //
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
void reconstructAllFields(const word &cloudName, const IOobjectList &cloudObjs, const wordRes &selectedFields=wordRes())
Reconstruct all fields for known cloud field types.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
#define doLocalCode(Type)
dynamicFvMesh & mesh
const word cloudName(propsDict.get< word >("cloud"))
A class for handling words, derived from Foam::string.
Definition: word.H:63
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
static int verbose_
Output verbosity when writing.
static bool writeLagrangianPositions
Write particle positions file (v1706 format and earlier) Default is true (disable in etc/controlDict)...
Definition: particle.H:472
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
List< label > labelList
A List of labels.
Definition: List.H:62
Tensor of scalars, i.e. Tensor<scalar>.
label reconstructPositions(const word &cloudName) const
Reconstruct positions for given cloud.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127