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 -------------------------------------------------------------------------------
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  passivePositionParticleCloud lagrangianPositions
62  (
63  mesh_,
64  cloudName,
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
135  new passivePositionParticle
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  {
155  IOPosition<passivePositionParticleCloud>
156  (
157  lagrangianPositions,
159  ).write();
160  }
161 
162  return lagrangianPositions.size();
163 }
164 
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 // ************************************************************************* //
Template class for intrusive linked lists.
Definition: ILList.H:45
label tetFace() const noexcept
Return current tet face particle is in.
Definition: particleI.H:134
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)
const barycentric & coordinates() const noexcept
Return current particle coordinates.
Definition: particleI.H:116
label procTetPt(const polyMesh &procMesh, const label procCell, const label procTetFace) const
Return the tet point appropriate for decomposition or reconstruction.
Definition: particle.C:1188
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:414
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
const point & location() const noexcept
The cached particle position.
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.
label cell() const noexcept
Return current cell particle is in.
Definition: particleI.H:122
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:79
Tensor of scalars, i.e. Tensor<scalar>.
label reconstructPositions(const word &cloudName) const
Reconstruct positions for given cloud.
Copy of base particle but without particle locating and preserving read location. ...
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:133