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 }
179 for (size_t k = 0; k < m_spacedim; ++k)
180 {
181 acceleration[k] = Array<OneD, NekDouble>(npts0, 0.0);
182 }
183
184 // set up pressure condition
185 if (params.find("Omega_z") != params.end())
186 {
187 NekDouble Wz2 = params["Omega_z"] * params["Omega_z"];
188 NekDouble dWz = 0.;
189 if (params.find("DOmega_z") != params.end())
190 {
191 dWz = params["DOmega_z"];
192 }
193 Vmath::Svtsvtp(npts0, Wz2, m_coords[0], 1, dWz, m_coords[1], 1, N[0],
194 1);
195 Vmath::Svtsvtp(npts0, Wz2, m_coords[1], 1, -dWz, m_coords[0], 1, N[1],
196 1);
197 }
198 std::vector<std::string> vars = {"A_x", "A_y", "A_z"};
199 for (int k = 0; k < m_bnddim; ++k)
200 {
201 if (params.find(vars[k]) != params.end())
202 {
203 Vmath::Sadd(npts0, -params[vars[k]], N[k], 1, N[k], 1);
204 }
205 }
206}
207
209 const Array<OneD, const Array<OneD, NekDouble>> &fields,
211 std::map<std::string, NekDouble> &params)
212{
213 if (m_intSteps == 0 || params.find("Kinvis") == params.end() ||
214 params["Kinvis"] <= 0. || fields.size() == 0)
215 {
216 return;
217 }
218 NekDouble kinvis = params["Kinvis"];
219 m_bndElmtExps->SetWaveSpace(m_field->GetWaveSpace());
222 // Loop all boundary conditions
223 int nq = m_bndElmtExps->GetTotPoints();
224 for (int i = 0; i < m_spacedim; i++)
225 {
226 Q[i] = Array<OneD, NekDouble>(nq, 0.0);
227 }
228
229 for (int i = 0; i < m_spacedim; i++)
230 {
231 m_field->ExtractPhysToBndElmt(m_nbnd, fields[i], Velocity[i]);
232 }
233
234 // CurlCurl
235 m_bndElmtExps->CurlCurl(Velocity, Q);
236
238 for (int i = 0; i < m_bnddim; i++)
239 {
240 m_field->ExtractElmtToBndPhys(m_nbnd, Q[i],
241 m_viscous[m_intSteps - 1][i]);
242 }
244 for (int i = 0; i < m_bnddim; i++)
245 {
246 Vmath::Svtvp(m_npoints, -kinvis, m_viscous[m_intSteps - 1][i], 1, N[i],
247 1, N[i], 1);
248 }
249}
250
253{
254 int nlevels = input.size();
256 tmp = input[nlevels - 1];
257 for (int n = nlevels - 1; n > 0; --n)
258 {
259 input[n] = input[n - 1];
260 }
261 input[0] = tmp;
262}
263
265 Array<OneD, Array<OneD, NekDouble>> &velocities,
266 std::map<std::string, NekDouble> &params, int npts0)
267{
268 if (npts0 == 0)
269 {
270 return;
271 }
272 // for the wall we need to calculate:
273 // [V_wall]_xyz = [V_frame]_xyz + [Omega X r]_xyz
274 // Note all vectors must be in moving frame coordinates xyz
275 // not in inertial frame XYZ
276
277 // vx = OmegaY*z-OmegaZ*y
278 // vy = OmegaZ*x-OmegaX*z
279 // vz = OmegaX*y-OmegaY*x
280 if (params.find("Omega_z") != params.end())
281 {
282 NekDouble Wz = params["Omega_z"];
283 if (m_BndExp.find(0) != m_BndExp.end())
284 {
285 Vmath::Smul(npts0, -Wz, m_coords[1], 1, velocities[0], 1);
286 }
287 if (m_BndExp.find(1) != m_BndExp.end())
288 {
289 Vmath::Smul(npts0, Wz, m_coords[0], 1, velocities[1], 1);
290 }
291 }
292 if (m_bnddim == 3)
293 {
294 if (params.find("Omega_x") != params.end())
295 {
296 NekDouble Wx = params["Omega_x"];
297 if (m_BndExp.find(2) != m_BndExp.end())
298 {
299 Vmath::Smul(npts0, Wx, m_coords[1], 1, velocities[2], 1);
300 }
301 if (m_BndExp.find(1) != m_BndExp.end())
302 {
303 Vmath::Svtvp(npts0, -Wx, m_coords[2], 1, velocities[1], 1,
304 velocities[1], 1);
305 }
306 }
307 if (params.find("Omega_y") != params.end())
308 {
309 NekDouble Wy = params["Omega_x"];
310 if (m_BndExp.find(0) != m_BndExp.end())
311 {
312 Vmath::Svtvp(npts0, Wy, m_coords[2], 1, velocities[0], 1,
313 velocities[0], 1);
314 }
315 if (m_BndExp.find(2) != m_BndExp.end())
316 {
317 Vmath::Svtvp(npts0, -Wy, m_coords[0], 1, velocities[2], 1,
318 velocities[2], 1);
319 }
320 }
321 }
322
323 // add the translation velocity
324 std::vector<std::string> vars = {"U", "V", "W"};
325 for (int k = 0; k < m_bnddim; ++k)
326 {
327 if (params.find(vars[k]) != params.end() &&
328 m_BndExp.find(k) != m_BndExp.end())
329 {
330 Vmath::Sadd(npts0, params[vars[k]], velocities[k], 1, velocities[k],
331 1);
332 }
333 }
334}
335
336} // namespace Nektar
#define ASSERTL0(condition, msg)
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()
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