OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
NDIndexInlines.h
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 *
4 * The IPPL Framework
5 *
6 *
7 * Visit http://people.web.psi.ch/adelmann/ for more details
8 *
9 ***************************************************************************/
10
11#ifndef NDINDEX_INLINES_H
12#define NDINDEX_INLINES_H
13
14// include files
15#include "Utility/PAssert.h"
16
17
19// Construct from a simple array of Indexes
20template<unsigned Dim>
21inline
23{
24 for (unsigned i=0; i<Dim; ++i)
25 p[i]=idx[i];
26}
27
28// Intersect with another NDIndex.
29template<unsigned Dim>
30inline NDIndex<Dim>
32{
34 for (unsigned d=0;d<Dim;++d)
35 r[d] = p[d].intersect( i[d] );
36 return r;
37}
38
40
41// Forward substitute the base of one index into this one.
42
43template<unsigned D1, unsigned D2>
44inline NDIndex<D1> plugBase(const NDIndex<D1>& i1, const NDIndex<D2>& i2)
45{
46 // Construct and return ret.
47 NDIndex<D1> ret(i1);
48 // Loop over each of the Indexes in ret.
49 for (unsigned d1=0; d1<D1; ++d1)
50 // Try to find the corresponding Index in i2.
51 for (unsigned d2=0; d2<D2; ++d2)
52 if ( i1[d1].sameBase( i2[d2] ) )
53 {
54 // Found it. Substitute for this one.
55 ret[d1] = ret[d1].plugBase( i2[d2] );
56 break;
57 }
58 return ret;
59}
60
61
62
64
65
66template<unsigned Dim>
67inline unsigned
69{
70 unsigned s = p[0].length();
71 for (unsigned int d=1; d<Dim; ++d)
72 s *= p[d].length();
73 return s;
74}
75
76//----------------------------------------------------------------------
77
78template <unsigned Dim>
79inline bool
82 bool touch = true;
83 for (unsigned int d=0; (d<Dim)&&touch ; ++d)
84 touch = touch && p[d].touches(a.p[d]);
85 return touch;
88//----------------------------------------------------------------------
89
90template <unsigned Dim>
91inline bool
93{
94 bool cont = true;
95 for (unsigned int d=0; (d<Dim)&&cont ; ++d)
96 cont = cont && p[d].contains(a.p[d]);
97 return cont;
98}
99
100//----------------------------------------------------------------------
101
102template <unsigned Dim>
103inline bool
105{
106 bool cont = true;
107 for (unsigned int d=0; (d<Dim)&&cont ; ++d)
108 cont = cont && p[d].containsAllPoints(a.p[d]);
109 return cont;
112//----------------------------------------------------------------------
113
114template<unsigned Dim>
115inline bool
117{
118 bool r = false;
119 for (unsigned d=0; d<Dim; ++d)
120 r = r || p[d].empty();
121 return r;
122}
123
124//----------------------------------------------------------------------
125
126template<unsigned Dim>
127inline bool
129 unsigned d, double a) const
130{
131 if ( &l != this )
132 l = *this;
133 if ( &r != this )
134 r = *this;
135 return p[d].split(l[d],r[d],a);
136}
137
138template<unsigned Dim>
139inline bool
141{
142 if ( &l != this )
143 l = *this;
144 if ( &r != this )
145 r = *this;
146 return p[d].split(l[d],r[d]);
147}
148
149//----------------------------------------------------------------------
150
151template<unsigned Dim>
152inline bool
154{
155 unsigned int max_dim = 0;
156 unsigned int max_length = 0;
157 for (unsigned int d=0; d<Dim; ++d)
158 if ( p[d].length() > max_length ) {
159 max_dim = d;
160 max_length = p[d].length();
161 }
162 return split(l,r,max_dim);
163}
164
166
167template<unsigned Dim>
168inline
170{
171 PInsist(Dim==1, "Number of arguments does not match NDIndex dimension!!");
172 p[0] = i0;
173}
174
175template<unsigned Dim>
176inline
178{
179 PInsist(Dim==2, "Number of arguments does not match NDIndex dimension!!");
180 p[0] = i0;
181 p[1] = i1;
182}
183
184template<unsigned Dim>
185inline
186NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1,const Index& i2)
187{
188 PInsist(Dim==3, "Number of arguments does not match NDIndex dimension!!");
189 p[0] = i0;
190 p[1] = i1;
191 p[2] = i2;
192}
193
194template<unsigned Dim>
195inline
196NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1,const Index& i2,
197 const Index& i3)
198{
199 PInsist(Dim==4, "Number of arguments does not match NDIndex dimension!!");
200 p[0] = i0;
201 p[1] = i1;
202 p[2] = i2;
203 p[3] = i3;
204}
205
206template<unsigned Dim>
207inline
208NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1,const Index& i2,
209 const Index& i3,const Index& i4)
210{
211 PInsist(Dim==5, "Number of arguments does not match NDIndex dimension!!");
212 p[0] = i0;
213 p[1] = i1;
214 p[2] = i2;
215 p[3] = i3;
216 p[4] = i4;
217}
218
219template<unsigned Dim>
220inline
221NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1,const Index& i2,
222 const Index& i3,const Index& i4,const Index& i5)
223{
224 PInsist(Dim==6, "Number of arguments does not match NDIndex dimension!!");
225 p[0] = i0;
226 p[1] = i1;
227 p[2] = i2;
228 p[3] = i3;
229 p[4] = i4;
230 p[5] = i5;
231}
232
233template<> inline
235{
236 p[0] = ndi[0];
237 p[1] = i;
238}
239template<> inline
240NDIndex<3>::NDIndex(const NDIndex<2>& ndi, const Index& i)
241{
242 p[0] = ndi[0];
243 p[1] = ndi[1];
244 p[2] = i;
245}
246template<> inline
248{
249 p[0] = ndi[0];
250 p[1] = ndi[1];
251 p[2] = ndi[2];
252 p[3] = i;
253}
254template<> inline
256{
257 p[0] = ndi[0];
258 p[1] = ndi[1];
259 p[2] = ndi[2];
260 p[3] = ndi[3];
261 p[4] = i;
262}
263template<> inline
265{
266 p[0] = ndi[0];
267 p[1] = ndi[1];
268 p[2] = ndi[2];
269 p[3] = ndi[3];
270 p[4] = ndi[4];
271 p[5] = i;
272}
273
275//
276// Attempts to determine whether i2 represents a stencil relative
277// to i1. For each index in i1, it checks through all of the indices
278// in i2 to see if the id's match. If a match is obtained, but the
279// indexes are not equivalent, this must be a stencil. If i1's index
280// is not found in i2, we make the safe choice of returning
281// true (is-a-stencil). We only conclude this is not a stencil if
282// all indices in i1 appear in i2 and are equivalent.
283//
285
286template<unsigned D1, unsigned D2>
287inline bool isStencil(const NDIndex<D1> &i1, const NDIndex<D2> &i2)
288{
289 for (unsigned i = 0; i < D1; i++)
290 {
291 bool found = false;
292 for (unsigned j = 0; j < D2; j++)
293 {
294 if (i1[i].id() == i2[j].id())
295 {
296 found = true;
297 if (!(i1[i] == i2[j]))
298 return true;
299 }
300 }
301 if (!found)
302 return true;
303 }
304
305 return false;
306}
307
308#endif // NDINDEX_INLINES_H
309
310/***************************************************************************
311 * $RCSfile: NDIndexInlines.h,v $ $Author: adelmann $
312 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:27 $
313 * IPPL_VERSION_ID: $Id: NDIndexInlines.h,v 1.1.1.1 2003/01/23 07:40:27 adelmann Exp $
314 ***************************************************************************/
const unsigned Dim
NDIndex< D1 > plugBase(const NDIndex< D1 > &i1, const NDIndex< D2 > &i2)
bool isStencil(const NDIndex< D1 > &i1, const NDIndex< D2 > &i2)
std::complex< double > a
#define PInsist(c, m)
Definition: PAssert.h:120
unsigned size() const
NDIndex()
Definition: NDIndex.h:78
bool touches(const NDIndex< Dim > &) const
NDIndex< Dim > plugBase(const NDIndex< D > &i) const
Definition: NDIndex.h:114
bool contains(const NDIndex< Dim > &a) const
Index p[Dim==0?1:Dim]
Definition: NDIndex.h:145
NDIndex< Dim > intersect(const NDIndex< Dim > &) const
bool split(NDIndex< Dim > &l, NDIndex< Dim > &r, unsigned d, double a) const
bool containsAllPoints(const NDIndex< Dim > &b) const
bool empty() const
Definition: Index.h:237