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
9ITHACAparallel* ITHACAparallel::getInstance(fvMesh& mesh, Time& localTime)
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 Start = autoPtr<labelList> (new labelList(N_BF, 0));
94
95 for (label i = 0; i < N_BF; i++)
96 {
97 if (IndFaceLocal()[i].size() == 0)
98 {
99 Start()[i] = INT_MAX;
100 }
101 else if (IndFaceLocal()[i][0] < 0)
102 {
103 Start()[i] = INT_MAX;
104 }
105
106 if (IndFaceLocal()[i].size() != 0)
107 {
108 Start()[i] = IndFaceLocal()[i][0];
109 }
110
111 reduce(Start()[i], minOp<label>());
112 }
113}
114
116{
117 Pstream::parRun() = false;
118 label comm = Pstream::worldComm;
119 oldProcIDs_ = Pstream::procID(comm);
120 newProcIDs_ = List<int> (1);
121 Pstream::procID(comm) = newProcIDs_;
122}
123
125{
126 label comm = Pstream::worldComm;
127 Pstream::procID(comm) = oldProcIDs_;
128 Pstream::parRun() = true;
129}
130
131template<>
132List<List <scalar >> ITHACAparallel::combineFields(
133 GeometricField<scalar, fvPatchField, volMesh>& field)
134{
135 List<List< scalar >> GlobField(field.boundaryFieldRef().size() + 1);
136 GlobField[0].resize(N_IF_glob);
137
138 // Assemble internalField
139 for (label i = 0; i < field.size(); i++)
140 {
141 GlobField[0][indices()[i]] = field[i];
142 }
143
144 reduce(GlobField[0], sumOp<List<scalar >> ());
145
146 // Assemble BoundariField
147 for (label i = 0; i < N_BF; i++)
148 {
149 GlobField[i + 1].resize(Gsize_BF()[i]);
150 Field<scalar> zero(Gsize_BF()[i], 0.0);
151 GlobField[i + 1] = zero;
152 }
153 for (label i = 0; i < N_BF; i++)
154 {
155 for (label k = 0; k < field.boundaryFieldRef()[i].size(); k++)
156 {
157 if (IndFaceLocal()[i].size() > 0
158 && field.boundaryFieldRef()[i].type() != "zeroGradient"
159 && field.boundaryFieldRef()[i].type() != "processor" )
160 {
161 GlobField[i + 1][abs(IndFaceLocal()[i][k]) - Start()[i]] =
162 field.boundaryFieldRef()[i][k];
163 }
164 }
165
166 reduce(GlobField[i + 1], sumOp<List<scalar >> ());
167 }
168 return GlobField;
169}
170
171template<>
172List<List <vector >> ITHACAparallel::combineFields(
173 GeometricField<vector, fvPatchField, volMesh>& field)
174{
175 List<List< vector >> GlobField(field.boundaryFieldRef().size() + 1);
176 GlobField[0].resize(N_IF_glob);
177 GlobField[0] = GlobField[0] * 0;
178
179 // Assemble internalField
180 for (label i = 0; i < field.size(); i++)
181 {
182 GlobField[0][indices()[i]] = field[i];
183 }
184
185 reduce(GlobField[0], sumOp<List<vector >> ());
186
187 // Assemble BoundariField
188 for (label i = 0; i < N_BF; i++)
189 {
190 GlobField[i + 1].resize(Gsize_BF()[i]);
191 List<vector> zero(Gsize_BF()[i], vector(0.0, 0.0, 0.0));
192 GlobField[i + 1] = zero;
193 }
194 for (label i = 0; i < N_BF; i++)
195 {
196 for (label k = 0; k < field.boundaryFieldRef()[i].size(); k++)
197 {
198 if (IndFaceLocal()[i].size() > 0
199 && field.boundaryFieldRef()[i].type() != "zeroGradient"
200 && field.boundaryFieldRef()[i].type() != "processor" )
201 {
202 GlobField[i + 1][abs(IndFaceLocal()[i][k]) - Start()[i]] =
203 field.boundaryFieldRef()[i][k];
204 }
205 }
206
207 reduce(GlobField[i + 1], sumOp<List<vector >> ());
208 }
209 return GlobField;
210}
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.
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.
autoPtr< List< labelList > > IndFaceLocal
Indexing.
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