lagrangianFieldDecomposer.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 #include "passiveParticleCloud.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 (
33  const fvMesh& completeMesh,
34  const PtrList<fvMesh>& procMeshes,
35  const labelListList& faceProcAddressing,
36  const labelListList& cellProcAddressing,
37  const word& cloudName
38 )
39 :
40  completeMesh_(completeMesh),
41  procMeshes_(procMeshes),
42  particleProcAddressing_(procMeshes_.size()),
43  procClouds_(procMeshes.size()),
44  cloudName_(cloudName)
45 {
46  // Create reverse cell addressing
47  List<remote> cellProcCell(completeMesh_.nCells());
48  forAll(cellProcAddressing, proci)
49  {
50  forAll(cellProcAddressing[proci], procCelli)
51  {
52  cellProcCell[cellProcAddressing[proci][procCelli]] =
53  remote(proci, procCelli);
54  }
55  }
56 
57  // Create reverse face addressing
58  List<remote> faceOwnerProcFace(completeMesh_.nFaces());
59  List<remote> faceNeighbourProcFace(completeMesh_.nFaces());
60  forAll(faceProcAddressing, proci)
61  {
62  forAll(faceProcAddressing[proci], procFacei)
63  {
64  const bool owner = faceProcAddressing[proci][procFacei] > 0;
65  const label facei = mag(faceProcAddressing[proci][procFacei]) - 1;
66 
67  (owner ? faceOwnerProcFace : faceNeighbourProcFace)[facei] =
68  remote(proci, procFacei);
69  }
70  }
71 
72  // Read the complete positions
73  const passiveParticleCloud completeCloud
74  (
75  completeMesh_,
76  cloudName_,
77  false
78  );
79 
80  // Construct empty clouds for processor positions
81  forAll(procMeshes_, proci)
82  {
83  procClouds_.set
84  (
85  proci,
87  (
88  procMeshes_[proci],
89  cloudName_,
91  )
92  );
93  }
94 
95  // Count the number of particles on each processor
96  labelList procNParticles(procMeshes_.size(), 0);
97  forAllConstIter(passiveParticleCloud, completeCloud, iter)
98  {
99  const passiveParticle& p = iter();
100  const label proci = cellProcCell[p.cell()].proci;
101 
102  procNParticles[proci] ++;
103  }
104 
105  // Resize the addressing
106  forAll(procMeshes_, proci)
107  {
108  particleProcAddressing_[proci].resize(procNParticles[proci], -1);
109  }
110 
111  // Distribute positions to the processor meshes
112  label completeParticlei = 0;
113  labelList procParticlei(procMeshes_.size(), 0);
114  forAllConstIter(passiveParticleCloud, completeCloud, iter)
115  {
116  const passiveParticle& p = iter();
117  const label proci = cellProcCell[p.cell()].proci;
118  const label procCelli = cellProcCell[p.cell()].elementi;
119  const label procFacei =
120  faceOwnerProcFace[p.tetFace()].proci == proci
121  ? faceOwnerProcFace[p.tetFace()].elementi
122  : faceNeighbourProcFace[p.tetFace()].elementi;
123 
124  particleProcAddressing_[proci][procParticlei[proci]] =
125  completeParticlei;
126 
127  procClouds_[proci].append
128  (
129  new passiveParticle
130  (
131  procMeshes_[proci],
132  p.coordinates(),
133  procCelli,
134  procFacei,
135  p.procTetPt
136  (
137  completeMesh_,
138  procMeshes_[proci],
139  procCelli,
140  procFacei
141  )
142  )
143  );
144 
145  completeParticlei ++;
146  procParticlei[proci] ++;
147  }
148 }
149 
150 
151 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
152 
154 {}
155 
156 
157 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
158 
160 {
161  bool result = false;
162 
163  #define DO_LAGRANGIAN_FIELDS_TYPE(Type, nullArg) \
164  result = result \
165  || !objects.lookupClass(IOField<Type>::typeName).empty() \
166  || !objects.lookupClass(IOField<Field<Type>>::typeName).empty() \
167  || !objects.lookupClass(CompactIOField<Field<Type>>::typeName).empty();
170  #undef DO_LAGRANGIAN_FIELDS_TYPE
171 
172  return result;
173 }
174 
175 
178 {
179  return procClouds_;
180 }
181 
182 
184 {
185  forAll(procClouds_, proci)
186  {
187  IOPosition<passiveParticleCloud>(procClouds_[proci]).write();
188  }
189 }
190 
191 
192 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:476
Template class for intrusive linked lists.
Definition: ILList.H:67
Helper IO class to read and write particle positions.
Definition: IOPosition.H:60
virtual bool write(const bool write=true) const
Write using setting from DB.
Definition: IOPosition.C:59
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:53
void resize(const label)
Alias for setSize(const label)
Definition: ListI.H:138
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
void decomposePositions() const
Write the decomposed positions.
static bool decomposes(const IOobjectList &objects)
Return whether anything in the object list gets decomposed.
const PtrList< passiveParticleCloud > & procClouds() const
Access the decomposed clouds.
lagrangianFieldDecomposer(const fvMesh &completeMesh, const PtrList< fvMesh > &procMeshes, const labelListList &faceProcAddressing, const labelListList &cellProcAddressing, const word &cloudName)
Construct from components.
A Cloud of passive particles.
Copy of base particle.
label nCells() const
label nFaces() const
Struct for keeping processor, element (cell, face, point) index.
Definition: remote.H:57
A class for handling words, derived from string.
Definition: word.H:62
#define DO_LAGRANGIAN_FIELDS_TYPE(Type, nullArg)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
objects
volScalarField & p
const word cloudName(propsDict.lookup("cloudName"))