Nektar++
ProcessScalGrad.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: ProcessScalGrad.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 scalar gradient field.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include <iostream>
36#include <string>
37using namespace std;
38
39#include "ProcessScalGrad.h"
40
43
44namespace Nektar::FieldUtils
45{
46
50 "Computes scalar gradient field.");
51
53{
54}
55
57{
58}
59
60void ProcessScalGrad::v_Process(po::variables_map &vm)
61{
63
64 int i, j, k;
65
66 int spacedim = m_f->m_graph->GetSpaceDimension();
67 if ((m_f->m_numHomogeneousDir) == 1 || (m_f->m_numHomogeneousDir) == 2)
68 {
69 spacedim = 3;
70 }
71
72 int nfields = m_f->m_variables.size();
73
74 string var;
75 for (i = 0; i < nfields; i++)
76 {
77 var = m_f->m_variables[i];
78 stringstream filename;
79 filename << var << "_scalar_gradient";
80 filename >> var;
81 m_f->m_variables[i] = var;
82 }
83 if (m_f->m_exp[0]->GetNumElmts() == 0)
84 {
85 return;
86 }
87
88 if (spacedim == 1)
89 {
90 ASSERTL0(false, "Error: scalar gradient for a 1D problem cannot "
91 "be computed");
92 }
93
94 int ngrad = spacedim;
95 int n, cnt, elmtid, nq, offset, boundary, nfq;
96 int npoints = m_f->m_exp[0]->GetNpoints();
98 Array<OneD, Array<OneD, NekDouble>> grad(ngrad), fgrad(ngrad),
99 outfield(nfields);
100
103 Array<OneD, int> BoundarytoElmtID, BoundarytoTraceID;
105
106 m_f->m_exp[0]->GetBoundaryToElmtMap(BoundarytoElmtID, BoundarytoTraceID);
107
108 for (i = 0; i < nfields; i++)
109 {
110 BndExp[i] = m_f->m_exp[i]->GetBndCondExpansions();
111 outfield[i] = Array<OneD, NekDouble>(npoints);
112 }
113
114 // loop over the types of boundary conditions
115 for (cnt = n = 0; n < BndExp[0].size(); ++n)
116 {
117 bool doneBnd = false;
118 // identify if boundary has been defined
119 for (int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
120 {
121 if (n == m_f->m_bndRegionsToWrite[b])
122 {
123 doneBnd = true;
124 for (i = 0; i < BndExp[0][n]->GetExpSize(); ++i, cnt++)
125 {
126 // find element and face of this expansion.
127 elmtid = BoundarytoElmtID[cnt];
128 elmt = m_f->m_exp[0]->GetExp(elmtid);
129 nq = elmt->GetTotPoints();
130 offset = m_f->m_exp[0]->GetPhys_Offset(elmtid);
131
132 // Initialise local arrays for the velocity
133 // gradients, and stress components size of total
134 // number of quadrature points for each element
135 // (hence local).
136 for (j = 0; j < ngrad; ++j)
137 {
138 grad[j] = Array<OneD, NekDouble>(nq);
139 }
140
141 if (spacedim == 2)
142 {
143 // Not implemented in 2D.
144 }
145 else
146 {
147 for (j = 0; j < nfields; j++)
148 {
149 outfield[j] = BndExp[j][n]->UpdateCoeffs() +
150 BndExp[j][n]->GetCoeff_Offset(i);
151 }
152
153 // Get face 2D expansion from element expansion
154 bc = std::dynamic_pointer_cast<
156 BndExp[0][n]->GetExp(i));
157 nfq = bc->GetTotPoints();
158
159 // identify boundary of element looking at.
160 boundary = BoundarytoTraceID[cnt];
161
162 const LocalRegions::Expansion *lep =
163 dynamic_cast<const LocalRegions::Expansion *>(
164 &(*bc));
165
166 // Get face normals
168 m_metricinfo = lep->GetMetricInfo();
169
171 normals = elmt->GetTraceNormal(boundary);
172
173 // initialise arrays
174 for (j = 0; j < ngrad; ++j)
175 {
176 fgrad[j] = Array<OneD, NekDouble>(nfq);
177 }
178 Array<OneD, NekDouble> gradnorm(nfq);
179
180 for (k = 0; k < nfields; k++)
181 {
182 Vmath::Zero(nfq, gradnorm, 1);
183
184 scalar = m_f->m_exp[k]->GetPhys() + offset;
185 elmt->PhysDeriv(scalar, grad[0], grad[1], grad[2]);
186
187 for (j = 0; j < ngrad; ++j)
188 {
189 elmt->GetTracePhysVals(boundary, bc, grad[j],
190 fgrad[j]);
191 }
192
193 // surface curved
194 if (m_metricinfo->GetGtype() ==
196 {
197 for (j = 0; j < ngrad; j++)
198 {
199 Vmath::Vvtvp(nfq, normals[j], 1, fgrad[j],
200 1, gradnorm, 1, gradnorm, 1);
201 }
202 }
203 else
204 {
205 for (j = 0; j < ngrad; j++)
206 {
207 Vmath::Svtvp(nfq, normals[j][0], fgrad[j],
208 1, gradnorm, 1, gradnorm, 1);
209 }
210 }
211 bc->FwdTrans(gradnorm, outfield[k]);
212 }
213 }
214 }
215 }
216 }
217 if (doneBnd == false)
218 {
219 cnt += BndExp[0][n]->GetExpSize();
220 }
221 }
222
223 for (j = 0; j < nfields; ++j)
224 {
225 for (int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
226 {
227 m_f->m_exp[j]->UpdateBndCondExpansion(m_f->m_bndRegionsToWrite[b]) =
228 BndExp[j][m_f->m_bndRegionsToWrite[b]];
229 }
230 }
231}
232} // namespace Nektar::FieldUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
This processing module sets up for the boundary field to be extracted.
void v_Process(po::variables_map &vm) override
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:197
const SpatialDomains::GeomFactorsSharedPtr & GetMetricInfo() const
Definition: Expansion.cpp:246
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
Definition: StdExpansion.h:134
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
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:66
std::shared_ptr< GeomFactors > GeomFactorsSharedPtr
Pointer to a GeomFactors object.
Definition: GeomFactors.h:60
@ eDeformed
Geometry is curved or has non-constant factors.
std::shared_ptr< StdExpansion2D > StdExpansion2DSharedPtr
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 Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.hpp:273