Nektar++
Loading...
Searching...
No Matches
PerforatedPlate.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: PerforatedPlate.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2026 Nicolas de Jong
10// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
11// Department of Aeronautics, Imperial College London (UK), and Scientific
12// Computing and Imaging Institute, University of Utah (USA).
13//
14// Permission is hereby granted, free of charge, to any person obtaining a
15// copy of this software and associated documentation files (the "Software"),
16// to deal in the Software without restriction, including without limitation
17// the rights to use, copy, modify, merge, publish, distribute, sublicense,
18// and/or sell copies of the Software, and to permit persons to whom the
19// Software is furnished to do so, subject to the following conditions:
20//
21// The above copyright notice and this permission notice shall be included
22// in all copies or substantial portions of the Software.
23//
24// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30// DEALINGS IN THE SOFTWARE.
31//
32// Description: PerforatedPlate
33//
34///////////////////////////////////////////////////////////////////////////////
35
36#include <iostream>
37
39
43
44namespace Nektar
45{
46
48 NekDouble wI, NekDouble u0, NekDouble uI)
49 : m_modelType(linerType), m_w0(w0), m_wI(wI), m_u0(u0), m_uI(uI)
50{
51}
52
53/**
54 * @brief Initialization object for the AcousticSystem class.
55 */
57 Array<OneD, NekDouble> &B, short sizeF,
58 int nBC, Array<OneD, int> &nPnt, int nExp)
59{
60 (void)m_modelType; // unused, for future development
61
62 // Format rational fraction coefficients
63 m_A = NekVector<NekDouble>(sizeF, 0.0);
64 m_B = NekVector<NekDouble>(sizeF, 0.0);
65 for (short i = 0; i < sizeF; ++i)
66 {
67 m_A[i] = A[i];
68 m_B[i] = B[i];
69 }
70 if (m_A[sizeF - 1] != 1.0)
71 {
72 Vmath::Smul(sizeF, 1.0 / m_A[sizeF - 1], &m_B[0], 1, &m_B[0], 1);
73 Vmath::Smul(sizeF, 1.0 / m_A[sizeF - 1], &m_A[0], 1, &m_A[0], 1);
74 }
75
76 // Liner initial state computation
77 NekDouble iV_real = m_A[0], iV_imag = 0.0, iV_mod = 0.0, lastImag = 0.0;
78 for (short k = 2; k < m_A.GetDimension(); k = k + 2)
79 {
80 iV_real = iV_real + m_A[k] * std::pow(m_w0, k) * std::pow(-1.0, k / 2);
81 iV_imag = iV_imag + m_A[k] * std::pow(m_wI, k) * std::pow(-1.0, k / 2);
82 }
83 for (short k = 1; k < m_A.GetDimension(); k = k + 2)
84 {
85 iV_imag =
86 iV_imag + m_A[k] * std::pow(m_w0, k) * std::pow(-1.0, (k - 1) / 2);
87 iV_real =
88 iV_real + m_A[k] * std::pow(m_wI, k) * std::pow(-1.0, (k + 1) / 2);
89 }
90 iV_mod = 1.0 / (std::pow(iV_real, 2.0) + std::pow(iV_imag, 2.0));
91 iV_real = iV_real * iV_mod;
92 iV_imag = -iV_imag * iV_mod;
93 if (m_u0 != 0.0)
94 {
95 iV_real = iV_real * m_u0 - iV_imag * m_uI;
96 iV_imag = iV_real * m_uI + iV_imag * m_u0;
97 }
98
99 // ODE Parameter initialization
102 for (short i = 0; i < nBC; ++i)
103 {
106 for (short j = 0; j < nPnt[i]; ++j)
107 {
109 m_U[i][j][0] = Array<OneD, NekDouble>(nExp, 0.0);
110 m_U[i][j][1] = Array<OneD, NekDouble>(nExp, iV_real);
112 m_y[i][j][0] = Array<OneD, NekDouble>(nExp, 0.0);
113 m_y[i][j][1] = Array<OneD, NekDouble>(nExp, 0.0);
114 lastImag = iV_imag;
115 for (short k = 2; k < m_A.GetDimension(); ++k)
116 {
117 m_U[i][j][k] = Array<OneD, NekDouble>(
118 nExp, -m_U[i][j][k - 1][0] * m_wI - lastImag * m_w0);
119 lastImag = m_U[i][j][k - 1][0] * m_w0 - lastImag * m_wI;
120 m_y[i][j][k] = Array<OneD, NekDouble>(nExp, 0.0);
121 }
122 }
123 }
124 m_currentTime = 0.0;
125
126 // ODE intialization
129 "RungeKutta", "", 4, {});
132}
133
134/**
135 * @brief Function to compute the pressure jump across the perforated plate for
136 * a given value of the acoustic velocity.
137 */
139 const int point,
140 const NekDouble *u,
141 const NekDouble intTime,
142 const NekDouble simdt)
143{
144 // Initialize ODE parameters
145 Vmath::Vcopy(m_U[bound][point][0].size(), u, 1, &m_U[bound][point][0][0],
146 1);
147 if (intTime == 0.0 && m_u0 == 0.0)
148 {
149 m_dt = 0.0;
150 for (short i = 1; i < m_A.GetDimension(); ++i)
151 {
152 Vmath::Vmul(m_U[bound][point][i].size(), u, 1,
153 &m_U[bound][point][i][0], 1, &m_U[bound][point][i][0],
154 1);
155 }
156 }
157
158 // Compute time step and update base state
159 if (m_lastTime < intTime)
160 {
161 m_dt = intTime - m_currentTime;
162 if (m_dt > simdt)
163 {
165 m_dt = intTime - m_lastTime;
166 for (int j = 0; j < m_U.size(); ++j)
167 {
168 for (int k = 0; k < m_U[j].size(); ++k)
169 {
170 for (int i = 1; i < m_y[j][k].size(); ++i)
171 {
172 Vmath::Vcopy(m_U[j][k][i].size(), &m_y[j][k][i][0], 1,
173 &m_U[j][k][i][0], 1);
174 }
175 }
176 }
177 }
178 m_lastTime = intTime;
179 }
180
181 // ODE single step integration
182 m_timeScheme->InitializeScheme(m_dt, m_U[bound][point], m_currentTime,
183 m_ODE);
184 m_y[bound][point] = m_timeScheme->TimeIntegrate(0, m_dt);
185
186 // Compute output
187 Array<OneD, NekDouble> bsum(m_y[bound][point][0].size(), 0.0);
188 for (short i = 0; i < m_A.GetDimension() - 1; ++i)
189 {
190 Vmath::Svtvp(bsum.size(), m_B[i] - m_B[m_A.GetDimension() - 1] * m_A[i],
191 &m_y[bound][point][1 + i][0], 1, &bsum[0], 1, &bsum[0], 1);
192 }
193 Vmath::Svtvp(bsum.size(), m_B[m_A.GetDimension() - 1], &u[0], 1, &bsum[0],
194 1, &bsum[0], 1);
195
196 return bsum;
197}
198
199/**
200 * @brief Operator used for the ODE time integration.
201 */
203 const Array<OneD, const Array<OneD, NekDouble>> &inx,
205 [[maybe_unused]] const NekDouble time)
206{
207 // inx element 0 is u vector, element 1 to end are ss variables and its
208 // derivatives; outx elements are the derivatives of x and u
209 Array<OneD, NekDouble> asum(inx[0].size(), 0.0);
210 for (short i = 1; i < m_A.GetDimension(); ++i)
211 {
212 if (i < m_A.GetDimension() - 1)
213 {
214 Vmath::Vcopy(inx[i].size(), &inx[i + 1][0], 1, &outx[i][0], 1);
215 }
216 Vmath::Svtvp(inx[i].size(), m_A[i - 1], &inx[i][0], 1, &asum[0], 1,
217 &asum[0], 1);
218 }
219 Vmath::Vsub(inx[0].size(), &inx[0][0], 1, &asum[0], 1,
220 &outx[m_A.GetDimension() - 1][0], 1);
221 Vmath::Zero(inx[0].size(), &outx[0][0], 1);
222}
223
224/**
225 * @brief Operator used for the ODE time integration.
226 */
228 const Array<OneD, Array<OneD, NekDouble>> &inx,
229 Array<OneD, Array<OneD, NekDouble>> &outx, [[maybe_unused]] NekDouble time)
230{
231 for (int i = 0; i < inx.size(); ++i)
232 {
233 Vmath::Vcopy(inx[i].size(), &inx[i][0], 1, &outx[i][0], 1);
234 }
235}
236
237} // namespace Nektar
tBasePtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
void DefineProjection(FuncPointerT func, ObjectPointerT obj)
unsigned int GetDimension() const
Returns the number of dimensions for the point.
LibUtilities::TimeIntegrationSchemeSharedPtr m_timeScheme
NekVector< NekDouble > m_A
Array< OneD, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > > m_U
void InitObject(Array< OneD, NekDouble > &A, Array< OneD, NekDouble > &B, short sizeF, int nBC, Array< OneD, int > &nPnt, int nExp)
Initialization object for the AcousticSystem class.
PerforatedPlate(int linerType, NekDouble w0, NekDouble wI, NekDouble u0, NekDouble uI)
void LinerOperator(const Array< OneD, const Array< OneD, NekDouble > > &inx, Array< OneD, Array< OneD, NekDouble > > &outx, const NekDouble time)
Operator used for the ODE time integration.
void LinerProjection(const Array< OneD, Array< OneD, NekDouble > > &inx, Array< OneD, Array< OneD, NekDouble > > &outx, const NekDouble time)
Operator used for the ODE time integration.
Array< OneD, NekDouble > LinerOutput(int bound, int point, const NekDouble *u, const NekDouble intTime, const NekDouble simdt)
Function to compute the pressure jump across the perforated plate for a given value of the acoustic v...
Array< OneD, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > > m_y
NekVector< NekDouble > m_B
LibUtilities::TimeIntegrationSchemeOperators m_ODE
TimeIntegrationSchemeFactory & GetTimeIntegrationSchemeFactory()
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition Vmath.hpp:74
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:398
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:102
void Zero(int n, T *x, const int incx)
Zero vector.
Definition Vmath.hpp:275
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:828
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition Vmath.hpp:222