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-2023 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  cloudName_(cloudName)
44 {
45  // Create reverse cell addressing
46  List<remote> cellProcCell(completeMesh_.nCells());
47  forAll(cellProcAddressing, proci)
48  {
49  forAll(cellProcAddressing[proci], procCelli)
50  {
51  cellProcCell[cellProcAddressing[proci][procCelli]] =
52  remote(proci, procCelli);
53  }
54  }
55 
56  // Create reverse face addressing
57  List<remote> faceOwnerProcFace(completeMesh_.nFaces());
58  List<remote> faceNeighbourProcFace(completeMesh_.nFaces());
59  forAll(faceProcAddressing, proci)
60  {
61  forAll(faceProcAddressing[proci], procFacei)
62  {
63  const bool owner = faceProcAddressing[proci][procFacei] > 0;
64  const label facei = mag(faceProcAddressing[proci][procFacei]) - 1;
65 
66  (owner ? faceOwnerProcFace : faceNeighbourProcFace)[facei] =
67  remote(proci, procFacei);
68  }
69  }
70 
71  // Read the complete positions
72  const passiveParticleCloud completePositions
73  (
74  completeMesh_,
75  cloudName_,
76  false
77  );
78 
79  // Construct empty clouds for processor positions
80  PtrList<passiveParticleCloud> procPositions(procMeshes_.size());
81  forAll(procMeshes_, proci)
82  {
83  procPositions.set
84  (
85  proci,
86  new passiveParticleCloud
87  (
88  procMeshes_[proci],
89  cloudName_,
90  IDLList<passiveParticle>()
91  )
92  );
93  }
94 
95  // Count the number of particles on each processor
96  labelList procNParticles(procMeshes_.size(), 0);
97  forAllConstIter(passiveParticleCloud, completePositions, 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, completePositions, 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  procPositions[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  // Write
150  forAll(procPositions, proci)
151  {
152  IOPosition<passiveParticleCloud>(procPositions[proci]).write();
153  }
154 }
155 
156 
157 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
158 
160 {}
161 
162 
163 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
164 
166 {
167  bool result = false;
168 
169  #define DO_LAGRANGIAN_FIELDS_TYPE(Type, nullArg) \
170  result = result \
171  || !objects.lookupClass(IOField<Type>::typeName).empty() \
172  || !objects.lookupClass(IOField<Field<Type>>::typeName).empty() \
173  || !objects.lookupClass(CompactIOField<Field<Type>>::typeName).empty();
174  DO_LAGRANGIAN_FIELDS_TYPE(label, )
175  FOR_ALL_FIELD_TYPES(DO_LAGRANGIAN_FIELDS_TYPE)
176  #undef DO_LAGRANGIAN_FIELDS_TYPE
177 
178  return result;
179 }
180 
181 
182 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
static bool decomposes(const IOobjectList &objects)
Return whether anything in the object list gets decomposed.
lagrangianFieldDecomposer(const fvMesh &completeMesh, const PtrList< fvMesh > &procMeshes, const labelListList &faceProcAddressing, const labelListList &cellProcAddressing, const word &cloudName)
Construct from components.
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
dimensioned< scalar > mag(const dimensioned< Type > &)
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
objects
volScalarField & p
const word cloudName(propsDict.lookup("cloudName"))