Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
MeshInterface_def.hpp
1#ifndef MESHINTERFACE_def_hpp
2#define MESHINTERFACE_def_hpp
3#include "MeshInterface_decl.hpp"
4
13
14
15//search all code for these functions and move them to Tools file.
16template <typename T>
17std::vector<T> sort_from_ref(
18 std::vector<T> const& in,
19 std::vector<int> const& reference
20 ) {
21 std::vector<T> ret(in.size());
22
23 int const size = in.size();
24 for (int i = 0; i < size; ++i)
25 ret[i] = in[reference[i]];
26
27 return ret;
28};
29
30template <typename T>
31std::vector<T> sort_from_ref(
32 std::vector<T> const& in,
33 std::vector<long long> const& reference
34 ) {
35 std::vector<T> ret(in.size());
36
37 int const size = in.size();
38 for (long long i = 0; i < size; ++i)
39 ret[i] = in[reference[i]];
40
41 return ret;
42};
43
44namespace FEDD {
45
46template <class SC, class LO, class GO, class NO>
47MeshInterface<SC,LO,GO,NO>::MeshInterface():
48indicesGlobalMatched_(),
49indicesGlobalMatchedOrigin_(),
50indicesGlobalMatchedUnique_(),
51isPartitioned_(false),
52partialCouplingFlag_(0),
53partialCouplingType_(0),
54comm_()
55{
56
57}
58
59template <class SC, class LO, class GO, class NO>
60MeshInterface<SC,LO,GO,NO>::MeshInterface(CommConstPtr_Type comm):
61indicesGlobalMatched_(),
62indicesGlobalMatchedOrigin_(),
63indicesGlobalMatchedUnique_(),
64isPartitioned_(false),
65partialCouplingFlag_(0),
66partialCouplingType_(0),
67comm_(comm)
68{
69
70}
71
72template <class SC, class LO, class GO, class NO>
73void MeshInterface<SC,LO,GO,NO>::partitionMeshInterface(MapPtr_Type mapRepeated, MapPtr_Type mapUnique){
74
75 // TODO: irgenwann mal in indicesGlobalMatchedOrigin_ abaendern
76 vec3D_GO_ptr_Type indicesSerial = indicesGlobalMatchedOrigin_;
77
78 // Das ist der repated Vektor
79 indicesGlobalMatched_.reset(new vec3D_GO_Type ( indicesSerial->size() , vec2D_GO_Type( 2 , vec_GO_Type(0) ) ) );
80
81 // Das ist der unique Vektor
82 indicesGlobalMatchedUnique_.reset(new vec3D_GO_Type ( indicesSerial->size() , vec2D_GO_Type( 2 , vec_GO_Type(0) ) ) );
83
84 for (int flag=0; flag<indicesSerial->size(); flag++) {
85 for (int i=0; i<indicesSerial->at(flag).at(0).size(); i++) {
86 // Fuer den repated Vektor
87 GO indexThis = mapRepeated->getLocalElement( indicesSerial->at(flag).at(0).at(i) );
88 if ( indexThis != Teuchos::OrdinalTraits<LO>::invalid() ) {
89 indicesGlobalMatched_->at(flag).at(0).push_back( indicesSerial->at(flag).at(0).at(i) );
90 indicesGlobalMatched_->at(flag).at(1).push_back( indicesSerial->at(flag).at(1).at(i) );
91 }
92
93 GO indexThisUni = mapUnique->getLocalElement( indicesSerial->at(flag).at(0).at(i) );
94 // Fuer den unique Vektor
95 if ( indexThisUni != Teuchos::OrdinalTraits<LO>::invalid() ) {
96 indicesGlobalMatchedUnique_->at(flag).at(0).push_back( indicesSerial->at(flag).at(0).at(i) );
97 indicesGlobalMatchedUnique_->at(flag).at(1).push_back( indicesSerial->at(flag).at(1).at(i) );
98 }
99
100 }
101 }
102
103 isPartitioned_ = true;
104}
105
106
107template <class SC, class LO, class GO, class NO>
108void MeshInterface<SC,LO,GO,NO>::determineInterface( vec2D_dbl_ptr_Type pointsRepThis, vec2D_dbl_ptr_Type pointsRepOther, vec_int_ptr_Type flagThis, vec_int_ptr_Type flagOther, vec_int_Type relevant_flag_vec ){
109
110 indicesGlobalMatched_.reset(new vec3D_GO_Type( relevant_flag_vec.size(), vec2D_GO_Type(2) ) );
111
112 // Damit wir auf den nicht-partionierten Vektor zugreifen koennen.
113 indicesGlobalMatchedOrigin_.reset(new vec3D_GO_Type( relevant_flag_vec.size(), vec2D_GO_Type(2) ) );
114
115 // Points N x dim vectors
116 for (int flag=0; flag<relevant_flag_vec.size(); flag++) {
117 vec2D_dbl_Type pointThis(0);
118 vec2D_dbl_Type pointOther(0);
119 vec_GO_Type indexGlobalThis(0);
120 vec_GO_Type indexGlobalOther(0);
121 vec_int_Type indexThis(0);
122 vec_int_Type indexOther(0);
123 int counter = 0;
124 for (int i=0; i<pointsRepThis->size(); i++) {
125 if (flagThis->at(i) == relevant_flag_vec.at(flag)) {
126 pointThis.push_back( pointsRepThis->at(i) );
127 indexGlobalThis.push_back(i);
128 indexThis.push_back(counter);
129 counter++;
130 }
131 }
132 counter = 0;
133 for (int i=0; i<pointsRepOther->size(); i++) {
134 if (flagOther->at(i) == relevant_flag_vec.at(flag)) {
135 pointOther.push_back( pointsRepOther->at(i) );
136 indexGlobalOther.push_back(i);
137 indexOther.push_back(counter);
138 counter++;
139 }
140 }
141
142 std::cout << "serial determineInterface - number flag nodes this:" << indexThis.size()<< " other:" << indexOther.size() << std::endl;
143
144 sort(indexThis.begin(), indexThis.end(),
145 [&](const int& a, const int& b) {
146 return pointThis[a] < pointThis[b];
147 }
148 );
149
150 sort(indexOther.begin(), indexOther.end(),
151 [&](const int& a, const int& b) {
152 return pointOther[a] < pointOther[b];
153 }
154 );
155
156 indexGlobalThis = sort_from_ref(indexGlobalThis, indexThis);
157 indexGlobalOther = sort_from_ref(indexGlobalOther, indexOther);
158
159 TEUCHOS_TEST_FOR_EXCEPTION( indexGlobalThis.size()!=indexGlobalOther.size(), std::logic_error, "Interfaces do not have the same length!");
160
161
162 indicesGlobalMatched_->at(flag).at(0) = indexGlobalThis;
163 indicesGlobalMatched_->at(flag).at(1) = indexGlobalOther;
164
165 indicesGlobalMatchedOrigin_->at(flag).at(0) = indexGlobalThis;
166 indicesGlobalMatchedOrigin_->at(flag).at(1) = indexGlobalOther;
167
168 }
169
170}
171
172template <class SC, class LO, class GO, class NO>
173int MeshInterface<SC,LO,GO,NO>::isPartialCouplingFlag(int flag){
174
175 auto it = std::find( partialCouplingFlag_.begin(), partialCouplingFlag_.end(), flag );
176 if ( it!=partialCouplingFlag_.end() )
177 return std::distance( partialCouplingFlag_.begin(), it );
178 else
179 return -1;
180}
181
182template <class SC, class LO, class GO, class NO>
183void MeshInterface<SC,LO,GO,NO>::setPartialCoupling(int flag, std::string type){
184 partialCouplingFlag_.push_back(flag);
185 partialCouplingType_.push_back(type);
186
187}
188
189template <class SC, class LO, class GO, class NO>
190int MeshInterface<SC,LO,GO,NO>::getPartialCouplingFlag(int i){
191 TEUCHOS_TEST_FOR_EXCEPTION(sizePartialCoupling()-1 < i, std::runtime_error, "There is no partial coupling for this index");
192 return partialCouplingFlag_[i];
193}
194
195template <class SC, class LO, class GO, class NO>
196std::string MeshInterface<SC,LO,GO,NO>::getPartialCouplingType(int i){
197 TEUCHOS_TEST_FOR_EXCEPTION(sizePartialCoupling()-1 < i, std::runtime_error, "There is no partial coupling for this index");
198 return partialCouplingType_[i];
199}
200
201template <class SC, class LO, class GO, class NO>
202int MeshInterface<SC,LO,GO,NO>::sizePartialCoupling(){
203 return partialCouplingFlag_.size();
204}
205
206template <class SC, class LO, class GO, class NO>
207void MeshInterface<SC,LO,GO,NO>::determineInterfaceParallelAndDistance( vec2D_dbl_ptr_Type pointsUniThis, vec2D_dbl_ptr_Type pointsUniOther, vec_int_ptr_Type flagUniThis, vec_int_ptr_Type flagUniOther, vec_int_Type relevant_flag_vec, MapConstPtr_Type mapUniThis, MapConstPtr_Type mapUniOther, vec_dbl_ptr_Type &distancesToInterface, vec2D_dbl_ptr_Type pointsRepThis, int dim ) {
208
209 SC eps100 = 100. * Teuchos::ScalarTraits<SC>::eps();
210 GO invalid = Teuchos::OrdinalTraits<GO>::invalid();
211
212 indicesGlobalMatched_.reset(new vec3D_GO_Type( relevant_flag_vec.size(), vec2D_GO_Type(2) ) );
213
214 // Damit wir auf den nicht-partionierten Vektor zugreifen koennen.
215 // Build in parallel first and then build this global index vector
216 // Adjust size
217 indicesGlobalMatchedOrigin_.reset(new vec3D_GO_Type( relevant_flag_vec.size(), vec2D_GO_Type(2) ) );
218
219 // send data for the relevant flag
220 for (int flagIndex=0; flagIndex<relevant_flag_vec.size(); flagIndex++) {
221 int flag = relevant_flag_vec[flagIndex];
222 //Warning !!! The following information is local!
223 vec_GO_Type indexGlobalCommThis(0);
224 vec_GO_Type indexGlobalCommOther(0);
225
226 for (int i=0; i<pointsUniThis->size(); i++) {
227 if ( flagUniThis->at(i) == flag ) {
228 indexGlobalCommThis.push_back( mapUniThis->getGlobalElement( i ) );
229 }
230 }
231
232 for (int i=0; i<pointsUniOther->size(); i++) {
233 if ( flagUniOther->at(i) == flag ) {
234 indexGlobalCommOther.push_back( mapUniOther->getGlobalElement( i ) );
235 }
236 }
237
238 //Communicate everything with MultiVectors.
239 //First determine the length of the new global vector
240 GO numInterfaceGlobalThis = 0;
241 GO numInterfaceGlobalOther = 0;
242
243 Teuchos::reduceAll( *this->comm_, Teuchos::REDUCE_SUM, (GO) indexGlobalCommThis.size(), Teuchos::ptrFromRef( numInterfaceGlobalThis ) );
244
245 Teuchos::reduceAll( *this->comm_, Teuchos::REDUCE_SUM, (GO) indexGlobalCommOther.size(), Teuchos::ptrFromRef( numInterfaceGlobalOther ) );
246
247 MapPtr_Type mapThis = Teuchos::rcp( new Map_Type( -1, Teuchos::arrayViewFromVector( indexGlobalCommThis ), 0, this->comm_ ) );
248
249 MapPtr_Type mapOther = Teuchos::rcp( new Map_Type( -1, Teuchos::arrayViewFromVector( indexGlobalCommOther ), 0, this->comm_ ) );
250
251 std::cout << "numInterfaceGlobalThis:" << numInterfaceGlobalThis << std::endl;
252 std::cout << "numInterfaceGlobalOther:" << numInterfaceGlobalOther << std::endl;
253 TEUCHOS_TEST_FOR_EXCEPTION( numInterfaceGlobalThis != numInterfaceGlobalOther, std::runtime_error, "DetermineInterfaceInParallel failed. ThisMesh and OtherMesh seem to have different numbers of interface nodes." );
254
255 std::vector<GO> gatherAllIndices(numInterfaceGlobalThis);
256 std::iota ( std::begin( gatherAllIndices ), std::end( gatherAllIndices ), 0 );
257
258 MapPtr_Type linearMapThis = Teuchos::rcp( new Map_Type( numInterfaceGlobalThis, indexGlobalCommThis.size(), 0, this->comm_ ) );
259 MapPtr_Type linearMapOther = Teuchos::rcp( new Map_Type(numInterfaceGlobalThis, indexGlobalCommOther.size(), 0, this->comm_ ) );
260 MapPtr_Type gatherAllMap = Teuchos::rcp( new Map_Type( invalid, Teuchos::arrayViewFromVector( gatherAllIndices ), 0, this->comm_ ) );
261
262 // We would like to use the Teuchos version of MPI_Allgatherv, which does not exist. Therefore we gatherv on a root and broadcast afterwards
263 // Gather local lengths first
264 vec_int_Type localSizeThis( this->comm_->getSize(),0 );
265 vec_int_Type localSizeOther( this->comm_->getSize(),0 );
266 int root = 0;
267
268 int sizeThis = indexGlobalCommThis.size();
269 int sizeOther = indexGlobalCommOther.size();
270 Teuchos::gather<int, int>( &sizeThis, 1, &localSizeThis[0], 1, root, *this->comm_ );
271 Teuchos::gather<int, int>( &sizeOther, 1, &localSizeOther[0], 1, root, *this->comm_ );
272
273 GO* sendThis = NULL;
274 if (indexGlobalCommThis.size()>0)
275 sendThis = &indexGlobalCommThis[0];
276 GO* sendOther = NULL;
277 if (indexGlobalCommOther.size()>0)
278 sendOther = &indexGlobalCommOther[0];
279
280 vec_GO_Type gatheredThis( numInterfaceGlobalThis , -1);
281 vec_GO_Type gatheredOther( numInterfaceGlobalThis, -1);
282
283 vec_int_Type displacementsThis( ((int) this->comm_->getRank()==root ) * this->comm_->getSize(),0 );
284 vec_int_Type displacementsOther( ((int) this->comm_->getRank()==root ) * this->comm_->getSize(),0 );
285 int* displThis = NULL;
286 if (displacementsThis.size()>0)
287 displThis = &displacementsThis[0];
288 int* displOther = NULL;
289 if (displacementsOther.size()>0)
290 displOther = &displacementsOther[0];
291
292 for (int i=1; i<displacementsThis.size(); i++)
293 displacementsThis[i] = displacementsThis[i-1] + localSizeThis[i-1];
294 for (int i=1; i<displacementsOther.size(); i++)
295 displacementsOther[i] = displacementsOther[i-1] + localSizeOther[i-1];
296
297 Teuchos::gatherv<int,GO>( sendThis, indexGlobalCommThis.size(), &gatheredThis[0], &localSizeThis[0], displThis, root, *this->comm_ );
298 Teuchos::gatherv<int,GO>( sendOther, indexGlobalCommOther.size(), &gatheredOther[0], &localSizeOther[0], displOther, root, *this->comm_ );
299
300 //Now we broadcast from root
301 Teuchos::broadcast<int,GO>( *this->comm_, root, Teuchos::arrayViewFromVector( gatheredThis ) );
302 Teuchos::broadcast<int,GO>( *this->comm_, root, Teuchos::arrayViewFromVector( gatheredOther ) );
303
304 MapPtr_Type mapAllThis = Teuchos::rcp( new Map_Type(invalid, Teuchos::arrayViewFromVector( gatheredThis ), 0, this->comm_ ) );
305 MapPtr_Type mapAllOther = Teuchos::rcp( new Map_Type( invalid, Teuchos::arrayViewFromVector( gatheredOther ), 0, this->comm_ ) );
306
307 bool meshOnRank = false;
308 if (pointsUniThis->size() > 0)
309 meshOnRank = true;
310
311 MultiVectorPtr_Type mvLocalThis;
312 MultiVectorPtr_Type mvLocalOther;
313
314 mvLocalThis = Teuchos::rcp( new MultiVector_Type( mapThis, dim + 1 ) );
315 mvLocalOther = Teuchos::rcp( new MultiVector_Type( mapOther, dim + 1 ) );
316
317 // Fill local vectors with node coordinates and global index; last column is the global index
318 // This
319 for (int j=0; j<dim; j++) {
320 Teuchos::ArrayRCP< SC > data = mvLocalThis->getDataNonConst(j);
321 for (int i=0; i<data.size(); i++) {
322 LO index = mapUniThis->getLocalElement( indexGlobalCommThis[i] );
323 data[i] = pointsUniThis->at( index )[j];
324 }
325 }
326
327 Teuchos::ArrayRCP< SC > dataThis = mvLocalThis->getDataNonConst( dim );
328 for (int i=0; i<dataThis.size(); i++)
329 dataThis[i] = indexGlobalCommThis[i];
330
331
332 // Other
333 for (int j=0; j<dim; j++) {
334 Teuchos::ArrayRCP< SC > data = mvLocalOther->getDataNonConst(j);
335 for (int i=0; i<data.size(); i++) {
336 LO index = mapUniOther->getLocalElement( indexGlobalCommOther[i] );
337 data[i] = pointsUniOther->at( index )[j];
338 }
339 }
340
341 Teuchos::ArrayRCP< SC > dataOther = mvLocalOther->getDataNonConst( dim );
342 for (int i=0; i<dataOther.size(); i++)
343 dataOther[i] = indexGlobalCommOther[i];
344
345
346 MultiVectorPtr_Type mvGlobalThis;
347 MultiVectorPtr_Type mvGlobalOther;
348
349 mvGlobalThis = Teuchos::rcp( new MultiVector_Type( mapAllThis, dim + 1 ) );
350 mvGlobalOther = Teuchos::rcp( new MultiVector_Type( mapAllOther, dim + 1 ) );
351 // Communicate, we might want to use gatherv and broadcast here aswell
352 mvGlobalThis->exportFromVector( mvLocalThis, true, "Insert", "Reverse" );
353 mvGlobalOther->exportFromVector( mvLocalOther, true, "Insert", "Reverse" );
354
355 // now we can go through the same data on every rank like in the serial case
356 // copy to std::vectors first; we should try to avoid this in a optimized implementation
357 // Points N x dim vectors
358
359 vec_int_Type indexThis( numInterfaceGlobalThis );
360 vec_int_Type indexOther( numInterfaceGlobalThis );
361 std::iota ( std::begin( indexThis ), std::end( indexThis ), 0 );
362 std::iota ( std::begin( indexOther ), std::end( indexOther ), 0 );
363
364 vec2D_dbl_Type pointThis( numInterfaceGlobalThis, vec_dbl_Type(dim) );
365 vec2D_dbl_Type pointOther( numInterfaceGlobalThis, vec_dbl_Type(dim) );
366
367 vec_GO_Type indexGlobalThis( numInterfaceGlobalThis );
368 vec_GO_Type indexGlobalOther( numInterfaceGlobalThis );
369
370
371 int counter = 0;
372 {
373 Teuchos::ArrayRCP< const SC > dataX = mvGlobalThis->getData(0);
374 Teuchos::ArrayRCP< const SC > dataY = mvGlobalThis->getData(1);
375 Teuchos::ArrayRCP< const SC > dataZ;
376 Teuchos::ArrayRCP< const SC > dataGlob;
377 if (dim==3) {
378 dataZ = mvGlobalThis->getData(2);
379 dataGlob = mvGlobalThis->getData(dim);
380 }
381 else if (dim==2)
382 dataGlob = mvGlobalThis->getData(dim);
383
384 for (int i=0; i<pointThis.size(); i++) {
385 pointThis[i][0] = dataX[i];
386 pointThis[i][1] = dataY[i];
387 if (dim==3)
388 pointThis[i][2] = dataZ[i];
389 indexGlobalThis[i] = (GO) dataGlob[i] + eps100;
390 }
391 }
392 {
393 Teuchos::ArrayRCP< const SC > dataX = mvGlobalOther->getData(0);
394 Teuchos::ArrayRCP< const SC > dataY = mvGlobalOther->getData(1);
395 Teuchos::ArrayRCP< const SC > dataZ;
396 Teuchos::ArrayRCP< const SC > dataGlob;
397 if (dim==3) {
398 dataZ = mvGlobalOther->getData(2);
399 dataGlob = mvGlobalOther->getData(dim);
400 }
401 else if (dim==2)
402 dataGlob = mvGlobalOther->getData(dim);
403
404 for (int i=0; i<pointOther.size(); i++) {
405 pointOther[i][0] = dataX[i];
406 pointOther[i][1] = dataY[i];
407 if (dim==3)
408 pointOther[i][2] = dataZ[i];
409 indexGlobalOther[i] = (GO) dataGlob[i] + eps100;
410
411 }
412 }
413
414 sort(indexThis.begin(), indexThis.end(),
415 [&](const int& a, const int& b) {
416 return pointThis[a] < pointThis[b];
417 }
418 );
419
420 sort(indexOther.begin(), indexOther.end(),
421 [&](const int& a, const int& b) {
422 return pointOther[a] < pointOther[b];
423 }
424 );
425
426 indexGlobalThis = sort_from_ref(indexGlobalThis, indexThis);
427 indexGlobalOther = sort_from_ref(indexGlobalOther, indexOther);
428
429
430 indicesGlobalMatched_->at(flagIndex).at(0) = indexGlobalThis;
431 indicesGlobalMatched_->at(flagIndex).at(1) = indexGlobalOther;
432// std::cout << "indexGlobalThis->size():" << indexGlobalThis.size() << std::endl;
433// std::cout << "indexGlobalOther->size():" << indexGlobalOther.size() << std::endl;
434 indicesGlobalMatchedOrigin_->at(flagIndex).at(0) = indexGlobalThis;
435 indicesGlobalMatchedOrigin_->at(flagIndex).at(1) = indexGlobalOther;
436
437 //determine distance for this flag.
438 calculateDistancesToInterfaceParallel( distancesToInterface, pointThis, pointsRepThis );
439 }
440}
441
442
443template <class SC, class LO, class GO, class NO>
444void MeshInterface<SC,LO,GO,NO>::calculateDistancesToInterfaceParallel( vec_dbl_ptr_Type &distancesToInterface, vec2D_dbl_Type &pointThis/*global interface, every proc has same information*/, vec2D_dbl_ptr_Type sourceNodesRep /*partitioned points*/)
445{
446
447 int dim = -1;
448 if (pointThis.size() > 0)
449 dim = pointThis[0].size();
450
451 // See comments for calculateDistancesToInterface() in class Domain.
452 // This is the parallel version
453
454 // Not partitioned interfaces
455 vec3D_GO_ptr_Type indicesGlobalMatched = this->indicesGlobalMatched_;
456
457 // SourceNodes (z.B. Fluidgebiet) aus dem Gitter ziehen
458 // Gefaehrlich, da Veraenderungen an SourceNodesRep auch PointsRep_ veraendern;
459 // Sonst auf 0.0 setzen und dann Werte reinschreiben.
460 // Am besten waere es Getter zu haben mit return vec2D_dbl_ptr_Type bzw. const vec2vec2D_dbl_ptr_Type, damit nichts passieren kann.
461
462 // Zaehle mit Hilfe von indicesGlobalMatched wie viele Interfaceknoten es insgesamt gibt.
463 // Here we should loop over all flags in the case of more than one flag.
464 int numberInterfaceNodes = indicesGlobalMatched->at(0).at(0).size();
465
466 // EndNodes (Interfaceknoten) aus dem Gitter ziehen; mit Hilfe von IndicesGlobalMatched
467 vec2D_dbl_ptr_Type endNodesRep = Teuchos::rcpFromRef(pointThis);
468
469 // Distanz zum Interface auf eine unrealistisch grosse Zahl setzen.
470 // In DistancesToInterface_->at(i) steht die Distanz der globalen Knoten-ID i zum Interface
471
472 if ( distancesToInterface.is_null() )
473 distancesToInterface = Teuchos::rcp( new vec_dbl_Type( sourceNodesRep->size(), 1000.0 ) );
474
475 // Berechne nun den Abstand von den sourceNodesRep zu den EndNodesRep
476 double distance = 0.0;
477 for(int i = 0; i < sourceNodesRep->size(); i++)
478 {
479 for(int j = 0; j < endNodesRep->size(); j++)
480 {
481 for(int k = 0; k < dim; k++)
482 {
483 distance = distance + std::pow( sourceNodesRep->at(i).at(k) - endNodesRep->at(j).at(k), 2.0 );
484 }
485
486 // Noch die Wurzel ziehen
487 distance = std::sqrt(distance);
488
489 if(distancesToInterface->at(i) > distance)
490 distancesToInterface->at(i) = distance;
491
492 // Reseten
493 distance = 0.0;
494 }
495 }
496}
497
498
499template <class SC, class LO, class GO, class NO>
500void MeshInterface<SC,LO,GO,NO>::buildFromOtherInterface( Teuchos::RCP<MeshInterface> otherMeshInterface){
501
502 TEUCHOS_TEST_FOR_EXCEPTION( otherMeshInterface->indicesGlobalMatched_->size()<=0, std::logic_error, "MeshInterface given is empty.");
503 TEUCHOS_TEST_FOR_EXCEPTION( otherMeshInterface->indicesGlobalMatched_->at(0).size()<=0, std::logic_error, "MeshInterface given is empty.");
504 TEUCHOS_TEST_FOR_EXCEPTION( otherMeshInterface->isPartitioned_, std::logic_error, "Other MeshInterface already partitioned.");
505 TEUCHOS_TEST_FOR_EXCEPTION( isPartitioned_, std::logic_error, "This MeshInterface already partitioned.");
506
507 indicesGlobalMatched_.reset(new vec3D_GO_Type( otherMeshInterface->indicesGlobalMatched_->size(), vec2D_GO_Type ( 2 , vec_GO_Type( 0 ) ) ) );
508
509 indicesGlobalMatchedOrigin_.reset(new vec3D_GO_Type( otherMeshInterface->indicesGlobalMatchedOrigin_->size(), vec2D_GO_Type ( 2 , vec_GO_Type( 0 ) ) ) );
510
511 for (int i=0; i<otherMeshInterface->indicesGlobalMatched_->size(); i++) {
512 indicesGlobalMatched_->at(i).at(0).resize( otherMeshInterface->indicesGlobalMatched_->at(i).at(0).size() );
513 indicesGlobalMatched_->at(i).at(1).resize( otherMeshInterface->indicesGlobalMatched_->at(i).at(1).size() );
514 indicesGlobalMatchedOrigin_->at(i).at(0).resize( otherMeshInterface->indicesGlobalMatchedOrigin_->at(i).at(0).size() );
515 indicesGlobalMatchedOrigin_->at(i).at(1).resize( otherMeshInterface->indicesGlobalMatchedOrigin_->at(i).at(1).size() );
516 for (int j=0; j<otherMeshInterface->indicesGlobalMatched_->at(i).at(0).size(); j++) {
517 indicesGlobalMatched_->at(i).at(0).at(j) = otherMeshInterface->indicesGlobalMatched_->at(i).at(1).at(j);
518 indicesGlobalMatched_->at(i).at(1).at(j) = otherMeshInterface->indicesGlobalMatched_->at(i).at(0).at(j);
519
520 indicesGlobalMatchedOrigin_->at(i).at(0).at(j) = otherMeshInterface->indicesGlobalMatchedOrigin_->at(i).at(1).at(j);
521 indicesGlobalMatchedOrigin_->at(i).at(1).at(j) = otherMeshInterface->indicesGlobalMatchedOrigin_->at(i).at(0).at(j);
522
523 }
524 }
525}
526
527template <class SC, class LO, class GO, class NO>
528void MeshInterface<SC,LO,GO,NO>::print(CommConstPtr_Type comm){
529
530 for (int i=0; i<indicesGlobalMatched_->size(); i++) {
531 for (int j=0; j<indicesGlobalMatched_->at(i).at(0).size(); j++) {
532 std::cout << comm->getRank()<<" Matched IDs for flag " << i << " :" << indicesGlobalMatched_->at(i).at(0).at(j) << " - " << indicesGlobalMatched_->at(i).at(0).at(j) << std::endl;
533 }
534 }
535}
536
537template <class SC, class LO, class GO, class NO>
538typename MeshInterface<SC,LO,GO,NO>::vec3D_GO_ptr_Type MeshInterface<SC,LO,GO,NO>::getIndicesGlobalMatched(){
539 return indicesGlobalMatched_;
540}
541
542template <class SC, class LO, class GO, class NO>
543typename MeshInterface<SC,LO,GO,NO>::vec3D_GO_ptr_Type MeshInterface<SC,LO,GO,NO>::getIndicesGlobalMatchedOrigin()
544{
545 return indicesGlobalMatchedOrigin_;
546}
547
548template <class SC, class LO, class GO, class NO>
549typename MeshInterface<SC,LO,GO,NO>::vec3D_GO_ptr_Type MeshInterface<SC,LO,GO,NO>::getIndicesGlobalMatchedUnique()
550{
551 return indicesGlobalMatchedUnique_;
552}
553
554
555}
556#endif
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement.cpp:5