Chombo + EB + MF  3.2
BaseFabImplem.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #include <utility>
12 #ifndef _BASEFABIMPLEM_H_
13 #define _BASEFABIMPLEM_H_
14 
15 #include "BaseFabMacros.H"
16 #include "CH_Timer.H"
17 #include "SliceSpec.H"
18 #include "MayDay.H"
19 #include "parstream.H"
20 #include "BoxIterator.H"
21 #include "NamespaceHeader.H"
22 
23 //
24 // BaseFab<Real> specializations
25 //
26 
27 template < > void BaseFab<Real>::define();
28 
29 template < > void BaseFab<Real>::undefine();
30 
31 template < > void BaseFab<Real>::setVal (Real val);
32 
33 template < > void BaseFab<int>::define();
34 
35 template < > void BaseFab<int>::undefine();
36 
37 template < > int BaseFab<int>::test();
38 
39 template <class T> int BaseFab<T>::testBoxAndComp()
40 {
41  MayDay::Warning("pretty minimal test");
43  BaseFab<T> blerg;
44  blerg.define(b, 1);
45 
46  if (blerg.nComp() != 1)
47  {
48  pout() << "ncomp busted" << endl;
49  return -2;
50  }
51  if (blerg.box() != b)
52  {
53  pout() << "box return busted" << endl;
54  return -2;
55  }
56  for (int idir = 0; idir < SpaceDim; idir++)
57  {
58  if (blerg.size()[idir] != 2)
59  {
60  pout() << "size busted" <<endl;
61  return -3;
62  }
63  }
64 
65  if (blerg.smallEnd() != IntVect::Zero)
66  {
67  pout() << "smallend busted" <<endl;
68  return -4;
69  }
70  if (blerg.bigEnd() != IntVect::Unit)
71  {
72  pout() << "bigend busted" <<endl;
73  return -5;
74  }
75  return 0;
76 }///
77 template <class T> int BaseFab<T>::test()
78 {
79  int retval = testBoxAndComp();
80  return retval;
81 }
82 
83 //
84 // Implementation.=====================================
85 //
86 template <class T> inline BaseFab<T>::BaseFab(BaseFab<T>&& a_in) noexcept
87  :m_domain(std::move(a_in.m_domain)),
88  m_nvar(a_in.m_nvar),
89  m_numpts(a_in.m_numpts),
90  m_truesize(a_in.m_truesize),
91  m_dptr(a_in.m_dptr),
92  m_aliased(a_in.m_aliased)
93 #if CXXSTD>=14
94  ,
95  m_mdarray(a_in.m_mdarray)
96 #endif
97 {
98  a_in.m_aliased=true;
99 }
100 
101 template <class T> inline BaseFab<T>& BaseFab<T>::operator=(BaseFab<T>&& a_in) noexcept
102 {
103  m_domain = std::move(a_in.m_domain);
104  m_nvar=a_in.m_nvar;
105  m_numpts=a_in.m_numpts;
106  std::swap(m_truesize,a_in.m_truesize);
107  std::swap(m_dptr,a_in.m_dptr);
108  std::swap(m_aliased,a_in.m_aliased);
109 #if CXXSTD>=14
110  m_mdarray=a_in.m_mdarray;
111 #endif
112  return *this;
113 }
114 
115 template <class T> inline BaseFab<T>::BaseFab()
116  :
117  m_domain(Box()),
118  m_nvar(0),
119  m_numpts(0),
120  m_truesize(0),
121  m_dptr(nullptr),
122  m_aliased(false)
123 {
124 }
125 
126 template <class T> inline BaseFab<T>::BaseFab(const Box& a_bx,
127  int a_n,
128  T* a_alias)
129  :
130  m_domain(a_bx),
131  m_nvar(a_n),
132  m_numpts(a_bx.numPts()),
133  m_truesize(a_bx.numPts() * a_n),
134  m_dptr(nullptr),
135  m_aliased(false)
136 {
137  if (a_alias != NULL)
138  {
139  m_dptr = a_alias;
140  m_aliased = true;
141  }
142  else
143  {
144  define();
145  }
146 #if CXXSTD>=14
147  T* mddata = isUsable() ? m_dptr + m_domain.index(IntVect::Zero) : nullptr;
148  m_mdarray.define(mddata, m_domain.size());
149 #endif
150 }
151 
152 template <class T> inline BaseFab<T>::BaseFab(const Interval& a_comps,
153  BaseFab<T>& a_original)
154  :
155  m_domain(a_original.m_domain),
156  m_nvar(a_comps.size()),
157  m_numpts(a_original.m_numpts),
158  m_truesize(a_original.m_numpts * m_nvar),
159  m_dptr(a_original.dataPtr(a_comps.begin())),
160  m_aliased(true)
161 {
162 #if CXXSTD>=14
163  T* mddata = isUsable() ? m_dptr + m_domain.index(IntVect::Zero) : nullptr;
164  m_mdarray.define(mddata, m_domain.size());
165 #endif
166 }
167 
168 template <class T> inline BaseFab<T>::~BaseFab()
169 {
170  undefine();
171 }
172 
173 template <class T> void BaseFab<T>::resize(const Box& a_b,
174  int a_n,
175  T* a_alias)
176 {
177  // m_nvar = a_n;
178  // m_domain = a_b;
179  // m_numpts = m_domain.numPts();
180  //
181  // if (m_dptr == 0)
182  // {
183  // define();
184  // }
185  // else if (m_nvar*m_numpts > m_truesize)
186  // {
187  // undefine();
188  // define();
189  // }
190 
191  undefine();
192 
193  m_nvar = a_n;
194  m_domain = a_b;
195  m_numpts = m_domain.numPts();
196  m_truesize = m_numpts * m_nvar;
197 
198  if (a_alias != NULL)
199  {
200  m_dptr = a_alias;
201  m_aliased = true;
202  }
203  else
204  {
205  m_aliased = false;
206  define();
207  }
208 #if CXXSTD>=14
209  T* mddata = isUsable() ? m_dptr + m_domain.index(IntVect::Zero) : nullptr;
210  m_mdarray.define(mddata, m_domain.size());
211 #endif
212 }
213 
214 template <class T> inline void BaseFab<T>::define(const Interval& a_comps,
215  BaseFab<T>& a_original)
216 {
217  undefine();
218 
219  m_domain = a_original.m_domain;
220  m_numpts = a_original.m_numpts;
221  m_truesize = a_original.m_numpts*a_comps.size();
222  m_nvar = a_comps.size();
223  m_dptr = a_original.dataPtr(a_comps.begin());
224  m_aliased = true;
225 #if CXXSTD>=14
226  T* mddata = isUsable() ? m_dptr + m_domain.index(IntVect::Zero) : nullptr;
227  m_mdarray.define(mddata, m_domain.size());
228 #endif
229  // resize(a_original.m_domain, a_comps.size(),
230  // a_original.dataPtr(a_comps.begin()));
231 }
232 
233 #ifdef USE_PROTO
234 template < class T>
235 template<unsigned int C>
236 void BaseFab<T>::define(Proto::BoxData<T,C,1,1>& a_original)
237 {
238  undefine();
239  m_domain = getBox(a_original.box());
240  m_numpts = a_original.box().size();
241  m_truesize = a_original.size();
242  m_nvar = C;
243  m_dptr = &a_original(a_original.box().low());
244  m_aliased = true;
245 #if CXXSTD>=14
246  T* mddata = isUsable() ? m_dptr + m_domain.index(IntVect::Zero) : nullptr;
247  m_mdarray.define(mddata, m_domain.size());
248 #endif
249 }
250 #endif
251 
252 template <class T> inline void BaseFab<T>::clear()
253 {
254  undefine();
255 
256  m_domain = Box();
257  m_nvar = 0;
258  m_numpts = 0;
259 #if CXXSTD>=14
260  m_mdarray.clear();
261 #endif
262 }
263 
264 template <class T> inline int BaseFab<T>::nComp() const
265 {
266  return m_nvar;
267 }
268 
269 template <class T> Arena* BaseFab<T>::s_Arena = NULL;
270 
271 template <class T> inline const Box& BaseFab<T>::box() const
272 {
273  return m_domain;
274 }
275 
276 template <class T> inline IntVect BaseFab<T>::size() const
277 {
278  return m_domain.size();
279 }
280 
281 template <class T> inline const IntVect& BaseFab<T>::smallEnd() const
282 {
283  return m_domain.smallEnd();
284 }
285 
286 template <class T> inline const IntVect& BaseFab<T>::bigEnd() const
287 {
288  return m_domain.bigEnd();
289 }
290 
291 template <class T> inline T& BaseFab<T>::operator () (const IntVect& a_p,
292  int a_n)
293 {
294  CH_assert(a_n >= 0);
295  CH_assert(a_n < m_nvar);
296  CH_assert(m_dptr != nullptr);
297  CH_assert(m_domain.contains(a_p));
298 
299  long int ind1 = m_domain.index(a_p);
300  long int ind2 = a_n * m_numpts;
301  long int ind = ind1 + ind2;
302 
303  return m_dptr[ind];
304 }
305 
306 template <class T> inline T& BaseFab<T>::operator () (const IntVect& a_p)
307 {
308  CH_assert(m_dptr != nullptr);
309  CH_assert(m_domain.contains(a_p));
310 
311  return m_dptr[m_domain.index(a_p)];
312 }
313 
314 template <class T> inline const T& BaseFab<T>::operator () (const IntVect& a_p,
315  int a_n) const
316 {
317  CH_assert(a_n >= 0);
318  CH_assert(a_n < m_nvar);
319  CH_assert(m_dptr != nullptr);
320  CH_assert(m_domain.contains(a_p));
321 
322  return m_dptr[m_domain.index(a_p) + a_n * m_numpts];
323 }
324 
325 template <class T> inline const T& BaseFab<T>::operator () (const IntVect& a_p) const
326 {
327  CH_assert(m_dptr != nullptr);
328  CH_assert(m_domain.contains(a_p));
329 
330  return m_dptr[m_domain.index(a_p)];
331 }
332 
333 template <class T> inline void BaseFab<T>::getVal(T* a_data,
334  const IntVect& a_pos,
335  int a_n,
336  int a_numcomp) const
337 {
338  const int loc = m_domain.index(a_pos);
339  const long size = m_domain.numPts();
340 
341  CH_assert(m_dptr != nullptr);
342  CH_assert(a_n >= 0 && a_n + a_numcomp <= m_nvar);
343 
344  for (int k = 0; k < a_numcomp; k++)
345  {
346  a_data[k] = m_dptr[loc+(a_n+k)*size];
347  }
348 }
349 
350 template <class T> inline void BaseFab<T>::getVal(T* a_data,
351  const IntVect& a_pos) const
352 {
353  getVal(a_data,a_pos,0,m_nvar);
354 }
355 
356 template <class T> inline const int* BaseFab<T>::loVect() const
357 {
358  return m_domain.loVect();
359 }
360 
361 template <class T> inline const int* BaseFab<T>::hiVect() const
362 {
363  return m_domain.hiVect();
364 }
365 
366 template <class T> inline const int* BaseFab<T>::nCompPtr() const
367 {
368  CH_assert(m_dptr != nullptr);
369 
370  return &m_nvar;
371 }
372 
373 template <class T> inline T* BaseFab<T>::dataPtr(int a_n)
374 {
375  CH_assert(m_dptr != nullptr);
376  CH_assert((a_n >= 0) && (a_n < m_nvar));
377 
378  return &m_dptr[a_n * m_numpts];
379 }
380 
381 template <class T> inline const T* BaseFab<T>::dataPtr(int a_n) const
382 {
383  CH_assert(m_dptr != nullptr);
384  CH_assert((a_n >= 0) && (a_n < m_nvar));
385 
386  return &m_dptr[a_n * m_numpts];
387 }
388 
389 template <class T> inline bool BaseFab<T>::contains(const BaseFab<T>& a_fab) const
390 {
391  return box().contains(a_fab.box()) && m_nvar <= a_fab.m_nvar;
392 }
393 
394 template <class T> inline bool BaseFab<T>::contains (const Box& a_bx) const
395 {
396  return box().contains(a_bx);
397 }
398 
399 template <class T> inline void BaseFab<T>::setVal(T a_x,
400  const Box& a_bx,
401  int a_nstart,
402  int a_numcomp)
403 {
404  performSetVal(a_x,a_bx,a_nstart,a_numcomp);
405 }
406 
407 template <class T> inline void BaseFab<T>::setVal(T a_x,
408  const Box& a_bx,
409  int a_n)
410 {
411  performSetVal(a_x,a_bx,a_n,1);
412 }
413 
414 template <class T> inline void BaseFab<T>::setVal(T a_x,
415  int a_n)
416 {
417  performSetVal(a_x,m_domain,a_n,1);
418 }
419 
420 template <class T> inline void BaseFab<T>::setVal(T a_x)
421 {
422  performSetVal(a_x,box(),0,m_nvar);
423 }
424 
425 template <class T>
427  const Box& a_srcbox,
428  int a_srccomp,
429  const Box& a_destbox,
430  int a_destcomp,
431  int a_numcomp)
432 {
433  CH_assert(a_srcbox.sameSize(a_destbox));
434  CH_assert(a_src.box().contains(a_srcbox));
435  CH_assert(m_domain.contains(a_destbox));
436  CH_assert(a_srccomp >= 0 && a_srccomp+a_numcomp <= a_src.nComp());
437  CH_assert(a_destcomp >= 0 && a_destcomp+a_numcomp <= m_nvar);
438 
439  performCopy(a_src,a_srcbox,a_srccomp,a_destbox,a_destcomp,a_numcomp);
440 
441  return *this;
442 }
443 
444 template <class T>
446  int a_srccomp,
447  int a_destcomp,
448  int a_numcomp)
449 {
450  CH_assert(a_srccomp >= 0 && a_srccomp + a_numcomp <= a_src.m_nvar);
451  CH_assert(a_destcomp >= 0 && a_destcomp + a_numcomp <= m_nvar);
452 
453  Box overlap(m_domain);
454  overlap &= a_src.m_domain;
455 
456  if (!overlap.isEmpty())
457  {
458  performCopy(a_src,overlap,a_srccomp,overlap,a_destcomp,a_numcomp);
459  }
460 
461  return *this;
462 }
463 
464 template <class T>
466  const Box& a_destbox)
467 {
468  CH_assert(m_nvar <= a_src.m_nvar);
469  CH_assert(m_domain.contains(a_destbox));
470 
471  Box overlap(a_destbox);
472  overlap &= a_src.m_domain;
473 
474  if (!overlap.isEmpty())
475  {
476  performCopy(a_src,overlap,0,overlap,0,m_nvar);
477  }
478 
479  return *this;
480 }
481 
482 template <class T>
484 {
485  CH_assert(m_nvar <= a_src.m_nvar);
486  CH_assert(m_domain.sameType(a_src.m_domain));
487 
488  Box overlap(m_domain);
489  overlap &= a_src.m_domain;
490 
491  if (!overlap.isEmpty())
492  {
493  performCopy(a_src,overlap,0,overlap,0,m_nvar);
494  }
495 
496  return *this;
497 }
498 
499 template <class T> inline void BaseFab<T>::copy(const Box& a_RegionFrom,
500  const Interval& a_Cdest,
501  const Box& a_RegionTo,
502  const BaseFab<T>& a_src,
503  const Interval& a_Csrc)
504 {
505  if ((this == &a_src) && (a_RegionFrom == a_RegionTo) && (a_Cdest == a_Csrc) )
506  {
507  return;
508  }
509 
510  CH_assert(a_Cdest.size() == a_Csrc.size());
511 
512  copy(a_src, a_RegionFrom, a_Csrc.begin(), a_RegionTo,
513  a_Cdest.begin(), a_Cdest.size());
514 }
515 
516 template <class T> inline BaseFab<T>& BaseFab<T>::shift(const IntVect& a_v)
517 {
518  CH_assert(isUsable());
519  m_domain += a_v;
520 #if CXXSTD>=14
521  m_mdarray.resetData(m_dptr + m_domain.index(IntVect::Zero));
522 #endif
523 
524  return *this;
525 }
526 
527 template <class T> inline BaseFab<T>& BaseFab<T>::shift(int a_idir,
528  int a_ncells)
529 {
530  CH_assert(isUsable());
531  m_domain.shift(a_idir,a_ncells);
532 #if CXXSTD>=14
533  m_mdarray.resetData(m_dptr + m_domain.index(IntVect::Zero));
534 #endif
535 
536  return *this;
537 }
538 
539 template <class T> inline BaseFab<T> & BaseFab<T>::shiftHalf(int a_idir,
540  int a_numHalfs)
541 {
542  CH_assert(isUsable());
543  m_domain.shiftHalf(a_idir,a_numHalfs);
544 #if CXXSTD>=14
545  m_mdarray.resetData(m_dptr + m_domain.index(IntVect::Zero));
546 #endif
547 
548  return *this;
549 }
550 
551 template <class T> inline BaseFab<T> & BaseFab<T>::shiftHalf(const IntVect& a_v)
552 {
553  CH_assert(isUsable());
554  m_domain.shiftHalf(a_v);
555 #if CXXSTD>=14
556  m_mdarray.resetData(m_dptr + m_domain.index(IntVect::Zero));
557 #endif
558 
559  return *this;
560 }
561 
562 template <class T> inline size_t BaseFab<T>::size(const Box& a_box,
563  const Interval& a_comps) const
564 {
565  return a_box.numPts() * (sizeof(T) * a_comps.size());
566 }
567 
568 template <class T> inline void BaseFab<T>::linearOut(void* a_buf,
569  const Box& a_R,
570  const Interval& a_comps) const
571 {
572  linearOut2(a_buf, a_R, a_comps);
573 }
574 template <class T> inline void* BaseFab<T>::linearOut2(void* a_buf,
575  const Box& a_R,
576  const Interval& a_comps) const
577 {
578  T* buffer = (T*)a_buf;
579 
580  ForAllThisCBNN(T,a_R,a_comps.begin(),a_comps.size())
581  {
582  *buffer = thisR;
583  ++buffer;
584  } EndFor;
585  return (void*)buffer;
586 }
587 
588 template <class T> inline void BaseFab<T>::linearIn(void* a_buf,
589  const Box& a_R,
590  const Interval& a_comps)
591 {
592  // pout() << "basefab::linearin box = " << a_R << "comps = (" << a_comps.begin() << "," << a_comps.end() << ")" << endl;
593  linearIn2(a_buf, a_R, a_comps);
594 }
595 
596 template <class T> inline void* BaseFab<T>::linearIn2(void* a_buf,
597  const Box& a_R,
598  const Interval& a_comps)
599 {
600  T* buffer = (T*)a_buf;
601 
602  ForAllThisBNN(T,a_R,a_comps.begin(),a_comps.size())
603  {
604  thisR = *buffer;
605  ++buffer;
606  } EndFor;
607 
608  return (void*) buffer;
609 }
610 
611 // ---------------------------------------------------------
612 // this is for broadcast & gather; the Box is in the msg
613 template <class T> inline void BaseFab<T>::linearOut(void* a_outBuf) const
614 {
615  char * bufptr = static_cast<char*>(a_outBuf) ;
616 
617  CH_XD::linearOut( bufptr ,m_domain );
618  bufptr += CH_XD::linearSize(m_domain);
619 
620  CH_XD::linearOut( bufptr ,m_nvar );
621  bufptr += sizeof(int) ;
622 
623  linearOut( bufptr ,m_domain ,interval() );
624 }
625 
626 // ---------------------------------------------------------
627 // this is for broadcast & gather; the Box is in the msg
628 template <class T> inline void BaseFab<T>::linearIn(const void* const a_buf)
629 {
630  // first get the box, then the number of components, then the data
631  char * bufptr = static_cast<char*>(const_cast<void*>(a_buf)) ;
632 
633  CH_XD::linearIn( m_domain ,bufptr );
634  bufptr += CH_XD::linearSize( m_domain );
635 
636  int ncomps;
637  CH_XD::linearIn( ncomps ,bufptr );
638  bufptr += sizeof( ncomps );
639 
640  resize(m_domain, ncomps);
641 
642  // Tried calling:
643  // linearIn( bufptr, m_domain, Interval( 0,ncomps-1 ) );
644  // but it crashed with OPT setting.
645  // So we use BoxIterator instead.
646  T* buffer = (T*)bufptr;
647  for (int icomp = 0; icomp < ncomps; icomp++)
648  {
649  for (BoxIterator bit(m_domain); bit.ok(); ++bit)
650  {
651  IntVect iv = bit();
652  (*this)(iv, icomp) = *buffer;
653  ++buffer;
654  }
655  }
656 
657  // ForAllThisBNN(T,m_domain,0,ncomps)
658  // {
659  // thisR = *buffer;
660  // ++buffer;
661  // } EndFor;
662  // return (void*) buffer;
663 }
664 
665 // ---------------------------------------------------------
666 // this is for broadcast & gather; the Box is in the msg
667 template <class T> inline int BaseFab<T>::linearSize( ) const
668 { // the linearization contains the Box, #components, and data
669  return CH_XD::linearSize(m_domain) + sizeof(int) + size(m_domain, interval());
670 }
671 
672 template <class T> inline void BaseFab<T>::define()
673 {
674  CH_assert(m_nvar > 0);
675  CH_assert(m_dptr == nullptr);
676  // CH_assert(m_numpts > 0); // OK if box is empty
677  CH_assert(!m_aliased);
678  //CH_assert(!(The_FAB_Arena == 0));// not a sufficient test !!!
679 
680 #ifdef CH_USE_MEMORY_TRACKING
681  if (s_Arena == NULL)
682  {
683  s_Arena = new BArena(name().c_str());
684  }
685 #else
686  if (s_Arena == NULL)
687  {
688  s_Arena = new BArena("");
689  }
690 #endif
691 
692  if (s_Arena == NULL)
693  {
694  MayDay::Error("malloc in basefab failed");
695  }
696 
697  m_truesize = m_nvar * m_numpts;
698  if (m_truesize > 0)
699  {
700  m_dptr = static_cast<T*>(s_Arena->alloc(m_truesize * sizeof(T)));
701 
702 #ifdef CH_USE_MEMORY_TRACKING
703  ch_memcount+=m_truesize * sizeof(T) + sizeof(BaseFab<T>);
704  s_Arena->bytes += m_truesize * sizeof(T) + sizeof(BaseFab<T>);
705  CH_assert(s_Arena->bytes > 0);
706  if (s_Arena->bytes > s_Arena->peak)
707  {
708  s_Arena->peak = s_Arena->bytes;
709  }
710 #endif
711  }
712  else
713  { // m_truesize == 0: allocating no space
714  m_dptr = nullptr;
715  }
716 
717  //
718  // Now call T::T() on the raw memo'ry so we have valid Ts.
719  //
720  T* ptr = m_dptr;
721 
722  for (long int i = 0; i < m_truesize; i++, ptr++)
723  {
724  new (ptr) T;
725  }
726 }
727 
728 template <class T> inline void BaseFab<T>::undefine()
729 {
730  //CH_assert(!(The_FAB_Arena == 0));
731  //
732  // Call T::~T() on the to-be-destroyed memory.
733  //
734  if (m_aliased)
735  {
736  m_dptr = nullptr;
737  return;
738  }
739 
740  if (m_dptr == nullptr)
741  {
742  return;
743  }
744 
745  T* ptr = m_dptr;
746 
747  for (long int i = 0; i < m_truesize; i++, ptr++)
748  {
749  ptr->~T();
750  }
751 
752  s_Arena->free(m_dptr);
753 
754 #ifdef CH_USE_MEMORY_TRACKING
755  ch_memcount -= m_truesize * sizeof(T) + sizeof(BaseFab<T>);
756  s_Arena->bytes -= m_truesize * sizeof(T) + sizeof(BaseFab<T>);
757  CH_assert(s_Arena->bytes >= 0);
758 #endif
759 
760  m_dptr = nullptr;
761 }
762 
763 template <class T> inline std::string BaseFab<T>::name()
764 {
765  std::string rtn = (typeid(T)).name();
766 
767  return rtn;
768 }
769 
770 template <class T>
771 inline void BaseFab<T>::performCopy(const BaseFab<T>& a_src,
772  const Box& a_srcbox,
773  int a_srccomp,
774  const Box& a_destbox,
775  int a_destcomp,
776  int a_numcomp)
777 {
778  CH_assert(a_src.box().contains(a_srcbox));
779  CH_assert(box().contains(a_destbox));
780  CH_assert(a_destbox.sameSize(a_srcbox));
781  CH_assert(a_srccomp >= 0 && a_srccomp + a_numcomp <= a_src.nComp());
782  CH_assert(a_destcomp >= 0 && a_destcomp + a_numcomp <= nComp());
783  // CH_TIME("BaseFab::performCopy")
784  ForAllThisBNNXCBN(T, a_destbox, a_destcomp, a_numcomp, a_src, a_srcbox, a_srccomp)
785  {
786  thisR = a_srcR;
787  } EndForTX
788 }
789 
790 template <class T> inline void BaseFab<T>::performSetVal(T a_x,
791  const Box& a_bx,
792  int a_nstart,
793  int a_numcomp)
794 {
795  CH_assert(m_domain.contains(a_bx));
796  CH_assert(a_nstart >= 0 && a_nstart + a_numcomp <= m_nvar);
797 
798  if (a_bx == m_domain)
799  {
800  T* data = &m_dptr[a_nstart * m_numpts];
801 
802  for (long i = 0, N = a_numcomp * m_numpts; i < N; i++)
803  {
804  *data++ = a_x;
805  }
806  }
807  else
808  {
809  ForAllThisBNN(T,a_bx,a_nstart,a_numcomp)
810  {
811  thisR = a_x;
812  } EndFor
813  }
814 }
815 
816 template <class T>
818 {
819  return m_aliased;
820 }
821 
822 template <class T>
824 {
825  return (m_dptr != nullptr && m_truesize > 0);
826 }
827 
828 template <class T> void
830  const SliceSpec& a_sliceSpec ) const
831 {
832  bool outofbounds;
833  Box degenerateBox;
834  this->box().degenerate( degenerateBox, a_sliceSpec, &outofbounds );
835  if ( outofbounds )
836  {
837  MayDay::Error( "Tried to slice out-of-bounds." );
838  }
839  a_slice.define( degenerateBox, this->nComp() );
840  a_slice.copy( *this, degenerateBox );
841 }
842 
843 #include "NamespaceFooter.H"
844 
845 #endif
int linearSize(void) const
Definition: BaseFabImplem.H:667
std::ostream & pout()
Use this in place of std::cout for program output.
bool ok()
Definition: BoxIterator.H:281
void clear()
Definition: BaseFabImplem.H:252
bool isUsable() const
Definition: BaseFabImplem.H:823
const int * loVect() const
{ Fortran interface functions}
Definition: BaseFabImplem.H:356
#define CH_assert(cond)
Definition: CHArray.H:37
void setVal(T a_x, const Box &a_bx, int a_nstart, int a_numcomp)
{ data modification functions}
Definition: BaseFabImplem.H:399
bool contains(const BaseFab< T > &a_fab) const
{ comparison functions}
Definition: BaseFabImplem.H:389
virtual ~BaseFab()
Definition: BaseFabImplem.H:168
BaseFab< T > & shift(const IntVect &a_v)
{ domain modification functions}
Definition: BaseFabImplem.H:516
virtual void linearIn(void *a_buf, const Box &a_R, const Interval &a_comps)
Definition: BaseFabImplem.H:588
Definition: SliceSpec.H:41
static std::string name()
Definition: BaseFabImplem.H:763
Box m_domain
Definition: BaseFab.H:632
iterates through the IntVects of a Box
Definition: BoxIterator.H:37
int m_nvar
Definition: BaseFab.H:633
int size() const
Definition: Interval.H:75
virtual void linearOut(void *a_buf, const Box &a_R, const Interval &a_comps) const
Definition: BaseFabImplem.H:568
A Concrete Class for Dynamic Memory Management.
Definition: Arena.H:124
BaseFab< T > & operator=(BaseFab< T > &&) noexcept
move assignment
Definition: BaseFabImplem.H:101
const int SpaceDim
Definition: SPACE.H:38
BaseFab()
Definition: BaseFabImplem.H:115
const IntVect & smallEnd() const
Definition: BaseFabImplem.H:281
int nComp() const
{ accessors}
Definition: BaseFabImplem.H:264
Definition: EBInterface.H:45
void const char const int const int const int const Real const Real const int const Real const int const Real Real * C
Definition: Lapack.H:83
BaseFab< T > & shiftHalf(int a_dir, int a_numHalfs)
Definition: BaseFabImplem.H:539
bool isAliased() const
Definition: BaseFabImplem.H:817
Structure for passing component ranges in code.
Definition: Interval.H:23
static const IntVect Unit
Definition: IntVect.H:663
const char * name(const FArrayBox &a_dummySpecializationArg)
Definition: CH_HDF5.H:864
void linearOut(void *const a_outBuf, const T &inputT)
Definition: SPMDI.H:33
virtual void define(const Box &a_box, int a_comps, T *a_alias=NULL)
Definition: BaseFab.H:205
A Virtual Base Class for Dynamic Memory Managemen.
Definition: Arena.H:40
double Real
Definition: REAL.H:33
void define()
Definition: BaseFabImplem.H:672
virtual void performCopy(const BaseFab< T > &a_src, const Box &a_srcbox, int a_srccomp, const Box &a_destbox, int a_destcomp, int a_numcomp)
Definition: BaseFabImplem.H:771
BaseFab< T > & copy(const BaseFab< T > &a_src, const Box &a_srcbox, int a_srccomp, const Box &a_destbox, int a_destcomp, int a_numcomp)
Definition: BaseFabImplem.H:426
int linearSize(const T &inputT)
Definition: SPMDI.H:21
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.
int begin() const
Definition: Interval.H:99
bool isEmpty() const
{ Comparison Functions}
Definition: Box.H:1862
const int * hiVect() const
Definition: BaseFabImplem.H:361
Definition: BaseFab.H:81
T * dataPtr(int a_n=0)
Definition: BaseFabImplem.H:373
static const IntVect Zero
Definition: IntVect.H:658
virtual void * linearOut2(void *a_buf, const Box &a_R, const Interval &a_comps) const
Same as linearOut, but returns the current location in the buffer.
Definition: BaseFabImplem.H:574
static void Warning(const char *const a_msg=m_nullString)
Print out message to cerr and continue.
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
bool m_aliased
Definition: BaseFab.H:638
size_t numPts() const
bool sameSize(const Box &b) const
Definition: Box.H:1912
bool contains(const IntVect &p) const
Definition: Box.H:1887
const int * nCompPtr() const
Definition: BaseFabImplem.H:366
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
void getVal(T *a_data, const IntVect &a_pos, int a_N, int a_numcomp) const
Definition: BaseFabImplem.H:333
T & operator()(const IntVect &a_p, int a_N)
Definition: BaseFabImplem.H:291
void const char const int const int * N
Definition: Lapack.H:83
void resize(const Box &a_b, int a_n=1, T *a_alias=NULL)
Definition: BaseFabImplem.H:173
void undefine()
Definition: BaseFabImplem.H:728
static int testBoxAndComp()
regression test
Definition: BaseFabImplem.H:39
void performSetVal(T a_x, const Box &a_bx, int a_nstart, int a_numcomp)
Definition: BaseFabImplem.H:790
static int test()
regression test
Definition: BaseFabImplem.H:77
void linearIn(T &a_outputT, const void *const inBuf)
Definition: SPMDI.H:27
virtual void * linearIn2(void *a_buf, const Box &a_R, const Interval &a_comps)
same as linearIn, but returns the current location in the buffer
Definition: BaseFabImplem.H:596
IntVect size() const
Definition: BaseFabImplem.H:276
void degenerate(BaseFab< T > &a_slice, const SliceSpec &a_sliceSpec) const
Definition: BaseFabImplem.H:829
long m_numpts
Definition: BaseFab.H:634
const IntVect & bigEnd() const
Definition: BaseFabImplem.H:286
const Box & box() const
Definition: BaseFabImplem.H:271