1 #ifndef HPP_SPECTRAL_UTILS_H 2 #define HPP_SPECTRAL_UTILS_H 43 inline int fftwFlat2(
int i0,
int i1,
int N0,
int N1)
48 inline int fftwFlat4(
int i0,
int i1,
int i2,
int i3,
const std::vector<ptrdiff_t>& N)
50 return i0*N[1]*N[2]*N[3] + i1*N[2]*N[3] + i2*N[3] + i3;
92 return std::sqrt(std::pow(comps[0], 2) + std::pow(comps[1], 2));
103 #define HPP_DEFAULT_ALIGNMENT 32 104 template <
typename U>
113 SpectralDataset(
const std::vector<std::vector<unsigned int>>& coordsList,
const std::vector<std::complex<U>>& coeffList);
165 SpectralDatasetID(
const std::string& baseName,
const std::vector<unsigned int>& component) : baseName(baseName), component(component) {
184 #define HPP_DEFAULT_UNIFIED_COORDS_NAME "unified_coords" 185 #define HPP_DEFAULT_COORDS_SUFFIX "_coords" 186 #define HPP_DEFAULT_COEFFS_SUFFIX "_vals" 196 template <
typename U>
198 std::string suffix =
"_";
199 for(
auto component : componentIdx) {
200 suffix += std::to_string(component);
205 std::string dsetName;
224 template <
typename U>
234 SpectralDatabase(std::string dbFilename, std::vector<std::string> dsetBasenames,
unsigned int nTerms, MPI_Comm comm,
unsigned int refineMult=1);
240 U getIDFTReal(std::string dsetBasename, std::vector<unsigned int> componentIdx, std::vector<unsigned int> spatialCoord)
const;
241 U getIDFTReal(std::string dsetBasename, std::vector<unsigned int> spatialCoord)
const;
266 return dsets.at(dsetID);
272 return dsets.begin()->second.getNTerms();
289 std::map<SpectralDatasetID, SpectralDataset<U>>
dsets;
298 void loadDatasetSingleComponent(
HDF5Handler& dbfile, std::string dsetBasename, std::vector<unsigned int> componentIdxUint,
unsigned int nTerms,
unsigned int refineMult=1);
299 void loadDataset(
HDF5Handler& dbfile, std::string dsetBasename,
unsigned int nTerms,
unsigned int refineMult=1);
302 void generateExponentialTable();
316 template <
typename U>
324 SpectralDatabaseUnified(std::string dbFilename, std::vector<SpectralDatasetID> dsetIDs,
unsigned int nTerms, MPI_Comm comm,
unsigned int refineMult=1);
325 SpectralDatabaseUnified(std::string dbFilename, std::vector<SpectralDatasetID> dsetIDs,
unsigned int nTerms,
unsigned int refineMult=1);
328 SpectralDatabaseUnified(std::string dbFilename,
unsigned int nTerms, MPI_Comm comm,
unsigned int refineMult=1);
333 U getIDFTReal(
SpectralDatasetID dsetID, std::vector<unsigned int> spatialCoord)
const;
334 U getIDFTReal(std::string dsetBasename, std::vector<unsigned int> componentIdx, std::vector<unsigned int> spatialCoord)
const;
335 U getIDFTReal(std::string dsetFullname, std::vector<unsigned int> spatialCoord)
const;
360 return coeffs.at(dsetID);
363 const std::shared_ptr<int>&
getCoords()
const {
return coords;}
366 void constructFromHandler(
HDF5Handler& dbFile, std::vector<SpectralDatasetID> dsetIDs,
unsigned int nTerms,
unsigned int refineMult=1);
387 std::map<SpectralDatasetID, std::shared_ptr<U>>
coeffs;
396 void loadDatasets(
HDF5Handler& dbfile, std::vector<SpectralDatasetID> dsetIDs,
unsigned int nTerms,
unsigned int refineMult=1);
413 template <
typename U>
414 void loadSpectralDatabase(
hpp::HDF5Handler& infile, std::string dsetNameCoords, std::string dsetNameCoeffs, std::vector<hsize_t> componentIdx, std::vector<std::vector<unsigned int>>& coordsList, std::vector<std::complex<U>>& coeffList,
unsigned int nTerms,
unsigned int refineMult=1)
420 hid_t dsetCoords = infile.
getDataset(dsetNameCoords);
421 hid_t dsetCoeffs = infile.
getDataset(dsetNameCoeffs);
426 unsigned int nCoeffs = dsetCoordsDims.end()[-2];
427 unsigned int nDims = dsetCoordsDims.back();
428 if (nCoeffs != dsetCoeffsDims.back())
throw std::runtime_error(
"Mismatch in dimensions of coeffs and coords.");
429 if (nTerms > nCoeffs)
throw std::runtime_error(
"Requested more terms than exist in the dataset.");
432 hid_t dsetGridDims = infile.
getDataset(
"grid_dims");
434 std::vector<unsigned int> gridDims(nDims);
435 std::vector<unsigned short int> gridDimsBuffer(nDims);
437 std::copy(gridDimsBuffer.begin(), gridDimsBuffer.end(), gridDims.data());
440 std::vector<unsigned short int> coordsBuffer(nTerms*nDims);
441 std::vector<hpp::hdf_complex_t> coeffsBuffer(nTerms);
447 coordsReadParams.
dataCount = std::vector<hsize_t>(componentIdx.size(), 1);
448 coordsReadParams.
dataCount.push_back(nTerms);
449 coordsReadParams.
dataCount.push_back(nDims);
450 coordsReadParams.
datatype = H5Dget_type(dsetCoords);
455 coeffsReadParams.dataOffset.push_back(0);
456 coeffsReadParams.dataCount = std::vector<hsize_t>(componentIdx.size(), 1);
457 coeffsReadParams.dataCount.push_back(nTerms);
458 coeffsReadParams.datatype = H5Dget_type(dsetCoeffs);
462 if (refineMult == 0) {
463 throw std::runtime_error(
"Refinement multiplier must be strictly positive.");
465 for (
auto&& dim : gridDims) {
471 coordsList.resize(nTerms);
472 coeffList.resize(nTerms);
477 unsigned int nTermsIncluded = 0;
478 unsigned int nTermsNumerical = 0;
479 for (
unsigned int i=0; nTermsIncluded<nTerms; i++) {
481 coordsList[i].resize(nDims);
482 unsigned short int *start = coordsBuffer.data()+i*nDims;
483 unsigned short int *end = start+nDims;
484 std::copy(start, end, coordsList[i].data());
487 for (
auto&& coord : coordsList[i]) {
493 coeffList[i] = std::complex<U>((U)rawVal.
r, (U)rawVal.
i);
497 bool shouldAddConjugate =
true;
500 if (coordsList[i].back() == 0) {
501 shouldAddConjugate =
false;
505 if (gridDims.back()%2 == 0 && coordsList[i].back()*2 == gridDims.back()) {
506 shouldAddConjugate =
false;
509 if (shouldAddConjugate) {
510 if (nTermsIncluded<nTerms) {
512 coeffList[i] *= (U)2.0;
522 coordsList.resize(nTermsNumerical);
523 coeffList.resize(nTermsNumerical);
530 template <
typename U>
531 std::complex<U>
TruncatedIFFTNDSingleSquare(
const unsigned int spatialDim,
const std::vector<std::complex<U>>& expTable,
const std::vector<std::vector<unsigned int>>& spectralCoordsList,
const std::vector<std::complex<U>>& coeffs, std::vector<unsigned int> spatialCoord,
unsigned int nTerms)
534 unsigned int nDims = spatialCoord.size();
535 unsigned int nCoeffs = spectralCoordsList.size();
536 if (coeffs.size() != nCoeffs)
throw std::runtime_error(
"Mismatch between number of coordinates and coefficients.");
537 if (nTerms > nCoeffs) {
538 std::string errString =
"Requested more terms than have been loaded: ";
539 errString += std::to_string(nTerms) +
" > " + std::to_string(nCoeffs);
540 throw std::runtime_error(errString);
544 std::complex<U> val = 0.0;
545 std::complex<U> iUnit(0, 1);
546 std::complex<U> seriesTerm;
547 for (
unsigned int iCoeff=0; iCoeff<nTerms; iCoeff++) {
549 unsigned int expFactorInt = 0;
550 for (
unsigned int iDim=0; iDim<nDims; iDim++) {
551 expFactorInt += spectralCoordsList[iCoeff][iDim]*spatialCoord[iDim];
555 expFactorInt = expFactorInt % spatialDim;
556 seriesTerm = coeffs[iCoeff]*expTable[expFactorInt];
566 template <
typename U>
567 U
TruncatedIFFTNDSingleSquareReal(
const unsigned int spatialDim,
const std::vector<std::complex<U>>& expTable,
const std::vector<std::vector<unsigned int>>& spectralCoordsList,
const std::vector<std::complex<U>>& coeffs, std::vector<unsigned int> spatialCoord,
unsigned int nTerms)
570 unsigned int nDims = spatialCoord.size();
571 unsigned int nCoeffs = spectralCoordsList.size();
572 if (coeffs.size() != nCoeffs)
throw std::runtime_error(
"Mismatch between number of coordinates and coefficients.");
573 if (nTerms > nCoeffs)
throw std::runtime_error(
"Requested more terms than have been loaded.");
577 std::complex<U> coeff;
578 std::complex<U> expVal;
579 for (
unsigned int iCoeff=0; iCoeff<nTerms; iCoeff++) {
581 unsigned int expFactorInt = 0;
582 for (
unsigned int iDim=0; iDim<nDims; iDim++) {
583 expFactorInt += spectralCoordsList[iCoeff][iDim]*spatialCoord[iDim];
587 expFactorInt = expFactorInt % spatialDim;
590 coeff = coeffs[iCoeff];
591 expVal = expTable[expFactorInt];
592 U seriesTerm = std::real(coeff)*std::real(expVal) - std::imag(coeff)*std::imag(expVal);
606 template <
typename U>
607 U
TruncatedIFFTNDSingleSquareRealScalar(
const unsigned int nDims,
const unsigned int spatialDim,
const U expTable[],
const int spectralCoordsList[],
const U coeffs[], std::vector<unsigned int> spatialCoord,
unsigned int nTerms)
610 for (
unsigned int iCoeff=0; iCoeff<nTerms; iCoeff++) {
612 int expFactorInt = 0;
613 for (
unsigned int iDim=0; iDim<nDims; iDim++) {
614 expFactorInt += spectralCoordsList[nDims*iCoeff+iDim]*spatialCoord[iDim];
618 U seriesTerm = coeffs[2*iCoeff]*expTable[2*expFactorInt] - coeffs[2*iCoeff+1]*expTable[2*expFactorInt+1];
630 template <
typename U>
631 U
TruncatedIFFTNDSingleSquareRealScalar(
const unsigned int nDims,
const unsigned int spatialDim,
const int spectralCoordsList[],
const U coeffs[], std::vector<unsigned int> spatialCoord,
unsigned int nTerms)
634 for (
unsigned int iCoeff=0; iCoeff<nTerms; iCoeff++) {
636 int expFactorInt = 0;
637 for (
unsigned int iDim=0; iDim<nDims; iDim++) {
638 expFactorInt += spectralCoordsList[nDims*iCoeff+iDim]*spatialCoord[iDim];
642 expFactorInt = expFactorInt % spatialDim;
645 U expValRe = std::cos(2*expFactorInt*M_PI/spatialDim);
646 U expValIm = std::sin(2*expFactorInt*M_PI/spatialDim);
647 U seriesTerm = coeffs[2*iCoeff]*expValRe - coeffs[2*iCoeff+1]*expValIm;
661 template <
typename U>
662 U TruncatedIFFT4DSingleSquareRealAVX(
const unsigned int spatialDim,
const U expTable[],
const int spectralCoordsList[],
const U coeffs[], std::vector<unsigned int> spatialCoord,
unsigned int nTerms)
664 __m256 productsSumVecF = _mm256_set_ps(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
665 __m256d productsSumVecD = _mm256_set_pd(0.0, 0.0, 0.0, 0.0);
666 __m128i spatialCoordVec = _mm_set_epi32((
int)spatialCoord[3],(
int)spatialCoord[2],(
int)spatialCoord[1],(
int)spatialCoord[0]);
667 __m128i twos = _mm_set_epi32(2,2,2,2);
668 unsigned int nChunks = nTerms/4;
669 for (
unsigned int iChunk=0; iChunk<nChunks; iChunk++) {
670 const unsigned int iCoeff0 = iChunk*4;
671 const unsigned int iCoeff1 = iChunk*4+1;
672 const unsigned int iCoeff2 = iChunk*4+2;
673 const unsigned int iCoeff3 = iChunk*4+3;
676 __m128i coordsVec = _mm_load_si128((__m128i*)(spectralCoordsList+4*iCoeff0));
678 __m128i coordProdsVec0 = _mm_mullo_epi32(coordsVec, spatialCoordVec);
681 coordsVec = _mm_load_si128((__m128i*)(spectralCoordsList+4*iCoeff1));
682 __m128i coordProdsVec1 = _mm_mullo_epi32(coordsVec, spatialCoordVec);
684 coordsVec = _mm_load_si128((__m128i*)(spectralCoordsList+4*iCoeff2));
685 __m128i coordProdsVec2 = _mm_mullo_epi32(coordsVec, spatialCoordVec);
687 coordsVec = _mm_load_si128((__m128i*)(spectralCoordsList+4*iCoeff3));
688 __m128i coordProdsVec3 = _mm_mullo_epi32(coordsVec, spatialCoordVec);
691 __m128i addedPairsVec01 = _mm_hadd_epi32(coordProdsVec0, coordProdsVec1);
697 __m128i addedPairsVec23 = _mm_hadd_epi32(coordProdsVec2, coordProdsVec3);
703 __m128i fullyAddedVec0123 = _mm_hadd_epi32(addedPairsVec01, addedPairsVec23);
709 fullyAddedVec0123 = _mm_mullo_epi32(fullyAddedVec0123, twos);
710 int32_t *expFac = (int32_t*)&fullyAddedVec0123;
714 if (std::is_same<U, float>::value) {
715 __m256 coeffVecF = _mm256_load_ps((
float*)coeffs+2*iCoeff0);
716 __m256 expValVecF = _mm256_loadu4_m64((
float*)expTable+expFac[3], (
float*)expTable+expFac[2], (
float*)expTable+expFac[1], (
float*)expTable+expFac[0]);
717 __m256 productsVecF = _mm256_mul_ps(coeffVecF, expValVecF);
718 productsSumVecF = _mm256_add_ps(productsSumVecF, productsVecF);
720 }
else if (std::is_same<U, double>::value) {
722 __m256d coeffVecD = _mm256_load_pd((
double*)coeffs+2*iCoeff0);
723 __m256d expValVecD =
_mm256_loadu2_m128d((
double*)expTable+expFac[1], (
double*)expTable+expFac[0]);
724 __m256d productsVecD = _mm256_mul_pd(coeffVecD, expValVecD);
725 productsSumVecD = _mm256_add_pd(productsSumVecD, productsVecD);
728 coeffVecD = _mm256_load_pd((
double*)coeffs+2*iCoeff2);
729 expValVecD =
_mm256_loadu2_m128d((
double*)expTable+expFac[3], (
double*)expTable+expFac[2]);
730 productsVecD = _mm256_mul_pd(coeffVecD, expValVecD);
731 productsSumVecD = _mm256_add_pd(productsSumVecD, productsVecD);
737 if (std::is_same<U, float>::value) {
738 float *productsSum = (
float*)&productsSumVecF;
739 return productsSum[0] - productsSum[1] + productsSum[2] - productsSum[3] + productsSum[4] - productsSum[5] + productsSum[6] - productsSum[7];
741 }
else if (std::is_same<U, double>::value) {
742 double *productsSum = (
double*)&productsSumVecD;
743 return productsSum[0] - productsSum[1] + productsSum[2] - productsSum[3];
752 template <
typename U>
753 U TruncatedIFFT4DSingleSquareRealAVX2(
const unsigned int spatialDim,
const U expTable[],
const int spectralCoordsList[],
const U coeffs[], std::vector<unsigned int> spatialCoord,
unsigned int nTerms)
755 __m256 productsSumVecF = _mm256_set_ps(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
756 __m256d productsSumVecD = _mm256_set_pd(0.0, 0.0, 0.0, 0.0);
757 __m256i spatialCoordVec = _mm256_set_epi32((
int)spatialCoord[3],(
int)spatialCoord[2],(
int)spatialCoord[1],(
int)spatialCoord[0],(
int)spatialCoord[3],(
int)spatialCoord[2],(
int)spatialCoord[1],(
int)spatialCoord[0]);
758 __m256i twos = _mm256_set_epi32(2,2,2,2,2,2,2,2);
759 unsigned int nChunks = nTerms/8;
760 for (
unsigned int iChunk=0; iChunk<nChunks; iChunk++) {
761 const unsigned int iCoeff0 = iChunk*8;
762 const unsigned int iCoeff2 = iChunk*8+2;
763 const unsigned int iCoeff4 = iChunk*8+4;
764 const unsigned int iCoeff6 = iChunk*8+6;
767 __m256i coordsVec = _mm256_load_si256((__m256i*)(spectralCoordsList+4*iCoeff0));
771 __m256i coordProdsVec01 = _mm256_mullo_epi32(coordsVec, spatialCoordVec);
776 coordsVec = _mm256_load_si256((__m256i*)(spectralCoordsList+4*iCoeff2));
777 __m256i coordProdsVec23 = _mm256_mullo_epi32(coordsVec, spatialCoordVec);
779 coordsVec = _mm256_load_si256((__m256i*)(spectralCoordsList+4*iCoeff4));
780 __m256i coordProdsVec45 = _mm256_mullo_epi32(coordsVec, spatialCoordVec);
782 coordsVec = _mm256_load_si256((__m256i*)(spectralCoordsList+4*iCoeff6));
783 __m256i coordProdsVec67 = _mm256_mullo_epi32(coordsVec, spatialCoordVec);
786 __m256i addedPairsVec0213 = _mm256_hadd_epi32(coordProdsVec01, coordProdsVec23);
792 __m256i addedPairsVec4657 = _mm256_hadd_epi32(coordProdsVec45, coordProdsVec67);
793 __m256i fullyAddedVec02461357 = _mm256_hadd_epi32(addedPairsVec0213, addedPairsVec4657);
803 fullyAddedVec02461357 = _mm256_mullo_epi32(fullyAddedVec02461357, twos);
804 int32_t *expFac = (int32_t*)&fullyAddedVec02461357;
808 if (std::is_same<U, float>::value) {
810 __m256 coeffVecF = _mm256_load_ps((
float*)coeffs+2*iCoeff0);
811 __m256 expValVecF = _mm256_loadu4_m64((
float*)expTable+expFac[5], (
float*)expTable+expFac[1], (
float*)expTable+expFac[4], (
float*)expTable+expFac[0]);
812 __m256 productsVecF = _mm256_mul_ps(coeffVecF, expValVecF);
813 productsSumVecF = _mm256_add_ps(productsSumVecF, productsVecF);
816 coeffVecF = _mm256_load_ps((
float*)coeffs+2*iCoeff4);
817 expValVecF = _mm256_loadu4_m64((
float*)expTable+expFac[7], (
float*)expTable+expFac[3], (
float*)expTable+expFac[6], (
float*)expTable+expFac[2]);
818 productsVecF = _mm256_mul_ps(coeffVecF, expValVecF);
819 productsSumVecF = _mm256_add_ps(productsSumVecF, productsVecF);
821 }
else if (std::is_same<U, double>::value) {
823 __m256d coeffVecD = _mm256_load_pd((
double*)coeffs+2*iCoeff0);
824 __m256d expValVecD =
_mm256_loadu2_m128d((
double*)expTable+expFac[4], (
double*)expTable+expFac[0]);
825 __m256d productsVecD = _mm256_mul_pd(coeffVecD, expValVecD);
826 productsSumVecD = _mm256_add_pd(productsSumVecD, productsVecD);
829 coeffVecD = _mm256_load_pd((
double*)coeffs+2*iCoeff2);
830 expValVecD =
_mm256_loadu2_m128d((
double*)expTable+expFac[5], (
double*)expTable+expFac[1]);
831 productsVecD = _mm256_mul_pd(coeffVecD, expValVecD);
832 productsSumVecD = _mm256_add_pd(productsSumVecD, productsVecD);
835 coeffVecD = _mm256_load_pd((
double*)coeffs+2*iCoeff4);
836 expValVecD =
_mm256_loadu2_m128d((
double*)expTable+expFac[6], (
double*)expTable+expFac[2]);
837 productsVecD = _mm256_mul_pd(coeffVecD, expValVecD);
838 productsSumVecD = _mm256_add_pd(productsSumVecD, productsVecD);
841 coeffVecD = _mm256_load_pd((
double*)coeffs+2*iCoeff6);
842 expValVecD =
_mm256_loadu2_m128d((
double*)expTable+expFac[7], (
double*)expTable+expFac[3]);
843 productsVecD = _mm256_mul_pd(coeffVecD, expValVecD);
844 productsSumVecD = _mm256_add_pd(productsSumVecD, productsVecD);
850 if (std::is_same<U, float>::value) {
851 float *productsSum = (
float*)&productsSumVecF;
852 return productsSum[0] - productsSum[1] + productsSum[2] - productsSum[3] + productsSum[4] - productsSum[5] + productsSum[6] - productsSum[7];
854 }
else if (std::is_same<U, double>::value) {
855 double *productsSum = (
double*)&productsSumVecD;
856 return productsSum[0] - productsSum[1] + productsSum[2] - productsSum[3];
871 template <
typename U>
872 U
TruncatedIFFT4DSingleSquareReal(
const unsigned int spatialDim,
const U expTable[],
const int spectralCoordsList[],
const U coeffs[],
const std::vector<unsigned int>& spatialCoord,
unsigned int nTerms)
875 #if defined HPP_USE_AVX2 876 return TruncatedIFFT4DSingleSquareRealAVX2(spatialDim, expTable, spectralCoordsList, coeffs, spatialCoord, nTerms);
877 #elif defined HPP_USE_AVX 878 return TruncatedIFFT4DSingleSquareRealAVX(spatialDim, expTable, spectralCoordsList, coeffs, spatialCoord, nTerms);
884 template <
typename U>
885 U
TruncatedIFFTNDSingleSquareReal(
const unsigned int nDims,
const unsigned int spatialDim,
const U expTable[],
const int spectralCoordsList[],
const U coeffs[],
const std::vector<unsigned int>& spatialCoord,
unsigned int nTerms)
892 template <
typename U>
893 U
TruncatedIFFT4DSingleSquareReal(
const unsigned int spatialDim,
const int spectralCoordsList[],
const U coeffs[],
const std::vector<unsigned int>& spatialCoord,
unsigned int nTerms)
900 template <
typename U>
901 U
TruncatedIFFTNDSingleSquareReal(
const unsigned int nDims,
const unsigned int spatialDim,
const int spectralCoordsList[],
const U coeffs[],
const std::vector<unsigned int>& spatialCoord,
unsigned int nTerms)
908 void evaluateSpectralCompressionErrorFull(std::string rawDBName, std::string spectralDBName, std::string errorDBName,
unsigned int nTermsMax, std::string outFilename, MPI_Comm comm);
910 void evaluateSpectralCompressionErrorAxisSlice(std::string rawDBName, std::string spectralDBName, std::vector<std::string> dsetBasenames,
unsigned int nTermsMax,
unsigned int refineMult, std::vector<int> axisSlice, std::string outFilename, MPI_Comm comm);
914 void evaluateSpectralCompressionErrorAxisSliceUnified(std::string rawDBName, std::string spectralDBName, std::vector<std::string> dsetBasenames,
unsigned int nTermsMax,
unsigned int refineMult, std::vector<int> axisSlice, std::string outFilename, MPI_Comm comm);
Definition: spectralUtils.h:317
std::vector< hsize_t > dataOffset
Definition: hdfUtils.h:98
SpectralDataset()
Definition: spectralUtils.h:109
std::vector< hsize_t > dataCount
Definition: hdfUtils.h:99
std::vector< unsigned int > component
Definition: spectralUtils.h:174
SpectralDataset< U > getDataset(const SpectralDatasetID &dsetID) const
Definition: spectralUtils.h:265
#define HPP_DEFAULT_COEFFS_SUFFIX
Definition: spectralUtils.h:186
SpectralDatabase()
Definition: spectralUtils.h:229
unsigned int getNTerms() const
Definition: spectralUtils.h:362
const std::shared_ptr< int > & getCoords() const
Definition: spectralUtils.h:119
std::map< SpectralDatasetID, std::shared_ptr< U > > coeffs
Definition: spectralUtils.h:387
unsigned int nTerms
Definition: spectralUtils.h:372
std::string baseName
Definition: spectralUtils.h:173
const std::vector< double > & getGridSteps() const
Definition: spectralUtils.h:259
#define _mm256_loadu2_m128d(hi, lo)
Definition: simdUtils.h:17
U TruncatedIFFTNDSingleSquareRealScalar(const unsigned int nDims, const unsigned int spatialDim, const U expTable[], const int spectralCoordsList[], const U coeffs[], std::vector< unsigned int > spatialCoord, unsigned int nTerms)
Scalar implementation of hpp.TruncatedIFFTNDSingleSquareReal.
Definition: spectralUtils.h:607
SpectralDatasetID(const std::string &baseName, const std::vector< unsigned int > &component)
Definition: spectralUtils.h:165
Definition: spectralUtils.h:161
const std::shared_ptr< U > & getExpTable() const
Definition: spectralUtils.h:244
const std::vector< double > & getGridEnds() const
Definition: spectralUtils.h:250
std::vector< ptrdiff_t > realDims
Definition: spectralUtils.h:56
Definition: casesUtils.cpp:4
void destroyConfigRealND(FFTWConfigRealND &cfg)
Definition: spectralUtils.cpp:62
U TruncatedIFFT4DSingleSquareReal(const unsigned int spatialDim, const U expTable[], const int spectralCoordsList[], const U coeffs[], const std::vector< unsigned int > &spatialCoord, unsigned int nTerms)
AVX implementation of hpp.TruncatedIFFT4DSingleSquareReal.
Definition: spectralUtils.h:872
bool hasDset(SpectralDatasetID dsetID)
Definition: spectralUtils.h:330
ptrdiff_t localN0
Definition: spectralUtils.h:65
#define HPP_DEFAULT_COORDS_SUFFIX
Definition: spectralUtils.h:185
std::string getDefaultCoeffsDatasetName(SpectralDatasetID dsetID)
Definition: spectralUtils.h:204
const std::vector< double > & getGridSteps() const
Definition: spectralUtils.h:353
hid_t datatype
Definition: hdfUtils.h:100
const std::vector< double > & getGridStarts() const
Definition: spectralUtils.h:350
Definition: hdfUtils.h:338
std::vector< double > gridSteps
Definition: spectralUtils.h:286
bool operator<(const SpectralDatasetID &l, const SpectralDatasetID &r)
Definition: spectralUtils.cpp:107
Definition: spectralUtils.h:225
const std::vector< double > & getGridLengths() const
Definition: spectralUtils.h:347
std::vector< hsize_t > getDatasetDims(hid_t dset_id)
Definition: hdfUtils.cpp:35
unsigned int getNDsets() const
Definition: spectralUtils.h:268
Definition: hdfUtils.h:97
unsigned int getNTerms() const
Definition: spectralUtils.h:125
const hsize_t & getNDims() const
Definition: spectralUtils.h:262
std::complex< U > TruncatedIFFTNDSingleSquare(const unsigned int spatialDim, const std::vector< std::complex< U >> &expTable, const std::vector< std::vector< unsigned int >> &spectralCoordsList, const std::vector< std::complex< U >> &coeffs, std::vector< unsigned int > spatialCoord, unsigned int nTerms)
TruncatedIFFTND where all dimensions have the same number of points.
Definition: spectralUtils.h:531
void operator()(void *x)
Definition: spectralUtils.h:33
ptrdiff_t nLocalReal
Definition: spectralUtils.h:70
std::vector< ptrdiff_t > realDimsLocal
Definition: spectralUtils.h:69
ptrdiff_t nLocalRealPadded
Definition: spectralUtils.h:74
fftw_plan forwardPlan
Definition: spectralUtils.h:83
A complex number type.
Definition: hdfUtils.h:62
Definition: spectralUtils.h:53
ptrdiff_t local0Start
Definition: spectralUtils.h:66
double r
Definition: hdfUtils.h:63
Header file for helper functions with HDF.
Header file for tensor classes.
bool operator==(const SpectralDatasetID &l, const SpectralDatasetID &r)
Definition: spectralUtils.cpp:132
std::string getCoeffsName(std::string baseName)
Definition: spectralUtils.h:192
std::vector< ptrdiff_t > complexDims
Definition: spectralUtils.h:58
std::shared_ptr< int > coords
Definition: spectralUtils.h:384
std::string getCoordsName(std::string baseName)
Definition: spectralUtils.h:189
SpectralDatasetID()
Definition: spectralUtils.h:162
const std::shared_ptr< int > & getCoords() const
Definition: spectralUtils.h:363
std::vector< ptrdiff_t > realDimsPaddedLocal
Definition: spectralUtils.h:75
double * in
Definition: spectralUtils.h:78
void loadSpectralDatabase(hpp::HDF5Handler &infile, std::string dsetNameCoords, std::string dsetNameCoeffs, std::vector< hsize_t > componentIdx, std::vector< std::vector< unsigned int >> &coordsList, std::vector< std::complex< U >> &coeffList, unsigned int nTerms, unsigned int refineMult=1)
Load a spectral database.
Definition: spectralUtils.h:414
std::vector< double > gridLengths
Definition: spectralUtils.h:380
std::map< SpectralDatasetID, SpectralDataset< U > > dsets
Definition: spectralUtils.h:289
#define HPP_DEFAULT_ALIGNMENT
Definition: spectralUtils.h:103
std::vector< double > gridStarts
Definition: spectralUtils.h:283
hid_t getPropertyListTransferIndependent()
Definition: hdfUtils.h:357
unsigned int NComplex
Definition: spectralUtils.h:62
ptrdiff_t nLocalComplexMem
Definition: spectralUtils.h:73
SpectralDatabaseUnified()
Definition: spectralUtils.h:321
std::vector< ptrdiff_t > realDimsPadded
Definition: spectralUtils.h:57
std::shared_ptr< U > expTable
Definition: spectralUtils.h:292
std::shared_ptr< int > coords
Definition: spectralUtils.h:143
ptrdiff_t nLocalComplex
Definition: spectralUtils.h:67
void evaluateSpectralCompressionErrorAxisSliceUnified(std::string rawDBName, std::string spectralDBName, std::vector< std::string > dsetBasenames, unsigned int nTermsMax, unsigned int refineMult, std::vector< int > axisSlice, std::string outFilename, MPI_Comm comm)
Evaluate the error incurred in the spectral reresentation of a database.
Definition: spectralUtils.cpp:1280
FFTWConfigRealND prepareFFTWConfigRealND(const std::vector< ptrdiff_t > &realDims, MPI_Comm comm)
Definition: spectralUtils.cpp:8
double fftwComplexMag(fftw_complex comps)
Definition: spectralUtils.h:90
double * backin
Definition: spectralUtils.h:80
void evaluateSpectralCompressionErrorFullUnified(std::string rawDBName, std::string spectralDBName, std::string errorDBName, unsigned int nTermsMax, std::string outFilename, MPI_Comm comm)
Definition: spectralUtils.cpp:923
int fftwFlat2(int i0, int i1, int N0, int N1)
Definition: spectralUtils.h:43
const std::vector< unsigned int > & getGridDims() const
Definition: spectralUtils.h:247
const std::vector< unsigned int > & getGridDims() const
Definition: spectralUtils.h:341
std::vector< double > gridStarts
Definition: spectralUtils.h:378
const std::vector< double > & getGridStarts() const
Definition: spectralUtils.h:256
MPI_Comm comm
Definition: spectralUtils.h:54
size_t gridRank
Definition: spectralUtils.h:55
std::shared_ptr< U > coeffs
Definition: spectralUtils.h:148
fftw_complex * out
Definition: spectralUtils.h:79
std::vector< ptrdiff_t > complexDimsLocal
Definition: spectralUtils.h:68
unsigned int nDims
Definition: spectralUtils.h:131
void readHDF5SimpleArray(hid_t dset_id, hid_t plist_id, HDFReadWriteParamsC parms, T *output)
Definition: hdfUtils.h:264
std::vector< double > gridEnds
Definition: spectralUtils.h:284
std::vector< unsigned int > gridDims
Definition: spectralUtils.h:280
SpectralDatasetID(const std::string &baseName)
Definition: spectralUtils.h:168
std::vector< unsigned int > gridDims
Definition: spectralUtils.h:375
std::string getComponentSuffix(const std::vector< U > &componentIdx)
Definition: spectralUtils.h:197
Definition: spectralUtils.h:32
std::shared_ptr< U > getCoeffs(const SpectralDatasetID &dsetID) const
Definition: spectralUtils.h:359
Definition: spectralUtils.h:105
unsigned int NReal
Definition: spectralUtils.h:61
const hsize_t & getNDims() const
Definition: spectralUtils.h:356
const std::shared_ptr< U > & getCoeffs() const
Definition: spectralUtils.h:116
const std::vector< double > & getGridEnds() const
Definition: spectralUtils.h:344
unsigned int getNDims() const
Definition: spectralUtils.h:122
void evaluateSpectralCompressionErrorAxisSlice(std::string rawDBName, std::string spectralDBName, std::vector< std::string > dsetBasenames, unsigned int nTermsMax, unsigned int refineMult, std::vector< int > axisSlice, std::string outFilename, MPI_Comm comm)
Evaluate the error incurred in the spectral reresentation of a database.
Definition: spectralUtils.cpp:1131
U TruncatedIFFTNDSingleSquareReal(const unsigned int spatialDim, const std::vector< std::complex< U >> &expTable, const std::vector< std::vector< unsigned int >> &spectralCoordsList, const std::vector< std::complex< U >> &coeffs, std::vector< unsigned int > spatialCoord, unsigned int nTerms)
Definition: spectralUtils.h:567
unsigned int nTerms
Definition: spectralUtils.h:134
double i
Definition: hdfUtils.h:64
const std::vector< double > & getGridLengths() const
Definition: spectralUtils.h:253
void evaluateSpectralCompressionErrorFull(std::string rawDBName, std::string spectralDBName, std::string errorDBName, unsigned int nTermsMax, std::string outFilename, MPI_Comm comm)
Definition: spectralUtils.cpp:731
std::vector< double > gridLengths
Definition: spectralUtils.h:285
fftw_plan backwardPlan
Definition: spectralUtils.h:84
std::vector< double > gridSteps
Definition: spectralUtils.h:381
Header file for implementations of stdlib functions that may be missing.
hid_t getDataset(std::string datasetName)
Definition: hdfUtils.cpp:129
unsigned int getNTerms() const
Definition: spectralUtils.h:271
int fftwFlat4(int i0, int i1, int i2, int i3, const std::vector< ptrdiff_t > &N)
Definition: spectralUtils.h:48
std::vector< double > gridEnds
Definition: spectralUtils.h:379
void readSingleHDF5Array(hid_t dset_id, hid_t plist_id, std::vector< hsize_t > gridOffset, std::vector< hsize_t > arrayDims, T *output)
Definition: hdfUtils.h:274