Nektar++
Loading...
Searching...
No Matches
IncBaseCondition.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: IncBaseCondition.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Abstract base class for Extrapolate.
32//
33///////////////////////////////////////////////////////////////////////////////
34
37
38namespace Nektar
39{
40
42 {1.0, 0.0, 0.0}, {2.0, -1.0, 0.0}, {3.0, -3.0, 1.0}};
44 {1.0, 0.0, 0.0}, {2.0, -0.5, 0.0}, {3.0, -1.5, 1.0 / 3.0}};
46 11.0 / 6.0};
47
49{
50 static IncBCFactory instance;
51 return instance;
52}
53
55 [[maybe_unused]] const LibUtilities::SessionReaderSharedPtr pSession,
56 [[maybe_unused]] Array<OneD, MultiRegions::ExpListSharedPtr> pFields,
59 [[maybe_unused]] int nbnd, [[maybe_unused]] int spacedim,
60 [[maybe_unused]] int bnddim)
61 : m_spacedim(spacedim), m_bnddim(bnddim), m_nbnd(nbnd), m_field(pFields[0])
62{
63}
64
67{
68 m_npoints = m_BndExp.begin()->second->GetNpoints();
69 m_numCalls = 0;
70 if (pSession->DefinesParameter("ExtrapolateOrder"))
71 {
72 m_intSteps = std::round(pSession->GetParameter("ExtrapolateOrder"));
73 m_intSteps = std::min(3, std::max(0, m_intSteps));
74 }
75 else if (pSession->DefinesTimeIntScheme())
76 {
77 m_intSteps = pSession->GetTimeIntScheme().order;
78 }
79 else
80 {
81 m_intSteps = 0;
82 }
83}
84
86{
87 if (m_BndExp.begin()->second->GetExpType() == MultiRegions::e2DH1D)
88 {
89 if (m_field->GetZIDs()[0] == 0)
90 {
91 npointsPlane0 = m_BndExp.begin()->second->GetPlane(0)->GetNpoints();
92 }
93 else
94 {
95 npointsPlane0 = 0;
96 }
97 }
98 else
99 {
100 npointsPlane0 = m_BndExp.begin()->second->GetNpoints();
101 }
102}
103
105 std::map<std::string, NekDouble> &params)
106{
107 MultiRegions::ExpListSharedPtr bndexp = m_BndExp.begin()->second;
108 if (m_coords.size() == 0)
109 {
111 for (size_t k = 0; k < m_spacedim; ++k)
112 {
114 }
115 if (m_spacedim == 2)
116 {
117 bndexp->GetCoords(m_coords[0], m_coords[1]);
118 }
119 else
120 {
121 bndexp->GetCoords(m_coords[0], m_coords[1], m_coords[2]);
122 }
123 // move the centre to the location of pivot
124 std::vector<std::string> xyz = {"X0", "Y0", "Z0"};
125 for (int i = 0; i < m_spacedim; ++i)
126 {
127 if (params.find(xyz[i]) != params.end())
128 {
129 Vmath::Sadd(m_npoints, -params[xyz[i]], m_coords[i], 1,
130 m_coords[i], 1);
131 }
132 }
133 }
134}
135
137 const int numCalls, Array<OneD, Array<OneD, Array<OneD, NekDouble>>> &array)
138{
139 if (m_intSteps == 1)
140 {
141 return;
142 }
143 int nint = std::min(numCalls, m_intSteps);
144 int nlevels = array.size();
145 int dim = array[0].size();
146 int nPts = array[0][0].size();
147 // Check integer for time levels
148 // Note that ExtrapolateArray assumes m_pressureCalls is >= 1
149 // meaning v_EvaluatePressureBCs has been called previously
150 ASSERTL0(nint > 0, "nint must be > 0 when calling ExtrapolateArray.");
151 // Update array
152 RollOver(array);
153 // Extrapolate to outarray
154 for (int i = 0; i < dim; ++i)
155 {
156 Vmath::Smul(nPts, StifflyStable_Betaq_Coeffs[nint - 1][nint - 1],
157 array[nint - 1][i], 1, array[nlevels - 1][i], 1);
158 }
159 for (int n = 0; n < nint - 1; ++n)
160 {
161 for (int i = 0; i < dim; ++i)
162 {
163 Vmath::Svtvp(nPts, StifflyStable_Betaq_Coeffs[nint - 1][n],
164 array[n][i], 1, array[nlevels - 1][i], 1,
165 array[nlevels - 1][i], 1);
166 }
167 }
168}
169
171 std::map<std::string, NekDouble> &params,
172 int npts0)
173{
174 if (npts0 == 0)
175 {
176 return;
177 }
178 NekDouble u0 = 0., v0 = 0., Ax = 0., Ay = 0., Omega = 0., DOmega = 0.;
179 if (params.find("U") != params.end())
180 {
181 u0 = params["U"];
182 }
183 if (params.find("V") != params.end())
184 {
185 v0 = params["V"];
186 }
187 if (params.find("A_x") != params.end())
188 {
189 Ax = params["A_x"];
190 }
191 if (params.find("A_y") != params.end())
192 {
193 Ay = params["A_y"];
194 }
195 if (params.find("Omega_z") != params.end())
196 {
197 Omega = params["Omega_z"];
198 }
199 if (params.find("DOmega_z") != params.end())
200 {
201 DOmega = params["DOmega_z"];
202 }
204 for (size_t k = 0; k < m_spacedim; ++k)
205 {
206 acceleration[k] = Array<OneD, NekDouble>(npts0, 0.0);
207 }
208 // set up pressure condition
209 if (params.find("Omega_z") != params.end() ||
210 params.find("DOmega_z") != params.end())
211 {
212 NekDouble Wz2 = Omega * Omega;
213 Vmath::Svtsvtp(npts0, Wz2, m_coords[0], 1, DOmega, m_coords[1], 1, N[0],
214 1);
215 Vmath::Svtsvtp(npts0, Wz2, m_coords[1], 1, -DOmega, m_coords[0], 1,
216 N[1], 1);
217 }
218 Vmath::Sadd(npts0, -Ax + Omega * v0, N[0], 1, N[0], 1);
219 Vmath::Sadd(npts0, -Ay - Omega * u0, N[1], 1, N[1], 1);
220 if (m_bnddim > 2 && params.find("A_z") != params.end())
221 {
222 Vmath::Sadd(npts0, -params["A_z"], N[2], 1, N[2], 1);
223 }
224}
225
227 const Array<OneD, const Array<OneD, NekDouble>> &fields,
229 std::map<std::string, NekDouble> &params)
230{
231 if (m_intSteps == 0 || params.find("Kinvis") == params.end() ||
232 params["Kinvis"] <= 0. || fields.size() == 0)
233 {
234 return;
235 }
236 NekDouble kinvis = params["Kinvis"];
237 m_bndElmtExps->SetWaveSpace(m_field->GetWaveSpace());
240 // Loop all boundary conditions
241 int nq = m_bndElmtExps->GetTotPoints();
242 for (int i = 0; i < m_spacedim; i++)
243 {
244 Q[i] = Array<OneD, NekDouble>(nq, 0.0);
245 }
246
247 for (int i = 0; i < m_spacedim; i++)
248 {
249 m_field->ExtractPhysToBndElmt(m_nbnd, fields[i], Velocity[i]);
250 }
251
252 // CurlCurl
253 m_bndElmtExps->CurlCurl(Velocity, Q);
254
256 for (int i = 0; i < m_bnddim; i++)
257 {
258 m_field->ExtractElmtToBndPhys(m_nbnd, Q[i], temp);
259 Vmath::Svtvp(m_npoints, -kinvis, temp, 1, N[i], 1, N[i], 1);
260 }
261}
262
264 const Array<OneD, const Array<OneD, NekDouble>> &fields,
266 std::map<std::string, NekDouble> &params)
267{
268 for (int i = 0; i < m_bnddim; ++i)
269 {
271 }
272 AddVisPressureBCs(fields, m_extrapArray[m_intSteps - 1], params);
274 for (int i = 0; i < m_bnddim; i++)
275 {
276 Vmath::Vadd(m_npoints, m_extrapArray[m_intSteps - 1][i], 1, N[i], 1,
277 N[i], 1);
278 }
279}
280
283{
284 int nlevels = input.size();
286 tmp = input[nlevels - 1];
287 for (int n = nlevels - 1; n > 0; --n)
288 {
289 input[n] = input[n - 1];
290 }
291 input[0] = tmp;
292}
293
295 Array<OneD, Array<OneD, NekDouble>> &velocities,
296 std::map<std::string, NekDouble> &params, int npts0)
297{
298 if (npts0 == 0)
299 {
300 return;
301 }
302 // for the wall we need to calculate:
303 // [V_wall]_xyz = [V_frame]_xyz + [Omega X r]_xyz
304 // Note all vectors must be in moving frame coordinates xyz
305 // not in inertial frame XYZ
306
307 // vx = OmegaY*z-OmegaZ*y
308 // vy = OmegaZ*x-OmegaX*z
309 // vz = OmegaX*y-OmegaY*x
310 if (params.find("Omega_z") != params.end())
311 {
312 NekDouble Wz = params["Omega_z"];
313 if (m_BndExp.find(0) != m_BndExp.end())
314 {
315 Vmath::Smul(npts0, -Wz, m_coords[1], 1, velocities[0], 1);
316 }
317 if (m_BndExp.find(1) != m_BndExp.end())
318 {
319 Vmath::Smul(npts0, Wz, m_coords[0], 1, velocities[1], 1);
320 }
321 }
322 if (m_bnddim == 3)
323 {
324 if (params.find("Omega_x") != params.end())
325 {
326 NekDouble Wx = params["Omega_x"];
327 if (m_BndExp.find(2) != m_BndExp.end())
328 {
329 Vmath::Smul(npts0, Wx, m_coords[1], 1, velocities[2], 1);
330 }
331 if (m_BndExp.find(1) != m_BndExp.end())
332 {
333 Vmath::Svtvp(npts0, -Wx, m_coords[2], 1, velocities[1], 1,
334 velocities[1], 1);
335 }
336 }
337 if (params.find("Omega_y") != params.end())
338 {
339 NekDouble Wy = params["Omega_x"];
340 if (m_BndExp.find(0) != m_BndExp.end())
341 {
342 Vmath::Svtvp(npts0, Wy, m_coords[2], 1, velocities[0], 1,
343 velocities[0], 1);
344 }
345 if (m_BndExp.find(2) != m_BndExp.end())
346 {
347 Vmath::Svtvp(npts0, -Wy, m_coords[0], 1, velocities[2], 1,
348 velocities[2], 1);
349 }
350 }
351 }
352
353 // add the translation velocity
354 std::vector<std::string> vars = {"U", "V", "W"};
355 for (int k = 0; k < m_bnddim; ++k)
356 {
357 if (params.find(vars[k]) != params.end() &&
358 m_BndExp.find(k) != m_BndExp.end())
359 {
360 Vmath::Sadd(npts0, params[vars[k]], velocities[k], 1, velocities[k],
361 1);
362 }
363 }
364}
365
366} // namespace Nektar
const NekDouble Omega
#define ASSERTL0(condition, msg)
std::map< int, MultiRegions::ExpListSharedPtr > m_BndExp
MultiRegions::ExpListSharedPtr m_field
static NekDouble StifflyStable_Alpha_Coeffs[3][3]
int m_bnddim
bounday dimensionality
void InitialiseCoords(std::map< std::string, NekDouble > &params)
IncBaseCondition(const LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields, Array< OneD, SpatialDomains::BoundaryConditionShPtr > cond, Array< OneD, MultiRegions::ExpListSharedPtr > exp, int nbnd, int spacedim, int bnddim)
void ExtrapolateArray(const int numCalls, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &array)
void RigidBodyVelocity(Array< OneD, Array< OneD, NekDouble > > &velocities, std::map< std::string, NekDouble > &params, int npts0)
MultiRegions::ExpListSharedPtr m_bndElmtExps
void RollOver(Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &input)
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > m_extrapArray
void AddRigidBodyAcc(Array< OneD, Array< OneD, NekDouble > > &N, std::map< std::string, NekDouble > &params, int npts0)
virtual void v_Initialise(const LibUtilities::SessionReaderSharedPtr &pSession)
static NekDouble StifflyStable_Betaq_Coeffs[3][3]
static NekDouble StifflyStable_Gamma0_Coeffs[3]
void SetNumPointsOnPlane0(int &npointsPlane0)
void AddExtrapVisPressureBCs(const Array< OneD, const Array< OneD, NekDouble > > &fields, Array< OneD, Array< OneD, NekDouble > > &N, std::map< std::string, NekDouble > &params)
void AddVisPressureBCs(const Array< OneD, const Array< OneD, NekDouble > > &fields, Array< OneD, Array< OneD, NekDouble > > &N, std::map< std::string, NekDouble > &params)
Array< OneD, Array< OneD, NekDouble > > m_coords
Provides a generic Factory class.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
IncBCFactory & GetIncBCFactory()
void Svtsvtp(int n, const T alpha, const T *x, int incx, const T beta, const T *y, int incy, T *z, int incz)
Svtsvtp (scalar times vector plus scalar times vector):
Definition Vmath.hpp:473
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:396
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition Vmath.hpp:180
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:100
void Zero(int n, T *x, const int incx)
Zero vector.
Definition Vmath.hpp:273
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha + x.
Definition Vmath.hpp:194