Nektar++
ProcessVorticity.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: ProcessVorticity.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 vorticity field.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include <iostream>
36#include <string>
37using namespace std;
38
41
42#include "ProcessMapping.h"
43#include "ProcessVorticity.h"
44
45namespace Nektar::FieldUtils
46{
47
51 "Computes vorticity field.");
52
54{
55}
56
58{
59}
60
61void ProcessVorticity::v_Process(po::variables_map &vm)
62{
63 m_f->SetUpExp(vm);
64
65 int i, s;
66 int expdim = m_f->m_graph->GetMeshDimension();
67 m_spacedim = expdim;
68 if ((m_f->m_numHomogeneousDir) == 1 || (m_f->m_numHomogeneousDir) == 2)
69 {
70 m_spacedim = 3;
71 }
72 int nfields = m_f->m_variables.size();
74 "Error: Vorticity for a 1D problem cannot be computed");
75 int addfields = (m_spacedim == 2) ? 1 : 3;
76
77 // Append field names
78 if (addfields == 1)
79 {
80 m_f->m_variables.push_back("W_z");
81 }
82 else
83 {
84 m_f->m_variables.push_back("W_x");
85 m_f->m_variables.push_back("W_y");
86 m_f->m_variables.push_back("W_z");
87 }
88
89 // Skip in case of empty partition
90 if (m_f->m_exp[0]->GetNumElmts() == 0)
91 {
92 return;
93 }
94 int npoints = m_f->m_exp[0]->GetNpoints();
96 Array<OneD, Array<OneD, NekDouble>> outfield(addfields);
97
98 int nstrips;
99
100 m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
101
102 for (i = 0; i < m_spacedim * m_spacedim; ++i)
103 {
104 grad[i] = Array<OneD, NekDouble>(npoints);
105 }
106
107 for (i = 0; i < addfields; ++i)
108 {
109 outfield[i] = Array<OneD, NekDouble>(npoints);
110 }
111
113 for (int i = 0; i < m_spacedim; i++)
114 {
115 tmp[i] = Array<OneD, NekDouble>(npoints);
116 }
117
118 // add in new fields
119 for (s = 0; s < nstrips; ++s)
120 {
121 for (i = 0; i < addfields; ++i)
122 {
124 m_f->AppendExpList(m_f->m_numHomogeneousDir);
125 m_f->m_exp.insert(m_f->m_exp.begin() + s * (nfields + addfields) +
126 nfields + i,
127 Exp);
128 }
129 }
130
131 // Get mapping
133
134 for (s = 0; s < nstrips; ++s) // homogeneous strip varient
135 {
136 // Get velocity and convert to Cartesian system,
137 // if it is still in transformed system
139 GetVelocity(vel, nfields + addfields, s);
140 if (m_f->m_fieldMetaDataMap.count("MappingCartesianVel"))
141 {
142 if (m_f->m_fieldMetaDataMap["MappingCartesianVel"] == "False")
143 {
144 // Initialize arrays and copy velocity
145 if (m_f->m_exp[0]->GetWaveSpace())
146 {
147 for (int i = 0; i < m_spacedim; ++i)
148 {
149 m_f->m_exp[0]->HomogeneousBwdTrans(npoints, vel[i],
150 vel[i]);
151 }
152 }
153 // Convert velocity to cartesian system
154 mapping->ContravarToCartesian(vel, vel);
155 // Convert back to wavespace if necessary
156 if (m_f->m_exp[0]->GetWaveSpace())
157 {
158 for (int i = 0; i < m_spacedim; ++i)
159 {
160 m_f->m_exp[0]->HomogeneousFwdTrans(npoints, vel[i],
161 vel[i]);
162 }
163 }
164 }
165 }
166
167 // Calculate Gradient & Vorticity
168 if (m_spacedim == 2)
169 {
170 for (i = 0; i < m_spacedim; ++i)
171 {
172 m_f->m_exp[s * nfields + i]->PhysDeriv(vel[i], tmp[0], tmp[1]);
173 mapping->CovarToCartesian(tmp, tmp);
174 for (int j = 0; j < m_spacedim; j++)
175 {
176 Vmath::Vcopy(npoints, tmp[j], 1, grad[i * m_spacedim + j],
177 1);
178 }
179 }
180 // W_z = Vx - Uy
181 Vmath::Vsub(npoints, grad[1 * m_spacedim + 0], 1,
182 grad[0 * m_spacedim + 1], 1, outfield[0], 1);
183 }
184 else
185 {
186 for (i = 0; i < m_spacedim; ++i)
187 {
188 m_f->m_exp[s * nfields + i]->PhysDeriv(vel[i], tmp[0], tmp[1],
189 tmp[2]);
190 mapping->CovarToCartesian(tmp, tmp);
191 for (int j = 0; j < m_spacedim; j++)
192 {
193 Vmath::Vcopy(npoints, tmp[j], 1, grad[i * m_spacedim + j],
194 1);
195 }
196 }
197
198 // W_x = Wy - Vz
199 Vmath::Vsub(npoints, grad[2 * m_spacedim + 1], 1,
200 grad[1 * m_spacedim + 2], 1, outfield[0], 1);
201 // W_y = Uz - Wx
202 Vmath::Vsub(npoints, grad[0 * m_spacedim + 2], 1,
203 grad[2 * m_spacedim + 0], 1, outfield[1], 1);
204 // W_z = Vx - Uy
205 Vmath::Vsub(npoints, grad[1 * m_spacedim + 0], 1,
206 grad[0 * m_spacedim + 1], 1, outfield[2], 1);
207 }
208
209 for (i = 0; i < addfields; ++i)
210 {
211 int fid = s * (nfields + addfields) + nfields + i;
212 Vmath::Vcopy(npoints, outfield[i], 1, m_f->m_exp[fid]->UpdatePhys(),
213 1);
214 m_f->m_exp[fid]->FwdTransLocalElmt(outfield[i],
215 m_f->m_exp[fid]->UpdateCoeffs());
216 }
217 }
218}
219
221 int totfields, int strip)
222{
223 int npoints = m_f->m_exp[0]->GetNpoints();
224 if (boost::iequals(m_f->m_variables[0], "u"))
225 {
226 // IncNavierStokesSolver
227 for (int i = 0; i < m_spacedim; ++i)
228 {
229 vel[i] = Array<OneD, NekDouble>(npoints);
230 Vmath::Vcopy(npoints, m_f->m_exp[strip * totfields + i]->GetPhys(),
231 1, vel[i], 1);
232 }
233 }
234 else if (boost::iequals(m_f->m_variables[0], "rho") &&
235 boost::iequals(m_f->m_variables[1], "rhou"))
236 {
237 // CompressibleFlowSolver
238 for (int i = 0; i < m_spacedim; ++i)
239 {
240 vel[i] = Array<OneD, NekDouble>(npoints);
242 npoints, m_f->m_exp[strip * totfields + i + 1]->GetPhys(), 1,
243 m_f->m_exp[strip * totfields + 0]->GetPhys(), 1, vel[i], 1);
244 }
245 }
246 else
247 {
248 // Unknown
249 ASSERTL0(false, "Could not identify velocity for ProcessVorticity");
250 }
251}
252
253} // namespace Nektar::FieldUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
static GlobalMapping::MappingSharedPtr GetMapping(FieldSharedPtr f)
Abstract base class for processing modules.
Definition: Module.h:301
void GetVelocity(Array< OneD, Array< OneD, NekDouble > > &vel, int totfields, int strip=0)
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.
Definition: NekFactory.hpp:197
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:990
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47
GLOBAL_MAPPING_EXPORT typedef std::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
Definition: Mapping.h:51
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
void Vdiv(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:126
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