Chombo + EB + MF  3.2
AggStencilI.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 #ifndef _AGGSTENCILI_H_
12 #define _AGGSTENCILI_H_
13 
14 /**************/
15 template <class srcData_t, class dstData_t>
18  const Vector<RefCountedPtr<BaseStencil> > & a_vofStencil,
19  const srcData_t & a_srcData,
20  const dstData_t & a_dstData)
21 {
22  CH_TIME("AggSten.constructor");
23  m_ebstencil.resize(a_dstVoFs.size());
24  m_dstAccess.resize(a_dstVoFs.size());
25 
26  for (int idst = 0; idst < a_dstVoFs.size(); idst++)
27  {
28  const BaseIndex& dstVoF = *a_dstVoFs[idst];
29  m_dstAccess[idst].dataID = a_dstData.dataType(dstVoF);
30  m_dstAccess[idst].offset = a_dstData.offset(dstVoF, 0);
31 
32  const BaseStencil& sten = *a_vofStencil[idst];
33  m_ebstencil[idst].resize(sten.size());
34  for (int isten = 0; isten < sten.size(); isten++)
35  {
36  const BaseIndex& stencilVoF = sten.index(isten);
37  m_ebstencil[idst][isten].first.offset = a_srcData.offset(stencilVoF, sten.variable(isten));
38  m_ebstencil[idst][isten].first.dataID = a_srcData.dataType(stencilVoF);
39  m_ebstencil[idst][isten].second = sten.weight(isten);
40  }
41  }
42  // CH_STOP(t1);
43 }
44 /**************/
45 template <class srcData_t, class dstData_t>
46 void
48 apply(dstData_t & a_lph,
49  const srcData_t & a_phi,
50  const int & a_varDest,
51  const bool & a_incrementOnly) const
52 {
53  int varSrc = 0; int nComp = 1;
54  apply(a_lph, a_phi, varSrc, a_varDest, nComp, a_incrementOnly);
55 }
56 /**************/
57 template <class srcData_t, class dstData_t>
58 void
60 apply(dstData_t & a_lph,
61  const srcData_t & a_phi,
62  const int & a_src,
63  const int & a_dst,
64  const int & a_nco,
65  const bool & a_incrementOnly) const
66 {
67 
68  CH_TIME("AggSten::apply");
69  const int numtypelph = a_lph.numDataTypes();
70  const int numtypephi = a_phi.numDataTypes();
71  Vector<Real*> dataPtrsLph(numtypelph);
72  Vector<const Real*> dataPtrsPhi(numtypephi);
73  for (int icomp = 0; icomp < a_nco; icomp++)
74  {
75  int varDst = a_dst + icomp;
76  int varSrc = a_src + icomp;
77  for (int ivec = 0; ivec < numtypelph; ivec++)
78  {
79  dataPtrsLph[ivec] = a_lph.dataPtr(ivec, varDst);
80  }
81 
82  for (int ivec = 0; ivec < numtypephi; ivec++)
83  {
84  dataPtrsPhi[ivec] = a_phi.dataPtr(ivec, varSrc);
85  }
86 
87  for (int idst = 0; idst < m_ebstencil.size(); idst++)
88  {
89  Real* lphiPtr = dataPtrsLph[m_dstAccess[idst].dataID] + m_dstAccess[idst].offset;
90  Real& lphi = *lphiPtr;
91  if (!a_incrementOnly)
92  {
93  lphi = 0.;
94  }
95  const stencil_t& ebstencil = m_ebstencil[idst];
96  for (int isten = 0; isten < ebstencil.size(); isten++)
97  {
98  const Real& weight = ebstencil[isten].second;
99  const long& offset = ebstencil[isten].first.offset;
100  const int & dataID = ebstencil[isten].first.dataID;
101  const Real& phiVal = *(dataPtrsPhi[dataID] + offset);
102  lphi += phiVal*weight;
103  }
104  ch_flops()+= ebstencil.size()*2;
105  }
106  }
107 }
108 
109 template <class srcData_t, class dstData_t>
110 void
112 cache(const dstData_t& a_lph) const
113 {
114 // CH_assert(m_cache.size() == m_ebstencil.size());
115 
116  m_cacheDst.resize( m_ebstencil.size(), Vector<Real>(a_lph.nComp(), 0.));
117  CH_TIME("AggSten::cache");
118  Vector<const Real*> dataPtrsLph(a_lph.numDataTypes());
119  for (int ivar = 0; ivar < a_lph.nComp(); ivar++)
120  {
121  for (int ivec = 0; ivec < dataPtrsLph.size(); ivec++)
122  {
123  dataPtrsLph[ivec] = a_lph.dataPtr(ivec, ivar);
124  }
125 
126  for (int idst = 0; idst < m_ebstencil.size(); idst++)
127  {
128  const Real* lphPtr = dataPtrsLph[m_dstAccess[idst].dataID] + m_dstAccess[idst].offset;
129  m_cacheDst[idst][ivar] = *lphPtr;
130  }
131  }
132 }
133 /**************/
134 template <class srcData_t, class dstData_t>
135 void
137 uncache(dstData_t& a_lph) const
138 {
139  CH_TIME("AggSten::uncache");
140  Vector<Real*> dataPtrsLph(a_lph.numDataTypes());
141  for (int ivar = 0; ivar < a_lph.nComp(); ivar++)
142  {
143  for (int ivec = 0; ivec < dataPtrsLph.size(); ivec++)
144  {
145  dataPtrsLph[ivec] = a_lph.dataPtr(ivec, ivar);
146  }
147 
148  for (int idst = 0; idst < m_ebstencil.size(); idst++)
149  {
150  Real* lphPtr = dataPtrsLph[m_dstAccess[idst].dataID] + m_dstAccess[idst].offset;
151  *lphPtr = m_cacheDst[idst][ivar];
152  }
153  }
154 }
155 /**************/
156 
157 #endif
void uncache(dstData_t &a_phi) const
Definition: AggStencilI.H:137
A reference-counting handle class.
Definition: RefCountedPtr.H:173
virtual int size() const =0
one dimensional dynamic array
Definition: Vector.H:53
virtual const BaseIndex & index(int isten) const =0
index for other indicies to inherit
Definition: BaseIndex.H:26
AggStencil()
disallowed operators. Without code because Jeff says that is better.
#define CH_TIME(name)
Definition: CH_Timer.H:82
double Real
Definition: REAL.H:33
void cache(const dstData_t &a_lph) const
Definition: AggStencilI.H:112
size_t size() const
Definition: Vector.H:192
Definition: Stencils.H:26
long long int ch_flops
Definition: CH_Counters.H:30
void apply(dstData_t &a_lph, const srcData_t &a_phi, const int &a_varDest, const bool &a_incrementOnly) const
Definition: AggStencilI.H:48
virtual const Real & weight(int isten) const =0
virtual const int & variable(int isten) const =0