Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
Nektar::FieldUtils::ProcessCompressibleFields Class Reference

This processing module computes, from the conservative variables of a compressible flow, the velocity, pressure, temperature, entropy, sound speed and Mach number fields, assuming an ideal gas. More...

#include <ProcessCompressibleFields.h>

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

Public Member Functions

 ProcessCompressibleFields (FieldSharedPtr f)
 
 ~ProcessCompressibleFields () 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 ConfigOption & GetConfigOption (const std::string &key) const
 
ModulePriority GetModulePriority ()
 
std::vector< ModuleKey > GetModulePrerequisites ()
 
FIELD_UTILS_EXPORT void RegisterConfig (std::string key, std::string value="")
 Register a configuration option with a module.
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module.
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set.
 
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< Module > create (FieldSharedPtr f)
 Creates an instance of this class.
 

Static Public Attributes

static ModuleKey className
 

Protected Member Functions

void v_Process (po::variables_map &vm) override
 Compute the compressible fields and append them to the field.
 
std::string v_GetModuleName () override
 
std::string v_GetModuleDescription () override
 
ModulePriority v_GetModulePriority () override
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
virtual std::vector< ModuleKey > v_GetModulePrerequisites ()
 

Additional Inherited Members

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

Detailed Description

This processing module computes, from the conservative variables of a compressible flow, the velocity, pressure, temperature, entropy, sound speed and Mach number fields, assuming an ideal gas.

Definition at line 48 of file ProcessCompressibleFields.h.

Constructor & Destructor Documentation

◆ ProcessCompressibleFields()

Nektar::FieldUtils::ProcessCompressibleFields::ProcessCompressibleFields ( FieldSharedPtr  f)

Definition at line 56 of file ProcessCompressibleFields.cpp.

◆ ~ProcessCompressibleFields()

Nektar::FieldUtils::ProcessCompressibleFields::~ProcessCompressibleFields ( )
override

Definition at line 61 of file ProcessCompressibleFields.cpp.

62{
63}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 52 of file ProcessCompressibleFields.h.

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

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

◆ v_GetModuleDescription()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 70 of file ProcessCompressibleFields.h.

71 {
72 return "Computing compressible fields (u,v,w,p,T,s,a,Mach)";
73 }

◆ v_GetModuleName()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 65 of file ProcessCompressibleFields.h.

66 {
67 return "ProcessCompressibleFields";
68 }

◆ v_GetModulePriority()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 75 of file ProcessCompressibleFields.h.

76 {
77 return eModifyExp;
78 }

References Nektar::FieldUtils::eModifyExp.

◆ v_Process()

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

Compute the compressible fields and append them to the field.

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 65 of file ProcessCompressibleFields.cpp.

66{
67 m_f->SetUpExp(vm);
68
69 ASSERTL0(m_f->m_session && m_f->m_graph,
70 "ProcessCompressibleFields requires a session file.");
71
72 std::string eosType;
73 m_f->m_session->LoadSolverInfo("EquationOfState", eosType, "IdealGas");
74 ASSERTL0(StringUtils::IEquals(eosType, "IdealGas"),
75 "ProcessCompressibleFields only supports the IdealGas equation "
76 "of state.");
77
78 int nfields = m_f->m_variables.size();
79 int spacedim = m_f->m_graph->GetMeshDimension() + m_f->m_numHomogeneousDir;
80
81 // Locate the conservative variables by name, so that the input may contain
82 // other fields in any order
83 auto findField = [&](const std::string &name) {
84 auto it =
85 std::find(m_f->m_variables.begin(), m_f->m_variables.end(), name);
86 ASSERTL0(it != m_f->m_variables.end(),
87 "ProcessCompressibleFields requires the field '" + name +
88 "' (conservative variables of a compressible flow).");
89 return static_cast<int>(it - m_f->m_variables.begin());
90 };
91
92 const std::string momNames[3] = {"rhou", "rhov", "rhow"};
93 const std::string velNames[3] = {"u", "v", "w"};
94
95 int rhoId = findField("rho");
96 int EId = findField("E");
97 std::vector<int> momId(spacedim);
98 for (int i = 0; i < spacedim; ++i)
99 {
100 momId[i] = findField(momNames[i]);
101 }
102
103 // New fields: velocity components, p, T, s, a and Mach
104 std::vector<std::string> newNames(velNames, velNames + spacedim);
105 newNames.insert(newNames.end(), {"p", "T", "s", "a", "Mach"});
106 int addfields = newNames.size();
107
108 for (auto &name : newNames)
109 {
110 ASSERTL0(std::find(m_f->m_variables.begin(), m_f->m_variables.end(),
111 name) == m_f->m_variables.end(),
112 "Field '" + name +
113 "' already exists (e.g. the file was written with "
114 "OutputExtraFields); remove it first with the "
115 "removefield module.");
116 }
117
118 // Append field names
119 m_f->m_variables.insert(m_f->m_variables.end(), newNames.begin(),
120 newNames.end());
121
122 // Skip in case of empty partition
123 if (m_f->m_exp[0]->GetNumElmts() == 0)
124 {
125 return;
126 }
127
128 int nstrips;
129 m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
130
131 // Add in new fields
132 for (int s = 0; s < nstrips; ++s)
133 {
134 for (int i = 0; i < addfields; ++i)
135 {
137 m_f->AppendExpList(m_f->m_numHomogeneousDir);
138 m_f->m_exp.insert(m_f->m_exp.begin() + s * (nfields + addfields) +
139 nfields + i,
140 Exp);
141 }
142 }
143
144 NekDouble gamma, gasConstant;
145 m_f->m_session->LoadParameter("Gamma", gamma, 1.4);
146 m_f->m_session->LoadParameter("GasConstant", gasConstant, 287.058);
147 NekDouble cv = gasConstant / (gamma - 1.0);
148
149 int npoints = m_f->m_exp[0]->GetNpoints();
150 bool waveSpace = m_f->m_exp[0]->GetWaveSpace();
151
152 Array<OneD, NekDouble> rho(npoints), e(npoints), vel2(npoints);
153 Array<OneD, NekDouble> tmp(npoints);
154 Array<OneD, Array<OneD, NekDouble>> outfield(addfields);
155 for (int i = 0; i < addfields; ++i)
156 {
157 outfield[i] = Array<OneD, NekDouble>(npoints);
158 }
159 Array<OneD, NekDouble> &pressure = outfield[spacedim];
160 Array<OneD, NekDouble> &temperature = outfield[spacedim + 1];
161 Array<OneD, NekDouble> &entropy = outfield[spacedim + 2];
162 Array<OneD, NekDouble> &soundspeed = outfield[spacedim + 3];
163 Array<OneD, NekDouble> &mach = outfield[spacedim + 4];
164
165 // The fields are nonlinear functions of the conservative variables, so
166 // they have to be computed in physical space
167 auto getPhys = [&](int fid, Array<OneD, NekDouble> &out) {
168 if (waveSpace)
169 {
170 m_f->m_exp[fid]->HomogeneousBwdTrans(
171 npoints, m_f->m_exp[fid]->GetPhys(), out);
172 }
173 else
174 {
175 Vmath::Vcopy(npoints, m_f->m_exp[fid]->GetPhys(), 1, out, 1);
176 }
177 };
178
179 for (int s = 0; s < nstrips; ++s)
180 {
181 int offset = s * (nfields + addfields);
182
183 getPhys(offset + rhoId, rho);
184
185 // Velocity u_i = (rho u_i) / rho and its squared magnitude |u|^2
186 Vmath::Zero(npoints, vel2, 1);
187 for (int i = 0; i < spacedim; ++i)
188 {
189 getPhys(offset + momId[i], outfield[i]);
190 Vmath::Vdiv(npoints, outfield[i], 1, rho, 1, outfield[i], 1);
191 Vmath::Vvtvp(npoints, outfield[i], 1, outfield[i], 1, vel2, 1, vel2,
192 1);
193 }
194
195 // Internal energy e = E / rho - 0.5 |u|^2
196 getPhys(offset + EId, e);
197 Vmath::Vdiv(npoints, e, 1, rho, 1, e, 1);
198 Vmath::Svtvp(npoints, -0.5, vel2, 1, e, 1, e, 1);
199
200 // Pressure p = (gamma - 1) rho e
201 Vmath::Vmul(npoints, rho, 1, e, 1, pressure, 1);
202 Vmath::Smul(npoints, gamma - 1.0, pressure, 1, pressure, 1);
203
204 // Temperature T = e / cv
205 Vmath::Smul(npoints, 1.0 / cv, e, 1, temperature, 1);
206
207 // Entropy s = cv log(T) - R log(rho)
208 Vmath::Vlog(npoints, temperature, 1, entropy, 1);
209 Vmath::Smul(npoints, cv, entropy, 1, entropy, 1);
210 Vmath::Vlog(npoints, rho, 1, tmp, 1);
211 Vmath::Svtvp(npoints, -gasConstant, tmp, 1, entropy, 1, entropy, 1);
212
213 // Sound speed a = sqrt(gamma R T)
214 Vmath::Smul(npoints, gamma * gasConstant, temperature, 1, soundspeed,
215 1);
216 Vmath::Vsqrt(npoints, soundspeed, 1, soundspeed, 1);
217
218 // Mach number M = |u| / a
219 Vmath::Vsqrt(npoints, vel2, 1, mach, 1);
220 Vmath::Vdiv(npoints, mach, 1, soundspeed, 1, mach, 1);
221
222 for (int i = 0; i < addfields; ++i)
223 {
224 int fid = offset + nfields + i;
225 if (waveSpace)
226 {
227 m_f->m_exp[fid]->HomogeneousFwdTrans(npoints, outfield[i],
228 outfield[i]);
229 }
230 Vmath::Vcopy(npoints, outfield[i], 1, m_f->m_exp[fid]->UpdatePhys(),
231 1);
232 m_f->m_exp[fid]->FwdTransLocalElmt(outfield[i],
233 m_f->m_exp[fid]->UpdateCoeffs());
234 }
235 }
236}
#define ASSERTL0(condition, msg)
FieldSharedPtr m_f
Field object.
Definition Module.h:239
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT out
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
bool IEquals(std::string_view a, std::string_view b)
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
Definition Vmath.hpp:342
void Vmul(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:74
void Vlog(int n, const T *x, const int incx, T *y, const int incy)
log y = log(x)
Definition Vmath.hpp:305
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:398
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:368
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition Vmath.hpp:102
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:128
void Zero(int n, T *x, const int incx)
Zero vector.
Definition Vmath.hpp:275
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:828

References ASSERTL0, Nektar::StringUtils::IEquals(), Nektar::FieldUtils::Module::m_f, Vmath::Smul(), Vmath::Svtvp(), Vmath::Vcopy(), Vmath::Vdiv(), Vmath::Vlog(), Vmath::Vmul(), Vmath::Vsqrt(), Vmath::Vvtvp(), and Vmath::Zero().

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessCompressibleFields::className
static
Initial value:
=
ModuleKey(eProcessModule, "compressiblefields"),
"Computes velocity, pressure, temperature, entropy, sound speed and "
"Mach number from compressible flow fields.")
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::pair< ModuleType, std::string > ModuleKey
Definition Module.h:180
ModuleFactory & GetModuleFactory()
Definition Module.cpp:48

Definition at line 56 of file ProcessCompressibleFields.h.