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 ()
 
virtual void Process (po::variables_map &vm)
 Write mesh to output file. More...
 
virtual std::string GetModuleName ()
 
virtual std::string GetModuleDescription ()
 
virtual ModulePriority GetModulePriority ()
 
- 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
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
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 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 ()
 

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.

58  : ProcessModule(f)
59 {
60 }

◆ ~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 188 of file ProcessCFL.cpp.

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

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

Referenced by Process().

◆ GetModuleDescription()

virtual std::string Nektar::FieldUtils::ProcessCFL::GetModuleDescription ( )
inlinevirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 69 of file ProcessCFL.h.

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

◆ GetModuleName()

virtual std::string Nektar::FieldUtils::ProcessCFL::GetModuleName ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 64 of file ProcessCFL.h.

65  {
66  return "ProcessCFL";
67  }

◆ GetModulePriority()

virtual ModulePriority Nektar::FieldUtils::ProcessCFL::GetModulePriority ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 75 of file ProcessCFL.h.

76  {
77  return eModifyExp;
78  }

References Nektar::FieldUtils::eModifyExp.

◆ GetVelocity()

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

Definition at line 153 of file ProcessCFL.cpp.

155 {
156  int expdim = m_f->m_graph->GetMeshDimension();
157  int nfields = m_f->m_variables.size();
158  int npoints = m_f->m_exp[0]->GetNpoints();
159  if (boost::iequals(m_f->m_variables[0], "u"))
160  {
161  // IncNavierStokesSolver
162  // Using expdim instead of spacedim
163  // This is because for 3DH1D, only a 2D plane will be considered
164  for (int i = 0; i < expdim; ++i)
165  {
166  vel[i] = Array<OneD, NekDouble>(npoints);
167  Vmath::Vcopy(npoints, m_f->m_exp[strip * nfields + i]->GetPhys(), 1,
168  vel[i], 1);
169  }
170  }
171  else if (boost::iequals(m_f->m_variables[0], "rho") &&
172  boost::iequals(m_f->m_variables[1], "rhou"))
173  {
174  // CompressibleFlowSolver
175  ASSERTL0(false, "CFL calculation is not supported for the compressible "
176  "flow simulations at the moment");
177  }
178  else
179  {
180  // Unknown
181  ASSERTL0(false, "Could not identify velocity for ProcessCFL");
182  }
183 }
#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:1255

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

Referenced by Process().

◆ Process()

void Nektar::FieldUtils::ProcessCFL::Process ( po::variables_map &  vm)
virtual

Write mesh to output file.

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

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:285
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 86 of file ProcessCFL.h.

Referenced by Process().