Loading...
Searching...
No Matches
ITHACAparallel.C
Go to the documentation of this file.
1#define NoConstructFromTmp
2#include "ITHACAparallel.H"
3#undef NoConstructFromTmp
4
7ITHACAparallel* ITHACAparallel::instance = nullptr;
8
10
11{
12 M_Assert(instance == nullptr,
13 "ITHACAparallel is already initialized, call ITHACAparallel::getInstance() to return an instance of ITHACAparallel");
14 instance = new ITHACAparallel(mesh, localTime);
15 return instance;
16}
17
19
20{
21 M_Assert(instance != nullptr,
22 "ITHACAparallel needs to be initialized, call ITHACAparallel::getInstance(mesh, runTime) first");
23 return instance;
24}
25
26
27ITHACAparallel::ITHACAparallel(fvMesh& mesh, Time& localTime)
28 :
29 runTime(localTime),
30 mesh(mesh)
31{
32 N_BF = 0;
33
34 for (label i = 0; i < mesh.boundaryMesh().size(); i++)
35 {
36 if (mesh.boundaryMesh()[i].type() != "processor")
37 {
38 N_BF++;
39 }
40 }
41
42 // Load cell addressing
43 indices = autoPtr<labelIOList>
44 (
45 new labelIOList
46 (
47 IOobject
48 (
49 "cellProcAddressing",
50 mesh.facesInstance(),
51 mesh.meshSubDir,
52 mesh,
53 IOobject::MUST_READ,
54 IOobject::NO_WRITE
55 )
56 )
57 );
58 // Load face addressing
59 indicesF = autoPtr<labelIOList>
60 (
61 new labelIOList
62 (
63 IOobject
64 (
65 "faceProcAddressing",
66 mesh.facesInstance(),
67 mesh.meshSubDir,
68 mesh,
69 IOobject::MUST_READ,
70 IOobject::NO_WRITE
71 )
72 )
73 );
74 // Calculate total number of cells
75 N_IF_glob = (mesh.C().size());
76 reduce(N_IF_glob, sumOp<label>());
77 // BF construction
78 Gsize_BF = autoPtr<labelList>(new labelList (N_BF, label(0)));
79 IndFaceLocal = autoPtr< List<labelList>> (new List<labelList> (N_BF,
80 labelList(label(0), label(0))));
81
82 for (label i = 0; i < N_BF; i++)
83 {
84 Gsize_BF()[i] = mesh.boundaryMesh()[i].size();
85 reduce(Gsize_BF()[i], sumOp<label>());
86 IndFaceLocal()[i].resize(mesh.boundaryMesh()[i].size());
87
88 for (label k = 0; k < mesh.boundaryMesh()[i].size(); k++)
89 {
90 IndFaceLocal()[i][k] = indicesF()[mesh.boundaryMesh()[i].start() + k];
91 }
92 }
93
94 Start = autoPtr<labelList> (new labelList(N_BF, 0));
95
96 for (label i = 0; i < N_BF; i++)
97 {
98 if (IndFaceLocal()[i].size() == 0)
99 {
100 Start()[i] = INT_MAX;
101 }
102 else if (IndFaceLocal()[i][0] < 0)
103 {
104 Start()[i] = INT_MAX;
105 }
106
107 if (IndFaceLocal()[i].size() != 0)
108 {
109 Start()[i] = IndFaceLocal()[i][0];
110 }
111
112 reduce(Start()[i], minOp<label>());
113 }
114}
115
117{
118 Pstream::parRun() = false;
119 label comm = Pstream::worldComm;
120 oldProcIDs_ = Pstream::procID(comm);
121 newProcIDs_ = List<int> (1);
122 Pstream::procID(comm) = newProcIDs_;
123}
124
126{
127 label comm = Pstream::worldComm;
128 Pstream::procID(comm) = oldProcIDs_;
129 Pstream::parRun() = true;
130}
131
132template<>
134 GeometricField<scalar, fvPatchField, volMesh>& field)
135{
136 List<List< scalar>> GlobField(field.boundaryFieldRef().size() + 1);
137 GlobField[0].resize(N_IF_glob);
138
139 // Assemble internalField
140 for (label i = 0; i < field.size(); i++)
141 {
142 GlobField[0][indices()[i]] = field[i];
143 }
144
145 reduce(GlobField[0], sumOp<List<scalar>>());
146
147 // Assemble BoundariField
148 for (label i = 0; i < N_BF; i++)
149 {
150 GlobField[i + 1].resize(Gsize_BF()[i]);
151 Field<scalar> zero(Gsize_BF()[i], 0.0);
152 GlobField[i + 1] = zero;
153 }
154
155 for (label i = 0; i < N_BF; i++)
156 {
157 for (label k = 0; k < field.boundaryFieldRef()[i].size(); k++)
158 {
159 if (IndFaceLocal()[i].size() > 0
160 && field.boundaryFieldRef()[i].type() != "zeroGradient"
161 && field.boundaryFieldRef()[i].type() != "processor" )
162 {
163 GlobField[i + 1][abs(IndFaceLocal()[i][k]) - Start()[i]] =
164 field.boundaryFieldRef()[i][k];
165 }
166 }
167
168 reduce(GlobField[i + 1], sumOp<List<scalar>>());
169 }
170
171 return GlobField;
172}
173
174template<>
176 GeometricField<vector, fvPatchField, volMesh>& field)
177{
178 List<List< vector>> GlobField(field.boundaryFieldRef().size() + 1);
179 GlobField[0].resize(N_IF_glob);
180 GlobField[0] = GlobField[0] * 0;
181
182 // Assemble internalField
183 for (label i = 0; i < field.size(); i++)
184 {
185 GlobField[0][indices()[i]] = field[i];
186 }
187
188 reduce(GlobField[0], sumOp<List<vector>>());
189
190 // Assemble BoundariField
191 for (label i = 0; i < N_BF; i++)
192 {
193 GlobField[i + 1].resize(Gsize_BF()[i]);
194 List<vector> zero(Gsize_BF()[i], vector(0.0, 0.0, 0.0));
195 GlobField[i + 1] = zero;
196 }
197
198 for (label i = 0; i < N_BF; i++)
199 {
200 for (label k = 0; k < field.boundaryFieldRef()[i].size(); k++)
201 {
202 if (IndFaceLocal()[i].size() > 0
203 && field.boundaryFieldRef()[i].type() != "zeroGradient"
204 && field.boundaryFieldRef()[i].type() != "processor" )
205 {
206 GlobField[i + 1][abs(IndFaceLocal()[i][k]) - Start()[i]] =
207 field.boundaryFieldRef()[i][k];
208 }
209 }
210
211 reduce(GlobField[i + 1], sumOp<List<vector>>());
212 }
213
214 return GlobField;
215}
Foam::fvMesh & mesh
Definition createMesh.H:47
Foam::Time & runTime
Definition createTime.H:33
#define M_Assert(Expr, Msg)
Class for parallel handling, it has several functions to deal with parallel problems,...
autoPtr< labelList > Start
StartFace on the gloabl Mesh.
autoPtr< labelIOList > indices
Cell proc addressing.
autoPtr< List< labelList > > IndFaceLocal
Indexing.
static void suspendMPI()
Function to sumpend MPI.
fvMesh & mesh
Mesh object defined locally.
ITHACAparallel()=delete
Delete empty constructor.
static ITHACAparallel * getInstance()
Gets an instance of ithacaparallel, to be used if the instance is already existing.
static void resumeMPI()
Function to resume MPI.
label N_IF_glob
Totoal number of internal field cells.
static List< int > newProcIDs_
ID of the NEW process.
autoPtr< labelIOList > indicesF
Face proc addressing.
static List< int > oldProcIDs_
ID of the OLD process.
autoPtr< labelList > Gsize_BF
Boundary Field variables representing the total number of faces for each processor.
List< List< Type > > combineFields(GeometricField< Type, fvPatchField, volMesh > &field)
Function to get a global field from a parallel one.
label N_BF
Number of Boundary Patches without considering processors.
label i
Definition pEqn.H:46