Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
ImmersedBoundaryFftInterface.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "ImmersedBoundaryFftInterface.hpp"
37#include <assert.h>
38#include "FileFinder.hpp"
39#include "Warnings.hpp"
40
41template<unsigned DIM>
43 double* pIn,
44 std::complex<double>* pComplex,
45 double* pOut,
46 bool activeSources)
47 : mpMesh(pMesh),
48 mpInputArray(pIn),
49 mpComplexArray(pComplex),
50 mpOutputArray(pOut)
51{
52 int num_grid_pts_x = (int)mpMesh->GetNumGridPtsX();
53 int num_grid_pts_y = (int)mpMesh->GetNumGridPtsY();
54
55 // We require an even number of grid points
56 assert(num_grid_pts_y % 2 == 0);
57
58 /*
59 * Resize the grids. All complex grids are half-sized in the y-coordinate due to redundancy inherent in the
60 * fast-Fourier method for solving Navier-Stokes.
61 */
62 int reduced_y = 1 + (num_grid_pts_y/2);
63
64 // Plan variables
65 mRealDims = {(long unsigned int)num_grid_pts_x, (long unsigned int)num_grid_pts_y}; // Dimensions of each real array
66 mCompDims = {(long unsigned int)num_grid_pts_x, (long unsigned int)reduced_y}; // Dimensions of each complex array
67
68 mHowManyForward = 2 + (unsigned)activeSources; // Number of forward transforms (one more if sources are active)
69 mHowManyInverse = 2; // Number of inverse transforms (always 2)
70
71 mRealSep = num_grid_pts_x * num_grid_pts_y; // How many doubles between start of first array and start of second
72 mCompSep = num_grid_pts_x * reduced_y; // How many fftw_complex between start of first array and start of second
73
74 mRealStride = sizeof(double); // Each real array is contiguous in memory
75 mCompStride = sizeof(std::complex<double>); // Each complex array is contiguous in memory
76
77/*
78
79 multi-dimensional arrays are stored row-major
80 real_dims = dimensions of matrix
81 real_sep = pointer offset between matrices
82 how_many_forward = number of matrices to operate on
83 stride = 1 => matrices are continguously stored one after the other
84 */
85}
86
87template<unsigned DIM>
91
92template<unsigned DIM>
94{
95 // Real to complex
96 pocketfft::stride_t rStride = {mRealStride*static_cast<long int>(mRealDims[1]), mRealStride};
97 pocketfft::stride_t cStride = {mCompStride*static_cast<long int>(mCompDims[1]), mCompStride};
98 pocketfft::shape_t axes = {0, 1};
99
100 for (unsigned i = 0; i < mHowManyForward; i++)
101 {
102 pocketfft::r2c<double>(mRealDims, rStride, cStride, axes, true, mpInputArray + i*mRealSep, mpComplexArray + i*mCompSep, 1.0, 1);
103 }
104}
105
106template<unsigned DIM>
108{
109 // Complex to real
110 pocketfft::stride_t rStride = {mRealStride*static_cast<long int>(mRealDims[1]), mRealStride};
111 pocketfft::stride_t cStride = {mCompStride*static_cast<long int>(mCompDims[1]), mCompStride};
112 pocketfft::shape_t axes = {0, 1};
113
114 for (unsigned i = 0; i < mHowManyInverse; i++)
115 {
116 // For c2r, output array dims are supplied
117 pocketfft::c2r(mRealDims, cStride, rStride, axes, false, mpComplexArray + i*mCompSep, mpOutputArray + i*mRealSep, 1.0, 1);
118 }
119}
120
121// Explicit instantiation
ImmersedBoundaryMesh< DIM, DIM > * mpMesh