Pull out common classes for FFT/DST transforms in some Laplacians#3261
Pull out common classes for FFT/DST transforms in some Laplacians#3261
Conversation
The Laplacian inversion solvers `LaplaceCyclic`, `LaplacePCR`, `LaplacePCR_THOMAS` all use identical code for transforming using FFTs/DSTs. This commit pulls out that common code to make it easier to maintain. Also, make the transforms parallel-Z-ready by using the Z guard cells as offsets
89d4071 to
cb6260d
Compare
| void tridagCoefs(int jx, int jy, int jz, dcomplex& a, dcomplex& b, dcomplex& c, | ||
| const Field2D* ccoef = nullptr, const Field2D* d = nullptr, | ||
| CELL_LOC loc = CELL_DEFAULT); | ||
| CELL_LOC loc = CELL_DEFAULT) const; |
There was a problem hiding this comment.
warning: no header providing "CELL_DEFAULT" is directly included [misc-include-cleaner]
CELL_LOC loc = CELL_DEFAULT) const;
^|
|
||
| Matrices result(nsys, nx); | ||
|
|
||
| BOUT_OMP_PERF(parallel) |
There was a problem hiding this comment.
warning: no header providing "BOUT_OMP_PERF" is directly included [misc-include-cleaner]
src/invert/laplace/common_transform.cxx:10:
- #include "bout/utils.hxx"
+ #include "bout/openmpwrap.hxx"
+ #include "bout/utils.hxx"| { | ||
| /// Create a local thread-scope working array | ||
| // ZFFT routine expects input of this length | ||
| auto k1d = Array<dcomplex>((nz / 2) + 1); |
There was a problem hiding this comment.
warning: no header providing "Array" is directly included [misc-include-cleaner]
src/invert/laplace/common_transform.cxx:2:
- #include "bout/constants.hxx"
+ #include "bout/array.hxx"
+ #include "bout/constants.hxx"| // (unless periodic in x) | ||
| BOUT_OMP_PERF(for) | ||
| for (int ind = 0; ind < nxny; ++ind) { | ||
| int ix = xs + (ind / ny); |
There was a problem hiding this comment.
warning: variable 'ix' of type 'int' can be declared 'const' [misc-const-correctness]
| int ix = xs + (ind / ny); | |
| int const ix = xs + (ind / ny); |
| BOUT_OMP_PERF(for) | ||
| for (int ind = 0; ind < nxny; ++ind) { | ||
| int ix = xs + (ind / ny); | ||
| int iy = ys + (ind % ny); |
There was a problem hiding this comment.
warning: variable 'iy' of type 'int' can be declared 'const' [misc-const-correctness]
| int iy = ys + (ind % ny); | |
| int const iy = ys + (ind % ny); |
| // including boundary conditions | ||
| BOUT_OMP_PERF(for nowait) | ||
| for (int kz = 0; kz < nmode; kz++) { | ||
| BoutReal kwave = kz * 2.0 * PI / zlength; // wave number is 1/[rad] |
There was a problem hiding this comment.
warning: variable 'kwave' of type 'BoutReal' (aka 'double') can be declared 'const' [misc-const-correctness]
| BoutReal kwave = kz * 2.0 * PI / zlength; // wave number is 1/[rad] | |
| BoutReal const kwave = kz * 2.0 * PI / zlength; // wave number is 1/[rad] |
| /// Helper class to do FFTs for `LaplaceCyclic`, `LaplacePCR`, `LaplacePCR_THOMAS` | ||
| class FFTTransform { | ||
| /// Physical length of the Z domain | ||
| BoutReal zlength; |
There was a problem hiding this comment.
warning: no header providing "BoutReal" is directly included [misc-include-cleaner]
src/invert/laplace/common_transform.hxx:2:
- #include "bout/dcomplex.hxx"
+ #include "bout/bout_types.hxx"
+ #include "bout/dcomplex.hxx"|
|
||
| if (localmesh->periodicX) { | ||
| // Subtract X average of kz=0 mode | ||
| BoutReal local[2] = { |
There was a problem hiding this comment.
warning: do not declare C-style arrays, use 'std::array' instead [cppcoreguidelines-avoid-c-arrays]
BoutReal local[2] = {
^|
|
||
| irfft(std::begin(k1d), localmesh->LocalNz, x[ix]); | ||
| } | ||
| BoutReal global[2]; |
There was a problem hiding this comment.
warning: do not declare C-style arrays, use 'std::array' instead [cppcoreguidelines-avoid-c-arrays]
BoutReal global[2];
^| irfft(std::begin(k1d), localmesh->LocalNz, x[ix]); | ||
| } | ||
| BoutReal global[2]; | ||
| MPI_Allreduce(local, global, 2, MPI_DOUBLE, MPI_SUM, localmesh->getXcomm()); |
There was a problem hiding this comment.
warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]
MPI_Allreduce(local, global, 2, MPI_DOUBLE, MPI_SUM, localmesh->getXcomm());
^
The Laplacian inversion solvers
LaplaceCyclic,LaplacePCR,LaplacePCR_THOMASall use identical code for transforming using FFTs/DSTs. This commit pulls out that common code to make it easier to maintain.Also, make the transforms parallel-Z-ready by using the Z guard cells as offsets