Nektar++
Loading...
Searching...
No Matches
CoalescedGeomData.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: CoalescedGeomData.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Coalesced geometry data definition
32//
33///////////////////////////////////////////////////////////////////////////////
34
38
39using namespace std;
40
41namespace Nektar::Collections
42{
43
45 vector<LocalRegions::ExpansionSharedPtr> &pCollExp)
46{
47
48 if (m_oneDGeomData.count(eJac) == 0)
49 {
50 LibUtilities::PointsKeyVector ptsKeys = pCollExp[0]->GetPointsKeys();
51 int nElmts = pCollExp.size();
52 int npts = pCollExp[0]->GetTotPoints();
53
54 if (IsDeformed(pCollExp))
55 {
56 Array<OneD, NekDouble> newjac(npts * nElmts);
57
58 // copy Jacobians into a continuous list and set new chatched value
59 int cnt = 0;
60 for (int i = 0; i < nElmts; ++i)
61 {
63 pCollExp[i]->GetGeomFactors()->GetJac();
64
65 Vmath::Vcopy(npts, &jac[0], 1, &newjac[cnt], 1);
66
67 cnt += npts;
68 }
69
70 m_oneDGeomData[eJac] = newjac;
71 }
72 else
73 {
74 Array<OneD, NekDouble> newjac(nElmts);
75 // copy Jacobians into a continuous list
76 for (int i = 0; i < nElmts; ++i)
77 {
79 pCollExp[i]->GetGeomFactors()->GetJac();
80
81 newjac[i] = jac[0];
82 }
83 m_oneDGeomData[eJac] = newjac;
84 }
85 }
86
87 return m_oneDGeomData[eJac];
88}
89
90const std::shared_ptr<VecVec_t> CoalescedGeomData::GetJacInterLeave(
91 vector<LocalRegions::ExpansionSharedPtr> &pCollExp, int nElmt)
92{
93
94 if (m_oneDGeomDataInterLeave.count(eJac) == 0)
95 {
96 const Array<OneD, const NekDouble> jac = GetJac(pCollExp);
97 int jacsize = jac.size();
98 int npts = pCollExp[0]->GetTotPoints();
99
100 ASSERTL1(nElmt % vec_t::width == 0,
101 "Number of elements not divisible by vector "
102 "width, padding not yet implemented.");
103 int nBlocks = nElmt / vec_t::width;
104
105 VecVec_t newjac;
106
107 LibUtilities::PointsKeyVector ptsKeys = pCollExp[0]->GetPointsKeys();
108
109 if (IsDeformed(pCollExp))
110 {
111 newjac.resize(nBlocks * npts);
112
113 alignas(vec_t::alignment) NekDouble tmp[vec_t::width];
114
115 for (size_t block = 0; block < nBlocks; ++block)
116 {
117 size_t nblock_width = block * npts * vec_t::width;
118 for (size_t q = 0; q < npts; q++)
119 {
120 for (int j = 0; j < vec_t::width; ++j)
121 {
122 if (nblock_width + npts * j + q < jacsize)
123 {
124 tmp[j] = jac[nblock_width + npts * j + q];
125 }
126 else
127 {
128 tmp[j] = 0.0;
129 }
130 }
131
132 // Order is [block][quadpt]
133 newjac[block * npts + q].load(&tmp[0]);
134 }
135 }
136 }
137 else
138 {
139 newjac.resize(nBlocks);
140
141 alignas(vec_t::alignment) NekDouble tmp[vec_t::width];
142 for (size_t i = 0; i < nBlocks; ++i)
143 {
144 for (int j = 0; j < vec_t::width; ++j)
145 {
146 if (vec_t::width * i + j < jacsize)
147 {
148 tmp[j] = jac[vec_t::width * i + j];
149 }
150 else
151 {
152 tmp[j] = 0.0;
153 }
154 }
155
156 newjac[i].load(&tmp[0]);
157 }
158 }
159
162 }
163
165}
166
168 vector<LocalRegions::ExpansionSharedPtr> &pCollExp)
169{
170 if (m_oneDGeomData.count(eJacWithStdWeights) == 0)
171 {
172 LibUtilities::PointsKeyVector ptsKeys = pCollExp[0]->GetPointsKeys();
173 int nElmts = pCollExp.size();
174 int npts = pCollExp[0]->GetTotPoints();
175
176 // copy Jacobians into a continuous list and set new chatched value
177 Array<OneD, NekDouble> newjac(npts * nElmts), tmp;
178 int cnt = 0;
179 for (int i = 0; i < nElmts; ++i)
180 {
182 pCollExp[i]->GetGeomFactors()->GetJac();
183
184 if (pCollExp[i]->GetGeomFactors()->GetGtype() ==
186 {
187 Vmath::Vcopy(npts, &jac[0], 1, &newjac[cnt], 1);
188 }
189 else
190 {
191 Vmath::Fill(npts, jac[0], &newjac[cnt], 1);
192 }
193
194 pCollExp[0]->MultiplyByStdQuadratureMetric(newjac + cnt,
195 tmp = newjac + cnt);
196 cnt += npts;
197 }
198
200 }
201
203}
204
206 vector<LocalRegions::ExpansionSharedPtr> &pCollExp)
207{
208 if (m_twoDGeomData.count(eDerivFactors) == 0)
209 {
210 LibUtilities::PointsKeyVector ptsKeys = pCollExp[0]->GetPointsKeys();
211
212 int nElmts = pCollExp.size();
213 int npts = pCollExp[0]->GetTotPoints();
214 const int coordim = pCollExp[0]->GetCoordim();
215 int dim = ptsKeys.size();
216
217 // set up Cached Jacobians to be continuous
219
220 if (IsDeformed(pCollExp))
221 {
222 newDFac = Array<TwoD, NekDouble>(dim * coordim, npts * nElmts);
223 }
224 else
225 {
226 newDFac = Array<TwoD, NekDouble>(dim * coordim, nElmts);
227 }
228
229 // copy Jacobians into a continuous list and set new chatched value
230 int cnt = 0;
231 for (int i = 0; i < nElmts; ++i)
232 {
234 pCollExp[i]->GetGeomFactors()->GetDerivFactors();
235
236 if (IsDeformed(pCollExp))
237 {
238 for (int j = 0; j < dim * coordim; ++j)
239 {
240 Vmath::Vcopy(npts, &Dfac[j][0], 1, &newDFac[j][cnt], 1);
241 }
242 }
243 else
244 {
245 for (int j = 0; j < dim * coordim; ++j)
246 {
247 newDFac[j][i] = Dfac[j][0];
248 }
249 }
250 cnt += npts;
251 }
252
253 m_twoDGeomData[eDerivFactors] = newDFac;
254 }
255
257}
258
259const std::shared_ptr<VecVec_t> CoalescedGeomData::GetDerivFactorsInterLeave(
260 vector<LocalRegions::ExpansionSharedPtr> &pCollExp, int nElmt)
261{
263 {
264 ASSERTL1(nElmt % vec_t::width == 0,
265 "Number of elements not divisible by vector "
266 "width, padding not yet implemented.");
267
268 int nBlocks = nElmt / vec_t::width;
269
270 LibUtilities::PointsKeyVector ptsKeys = pCollExp[0]->GetPointsKeys();
271 const int coordim = pCollExp[0]->GetCoordim();
272 int dim = ptsKeys.size();
273
274 unsigned int n_df = coordim * dim;
275 alignas(vec_t::alignment) NekDouble vec[vec_t::width];
276
278 int dfsize = df.GetColumns();
279
280 VecVec_t newdf;
281
282 int npts = pCollExp[0]->GetTotPoints();
283
284 if (IsDeformed(pCollExp))
285 {
286 newdf.resize(nBlocks * n_df * npts);
287 auto *df_ptr = &newdf[0];
288 for (int e = 0; e < nBlocks; ++e)
289 {
290 for (int q = 0; q < npts; q++)
291 {
292 for (int dir = 0; dir < n_df; ++dir, ++df_ptr)
293 {
294 for (int j = 0; j < vec_t::width; ++j)
295 {
296 // manage padding
297 if ((vec_t::width * e + j) * npts + q < dfsize)
298 {
299 vec[j] =
300 df[dir][(vec_t::width * e + j) * npts + q];
301 }
302 else
303 {
304 vec[j] = 0.0;
305 }
306 }
307 (*df_ptr).load(&vec[0]);
308 }
309 }
310 }
311 }
312 else
313 {
314 newdf.resize(nBlocks * n_df);
315 for (int e = 0; e < nBlocks; ++e)
316 {
317 for (int dir = 0; dir < n_df; ++dir)
318 {
319 for (int j = 0; j < vec_t::width; ++j)
320 {
321 // padding
322 if (vec_t::width * e + j < dfsize)
323 {
324 vec[j] = df[dir][vec_t::width * e + j];
325 }
326 else
327 {
328 vec[j] = 0.0;
329 }
330 }
331 // Must have all vec_t::width elemnts aligned to do a load.
332 newdf[e * n_df + dir].load(&vec[0]);
333 }
334 }
335 }
336
339 }
340
342}
343
345 vector<LocalRegions::ExpansionSharedPtr> &pCollExp)
346{
347 return pCollExp[0]->GetGeomFactors()->GetGtype() ==
349}
350
351} // namespace Nektar::Collections
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
std::map< GeomData, std::shared_ptr< VecVec_t > > m_twoDGeomDataInterLeave
std::map< GeomData, std::shared_ptr< VecVec_t > > m_oneDGeomDataInterLeave
bool IsDeformed(std::vector< LocalRegions::ExpansionSharedPtr > &pCollExp)
const Array< OneD, const NekDouble > & GetJac(std::vector< LocalRegions::ExpansionSharedPtr > &pColLExp)
const std::shared_ptr< VecVec_t > GetDerivFactorsInterLeave(std::vector< LocalRegions::ExpansionSharedPtr > &pCollExp, int nElmts)
std::map< GeomData, Array< OneD, NekDouble > > m_oneDGeomData
const Array< TwoD, const NekDouble > & GetDerivFactors(std::vector< LocalRegions::ExpansionSharedPtr > &pColLExp)
const Array< OneD, const NekDouble > & GetJacWithStdWeights(std::vector< LocalRegions::ExpansionSharedPtr > &pColLExp)
std::map< GeomData, Array< TwoD, NekDouble > > m_twoDGeomData
const std::shared_ptr< VecVec_t > GetJacInterLeave(std::vector< LocalRegions::ExpansionSharedPtr > &pCollExp, int nElmts)
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::vector< vec_t, tinysimd::allocator< vec_t > > VecVec_t
std::vector< PointsKey > PointsKeyVector
Definition Points.h:313
@ eDeformed
Geometry is curved or has non-constant factors.
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition Vmath.hpp:54
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:825
STL namespace.