Nektar++
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->DefinesSolverInfo("TimeIntegrationMethod") ||
76 pSession->DefinesTimeIntScheme())
77 {
78 std::string method;
79 if (pSession->DefinesTimeIntScheme())
80 {
81 auto timeInt = pSession->GetTimeIntScheme();
82 method = timeInt.method + "Order" + std::to_string(timeInt.order);
83 }
84 else
85 {
86 method = pSession->GetSolverInfo("TimeIntegrationMethod");
87 }
88
89 if (method == "IMEXOrder1")
90 {
91 m_intSteps = 1;
92 }
93 else if (method == "IMEXOrder2")
94 {
95 m_intSteps = 2;
96 }
97 else
98 {
99 m_intSteps = 3;
100 }
101 }
102 else
103 {
104 m_intSteps = 0;
105 }
106}
107
109{
110 if (m_BndExp.begin()->second->GetExpType() == MultiRegions::e2DH1D)
111 {
112 if (m_field->GetZIDs()[0] == 0)
113 {
114 npointsPlane0 = m_BndExp.begin()->second->GetPlane(0)->GetNpoints();
115 }
116 else
117 {
118 npointsPlane0 = 0;
119 }
120 }
121 else
122 {
123 npointsPlane0 = m_BndExp.begin()->second->GetNpoints();
124 }
125}
126
128 std::map<std::string, NekDouble> &params)
129{
130 MultiRegions::ExpListSharedPtr bndexp = m_BndExp.begin()->second;
131 if (m_coords.size() == 0)
132 {
134 for (size_t k = 0; k < m_spacedim; ++k)
135 {
137 }
138 if (m_spacedim == 2)
139 {
140 bndexp->GetCoords(m_coords[0], m_coords[1]);
141 }
142 else
143 {
144 bndexp->GetCoords(m_coords[0], m_coords[1], m_coords[2]);
145 }
146 // move the centre to the location of pivot
147 std::vector<std::string> xyz = {"X0", "Y0", "Z0"};
148 for (int i = 0; i < m_spacedim; ++i)
149 {
150 if (params.find(xyz[i]) != params.end())
151 {
152 Vmath::Sadd(m_npoints, -params[xyz[i]], m_coords[i], 1,
153 m_coords[i], 1);
154 }
155 }
156 }
157}
158
160 const int numCalls, Array<OneD, Array<OneD, Array<OneD, NekDouble>>> &array)
161{
162 if (m_intSteps == 1)
163 {
164 return;
165 }
166 int nint = std::min(numCalls, m_intSteps);
167 int nlevels = array.size();
168 int dim = array[0].size();
169 int nPts = array[0][0].size();
170 // Check integer for time levels
171 // Note that ExtrapolateArray assumes m_pressureCalls is >= 1
172 // meaning v_EvaluatePressureBCs has been called previously
173 ASSERTL0(nint > 0, "nint must be > 0 when calling ExtrapolateArray.");
174 // Update array
175 RollOver(array);
176 // Extrapolate to outarray
177 for (int i = 0; i < dim; ++i)
178 {
179 Vmath::Smul(nPts, StifflyStable_Betaq_Coeffs[nint - 1][nint - 1],
180 array[nint - 1][i], 1, array[nlevels - 1][i], 1);
181 }
182 for (int n = 0; n < nint - 1; ++n)
183 {
184 for (int i = 0; i < dim; ++i)
185 {
186 Vmath::Svtvp(nPts, StifflyStable_Betaq_Coeffs[nint - 1][n],
187 array[n][i], 1, array[nlevels - 1][i], 1,
188 array[nlevels - 1][i], 1);
189 }
190 }
191}
192
194 std::map<std::string, NekDouble> &params,
195 int npts0)
196{
197 if (npts0 == 0)
198 {
199 return;
200 }
202 for (size_t k = 0; k < m_spacedim; ++k)
203 {
204 acceleration[k] = Array<OneD, NekDouble>(npts0, 0.0);
205 }
206
207 // set up pressure condition
208 if (params.find("Omega_z") != params.end())
209 {
210 NekDouble Wz2 = params["Omega_z"] * params["Omega_z"];
211 NekDouble dWz = 0.;
212 if (params.find("DOmega_z") != params.end())
213 {
214 dWz = params["DOmega_z"];
215 }
216 Vmath::Svtsvtp(npts0, Wz2, m_coords[0], 1, dWz, m_coords[1], 1, N[0],
217 1);
218 Vmath::Svtsvtp(npts0, Wz2, m_coords[1], 1, -dWz, m_coords[0], 1, N[1],
219 1);
220 }
221 std::vector<std::string> vars = {"A_x", "A_y", "A_z"};
222 for (int k = 0; k < m_bnddim; ++k)
223 {
224 if (params.find(vars[k]) != params.end())
225 {
226 Vmath::Sadd(npts0, -params[vars[k]], N[k], 1, N[k], 1);
227 }
228 }
229}
230
232 const Array<OneD, const Array<OneD, NekDouble>> &fields,
234 std::map<std::string, NekDouble> &params)
235{
236 if (m_intSteps == 0 || params.find("Kinvis") == params.end() ||
237 params["Kinvis"] <= 0. || fields.size() == 0)
238 {
239 return;
240 }
241 NekDouble kinvis = params["Kinvis"];
242 m_bndElmtExps->SetWaveSpace(m_field->GetWaveSpace());
245 // Loop all boundary conditions
246 int nq = m_bndElmtExps->GetTotPoints();
247 for (int i = 0; i < m_spacedim; i++)
248 {
249 Q[i] = Array<OneD, NekDouble>(nq, 0.0);
250 }
251
252 for (int i = 0; i < m_spacedim; i++)
253 {
254 m_field->ExtractPhysToBndElmt(m_nbnd, fields[i], Velocity[i]);
255 }
256
257 // CurlCurl
258 m_bndElmtExps->CurlCurl(Velocity, Q);
259
261 for (int i = 0; i < m_bnddim; i++)
262 {
263 m_field->ExtractElmtToBndPhys(m_nbnd, Q[i],
264 m_viscous[m_intSteps - 1][i]);
265 }
267 for (int i = 0; i < m_bnddim; i++)
268 {
269 Vmath::Svtvp(m_npoints, -kinvis, m_viscous[m_intSteps - 1][i], 1, N[i],
270 1, N[i], 1);
271 }
272}
273
276{
277 int nlevels = input.size();
279 tmp = input[nlevels - 1];
280 for (int n = nlevels - 1; n > 0; --n)
281 {
282 input[n] = input[n - 1];
283 }
284 input[0] = tmp;
285}
286
288 Array<OneD, Array<OneD, NekDouble>> &velocities,
289 std::map<std::string, NekDouble> &params, int npts0)
290{
291 if (npts0 == 0)
292 {
293 return;
294 }
295 // for the wall we need to calculate:
296 // [V_wall]_xyz = [V_frame]_xyz + [Omega X r]_xyz
297 // Note all vectors must be in moving frame coordinates xyz
298 // not in inertial frame XYZ
299
300 // vx = OmegaY*z-OmegaZ*y
301 // vy = OmegaZ*x-OmegaX*z
302 // vz = OmegaX*y-OmegaY*x
303 if (params.find("Omega_z") != params.end())
304 {
305 NekDouble Wz = params["Omega_z"];
306 if (m_BndExp.find(0) != m_BndExp.end())
307 {
308 Vmath::Smul(npts0, -Wz, m_coords[1], 1, velocities[0], 1);
309 }
310 if (m_BndExp.find(1) != m_BndExp.end())
311 {
312 Vmath::Smul(npts0, Wz, m_coords[0], 1, velocities[1], 1);
313 }
314 }
315 if (m_bnddim == 3)
316 {
317 if (params.find("Omega_x") != params.end())
318 {
319 NekDouble Wx = params["Omega_x"];
320 if (m_BndExp.find(2) != m_BndExp.end())
321 {
322 Vmath::Smul(npts0, Wx, m_coords[1], 1, velocities[2], 1);
323 }
324 if (m_BndExp.find(1) != m_BndExp.end())
325 {
326 Vmath::Svtvp(npts0, -Wx, m_coords[2], 1, velocities[1], 1,
327 velocities[1], 1);
328 }
329 }
330 if (params.find("Omega_y") != params.end())
331 {
332 NekDouble Wy = params["Omega_x"];
333 if (m_BndExp.find(0) != m_BndExp.end())
334 {
335 Vmath::Svtvp(npts0, Wy, m_coords[2], 1, velocities[0], 1,
336 velocities[0], 1);
337 }
338 if (m_BndExp.find(2) != m_BndExp.end())
339 {
340 Vmath::Svtvp(npts0, -Wy, m_coords[0], 1, velocities[2], 1,
341 velocities[2], 1);
342 }
343 }
344 }
345
346 // add the translation velocity
347 std::vector<std::string> vars = {"U", "V", "W"};
348 for (int k = 0; k < m_bnddim; ++k)
349 {
350 if (params.find(vars[k]) != params.end() &&
351 m_BndExp.find(k) != m_BndExp.end())
352 {
353 Vmath::Sadd(npts0, params[vars[k]], velocities[k], 1, velocities[k],
354 1);
355 }
356 }
357}
358
359} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
std::map< int, MultiRegions::ExpListSharedPtr > m_BndExp
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > m_viscous
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)
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 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()
double NekDouble
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 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 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