Nektar++
ProcessQCriterion.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: ProcessQCriterion.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: Computes Q Criterion field.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include <iostream>
36#include <string>
37using namespace std;
38
40
41#include "ProcessQCriterion.h"
42
43namespace Nektar::FieldUtils
44{
45
49 "Computes Q-Criterion.");
50
52{
53}
54
56{
57}
58
59void ProcessQCriterion::v_Process(po::variables_map &vm)
60{
61 m_f->SetUpExp(vm);
62
63 int nfields = m_f->m_variables.size();
64 m_f->m_variables.push_back("Q");
65 // Skip in case of empty partition
66 if (m_f->m_exp[0]->GetNumElmts() == 0)
67 {
68 return;
69 }
70
71 int i, s;
72 int expdim = m_f->m_graph->GetMeshDimension();
73 int spacedim = expdim + (m_f->m_numHomogeneousDir);
74
76 spacedim == 3 || spacedim == 2,
77 "ProcessQCriterion must be computed for a 2D, quasi-3D, or 3D case.");
78
79 int npoints = m_f->m_exp[0]->GetNpoints();
80
81 Array<OneD, Array<OneD, NekDouble>> grad(spacedim * spacedim);
82
83 Array<OneD, NekDouble> omega(npoints, 0.);
84 Array<OneD, NekDouble> S(npoints, 0.);
85
86 // Will store the Q-Criterion
87 Array<OneD, NekDouble> outfield(npoints);
88
89 int nstrips;
90
91 m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
92
93 for (i = 0; i < spacedim * spacedim; ++i)
94 {
95 grad[i] = Array<OneD, NekDouble>(npoints);
96 }
97
99
100 for (s = 0; s < nstrips; ++s) // homogeneous strip varient
101 {
102 Exp = m_f->AppendExpList(m_f->m_numHomogeneousDir);
103 auto it = m_f->m_exp.begin() + s * (nfields + 1) + nfields;
104 m_f->m_exp.insert(it, Exp);
105 }
106
107 NekDouble fac = 0.5;
108 if (spacedim == 2)
109 {
110 for (s = 0; s < nstrips; ++s) // homogeneous strip varient
111 {
112 for (i = 0; i < spacedim; ++i)
113 {
114 m_f->m_exp[s * nfields + i]->PhysDeriv(
115 m_f->m_exp[s * nfields + i]->GetPhys(), grad[i * spacedim],
116 grad[i * spacedim + 1]);
117 }
118
119 // W_z = Vx - Uy
120 Vmath::Vsub(npoints, grad[1 * spacedim + 0], 1,
121 grad[0 * spacedim + 1], 1, outfield, 1);
122 // W_z^2
123 Vmath::Vmul(npoints, outfield, 1, outfield, 1, omega, 1);
124
125 // Ux^2
126 Vmath::Vmul(npoints, grad[0 * spacedim + 0], 1,
127 grad[0 * spacedim + 0], 1, S, 1);
128 // Vy^2
129 Vmath::Vvtvp(npoints, grad[1 * spacedim + 1], 1,
130 grad[1 * spacedim + 1], 1, S, 1, S, 1);
131
132 // Vx + Uy
133 Vmath::Vadd(npoints, grad[1 * spacedim + 0], 1,
134 grad[0 * spacedim + 1], 1, outfield, 1);
135 Vmath::Vmul(npoints, outfield, 1, outfield, 1, outfield, 1);
136 Vmath::Svtvp(npoints, fac, outfield, 1, S, 1, S, 1);
137
138 Vmath::Svtvm(npoints, fac, omega, 1, S, 1, outfield, 1);
139 Vmath::Smul(npoints, fac, outfield, 1, outfield, 1);
140
141 int fid = s * (nfields + 1) + nfields;
142 Vmath::Vcopy(npoints, outfield, 1, m_f->m_exp[fid]->UpdatePhys(),
143 1);
144 Exp->FwdTransLocalElmt(outfield, m_f->m_exp[fid]->UpdateCoeffs());
145 }
146 }
147 else if (spacedim == 3)
148 {
149 Array<OneD, NekDouble> outfield1(npoints);
150 Array<OneD, NekDouble> outfield2(npoints);
151 Array<OneD, NekDouble> outfield3(npoints);
152 for (s = 0; s < nstrips; ++s) // homogeneous strip varient
153 {
154 for (i = 0; i < spacedim; ++i)
155 {
156 m_f->m_exp[s * nfields + i]->PhysDeriv(
157 m_f->m_exp[s * nfields + i]->GetPhys(), grad[i * spacedim],
158 grad[i * spacedim + 1], grad[i * spacedim + 2]);
159 }
160
161 // W_x = Wy - Vz
162 Vmath::Vsub(npoints, grad[2 * spacedim + 1], 1,
163 grad[1 * spacedim + 2], 1, outfield1, 1);
164 // W_x^2
165 Vmath::Vmul(npoints, outfield1, 1, outfield1, 1, outfield1, 1);
166
167 // W_y = Uz - Wx
168 Vmath::Vsub(npoints, grad[0 * spacedim + 2], 1,
169 grad[2 * spacedim + 0], 1, outfield2, 1);
170 // W_y^2
171 Vmath::Vmul(npoints, outfield2, 1, outfield2, 1, outfield2, 1);
172
173 // W_z = Vx - Uy
174 Vmath::Vsub(npoints, grad[1 * spacedim + 0], 1,
175 grad[0 * spacedim + 1], 1, outfield3, 1);
176 // W_z^2
177 Vmath::Vmul(npoints, outfield3, 1, outfield3, 1, outfield3, 1);
178
179 // Omega = 0.5*(W_x^2 + W_y^2 + W_z^2)
180 Vmath::Vadd(npoints, outfield1, 1, outfield2, 1, omega, 1);
181 Vmath::Vadd(npoints, omega, 1, outfield3, 1, omega, 1);
182 Vmath::Smul(npoints, fac, omega, 1, omega, 1);
183
184 // Ux^2
185 Vmath::Vmul(npoints, grad[0 * spacedim + 0], 1,
186 grad[0 * spacedim + 0], 1, outfield1, 1);
187 // Vy^2
188 Vmath::Vmul(npoints, grad[1 * spacedim + 1], 1,
189 grad[1 * spacedim + 1], 1, outfield2, 1);
190 // Wz^2
191 Vmath::Vmul(npoints, grad[2 * spacedim + 2], 1,
192 grad[2 * spacedim + 2], 1, outfield3, 1);
193
194 //
195 Vmath::Vadd(npoints, outfield1, 1, outfield2, 1, S, 1);
196 Vmath::Vadd(npoints, S, 1, outfield3, 1, S, 1);
197
198 // Wy + Vz
199 Vmath::Vadd(npoints, grad[2 * spacedim + 1], 1,
200 grad[1 * spacedim + 2], 1, outfield1, 1);
201 Vmath::Vmul(npoints, outfield1, 1, outfield1, 1, outfield1, 1);
202
203 // Uz + Wx
204 Vmath::Vadd(npoints, grad[0 * spacedim + 2], 1,
205 grad[2 * spacedim + 0], 1, outfield2, 1);
206 Vmath::Vmul(npoints, outfield2, 1, outfield2, 1, outfield2, 1);
207
208 // Vx + Uy
209 Vmath::Vadd(npoints, grad[1 * spacedim + 0], 1,
210 grad[0 * spacedim + 1], 1, outfield3, 1);
211 Vmath::Vmul(npoints, outfield3, 1, outfield3, 1, outfield3, 1);
212
213 Vmath::Vadd(npoints, outfield1, 1, outfield2, 1, outfield2, 1);
214 Vmath::Vadd(npoints, outfield2, 1, outfield3, 1, outfield3, 1);
215
216 Vmath::Smul(npoints, fac, outfield3, 1, outfield3, 1);
217
218 Vmath::Vadd(npoints, outfield3, 1, S, 1, S, 1);
219 Vmath::Vsub(npoints, omega, 1, S, 1, outfield, 1);
220
221 Vmath::Smul(npoints, fac, outfield, 1, outfield, 1);
222
223 int fid = s * (nfields + 1) + nfields;
224 Vmath::Vcopy(npoints, outfield, 1, m_f->m_exp[fid]->UpdatePhys(),
225 1);
226 Exp->FwdTransLocalElmt(outfield, m_f->m_exp[fid]->UpdateCoeffs());
227 }
228 }
229}
230
231} // namespace Nektar::FieldUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
Abstract base class for processing modules.
Definition: Module.h:301
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
void v_Process(po::variables_map &vm) override
Write mesh to output file.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:1026
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
double NekDouble
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:72
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 Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.hpp:366
void Svtvm(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Svtvm (scalar times vector minus vector): z = alpha*x - y.
Definition: Vmath.hpp:424
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 Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825
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:220
STL namespace.