Chaste Commit::8b5d759ac2eb95e67ae57699734101efccb0a0a9
ImmersedBoundary2dArrays.cpp
1
2/*
3
4Copyright (c) 2005-2024, University of Oxford.
5All rights reserved.
6
7University of Oxford means the Chancellor, Masters and Scholars of the
8University of Oxford, having an administrative office at Wellington
9Square, Oxford OX1 2JD, UK.
10
11This file is part of Chaste.
12
13Redistribution and use in source and binary forms, with or without
14modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright notice,
16 this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright notice,
18 this list of conditions and the following disclaimer in the documentation
19 and/or other materials provided with the distribution.
20 * Neither the name of the University of Oxford nor the names of its
21 contributors may be used to endorse or promote products derived from this
22 software without specific prior written permission.
23
24THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
30GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35*/
36
37#include "ImmersedBoundary2dArrays.hpp"
38#include <assert.h>
39#include "Exception.hpp"
40
41template<unsigned DIM>
42ImmersedBoundary2dArrays<DIM>::ImmersedBoundary2dArrays(ImmersedBoundaryMesh<DIM,DIM>* pMesh, double dt, double reynoldsNumber, bool activeSources)
43 : mpMesh(pMesh),
44 mActiveSources(activeSources)
45{
46 unsigned num_gridpts_x = mpMesh->GetNumGridPtsX();
47 unsigned num_gridpts_y = mpMesh->GetNumGridPtsY();
48
49 // We require an even number of grid points
50 assert(num_gridpts_y % 2 == 0);
51
52 /*
53 * Resize the grids. All complex grids are half-sized in the y-coordinate due to redundancy inherent in the
54 * fast-Fourier method for solving Navier-Stokes.
55 */
56 unsigned reduced_y = 1 + (num_gridpts_y/2);
57
58 // Resize real arrays to be num X by num Y
59 mForceGrids.resize(extents[2][num_gridpts_x][num_gridpts_y]);
60
61 mRightHandSideGrids.resize(extents[3][num_gridpts_x][num_gridpts_y]);
62
63 // The source gradient grids are only needed when fluid sources are present. Otherwise, we need do nothing
65 {
66 mSourceGradientGrids.resize(extents[2][num_gridpts_x][num_gridpts_y]);
67 }
68
69 // Resize Fourier-domain arrays
70 // There are three such FourierGrid arrays if sources are active
71 mOperator1.resize(extents[num_gridpts_x][reduced_y]);
72 mOperator2.resize(extents[num_gridpts_x][reduced_y]);
73 mFourierGrids.resize(extents[2 + (int)mActiveSources][num_gridpts_x][reduced_y]);
74 mPressureGrid.resize(extents[num_gridpts_x][reduced_y]);
75
76 mSin2x.resize(num_gridpts_x);
77 mSin2y.resize(reduced_y);
78
79 /*
80 * There are several constants used in the Fourier domain as part of the Navier-Stokes solution which are constant
81 * once grid sizes are known. We pre-calculate these to eliminate re-calculation at every time step.
82 */
83 double x_spacing = 1.0 / (double) num_gridpts_x;
84 double y_spacing = 1.0 / (double) num_gridpts_y;
85
86 for (unsigned x = 0; x < num_gridpts_x; x++)
87 {
88 mSin2x[x] = sin(2 * M_PI * (double) x * x_spacing);
89 }
90
91 for (unsigned y = 0; y < reduced_y; y++)
92 {
93 mSin2y[y] = sin(2 * M_PI * (double) y * y_spacing);
94 }
95
96 for (unsigned x = 0; x < num_gridpts_x; x++)
97 {
98 for (unsigned y = 0; y < reduced_y; y++)
99 {
100 mOperator1[x][y] = (mSin2x[x] * mSin2x[x] / (x_spacing * x_spacing)) + (mSin2y[y] * mSin2y[y] / (y_spacing * y_spacing));
101 mOperator1[x][y] *= dt / reynoldsNumber;
102
103 double sin_x = sin(M_PI * (double) x * x_spacing);
104 double sin_y = sin(M_PI * (double) y * y_spacing);
105
106 mOperator2[x][y] = (sin_x * sin_x / (x_spacing * x_spacing)) + (sin_y * sin_y / (y_spacing * y_spacing));
107 mOperator2[x][y] *= 4.0 * dt / reynoldsNumber;
108 mOperator2[x][y] += 1.0;
109 }
110 }
111}
112
113template<unsigned DIM>
117
118template<unsigned DIM>
120{
121 return mForceGrids;
122}
123
124template<unsigned DIM>
126{
127 return mRightHandSideGrids;
128}
129
130template<unsigned DIM>
132{
133 return mSourceGradientGrids;
134}
135
136template<unsigned DIM>
138{
139 return mFourierGrids;
140}
141
142template<unsigned DIM>
144{
145 return mPressureGrid;
146}
147
148template<unsigned DIM>
149const multi_array<double, 2>& ImmersedBoundary2dArrays<DIM>::rGetOperator1() const
150{
151 return mOperator1;
152}
153
154template<unsigned DIM>
155const multi_array<double, 2>& ImmersedBoundary2dArrays<DIM>::rGetOperator2() const
156{
157 return mOperator2;
158}
159
160template<unsigned DIM>
161const std::vector<double>& ImmersedBoundary2dArrays<DIM>::rGetSin2x() const
162{
163 return mSin2x;
164}
165
166template<unsigned DIM>
167const std::vector<double>& ImmersedBoundary2dArrays<DIM>::rGetSin2y() const
168{
169 return mSin2y;
170}
171
172template<unsigned DIM>
177
178template<unsigned DIM>
180{
181 return mActiveSources;
182}
183
184// Explicit instantiation
185template class ImmersedBoundary2dArrays<1>;
186template class ImmersedBoundary2dArrays<2>;
187template class ImmersedBoundary2dArrays<3>;
multi_array< std::complex< double >, 3 > mFourierGrids
multi_array< double, 2 > mOperator2
const std::vector< double > & rGetSin2x() const
multi_array< double, 3 > mRightHandSideGrids
multi_array< std::complex< double >, 2 > & rGetModifiablePressureGrid()
const multi_array< double, 2 > & rGetOperator2() const
multi_array< double, 3 > mForceGrids
multi_array< std::complex< double >, 2 > mPressureGrid
multi_array< std::complex< double >, 3 > & rGetModifiableFourierGrids()
const multi_array< double, 2 > & rGetOperator1() const
ImmersedBoundaryMesh< DIM, DIM > * GetMesh()
multi_array< double, 3 > & rGetModifiableSourceGradientGrids()
multi_array< double, 2 > mOperator1
ImmersedBoundaryMesh< DIM, DIM > * mpMesh
multi_array< double, 3 > mSourceGradientGrids
multi_array< double, 3 > & rGetModifiableRightHandSideGrids()
const std::vector< double > & rGetSin2y() const
multi_array< double, 3 > & rGetModifiableForceGrids()