Chombo + EB  3.0
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  }
105  }
106 }
107 
108 template <class srcData_t, class dstData_t>
109 void
111 cache(const dstData_t& a_lph) const
112 {
113 // CH_assert(m_cache.size() == m_ebstencil.size());
114 
115  m_cacheDst.resize( m_ebstencil.size(), Vector<Real>(a_lph.nComp(), 0.));
116  CH_TIME("AggSten::cache");
117  Vector<const Real*> dataPtrsLph(a_lph.numDataTypes());
118  for (int ivar = 0; ivar < a_lph.nComp(); ivar++)
119  {
120  for (int ivec = 0; ivec < dataPtrsLph.size(); ivec++)
121  {
122  dataPtrsLph[ivec] = a_lph.dataPtr(ivec, ivar);
123  }
124 
125  for (int idst = 0; idst < m_ebstencil.size(); idst++)
126  {
127  const Real* lphPtr = dataPtrsLph[m_dstAccess[idst].dataID] + m_dstAccess[idst].offset;
128  m_cacheDst[idst][ivar] = *lphPtr;
129  }
130  }
131 }
132 /**************/
133 template <class srcData_t, class dstData_t>
134 void
136 uncache(dstData_t& a_lph) const
137 {
138  CH_TIME("AggSten::uncache");
139  Vector<Real*> dataPtrsLph(a_lph.numDataTypes());
140  for (int ivar = 0; ivar < a_lph.nComp(); ivar++)
141  {
142  for (int ivec = 0; ivec < dataPtrsLph.size(); ivec++)
143  {
144  dataPtrsLph[ivec] = a_lph.dataPtr(ivec, ivar);
145  }
146 
147  for (int idst = 0; idst < m_ebstencil.size(); idst++)
148  {
149  Real* lphPtr = dataPtrsLph[m_dstAccess[idst].dataID] + m_dstAccess[idst].offset;
150  *lphPtr = m_cacheDst[idst][ivar];
151  }
152  }
153 }
154 /**************/
155 
156 #endif
void uncache(dstData_t &a_phi) const
Definition: AggStencilI.H:136
A reference-counting handle class.
Definition: RefCountedPtr.H:66
virtual int size() const =0
one dimensional dynamic array
Definition: Vector.H:52
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:59
double Real
Definition: REAL.H:33
void cache(const dstData_t &a_lph) const
Definition: AggStencilI.H:111
size_t size() const
Definition: Vector.H:177
Definition: Stencils.H:25
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