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
41
42#include "ProcessMapping.h"
44
45namespace Nektar::FieldUtils
46{
47
50 ModuleKey(eProcessModule, "divergence"),
52 "Computes divergence of the velocity field.");
53
55 : ProcessModule(f)
56{
57}
58
60{
61}
62
63void ProcessVelocityDivergence::v_Process(po::variables_map &vm)
64{
65 m_f->SetUpExp(vm);
66
67 int i, s;
68 int expdim = m_f->m_graph->GetMeshDimension();
69 m_spacedim = expdim;
70 if ((m_f->m_numHomogeneousDir) == 1 || (m_f->m_numHomogeneousDir) == 2)
71 {
72 m_spacedim = 3;
73 }
74 int nfields = m_f->m_variables.size();
76 "Error: Divergence for a 1D problem cannot be computed");
77
78 // Append field names
79 m_f->m_variables.push_back("divV");
80
81 // Skip in case of empty partition
82 if (m_f->m_exp[0]->GetNumElmts() == 0)
83 {
84 return;
85 }
86 int npoints = m_f->m_exp[0]->GetNpoints();
89
90 int nstrips;
91
92 m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
93
94 for (i = 0; i < m_spacedim * m_spacedim; ++i)
95 {
96 grad[i] = Array<OneD, NekDouble>(npoints);
97 }
98
99 outfield[0] = Array<OneD, NekDouble>(npoints);
100
102 for (int i = 0; i < m_spacedim; i++)
103 {
104 tmp[i] = Array<OneD, NekDouble>(npoints);
105 }
106
107 vector<MultiRegions::ExpListSharedPtr> Exp(nstrips);
108
109 // Get mapping
111
112 for (s = 0; s < nstrips; ++s) // homogeneous strip varient
113 {
114 // Get velocity and convert to Cartesian system,
115 // if it is still in transformed system
117 GetVelocity(vel, s);
118 if (m_f->m_fieldMetaDataMap.count("MappingCartesianVel"))
119 {
120 if (m_f->m_fieldMetaDataMap["MappingCartesianVel"] == "False")
121 {
122 // Initialize arrays and copy velocity
123 if (m_f->m_exp[0]->GetWaveSpace())
124 {
125 for (int i = 0; i < m_spacedim; ++i)
126 {
127 m_f->m_exp[0]->HomogeneousBwdTrans(npoints, vel[i],
128 vel[i]);
129 }
130 }
131 // Convert velocity to cartesian system
132 mapping->ContravarToCartesian(vel, vel);
133 // Convert back to wavespace if necessary
134 if (m_f->m_exp[0]->GetWaveSpace())
135 {
136 for (int i = 0; i < m_spacedim; ++i)
137 {
138 m_f->m_exp[0]->HomogeneousFwdTrans(npoints, vel[i],
139 vel[i]);
140 }
141 }
142 }
143 }
144
145 // Calculate Gradient
146 if (m_spacedim == 2)
147 {
148 for (i = 0; i < m_spacedim; ++i)
149 {
150 m_f->m_exp[s * nfields + i]->PhysDeriv(vel[i], tmp[0], tmp[1]);
151 mapping->CovarToCartesian(tmp, tmp);
152 for (int j = 0; j < m_spacedim; j++)
153 {
154 Vmath::Vcopy(npoints, tmp[j], 1, grad[i * m_spacedim + j],
155 1);
156 }
157 }
158 // diV = Ux + Vy
159 Vmath::Vadd(npoints, grad[0 * m_spacedim + 0], 1,
160 grad[1 * m_spacedim + 1], 1, outfield[0], 1);
161 }
162 else
163 {
164 for (i = 0; i < m_spacedim; ++i)
165 {
166 m_f->m_exp[s * nfields + i]->PhysDeriv(vel[i], tmp[0], tmp[1],
167 tmp[2]);
168 mapping->CovarToCartesian(tmp, tmp);
169 for (int j = 0; j < m_spacedim; j++)
170 {
171 Vmath::Vcopy(npoints, tmp[j], 1, grad[i * m_spacedim + j],
172 1);
173 }
174 }
175
176 // diV = Ux + Vy + Wz
177 Vmath::Vadd(npoints, grad[0 * m_spacedim + 0], 1,
178 grad[1 * m_spacedim + 1], 1, outfield[0], 1);
179 Vmath::Vadd(npoints, outfield[0], 1, grad[2 * m_spacedim + 2], 1,
180 outfield[0], 1);
181 }
182
183 Exp[s] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
184 Vmath::Vcopy(npoints, outfield[0], 1, Exp[s]->UpdatePhys(), 1);
185 Exp[s]->FwdTransLocalElmt(outfield[0], Exp[s]->UpdateCoeffs());
186 }
187
188 for (s = 0; s < nstrips; ++s)
189 {
190 m_f->m_exp.insert(m_f->m_exp.begin() + s * (nfields + 1) + nfields,
191 Exp[s]);
192 }
193}
194
196 Array<OneD, Array<OneD, NekDouble>> &vel, int strip)
197{
198 int nfields = m_f->m_variables.size();
199 int npoints = m_f->m_exp[0]->GetNpoints();
200 if (boost::iequals(m_f->m_variables[0], "u"))
201 {
202 // IncNavierStokesSolver
203 for (int i = 0; i < m_spacedim; ++i)
204 {
205 vel[i] = Array<OneD, NekDouble>(npoints);
206 Vmath::Vcopy(npoints, m_f->m_exp[strip * nfields + i]->GetPhys(), 1,
207 vel[i], 1);
208 }
209 }
210 else if (boost::iequals(m_f->m_variables[0], "rho") &&
211 boost::iequals(m_f->m_variables[1], "rhou"))
212 {
213 // CompressibleFlowSolver
214 for (int i = 0; i < m_spacedim; ++i)
215 {
216 vel[i] = Array<OneD, NekDouble>(npoints);
217 Vmath::Vdiv(npoints, m_f->m_exp[strip * nfields + i + 1]->GetPhys(),
218 1, m_f->m_exp[strip * nfields + 0]->GetPhys(), 1,
219 vel[i], 1);
220 }
221 }
222 else
223 {
224 // Unknown
225 ASSERTL0(false,
226 "Could not identify velocity for ProcessVelocityDivergence");
227 }
228}
229
230} // 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 strip=0)
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.
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
GLOBAL_MAPPING_EXPORT typedef std::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
Definition: Mapping.h:51
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 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
STL namespace.