Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Attributes | List of all members
Nektar::FieldUtils::ProcessVelocityDivergence Class Reference

This processing module calculates the divergence of the velocity field and adds it as an extra-field to the output file. More...

#include <ProcessVelocityDivergence.h>

Inheritance diagram for Nektar::FieldUtils::ProcessVelocityDivergence:
[legend]

Public Member Functions

 ProcessVelocityDivergence (FieldSharedPtr f)
 
 ~ProcessVelocityDivergence () override
 
- Public Member Functions inherited from Nektar::FieldUtils::ProcessModule
 ProcessModule ()
 
 ProcessModule (FieldSharedPtr p_f)
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
virtual ~Module ()=default
 
void Process (po::variables_map &vm)
 
std::string GetModuleName ()
 
std::string GetModuleDescription ()
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
ModulePriority GetModulePriority ()
 
std::vector< ModuleKeyGetModulePrerequisites ()
 
FIELD_UTILS_EXPORT void RegisterConfig (std::string key, std::string value="")
 Register a configuration option with a module. More...
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
FIELD_UTILS_EXPORT void AddFile (std::string fileType, std::string fileName)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

static std::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class. More...
 

Static Public Attributes

static ModuleKey className
 

Protected Member Functions

void v_Process (po::variables_map &vm) override
 Write mesh to output file. More...
 
std::string v_GetModuleName () override
 
std::string v_GetModuleDescription () override
 
ModulePriority v_GetModulePriority () override
 
void GetVelocity (Array< OneD, Array< OneD, NekDouble > > &vel, int strip=0)
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
virtual void v_Process (po::variables_map &vm)
 
virtual std::string v_GetModuleName ()
 
virtual std::string v_GetModuleDescription ()
 
virtual ModulePriority v_GetModulePriority ()
 
virtual std::vector< ModuleKeyv_GetModulePrerequisites ()
 

Private Attributes

int m_spacedim
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values. More...
 
std::set< std::string > m_allowedFiles
 List of allowed file formats. More...
 

Detailed Description

This processing module calculates the divergence of the velocity field and adds it as an extra-field to the output file.

Definition at line 46 of file ProcessVelocityDivergence.h.

Constructor & Destructor Documentation

◆ ProcessVelocityDivergence()

Nektar::FieldUtils::ProcessVelocityDivergence::ProcessVelocityDivergence ( FieldSharedPtr  f)

Definition at line 54 of file ProcessVelocityDivergence.cpp.

◆ ~ProcessVelocityDivergence()

Nektar::FieldUtils::ProcessVelocityDivergence::~ProcessVelocityDivergence ( )
override

Definition at line 59 of file ProcessVelocityDivergence.cpp.

60{
61}

Member Function Documentation

◆ create()

static std::shared_ptr< Module > Nektar::FieldUtils::ProcessVelocityDivergence::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 50 of file ProcessVelocityDivergence.h.

51 {
53 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

◆ GetVelocity()

void Nektar::FieldUtils::ProcessVelocityDivergence::GetVelocity ( Array< OneD, Array< OneD, NekDouble > > &  vel,
int  strip = 0 
)
protected

Definition at line 195 of file ProcessVelocityDivergence.cpp.

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}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
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

References ASSERTL0, Nektar::FieldUtils::Module::m_f, m_spacedim, Vmath::Vcopy(), and Vmath::Vdiv().

Referenced by v_Process().

◆ v_GetModuleDescription()

std::string Nektar::FieldUtils::ProcessVelocityDivergence::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 68 of file ProcessVelocityDivergence.h.

69 {
70 return "Calculating velocity divergence";
71 }

◆ v_GetModuleName()

std::string Nektar::FieldUtils::ProcessVelocityDivergence::v_GetModuleName ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 63 of file ProcessVelocityDivergence.h.

64 {
65 return "ProcessVelocityDivergence";
66 }

◆ v_GetModulePriority()

ModulePriority Nektar::FieldUtils::ProcessVelocityDivergence::v_GetModulePriority ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 73 of file ProcessVelocityDivergence.h.

74 {
75 return eModifyExp;
76 }

References Nektar::FieldUtils::eModifyExp.

◆ v_Process()

void Nektar::FieldUtils::ProcessVelocityDivergence::v_Process ( po::variables_map &  vm)
overrideprotectedvirtual

Write mesh to output file.

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 63 of file ProcessVelocityDivergence.cpp.

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();
87 Array<OneD, Array<OneD, NekDouble>> grad(m_spacedim * m_spacedim);
88 Array<OneD, Array<OneD, NekDouble>> outfield(1);
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
101 Array<OneD, Array<OneD, NekDouble>> tmp(m_spacedim);
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
116 Array<OneD, Array<OneD, NekDouble>> vel(m_spacedim);
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}
static GlobalMapping::MappingSharedPtr GetMapping(FieldSharedPtr f)
void GetVelocity(Array< OneD, Array< OneD, NekDouble > > &vel, int strip=0)
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

References ASSERTL0, Nektar::FieldUtils::ProcessMapping::GetMapping(), GetVelocity(), Nektar::FieldUtils::Module::m_f, m_spacedim, Nektar::GlobalMapping::MappingSharedPtr, Vmath::Vadd(), and Vmath::Vcopy().

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessVelocityDivergence::className
static
Initial value:
=
ModuleKey(eProcessModule, "divergence"),
"Computes divergence of the velocity field.")
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
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47

Definition at line 54 of file ProcessVelocityDivergence.h.

◆ m_spacedim

int Nektar::FieldUtils::ProcessVelocityDivergence::m_spacedim
private

Definition at line 81 of file ProcessVelocityDivergence.h.

Referenced by GetVelocity(), and v_Process().