15#include <dune/common/unused.hh>
20template<
typename P0,
typename P1>
22 : patches_{gp0, gp1}, merger_(merger)
26 if (gp0->gridView().comm().size() == 1
27 && gp1->gridView().comm().size() == 1)
28 mpicomm_ = MPI_COMM_SELF;
30 mpicomm_ = MPI_COMM_WORLD;
32 std::cout <<
"GridGlue: Constructor succeeded!" << std::endl;
35template<
typename P0,
typename P1>
41 MPI_Comm_rank(mpicomm_, &myrank);
42 MPI_Comm_size(mpicomm_, &commsize);
47 std::vector<IntersectionData> dummy(1);
48 intersections_.swap(dummy);
51 std::vector<Dune::FieldVector<ctype, dimworld> > patch0coords;
52 std::vector<unsigned int> patch0entities;
53 std::vector<Dune::GeometryType> patch0types;
54 std::vector<Dune::FieldVector<ctype,dimworld> > patch1coords;
55 std::vector<unsigned int> patch1entities;
56 std::vector<Dune::GeometryType> patch1types;
67 std::cout <<
">>>> rank " << myrank <<
" coords: "
68 << patch0coords.size() <<
" and " << patch1coords.size() << std::endl;
69 std::cout <<
">>>> rank " << myrank <<
" entities: "
70 << patch0entities.size() <<
" and " << patch1entities.size() << std::endl;
71 std::cout <<
">>>> rank " << myrank <<
" types: "
72 << patch0types.size() <<
" and " << patch1types.size() << std::endl;
75 const char prefix[] =
"GridGlue::Builder::build() : ";
77 sprintf(patch0surf,
"/tmp/vtk-patch0-test-%i", myrank);
79 sprintf(patch1surf,
"/tmp/vtk-patch1-test-%i", myrank);
99 patch0_is_.beginResize();
100 patch1_is_.beginResize();
105 const int mergingrank,
106 const std::vector<Dune::FieldVector<ctype,dimworld> >& remotePatch0coords,
107 const std::vector<unsigned int>& remotePatch0entities,
108 const std::vector<Dune::GeometryType>& remotePatch0types,
109 const std::vector<Dune::FieldVector<ctype,dimworld> >& remotePatch1coords,
110 const std::vector<unsigned int>& remotePatch1entities,
111 const std::vector<Dune::GeometryType>& remotePatch1types
114 if (remotePatch1entities.size() > 0 && patch0entities.size() > 0)
115 mergePatches(patch0coords, patch0entities, patch0types, myrank,
116 remotePatch1coords, remotePatch1entities, remotePatch1types, mergingrank);
117 if (mergingrank != myrank &&
118 remotePatch0entities.size() > 0 && patch1entities.size() > 0)
119 mergePatches(remotePatch0coords, remotePatch0entities, remotePatch0types, mergingrank,
120 patch1coords, patch1entities, patch1types, myrank);
123 patch0coords, patch0entities, patch0types,
124 patch1coords, patch1entities, patch1types
130 patch0_is_.endResize();
131 patch1_is_.endResize();
134 remoteIndices_.setIncludeSelf(
true);
136 remoteIndices_.setIndexSets(patch0_is_, patch1_is_, mpicomm_) ;
137 remoteIndices_.rebuild<
true>();
140#ifdef DEBUG_GRIDGLUE_PARALLELMERGE
141 for (
auto it = remoteIndices_.begin(); it != remoteIndices_.end(); it++)
143 std::cout << myrank <<
"\tri-list\t" << it->first << std::endl;
144 for (
auto xit = it->second.first->begin(); xit != it->second.first->end(); ++xit)
145 std::cout << myrank <<
"\tri-list 1 \t" << it->first <<
"\t" << *xit << std::endl;
146 for (
auto xit = it->second.second->begin(); xit != it->second.second->end(); ++xit)
147 std::cout << myrank <<
"\tri-list 2 \t" << it->first <<
"\t" << *xit << std::endl;
153 if (patch1entities.size() > 0 && patch0entities.size() > 0)
155 mergePatches(patch0coords, patch0entities, patch0types, myrank,
156 patch1coords, patch1entities, patch1types, myrank);
157#ifdef CALL_MERGER_TWICE
158 mergePatches(patch0coords, patch0entities, patch0types, myrank,
159 patch1coords, patch1entities, patch1types, myrank);
168void printVector(
const std::vector<T> & v, std::string name,
int rank)
170 std::cout << rank <<
": " << name << std::endl;
171 for (
size_t i=0; i<v.size(); i++)
173 std::cout << v[i] <<
" ";
175 std::cout << std::endl;
178template<
typename P0,
typename P1>
180 const std::vector<Dune::FieldVector<ctype,dimworld> >& patch0coords,
181 const std::vector<unsigned int>& patch0entities,
182 const std::vector<Dune::GeometryType>& patch0types,
183 const int patch0rank,
184 const std::vector<Dune::FieldVector<ctype,dimworld> >& patch1coords,
185 const std::vector<unsigned int>& patch1entities,
186 const std::vector<Dune::GeometryType>& patch1types,
187 const int patch1rank)
195 MPI_Comm_rank(mpicomm_, &myrank);
196 MPI_Comm_size(mpicomm_, &commsize);
200 const bool patch0local = (myrank == patch0rank);
201 const bool patch1local = (myrank == patch1rank);
204 const unsigned int offset = intersections_.size()-1;
207 <<
" GridGlue::mergePatches : rank " << patch0rank <<
" / " << patch1rank << std::endl;
210 merger_->build(patch0coords, patch0entities, patch0types,
211 patch1coords, patch1entities, patch1types);
214 intersections_.resize(merger_->nSimplices() + offset + 1);
215 for (
unsigned int i = 0; i < merger_->nSimplices(); ++i)
216 intersections_[offset + i] = IntersectionData(*
this, i, offset, patch0local, patch1local);
218 index__sz = intersections_.size() - 1;
221 <<
" GridGlue::mergePatches : "
222 <<
"The number of remote intersections is " << intersections_.size()-1 << std::endl;
226 printVector(patch0entities,
"patch0entities",myrank);
229 printVector(patch1entities,
"patch1entities",myrank);
237 assert(Dune::RESIZE == patch0_is_.state());
238 assert(Dune::RESIZE == patch1_is_.state());
240 for (
unsigned int i = 0; i < merger_->nSimplices(); i++)
243 const IntersectionData & it = intersections_[i];
244 GlobalId gid(patch0rank, patch1rank, i);
245 if (it.template local<0>())
247 Dune::PartitionType ptype =
patch<0>().element(it.template index<0>()).partitionType();
248 patch0_is_.add (gid, LocalIndex(offset+i, ptype) );
250 if (it.template local<1>())
252 Dune::PartitionType ptype =
patch<1>().element(it.template index<1>()).partitionType();
253 patch1_is_.add (gid, LocalIndex(offset+i, ptype) );
263template<
typename P0,
typename P1>
264template<
typename Extractor>
266 std::vector<Dune::FieldVector<ctype, dimworld> > & coords,
267 std::vector<unsigned int> & entities,
268 std::vector<Dune::GeometryType>& geometryTypes)
const
270 std::vector<typename Extractor::Coords> tempcoords;
271 std::vector<typename Extractor::VertexVector> tempentities;
275 coords.reserve(tempcoords.size());
277 for (
unsigned int i = 0; i < tempcoords.size(); ++i)
280 coords.push_back(Dune::FieldVector<ctype, dimworld>());
281 for (
size_t j = 0; j <
dimworld; ++j)
282 coords.back()[j] = tempcoords[i][j];
288 for (
unsigned int i = 0; i < tempentities.size(); ++i) {
289 for (
unsigned int j = 0; j < tempentities[i].size(); ++j)
290 entities.push_back(tempentities[i][j]);
298template<
typename P0,
typename P1>
299template<
class DataHandleImp,
class DataTypeImp>
302 Dune::InterfaceType iftype, Dune::CommunicationDirection dir)
const
305 typedef typename DataHandle::DataType DataType;
309 if (mpicomm_ != MPI_COMM_SELF)
315 Dune::dinfo <<
"GridGlue: parallel communication" << std::endl;
316 typedef Dune::EnumItem <Dune::PartitionType, Dune::InteriorEntity> InteriorFlags;
317 typedef Dune::EnumItem <Dune::PartitionType, Dune::OverlapEntity> OverlapFlags;
318 typedef Dune::EnumRange <Dune::PartitionType, Dune::InteriorEntity, Dune::GhostEntity> AllFlags;
319 Dune::Interface interface;
320 assert(remoteIndices_.isSynced());
323 case Dune::InteriorBorder_InteriorBorder_Interface :
324 interface.build (remoteIndices_, InteriorFlags(), InteriorFlags() );
326 case Dune::InteriorBorder_All_Interface :
327 if (dir == Dune::ForwardCommunication)
328 interface.build (remoteIndices_, InteriorFlags(), AllFlags() );
330 interface.build (remoteIndices_, AllFlags(), InteriorFlags() );
332 case Dune::Overlap_OverlapFront_Interface :
333 interface.build (remoteIndices_, OverlapFlags(), OverlapFlags() );
335 case Dune::Overlap_All_Interface :
336 if (dir == Dune::ForwardCommunication)
337 interface.build (remoteIndices_, OverlapFlags(), AllFlags() );
339 interface.build (remoteIndices_, AllFlags(), OverlapFlags() );
341 case Dune::All_All_Interface :
342 interface.build (remoteIndices_, AllFlags(), AllFlags() );
345 DUNE_THROW(Dune::NotImplemented,
"GridGlue::communicate for interface " << iftype <<
" not implemented");
353 commInfo.
data = &data;
356 Dune::BufferedCommunicator bComm ;
361 if (dir == Dune::ForwardCommunication)
372 Dune::dinfo <<
"GridGlue: sequential fallback communication" << std::endl;
375 int ssz =
size() * 10;
376 int rsz =
size() * 10;
379 auto sendbuffer = std::make_unique<DataType[]>(ssz);
380 auto receivebuffer = std::make_unique<DataType[]>(rsz);
389 if (dir == Dune::ForwardCommunication)
396 data.
gather(gatherbuffer, in.inside(), in);
406 data.
gather(gatherbuffer, in.outside(), in.flip());
412 for (
int i=0; i<ssz; i++)
413 receivebuffer[i] = sendbuffer[i];
422 if (dir == Dune::ForwardCommunication)
428 data.
scatter(scatterbuffer, in.outside(), in.flip(),
437 data.
scatter(scatterbuffer, in.inside(), in,
Central component of the module implementing the coupling of two grids.
Model of the Intersection concept provided by GridGlue.
Definition gridglue.hh:37
Definition gridglue.hh:38
CommunicationOperator< Dune::BackwardCommunication > BackwardOperator
Definition gridgluecommunicate.hh:264
CommunicationOperator< Dune::ForwardCommunication > ForwardOperator
Definition gridgluecommunicate.hh:263
IteratorRange<... > intersections(const GridGlue<... > &glue, const Reverse<... > &reverse=!reversed)
Iterate over all intersections of a GridGlue.
void printVector(const std::vector< T > &v, std::string name, int rank)
Definition gridglue.cc:168
void MPI_AllApply(MPI_Comm mpicomm, OP &&op, const Args &... data)
apply an operator locally to a difstributed data set
Definition ringcomm.hh:297
void mergePatches(const std::vector< Dune::FieldVector< ctype, dimworld > > &patch0coords, const std::vector< unsigned int > &patch0entities, const std::vector< Dune::GeometryType > &patch0types, const int patch0rank, const std::vector< Dune::FieldVector< ctype, dimworld > > &patch1coords, const std::vector< unsigned int > &patch1entities, const std::vector< Dune::GeometryType > &patch1types, const int patch1rank)
after building the merged grid the intersection can be updated through this method (for internal use)
Definition gridglue.cc:179
void communicate(Dune::GridGlue::CommDataHandle< DataHandleImp, DataTypeImp > &data, Dune::InterfaceType iftype, Dune::CommunicationDirection dir) const
Communicate information on the MergedGrid of a GridGlue.
Definition gridglue.cc:300
static constexpr int dimworld
export the world dimension This is the maximum of the extractors' world dimensions.
Definition gridglue.hh:166
GridGlue(const std::shared_ptr< const GridPatch< 0 > > &gp0, const std::shared_ptr< const GridPatch< 1 > > &gp1, const std::shared_ptr< Merger > &merger)
constructor
Definition gridglue.cc:21
void build()
Definition gridglue.cc:36
void extractGrid(const Extractor &extractor, std::vector< Dune::FieldVector< ctype, dimworld > > &coords, std::vector< unsigned int > &faces, std::vector< Dune::GeometryType > &geometryTypes) const
Definition gridglue.cc:265
const GridPatch< P > & patch() const
Definition gridglue.hh:308
std::conditional_t< side==0, P0, std::conditional_t< side==1, P1, void > > GridPatch
Definition gridglue.hh:96
size_t size() const
Definition gridglue.hh:393
describes the features of a data handle for communication in parallel runs using the GridGlue::commun...
Definition gridgluecommunicate.hh:77
size_t size(RISType &i) const
Definition gridgluecommunicate.hh:92
void scatter(MessageBufferImp &buff, const EntityType &e, const RISType &i, size_t n)
Definition gridgluecommunicate.hh:118
void gather(MessageBufferImp &buff, const EntityType &e, const RISType &i) const
pack data from user to message buffer
Definition gridgluecommunicate.hh:104
Definition gridgluecommunicate.hh:141
collects all GridGlue data required for communication
Definition gridgluecommunicate.hh:272
Dune::CommunicationDirection dir
Definition gridgluecommunicate.hh:288
::Dune::GridGlue::CommDataHandle< DataHandleImp, DataTypeImp > * data
Definition gridgluecommunicate.hh:282
const GridGlue * gridglue
Definition gridgluecommunicate.hh:281
Provides codimension-independent methods for grid extraction.
Definition extractor.hh:46
static constexpr auto dimworld
Definition extractor.hh:50
void getFaces(std::vector< VertexVector > &faces) const
Get the corners of the extracted subentities.
Definition extractor.hh:285
void getGeometryTypes(std::vector< Dune::GeometryType > &geometryTypes) const
Get the list of geometry types.
Definition extractor.hh:274
void getCoords(std::vector< Dune::FieldVector< ctype, dimworld > > &coords) const
getter for the coordinates array
Definition extractor.hh:256