13 #ifndef _PARTICLEDATAI_H_ 14 #define _PARTICLEDATAI_H_ 17 #include "NamespaceHeader.H" 21 using std::binary_function;
45 valid[di].setVal(
false);
47 a_mask->copyTo(valid);
54 const IntVect iv(
D_DECL6((
int)floor((x[0] - a_origin[0])/a_meshSpacing[0]),
55 (
int)floor((x[1] - a_origin[1])/a_meshSpacing[1]),
56 (
int)floor((x[2] - a_origin[2])/a_meshSpacing[2]),
57 (
int)floor((x[3] - a_origin[3])/a_meshSpacing[3]),
58 (
int)floor((x[4] - a_origin[4])/a_meshSpacing[4]),
59 (
int)floor((x[5] - a_origin[5])/a_meshSpacing[5])));
61 if (valid[di](iv) ^ a_flip) a_partValid.
transfer(li);
76 CH_TIMERS(
"collectValidParticles(ParticleData)");
85 valid[di].setVal(
false);
87 a_mask->copyTo(valid);
94 const IntVect iv(
D_DECL6((
int)floor((x[0] - a_origin[0])/a_meshSpacing[0]),
95 (
int)floor((x[1] - a_origin[1])/a_meshSpacing[1]),
96 (
int)floor((x[2] - a_origin[2])/a_meshSpacing[2]),
97 (
int)floor((x[3] - a_origin[3])/a_meshSpacing[3]),
98 (
int)floor((x[4] - a_origin[4])/a_meshSpacing[4]),
99 (
int)floor((x[5] - a_origin[5])/a_meshSpacing[5])));
101 if (valid[di](iv) ^ a_flip)
102 a_PDValid[di].listItems().transfer(li);
109 inline void myswap(pair<const IntVect,boxids>& aa, pair<const IntVect,boxids>& bb)
111 pair<IntVect,boxids> a=(pair<IntVect,boxids>)aa;
112 pair<IntVect,boxids> b=(pair<IntVect,boxids>)bb;
113 pair<IntVect,boxids> t=make_pair(b.first,b.second);
121 template <
class ForwardIterator>
122 void myrotate ( ForwardIterator first, ForwardIterator middle,
123 ForwardIterator last )
125 ForwardIterator next = middle;
128 myswap (*first++,*next++);
129 if (next==last) next=middle;
130 else if (first == middle) middle=next;
134 typedef multimap<IntVect, boxids>::iterator
RmIt;
137 class CompCounts :
public binary_function<pair<IntVect,boxids>,
138 pair<IntVect,boxids>,bool>
146 const pair<const IntVect,boxids>& b)
const 148 return (
pp[a.second.pid][a.second.idx].length() <
149 pp[b.second.pid][b.second.idx].length());
153 vector<map<unsigned, List<P> > >&
pp;
167 const int& a_fixedBoxSize,
171 define(a_dp, a_domain, a_fixedBoxSize, a_meshSpacing, a_origin);
177 const int& a_fixedBoxSize,
205 (*this)[di].listItems().clear();
220 numParticles += (*this)[di].numItems();
240 gather(allCounts, countLocal, srcProc);
245 for(
int ivec = 0; ivec <
numProc(); ivec++)
247 count += allCounts[ivec];
266 numValid += (*this)[di].numItems();
284 gather(allCounts, countLocal, srcProc);
289 for(
int ivec = 0; ivec <
numProc(); ivec++)
291 count += allCounts[ivec];
324 gather(allCounts, countLocal, srcProc);
329 for(
int ivec = 0; ivec <
numProc(); ivec++)
331 count += allCounts[ivec];
393 for(
int i=0; i<nbox; i++)
395 unsigned int index = it[i].datInd();
396 Box abox = this->
box(it[i]);
411 (*this)[dit].getInvalidDestructive(
m_outcast,
422 const unsigned myPID =
procID();
425 vector<map<unsigned, List<P> > > pp(
numProc());
435 set<IntVect,CompIntVect> bivs;
436 map<IntVect,unsigned,CompIntVect> mil;
437 multimap<IntVect,boxids,CompIntVect> mip;
445 const unsigned pid=grids.
procID(li());
446 const unsigned idx=grids.
index(li());
453 mip.insert(pair<IntVect,boxids>(biv,
boxids(idx,pid)));
457 mil[biv] = grids.
index(li());
463 set<IntVect,CompIntVect>::iterator it;
464 for ( it=bivs.begin() ; it != bivs.end(); ++it )
466 const int count=mip.count(*it);
469 unsigned midn= myPID%count;
470 pair<RmIt,RmIt> rit=mip.equal_range(*it);
472 while (midn-->0) mid++;
479 map<IntVect,unsigned,CompIntVect>::iterator lit=mil.begin();
481 map<IntVect,boxids,CompIntVect>::iterator pit;
483 pair<RmIt,RmIt> rit=mip.equal_range(mip.begin()->first);
490 pp[myPID][lit->second].transfer(pi);
497 pp[myPID][lit->second].transfer(pi);
500 else if (ip==rit.first->first)
502 pit = min_element(rit.first,rit.second,compCounts);
503 pp[pit->second.pid][pit->second.idx].transfer(pi);
510 rit=mip.equal_range(ip);
511 pit= min_element(rit.first,rit.second,compCounts);
512 pp[pit->second.pid][pit->second.idx].transfer(pi);
525 map<unsigned,List<P> > lp;
526 typename map<unsigned,List<P> >::iterator mi;
527 for (mi=pp[myPID].begin(); mi!=pp[myPID].end(); ++mi)
529 lp[mi->first].catenate(mi->second);
535 mpi_scatter_part(lp,pp);
541 unsigned idx = grids.
index(di());
542 if (lp.find(idx) != lp.end())
544 (*this)[di].listItems().catenate(lp[idx]);
564 if (a_index[d] < lo[d])
566 new_index[d] += dim[d];
569 if (a_index[d] > hi[d])
571 new_index[d] -= dim[d];
580 const int a_numGhost)
const 591 RealVect domainWidth = domRE - domLE;
596 map<IntVect, boxids, CompIntVect> IntVectToBoxIDMap;
607 map<IntVect, boxids, CompIntVect>::iterator IntVectToBoxIDIterator;
608 IntVectToBoxIDIterator = IntVectToBoxIDMap.begin();
611 vector<map<unsigned, List<P> > > ghostsToSend(
numProc());
615 const Box& thisBox = grids[dit];
617 unsigned thisIndex = grids.
index(dit());
625 vector<unsigned> alreadySentTo;
631 alreadySentTo.clear();
633 D_TERM6(
for (
int i = -1; i < 2; i++) {,
634 for (
int j = -1; j < 2; j++) {,
635 for (
int k = -1; k < 2; k++) {,
636 for (
int l = -1; l < 2; l++) {,
637 for (
int m = -1; m < 2; m++) {,
638 for (
int n = -1; n < 2; n++) {)
642 RealVect shiftedPosition = pi().position() + shift;
645 srcIntVectIndex =
locateBin(pi().position(),
650 destIntVectIndex =
locateBin(shiftedPosition,
655 if (destIntVectIndex != srcIntVectIndex)
663 IntVectToBoxIDIterator = IntVectToBoxIDMap.find(periodicIntVectIndex);
664 unsigned destPID = IntVectToBoxIDIterator->second.pid;
665 unsigned destBoxID = IntVectToBoxIDIterator->second.idx;
668 for (
unsigned id=0;
id < alreadySentTo.size();
id++)
670 if (destBoxID == alreadySentTo[
id])
678 alreadySentTo.push_back(destBoxID);
686 if (periodicIntVectIndex != destIntVectIndex)
689 for (
int idim = 0; idim <
SpaceDim; idim++)
691 if (periodicIntVectIndex[idim] < destIntVectIndex[idim]) {
692 x[idim] -= domainWidth[idim];
694 if (periodicIntVectIndex[idim] > destIntVectIndex[idim]) {
695 x[idim] += domainWidth[idim];
701 ghostsToSend[destPID][destBoxID].add(p);
709 unsigned myPID =
procID();
710 map<unsigned, List<P> > localGhosts;
711 typename map<unsigned, List<P> >::iterator ghostMapIterator;
712 for (ghostMapIterator = ghostsToSend[myPID].begin(); ghostMapIterator != ghostsToSend[myPID].end(); ++ghostMapIterator)
714 unsigned myBoxID = ghostMapIterator->first;
715 List<P>& myGhosts = ghostMapIterator->second;
716 localGhosts[myBoxID].
catenate(myGhosts);
718 ghostsToSend[myPID].clear();
722 mpi_scatter_part(localGhosts, ghostsToSend);
728 unsigned idx = grids.
index(dit());
729 if (localGhosts.find(idx) != localGhosts.end())
731 a_particlesWithGhosts[dit].listItems().join((*
this)[dit].listItems());
732 a_particlesWithGhosts[dit].listItems().catenate(localGhosts[idx]);
743 #include "NamespaceFooter.H" #define D_DECL6(a, b, c, d, e, f)
Definition: CHArray.H:39
void myrotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last)
Definition: ParticleDataI.H:122
void catenate(List< T > &src)
Appends a copy of all items in List<T> src to this List<T>.
Definition: ListImplem.H:211
multimap< IntVect, boxids >::iterator RmIt
Definition: ParticleDataI.H:134
void fillGhosts(ParticleData< P > &a_particlesWithGhosts, const int a_numGhost) const
Definition: ParticleDataI.H:579
#define CH_TIMERS(name)
Definition: CH_Timer.H:133
virtual ListBox< T > * create(const Box &a_box, int a_numComps, const DataIndex &a_datInd) const
Factory function. Note that both a_numComps and a_dit are ignored.
Definition: ListBoxFactoryI.H:45
IntVect locateBin(const RealVect a_x, const RealVect a_dx, const RealVect a_origin)
compute the cell index containing the physical position of the item
Definition: ParticleData.H:47
Definition: ParticleDataI.H:137
bool m_callDelete
Definition: LayoutData.H:131
#define D_TERM6(a, b, c, d, e, f)
Definition: CHArray.H:40
#define CH_SPACEDIM
Definition: SPACE.H:51
size_t numValid() const
Definition: ParticleDataI.H:273
Box refine(const Box &b, const IntVect &refinement_ratio)
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
Vector< ListBox< P > *> m_vector
Definition: LayoutData.H:124
void transfer(ListIterator< T > &lit)
Transfer the object pointed to by lit from the List<T> lit is associated with to this one...
Definition: ListImplem.H:317
const ProblemDomain & physDomain() const
Get the physical domain associated with this ParticleData.
Definition: ParticleDataI.H:354
void gatherOutcast()
Definition: ParticleDataI.H:406
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:145
Data that maintains a one-to-one mapping of T to the boxes in a BoxLayout.
Definition: BoxLayout.H:26
void clear()
Removes all the items from all the boxes in the container.
Definition: ParticleDataI.H:199
void clear()
Removes all objects from the List<T>.
Definition: ListImplem.H:263
const BoxLayout & boxLayout() const
Definition: LayoutData.H:107
DataIterator dataIterator() const
Definition: LayoutDataI.H:78
size_t numOutcastLocal() const
Return the number of particles in the outcast list.
Definition: ParticleDataI.H:302
Box box(const DataIndex &a_index) const
Definition: LayoutDataI.H:66
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:117
void remapOutcast()
Definition: ParticleDataI.H:417
Definition: DataIterator.H:190
IntVect enforcePeriodic(const IntVect &a_index) const
Definition: ParticleDataI.H:550
virtual bool callDelete() const
Definition: BoxLayoutData.H:43
bool operator()(const pair< const IntVect, boxids > &a, const pair< const IntVect, boxids > &b) const
Definition: ParticleDataI.H:145
unsigned int numProc()
number of parallel processes
An Iterator based on a BoxLayout object.
Definition: LayoutIterator.H:35
const int SpaceDim
Definition: SPACE.H:38
void resize(unsigned int isize)
Definition: Vector.H:346
IndexTM< T, N > coarsen(const IndexTM< T, N > &a_p, T a_s)
Definition: IndexTMI.H:430
ProblemDomain m_physDomain
Definition: ParticleData.H:187
void gather(Vector< T > &a_outVec, const T &a_input, int a_dest)
Definition: SPMDI.H:197
bool ok() const
Return true if the iterator is not past the end of the list.
Definition: List.H:465
const RealVect & meshSpacing() const
Get the mesh spacing associated with this ParticleData,.
Definition: ParticleDataI.H:360
const IntVect & bigEnd() const
Definition: Box.H:1784
unsigned int index(const LayoutIndex &index) const
Definition: BoxLayout.H:748
int size() const
Definition: DataIterator.H:218
RealVect m_origin
Definition: ParticleData.H:189
static const IntVect Unit
Definition: IntVect.H:663
bool m_isDefined
Definition: ParticleData.H:192
new code
Definition: BoxLayoutData.H:170
bool isClosed() const
Is this ParticleData.
Definition: ParticleDataI.H:348
Iterator over a List.
Definition: List.H:20
const IntVect & smallEnd() const
{ Accessors}
Definition: Box.H:1770
Data on a BoxLayout.
Definition: BoxLayoutData.H:97
double Real
Definition: REAL.H:33
vector< map< unsigned, List< P > > > & pp
Definition: ParticleDataI.H:153
void myswap(pair< const IntVect, boxids > &aa, pair< const IntVect, boxids > &bb)
Definition: ParticleDataI.H:109
Box grow(const Box &b, int i)
Definition: Box.H:2277
List< P > m_outcast
Definition: ParticleData.H:186
CompCounts(vector< map< unsigned, List< P > > > &a_pp)
Definition: ParticleDataI.H:142
bool isPeriodic(int a_dir) const
Returns true if BC is periodic in direction a_dir.
Definition: ProblemDomain.H:894
size_t size() const
Definition: Vector.H:192
size_t numOutcast() const
Definition: ParticleDataI.H:313
static void Error(const char *const a_msg=m_nullString, int m_exitCode=CH_DEFAULT_ERROR_CODE)
Print out message to cerr and exit with the specified exit code.
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
const BoxLayout & getBoxes() const
Get the BoxLayout on which this ParticleData.
Definition: ParticleDataI.H:193
void collectValidParticles(List< P > &a_partValid, ParticleData< P > &a_PD, const LevelData< BaseFab< bool > > *a_mask, const RealVect a_meshSpacing, const int a_refRatio, const bool a_flip, const RealVect a_origin)
Definition: ParticleDataI.H:28
size_t numParticlesLocal() const
Return the number of particles in the container, outcast and valid.
Definition: ParticleDataI.H:212
ParticleData()
Weak Constructor.
Definition: ParticleDataI.H:157
int length() const
Returns the number of objects in the List<T>.
Definition: ListImplem.H:56
RealVect m_meshSpacing
Definition: ParticleData.H:188
Definition: ParticleData.H:26
void define(const BoxLayout &a_dp, const ProblemDomain &a_domain, const int &a_fixedBoxSize, const RealVect &a_meshSpacing, const RealVect &a_origin)
Define function. Same as the full constructor.
Definition: ParticleDataI.H:175
void allocateVector()
Definition: ParticleDataI.H:378
int m_fixedBoxSize
Definition: ParticleData.H:190
size_t numValidLocal() const
Return the number of valid particles in the container, not counting outcasts.
Definition: ParticleDataI.H:258
size_t numParticles() const
Definition: ParticleDataI.H:229
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
List< P > & outcast()
Definition: ParticleDataI.H:342
const RealVect & origin() const
Get the origin of the coordinate system.
Definition: ParticleDataI.H:366
bool isEmpty() const
Returns true if the List<T> is empty.
Definition: List.H:619
void broadcast(T &a_inAndOut, int a_src)
broadcast to every process
Definition: SPMDI.H:207
const Box & domainBox() const
Returns the logical computational domain.
Definition: ProblemDomain.H:887
LayoutIterator layoutIterator() const
Iterator that processes through ALL the boxes in a BoxLayout.
virtual void getInvalid(List< T > &a_list, const Box &a_valid) const
Definition: ListBoxI.H:189
DataIterator dataIterator() const
Parallel iterator.
int dim
Definition: EBInterface.H:146
int procID()
local process ID
const int & fixedBoxSize() const
Get the fixed Box size.
Definition: ParticleDataI.H:372
Definition: ParticleData.H:67
ListBoxFactory< P > m_factory
Definition: ParticleData.H:191
unsigned int procID(const LayoutIndex &a_index) const
Definition: BoxLayout.H:760
void define(const RealVect &a_meshSpacing, const RealVect &a_origin)
Use these parameters for all manufactured ListBox instances.
Definition: ListBoxFactoryI.H:36