Nektar++
ProcessVelocityDivergence.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: ProcessVelocityDivergence.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 velocity divergence field.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include <iostream>
36#include <string>
37using namespace std;
38
39#include <boost/core/ignore_unused.hpp>
40
43
44#include "ProcessMapping.h"
46
47namespace Nektar
48{
49namespace FieldUtils
50{
51
54 ModuleKey(eProcessModule, "divergence"),
56 "Computes divergence of the velocity field.");
57
59 : ProcessModule(f)
60{
61}
62
64{
65}
66
67void ProcessVelocityDivergence::v_Process(po::variables_map &vm)
68{
69 m_f->SetUpExp(vm);
70
71 int i, s;
72 int expdim = m_f->m_graph->GetMeshDimension();
73 m_spacedim = expdim;
74 if ((m_f->m_numHomogeneousDir) == 1 || (m_f->m_numHomogeneousDir) == 2)
75 {
76 m_spacedim = 3;
77 }
78 int nfields = m_f->m_variables.size();
80 "Error: Divergence for a 1D problem cannot be computed");
81
82 // Append field names
83 m_f->m_variables.push_back("divV");
84
85 // Skip in case of empty partition
86 if (m_f->m_exp[0]->GetNumElmts() == 0)
87 {
88 return;
89 }
90 int npoints = m_f->m_exp[0]->GetNpoints();
93
94 int nstrips;
95
96 m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
97
98 for (i = 0; i < m_spacedim * m_spacedim; ++i)
99 {
100 grad[i] = Array<OneD, NekDouble>(npoints);
101 }
102
103 outfield[0] = Array<OneD, NekDouble>(npoints);
104
106 for (int i = 0; i < m_spacedim; i++)
107 {
108 tmp[i] = Array<OneD, NekDouble>(npoints);
109 }
110
111 vector<MultiRegions::ExpListSharedPtr> Exp(nstrips);
112
113 // Get mapping
115
116 for (s = 0; s < nstrips; ++s) // homogeneous strip varient
117 {
118 // Get velocity and convert to Cartesian system,
119 // if it is still in transformed system
121 GetVelocity(vel, s);
122 if (m_f->m_fieldMetaDataMap.count("MappingCartesianVel"))
123 {
124 if (m_f->m_fieldMetaDataMap["MappingCartesianVel"] == "False")
125 {
126 // Initialize arrays and copy velocity
127 if (m_f->m_exp[0]->GetWaveSpace())
128 {
129 for (int i = 0; i < m_spacedim; ++i)
130 {
131 m_f->m_exp[0]->HomogeneousBwdTrans(npoints, vel[i],
132 vel[i]);
133 }
134 }
135 // Convert velocity to cartesian system
136 mapping->ContravarToCartesian(vel, vel);
137 // Convert back to wavespace if necessary
138 if (m_f->m_exp[0]->GetWaveSpace())
139 {
140 for (int i = 0; i < m_spacedim; ++i)
141 {
142 m_f->m_exp[0]->HomogeneousFwdTrans(npoints, vel[i],
143 vel[i]);
144 }
145 }
146 }
147 }
148
149 // Calculate Gradient
150 if (m_spacedim == 2)
151 {
152 for (i = 0; i < m_spacedim; ++i)
153 {
154 m_f->m_exp[s * nfields + i]->PhysDeriv(vel[i], tmp[0], tmp[1]);
155 mapping->CovarToCartesian(tmp, tmp);
156 for (int j = 0; j < m_spacedim; j++)
157 {
158 Vmath::Vcopy(npoints, tmp[j], 1, grad[i * m_spacedim + j],
159 1);
160 }
161 }
162 // diV = Ux + Vy
163 Vmath::Vadd(npoints, grad[0 * m_spacedim + 0], 1,
164 grad[1 * m_spacedim + 1], 1, outfield[0], 1);
165 }
166 else
167 {
168 for (i = 0; i < m_spacedim; ++i)
169 {
170 m_f->m_exp[s * nfields + i]->PhysDeriv(vel[i], tmp[0], tmp[1],
171 tmp[2]);
172 mapping->CovarToCartesian(tmp, tmp);
173 for (int j = 0; j < m_spacedim; j++)
174 {
175 Vmath::Vcopy(npoints, tmp[j], 1, grad[i * m_spacedim + j],
176 1);
177 }
178 }
179
180 // diV = Ux + Vy + Wz
181 Vmath::Vadd(npoints, grad[0 * m_spacedim + 0], 1,
182 grad[1 * m_spacedim + 1], 1, outfield[0], 1);
183 Vmath::Vadd(npoints, outfield[0], 1, grad[2 * m_spacedim + 2], 1,
184 outfield[0], 1);
185 }
186
187 Exp[s] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
188 Vmath::Vcopy(npoints, outfield[0], 1, Exp[s]->UpdatePhys(), 1);
189 Exp[s]->FwdTransLocalElmt(outfield[0], Exp[s]->UpdateCoeffs());
190 }
191
192 for (s = 0; s < nstrips; ++s)
193 {
194 m_f->m_exp.insert(m_f->m_exp.begin() + s * (nfields + 1) + nfields,
195 Exp[s]);
196 }
197}
198
200 Array<OneD, Array<OneD, NekDouble>> &vel, int strip)
201{
202 int nfields = m_f->m_variables.size();
203 int npoints = m_f->m_exp[0]->GetNpoints();
204 if (boost::iequals(m_f->m_variables[0], "u"))
205 {
206 // IncNavierStokesSolver
207 for (int i = 0; i < m_spacedim; ++i)
208 {
209 vel[i] = Array<OneD, NekDouble>(npoints);
210 Vmath::Vcopy(npoints, m_f->m_exp[strip * nfields + i]->GetPhys(), 1,
211 vel[i], 1);
212 }
213 }
214 else if (boost::iequals(m_f->m_variables[0], "rho") &&
215 boost::iequals(m_f->m_variables[1], "rhou"))
216 {
217 // CompressibleFlowSolver
218 for (int i = 0; i < m_spacedim; ++i)
219 {
220 vel[i] = Array<OneD, NekDouble>(npoints);
221 Vmath::Vdiv(npoints, m_f->m_exp[strip * nfields + i + 1]->GetPhys(),
222 1, m_f->m_exp[strip * nfields + 0]->GetPhys(), 1,
223 vel[i], 1);
224 }
225 }
226 else
227 {
228 // Unknown
229 ASSERTL0(false,
230 "Could not identify velocity for ProcessVelocityDivergence");
231 }
232}
233
234} // namespace FieldUtils
235} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
static GlobalMapping::MappingSharedPtr GetMapping(FieldSharedPtr f)
Abstract base class for processing modules.
Definition: Module.h:292
void GetVelocity(Array< OneD, Array< OneD, NekDouble > > &vel, int strip=0)
virtual void v_Process(po::variables_map &vm) override
Write mesh to output file.
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
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
GLOBAL_MAPPING_EXPORT typedef std::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
Definition: Mapping.h:53
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
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.cpp:354
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.cpp:280
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1191