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

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

#include <ProcessCFL.h>

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

Public Member Functions

 ProcessCFL (FieldSharedPtr f)
 
virtual ~ProcessCFL ()
 
- 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 ()
 
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

virtual void v_Process (po::variables_map &vm) override
 Write mesh to output file. More...
 
virtual std::string v_GetModuleName () override
 
virtual std::string v_GetModuleDescription () override
 
virtual ModulePriority v_GetModulePriority () override
 
void GetVelocity (Array< OneD, Array< OneD, NekDouble > > &vel, int strip=0)
 
Array< OneD, NekDoubleGetMaxStdVelocity (const 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 ()
 

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 CFL and adds it as an extra-field to the output file.

Definition at line 48 of file ProcessCFL.h.

Constructor & Destructor Documentation

◆ ProcessCFL()

Nektar::FieldUtils::ProcessCFL::ProcessCFL ( FieldSharedPtr  f)

Definition at line 58 of file ProcessCFL.cpp.

◆ ~ProcessCFL()

Nektar::FieldUtils::ProcessCFL::~ProcessCFL ( )
virtual

Definition at line 62 of file ProcessCFL.cpp.

63{
64}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 52 of file ProcessCFL.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().

◆ GetMaxStdVelocity()

Array< OneD, NekDouble > Nektar::FieldUtils::ProcessCFL::GetMaxStdVelocity ( const Array< OneD, Array< OneD, NekDouble > > &  vel,
int  strip = 0 
)
protected

Definition at line 183 of file ProcessCFL.cpp.

185{
186 int nfields = m_f->m_variables.size();
187 int n_points_0 = m_f->m_exp[0]->GetExp(0)->GetTotPoints();
188 int n_element = m_f->m_exp[0]->GetExpSize();
189 int nvel = vel.size();
190 int cnt;
191
192 NekDouble pntVelocity;
193
194 // Getting the standard velocity vector
195 Array<OneD, Array<OneD, NekDouble>> stdVelocity(nvel);
196 Array<OneD, NekDouble> tmp;
197 Array<OneD, NekDouble> maxV(n_element, 0.0);
199
200 for (int i = 0; i < nvel; ++i)
201 {
202 stdVelocity[i] = Array<OneD, NekDouble>(n_points_0);
203 }
204
205 cnt = 0.0;
206 for (int el = 0; el < n_element; ++el)
207 {
208 int n_points = m_f->m_exp[0]->GetExp(el)->GetTotPoints();
209 ptsKeys = m_f->m_exp[0]->GetExp(el)->GetPointsKeys();
210
211 // reset local space
212 if (n_points != n_points_0)
213 {
214 for (int j = 0; j < nvel; ++j)
215 {
216 stdVelocity[j] = Array<OneD, NekDouble>(n_points, 0.0);
217 }
218 n_points_0 = n_points;
219 }
220 else
221 {
222 for (int j = 0; j < nvel; ++j)
223 {
224 Vmath::Zero(n_points, stdVelocity[j], 1);
225 }
226 }
227
228 Array<TwoD, const NekDouble> gmat = m_f->m_exp[strip * nfields + 0]
229 ->GetExp(el)
230 ->GetGeom()
231 ->GetMetricInfo()
232 ->GetDerivFactors(ptsKeys);
233
234 if (m_f->m_exp[strip * nfields + 0]
235 ->GetExp(el)
236 ->GetGeom()
237 ->GetMetricInfo()
238 ->GetGtype() == SpatialDomains::eDeformed)
239 {
240 for (int j = 0; j < nvel; ++j)
241 {
242 for (int k = 0; k < nvel; ++k)
243 {
244 Vmath::Vvtvp(n_points, gmat[k * nvel + j], 1,
245 tmp = vel[k] + cnt, 1, stdVelocity[j], 1,
246 stdVelocity[j], 1);
247 }
248 }
249 }
250 else
251 {
252 for (int j = 0; j < nvel; ++j)
253 {
254 for (int k = 0; k < nvel; ++k)
255 {
256 Vmath::Svtvp(n_points, gmat[k * nvel + j][0],
257 tmp = vel[k] + cnt, 1, stdVelocity[j], 1,
258 stdVelocity[j], 1);
259 }
260 }
261 }
262 cnt += n_points;
263
264 // Calculate total velocity in stdVelocity[0]
265 Vmath::Vmul(n_points, stdVelocity[0], 1, stdVelocity[0], 1,
266 stdVelocity[0], 1);
267 for (int k = 1; k < nvel; ++k)
268 {
269 Vmath::Vvtvp(n_points, stdVelocity[k], 1, stdVelocity[k], 1,
270 stdVelocity[0], 1, stdVelocity[0], 1);
271 }
272 pntVelocity = Vmath::Vmax(n_points, stdVelocity[0], 1);
273 maxV[el] = sqrt(pntVelocity);
274 }
275
276 return maxV;
277}
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
std::vector< PointsKey > PointsKeyVector
Definition: Points.h:236
@ eDeformed
Geometry is curved or has non-constant factors.
double NekDouble
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.cpp:207
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.cpp:617
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.cpp:569
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:487
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
Definition: Vmath.cpp:940
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:294

References Nektar::SpatialDomains::eDeformed, Nektar::FieldUtils::Module::m_f, tinysimd::sqrt(), Vmath::Svtvp(), Vmath::Vmax(), Vmath::Vmul(), Vmath::Vvtvp(), and Vmath::Zero().

Referenced by v_Process().

◆ GetVelocity()

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

Definition at line 148 of file ProcessCFL.cpp.

150{
151 int expdim = m_f->m_graph->GetMeshDimension();
152 int nfields = m_f->m_variables.size();
153 int npoints = m_f->m_exp[0]->GetNpoints();
154 if (boost::iequals(m_f->m_variables[0], "u"))
155 {
156 // IncNavierStokesSolver
157 // Using expdim instead of spacedim
158 // This is because for 3DH1D, only a 2D plane will be considered
159 for (int i = 0; i < expdim; ++i)
160 {
161 vel[i] = Array<OneD, NekDouble>(npoints);
162 Vmath::Vcopy(npoints, m_f->m_exp[strip * nfields + i]->GetPhys(), 1,
163 vel[i], 1);
164 }
165 }
166 else if (boost::iequals(m_f->m_variables[0], "rho") &&
167 boost::iequals(m_f->m_variables[1], "rhou"))
168 {
169 // CompressibleFlowSolver
170 ASSERTL0(false, "CFL calculation is not supported for the compressible "
171 "flow simulations at the moment");
172 }
173 else
174 {
175 // Unknown
176 ASSERTL0(false, "Could not identify velocity for ProcessCFL");
177 }
178}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1191

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

Referenced by v_Process().

◆ v_GetModuleDescription()

virtual std::string Nektar::FieldUtils::ProcessCFL::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 70 of file ProcessCFL.h.

71 {
72 return "Calculating CFL number over the domain for the Incompressible "
73 "flow simulation";
74 }

◆ v_GetModuleName()

virtual std::string Nektar::FieldUtils::ProcessCFL::v_GetModuleName ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 65 of file ProcessCFL.h.

66 {
67 return "ProcessCFL";
68 }

◆ v_GetModulePriority()

virtual ModulePriority Nektar::FieldUtils::ProcessCFL::v_GetModulePriority ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 76 of file ProcessCFL.h.

77 {
78 return eModifyExp;
79 }

References Nektar::FieldUtils::eModifyExp.

◆ v_Process()

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

Write mesh to output file.

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 66 of file ProcessCFL.cpp.

67{
68 m_f->SetUpExp(vm);
69
70 int expdim = m_f->m_graph->GetMeshDimension();
71 int nelmt = m_f->m_exp[0]->GetExpSize();
72 int nfields = m_f->m_variables.size();
73 m_spacedim = expdim;
74
75 NekDouble timeStep = m_f->m_session->GetParameter("TimeStep");
76 NekDouble cLambda = 0.2; // Spencer's book
77
78 if (m_f->m_numHomogeneousDir == 1)
79 {
80 m_spacedim = 3;
81 }
82 ASSERTL0(m_f->m_numHomogeneousDir != 2,
83 "CFL for 3DH2D simulations is not supported");
84 ASSERTL0(m_spacedim != 1, "Error: CFL for a 1D problem is not supported");
85
86 // Append field names
87 m_f->m_variables.push_back("CFL");
88
89 // Skip in case of empty partition
90 if (m_f->m_exp[0]->GetNumElmts() == 0)
91 {
92 return;
93 }
94 int npoints = m_f->m_exp[0]->GetNpoints();
95 Array<OneD, NekDouble> outfield(npoints);
96
97 int nstrips;
98 m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
99
101 // add in new fields
102 for (int s = 0; s < nstrips; ++s)
103 {
104 Exp = m_f->AppendExpList(m_f->m_numHomogeneousDir);
105 m_f->m_exp.insert(m_f->m_exp.begin() + s * (nfields + 1) + nfields,
106 Exp);
107 }
108
109 for (int s = 0; s < nstrips; ++s) // homogeneous strip varient
110 {
111 Array<OneD, Array<OneD, NekDouble>> velocityField(expdim);
112
113 // Get the velocity field
114 GetVelocity(velocityField, s);
115
116 // compute the max velocity in the std regions
117 Array<OneD, NekDouble> stdVel = GetMaxStdVelocity(velocityField);
118
119 // get the maximum expansion order in each element
120 Array<OneD, int> expOrder =
121 m_f->m_exp[s * nfields + 0]->EvalBasisNumModesMaxPerExp();
122
123 // compute the CFL number
124 Array<OneD, NekDouble> cfl(nelmt);
125 for (int el = 0; el < nelmt; ++el)
126 {
127 int order = std::max(expOrder[el] - 1, 1);
128 cfl[el] = timeStep * stdVel[el] * cLambda * order * order;
129 }
130
131 int cnt = 0;
132 for (int el = 0; el < nelmt; ++el)
133 {
134 // using the field[0]==m_exp[s*nfields + 0]
135 int nquad = m_f->m_exp[s * nfields + 0]->GetExp(el)->GetTotPoints();
136 Vmath::Fill(nquad, cfl[el], &outfield[cnt], 1);
137 cnt += nquad;
138 }
139
140 // temporary store the CFL number field for each strip
141 Vmath::Vcopy(npoints, outfield, 1,
142 m_f->m_exp[s * (nfields + 1) + nfields]->UpdatePhys(), 1);
143 m_f->m_exp[0]->FwdTransLocalElmt(
144 outfield, m_f->m_exp[s * (nfields + 1) + nfields]->UpdateCoeffs());
145 }
146}
void GetVelocity(Array< OneD, Array< OneD, NekDouble > > &vel, int strip=0)
Definition: ProcessCFL.cpp:148
Array< OneD, NekDouble > GetMaxStdVelocity(const Array< OneD, Array< OneD, NekDouble > > &vel, int strip=0)
Definition: ProcessCFL.cpp:183
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:43

References ASSERTL0, Vmath::Fill(), GetMaxStdVelocity(), GetVelocity(), Nektar::FieldUtils::Module::m_f, m_spacedim, and Vmath::Vcopy().

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessCFL::className
static
Initial value:
"Computes CFL number for the entire domain for Incompressible flow.")
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
Definition: ProcessCFL.h:52
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49

Definition at line 56 of file ProcessCFL.h.

◆ m_spacedim

int Nektar::FieldUtils::ProcessCFL::m_spacedim
private

Definition at line 87 of file ProcessCFL.h.

Referenced by v_Process().