Nektar++
ProcessL2Criterion.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: ProcessL2Criterion.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 Lambda 2 Criterion field.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include <iostream>
36#include <string>
37using namespace std;
38
39#include <boost/core/ignore_unused.hpp>
40
42
43#include "ProcessL2Criterion.h"
44
45namespace Nektar
46{
47namespace FieldUtils
48{
49
53 "Computes Lambda 2 Criterion.");
54
56{
57}
58
60{
61}
62
63/**
64 * @brief Calculates eigenvalues of a 3x3 Symmetric matrix.
65 *
66 * @param d1, d2, d3 - matrix diagonal entries at [0,0], [1,1] and [2,2]
67 * @param a - matrix value at [0,1] and [1,0]
68 * @param b - matrix value at [0,2] and [2,0]
69 * @param c - matrix value at [1,2] and [2,1]
70 * @param l1, l2, l3 the computed eigenvalues, ordered l3 >= l2 >= l1
71 */
74 NekDouble &l3)
75{
76 NekDouble p = a * a + b * b + c * c;
77 if (p == 0)
78 {
79 l1 = d1;
80 l2 = d2;
81 l3 = d3;
82 if (l1 > l3)
83 {
84 swap(l1, l3);
85 }
86 if (l1 > l2)
87 {
88 swap(l1, l2);
89 }
90 if (l2 > l3)
91 {
92 swap(l2, l3);
93 }
94 }
95 else
96 {
97 NekDouble q = (d1 + d2 + d3) / 3.0;
98 p = (d1 - q) * (d1 - q) + (d2 - q) * (d2 - q) + (d3 - q) * (d3 - q) +
99 2.0 * p;
100 p = sqrt(p / 6.0);
101 NekDouble r =
102 -0.5 *
103 (a * a * d3 - a * a * q - 2.0 * a * b * c + b * b * d2 - b * b * q +
104 c * c * d1 - c * c * q - d1 * d2 * d3 + d1 * d2 * q + d1 * d3 * q -
105 d1 * q * q + d2 * d3 * q - d2 * q * q - d3 * q * q + q * q * q) /
106 (p * p * p);
107
108 NekDouble phi = 0;
109 if (r <= -1)
110 {
111 phi = M_PI / 3.0;
112 }
113 else if (r >= 1)
114 {
115 phi = 0.0;
116 }
117 else
118 {
119 phi = acos(r) / 3.0;
120 }
121
122 // the eigenvalues satisfy eig3 >= eig2 >= eig1
123 l3 = q + 2.0 * p * cos(phi);
124 l1 = q + 2.0 * p * cos(phi + (2.0 * M_PI / 3.0));
125 // since trace(A) = eig1 + eig2 + eig3
126 l2 = 3.0 * q - l1 - l3;
127 }
128}
129
130void ProcessL2Criterion::v_Process(po::variables_map &vm)
131{
132 m_f->SetUpExp(vm);
133
134 auto nfields = m_f->m_variables.size();
135 m_f->m_variables.push_back("L2");
136
137 // Skip in case of empty partition
138 if (m_f->m_exp[0]->GetNumElmts() == 0)
139 {
140 return;
141 }
142
143 int i, s;
144 int expdim = m_f->m_graph->GetMeshDimension();
145 int spacedim = expdim + (m_f->m_numHomogeneousDir);
146
147 ASSERTL0(
148 spacedim == 3,
149 "ProcessL2Criterion must be computed for a 3D (or quasi-3D) case.");
150
151 int npoints = m_f->m_exp[0]->GetNpoints();
152
153 Array<OneD, Array<OneD, NekDouble>> grad(spacedim * spacedim);
154
155 // Will store the Lambdas
156 NekDouble a00, a11, a22, a01, a02, a12;
157 NekDouble t1, t2, t3, t4, t5, t6, t7, t8, t10, t11, t13, t14, t15;
158 NekDouble outfield1, outfield3;
159 Array<OneD, NekDouble> outfield2(npoints);
160
161 int nstrips;
162 m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
163
164 for (i = 0; i < spacedim * spacedim; ++i)
165 {
166 grad[i] = Array<OneD, NekDouble>(npoints);
167 }
168
170
171 for (s = 0; s < nstrips; ++s) // homogeneous strip varient
172 {
173 Exp = m_f->AppendExpList(m_f->m_numHomogeneousDir);
174 auto it = m_f->m_exp.begin() + s * (nfields + 1) + nfields;
175 m_f->m_exp.insert(it, Exp);
176 }
177
178 for (s = 0; s < nstrips; ++s) // homogeneous strip varient
179 {
180 for (i = 0; i < spacedim; ++i)
181 {
182 m_f->m_exp[s * nfields + i]->PhysDeriv(
183 m_f->m_exp[s * nfields + i]->GetPhys(), grad[i * spacedim],
184 grad[i * spacedim + 1], grad[i * spacedim + 2]);
185 }
186
187 /*
188 * For each node calculate the S^2+W^2 tensor
189 * where S and W are the symmetric and the skew-symmetric
190 * parts of the velocity gradient tensor D=grad(u),
191 * S=0.5(D+transpose(D)) and W=0.5((D-transpose(D)))
192 */
193 for (int j = 0; j < npoints; ++j)
194 {
195 // diff(u,y) + diff(v,x);
196 t1 = grad[0 * spacedim + 1][j] + grad[1 * spacedim + 0][j];
197 // diff(u,z) + diff(w,x);
198 t2 = grad[0 * spacedim + 2][j] + grad[2 * spacedim + 0][j];
199 // diff(u,y) - diff(v,x);
200 t3 = grad[0 * spacedim + 1][j] - grad[1 * spacedim + 0][j];
201 // diff(u,z) - diff(w,x);
202 t4 = grad[0 * spacedim + 2][j] - grad[2 * spacedim + 0][j];
203
204 t5 = t2 * t2;
205 t6 = t4 * t4;
206 t7 = t3 * t3;
207 t8 = t1 * t1;
208
209 // diff(w,y) + diff(v,z);
210 t10 = grad[2 * spacedim + 1][j] + grad[1 * spacedim + 2][j];
211 // diff(w,y) - diff(v,z);
212 t11 = grad[2 * spacedim + 1][j] - grad[1 * spacedim + 2][j];
213
214 t13 = 0.25 * (t10 * t2 + t11 * t4) +
215 0.5 * t1 *
216 (grad[0 * spacedim + 0][j] + grad[1 * spacedim + 1][j]);
217 t14 = 0.5 * t2 *
218 (grad[0 * spacedim + 0][j] + grad[2 * spacedim + 2][j]) +
219 0.25 * (t1 * t10 - t11 * t3);
220 t15 = t10 * t10;
221 t11 = t11 * t11;
222 t1 = 0.5 * t10 *
223 (grad[1 * spacedim + 1][j] + grad[2 * spacedim + 2][j]) -
224 0.25 * (-t1 * t2 + t3 * t4);
225
226 a00 = 0.25 * (t5 - t6 - t7 + t8) +
227 grad[0 * spacedim + 0][j] * grad[0 * spacedim + 0][j];
228 a01 = t13;
229 a02 = t14;
230 a11 = 0.25 * (-t7 + t8 + t15 - t11) +
231 grad[1 * spacedim + 1][j] * grad[1 * spacedim + 1][j];
232 a12 = t1;
233 a22 = 0.25 * (t5 - t6 + t15 - t11) +
234 grad[2 * spacedim + 2][j] * grad[2 * spacedim + 2][j];
235
236 // Compute the eigenvalues of a symmetric 3x3 matrix
237 MatSymEVals(a00, a11, a22, a01, a02, a12, outfield1, outfield2[j],
238 outfield3);
239 }
240
241 int fid = s * (nfields + 1) + nfields;
242 Vmath::Vcopy(npoints, outfield2, 1, m_f->m_exp[fid]->UpdatePhys(), 1);
243 m_f->m_exp[fid]->FwdTransLocalElmt(outfield2,
244 m_f->m_exp[fid]->UpdateCoeffs());
245 }
246}
247} // namespace FieldUtils
248} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
virtual void v_Process(po::variables_map &vm) override
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
Abstract base class for processing modules.
Definition: Module.h:292
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
void MatSymEVals(NekDouble d1, NekDouble d2, NekDouble d3, NekDouble a, NekDouble b, NekDouble c, NekDouble &l1, NekDouble &l2, NekDouble &l3)
Calculates eigenvalues of a 3x3 Symmetric matrix.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:991
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::vector< double > q(NPUPPER *NPUPPER)
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1191
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:294