Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
Nektar::PreconCfsBRJ Class Reference

#include <PreconCfsBRJ.h>

Inheritance diagram for Nektar::PreconCfsBRJ:
[legend]

Public Member Functions

 PreconCfsBRJ (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vComm)
 
 ~PreconCfsBRJ () override=default
 
- Public Member Functions inherited from Nektar::PreconCfs
 PreconCfs (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vComm)
 
virtual ~PreconCfs ()=default
 
void InitObject ()
 
void DoPreconCfs (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &flag)
 
void BuildPreconCfs (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, const Array< OneD, NekDouble > > &intmp, const NekDouble time, const NekDouble lambda)
 
bool UpdatePreconMatCheck (const Array< OneD, const NekDouble > &res, const NekDouble dtLambda)
 
void SetOperators (const NekPreconCfsOperators &in)
 

Static Public Member Functions

static PreconCfsSharedPtr create (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vComm)
 Creates an instance of this class. More...
 

Static Public Attributes

static std::string className
 Name of the class. More...
 

Protected Member Functions

void v_InitObject () override
 
void v_DoPreconCfs (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &flag) override
 
void v_BuildPreconCfs (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, const Array< OneD, NekDouble > > &intmp, const NekDouble time, const NekDouble lambda) override
 
bool v_UpdatePreconMatCheck (const Array< OneD, const NekDouble > &res, const NekDouble dtLambda) override
 
virtual void v_InitObject ()=0
 
virtual void v_DoPreconCfs (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &flag)=0
 
virtual void v_BuildPreconCfs (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, const Array< OneD, NekDouble > > &intmp, const NekDouble time, const NekDouble lambda)=0
 
virtual bool v_UpdatePreconMatCheck (const Array< OneD, const NekDouble > &res, const NekDouble dtLambda)=0
 

Protected Attributes

int m_PreconItsStep
 
int m_BRJRelaxParam
 
Array< OneD, Array< OneD, SNekBlkMatSharedPtr > > m_PreconMatVarsSingle
 
unsigned int m_max_nblocks
 
unsigned int m_max_nElmtDof
 
std::vector< simd< NekSingle >, tinysimd::allocator< simd< NekSingle > > > m_sBlkDiagMat
 
std::vector< int > m_inputIdx
 
Array< OneD, SNekBlkMatSharedPtrm_TraceJacSingle
 
TensorOfArray4D< NekSinglem_TraceJacArraySingle
 
Array< OneD, SNekBlkMatSharedPtrm_TraceJacDerivSingle
 
TensorOfArray4D< NekSinglem_TraceJacDerivArraySingle
 
Array< OneD, Array< OneD, NekSingle > > m_TraceJacDerivSignSingle
 
TensorOfArray5D< NekSinglem_TraceIPSymJacArraySingle
 
- Protected Attributes inherited from Nektar::PreconCfs
LibUtilities::CommSharedPtr m_Comm
 
bool m_verbose
 
int m_spacedim
 
NekPreconCfsOperators m_operator
 
int m_PreconMatFreezNumb
 
int m_PreconTimesCounter
 
NekDouble m_DtLambdaPreconMat = -1.0
 
bool m_CalcPreconMatFlag = false
 

Private Member Functions

void DoNullPrecon (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &flag)
 
void PreconBlkDiag (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, NekDouble > &inarray, Array< OneD, NekDouble > &outarray)
 
template<typename DataType >
void MinusOffDiag2Rhs (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const size_t nvariables, const size_t nCoeffs, const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, TensorOfArray3D< NekDouble > &wspTrace, Array< OneD, Array< OneD, DataType > > &wspTraceDataType, const TensorOfArray4D< DataType > &TraceJacArray)
 
template<typename TypeNekBlkMatSharedPtr >
void AllocatePreconBlkDiagCoeff (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, Array< OneD, Array< OneD, TypeNekBlkMatSharedPtr > > &gmtxarray, const int &nscale=1)
 
void AllocateSIMDPreconBlkMatDiag (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
 This function creates the matrix structure for the block diagonal operator. It organizes the way that the matrix. More...
 
void AllocateNekBlkMatDig (SNekBlkMatSharedPtr &mat, const Array< OneD, unsigned int > nrow, const Array< OneD, unsigned int > ncol)
 

Friends

class MemoryManager< PreconCfsBRJ >
 

Detailed Description

Block Relaxed(weighted) Jacobi iterative (BRJ) Preconditioner for CFS

Solves a linear system using iterative methods.

Definition at line 49 of file PreconCfsBRJ.h.

Constructor & Destructor Documentation

◆ PreconCfsBRJ()

Nektar::PreconCfsBRJ::PreconCfsBRJ ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const LibUtilities::SessionReaderSharedPtr pSession,
const LibUtilities::CommSharedPtr vComm 
)

Definition at line 53 of file PreconCfsBRJ.cpp.

57 : PreconCfs(pFields, pSession, vComm)
58{
59 pSession->LoadParameter("PreconItsStep", m_PreconItsStep, 7);
60 pSession->LoadParameter("BRJRelaxParam", m_BRJRelaxParam, 1.0);
61
62 size_t nvariables = pFields.size();
63
65 Array<OneD, Array<OneD, SNekBlkMatSharedPtr>>(nvariables);
66 for (size_t i = 0; i < nvariables; i++)
67 {
68 m_PreconMatVarsSingle[i] = Array<OneD, SNekBlkMatSharedPtr>(nvariables);
69 }
71
73}
Array< OneD, Array< OneD, SNekBlkMatSharedPtr > > m_PreconMatVarsSingle
Definition: PreconCfsBRJ.h:77
void AllocatePreconBlkDiagCoeff(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, Array< OneD, Array< OneD, TypeNekBlkMatSharedPtr > > &gmtxarray, const int &nscale=1)
void AllocateSIMDPreconBlkMatDiag(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
This function creates the matrix structure for the block diagonal operator. It organizes the way that...
Definition: PreconCfsBRJ.h:138
PreconCfs(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vComm)
Definition: PreconCfs.cpp:48

References AllocatePreconBlkDiagCoeff(), AllocateSIMDPreconBlkMatDiag(), m_BRJRelaxParam, m_PreconItsStep, and m_PreconMatVarsSingle.

◆ ~PreconCfsBRJ()

Nektar::PreconCfsBRJ::~PreconCfsBRJ ( )
overridedefault

Member Function Documentation

◆ AllocateNekBlkMatDig()

void Nektar::PreconCfsBRJ::AllocateNekBlkMatDig ( SNekBlkMatSharedPtr mat,
const Array< OneD, unsigned int >  nrow,
const Array< OneD, unsigned int >  ncol 
)
inlineprivate

Definition at line 236 of file PreconCfsBRJ.h.

239 {
240 mat =
242 SNekMatSharedPtr loc_matNvar;
243 for (size_t nelm = 0; nelm < nrow.size(); ++nelm)
244 {
245 int nrowsVars = nrow[nelm];
246 int ncolsVars = ncol[nelm];
247
249 nrowsVars, ncolsVars, 0.0);
250 mat->SetBlock(nelm, nelm, loc_matNvar);
251 }
252 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< SNekMat > SNekMatSharedPtr

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and Nektar::eDIAGONAL.

Referenced by AllocatePreconBlkDiagCoeff(), and v_BuildPreconCfs().

◆ AllocatePreconBlkDiagCoeff()

template<typename TypeNekBlkMatSharedPtr >
void Nektar::PreconCfsBRJ::AllocatePreconBlkDiagCoeff ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
Array< OneD, Array< OneD, TypeNekBlkMatSharedPtr > > &  gmtxarray,
const int &  nscale = 1 
)
private

Definition at line 499 of file PreconCfsBRJ.cpp.

503{
504
505 size_t nvars = pFields.size();
506 size_t nelmts = pFields[0]->GetNumElmts();
507 size_t nelmtcoef;
508 Array<OneD, unsigned int> nelmtmatdim(nelmts);
509 for (size_t i = 0; i < nelmts; i++)
510 {
511 nelmtcoef = pFields[0]->GetExp(i)->GetNcoeffs();
512 nelmtmatdim[i] = nelmtcoef * nscale;
513 }
514
515 for (size_t i = 0; i < nvars; i++)
516 {
517 for (size_t j = 0; j < nvars; j++)
518 {
519 AllocateNekBlkMatDig(gmtxarray[i][j], nelmtmatdim, nelmtmatdim);
520 }
521 }
522}
void AllocateNekBlkMatDig(SNekBlkMatSharedPtr &mat, const Array< OneD, unsigned int > nrow, const Array< OneD, unsigned int > ncol)
Definition: PreconCfsBRJ.h:236

References AllocateNekBlkMatDig().

Referenced by PreconCfsBRJ().

◆ AllocateSIMDPreconBlkMatDiag()

void Nektar::PreconCfsBRJ::AllocateSIMDPreconBlkMatDiag ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields)
inlineprivate

This function creates the matrix structure for the block diagonal operator. It organizes the way that the matrix.

by SIMD instructions. The degrees of freedom of each element are reorganized, so they are placed in the correct location to perfom SIMD instructions.

Definition at line 138 of file PreconCfsBRJ.h.

140 {
141 using vec_t = simd<NekSingle>;
142
143 int TotMatLen = 0;
144 int TotLen = 0;
145 const auto nTotElmt = pFields[0]->GetNumElmts();
146 const auto nvariables = pFields.size();
147 const auto vecwidth = vec_t::width;
148
149 m_max_nblocks = 0;
150 m_max_nElmtDof = 0;
151
152 for (int ne = 0; ne < nTotElmt; ne++)
153 {
154 const auto nElmtDof = pFields[0]->GetNcoeffs(ne) * nvariables;
155 const auto nblocks = nElmtDof / vecwidth;
156 unsigned int totblocks =
157 (nElmtDof % vecwidth) ? nblocks + 1 : nblocks;
158
160 (m_max_nblocks > totblocks) ? m_max_nblocks : totblocks;
162 (m_max_nElmtDof > nElmtDof) ? m_max_nElmtDof : nElmtDof;
163
164 TotLen += totblocks * vecwidth;
165 TotMatLen += nElmtDof * totblocks;
166 }
167
168 m_sBlkDiagMat.resize(TotMatLen);
169 m_inputIdx.resize(TotLen);
170
171 // generate a index list of vector width aware mapping from
172 // local coeff storage over all variables to elemental storage
173 // over variables
174 unsigned int ncoeffs = pFields[0]->GetNcoeffs();
175 for (int ne = 0, cnt1 = 0; ne < nTotElmt; ne++)
176 {
177 const auto nElmtCoeff = pFields[0]->GetNcoeffs(ne);
178 const auto nElmtDof = nElmtCoeff * nvariables;
179 const auto nblocks = nElmtDof / vecwidth;
180 const auto nCoefOffset = pFields[0]->GetCoeff_Offset(ne);
181 int i = 0;
182 int i0 = 0;
183 int inOffset, j;
184
185 for (int m = 0; m < nvariables; m++)
186 {
187 inOffset = m * ncoeffs + nCoefOffset;
188
189 if (m && (vecwidth - i0 < nElmtCoeff))
190 {
191 // May need to add entries from later variables to
192 // remainder of last variable if the vector width
193 // was not exact multiple of number of elemental
194 // coeffs
195 for (i = 0; i0 < vecwidth; ++i, ++i0)
196 {
197 m_inputIdx[cnt1++] = inOffset + i;
198 }
199 }
200 else
201 {
202 i = 0;
203 }
204
205 // load up other vectors in variable that fit into vector
206 // width
207 for (j = 0; (j + 1) * vecwidth < nElmtCoeff - i; ++j)
208 {
209 for (i0 = 0; i0 < vecwidth; ++i0)
210 {
211 m_inputIdx[cnt1++] = inOffset + i + j * vecwidth + i0;
212 }
213 }
214
215 // load up any residual data for this variable
216 for (i0 = 0, j = j * vecwidth; j < nElmtCoeff - i; ++j, ++i0)
217 {
218 m_inputIdx[cnt1++] = inOffset + i + j;
219 }
220 }
221
222 const auto endwidth = nElmtDof - nblocks * vecwidth;
223
224 // fill out rest of index to match vector width with last entry
225 if (endwidth)
226 {
227 for (i0 = endwidth; i0 < vecwidth; ++i0)
228 {
229 m_inputIdx[cnt1++] = inOffset + i + j - 1;
230 }
231 }
232 ASSERTL1(cnt1 <= TotLen, "m_inputIdx over extended");
233 }
234 }
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
unsigned int m_max_nblocks
Definition: PreconCfsBRJ.h:79
unsigned int m_max_nElmtDof
Definition: PreconCfsBRJ.h:80
std::vector< int > m_inputIdx
Definition: PreconCfsBRJ.h:83
std::vector< simd< NekSingle >, tinysimd::allocator< simd< NekSingle > > > m_sBlkDiagMat
Definition: PreconCfsBRJ.h:82
tinysimd::simd< NekDouble > vec_t

References ASSERTL1, m_inputIdx, m_max_nblocks, m_max_nElmtDof, and m_sBlkDiagMat.

Referenced by PreconCfsBRJ().

◆ create()

static PreconCfsSharedPtr Nektar::PreconCfsBRJ::create ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const LibUtilities::SessionReaderSharedPtr pSession,
const LibUtilities::CommSharedPtr vComm 
)
inlinestatic

Creates an instance of this class.

Definition at line 55 of file PreconCfsBRJ.h.

59 {
61 pFields, pSession, vComm);
62 return p;
63 }
std::shared_ptr< PreconCfs > PreconCfsSharedPtr
Definition: PreconCfs.h:112

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and CellMLToNektar.cellml_metadata::p.

◆ DoNullPrecon()

void Nektar::PreconCfsBRJ::DoNullPrecon ( const Array< OneD, NekDouble > &  pInput,
Array< OneD, NekDouble > &  pOutput,
const bool &  flag 
)
private

Definition at line 288 of file PreconCfsBRJ.cpp.

291{
292 Vmath::Vcopy(pInput.size(), pInput, 1, pOutput, 1);
293}
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825

References Vmath::Vcopy().

Referenced by v_DoPreconCfs().

◆ MinusOffDiag2Rhs()

template<typename DataType >
void Nektar::PreconCfsBRJ::MinusOffDiag2Rhs ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const size_t  nvariables,
const size_t  nCoeffs,
const Array< OneD, const Array< OneD, NekDouble > > &  inarray,
Array< OneD, Array< OneD, NekDouble > > &  outarray,
TensorOfArray3D< NekDouble > &  wspTrace,
Array< OneD, Array< OneD, DataType > > &  wspTraceDataType,
const TensorOfArray4D< DataType > &  TraceJacArray 
)
private

Definition at line 377 of file PreconCfsBRJ.cpp.

385{
386 size_t nTracePts = pFields[0]->GetTrace()->GetNpoints();
387 size_t npoints = pFields[0]->GetNpoints();
388 size_t nDim = m_spacedim;
389
390 Array<OneD, Array<OneD, NekDouble>> outpnts(nvariables);
391 for (size_t i = 0; i < nvariables; i++)
392 {
393 outpnts[i] = Array<OneD, NekDouble>(npoints, 0.0);
394 pFields[i]->BwdTrans(outarray[i], outpnts[i]);
395 }
396
397 // Store forwards/backwards space along trace space
398 Array<OneD, Array<OneD, NekDouble>> Fwd;
399 Array<OneD, Array<OneD, NekDouble>> Bwd;
400 Array<OneD, Array<OneD, NekDouble>> FwdFlux;
401 Array<OneD, Array<OneD, NekDouble>> BwdFlux;
402 TensorOfArray3D<NekDouble> numDerivBwd(nDim);
403 TensorOfArray3D<NekDouble> numDerivFwd(nDim);
404 size_t indexwspTrace = 0;
405 Fwd = wspTrace[indexwspTrace], indexwspTrace++;
406 Bwd = wspTrace[indexwspTrace], indexwspTrace++;
407 FwdFlux = wspTrace[indexwspTrace], indexwspTrace++;
408 BwdFlux = wspTrace[indexwspTrace], indexwspTrace++;
409
410 LibUtilities::Timer timer;
411 for (size_t i = 0; i < nvariables; ++i)
412 {
413 timer.Start();
414 pFields[i]->GetFwdBwdTracePhys(outpnts[i], Fwd[i], Bwd[i]);
415 timer.Stop();
416 timer.AccumulateRegion("ExpList::GetFwdBwdTracePhys", 10);
417 }
418
419 size_t indexwspTraceDataType = 0;
420 Array<OneD, Array<OneD, DataType>> Fwdarray(nvariables);
421 for (size_t m = 0; m < nvariables; ++m)
422 {
423 Fwdarray[m] = wspTraceDataType[indexwspTraceDataType],
424 indexwspTraceDataType++;
425 }
426 Array<OneD, DataType> Fwdreslt;
427 Fwdreslt = wspTraceDataType[indexwspTraceDataType], indexwspTraceDataType++;
428
429 for (size_t m = 0; m < nvariables; ++m)
430 {
431 for (size_t i = 0; i < nTracePts; ++i)
432 {
433 Fwdarray[m][i] = DataType(Fwd[m][i]);
434 }
435 }
436 for (size_t m = 0; m < nvariables; ++m)
437 {
438 Vmath::Zero(nTracePts, Fwdreslt, 1);
439 for (size_t n = 0; n < nvariables; ++n)
440 {
441 for (size_t p = 0; p < nTracePts; ++p)
442 {
443 Fwdreslt[p] += TraceJacArray[0][m][n][p] * Fwdarray[n][p];
444 }
445 }
446 for (size_t i = 0; i < nTracePts; ++i)
447 {
448 FwdFlux[m][i] = NekDouble(Fwdreslt[i]);
449 }
450 }
451
452 for (size_t m = 0; m < nvariables; ++m)
453 {
454 for (size_t i = 0; i < nTracePts; ++i)
455 {
456 Fwdarray[m][i] = DataType(Bwd[m][i]);
457 }
458 }
459 for (size_t m = 0; m < nvariables; ++m)
460 {
461 Vmath::Zero(nTracePts, Fwdreslt, 1);
462 for (size_t n = 0; n < nvariables; ++n)
463 {
464 for (size_t p = 0; p < nTracePts; ++p)
465 {
466 Fwdreslt[p] += TraceJacArray[1][m][n][p] * Fwdarray[n][p];
467 }
468 }
469 for (size_t i = 0; i < nTracePts; ++i)
470 {
471 BwdFlux[m][i] = NekDouble(Fwdreslt[i]);
472 }
473 }
474
475 for (size_t i = 0; i < nvariables; ++i)
476 {
477 Vmath::Fill(nCoeffs, 0.0, outarray[i], 1);
478 timer.Start();
479 pFields[i]->AddTraceIntegralToOffDiag(FwdFlux[i], BwdFlux[i],
480 outarray[i]);
481 timer.Stop();
482 timer.AccumulateRegion("ExpList::AddTraceIntegralToOffDiag", 10);
483 }
484
485 for (size_t i = 0; i < nvariables; ++i)
486 {
487 for (size_t p = 0; p < nCoeffs; ++p)
488 {
489 outarray[i][p] =
490 -m_DtLambdaPreconMat * outarray[i][p] + inarray[i][p];
491 }
492 }
493}
NekDouble m_DtLambdaPreconMat
Definition: PreconCfs.h:94
double NekDouble
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.hpp:273
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.hpp:54

References Nektar::LibUtilities::Timer::AccumulateRegion(), Vmath::Fill(), Nektar::PreconCfs::m_DtLambdaPreconMat, Nektar::PreconCfs::m_spacedim, CellMLToNektar.cellml_metadata::p, Nektar::LibUtilities::Timer::Start(), Nektar::LibUtilities::Timer::Stop(), and Vmath::Zero().

Referenced by v_DoPreconCfs().

◆ PreconBlkDiag()

void Nektar::PreconCfsBRJ::PreconBlkDiag ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const Array< OneD, NekDouble > &  inarray,
Array< OneD, NekDouble > &  outarray 
)
private

Definition at line 298 of file PreconCfsBRJ.cpp.

301{
302 unsigned int nvariables = pFields.size();
303
304 int nTotElmt = pFields[0]->GetNumElmts();
305
306 using vec_t = simd<NekSingle>;
307 const auto vecwidth = vec_t::width;
308
309 // vectorized matrix multiply
310 std::vector<vec_t, tinysimd::allocator<vec_t>> Sinarray(m_max_nblocks);
311 std::vector<vec_t, tinysimd::allocator<vec_t>> Soutarray(m_max_nElmtDof);
312
313 alignas(vec_t::alignment) std::array<NekSingle, vec_t::width> tmp;
314
315 for (int ne = 0, cnt = 0, icnt = 0, icnt1 = 0; ne < nTotElmt; ne++)
316 {
317 const auto nElmtCoef = pFields[0]->GetNcoeffs(ne);
318 const auto nElmtDof = nElmtCoef * nvariables;
319 const auto nblocks = (nElmtDof % vecwidth) ? nElmtDof / vecwidth + 1
320 : nElmtDof / vecwidth;
321
322 // gather data into blocks - could probably be done with a
323 // gather call? can be replaced with a gather op when working
324 for (int j = 0; j < nblocks; ++j, icnt += vecwidth)
325 {
326 for (int i = 0; i < vecwidth; ++i)
327 {
328 tmp[i] = inarray[m_inputIdx[icnt + i]];
329 }
330
331 Sinarray[j].load(tmp.data());
332 }
333
334 // Do matrix multiply
335 // first block just needs multiplying
336 vec_t in = Sinarray[0];
337 for (int i = 0; i < nElmtDof; ++i)
338 {
339 Soutarray[i] = m_sBlkDiagMat[cnt++] * in;
340 }
341
342 // rest of blocks are multiply add operations;
343 for (int n = 1; n < nblocks; ++n)
344 {
345 in = Sinarray[n];
346 for (int i = 0; i < nElmtDof; ++i)
347 {
348 Soutarray[i].fma(m_sBlkDiagMat[cnt++], in);
349 }
350 }
351
352 // get block aligned index for this expansion
353 NekSingle val;
354 for (int i = 0; i < nElmtDof; ++i)
355 {
356 // Get hold of data
357 Soutarray[i].store(tmp.data());
358
359 // Sum vector width
360 val = tmp[0];
361 for (int j = 1; j < vecwidth; ++j)
362 {
363 val += tmp[j];
364 }
365 // put data into outarray
366 outarray[m_inputIdx[icnt1 + i]] = NekDouble(val);
367 }
368
369 icnt1 += nblocks * vecwidth;
370 }
371}

References m_inputIdx, m_max_nblocks, m_max_nElmtDof, and m_sBlkDiagMat.

Referenced by v_DoPreconCfs().

◆ v_BuildPreconCfs()

void Nektar::PreconCfsBRJ::v_BuildPreconCfs ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const Array< OneD, const Array< OneD, NekDouble > > &  intmp,
const NekDouble  time,
const NekDouble  lambda 
)
overrideprotectedvirtual

Copy array into column major blocks of vector width

Implements Nektar::PreconCfs.

Definition at line 188 of file PreconCfsBRJ.cpp.

192{
193 if (m_PreconItsStep > 0)
194 {
195 SNekBlkMatSharedPtr PreconMatSingle;
196 using vec_t = simd<NekSingle>;
197 int nvariables = pFields.size();
198 int nelmts = pFields[0]->GetNumElmts();
199 Array<OneD, unsigned int> matdim(nelmts);
200 for (int i = 0; i < nelmts; i++)
201 {
202 matdim[i] = pFields[0]->GetExp(i)->GetNcoeffs() * nvariables;
203 }
204 AllocateNekBlkMatDig(PreconMatSingle, matdim, matdim);
205
207 intmp, m_PreconMatVarsSingle, PreconMatSingle, m_TraceJacSingle,
211
212 if (m_verbose && m_Comm->GetRank() == 0)
213 {
214 cout << " ## CalcuPreconMat " << endl;
215 }
216
217 // copy matrix to simd layout
218 // load matrix
219 int cnt = 0;
220 const auto vecwidth = vec_t::width;
221
222 alignas(vec_t::alignment) std::array<NekSingle, vec_t::width> tmp;
223
224 for (int ne = 0; ne < nelmts; ne++)
225 {
226 const auto nElmtDof = matdim[ne];
227 const auto nblocks = nElmtDof / vecwidth;
228
229 const NekSingle *mmat =
230 PreconMatSingle->GetBlockPtr(ne, ne)->GetRawPtr();
231 /// Copy array into column major blocks of vector width
232 for (int i1 = 0; i1 < nblocks; ++i1)
233 {
234 for (int j = 0; j < nElmtDof; ++j)
235 {
236 for (int i = 0; i < vecwidth; ++i)
237 {
238 tmp[i] = mmat[j + (i1 * vecwidth + i) * nElmtDof];
239 }
240 // store contiguous vec_t array.
241 m_sBlkDiagMat[cnt++].load(tmp.data());
242 }
243 }
244
245 const auto endwidth = nElmtDof - nblocks * vecwidth;
246
247 // end rows that do not fit into vector widths
248 if (endwidth)
249 {
250 for (int j = 0; j < nElmtDof; ++j)
251 {
252 for (int i = 0; i < endwidth; ++i)
253 {
254 tmp[i] = mmat[j + (nblocks * vecwidth + i) * nElmtDof];
255 }
256
257 for (int i = endwidth; i < vecwidth; ++i)
258 {
259 tmp[i] = 0.0;
260 }
261 m_sBlkDiagMat[cnt++].load(tmp.data());
262 }
263 }
264 }
265 }
266
267 m_DtLambdaPreconMat = lambda;
268 m_CalcPreconMatFlag = false;
270}
void DoCalcPreconMatBRJCoeff(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, SNekBlkMatSharedPtr > > &gmtxarray, SNekBlkMatSharedPtr &gmtVar, Array< OneD, SNekBlkMatSharedPtr > &TraceJac, Array< OneD, SNekBlkMatSharedPtr > &TraceJacDeriv, Array< OneD, Array< OneD, NekSingle > > &TraceJacDerivSign, TensorOfArray4D< NekSingle > &TraceJacArray, TensorOfArray4D< NekSingle > &TraceJacDerivArray, TensorOfArray5D< NekSingle > &TraceIPSymJacArray)
Definition: PreconCfsOp.h:97
Array< OneD, SNekBlkMatSharedPtr > m_TraceJacSingle
Definition: PreconCfsBRJ.h:85
TensorOfArray4D< NekSingle > m_TraceJacArraySingle
Definition: PreconCfsBRJ.h:86
Array< OneD, SNekBlkMatSharedPtr > m_TraceJacDerivSingle
Definition: PreconCfsBRJ.h:87
Array< OneD, Array< OneD, NekSingle > > m_TraceJacDerivSignSingle
Definition: PreconCfsBRJ.h:89
TensorOfArray4D< NekSingle > m_TraceJacDerivArraySingle
Definition: PreconCfsBRJ.h:88
TensorOfArray5D< NekSingle > m_TraceIPSymJacArraySingle
Definition: PreconCfsBRJ.h:90
NekPreconCfsOperators m_operator
Definition: PreconCfs.h:91
int m_PreconTimesCounter
Definition: PreconCfs.h:93
bool m_CalcPreconMatFlag
Definition: PreconCfs.h:95
LibUtilities::CommSharedPtr m_Comm
Definition: PreconCfs.h:88
std::shared_ptr< SNekBlkMat > SNekBlkMatSharedPtr

References AllocateNekBlkMatDig(), Nektar::NekPreconCfsOperators::DoCalcPreconMatBRJCoeff(), Nektar::PreconCfs::m_CalcPreconMatFlag, Nektar::PreconCfs::m_Comm, Nektar::PreconCfs::m_DtLambdaPreconMat, Nektar::PreconCfs::m_operator, m_PreconItsStep, m_PreconMatVarsSingle, Nektar::PreconCfs::m_PreconTimesCounter, m_sBlkDiagMat, m_TraceIPSymJacArraySingle, m_TraceJacArraySingle, m_TraceJacDerivArraySingle, m_TraceJacDerivSignSingle, m_TraceJacDerivSingle, m_TraceJacSingle, and Nektar::PreconCfs::m_verbose.

◆ v_DoPreconCfs()

void Nektar::PreconCfsBRJ::v_DoPreconCfs ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const Array< OneD, NekDouble > &  pInput,
Array< OneD, NekDouble > &  pOutput,
const bool &  flag 
)
overrideprotectedvirtual

Implements Nektar::PreconCfs.

Definition at line 85 of file PreconCfsBRJ.cpp.

89{
90 size_t nBRJIterTot = m_PreconItsStep;
91 if (nBRJIterTot == 0)
92 {
93 DoNullPrecon(inarray, outarray, flag);
94 }
95 else
96 {
97 const NekDouble BRJParam = m_BRJRelaxParam;
98 const NekDouble OmBRJParam = 1.0 - BRJParam;
99
100 size_t nvariables = pFields.size();
101 size_t npoints = pFields[0]->GetNcoeffs();
102 size_t ntotpnt = inarray.size();
103
104 ASSERTL0(nvariables * npoints == ntotpnt,
105 "nvariables*npoints!=ntotpnt in PreconCoeff");
106
107 Array<OneD, NekDouble> rhs(ntotpnt);
108
109 Array<OneD, NekDouble> outN(ntotpnt);
110 Array<OneD, NekDouble> outTmp(ntotpnt);
111 Array<OneD, Array<OneD, NekDouble>> rhs2d(nvariables);
112 Array<OneD, Array<OneD, NekDouble>> out_2d(nvariables);
113 Array<OneD, Array<OneD, NekDouble>> outTmp_2d(nvariables);
114 for (size_t m = 0; m < nvariables; m++)
115 {
116 size_t moffset = m * npoints;
117 rhs2d[m] = rhs + moffset;
118 out_2d[m] = outarray + moffset;
119 outTmp_2d[m] = outTmp + moffset;
120 pFields[m]->MultiplyByMassMatrix(inarray + moffset, rhs2d[m]);
121 }
122
123 size_t nphysic = pFields[0]->GetNpoints();
124 size_t nTracePts = pFields[0]->GetTrace()->GetNpoints();
125 TensorOfArray3D<NekDouble> qfield(m_spacedim);
126 for (int i = 0; i < m_spacedim; i++)
127 {
128 qfield[i] = Array<OneD, Array<OneD, NekDouble>>(nvariables);
129 for (size_t j = 0; j < nvariables; j++)
130 {
131 qfield[i][j] = Array<OneD, NekDouble>(nphysic);
132 }
133 }
134 size_t ntmpTrace = 4 + 2 * m_spacedim;
135 TensorOfArray3D<NekDouble> tmpTrace(ntmpTrace);
136 for (size_t i = 0; i < ntmpTrace; i++)
137 {
138 tmpTrace[i] = Array<OneD, Array<OneD, NekDouble>>(nvariables);
139 for (size_t j = 0; j < nvariables; j++)
140 {
141 tmpTrace[i][j] = Array<OneD, NekDouble>(nTracePts);
142 }
143 }
144 Array<OneD, Array<OneD, NekDouble>> FwdFluxDeriv(nvariables);
145 Array<OneD, Array<OneD, NekDouble>> BwdFluxDeriv(nvariables);
146 for (size_t j = 0; j < nvariables; j++)
147 {
148 FwdFluxDeriv[j] = Array<OneD, NekDouble>(nTracePts);
149 BwdFluxDeriv[j] = Array<OneD, NekDouble>(nTracePts);
150 }
151
152 const size_t nwspTraceDataType = nvariables + 1;
153 Array<OneD, Array<OneD, NekSingle>> wspTraceDataType(nwspTraceDataType);
154 for (size_t m = 0; m < nwspTraceDataType; m++)
155 {
156 wspTraceDataType[m] = Array<OneD, NekSingle>(nTracePts);
157 }
158
159 LibUtilities::Timer timer;
160 timer.Start();
161 PreconBlkDiag(pFields, rhs, outarray);
162 timer.Stop();
163 timer.AccumulateRegion("PreconCfsBRJ::PreconBlkDiag", 2);
164
165 for (size_t nrelax = 0; nrelax < nBRJIterTot - 1; nrelax++)
166 {
167 Vmath::Smul(ntotpnt, OmBRJParam, outarray, 1, outN, 1);
168
169 timer.Start();
170 MinusOffDiag2Rhs(pFields, nvariables, npoints, rhs2d, out_2d,
171 tmpTrace, wspTraceDataType, m_TraceJacArraySingle);
172 timer.Stop();
173 timer.AccumulateRegion("PreconCfsBRJ::MinusOffDiag2Rhs", 2);
174
175 timer.Start();
176 PreconBlkDiag(pFields, outarray, outTmp);
177 timer.Stop();
178 timer.AccumulateRegion("PreconCfsBRJ::PreconBlkDiag", 2);
179
180 Vmath::Svtvp(ntotpnt, BRJParam, outTmp, 1, outN, 1, outarray, 1);
181 }
182 }
183}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
void MinusOffDiag2Rhs(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const size_t nvariables, const size_t nCoeffs, const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, TensorOfArray3D< NekDouble > &wspTrace, Array< OneD, Array< OneD, DataType > > &wspTraceDataType, const TensorOfArray4D< DataType > &TraceJacArray)
void PreconBlkDiag(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, NekDouble > &inarray, Array< OneD, NekDouble > &outarray)
void DoNullPrecon(const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &flag)
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Svtvp (scalar times vector plus vector): z = alpha*x + y.
Definition: Vmath.hpp:396
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.hpp:100

References Nektar::LibUtilities::Timer::AccumulateRegion(), ASSERTL0, DoNullPrecon(), m_BRJRelaxParam, m_PreconItsStep, Nektar::PreconCfs::m_spacedim, m_TraceJacArraySingle, MinusOffDiag2Rhs(), PreconBlkDiag(), Vmath::Smul(), Nektar::LibUtilities::Timer::Start(), Nektar::LibUtilities::Timer::Stop(), and Vmath::Svtvp().

◆ v_InitObject()

void Nektar::PreconCfsBRJ::v_InitObject ( )
overrideprotectedvirtual

Implements Nektar::PreconCfs.

Definition at line 78 of file PreconCfsBRJ.cpp.

79{
80}

◆ v_UpdatePreconMatCheck()

bool Nektar::PreconCfsBRJ::v_UpdatePreconMatCheck ( const Array< OneD, const NekDouble > &  res,
const NekDouble  dtLambda 
)
overrideprotectedvirtual

Friends And Related Function Documentation

◆ MemoryManager< PreconCfsBRJ >

friend class MemoryManager< PreconCfsBRJ >
friend

Definition at line 1 of file PreconCfsBRJ.h.

Member Data Documentation

◆ className

std::string Nektar::PreconCfsBRJ::className
static
Initial value:
=
"PreconCfsBRJ", PreconCfsBRJ::create,
"Block Relaxed Jacobi Preconditioner for CFS.")
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static PreconCfsSharedPtr create(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vComm)
Creates an instance of this class.
Definition: PreconCfsBRJ.h:55
PreconCfsFactory & GetPreconCfsFactory()
Declaration of the boundary condition factory singleton.
Definition: PreconCfs.cpp:42

Name of the class.

Definition at line 66 of file PreconCfsBRJ.h.

◆ m_BRJRelaxParam

int Nektar::PreconCfsBRJ::m_BRJRelaxParam
protected

Definition at line 75 of file PreconCfsBRJ.h.

Referenced by PreconCfsBRJ(), and v_DoPreconCfs().

◆ m_inputIdx

std::vector<int> Nektar::PreconCfsBRJ::m_inputIdx
protected

Definition at line 83 of file PreconCfsBRJ.h.

Referenced by AllocateSIMDPreconBlkMatDiag(), and PreconBlkDiag().

◆ m_max_nblocks

unsigned int Nektar::PreconCfsBRJ::m_max_nblocks
protected

Definition at line 79 of file PreconCfsBRJ.h.

Referenced by AllocateSIMDPreconBlkMatDiag(), and PreconBlkDiag().

◆ m_max_nElmtDof

unsigned int Nektar::PreconCfsBRJ::m_max_nElmtDof
protected

Definition at line 80 of file PreconCfsBRJ.h.

Referenced by AllocateSIMDPreconBlkMatDiag(), and PreconBlkDiag().

◆ m_PreconItsStep

int Nektar::PreconCfsBRJ::m_PreconItsStep
protected

Definition at line 74 of file PreconCfsBRJ.h.

Referenced by PreconCfsBRJ(), v_BuildPreconCfs(), and v_DoPreconCfs().

◆ m_PreconMatVarsSingle

Array<OneD, Array<OneD, SNekBlkMatSharedPtr> > Nektar::PreconCfsBRJ::m_PreconMatVarsSingle
protected

Definition at line 77 of file PreconCfsBRJ.h.

Referenced by PreconCfsBRJ(), and v_BuildPreconCfs().

◆ m_sBlkDiagMat

std::vector<simd<NekSingle>, tinysimd::allocator<simd<NekSingle> > > Nektar::PreconCfsBRJ::m_sBlkDiagMat
protected

Definition at line 82 of file PreconCfsBRJ.h.

Referenced by AllocateSIMDPreconBlkMatDiag(), PreconBlkDiag(), and v_BuildPreconCfs().

◆ m_TraceIPSymJacArraySingle

TensorOfArray5D<NekSingle> Nektar::PreconCfsBRJ::m_TraceIPSymJacArraySingle
protected

Definition at line 90 of file PreconCfsBRJ.h.

Referenced by v_BuildPreconCfs().

◆ m_TraceJacArraySingle

TensorOfArray4D<NekSingle> Nektar::PreconCfsBRJ::m_TraceJacArraySingle
protected

Definition at line 86 of file PreconCfsBRJ.h.

Referenced by v_BuildPreconCfs(), and v_DoPreconCfs().

◆ m_TraceJacDerivArraySingle

TensorOfArray4D<NekSingle> Nektar::PreconCfsBRJ::m_TraceJacDerivArraySingle
protected

Definition at line 88 of file PreconCfsBRJ.h.

Referenced by v_BuildPreconCfs().

◆ m_TraceJacDerivSignSingle

Array<OneD, Array<OneD, NekSingle> > Nektar::PreconCfsBRJ::m_TraceJacDerivSignSingle
protected

Definition at line 89 of file PreconCfsBRJ.h.

Referenced by v_BuildPreconCfs().

◆ m_TraceJacDerivSingle

Array<OneD, SNekBlkMatSharedPtr> Nektar::PreconCfsBRJ::m_TraceJacDerivSingle
protected

Definition at line 87 of file PreconCfsBRJ.h.

Referenced by v_BuildPreconCfs().

◆ m_TraceJacSingle

Array<OneD, SNekBlkMatSharedPtr> Nektar::PreconCfsBRJ::m_TraceJacSingle
protected

Definition at line 85 of file PreconCfsBRJ.h.

Referenced by v_BuildPreconCfs().